Hi Max,
You can use ngsxfem directly to compute the linearform. It's really simple
.
I make a simple example that you can easily adapt to your problem. I want to have f as the source term that is 1 for x<0.5 and 0 otherwise (independent of the mesh).
Code:
f = LinearForm(fes)
from xfem import SymbolicLFI, NEG
f += SymbolicLFI(levelset_domain={"levelset" : x-0.5, "domain_type": NEG}, form = v)
File Attachment:
File Name:
poisson.py
File Size:1 KB
You will need to install the ngsxfem package for this:
github.com/ngsxfem/ngsxfem
Some remarks:
* Importing SymbolicLFI from xfem overwrites (monkey-patches) the usual NGSolve definition. But no worries, the syntax is compatible with standard ngsolve (in fact, standard ngsolve SymbolicLFI is called if no levelset_domain is provided). It's actually just a wrapper.
* NEG is imported as a keyword for describing that you want to integrate only where the level set function is negative. If you want to integrate on other parts of the level set domain you may want to use POS or IF (zero level set) for that.
* For this linear interface the integration in the SymbolicLFI will be geometrically exact.
* For essentially arbitary level set functions the ngsxfem-integration will introduce an additional error.
* This error is of second order unless you do something about it. There are two ways to improve the situation:
1. Either you accept the second order convergence and add more refinements (for the numerical integration). For that you provide the additional key "subdivlvl" with a value > 0.
2. Or you use an isoparametric mapping, see the jupyter- and non-jupyter examples on github for that.
Best,
Christoph