Algebraic Multigrid for Compressed VectorH1 space

More
3 years 8 months ago #3549 by Ryanleaf
Dear Christoph,

Thank you very much for your kind help.
I'll discuss these possible solutions with my advisors.

Best,
Qi
More
3 years 8 months ago - 3 years 8 months ago #3550 by schruste
OK, I just did the third approach. The new variant that comes with ngsxfem (on github, current master branch) now has a RestrictedFESpace that you can obtain by replacing "Compress" with "Restrict". Instead of a BitArray of marked dofs you provide a BitArray of marked elements. The resulting dofs will be the same. However, when asked for element degrees of freedoms the RestrictedFESpace knows where no dofs should be placed at all.
With the change from
Code:
Vhneg = Compress(Vhbase, GetDofsOfElements(Vhbase, ci.GetElementsOfType(HASNEG))) Vhpos = Compress(Vhbase, GetDofsOfElements(Vhbase, ci.GetElementsOfType(HASPOS)))
to
Code:
Vhneg = Restrict(Vhbase, ci.GetElementsOfType(HASNEG)) Vhpos = Restrict(Vhbase, ci.GetElementsOfType(HASPOS))
your example should go through again.

Best,
Christoph
Last edit: 3 years 8 months ago by schruste.
The following user(s) said Thank You: Ryanleaf
More
3 years 8 months ago #3553 by Ryanleaf
Dear Christoph,

Thank you very much for your kind input, I will try to working on this.

Best,

Qi
More
3 years 8 months ago - 3 years 8 months ago #3559 by Ryanleaf
Dear Christoph,

I met another segmentation fault when I tried to add Dirichlet boundary conditions to this Restrict space. Here is part of script to demonstrate my problem.
Code:
from netgen.geom2d import SplineGeometry from netgen.meshing import MeshingParameters from xfem import * from netgen.csg import CSGeometry, OrthoBrick, Pnt import netgen.gui from netgen.geom2d import unit_square from ngsolve import * from ngsolve.la import EigenValues_Preconditioner from xfem.lsetcurv import * def eps(u): return 0.5 * (Grad(u) + Grad(u).trans) def Setup(): cube = CSGeometry() cube.Add(OrthoBrick(Pnt(-1.5, -1.5, -1.5), Pnt(1.5, 1.5, 1.5))) mesh = Mesh(cube.GenerateMesh(maxh=1, quad_dominated=False)) lsetmeshadap = LevelSetMeshAdaptation(mesh, order=3, threshold=1000, discontinuous_qn=True) phi = Norm(CoefficientFunction((x, y, z))) - 1 deformation = lsetmeshadap.CalcDeformation(phi) lsetp1 = lsetmeshadap.lset_p1 mesh.SetDeformation(deformation) ci = CutInfo(mesh, lsetp1) Vhbase = VectorH1(mesh, order=2, dirichlet=[1,2,3,4,5,6]) Vhneg = Restrict(Vhbase, ci.GetElementsOfType(HASNEG)) Vhpos = Restrict(Vhbase, ci.GetElementsOfType(HASPOS)) WhGV = FESpace([Vhneg, Vhpos], flags={"dgjumps": True}) coef_normal = CoefficientFunction((x, y, z)) lset_neg = {"levelset": lsetp1, "domain_type": NEG} lset_pos = {"levelset": lsetp1, "domain_type": POS} lset_doms = [lset_neg, lset_pos] elements_doms = [HASNEG, HASPOS] u, v = WhGV.TnT() a = BilinearForm(WhGV) for i in [0, 1]: # loop over domains a += SymbolicBFI(lset_doms[i], form=2* InnerProduct(eps(u[i]), eps(v[i])), definedonelements=ci.GetElementsOfType(elements_doms[i])) a += SymbolicBFI(lset_doms[i], form=u[i] * v[i], definedonelements=ci.GetElementsOfType(elements_doms[i])) return mesh, WhGV, a mesh, WhGV, a = Setup() gfu = GridFunction(WhGV) gfu.components[1].Set(CoefficientFunction((x,y,z)),BND) mg = Preconditioner(a, "h1amg") # register mg to a a.Assemble() print('NDOF = ', WhGV.ndof) preI = Projector(mask=WhGV.FreeDofs(), range=True) lams = EigenValues_Preconditioner(mat=a.mat, pre=mg.mat) print("condition number", max(lams)/min(lams))

Remove Illegal Elements
Volume Optimization
SearchCorrespondingPoint:: did not converge
WARNING: using flags as kwarg is deprecated in <class 'ngsolve.comp.FESpace'>, use the flag arguments as kwargs instead!
[qi-Alienware-17-R4:08254] *** Process received signal ***
[qi-Alienware-17-R4:08254] Signal: Segmentation fault (11)
[qi-Alienware-17-R4:08254] Signal code: Address not mapped (1)
[qi-Alienware-17-R4:08254] Failing at address: 0x3e0000003f
[qi-Alienware-17-R4:08254] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x46210)[0x7fbef6ab3210]
[qi-Alienware-17-R4:08254] [ 1] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngfem.so(_ZNK5ngfem22T_DifferentialOperatorINS_16DiffOpIdVectorH1ILi3ELNS_4VorBE1EEEE10CalcMatrixERKNS_13FiniteElementERKNS_30SIMD_BaseMappedIntegrationRuleEN5ngbla15BareSliceMatrixIN6ngcore4SIMDIdLi4EEELNSB_8ORDERINGE1EEE+0x11e)[0x7fbee8e2886e]
[qi-Alienware-17-R4:08254] [ 2] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngfem.so(_ZNK5ngfem30SymbolicBilinearFormIntegrator22T_CalcElementMatrixAddIdddEEvRKNS_13FiniteElementERKNS_21ElementTransformationEN5ngbla10FlatMatrixIT1_LNS8_8ORDERINGE1EmEERbRN6ngcore9LocalHeapE+0x8d6)[0x7fbee9b5d7a6]
[qi-Alienware-17-R4:08254] [ 3] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngfem.so(_ZNK5ngfem30SymbolicBilinearFormIntegrator17CalcElementMatrixERKNS_13FiniteElementERKNS_21ElementTransformationEN5ngbla10FlatMatrixIdLNS7_8ORDERINGE1EmEERN6ngcore9LocalHeapE+0x8b)[0x7fbee9b3e50b]
[qi-Alienware-17-R4:08254] [ 4] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(_ZZN6ngcomp9SetValuesIdEEvSt10shared_ptrIN5ngfem19CoefficientFunctionEERNS_12GridFunctionENS2_4VorBEPKNS_6RegionEPNS2_20DifferentialOperatorERN6ngcore9LocalHeapEbbiENKUlNS_7FESpace7ElementESF_E0_clESH_SF_+0x13f6)[0x7fbeeb2e23c6]
[qi-Alienware-17-R4:08254] [ 5] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(_ZNSt17_Function_handlerIFvN6ngcomp7FESpace7ElementERN6ngcore9LocalHeapEEZNS0_9SetValuesIdEEvSt10shared_ptrIN5ngfem19CoefficientFunctionEERNS0_12GridFunctionENS9_4VorBEPKNS0_6RegionEPNS9_20DifferentialOperatorES5_bbiEUlS2_S5_E0_E9_M_invokeERKSt9_Any_dataOS2_S5_+0x5a)[0x7fbeeb2e277a]
[qi-Alienware-17-R4:08254] [ 6] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(+0x750a6b)[0x7fbeeb042a6b]
[qi-Alienware-17-R4:08254] [ 7] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/netgen/../../../libngcore.so(_ZN6ngcore11TaskManager9CreateJobERKSt8functionIFvRNS_8TaskInfoEEEi+0x10d)[0x7fbef458e95d]
[qi-Alienware-17-R4:08254] [ 8] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(_ZN6ngcomp15IterateElementsERKNS_7FESpaceEN5ngfem4VorBERN6ngcore9LocalHeapERKSt8functionIFvNS0_7ElementES7_EE+0x322)[0x7fbeeb042742]
[qi-Alienware-17-R4:08254] [ 9] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(_ZN6ngcomp9SetValuesIdEEvSt10shared_ptrIN5ngfem19CoefficientFunctionEERNS_12GridFunctionENS2_4VorBEPKNS_6RegionEPNS2_20DifferentialOperatorERN6ngcore9LocalHeapEbbi+0xdf4)[0x7fbeeb2d96e4]
[qi-Alienware-17-R4:08254] [10] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(_ZN6ngcomp9SetValuesESt10shared_ptrIN5ngfem19CoefficientFunctionEERNS_12GridFunctionENS1_4VorBEPNS1_20DifferentialOperatorERN6ngcore9LocalHeapEbbi+0x224)[0x7fbeeb2b6724]
[qi-Alienware-17-R4:08254] [11] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(+0xd21527)[0x7fbeeb613527]
[qi-Alienware-17-R4:08254] [12] /home/qi/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/../../../libngcomp.so(+0x9b2aba)[0x7fbeeb2a4aba]
[qi-Alienware-17-R4:08254] [13] /usr/bin/python3.8[0x6b224d]
[qi-Alienware-17-R4:08254] [14] /usr/bin/python3.8(PyObject_Call+0x27e)[0x5f2c0e]
[qi-Alienware-17-R4:08254] [15] /usr/bin/python3.8(_PyEval_EvalFrameDefault+0x1f70)[0x56b7b0]
[qi-Alienware-17-R4:08254] [16] /usr/bin/python3.8(_PyEval_EvalCodeWithName+0x26a)[0x56822a]
[qi-Alienware-17-R4:08254] [17] /usr/bin/python3.8(_PyFunction_Vectorcall+0x393)[0x5f6033]
[qi-Alienware-17-R4:08254] [18] /usr/bin/python3.8(_PyEval_EvalFrameDefault+0x8f6)[0x56a136]
[qi-Alienware-17-R4:08254] [19] /usr/bin/python3.8(_PyEval_EvalCodeWithName+0x26a)[0x56822a]
[qi-Alienware-17-R4:08254] [20] /usr/bin/python3.8(PyEval_EvalCode+0x27)[0x68c1e7]
[qi-Alienware-17-R4:08254] [21] /usr/bin/python3.8[0x67d5a1]
[qi-Alienware-17-R4:08254] [22] /usr/bin/python3.8[0x67d61f]
[qi-Alienware-17-R4:08254] [23] /usr/bin/python3.8(PyRun_FileExFlags+0x9b)[0x67d6db]
[qi-Alienware-17-R4:08254] [24] /usr/bin/python3.8(PyRun_SimpleFileExFlags+0x17e)[0x67da6e]
[qi-Alienware-17-R4:08254] [25] /usr/bin/python3.8(Py_RunMain+0x212)[0x6b6132]
[qi-Alienware-17-R4:08254] [26] /usr/bin/python3.8(Py_BytesMain+0x2d)[0x6b64bd]
[qi-Alienware-17-R4:08254] [27] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x7fbef6a940b3]
[qi-Alienware-17-R4:08254] [28] /usr/bin/python3.8(_start+0x2e)[0x5f927e]
[qi-Alienware-17-R4:08254] *** End of error message ***


Is there something I should modify to enforce Dirichlet boundary conditions?
Best,
Qi
Last edit: 3 years 8 months ago by Ryanleaf.
More
3 years 8 months ago #3565 by schruste
Thanks for the report. This was a bug on my end. I only implemented the Restricted spaces for volume terms and access. The Set went into a trap then. This should be fixed now, see current master on github and have a try with that.

Best,
Christoph
More
3 years 8 months ago - 3 years 8 months ago #3566 by Ryanleaf
Dear Christoph,

Thank you very much for fixing the bug. This update fixed the boundary issue.
I am sorry I think may meet another problem about multigrid.:pinch:
Same script:
Code:
from netgen.geom2d import SplineGeometry from netgen.meshing import MeshingParameters from xfem import * from netgen.csg import CSGeometry, OrthoBrick, Pnt import netgen.gui from netgen.geom2d import unit_square from ngsolve import * from ngsolve.la import EigenValues_Preconditioner from xfem.lsetcurv import * def eps(u): return 0.5 * (Grad(u) + Grad(u).trans) def Setup(): cube = CSGeometry() cube.Add(OrthoBrick(Pnt(-1.5, -1.5, -1.5), Pnt(1.5, 1.5, 1.5))) mesh = Mesh(cube.GenerateMesh(maxh=1/8, quad_dominated=False)) lsetmeshadap = LevelSetMeshAdaptation(mesh, order=3, threshold=1000, discontinuous_qn=True) phi = Norm(CoefficientFunction((x, y, z))) - 1 deformation = lsetmeshadap.CalcDeformation(phi) lsetp1 = lsetmeshadap.lset_p1 mesh.SetDeformation(deformation) ci = CutInfo(mesh, lsetp1) Vhbase = VectorH1(mesh, order=2, dirichlet=[1,2,3,4,5,6]) Vhneg = Restrict(Vhbase, ci.GetElementsOfType(HASNEG)) Vhpos = Restrict(Vhbase, ci.GetElementsOfType(HASPOS)) WhGV = FESpace([Vhneg, Vhpos], flags={"dgjumps": True}) lset_neg = {"levelset": lsetp1, "domain_type": NEG} lset_pos = {"levelset": lsetp1, "domain_type": POS} lset_doms = [lset_neg, lset_pos] elements_doms = [HASNEG, HASPOS] u, v = WhGV.TnT() a = BilinearForm(WhGV) for i in [0, 1]: # loop over domains a += SymbolicBFI(lset_doms[i], form=2* InnerProduct(eps(u[i]), eps(v[i])), definedonelements=ci.GetElementsOfType(elements_doms[i])) a += SymbolicBFI(lset_doms[i], form=u[i] * v[i], definedonelements=ci.GetElementsOfType(elements_doms[i])) return mesh, WhGV, a mesh, WhGV, a = Setup() gfu = GridFunction(WhGV) gfu.components[1].Set(CoefficientFunction((x,y,z)),BND) mg = Preconditioner(a, "h1amg") # register mg to a a.Assemble() print('NDOF = ', WhGV.ndof) preI = Projector(mask=WhGV.FreeDofs(), range=True) lams = EigenValues_Preconditioner(mat=a.mat, pre=mg.mat) print("condition number", max(lams)/min(lams))
I noticed when I refine maxh to 1/8, I begin to get the following error:

Traceback (most recent call last):
File "/tmp/iterative_solver_krylov_hybrid.py/main.py", line 42, in <module>
a.Assemble()
netgen.libngpy._meshing.NgException: Inverse matrix: Matrix singularin Assemble BilinearForm 'biform_from_py'

Am I having inappropriate settings in this script to causing this problem?
Would you please let me know where to find a description about which version of algebraic multigrid is currently implemented?
Again thank you very much for your kind help.

Best,
Qi
Last edit: 3 years 8 months ago by Ryanleaf.
Time to create page: 0.115 seconds