- Thank you received: 0
BilinearForm.AssembleLinearization( ... ) crashes
5 years 6 months ago - 5 years 6 months ago #1569
by NilsHM
BilinearForm.AssembleLinearization( ... ) crashes was created 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
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.
- Guosheng Fu
- Offline
- Elite Member
Less
More
- Thank you received: 6
5 years 6 months ago #1570
by Guosheng Fu
Replied by Guosheng Fu on topic BilinearForm.AssembleLinearization( ... ) crashes
It would be easier to debug if you provide the python code.
The following user(s) said Thank You: NilsHM
5 years 6 months ago #1571
by NilsHM
Replied by NilsHM on topic BilinearForm.AssembleLinearization( ... ) crashes
Here is a stand-alone example.
The Newton Raphson is at the end of the file.
Thanks for the help!
The Newton Raphson is at the end of the file.
Thanks for the help!
Attachments:
- Guosheng Fu
- Offline
- Elite Member
Less
More
- Thank you received: 6
5 years 6 months ago #1572
by Guosheng Fu
Replied by Guosheng Fu on topic BilinearForm.AssembleLinearization( ... ) crashes
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.
not sure what's going on internally, maybe the developers can answer that.
The following user(s) said Thank You: NilsHM
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
5 years 6 months ago #1584
by christopher
Replied by christopher on topic BilinearForm.AssembleLinearization( ... ) crashes
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
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