1
2 """Canned operators for multivariable calculus."""
3
4 from __future__ import division
5
6 __copyright__ = "Copyright (C) 2009 Andreas Kloeckner"
7
8 __license__ = """
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see U{http://www.gnu.org/licenses/}.
21 """
22
23
24
25
26 from hedge.models import Operator
27
28
29
30
34
41
57
58 - def bind(self, discr):
66
67 return op
68
69
70
71
73 - def __init__(self, dimensions, subset=None):
84
101
103 from hedge.mesh import TAG_ALL
104 from hedge.optemplate import make_vector_field, pair_with_boundary, \
105 get_flux_operator, make_nabla, InverseMassOperator
106
107 nabla = make_nabla(self.dimensions)
108 m_inv = InverseMassOperator()
109
110 v = make_vector_field("v", self.arg_count)
111 bc = make_vector_field("bc", self.arg_count)
112
113 local_op_result = 0
114 idx = 0
115 for i, i_enabled in enumerate(self.subset):
116 if i_enabled and i < self.dimensions:
117 local_op_result += nabla[i]*v[idx]
118 idx += 1
119
120 flux_op = get_flux_operator(self.flux())
121
122 return local_op_result - m_inv*(
123 flux_op * v +
124 flux_op * pair_with_boundary(v, bc, TAG_ALL))
125
126 - def bind(self, discr):
133
134 return op
135