Out of memory error in frequency for loop

dolfinx.fem.Constant wraps constant quantities which can change between assemblies of the underlying matrix.

dolfinx.fem.petsc.LinearProblem has a PETSc Mat and Vec. Creating one every time step is extremely expensive, and not their intended use.

...  # Problem setup
k = dolfinx.fem.Constant(mesh, 0.0)
k.value = some_important_value
...  # Weak form definition
problem = LinearProblem(a, L, u=uh, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
...  # Other code
for nf in range(0,len(f_axis)):
    ...  # More code
    k.value = another_important_value
    problem.solve()
    ... # Postprocess
2 Likes