- Thank you received: 0
Adaptive Mesh Refinement in 3D
5 years 2 months ago #1841
by Elsakori
Adaptive Mesh Refinement in 3D was created 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.
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.
Attachments:
- mneunteufel
- Offline
- Premium Member
Less
More
- Thank you received: 59
5 years 2 months ago #1842
by mneunteufel
Replied by mneunteufel on topic Adaptive Mesh Refinement in 3D
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
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
Attachments:
5 years 2 months ago #1867
by Elsakori
Replied by Elsakori on topic Adaptive Mesh Refinement in 3D
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".
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".
Attachments:
- mneunteufel
- Offline
- Premium Member
Less
More
- Thank you received: 59
5 years 2 months ago #1876
by mneunteufel
Replied by mneunteufel on topic Adaptive Mesh Refinement in 3D
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
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
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
5 years 2 months ago #1885
by christopher
Replied by christopher on topic Adaptive Mesh Refinement in 3D
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:
Best
Christopher
Code:
for el in mesh.Elements(BND):
mesh.SetRefinementFlag(el, False)
Best
Christopher
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
5 years 1 month ago #1936
by christopher
Replied by christopher on topic Adaptive Mesh Refinement in 3D
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
Best
Christopher
Time to create page: 0.110 seconds