Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobEliasWagner committed Jan 10, 2024
1 parent a108991 commit 5ec2588
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/data/helmholtz/helmholtz.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib

from domain_properties import read_config
from solver import HelmholtzSolver
from .domain_properties import read_config
from .solver import HelmholtzSolver


class Helmholtz:
Expand Down
7 changes: 3 additions & 4 deletions src/data/helmholtz/solver/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dolfinx
import ufl
from dolfinx.fem.petsc import LinearProblem
from mpi4py import MPI
from petsc4py import PETSc

Expand Down Expand Up @@ -49,16 +50,14 @@ def __call__(self, description: Description):

for i, (k0, f) in enumerate(zip(description.ks, description.frequencies)):
# update k
k.x.array[:] = k0 * crystals(v, cell_tags).x.array + trunc(v, cell_tags).x.array
k.x.array[:] = k0 * crystals.eval(v, cell_tags).x.array + trunc.eval(v, cell_tags).x.array

# assemble problem
lhs = ufl.inner(ufl.grad(p), ufl.grad(xi)) * ufl.dx - k**2 * ufl.inner(p, xi) * ufl.dx
rhs = k * s * ufl.inner(v_f, xi) * d_excitation

# compute solution
problem = dolfinx.fem.petsc.LinearProblem(
lhs, rhs, u=p_sol, petsc_options={"ksp_type": "preonly", "pc_type": "lu"}
)
problem = LinearProblem(lhs, rhs, u=p_sol, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
problem.solve()

# write solution
Expand Down
12 changes: 6 additions & 6 deletions src/data/helmholtz/solver/wave_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class AdiabaticLayer(WaveNumberModifier):
"""

def __init__(self, pd: Description, degree: int = 2):
self.box_min = np.array([0.0, 0.0])
self.box_max = np.array([pd.width + pd.right_width, pd.height])
self.box_min = np.array([0.0, 0.0, 0.0])
self.box_max = np.array([pd.width + pd.right_width, pd.height, 0.0])
self.depth = pd.absorber_depth
self.degree = degree
rt = pd.round_trip
Expand All @@ -45,15 +45,15 @@ def eval(self, function_space: dolfinx.fem.FunctionSpace, ct: dolfinx.mesh.MeshT

def wave_mod(x: np.array) -> np.array:
# Clamp point coordinates to the range defined by the box
clamped = np.maximum(self.box_min, np.minimum(x, self.box_max))
clamped = np.maximum(self.box_min[:, np.newaxis], np.minimum(x, self.box_max[:, np.newaxis]))

# Compute the distance from the clamped point to the original point
dist = np.linalg.norm(clamped - x)
# Compute the distance from the clamped points to the original points
dist = np.linalg.norm(clamped - x, axis=0)

# Relative distance inside absorber
dist = dist / self.depth

return self.sigma_0 * 1j * np.sum(dist**self.degree)
return self.sigma_0 * 1j * dist**self.degree

f = dolfinx.fem.Function(function_space)
f.interpolate(wave_mod)
Expand Down

0 comments on commit 5ec2588

Please sign in to comment.