Here is a standalone example. It seems to crash when doing the assembly…
import numpy as np
import netgen.gui
from ngsolve import *
from netgen.geom2d import SplineGeometry
make the mesh
geo = SplineGeometry()
geo.AddRectangle( (0,0), (1,1), bc = “Gamma”)
mesh = Mesh(geo.GenerateMesh(maxh=1.0))
for r in range(4):
mesh.Refine()
Draw(mesh)
print(mesh.GetBoundaries())
zero_vec = CoefficientFunction((0.0, 0.0))
fes_V = H1(mesh, order=1) ** 2
a_form = BilinearForm (fes_V, symmetric=False)
setup weak formulation
qq = fes_V.TrialFunction()
pp = fes_V.TestFunction()
a_form += InnerProduct(grad(qq),grad(pp)) * dx
a_form += InnerProduct(qq,pp) * dx
f_form = LinearForm(fes_V)
f_vec = CoefficientFunction((x, y))
f_form += InnerProduct(f_vec,pp) * dx
this does NOT work (silently crashes; it doesn’t make it to the “Attempt to solve…” statement below)
c = Preconditioner(a_form, “multigrid”) # Register ‘c’ to ‘a’ BEFORE assembly
# this does work
c = Preconditioner(a_form, “h1amg”) # Register ‘c’ to ‘a’ BEFORE assembly
print(“Attempt to assemble…”)
a_form.Assemble()
f_form.Assemble()
print(“Attempt to solve…”)
with TaskManager():
# Conjugate gradient solver
inv = CGSolver(a_form.mat, c.mat, maxsteps=5000) #, precision=1e-12)
# do the solve
vec_data = inv * f_form.vec
print(“We solved it!”)
input(“Press Enter to finish…”)