# Multiple Levelset geometries in ngsxfem

Dear Colleagues

I’m trying to implement a code taking in account multiple levelset functions as circles, the questions is:

is There a way to implement a list of levelset functions for n discrete subdomains ?

Camilo

Hi Camilo,

Are the circles (almost) intersecting? In that case, you really require several level set functions simultaneously and would need the subsequent intersection to compute during quadrature. This is somethings that we haven’t implemented, yet. It may be added in the future, but not so much in the near future.

Otherwise you can combine several level sets with min/max operations to obtain one level set function that describes several circles at once.

Best,
Christoph

Thank you so much Christoph !

In fact there are not intersections between the inclusions, about the use of min/max operators, should interpolate the built-in coefficient functions x,y to be able to apply the min() for example ? sorry but is not too clear for me how to implement what you suggest I was thinking in something like:

``````f = 0.2;
n = 2;
Vt = 1;
r = sqrt(f/(n*pi));
centers = np.array([[-0.25,0],[0.25,0]])
el = centers.shape
for i in range(el):
levelseti  = np.append(levelset, (sqrt((x-centers[i,0])**2+(y-centers[i,1])**2) - r))

levelset = min(levelseti[i] for i in range(len(levelseti)))
``````

but it gives the following error: TypeError: ‘<’ not supported between instances of ‘ngsolve.fem.CoefficientFunction’ and ‘int’

I’ve tried like below too:

``````lsetp1 = GridFunction(H1(mesh,order=1))
for i in range(len(levelseti)):
InterpolateToP1(levelseti[i],lsetp1)
Draw(lsetp1,mesh,"lsetp1")
SetVisualization(min=0,max=0)
Redraw()``````

but the interpolation is superposed in the GridFunctionn then it gives no error but is drawing just the last levelset.

best regards

Camilo.

Hi Camilo,

The min/max-operations from python expect scalars and yield scalar. That is not what you want. NGSolve provides similar functionality (pointwise) for CoefficientFunctions through the IfPos-CoefficientFunction. To compute the min of two functions f and g you may use IfPos(f-g,g,f). So, in the context of your code you may want to use:

```levelset = sqrt((x-centers[0,0])**2+(y-centers[0,1])**2) - r for i in range(1,el): levelset_new_circle = sqrt((x-centers[i,0])**2+(y-centers[i,1])**2) - r levelset = IfPos(levelset_new_circle-levelset, levelset, levelset_new_circle)```

Best,
Christoph

Thank you so much for your help Christoph is working, perfect !!! , share the output

Best regards

Camilo

Attachment: fig.jpg