Hello guys,
I am currently solving frequency dependent Helmholtz equation in this way:
- After setting up mesh, defining frequency and wavenumber as
Constant(msh, PETSc.ScalarType())
, I write the weak form and define the linear problem as follows
#... initial settings ...
# ...
omega = Constant(msh, PETSc.ScalarType(1))
k0 = Constant(msh, PETSc.ScalarType(1))
#...
V = FunctionSpace(msh, ("CG", 2)
# ...other settings
f = Function(V)
# other stuff about f
a = inner(grad(u), grad(v)) * dx - k0**2 * inner(u, v) * dx
L = inner(f, v) * dx
uh = Function(V)
uh.name = "u"
problem = LinearProblem(a, L, u=uh, petsc_options={"ksp_type": "preonly", "pc_type": "lu","pc_factor_mat_solver_type": "mumps"}
- I update the value of k0 and omega inside a for loop and solve the problem for every frequency:
for freq in frequency_range:
# Compute solution
omega.value = 2*np.pi*freq
k0.value = 2*np.pi*freq*c0
problem.solve()
Now I need the LHS to change multiple times for some reason, so I need to assemble the system without using LinearProblem()
.
Question: Does the k0.value = something
have effect if the matrix has been assembled with
A = assemble_matrix(form(a), [])
A.assemble()
?
If not, do I need to bring out of the matrix all the frequency dependent terms and build something similar to:
[{K_{a}}] + \omega^{2}[M_a]
where [{K_{a}}] and [M_a] are assembled like this:
K_a = assemble_matrix(form(inner(grad(u), grad(v)) * dx), [])
M_a = assemble_matrix(form(1/c0**2 * inner(u, v) * dx ), [])
K_a.assemble()
M_a.assemble()
thank you very much, as always.