From d49041a891aa85d42d6308182a8e62733168efa0 Mon Sep 17 00:00:00 2001 From: Jakob Elias Wagner Date: Tue, 23 Jan 2024 21:01:08 +0100 Subject: [PATCH] change mesh origin to crystal lower left corner --- .../data/helmholtz/mesh/crystal_builder.py | 3 +- .../helmholtz/mesh/crystal_domain_builder.py | 4 +-- src/nos/data/helmholtz/mesh/mesh_builder.py | 33 +++++++++---------- .../helmholtz/solver/adiabatic_absorber.py | 2 +- .../helmholtz/solver/test_adiabatic_layer.py | 8 +++-- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/nos/data/helmholtz/mesh/crystal_builder.py b/src/nos/data/helmholtz/mesh/crystal_builder.py index f38021e7..bbc32aa9 100644 --- a/src/nos/data/helmholtz/mesh/crystal_builder.py +++ b/src/nos/data/helmholtz/mesh/crystal_builder.py @@ -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 diff --git a/src/nos/data/helmholtz/mesh/crystal_domain_builder.py b/src/nos/data/helmholtz/mesh/crystal_domain_builder.py index 64171df0..3341d2fc 100644 --- a/src/nos/data/helmholtz/mesh/crystal_domain_builder.py +++ b/src/nos/data/helmholtz/mesh/crystal_domain_builder.py @@ -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]: diff --git a/src/nos/data/helmholtz/mesh/mesh_builder.py b/src/nos/data/helmholtz/mesh/mesh_builder.py index ef10a146..3e24b834 100644 --- a/src/nos/data/helmholtz/mesh/mesh_builder.py +++ b/src/nos/data/helmholtz/mesh/mesh_builder.py @@ -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, @@ -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, @@ -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: @@ -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 @@ -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: diff --git a/src/nos/data/helmholtz/solver/adiabatic_absorber.py b/src/nos/data/helmholtz/solver/adiabatic_absorber.py index 3efe6888..42f1289e 100644 --- a/src/nos/data/helmholtz/solver/adiabatic_absorber.py +++ b/src/nos/data/helmholtz/solver/adiabatic_absorber.py @@ -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 diff --git a/test/data/helmholtz/solver/test_adiabatic_layer.py b/test/data/helmholtz/solver/test_adiabatic_layer.py index 2fb054d6..2b2dd6f4 100644 --- a/test/data/helmholtz/solver/test_adiabatic_layer.py +++ b/test/data/helmholtz/solver/test_adiabatic_layer.py @@ -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) @@ -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)