Skip to content

Commit 045798f

Browse files
committed
fix: adding support for unequal step vectors in 2D and 3D structured grid interpolators
1 parent 4659b47 commit 045798f

3 files changed

Lines changed: 494 additions & 12 deletions

File tree

LoopStructural/interpolators/supports/_2d_structured_grid.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,22 +495,36 @@ def vtk(self, node_properties={}, cell_properties={}):
495495
pass
496496

497497
def get_operators(self, weights: Dict[str, float]) -> Dict[str, Tuple[np.ndarray, float]]:
498-
"""Get
498+
"""Get operators with step vector scaling for unequal spacing
499499
500500
Parameters
501501
----------
502502
weights : Dict[str, float]
503-
_description_
503+
Weight value per operator
504504
505505
Returns
506506
-------
507507
Dict[str, Tuple[np.ndarray, float]]
508-
_description_
508+
Dictionary mapping operator names to (mask, scaled_weight) tuples
509+
510+
Notes
511+
-----
512+
Operator weights are scaled by step vector to account for unequal grid spacing:
513+
- Second derivatives (dxx, dyy): scale by 1 / step_vector[d]^2
514+
- Mixed derivatives (dxy): scale by 1 / (step_vector[0] * step_vector[1])
509515
"""
516+
# Get step vector for scaling (2D uses x and y)
517+
step_x, step_y = self.step_vector[0], self.step_vector[1]
518+
519+
# Scale factors for finite difference operators
520+
dxx_scale = 1.0 / (step_x ** 2)
521+
dyy_scale = 1.0 / (step_y ** 2)
522+
dxy_scale = 1.0 / (step_x * step_y)
523+
510524
# in a map we only want the xy operators
511525
operators = {
512-
'dxy': (Operator.Dxy_mask[1, :, :], weights['dxy'] * 2),
513-
'dxx': (Operator.Dxx_mask[1, :, :], weights['dxx']),
514-
'dyy': (Operator.Dyy_mask[1, :, :], weights['dyy']),
526+
'dxy': (Operator.Dxy_mask[1, :, :], weights['dxy'] * 2 * dxy_scale),
527+
'dxx': (Operator.Dxx_mask[1, :, :], weights['dxx'] * dxx_scale),
528+
'dyy': (Operator.Dyy_mask[1, :, :], weights['dyy'] * dyy_scale),
515529
}
516530
return operators

LoopStructural/interpolators/supports/_3d_structured_grid.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,33 @@ def get_operators(self, weights: Dict[str, float]) -> Dict[str, Tuple[np.ndarray
487487
-------
488488
operators
489489
A dictionary with a numpy array and float weight
490+
491+
Notes
492+
-----
493+
Operator weights are scaled by step vector to account for unequal grid spacing:
494+
- Second derivatives (dxx, dyy, dzz): scale by 1 / step_vector[d]^2
495+
- Mixed derivatives (dxy, dxz, dyz): scale by 1 / (step_vector[d1] * step_vector[d2])
490496
"""
497+
# Get step vector for scaling
498+
step_x, step_y, step_z = self.step_vector[0], self.step_vector[1], self.step_vector[2]
499+
500+
# Scale factors for finite difference operators
501+
# Second derivatives need 1/h^2 scaling for physical space
502+
dxx_scale = 1.0 / (step_x ** 2)
503+
dyy_scale = 1.0 / (step_y ** 2)
504+
dzz_scale = 1.0 / (step_z ** 2)
505+
506+
# Mixed derivatives need 1/(h1*h2) scaling for physical space
507+
dxy_scale = 1.0 / (step_x * step_y)
508+
dyz_scale = 1.0 / (step_y * step_z)
509+
dxz_scale = 1.0 / (step_x * step_z)
510+
491511
operators = {
492-
'dxy': (Operator.Dxy_mask, weights['dxy'] / 4),
493-
'dyz': (Operator.Dyz_mask, weights['dyz'] / 4),
494-
'dxz': (Operator.Dxz_mask, weights['dxz'] / 4),
495-
'dxx': (Operator.Dxx_mask, weights['dxx'] / 1),
496-
'dyy': (Operator.Dyy_mask, weights['dyy'] / 1),
497-
'dzz': (Operator.Dzz_mask, weights['dzz'] / 1),
512+
'dxy': (Operator.Dxy_mask, weights['dxy'] / 4 * dxy_scale),
513+
'dyz': (Operator.Dyz_mask, weights['dyz'] / 4 * dyz_scale),
514+
'dxz': (Operator.Dxz_mask, weights['dxz'] / 4 * dxz_scale),
515+
'dxx': (Operator.Dxx_mask, weights['dxx'] / 1 * dxx_scale),
516+
'dyy': (Operator.Dyy_mask, weights['dyy'] / 1 * dyy_scale),
517+
'dzz': (Operator.Dzz_mask, weights['dzz'] / 1 * dzz_scale),
498518
}
499519
return operators

0 commit comments

Comments
 (0)