Adaptive Mesh Refinement in 3D

More
5 years 2 months ago #1841 by Elsakori
Hello,

I am using NGSolve to solve Maxwell’s equations in time-harmonic form.
I am trying to use the adaptive refinement loop (Solve→Estimate→Mark→Refine→Solve→) to refine the mesh.
I used the approach in the example in section 1.6 (Error estimation & adaptive refinement) to do that, with the necessary changes; but this doesn't work. The step "mesh.SetRefinementFlag(el, elerr[el.nr] > 0.25*maxerr)" doesn't work even if I change the percentage of the max error.

Note: The example in section 1.6 works for 2D problem whereas my problem in 3D, so does this approach work for 3D meshes?


I am grateful for any explanation

Here are my python script.
More
5 years 2 months ago #1842 by mneunteufel
Hi Elsakori,

your exact solution may produce a singularity at (0,0,0) with the term (x**2+y**2+z**2)**0.6.
After regularizing this term it seems to work now.

By the way: You do not need sympy for computing the right-hand side for your problem. NGSolve has its own Diff method.

Attached you'll find the code.

Best regards,
Michael

File Attachment:

File Name: simple_exa...tive2.py
File Size:4 KB
More
5 years 2 months ago #1867 by Elsakori
Hi Michael,

Thank you for your response and the changes that you made in the code. you are right, the exact solution produce a singularity at (0,0,0) with the term (x**2+y**2+z**2)**0.6. So, I expected a finer refinement around (0,0,0), but the refinement went in strange way. I added a grid function "e" to store the local exact error (which is the estimate used to mark the elements) for each element; but by drawing "e" we can see that some elements with big errors were not refined whereas other were refined with small error values.
My question again, does the attribute "SetRefinementFlag" work with 3D meshes?. Because I couldn't find any other adaptive refinement example that work for 3D problems.

Note: I can't used the Diff method of NGSolve, it gives me this error
File "<string>", line 26, in <module>
AttributeError: 'ngsolve.fem.CoefficientFunction' object has no attribute 'Diff'.

I am grateful for any explanation

Here are my python script after adding the grid function "e".
More
5 years 2 months ago #1876 by mneunteufel
Hi Elsakori,

yes, you are right. There seems to be a bug regarding the SetRefinementFlag in 3D.
We are working to fix it.

The Diff method for CoefficientFunctions is a quite new feature. It should work, if you download the latest version of NGSolve.

Best,
Michael
More
5 years 2 months ago #1885 by christopher
In netgen either 2d or 3d elements can be marked for refinement. This results in the difference, that for 3d you have to mark all surface elements as False for refinement. Since only 2 and 3d elements can be marked this is not necessary in 2D. So add these 2 lines to your code:
Code:
for el in mesh.Elements(BND): mesh.SetRefinementFlag(el, False)

Best
Christopher
More
5 years 1 month ago #1936 by christopher
The default behaviour has been changed now to not automatically refine boundary elements. In the upcoming releases you can skip the setrefinmentflag for the bnd elements.

Best
Christopher
Time to create page: 0.110 seconds