This page was generated from unit-3.8-nonlmin/nonlmin.ipynb.
3.8 Nonlinear minimization problems¶
We consider problems of the form
[1]:
from ngsolve import *
import netgen.gui
Scalar minimization problems¶
As a first example we take \(V = H^1_0\) and
The minimization is equivalent to solving the nonlinear PDE:
We solve the PDE with a Newton iteration.
[2]:
from netgen.geom2d import unit_square
mesh = Mesh (unit_square.GenerateMesh(maxh=0.2))
V = H1(mesh, order=4, dirichlet=[1,2,3,4])
u = V.TrialFunction()
To solve the problem we use the Variation
integrator. Based on the symbolic description of the energy functional, it is able to
evaluate the energy functional (
Energy
)
compute the Gateau derivative for a given \(u\) (
Apply
):
compute the second derivative (
AssembleLinearization
)
[3]:
a = BilinearForm (V, symmetric=True)
a += Variation ( (grad(u)*grad(u) + u**4-u) * dx)
Equivalent to:
a += (2 * grad(u) * grad(v) + 4*u*u*u*v - 1 * v)*dx
(which has the same form as the problems in the nonlinear example)
We recall the Newton iteration (cf. unit-3.7 ) we make the loop:
Given an initial guess \(u^0\)
loop over \(i=0,..\) until convergence:
Compute linearization: $A u^i + \delta `A(u^i) :nbsphinx-math:Delta `u^{i} = 0 $:
\(f^i = A u^i\)
\(B^i = \delta A(u^i)\)
Solve \(B^i \Delta u^i = -f^i\)
Update \(u^{i+1} = u^i + \Delta u^{i}\)
Evaluate stopping criteria
Evaluate \(E(u^{i+1})\)
As a stopping criteria we take \(\langle A u^i,\Delta u^i \rangle = \langle A u^i, A u^i \rangle_{(B^i)^{-1}}< \varepsilon\).
[4]:
def SolveNonlinearMinProblem(a,gfu,tol=1e-13,maxits=25):
res = gfu.vec.CreateVector()
du = gfu.vec.CreateVector()
for it in range(maxits):
print ("Newton iteration {:3}".format(it),end="")
print ("energy = {:16}".format(a.Energy(gfu.vec)),end="")
#solve linearized problem:
a.Apply (gfu.vec, res)
a.AssembleLinearization (gfu.vec)
inv = a.mat.Inverse(V.FreeDofs())
du.data = inv * res
#update iteration
gfu.vec.data -= du
#stopping criteria
stopcritval = sqrt(abs(InnerProduct(du,res)))
print ("<A u",it,", A u",it,">_{-1}^0.5 = ", stopcritval)
if stopcritval < tol:
break
Redraw(blocking=True)
[5]:
gfu = GridFunction (V)
gfu.vec[:] = 0
Draw(gfu,mesh,"u")
SolveNonlinearMinProblem(a,gfu)
print ("energy = ", a.Energy(gfu.vec))
Newton iteration 0energy = 0.0<A u 0 , A u 0 >_{-1}^0.5 = 0.13255949695477584
Newton iteration 1energy = -0.008785666770072002<A u 1 , A u 1 >_{-1}^0.5 = 1.110760041466411e-05
Newton iteration 2energy = -0.008785666831761395<A u 2 , A u 2 >_{-1}^0.5 = 2.8074721184641564e-13
Newton iteration 3energy = -0.008785666831761397<A u 3 , A u 3 >_{-1}^0.5 = 3.3534118580780286e-17
energy = -0.008785666831761397
Again, a Newton for minimization is shipped with NGSolve:
[6]:
from ngsolve.solvers import *
gfu.vec[:] = 0
NewtonMinimization(a,gfu)
Redraw()
Newton iteration 0
Energy: 0.0
err = 0.1325594969547758
Newton iteration 1
Energy: -0.008785666770072002
err = 1.1107600414641456e-05
Newton iteration 2
Energy: -0.008785666831761395
err = 2.807487362219202e-13
Nonlinear elasticity¶
We consider a beam which is fixed on one side and is subject to gravity only. We assume a Neo-Hookean hyperelastic material. The model is a nonlinear minimization problem with
where \(\mu\) and \(\lambda\) are the Lamé parameters and \(F = I + D v\) where \(v: \Omega \to \mathbb{R}^2\) is the sought for displacement.
[7]:
import netgen.geom2d as geom2d
from ngsolve import *
geo = geom2d.SplineGeometry()
pnums = [ geo.AddPoint (x,y,maxh=0.01) for x,y in [(0,0), (1,0), (1,0.1), (0,0.1)] ]
for p1,p2,bc in [(0,1,"bot"), (1,2,"right"), (2,3,"top"), (3,0,"left")]:
geo.Append(["line", pnums[p1], pnums[p2]], bc=bc)
mesh = Mesh(geo.GenerateMesh(maxh=0.05))
[8]:
# E module and poisson number:
E, nu = 210, 0.2
# Lamé constants:
mu = E / 2 / (1+nu)
lam = E * nu / ((1+nu)*(1-2*nu))
V = VectorH1(mesh, order=2, dirichlet="left")
u = V.TrialFunction()
#gravity:
force = CoefficientFunction( (0,-1) )
[9]:
def Pow(a, b):
return exp (log(a)*b)
def NeoHook (C):
return 0.5 * mu * (Trace(C-I) + 2*mu/lam * Pow(Det(C), -lam/2/mu) - 1)
I = Id(mesh.dim)
F = I + Grad(u)
C = F.trans * F
factor = Parameter(1.0)
a = BilinearForm(V, symmetric=True)
a += Variation( NeoHook (C).Compile() * dx
-factor * (InnerProduct(force,u) ).Compile() * dx)
We want to solve the minimization problem for \(\gamma = 5\). Due to the high nonlinearity in the problem, the Newton iteration will not convergence with any initial guess. We approach the case \(\gamma = 5\) by solving problems with \(\gamma = i/10\) for \(i=1,..,50\) and taking the solution of the previous problem as an initial guess.
[10]:
gfu = GridFunction(V)
gfu.vec[:] = 0
Draw (gfu, mesh, "u")
SetVisualization (deformation=True)
res = gfu.vec.CreateVector()
du = gfu.vec.CreateVector()
for loadstep in range(50):
print ("loadstep", loadstep)
factor.Set ((loadstep+1)/10)
SolveNonlinearMinProblem(a,gfu)
Redraw()
loadstep 0
Newton iteration 0energy = 8.75<A u 0 , A u 0 >_{-1}^0.5 = 0.01667837789716294
Newton iteration 1energy = 8.750132585680886<A u 1 , A u 1 >_{-1}^0.5 = 0.02333323303877385
Newton iteration 2energy = 8.749861150793905<A u 2 , A u 2 >_{-1}^0.5 = 0.00010232235243752909
Newton iteration 3energy = 8.749861145558985<A u 3 , A u 3 >_{-1}^0.5 = 5.1345221820805024e-08
Newton iteration 4energy = 8.749861145558976<A u 4 , A u 4 >_{-1}^0.5 = 2.719796997242145e-13
Newton iteration 5energy = 8.749861145558976<A u 5 , A u 5 >_{-1}^0.5 = 8.489155657475164e-16
loadstep 1
Newton iteration 0energy = 8.749583894068525<A u 0 , A u 0 >_{-1}^0.5 = 0.016596074475351455
Newton iteration 1energy = 8.749710096952624<A u 1 , A u 1 >_{-1}^0.5 = 0.022958250215112486
Newton iteration 2energy = 8.749447302450054<A u 2 , A u 2 >_{-1}^0.5 = 0.0001421518844148885
Newton iteration 3energy = 8.749447292452313<A u 3 , A u 3 >_{-1}^0.5 = 2.325366945767692e-06
Newton iteration 4energy = 8.749447292449608<A u 4 , A u 4 >_{-1}^0.5 = 6.327856348315956e-10
Newton iteration 5energy = 8.749447292449604<A u 5 , A u 5 >_{-1}^0.5 = 1.4200644716863594e-15
loadstep 2
Newton iteration 0energy = 8.748898153886168<A u 0 , A u 0 >_{-1}^0.5 = 0.01635690011274786
Newton iteration 1energy = 8.749005269170539<A u 1 , A u 1 >_{-1}^0.5 = 0.02189266920476809
Newton iteration 2energy = 8.74876626740532<A u 2 , A u 2 >_{-1}^0.5 = 0.00020821715292313156
Newton iteration 3energy = 8.748766246051042<A u 3 , A u 3 >_{-1}^0.5 = 4.890669998698441e-06
Newton iteration 4energy = 8.748766246039082<A u 4 , A u 4 >_{-1}^0.5 = 2.6649769810725263e-09
Newton iteration 5energy = 8.748766246039079<A u 5 , A u 5 >_{-1}^0.5 = 2.4121219776343153e-15
loadstep 3
Newton iteration 0energy = 8.747955315897348<A u 0 , A u 0 >_{-1}^0.5 = 0.01598200195360293
Newton iteration 1energy = 8.748035442976246<A u 1 , A u 1 >_{-1}^0.5 = 0.02029221463481165
Newton iteration 2energy = 8.747830061346368<A u 2 , A u 2 >_{-1}^0.5 = 0.00026380016828774974
Newton iteration 3energy = 8.747830027042681<A u 3 , A u 3 >_{-1}^0.5 = 7.247074890834472e-06
Newton iteration 4energy = 8.747830027016413<A u 4 , A u 4 >_{-1}^0.5 = 4.743816241850526e-09
Newton iteration 5energy = 8.74783002701641<A u 5 , A u 5 >_{-1}^0.5 = 3.2976390382757475e-15
loadstep 4
Newton iteration 0energy = 8.746771046575285<A u 0 , A u 0 >_{-1}^0.5 = 0.01550100486749778
Newton iteration 1energy = 8.746821890459293<A u 1 , A u 1 >_{-1}^0.5 = 0.01835976359544054
Newton iteration 2energy = 8.7466537161557<A u 2 , A u 2 >_{-1}^0.5 = 0.00029905972517893455
Newton iteration 3energy = 8.746653671963946<A u 3 , A u 3 >_{-1}^0.5 = 8.720145357915462e-06
Newton iteration 4energy = 8.746653671925925<A u 4 , A u 4 >_{-1}^0.5 = 5.242759661034286e-09
Newton iteration 5energy = 8.746653671925923<A u 5 , A u 5 >_{-1}^0.5 = 4.4234832673102565e-15
loadstep 5
Newton iteration 0energy = 8.745362760787959<A u 0 , A u 0 >_{-1}^0.5 = 0.014946177234015291
Newton iteration 1energy = 8.745386511566494<A u 1 , A u 1 >_{-1}^0.5 = 0.01629286911330159
Newton iteration 2energy = 8.74525402944412<A u 2 , A u 2 >_{-1}^0.5 = 0.0003132011086276393
Newton iteration 3energy = 8.745253980844623<A u 3 , A u 3 >_{-1}^0.5 = 9.042728017413643e-06
Newton iteration 4energy = 8.745253980803733<A u 4 , A u 4 >_{-1}^0.5 = 4.216858315628299e-09
Newton iteration 5energy = 8.74525398080373<A u 5 , A u 5 >_{-1}^0.5 = 4.502929767556461e-15
loadstep 6
Newton iteration 0energy = 8.743748434181928<A u 0 , A u 0 >_{-1}^0.5 = 0.01434766397018871
Newton iteration 1energy = 8.743749824856769<A u 1 , A u 1 >_{-1}^0.5 = 0.0142489981325165
Newton iteration 2energy = 8.743648463213832<A u 2 , A u 2 >_{-1}^0.5 = 0.00030934357221652607
Newton iteration 3energy = 8.743648415689139<A u 3 , A u 3 >_{-1}^0.5 = 8.384719007108451e-06
Newton iteration 4energy = 8.743648415653977<A u 4 , A u 4 >_{-1}^0.5 = 2.6938790302881672e-09
Newton iteration 5energy = 8.74364841565398<A u 5 , A u 5 >_{-1}^0.5 = 3.885387925228453e-15
loadstep 7
Newton iteration 0energy = 8.741945720887195<A u 0 , A u 0 >_{-1}^0.5 = 0.013730677148116635
Newton iteration 1energy = 8.74193026145664<A u 1 , A u 1 >_{-1}^0.5 = 0.012333488773395495
Newton iteration 2energy = 8.74185429522767<A u 2 , A u 2 >_{-1}^0.5 = 0.00029212968575759727
Newton iteration 3energy = 8.741854252760945<A u 3 , A u 3 >_{-1}^0.5 = 7.129921987516718e-06
Newton iteration 4energy = 8.74185425273552<A u 4 , A u 4 >_{-1}^0.5 = 1.4434146852429946e-09
Newton iteration 5energy = 8.741854252735525<A u 5 , A u 5 >_{-1}^0.5 = 4.212799981116738e-15
loadstep 8
Newton iteration 0energy = 8.739971379346319<A u 0 , A u 0 >_{-1}^0.5 = 0.013114532465453918
Newton iteration 1energy = 8.739944212541436<A u 1 , A u 1 >_{-1}^0.5 = 0.010603947203790643
Newton iteration 2energy = 8.739888039894067<A u 2 , A u 2 >_{-1}^0.5 = 0.00026631896112284394
Newton iteration 3energy = 8.739888004546401<A u 3 , A u 3 >_{-1}^0.5 = 5.662691349667639e-06
Newton iteration 4energy = 8.739888004530366<A u 4 , A u 4 >_{-1}^0.5 = 6.719890520409138e-10
Newton iteration 5energy = 8.739888004530366<A u 5 , A u 5 >_{-1}^0.5 = 4.639319790442195e-15
loadstep 9
Newton iteration 0energy = 8.737840951524664<A u 0 , A u 0 >_{-1}^0.5 = 0.012512932002872682
Newton iteration 1energy = 8.737806321577136<A u 1 , A u 1 >_{-1}^0.5 = 0.009082034906871006
Newton iteration 2energy = 8.737765103079186<A u 2 , A u 2 >_{-1}^0.5 = 0.00023604102686678355
Newton iteration 3energy = 8.73776507528117<A u 3 , A u 3 >_{-1}^0.5 = 4.2584765420460276e-06
Newton iteration 4energy = 8.737765075272103<A u 4 , A u 4 >_{-1}^0.5 = 2.778737893892191e-10
Newton iteration 5energy = 8.737765075272101<A u 5 , A u 5 >_{-1}^0.5 = 6.084004788914466e-15
loadstep 10
Newton iteration 0energy = 8.735568625274242<A u 0 , A u 0 >_{-1}^0.5 = 0.011934863848938077
Newton iteration 1energy = 8.735529762928419<A u 1 , A u 1 >_{-1}^0.5 = 0.007766045926871915
Newton iteration 2energy = 8.735499615194952<A u 2 , A u 2 >_{-1}^0.5 = 0.00020449883699834713
Newton iteration 3energy = 8.73549959431349<A u 3 , A u 3 >_{-1}^0.5 = 3.0648855731627656e-06
Newton iteration 4energy = 8.735499594308791<A u 4 , A u 4 >_{-1}^0.5 = 1.0316754947098017e-10
Newton iteration 5energy = 8.735499594308797<A u 5 , A u 5 >_{-1}^0.5 = 7.251366075296926e-15
loadstep 11
Newton iteration 0energy = 8.73316721685034<A u 0 , A u 0 >_{-1}^0.5 = 0.011385670031564708
Newton iteration 1energy = 8.733126439934429<A u 1 , A u 1 >_{-1}^0.5 = 0.006641121982808617
Newton iteration 2energy = 8.733104387451332<A u 2 , A u 2 >_{-1}^0.5 = 0.0001739423552907702
Newton iteration 3energy = 8.733104372335806<A u 3 , A u 3 >_{-1}^0.5 = 2.1293553627905727e-06
Newton iteration 4energy = 8.733104372333534<A u 4 , A u 4 >_{-1}^0.5 = 3.432407508902105e-11
Newton iteration 5energy = 8.733104372333534<A u 5 , A u 5 >_{-1}^0.5 = 7.175239012593754e-15
loadstep 12
Newton iteration 0energy = 8.730648225487055<A u 0 , A u 0 >_{-1}^0.5 = 0.010868036985673566
Newton iteration 1energy = 8.730607117621929<A u 1 , A u 1 >_{-1}^0.5 = 0.005686365652188052
Newton iteration 2energy = 8.730590946021202<A u 2 , A u 2 >_{-1}^0.5 = 0.00014578250762003835
Newton iteration 3energy = 8.730590935399865<A u 3 , A u 3 >_{-1}^0.5 = 1.4383952180557336e-06
Newton iteration 4energy = 8.730590935398832<A u 4 , A u 4 >_{-1}^0.5 = 9.987521038773152e-12
Newton iteration 5energy = 8.730590935398832<A u 5 , A u 5 >_{-1}^0.5 = 7.228923974524719e-15
loadstep 13
Newton iteration 0energy = 8.728021926670921<A u 0 , A u 0 >_{-1}^0.5 = 0.01038280967508487
Newton iteration 1energy = 8.727981520177936<A u 1 , A u 1 >_{-1}^0.5 = 0.004879262215338342
Newton iteration 2energy = 8.72796961082598<A u 2 , A u 2 >_{-1}^0.5 = 0.00012076268875799493
Newton iteration 3energy = 8.727969603535861<A u 3 , A u 3 >_{-1}^0.5 = 9.505274351321292e-07
Newton iteration 4energy = 8.727969603535408<A u 4 , A u 4 >_{-1}^0.5 = 2.3275315780694176e-12
Newton iteration 5energy = 8.727969603535408<A u 5 , A u 5 >_{-1}^0.5 = 8.091082743445322e-15
loadstep 14
Newton iteration 0energy = 8.725297482482327<A u 0 , A u 0 >_{-1}^0.5 = 0.009929613985836517
Newton iteration 1energy = 8.725258414423633<A u 1 , A u 1 >_{-1}^0.5 = 0.004198147878872032
Newton iteration 2energy = 8.725249596259614<A u 2 , A u 2 >_{-1}^0.5 = 9.913907186673651e-05
Newton iteration 3energy = 8.72524959134576<A u 3 , A u 3 >_{-1}^0.5 = 6.177285840505399e-07
Newton iteration 4energy = 8.725249591345566<A u 4 , A u 4 >_{-1}^0.5 = 2.7064442087840637e-13
Newton iteration 5energy = 8.725249591345568<A u 5 , A u 5 >_{-1}^0.5 = 7.039763365519451e-15
loadstep 15
Newton iteration 0energy = 8.722483055768391<A u 0 , A u 0 >_{-1}^0.5 = 0.00950730994432693
Newton iteration 1energy = 8.722445689352115<A u 1 , A u 1 >_{-1}^0.5 = 0.0036234069470111496
Newton iteration 2energy = 8.722439119342239<A u 2 , A u 2 >_{-1}^0.5 = 8.084284444428935e-05
Newton iteration 3energy = 8.722439116074447<A u 3 , A u 3 >_{-1}^0.5 = 3.9659768845062976e-07
Newton iteration 4energy = 8.722439116074371<A u 4 , A u 4 >_{-1}^0.5 = 1.5327669347269986e-13
Newton iteration 5energy = 8.722439116074371<A u 5 , A u 5 >_{-1}^0.5 = 8.749454563219614e-15
loadstep 16
Newton iteration 0energy = 8.71958592054387<A u 0 , A u 0 >_{-1}^0.5 = 0.009114310087721926
Newton iteration 1energy = 8.71955043455605<A u 1 , A u 1 >_{-1}^0.5 = 0.003137908675334741
Newton iteration 2energy = 8.71954550658672<A u 2 , A u 2 >_{-1}^0.5 = 6.561173660398201e-05
Newton iteration 3energy = 8.71954550443416<A u 3 , A u 3 >_{-1}^0.5 = 2.525281703494368e-07
Newton iteration 4energy = 8.719545504434125<A u 4 , A u 4 >_{-1}^0.5 = 1.5047577657253087e-13
Newton iteration 5energy = 8.719545504434128<A u 5 , A u 5 >_{-1}^0.5 = 7.69643945153925e-15
loadstep 17
Newton iteration 0energy = 8.716612564628694<A u 0 , A u 0 >_{-1}^0.5 = 0.008748796565362569
Newton iteration 1energy = 8.716579017012805<A u 1 , A u 1 >_{-1}^0.5 = 0.0027270250054163363
Newton iteration 2energy = 8.716575294736641<A u 2 , A u 2 >_{-1}^0.5 = 5.308768781169104e-05
Newton iteration 3energy = 8.716575293327384<A u 3 , A u 3 >_{-1}^0.5 = 1.599940910665626e-07
Newton iteration 4energy = 8.716575293327372<A u 4 , A u 4 >_{-1}^0.5 = 9.257307385714292e-14
loadstep 18
Newton iteration 0energy = 8.713568782760653<A u 0 , A u 0 >_{-1}^0.5 = 0.008408865067911477
Newton iteration 1energy = 8.71353715470618<A u 1 , A u 1 >_{-1}^0.5 = 0.0023784404030578847
Newton iteration 2energy = 8.713534323011551<A u 2 , A u 2 >_{-1}^0.5 = 4.28834130840399e-05
Newton iteration 3energy = 8.713534322091974<A u 3 , A u 3 >_{-1}^0.5 = 1.0113990846643994e-07
Newton iteration 4energy = 8.713534322091967<A u 4 , A u 4 >_{-1}^0.5 = 4.926071629375478e-14
loadstep 19
Newton iteration 0energy = 8.710459759743205<A u 0 , A u 0 >_{-1}^0.5 = 0.00809261730082369
Newton iteration 1energy = 8.710429985680893<A u 1 , A u 1 >_{-1}^0.5 = 0.0020818766762752496
Newton iteration 2energy = 8.710427816012484<A u 2 , A u 2 >_{-1}^0.5 = 3.462363091161543e-05
Newton iteration 3energy = 8.710427815413038<A u 3 , A u 3 >_{-1}^0.5 = 6.393558553233767e-08
Newton iteration 4energy = 8.710427815413027<A u 4 , A u 4 >_{-1}^0.5 = 2.4879638160199976e-14
loadstep 20
Newton iteration 0energy = 8.707290143932667<A u 0 , A u 0 >_{-1}^0.5 = 0.007798218017934863
Newton iteration 1energy = 8.70726213160839<A u 1 , A u 1 >_{-1}^0.5 = 0.001828799855419964
Newton iteration 2energy = 8.70726045732614<A u 2 , A u 2 >_{-1}^0.5 = 2.7967520760142384e-05
Newton iteration 3energy = 8.707260456935016<A u 3 , A u 3 >_{-1}^0.5 = 4.0490516443410736e-08
Newton iteration 4energy = 8.707260456935014<A u 4 , A u 4 >_{-1}^0.5 = 1.3624832079831199e-14
loadstep 21
Newton iteration 0energy = 8.704064111753777<A u 0 , A u 0 >_{-1}^0.5 = 0.007523928078133754
Newton iteration 1energy = 8.704037755443867<A u 1 , A u 1 >_{-1}^0.5 = 0.0016121428291902722
Newton iteration 2energy = 8.704036454348385<A u 2 , A u 2 >_{-1}^0.5 = 2.2618413223441524e-05
Newton iteration 3energy = 8.70403645409257<A u 3 , A u 3 >_{-1}^0.5 = 2.572652086165343e-08
Newton iteration 4energy = 8.704036454092574<A u 4 , A u 4 >_{-1}^0.5 = 9.584809802207142e-15
loadstep 22
Newton iteration 0energy = 8.700785424101992<A u 0 , A u 0 >_{-1}^0.5 = 0.0072681215623135445
Newton iteration 1energy = 8.700760613149294<A u 1 , A u 1 >_{-1}^0.5 = 0.0014260583670406878
Newton iteration 2energy = 8.700759595081369<A u 2 , A u 2 >_{-1}^0.5 = 1.832551672999741e-05
Newton iteration 3energy = 8.700759594913444<A u 3 , A u 3 >_{-1}^0.5 = 1.64177682347151e-08
Newton iteration 4energy = 8.700759594913444<A u 4 , A u 4 >_{-1}^0.5 = 9.272149202115917e-15
loadstep 23
Newton iteration 0energy = 8.697457475532337<A u 0 , A u 0 >_{-1}^0.5 = 0.007029292502556886
Newton iteration 1energy = 8.697434099723003<A u 1 , A u 1 >_{-1}^0.5 = 0.0012657068145356869
Newton iteration 2energy = 8.697433297742606<A u 2 , A u 2 >_{-1}^0.5 = 1.488116749501069e-05
Newton iteration 3energy = 8.69743329763187<A u 3 , A u 3 >_{-1}^0.5 = 1.0532345383181586e-08
Newton iteration 4energy = 8.69743329763187<A u 4 , A u 4 >_{-1}^0.5 = 9.269312894754061e-15
loadstep 24
Newton iteration 0energy = 8.69408333710687<A u 0 , A u 0 >_{-1}^0.5 = 0.006806055012487304
Newton iteration 1energy = 8.694061289934714<A u 1 , A u 1 >_{-1}^0.5 = 0.001127077505286072
Newton iteration 2energy = 8.694060654023025<A u 2 , A u 2 >_{-1}^0.5 = 1.2115934414408505e-05
Newton iteration 3energy = 8.694060653949627<A u 3 , A u 3 >_{-1}^0.5 = 6.796593518161176e-09
Newton iteration 4energy = 8.694060653949627<A u 4 , A u 4 >_{-1}^0.5 = 8.361548244675059e-15
loadstep 25
Newton iteration 0energy = 8.690665793708689<A u 0 , A u 0 >_{-1}^0.5 = 0.00659713937725044
Newton iteration 1energy = 8.690644974240751<A u 1 , A u 1 >_{-1}^0.5 = 0.0010068405688217928
Newton iteration 2energy = 8.69064446678336<A u 2 , A u 2 >_{-1}^0.5 = 9.893021078410993e-06
Newton iteration 3energy = 8.690644466734426<A u 3 , A u 3 >_{-1}^0.5 = 4.413793704506755e-09
Newton iteration 4energy = 8.690644466734424<A u 4 , A u 4 >_{-1}^0.5 = 8.68752180898373e-15
loadstep 26
Newton iteration 0energy = 8.687207376550258<A u 0 , A u 0 >_{-1}^0.5 = 0.00640138581037434
Newton iteration 1energy = 8.68718769037758<A u 1 , A u 1 >_{-1}^0.5 = 0.0009022250045403993
Newton iteration 2energy = 8.687187282908429<A u 2 , A u 2 >_{-1}^0.5 = 8.102781439964035e-06
Newton iteration 3energy = 8.687187282875598<A u 3 , A u 3 >_{-1}^0.5 = 2.885520711688929e-09
Newton iteration 4energy = 8.6871872828756<A u 4 , A u 4 >_{-1}^0.5 = 9.289056186481608e-15
loadstep 27
Newton iteration 0energy = 8.683710391520691<A u 0 , A u 0 >_{-1}^0.5 = 0.006217737003635578
Newton iteration 1energy = 8.683691751120312<A u 1 , A u 1 >_{-1}^0.5 = 0.0008109188807146133
Newton iteration 2energy = 8.68369142196174<A u 2 , A u 2 >_{-1}^0.5 = 6.657757673212781e-06
Newton iteration 3energy = 8.683691421939578<A u 3 , A u 3 >_{-1}^0.5 = 1.8993898939454726e-09
Newton iteration 4energy = 8.68369142193958<A u 4 , A u 4 >_{-1}^0.5 = 1.0341655676334443e-14
loadstep 28
Newton iteration 0energy = 8.6801769439361<A u 0 , A u 0 >_{-1}^0.5 = 0.006045230198923513
Newton iteration 1energy = 8.680159268662702<A u 1 , A u 1 >_{-1}^0.5 = 0.0007309878719703942
Newton iteration 2energy = 8.680159001205098<A u 2 , A u 2 >_{-1}^0.5 = 5.4883997984215e-06
Newton iteration 3energy = 8.680159001190033<A u 3 , A u 3 >_{-1}^0.5 = 1.2590109331567081e-09
Newton iteration 4energy = 8.680159001190033<A u 4 , A u 4 >_{-1}^0.5 = 9.870842441466451e-15
loadstep 29
Newton iteration 0energy = 8.67660896018235<A u 0 , A u 0 >_{-1}^0.5 = 0.005882989243204439
Newton iteration 1energy = 8.676592176035282<A u 1 , A u 1 >_{-1}^0.5 = 0.0006608088422125518
Newton iteration 2energy = 8.676591957475672<A u 2 , A u 2 >_{-1}^0.5 = 4.539486119083961e-06
Newton iteration 3energy = 8.676591957465368<A u 3 , A u 3 >_{-1}^0.5 = 8.404009354000662e-10
Newton iteration 4energy = 8.676591957465366<A u 4 , A u 4 >_{-1}^0.5 = 9.107776531285389e-15
loadstep 30
Newton iteration 0energy = 8.673008206673307<A u 0 , A u 0 >_{-1}^0.5 = 0.005730216908352001
Newton iteration 1energy = 8.672992245935037<A u 1 , A u 1 >_{-1}^0.5 = 0.0005990156934619057
Newton iteration 2energy = 8.672992066346827<A u 2 , A u 2 >_{-1}^0.5 = 3.7671919868901872e-06
Newton iteration 3energy = 8.672992066339727<A u 3 , A u 3 >_{-1}^0.5 = 5.649080735658275e-10
Newton iteration 4energy = 8.672992066339726<A u 4 , A u 4 >_{-1}^0.5 = 1.0170090078921372e-14
loadstep 31
Newton iteration 0energy = 8.66937630648851<A u 0 , A u 0 >_{-1}^0.5 = 0.005586187637919248
Newton iteration 1energy = 8.669361107297396<A u 1 , A u 1 >_{-1}^0.5 = 0.0005444551771491348
Newton iteration 2energy = 8.669360958940151<A u 2 , A u 2 >_{-1}^0.5 = 3.1367240229685416e-06
Newton iteration 3energy = 8.669360958935233<A u 3 , A u 3 >_{-1}^0.5 = 3.8236360565374487e-10
Newton iteration 4energy = 8.669360958935235<A u 4 , A u 4 >_{-1}^0.5 = 9.069817966257758e-15
loadstep 32
Newton iteration 0energy = 8.665714754002668<A u 0 , A u 0 >_{-1}^0.5 = 0.005450240804228049
Newton iteration 1energy = 8.665700259900662<A u 1 , A u 1 >_{-1}^0.5 = 0.000496150781569729
Newton iteration 2energy = 8.665700136705132<A u 2 , A u 2 >_{-1}^0.5 = 2.6204297764800423e-06
Newton iteration 3energy = 8.665700136701695<A u 3 , A u 3 >_{-1}^0.5 = 2.605824517141975e-10
Newton iteration 4energy = 8.665700136701702<A u 4 , A u 4 >_{-1}^0.5 = 1.0508691072605487e-14
loadstep 33
Newton iteration 0energy = 8.662024927775535<A u 0 , A u 0 >_{-1}^0.5 = 0.005321774508239707
Newton iteration 1energy = 8.662011087256225<A u 1 , A u 1 >_{-1}^0.5 = 0.0004532731624139322
Newton iteration 2energy = 8.662010984437815<A u 2 , A u 2 >_{-1}^0.5 = 2.196297576340765e-06
Newton iteration 3energy = 8.662010984435405<A u 3 , A u 3 >_{-1}^0.5 = 1.7878607118819876e-10
Newton iteration 4energy = 8.662010984435403<A u 4 , A u 4 >_{-1}^0.5 = 1.1090322042536688e-14
loadstep 34
Newton iteration 0energy = 8.658308101932276<A u 0 , A u 0 >_{-1}^0.5 = 0.0052002399229364536
Newton iteration 1energy = 8.658294868004674<A u 1 , A u 1 >_{-1}^0.5 = 0.000415115876629683
Newton iteration 2energy = 8.658294781771751<A u 2 , A u 2 >_{-1}^0.5 = 1.846771417004263e-06
Newton iteration 3energy = 8.658294781770055<A u 3 , A u 3 >_{-1}^0.5 = 1.2347765368611494e-10
Newton iteration 4energy = 8.65829478177005<A u 4 , A u 4 >_{-1}^0.5 = 9.905245145538903e-15
loadstep 35
Newton iteration 0energy = 8.654565456231769<A u 0 , A u 0 >_{-1}^0.5 = 0.005085136160852866
Newton iteration 1energy = 8.654552786008827<A u 1 , A u 1 >_{-1}^0.5 = 0.00038107541887198184
Newton iteration 2energy = 8.654552713341332<A u 2 , A u 2 >_{-1}^0.5 = 1.5578172811942347e-06
Newton iteration 3energy = 8.65455271334012<A u 3 , A u 3 >_{-1}^0.5 = 8.583007354544487e-11
Newton iteration 4energy = 8.65455271334012<A u 4 , A u 4 >_{-1}^0.5 = 1.1498428062270151e-14
loadstep 36
Newton iteration 0energy = 8.650798084992662<A u 0 , A u 0 >_{-1}^0.5 = 0.004976005635625811
Newton iteration 1energy = 8.65078593930888<A u 1 , A u 1 >_{-1}^0.5 = 0.0003506347544669226
Newton iteration 2energy = 8.650785877789419<A u 2 , A u 2 >_{-1}^0.5 = 1.3181886279993772e-06
Newton iteration 3energy = 8.650785877788538<A u 3 , A u 3 >_{-1}^0.5 = 6.003894815486798e-11
Newton iteration 4energy = 8.650785877788543<A u 4 , A u 4 >_{-1}^0.5 = 1.0237989625591944e-14
loadstep 37
Newton iteration 0energy = 8.64700700502299<A u 0 , A u 0 >_{-1}^0.5 = 0.00487242988150087
Newton iteration 1energy = 8.646995348082879<A u 1 , A u 1 >_{-1}^0.5 = 0.0003233496992474283
Newton iteration 2energy = 8.646995295767141<A u 2 , A u 2 >_{-1}^0.5 = 1.1188488008725282e-06
Newton iteration 3energy = 8.646995295766514<A u 3 , A u 3 >_{-1}^0.5 = 4.225612013086363e-11
Newton iteration 4energy = 8.646995295766512<A u 4 , A u 4 >_{-1}^0.5 = 1.0641741658707828e-14
loadstep 38
Newton iteration 0energy = 8.643193162678875<A u 0 , A u 0 >_{-1}^0.5 = 0.004774025792534549
Newton iteration 1energy = 8.643181961736246<A u 1 , A u 1 >_{-1}^0.5 = 0.0002988376223750298
Newton iteration 2energy = 8.643181917053138<A u 2 , A u 2 >_{-1}^0.5 = 9.525166660833815e-07
Newton iteration 3energy = 8.643181917052686<A u 3 , A u 3 >_{-1}^0.5 = 2.9919182871097316e-11
Newton iteration 4energy = 8.643181917052694<A u 4 , A u 4 >_{-1}^0.5 = 1.057701126049018e-14
loadstep 39
Newton iteration 0energy = 8.639357440160742<A u 0 , A u 0 >_{-1}^0.5 = 0.004680442243450855
Newton iteration 1energy = 8.639346665227572<A u 1 , A u 1 >_{-1}^0.5 = 0.00027676804941248874
Newton iteration 2energy = 8.63934662690184<A u 2 , A u 2 >_{-1}^0.5 = 8.133088491499809e-07
Newton iteration 3energy = 8.63934662690151<A u 3 , A u 3 >_{-1}^0.5 = 2.1308585924940255e-11
Newton iteration 4energy = 8.63934662690151<A u 4 , A u 4 >_{-1}^0.5 = 1.0072078019415288e-14
loadstep 40
Newton iteration 0energy = 8.635500661140359<A u 0 , A u 0 >_{-1}^0.5 = 0.0045913570554424335
Newton iteration 1energy = 8.635490284723662<A u 1 , A u 1 >_{-1}^0.5 = 0.0002568548236894908
Newton iteration 2energy = 8.635490251715577<A u 2 , A u 2 >_{-1}^0.5 = 6.964576271150893e-07
Newton iteration 3energy = 8.635490251715337<A u 3 , A u 3 >_{-1}^0.5 = 1.5263381653471166e-11
Newton iteration 4energy = 8.63549025171533<A u 4 , A u 4 >_{-1}^0.5 = 1.1118113462466933e-14
loadstep 41
Newton iteration 0energy = 8.631623595799713<A u 0 , A u 0 >_{-1}^0.5 = 0.004506474272414941
Newton iteration 1energy = 8.631613592664195<A u 1 , A u 1 >_{-1}^0.5 = 0.0002388495489431832
Newton iteration 2energy = 8.631613564122443<A u 2 , A u 2 >_{-1}^0.5 = 5.98088077047208e-07
Newton iteration 3energy = 8.63161356412226<A u 3 , A u 3 >_{-1}^0.5 = 1.0992638864224494e-11
Newton iteration 4energy = 8.631613564122262<A u 4 , A u 4 >_{-1}^0.5 = 1.1575262258178401e-14
loadstep 42
Newton iteration 0energy = 8.627726965351709<A u 0 , A u 0 >_{-1}^0.5 = 0.004425521715870817
Newton iteration 1energy = 8.627717312306176<A u 1 , A u 1 >_{-1}^0.5 = 0.00022253608839447063
Newton iteration 2energy = 8.627717287530809<A u 2 , A u 2 >_{-1}^0.5 = 5.150416690354255e-07
Newton iteration 3energy = 8.627717287530674<A u 3 , A u 3 >_{-1}^0.5 = 7.961343649015863e-12
Newton iteration 4energy = 8.627717287530674<A u 4 , A u 4 >_{-1}^0.5 = 1.0293713738072014e-14
loadstep 43
Newton iteration 0energy = 8.62381144610366<A u 0 , A u 0 >_{-1}^0.5 = 0.004348248789230984
Newton iteration 1energy = 8.62380212180896<A u 1 , A u 1 >_{-1}^0.5 = 0.00020772593709563107
Newton iteration 2energy = 8.623802100222138<A u 2 , A u 2 >_{-1}^0.5 = 4.447363111688981e-07
Newton iteration 3energy = 8.623802100222044<A u 3 , A u 3 >_{-1}^0.5 = 5.795166405124738e-12
Newton iteration 4energy = 8.623802100222036<A u 4 , A u 4 >_{-1}^0.5 = 9.156937205801422e-15
loadstep 44
Newton iteration 0energy = 8.619877673116353<A u 0 , A u 0 >_{-1}^0.5 = 0.004274424505284864
Newton iteration 1energy = 8.619868657912763<A u 1 , A u 1 >_{-1}^0.5 = 0.00019425431834169314
Newton iteration 2energy = 8.619868639035584<A u 2 , A u 2 >_{-1}^0.5 = 3.8505503549006835e-07
Newton iteration 3energy = 8.619868639035513<A u 3 , A u 3 >_{-1}^0.5 = 4.239835432283946e-12
Newton iteration 4energy = 8.619868639035507<A u 4 , A u 4 >_{-1}^0.5 = 1.0977708183956882e-14
loadstep 45
Newton iteration 0energy = 8.61592624350484<A u 0 , A u 0 >_{-1}^0.5 = 0.004203835712874156
Newton iteration 1energy = 8.615917519257062<A u 1 , A u 1 >_{-1}^0.5 = 0.00018197688183221064
Newton iteration 2energy = 8.615917502691081<A u 2 , A u 2 >_{-1}^0.5 = 3.342572377911151e-07
Newton iteration 3energy = 8.615917502691026<A u 3 , A u 3 >_{-1}^0.5 = 3.117683017534833e-12
Newton iteration 4energy = 8.615917502691024<A u 4 , A u 4 >_{-1}^0.5 = 1.0445614983271109e-14
loadstep 46
Newton iteration 0energy = 8.61195771942136<A u 0 , A u 0 >_{-1}^0.5 = 0.00413628550164784
Newton iteration 1energy = 8.61194926937919<A u 1 , A u 1 >_{-1}^0.5 = 0.00017076690359188354
Newton iteration 2energy = 8.611949254791671<A u 2 , A u 2 >_{-1}^0.5 = 2.909077261071896e-07
Newton iteration 3energy = 8.611949254791623<A u 3 , A u 3 >_{-1}^0.5 = 2.3044734483966842e-12
Newton iteration 4energy = 8.611949254791623<A u 4 , A u 4 >_{-1}^0.5 = 9.535074179732207e-15
loadstep 47
Newton iteration 0energy = 8.607972630755366<A u 0 , A u 0 >_{-1}^0.5 = 0.004071591765631377
Newton iteration 1energy = 8.60796443942848<A u 1 , A u 1 >_{-1}^0.5 = 0.00016051290507746116
Newton iteration 2energy = 8.60796442654053<A u 2 , A u 2 >_{-1}^0.5 = 2.5381983240604357e-07
Newton iteration 3energy = 8.6079644265405<A u 3 , A u 3 >_{-1}^0.5 = 1.7110215397617725e-12
Newton iteration 4energy = 8.607964426540496<A u 4 , A u 4 >_{-1}^0.5 = 1.110369757740896e-14
loadstep 48
Newton iteration 0energy = 8.603971477581695<A u 0 , A u 0 >_{-1}^0.5 = 0.004009585908797429
Newton iteration 1energy = 8.603963530627095<A u 1 , A u 1 >_{-1}^0.5 = 0.0001511166237584682
Newton iteration 2energy = 8.603963519204118<A u 2 , A u 2 >_{-1}^0.5 = 2.2200969878333655e-07
Newton iteration 3energy = 8.603963519204095<A u 3 , A u 3 >_{-1}^0.5 = 1.2765230673701953e-12
Newton iteration 4energy = 8.6039635192041<A u 4 , A u 4 >_{-1}^0.5 = 1.1820429074306949e-14
loadstep 49
Newton iteration 0energy = 8.599954732383944<A u 0 , A u 0 >_{-1}^0.5 = 0.00395011167734378
Newton iteration 1energy = 8.59994701650458<A u 1 , A u 1 >_{-1}^0.5 = 0.0001424912788860544
Newton iteration 2energy = 8.599947006348602<A u 2 , A u 2 >_{-1}^0.5 = 1.946594183388035e-07
Newton iteration 3energy = 8.599947006348579<A u 3 , A u 3 >_{-1}^0.5 = 9.575484135294828e-13
Newton iteration 4energy = 8.599947006348575<A u 4 , A u 4 >_{-1}^0.5 = 1.1038405417068228e-14
Allen-Cahn equation¶
The Allen-Cahn equations describe the process of phase separation and is the (\(L^2\)) gradient-flow equation to the energy
i.e. the solution to the Allen-Cahn equation solves
The quantity \(u\) is an indicator for a phase where \(-1\) refers to one phase and \(1\) to another phase.
The equation has two driving forces:
\(u\) is pulled into one of the two minima (\(-1\) and \(1\)) of the nonlinear term \(u^2(1-u^2)\) (separation of the phases)
the diffusion term scaled with \(\varepsilon\) enforces a smooth transition between the two phases. \(\varepsilon\) determines the size of the transition layer
We use the “SymbolicEnergy” feature to formulate the energy minimization problem and combine it with an implicit Euler discretization:
which we can interpreted as a nonlinear minimization problem again with the energy
To solve the nonlinear equation at every time step we again rely on Newton’s method.
[11]:
from ngsolve import *
from netgen.geom2d import *
periodic = SplineGeometry()
pnts = [ (0,0), (1,0), (1,1), (0,1) ]
pnums = [periodic.AppendPoint(*p) for p in pnts]
lright = periodic.Append ( ["line", pnums[0], pnums[1]],bc="periodic")
btop = periodic.Append ( ["line", pnums[1], pnums[2]], bc="periodic")
periodic.Append ( ["line", pnums[3], pnums[2]], leftdomain=0, rightdomain=1, copy=lright, bc="periodic")
periodic.Append ( ["line", pnums[0], pnums[3]], leftdomain=0, rightdomain=1, copy=btop, bc="periodic")
mesh = Mesh (periodic.GenerateMesh(maxh=0.2))
V = Periodic(H1(mesh, order=4, dirichlet=[]))
u = V.TrialFunction()
eps = 4e-3
dt = 1e-1
gfu = GridFunction(V)
gfuold = GridFunction(V)
a = BilinearForm (V, symmetric=False)
a += Variation( (eps/2*grad(u)*grad(u) + ((1-u*u)*(1-u*u))
+ 0.5/dt*(u-gfuold)*(u-gfuold)) * dx)
[12]:
from math import pi
gfu = GridFunction(V)
gfu.Set(sin(2*pi*x))
#gfu.Set(sin(1e8*x)) #<- essentially a random function
Draw(gfu,mesh,"u")
SetVisualization (deformation=True)
t = 0
[13]:
for timestep in range(50):
gfuold.vec.data = gfu.vec
SolveNonlinearMinProblem(a,gfu)
Redraw()
t += dt
print("t = ", t)
Newton iteration 0energy = 0.41450274940004017<A u 0 , A u 0 >_{-1}^0.5 = 0.28092276820769385
Newton iteration 1energy = 0.37690042628264986<A u 1 , A u 1 >_{-1}^0.5 = 0.019175684672928434
Newton iteration 2energy = 0.3767159640889083<A u 2 , A u 2 >_{-1}^0.5 = 9.62988096864071e-05
Newton iteration 3energy = 0.3767159594520977<A u 3 , A u 3 >_{-1}^0.5 = 2.5081413874453625e-09
Newton iteration 4energy = 0.37671595945209774<A u 4 , A u 4 >_{-1}^0.5 = 2.770950400879142e-16
t = 0.1
Newton iteration 0energy = 0.3438887218899856<A u 0 , A u 0 >_{-1}^0.5 = 0.2359984304769602
Newton iteration 1energy = 0.3171274464604802<A u 1 , A u 1 >_{-1}^0.5 = 0.013451013644986742
Newton iteration 2energy = 0.3170367744533889<A u 2 , A u 2 >_{-1}^0.5 = 4.663240800351902e-05
Newton iteration 3energy = 0.31703677336608915<A u 3 , A u 3 >_{-1}^0.5 = 5.769081036770765e-10
Newton iteration 4energy = 0.3170367733660891<A u 4 , A u 4 >_{-1}^0.5 = 3.104600909251941e-16
t = 0.2
Newton iteration 0energy = 0.2955287970166734<A u 0 , A u 0 >_{-1}^0.5 = 0.18333961760859702
Newton iteration 1energy = 0.27922061920053365<A u 1 , A u 1 >_{-1}^0.5 = 0.008020159823637686
Newton iteration 2energy = 0.2791884145175679<A u 2 , A u 2 >_{-1}^0.5 = 1.6280453338856004e-05
Newton iteration 3energy = 0.27918841438504094<A u 3 , A u 3 >_{-1}^0.5 = 6.88277206865018e-11
Newton iteration 4energy = 0.2791884143850408<A u 4 , A u 4 >_{-1}^0.5 = 3.5918508178786496e-16
t = 0.30000000000000004
Newton iteration 0energy = 0.2670098660513399<A u 0 , A u 0 >_{-1}^0.5 = 0.13329903037709695
Newton iteration 1energy = 0.25831307616871746<A u 1 , A u 1 >_{-1}^0.5 = 0.0041875315462804544
Newton iteration 2energy = 0.2583043023901654<A u 2 , A u 2 >_{-1}^0.5 = 4.3728797510974884e-06
Newton iteration 3energy = 0.2583043023806044<A u 3 , A u 3 >_{-1}^0.5 = 4.8743476603423805e-12
Newton iteration 4energy = 0.2583043023806044<A u 4 , A u 4 >_{-1}^0.5 = 3.5485559099999397e-16
t = 0.4
Newton iteration 0energy = 0.25217569665415823<A u 0 , A u 0 >_{-1}^0.5 = 0.09212757625004177
Newton iteration 1energy = 0.24799278266903632<A u 1 , A u 1 >_{-1}^0.5 = 0.0019803055518447786
Newton iteration 2energy = 0.2479908212283336<A u 2 , A u 2 >_{-1}^0.5 = 9.675293371219298e-07
Newton iteration 3energy = 0.24799082122786548<A u 3 , A u 3 >_{-1}^0.5 = 2.351718624444368e-13
Newton iteration 4energy = 0.2479908212278656<A u 4 , A u 4 >_{-1}^0.5 = 3.5285019118579734e-16
t = 0.5
Newton iteration 0energy = 0.24516469919769227<A u 0 , A u 0 >_{-1}^0.5 = 0.06142246901372681
Newton iteration 1energy = 0.24329614316799697<A u 1 , A u 1 >_{-1}^0.5 = 0.0008742001822322159
Newton iteration 2energy = 0.243295761000651<A u 2 , A u 2 >_{-1}^0.5 = 1.8736246218623535e-07
Newton iteration 3energy = 0.24329576100063338<A u 3 , A u 3 >_{-1}^0.5 = 8.837199141043262e-15
t = 0.6
Newton iteration 0energy = 0.24206890764107003<A u 0 , A u 0 >_{-1}^0.5 = 0.03998278353294713
Newton iteration 1energy = 0.24127447024481935<A u 1 , A u 1 >_{-1}^0.5 = 0.00036914563244039837
Newton iteration 2energy = 0.24127440210648102<A u 2 , A u 2 >_{-1}^0.5 = 3.3396140007954435e-08
Newton iteration 3energy = 0.24127440210648043<A u 3 , A u 3 >_{-1}^0.5 = 5.392904101207391e-16
t = 0.7
Newton iteration 0energy = 0.24076206680029597<A u 0 , A u 0 >_{-1}^0.5 = 0.02565432378296499
Newton iteration 1energy = 0.24043427961385436<A u 1 , A u 1 >_{-1}^0.5 = 0.0001521836948922547
Newton iteration 2energy = 0.2404342680336267<A u 2 , A u 2 >_{-1}^0.5 = 5.749334331966722e-09
Newton iteration 3energy = 0.24043426803362666<A u 3 , A u 3 >_{-1}^0.5 = 4.0723660057673715e-16
t = 0.7999999999999999
Newton iteration 0energy = 0.2402247958434406<A u 0 , A u 0 >_{-1}^0.5 = 0.016360129469374974
Newton iteration 1energy = 0.24009130447406016<A u 1 , A u 1 >_{-1}^0.5 = 6.260945027184524e-05
Newton iteration 2energy = 0.24009130251406763<A u 2 , A u 2 >_{-1}^0.5 = 1.0310386702794883e-09
Newton iteration 3energy = 0.2400913025140676<A u 3 , A u 3 >_{-1}^0.5 = 4.430990996815971e-16
t = 0.8999999999999999
Newton iteration 0energy = 0.2400060001527204<A u 0 , A u 0 >_{-1}^0.5 = 0.010467378997427187
Newton iteration 1energy = 0.23995130728175787<A u 1 , A u 1 >_{-1}^0.5 = 2.660330565795448e-05
Newton iteration 2energy = 0.23995130692788802<A u 2 , A u 2 >_{-1}^0.5 = 2.2781443109275827e-10
Newton iteration 3energy = 0.23995130692788808<A u 3 , A u 3 >_{-1}^0.5 = 4.520167645921635e-16
t = 0.9999999999999999
Newton iteration 0energy = 0.23991591345508823<A u 0 , A u 0 >_{-1}^0.5 = 0.006815543354962078
Newton iteration 1energy = 0.2398927141233959<A u 1 , A u 1 >_{-1}^0.5 = 1.2418172737585205e-05
Newton iteration 2energy = 0.23989271404629017<A u 2 , A u 2 >_{-1}^0.5 = 7.456015681141339e-11
Newton iteration 3energy = 0.23989271404629015<A u 3 , A u 3 >_{-1}^0.5 = 4.857526180759073e-16
t = 1.0999999999999999
Newton iteration 0energy = 0.23987719120231832<A u 0 , A u 0 >_{-1}^0.5 = 0.0046219617602749
Newton iteration 1energy = 0.2398665191876579<A u 1 , A u 1 >_{-1}^0.5 = 6.8803322449782575e-06
Newton iteration 2energy = 0.2398665191639883<A u 2 , A u 2 >_{-1}^0.5 = 3.373660269756489e-11
Newton iteration 3energy = 0.23986651916398838<A u 3 , A u 3 >_{-1}^0.5 = 4.51866572779697e-16
t = 1.2
Newton iteration 0energy = 0.239858912438348<A u 0 , A u 0 >_{-1}^0.5 = 0.0033643229589345896
Newton iteration 1energy = 0.23985325717204478<A u 1 , A u 1 >_{-1}^0.5 = 4.626816464814933e-06
Newton iteration 2energy = 0.239853257161341<A u 2 , A u 2 >_{-1}^0.5 = 1.83404666236353e-11
Newton iteration 3energy = 0.23985325716134107<A u 3 , A u 3 >_{-1}^0.5 = 4.4167890039517904e-16
t = 1.3
Newton iteration 0energy = 0.23984885075665663<A u 0 , A u 0 >_{-1}^0.5 = 0.002682345350752739
Newton iteration 1energy = 0.23984525547226224<A u 1 , A u 1 >_{-1}^0.5 = 3.580510801938737e-06
Newton iteration 2energy = 0.23984525546585217<A u 2 , A u 2 >_{-1}^0.5 = 1.122826298267855e-11
Newton iteration 3energy = 0.23984525546585217<A u 3 , A u 3 >_{-1}^0.5 = 4.497655034487545e-16
t = 1.4000000000000001
Newton iteration 0energy = 0.23984219437981988<A u 0 , A u 0 >_{-1}^0.5 = 0.00232416801404013
Newton iteration 1energy = 0.23983949487484169<A u 1 , A u 1 >_{-1}^0.5 = 3.0009604397547507e-06
Newton iteration 2energy = 0.23983949487033884<A u 2 , A u 2 >_{-1}^0.5 = 7.511495133264662e-12
Newton iteration 3energy = 0.23983949487033895<A u 3 , A u 3 >_{-1}^0.5 = 4.457271102231051e-16
t = 1.5000000000000002
Newton iteration 0energy = 0.23983704669748698<A u 0 , A u 0 >_{-1}^0.5 = 0.0021291987319734737
Newton iteration 1energy = 0.23983478088560456<A u 1 , A u 1 >_{-1}^0.5 = 2.6257686686933636e-06
Newton iteration 2energy = 0.2398347808821573<A u 2 , A u 2 >_{-1}^0.5 = 5.384331218074664e-12
Newton iteration 3energy = 0.23983478088215732<A u 3 , A u 3 >_{-1}^0.5 = 4.0108515124668936e-16
t = 1.6000000000000003
Newton iteration 0energy = 0.23983265244268792<A u 0 , A u 0 >_{-1}^0.5 = 0.0020100557693737047
Newton iteration 1energy = 0.23983063294882798<A u 1 , A u 1 >_{-1}^0.5 = 2.3525389446384635e-06
Newton iteration 2energy = 0.2398306329460608<A u 2 , A u 2 >_{-1}^0.5 = 4.068146969940559e-12
Newton iteration 3energy = 0.23983063294606083<A u 3 , A u 3 >_{-1}^0.5 = 4.3910814781746883e-16
t = 1.7000000000000004
Newton iteration 0energy = 0.2398287030787631<A u 0 , A u 0 >_{-1}^0.5 = 0.0019252122100653665
Newton iteration 1energy = 0.239826850357478<A u 1 , A u 1 >_{-1}^0.5 = 2.1365289236943262e-06
Newton iteration 2energy = 0.23982685035519563<A u 2 , A u 2 >_{-1}^0.5 = 3.1940413812410494e-12
Newton iteration 3energy = 0.2398268503551957<A u 3 , A u 3 >_{-1}^0.5 = 4.3239790916168463e-16
t = 1.8000000000000005
Newton iteration 0energy = 0.23982506567647988<A u 0 , A u 0 >_{-1}^0.5 = 0.0018564195832818957
Newton iteration 1energy = 0.2398233429163234<A u 1 , A u 1 >_{-1}^0.5 = 1.9563579521165098e-06
Newton iteration 2energy = 0.2398233429144098<A u 2 , A u 2 >_{-1}^0.5 = 2.576532197084369e-12
Newton iteration 3energy = 0.23982334291440977<A u 3 , A u 3 >_{-1}^0.5 = 4.168337545674308e-16
t = 1.9000000000000006
Newton iteration 0energy = 0.23982167713524788<A u 0 , A u 0 >_{-1}^0.5 = 0.0017958971457824545
Newton iteration 1energy = 0.23982006481970106<A u 1 , A u 1 >_{-1}^0.5 = 1.8009639637079065e-06
Newton iteration 2energy = 0.23982006481807935<A u 2 , A u 2 >_{-1}^0.5 = 2.1180629067376886e-12
Newton iteration 3energy = 0.23982006481807938<A u 3 , A u 3 >_{-1}^0.5 = 4.275446995367114e-16
t = 2.0000000000000004
Newton iteration 0energy = 0.23981850280918926<A u 0 , A u 0 >_{-1}^0.5 = 0.001740310776358378
Newton iteration 1energy = 0.23981698871896923<A u 1 , A u 1 >_{-1}^0.5 = 1.6641243579421696e-06
Newton iteration 2energy = 0.23981698871758456<A u 2 , A u 2 >_{-1}^0.5 = 1.7645509925176325e-12
Newton iteration 3energy = 0.2398169887175845<A u 3 , A u 3 >_{-1}^0.5 = 4.1963762805438165e-16
t = 2.1000000000000005
Newton iteration 0energy = 0.23981552021572586<A u 0 , A u 0 >_{-1}^0.5 = 0.0016881769354288318
Newton iteration 1energy = 0.2398140954528447<A u 1 , A u 1 >_{-1}^0.5 = 1.5420178269083415e-06
Newton iteration 2energy = 0.23981409545165577<A u 2 , A u 2 >_{-1}^0.5 = 1.4844233174577358e-12
Newton iteration 3energy = 0.23981409545165577<A u 3 , A u 3 >_{-1}^0.5 = 4.02205045000741e-16
t = 2.2000000000000006
Newton iteration 0energy = 0.23981271253222786<A u 0 , A u 0 >_{-1}^0.5 = 0.0016387829756173893
Newton iteration 1energy = 0.23981136990222032<A u 1 , A u 1 >_{-1}^0.5 = 1.4320930678395655e-06
Newton iteration 2energy = 0.2398113699011948<A u 2 , A u 2 >_{-1}^0.5 = 1.2579829091911714e-12
Newton iteration 3energy = 0.2398113699011948<A u 3 , A u 3 >_{-1}^0.5 = 4.212159800438489e-16
t = 2.3000000000000007
Newton iteration 0energy = 0.2398100659309837<A u 0 , A u 0 >_{-1}^0.5 = 0.0015917433542050894
Newton iteration 1energy = 0.23980879925623955<A u 1 , A u 1 >_{-1}^0.5 = 1.3325202176466422e-06
Newton iteration 2energy = 0.2398087992553517<A u 2 , A u 2 >_{-1}^0.5 = 1.072191835063917e-12
Newton iteration 3energy = 0.23980879925535173<A u 3 , A u 3 >_{-1}^0.5 = 3.9147779396855535e-16
t = 2.400000000000001
Newton iteration 0energy = 0.23980756843352935<A u 0 , A u 0 >_{-1}^0.5 = 0.0015468169239539241
Newton iteration 1energy = 0.2398063722398347<A u 1 , A u 1 >_{-1}^0.5 = 1.2419105209608674e-06
Newton iteration 2energy = 0.23980637223906348<A u 2 , A u 2 >_{-1}^0.5 = 9.181606100885629e-13
Newton iteration 3energy = 0.2398063722390635<A u 3 , A u 3 >_{-1}^0.5 = 4.204249177876161e-16
t = 2.500000000000001
Newton iteration 0energy = 0.23980520937673644<A u 0 , A u 0 >_{-1}^0.5 = 0.0015038307895702187
Newton iteration 1energy = 0.23980407873345475<A u 1 , A u 1 >_{-1}^0.5 = 1.1591642352896874e-06
Newton iteration 2energy = 0.23980407873278287<A u 2 , A u 2 >_{-1}^0.5 = 7.894063470258062e-13
Newton iteration 3energy = 0.23980407873278284<A u 3 , A u 3 >_{-1}^0.5 = 4.294231133646188e-16
t = 2.600000000000001
Newton iteration 0energy = 0.23980297913275267<A u 0 , A u 0 >_{-1}^0.5 = 0.001462647788622576
Newton iteration 1energy = 0.2398019095592319<A u 1 , A u 1 >_{-1}^0.5 = 1.0833827515316492e-06
Newton iteration 2energy = 0.23980190955864508<A u 2 , A u 2 >_{-1}^0.5 = 6.810990802114164e-13
Newton iteration 3energy = 0.23980190955864508<A u 3 , A u 3 >_{-1}^0.5 = 4.2753009248048324e-16
t = 2.700000000000001
Newton iteration 0energy = 0.2398008689398244<A u 0 , A u 0 >_{-1}^0.5 = 0.0014231520130885233
Newton iteration 1energy = 0.23979985634253928<A u 1 , A u 1 >_{-1}^0.5 = 1.0138146157404198e-06
Newton iteration 2energy = 0.23979985634202533<A u 2 , A u 2 >_{-1}^0.5 = 5.894808712628097e-13
Newton iteration 3energy = 0.23979985634202533<A u 3 , A u 3 >_{-1}^0.5 = 4.1422756115981907e-16
t = 2.800000000000001
Newton iteration 0energy = 0.23979887078562834<A u 0 , A u 0 >_{-1}^0.5 = 0.0013852419317702752
Newton iteration 1energy = 0.23979791141117418<A u 1 , A u 1 >_{-1}^0.5 = 9.498204696464258e-07
Newton iteration 2energy = 0.239797911410723<A u 2 , A u 2 >_{-1}^0.5 = 5.116112791307342e-13
Newton iteration 3energy = 0.2397979114107231<A u 3 , A u 3 >_{-1}^0.5 = 4.076450029822525e-16
t = 2.9000000000000012
Newton iteration 0energy = 0.23979697731840338<A u 0 , A u 0 >_{-1}^0.5 = 0.0013488268130407179
Newton iteration 1energy = 0.23979606771576892<A u 1 , A u 1 >_{-1}^0.5 = 8.908491345635657e-07
Newton iteration 2energy = 0.23979606771537218<A u 2 , A u 2 >_{-1}^0.5 = 4.452475244786126e-13
Newton iteration 3energy = 0.2397960677153721<A u 3 , A u 3 >_{-1}^0.5 = 4.3922489477725524e-16
t = 3.0000000000000013
Newton iteration 0energy = 0.23979518177481676<A u 0 , A u 0 >_{-1}^0.5 = 0.0013138246473699483
Newton iteration 1energy = 0.23979431876380208<A u 1 , A u 1 >_{-1}^0.5 = 8.36420596492343e-07
Newton iteration 2energy = 0.23979431876345225<A u 2 , A u 2 >_{-1}^0.5 = 3.884509019712542e-13
Newton iteration 3energy = 0.23979431876345225<A u 3 , A u 3 >_{-1}^0.5 = 4.301690284769913e-16
t = 3.1000000000000014
Newton iteration 0energy = 0.23979347791918174<A u 0 , A u 0 >_{-1}^0.5 = 0.0012801607964436092
Newton iteration 1energy = 0.23979265856330648<A u 1 , A u 1 >_{-1}^0.5 = 7.86113458671679e-07
Newton iteration 2energy = 0.23979265856299747<A u 2 , A u 2 >_{-1}^0.5 = 3.3969874372684423e-13
Newton iteration 3energy = 0.23979265856299747<A u 3 , A u 3 >_{-1}^0.5 = 4.3004324600663537e-16
t = 3.2000000000000015
Newton iteration 0energy = 0.2397918599911152<A u 0 , A u 0 >_{-1}^0.5 = 0.0012477670242682008
Newton iteration 1energy = 0.23979108157404128<A u 1 , A u 1 >_{-1}^0.5 = 7.395554015632387e-07
Newton iteration 2energy = 0.23979108157376783<A u 2 , A u 2 >_{-1}^0.5 = 2.9777915336040986e-13
Newton iteration 3energy = 0.23979108157376777<A u 3 , A u 3 >_{-1}^0.5 = 3.9547542266396893e-16
t = 3.3000000000000016
Newton iteration 0energy = 0.23979032265987657<A u 0 , A u 0 >_{-1}^0.5 = 0.0012165807486120865
Newton iteration 1energy = 0.23978958266470105<A u 1 , A u 1 >_{-1}^0.5 = 6.964157409186844e-07
Newton iteration 2energy = 0.23978958266445857<A u 2 , A u 2 >_{-1}^0.5 = 2.6157855623946123e-13
Newton iteration 3energy = 0.23978958266445852<A u 3 , A u 3 >_{-1}^0.5 = 4.283654302417877e-16
t = 3.4000000000000017
Newton iteration 0energy = 0.23978886098419994<A u 0 , A u 0 >_{-1}^0.5 = 0.0011865444318763026
Newton iteration 1energy = 0.23978815707515655<A u 1 , A u 1 >_{-1}^0.5 = 6.56399492291637e-07
Newton iteration 2energy = 0.23978815707494122<A u 2 , A u 2 >_{-1}^0.5 = 2.302948265576988e-13
Newton iteration 3energy = 0.2397881570749413<A u 3 , A u 3 >_{-1}^0.5 = 4.086979269954084e-16
t = 3.5000000000000018
Newton iteration 0energy = 0.23978747037675902<A u 0 , A u 0 >_{-1}^0.5 = 0.0011576050677765749
Newton iteration 1energy = 0.23978680038297534<A u 1 , A u 1 >_{-1}^0.5 = 6.19242549160231e-07
Newton iteration 2energy = 0.23978680038278374<A u 2 , A u 2 >_{-1}^0.5 = 2.0315531529176785e-13
Newton iteration 3energy = 0.23978680038278372<A u 3 , A u 3 >_{-1}^0.5 = 3.9756498266179526e-16
t = 3.600000000000002
Newton iteration 0energy = 0.23978614657259592<A u 0 , A u 0 >_{-1}^0.5 = 0.0011297137384427701
Newton iteration 1energy = 0.23978550847362343<A u 1 , A u 1 >_{-1}^0.5 = 5.84707704590533e-07
Newton iteration 2energy = 0.23978550847345248<A u 2 , A u 2 >_{-1}^0.5 = 1.7958897594683527e-13
Newton iteration 3energy = 0.23978550847345256<A u 3 , A u 3 >_{-1}^0.5 = 4.0775697916972084e-16
t = 3.700000000000002
Newton iteration 0energy = 0.23978488560097597<A u 0 , A u 0 >_{-1}^0.5 = 0.0011028252260448733
Newton iteration 1energy = 0.2397842775138649<A u 1 , A u 1 >_{-1}^0.5 = 5.525813242295787e-07
Newton iteration 2energy = 0.23978427751371223<A u 2 , A u 2 >_{-1}^0.5 = 1.5907479433745375e-13
Newton iteration 3energy = 0.23978427751371229<A u 3 , A u 3 >_{-1}^0.5 = 4.256689574317313e-16
t = 3.800000000000002
Newton iteration 0energy = 0.23978368376023024<A u 0 , A u 0 >_{-1}^0.5 = 0.001076897668351713
Newton iteration 1energy = 0.23978310392795166<A u 1 , A u 1 >_{-1}^0.5 = 5.226705343920618e-07
Newton iteration 2energy = 0.2397831039278152<A u 2 , A u 2 >_{-1}^0.5 = 1.4116224904179915e-13
Newton iteration 3energy = 0.2397831039278151<A u 3 , A u 3 >_{-1}^0.5 = 4.174221029815967e-16
t = 3.900000000000002
Newton iteration 0energy = 0.23978253759521045<A u 0 , A u 0 >_{-1}^0.5 = 0.0010518922507697856
Newton iteration 1energy = 0.2397819843762649<A u 1 , A u 1 >_{-1}^0.5 = 4.948008225696191e-07
Newton iteration 2energy = 0.23978198437614234<A u 2 , A u 2 >_{-1}^0.5 = 1.2547261891036262e-13
Newton iteration 3energy = 0.2397819843761424<A u 3 , A u 3 >_{-1}^0.5 = 4.0416552040613763e-16
t = 4.000000000000002
Newton iteration 0energy = 0.23978144387704142<A u 0 , A u 0 >_{-1}^0.5 = 0.0010277729293769811
Newton iteration 1energy = 0.2397809157361111<A u 1 , A u 1 >_{-1}^0.5 = 4.6881397441626697e-07
Newton iteration 2energy = 0.23978091573600113<A u 2 , A u 2 >_{-1}^0.5 = 1.1181144187446951e-13
Newton iteration 3energy = 0.23978091573600113<A u 3 , A u 3 >_{-1}^0.5 = 4.016687422136611e-16
t = 4.100000000000001
Newton iteration 0energy = 0.23978039958490083<A u 0 , A u 0 >_{-1}^0.5 = 0.0010045061807557245
Newton iteration 1energy = 0.23977989508442546<A u 1 , A u 1 >_{-1}^0.5 = 4.44566287255703e-07
Newton iteration 2energy = 0.23977989508432665<A u 2 , A u 2 >_{-1}^0.5 = 9.980130671726263e-14
t = 4.200000000000001
Newton iteration 0energy = 0.2397794018895898<A u 0 , A u 0 >_{-1}^0.5 = 0.0009820607753089098
Newton iteration 1energy = 0.23977891968215984<A u 1 , A u 1 >_{-1}^0.5 = 4.219270158055787e-07
Newton iteration 2energy = 0.23977891968207077<A u 2 , A u 2 >_{-1}^0.5 = 8.925950644743311e-14
t = 4.300000000000001
Newton iteration 0energy = 0.23977844813869198<A u 0 , A u 0 >_{-1}^0.5 = 0.0009604075713616538
Newton iteration 1energy = 0.23977798696016697<A u 1 , A u 1 >_{-1}^0.5 = 4.007770120387171e-07
Newton iteration 2energy = 0.23977798696008668<A u 2 , A u 2 >_{-1}^0.5 = 7.994196152771886e-14
t = 4.4
Newton iteration 0energy = 0.23977753584314124<A u 0 , A u 0 >_{-1}^0.5 = 0.0009395193278036805
Newton iteration 1energy = 0.23977709450641457<A u 1 , A u 1 >_{-1}^0.5 = 3.8100753085926176e-07
Newton iteration 2energy = 0.239777094506342<A u 2 , A u 2 >_{-1}^0.5 = 7.179512773894963e-14
t = 4.5
Newton iteration 0energy = 0.239776662665046<A u 0 , A u 0 >_{-1}^0.5 = 0.0009193705333654081
Newton iteration 1energy = 0.23977624005438256<A u 1 , A u 1 >_{-1}^0.5 = 3.625191772482667e-07
Newton iteration 2energy = 0.23977624005431677<A u 2 , A u 2 >_{-1}^0.5 = 6.453622746009833e-14
t = 4.6
Newton iteration 0energy = 0.23977582640662712<A u 0 , A u 0 >_{-1}^0.5 = 0.0008999372508832096
Newton iteration 1energy = 0.2397754214725149<A u 1 , A u 1 >_{-1}^0.5 = 3.4522097539002697e-07
Newton iteration 2energy = 0.23977542147245537<A u 2 , A u 2 >_{-1}^0.5 = 5.818393855479234e-14
t = 4.699999999999999
Newton iteration 0energy = 0.23977502500015624<A u 0 , A u 0 >_{-1}^0.5 = 0.0008811969751174315
Newton iteration 1energy = 0.239774636754615<A u 1 , A u 1 >_{-1}^0.5 = 3.29029543283108e-07
Newton iteration 2energy = 0.23977463675456087<A u 2 , A u 2 >_{-1}^0.5 = 5.252888457043041e-14
t = 4.799999999999999
Newton iteration 0energy = 0.23977425649878278<A u 0 , A u 0 >_{-1}^0.5 = 0.0008631285028569205
Newton iteration 1energy = 0.2397738840110826<A u 1 , A u 1 >_{-1}^0.5 = 3.138683589703107e-07
Newton iteration 2energy = 0.23977388401103322<A u 2 , A u 2 >_{-1}^0.5 = 4.751561654199766e-14
t = 4.899999999999999
Newton iteration 0energy = 0.23977351906815902<A u 0 , A u 0 >_{-1}^0.5 = 0.0008457118141865206
Newton iteration 1energy = 0.23977316146090577<A u 1 , A u 1 >_{-1}^0.5 = 2.9966710699954903e-07
Newton iteration 2energy = 0.23977316146086092<A u 2 , A u 2 >_{-1}^0.5 = 4.3025917851734007e-14
t = 4.999999999999998
Minimal energy extension (postscript in unit-2.1.3 )¶
[14]:
from netgen.geom2d import unit_square
mesh = Mesh(unit_square.GenerateMesh(maxh=0.1))
fes_ho = Discontinuous(H1(mesh, order=10))
fes_lo = H1(mesh, order=1, dirichlet=".*")
fes_lam = Discontinuous(H1(mesh, order=1))
fes = fes_ho*fes_lo*fes_lam
uho, ulo, lam = fes.TrialFunction()
[15]:
a = BilinearForm(fes)
a += Variation(0.5 * grad(uho)*grad(uho)*dx
- 1*uho*dx
+ (uho-ulo)*lam*dx(element_vb=BBND))
gfu = GridFunction(fes)
solvers.Newton(a=a, u=gfu)
Draw(gfu.components[0])
Newton iteration 0
err = 0.39346141669994983
Newton iteration 1
err = 1.8488788182878563e-15
The minimization problem is solved by the solution of the PDE:
under the constraint
[ ]: