Skip to content
Snippets Groups Projects

finite difference stencil derivation for staggered positions

Merged Michael Kuron requested to merge fvm into master
Files
3
@@ -236,13 +236,14 @@ class FiniteDifferenceStaggeredStencilDerivation:
"""Derives a finite difference stencil for application at a staggered position
Args:
neighbor: the neighbor direction string at whose staggered index to calculate the derivative
neighbor: the neighbor direction string or vector at whose staggered position to calculate the derivative
dim: how many dimensions (2 or 3)
derivative: a tuple of directions over which to perform derivatives
"""
def __init__(self, neighbor, dim, derivative=tuple()):
neighbor = direction_string_to_offset(neighbor)
if type(neighbor) is str:
neighbor = direction_string_to_offset(neighbor)
if dim == 2:
assert neighbor[dim:] == 0
assert derivative is tuple() or max(derivative) < dim
@@ -339,4 +340,10 @@ class FiniteDifferenceStaggeredStencilDerivation:
plot(pts, data=ws)
def apply(self, field):
return sum([field.__getitem__(point) * weight for point, weight in zip(self.points, self.weights)])
if field.index_dimensions == 0:
return sum([field.__getitem__(point) * weight for point, weight in zip(self.points, self.weights)])
else:
total = field.neighbor_vector(self.points[0]) * self.weights[0]
for point, weight in zip(self.points[1:], self.weights[1:]):
total += field.neighbor_vector(point) * weight
return total