Skip to content

Commit

Permalink
change mesh origin to crystal lower left corner
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobEliasWagner committed Jan 23, 2024
1 parent 7f46c20 commit d49041a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/nos/data/helmholtz/mesh/crystal_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def __init__(self, description: Description):
# define center of crystals
offset = self.crystal_description.grid_size / 2.0
self.centers_x = [
offset + col * self.crystal_description.grid_size + self.description.left_width
for col in range(self.crystal_description.n)
offset + col * self.crystal_description.grid_size for col in range(self.crystal_description.n)
]
self.center_y = offset

Expand Down
4 changes: 1 addition & 3 deletions src/nos/data/helmholtz/mesh/crystal_domain_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def define_basic_shape(self) -> int:
Returns:
gmsh index to the rectangle.
"""
domain = self.factory.addRectangle(
self.description.left_width, 0.0, 0.0, self.description.domain_width, self.description.height
)
domain = self.factory.addRectangle(0.0, 0.0, 0.0, self.description.domain_width, self.description.height)
return domain

def define_tools(self) -> List[int]:
Expand Down
33 changes: 15 additions & 18 deletions src/nos/data/helmholtz/mesh/mesh_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ def build_basic_shapes(self) -> List[int]:
tags = []
# left space, domain, right space
if self.description.left_width > 0:
tags.append(self.factory.addRectangle(0.0, 0.0, 0.0, self.description.left_width, self.description.height))
tags.append(
self.factory.addRectangle(
-self.description.left_width, 0.0, 0.0, self.description.left_width, self.description.height
)
)
tags.append(self.domain_builder.build())
if self.description.right_width > 0:
tags.append(
self.factory.addRectangle(
self.description.left_width + self.description.domain_width,
self.description.domain_width,
0.0,
0.0,
self.description.right_width,
Expand All @@ -84,11 +88,15 @@ def build_basic_shapes(self) -> List[int]:
# absorbers
absorber_depth = self.description.absorber.lambda_depth * max(self.description.wave_lengths)
# left
tags.append(self.factory.add_rectangle(-absorber_depth, 0.0, 0.0, absorber_depth, self.description.height))
tags.append(
self.factory.add_rectangle(
-absorber_depth - self.description.left_width, 0.0, 0.0, absorber_depth, self.description.height
)
)
# right
tags.append(
self.factory.add_rectangle(
self.description.left_width + self.description.domain_width + self.description.right_width,
self.description.domain_width + self.description.right_width,
0.0,
0.0,
absorber_depth,
Expand Down Expand Up @@ -121,9 +129,9 @@ def get_physical_groups(self) -> List[Tuple[int, List[int], int]]:
all_surfaces = self.factory.get_entities(2)
surf_categories = defaultdict(list)
domain_bbox = BoundingBox2D(
-self.description.left_width,
0.0,
0.0,
self.description.left_width + self.description.domain_width + self.description.right_width,
self.description.domain_width + self.description.right_width,
self.description.height,
) # left space, domain, right space
for _, surf in all_surfaces:
Expand All @@ -138,7 +146,7 @@ def get_physical_groups(self) -> List[Tuple[int, List[int], int]]:
surf_categories["left_side"].append(surf)
continue
# domain
if com[0, 0] < self.description.left_width + self.description.domain_width:
if com[0, 0] < self.description.domain_width:
surf_categories["crystal_domain"].append(surf)
continue
# right spacer
Expand All @@ -147,17 +155,6 @@ def get_physical_groups(self) -> List[Tuple[int, List[int], int]]:
for name, indices in surf_categories.items():
categories.append((2, indices, self.description.indices[name]))

# lines
lines = self.factory.get_entities(1)
excitation_boundary = None
for _, line in lines:
com = np.array(self.factory.getCenterOfMass(1, line))
if np.allclose(com, [0, self.description.height / 2.0, 0]):
excitation_boundary = line
break

categories.append((1, [excitation_boundary], self.description.indices["excitation"]))

return categories

def set_physical_groups(self, groups: List[Tuple[int, List[int], int]]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/nos/data/helmholtz/solver/adiabatic_absorber.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AdiabaticAbsorber(WaveNumberFunction):

def __init__(self, description: Description):
self.bbox = BoundingBox2D(
0.0, 0.0, description.left_width + description.domain_width + description.right_width, description.height
-description.left_width, 0.0, description.domain_width + description.right_width, description.height
)
self.depth = description.absorber.lambda_depth
self.round_trip = description.absorber.round_trip
Expand Down
8 changes: 5 additions & 3 deletions test/data/helmholtz/solver/test_adiabatic_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ def all_sides_absorber():
)
absorber = AdiabaticAbsorber(des)

assert absorber.bbox.x_max == 3.0
assert absorber.bbox.x_max == 2.5
assert absorber.bbox.x_min == -0.5
assert absorber.bbox.y_max == 1.0
assert absorber.bbox.y_min == 0.0

return absorber


def test_inside_zero(all_sides_absorber):
x = np.random.random((1000, 2)) @ np.array([[3.0, 0.0], [0.0, 1.0]]) # scale to match all inside
x = np.random.random((1000, 2)) @ np.array([[3.0, 0.0], [0.0, 1.0]]) - np.array([0.5, 0]) # all inside
assert np.allclose(all_sides_absorber.eval(x), 0)


Expand All @@ -51,6 +53,6 @@ def test_correct_value(all_sides_absorber):
x = np.array([[4.0, 1.0], [-1, -1]])

sigma_0 = -3 * np.log(10) / 2.0
sol = sigma_0 * 1j * np.array([1.0, np.sqrt(2)]) ** 2
sol = sigma_0 * 1j * np.array([1.5, np.sqrt(1.25)]) ** 2

assert np.allclose(all_sides_absorber.eval(x), sol)

0 comments on commit d49041a

Please sign in to comment.