Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Multiple Levelset geometries in ngsxfem

More
4 years 2 months ago #2395 by camilo.suarezafanador
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 ?

Thanks by advance for your help.

Camilo
More
4 years 2 months ago #2397 by schruste
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
More
4 years 2 months ago #2399 by camilo.suarezafanador
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:
Code:
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[0]): 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:
Code:
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.

Thanks by advance for your advise !

best regards

Camilo.
More
4 years 2 months ago #2400 by schruste
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:
Code:
levelset = sqrt((x-centers[0,0])**2+(y-centers[0,1])**2) - r for i in range(1,el[0]): 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
The following user(s) said Thank You: camilo.suarezafanador
More
4 years 2 months ago #2401 by camilo.suarezafanador
Thank you so much for your help Christoph is working, perfect !!! :) , share the output

Best regards

Camilo

Attachments:
Time to create page: 0.166 seconds