BilinearForm.AssembleLinearization( ... ) crashes

More
5 years 6 months ago - 5 years 6 months ago #1569 by NilsHM
Hi!
I want to solve a nonlinear nonsymmetric system of equation via a newton raphson iteration.
The problem is defined as:


fesCurl_cplx = HCurl(mesh, order = 3, nograds = True, complex = True)
fes1_cplx_iron = H1(mesh, order = 3, complex = True)
fesMixed = FESpace([fesCurl_cplx, fes1_cplx_iron])
u_A, u_Psi = fesMixed.TrialFunction()
v_A, v_Psi = fesMixed.TestFunction()
sysmat_Mixed = BilinearForm(fesMixed)
sysmat_Mixed += SymbolicBFI(
mu_inv*curl(u_A)*curl(v_A) +
1j*omega*sigma*v_A*u_A +
1j*omega*sigma*v_A*grad(u_Psi)*u_Psi +
1j*omega*sigma*grad(v_Psi)*grad(u_Psi) +
1j*omega*sigma*grad(v_Psi)*u_A)
rhs_Mixed = LinearForm(fesMixed)
rhs_Mixed += SymbolicLFI(v_A*j_coil)
rhs_Mixed.Assemble()
sol_Mixed = GridFunction(fesMixed, name = "Mixed")


The Newton Raphson iteration works like this:



lhs = sol_Mixed.vec.CreateVector()
res = sol_Mixed.vec.CreateVector()
dsol = sol_Mixed.vec.CreateVector()
for it in range(10):
# calculate residual vector
sysmat_Mixed.Apply(sol_Mixed.vec, lhs)
res.data = rhs_Mixed.vec - lhs

# create preconditioner
pre = Preconditioner(sysmat_Mixed, "bddc") # "bddc", "multigrid"

# assemble linearized system matrix
sysmat_Mixed.AssembleLinearization(sol_Mixed.vec)

# solve linear system of equations
solvers.GMRes(A = sysmat_Mixed.mat, pre = pre.mat, b = res,
x = dsol, printrates = True, tol = 1e-10, maxsteps = 200)

# update solution
sol_Mixed.vec.data -= dsol

# check convergence
resval = sqrt(abs(InnerProduct(dsol, res)))
print ("residual = ", resval)
if resval < 1e-8:
break


For the first iteration loop this works fine but when assembling the linearization for the second time, the program crashes.
How can I fix that?

Thanks!
Nils
Last edit: 5 years 6 months ago by NilsHM.
More
5 years 6 months ago #1570 by Guosheng Fu
It would be easier to debug if you provide the python code.
The following user(s) said Thank You: NilsHM
More
5 years 6 months ago #1571 by NilsHM
Here is a stand-alone example.
The Newton Raphson is at the end of the file.
Thanks for the help!

File Attachment:

File Name: TEAM23_nonlinear.py
File Size:6 KB
More
5 years 6 months ago #1572 by Guosheng Fu
I got the code running by pulling out the preconditioner line outside the loop...
not sure what's going on internally, maybe the developers can answer that.
The following user(s) said Thank You: NilsHM
More
5 years 6 months ago #1584 by christopher
You are right, this was the problem. The BilinearForm keeps pointers to the preconditioners and updates them automatically if the BF is reassembled. But it doesn't keep the Preconditioners alive and it didn't yet unregister them on preconditioner destruction. This is what caused the segfault. I'll push a fix for that in the next days, but keep the preconditioner out anyway, since it is more efficient (there has to be no allocation of memory,...).
Here you can see in an example that the preconditioner is updated on the call of a.Assemble, the same happens for assemblelinearization.

Best Christopher
Time to create page: 0.104 seconds