This page was generated from unit-3.8-nonlmin/nonlmin.ipynb.

3.8 Nonlinear minimization problems

We consider problems of the form

\[\text{find } u \in V \text{ s.t. } E(u) \leq E(v) \quad \forall~ v \in V.\]
[1]:
from ngsolve import *
import netgen.gui

Scalar minimization problems

As a first example we take \(V = H^1_0\) and

\[E(u) = \int_{\Omega} \vert \nabla u \vert^2 + u^4 - fu ~dx.\]

The minimization is equivalent to solving the nonlinear PDE:

\[- \Delta u + 4 u^3 = f \text{ in } \Omega\]

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)

\[E(u) \qquad (E:V \to \mathbb{R})\]
  • compute the Gateau derivative for a given \(u\) (Apply):

\[A(u)(v) = E'(u)(v) \qquad (A(u): V \to \mathbb{R})\]
  • compute the second derivative (AssembleLinearization)

\[(\delta A)(w)(u,v) \qquad (\delta A(w): V\times V \to \mathbb{R})\]
[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.13255957337312613
Newton iteration   1energy = -0.008785676900152117<A u 1 , A u 1 >_{-1}^0.5 =  1.1107598189167146e-05
Newton iteration   2energy = -0.008785676961841486<A u 2 , A u 2 >_{-1}^0.5 =  2.807517603399629e-13
Newton iteration   3energy = -0.008785676961841488<A u 3 , A u 3 >_{-1}^0.5 =  3.3304484794486327e-17
energy =  -0.008785676961841488

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.13255957337312615
Newton iteration  1
Energy:  -0.008785676900152117
err =  1.1107598189171795e-05
Newton iteration  2
Energy:  -0.008785676961841486
err =  2.80747021639635e-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

\[E(v) := \int_{\Omega} \frac{\mu}{2} ( \operatorname{tr}(F^T F-I)+\frac{2 \mu}{\lambda} \operatorname{det}(F^T F)^{\frac{\lambda}{2\mu}} - 1) - \gamma ~ (f,v) ~~ dx\]

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.749999999999998<A u 0 , A u 0 >_{-1}^0.5 =  0.01667849444523386
Newton iteration   1energy = 8.750132591453418<A u 1 , A u 1 >_{-1}^0.5 =  0.023333560516275564
Newton iteration   2energy = 8.74986114895739<A u 2 , A u 2 >_{-1}^0.5 =  0.00010232534273250714
Newton iteration   3energy = 8.749861143722152<A u 3 , A u 3 >_{-1}^0.5 =  5.1484913353753e-08
Newton iteration   4energy = 8.749861143722145<A u 4 , A u 4 >_{-1}^0.5 =  2.734694947345281e-13
Newton iteration   5energy = 8.749861143722145<A u 5 , A u 5 >_{-1}^0.5 =  9.247273008118622e-16
loadstep 1
Newton iteration   0energy = 8.74958388866222<A u 0 , A u 0 >_{-1}^0.5 =  0.016596172790229985
Newton iteration   1energy = 8.749710096254224<A u 1 , A u 1 >_{-1}^0.5 =  0.022958523347670023
Newton iteration   2energy = 8.749447295506688<A u 2 , A u 2 >_{-1}^0.5 =  0.00014215759220200522
Newton iteration   3energy = 8.749447285508145<A u 3 , A u 3 >_{-1}^0.5 =  2.325574122106694e-06
Newton iteration   4energy = 8.749447285505438<A u 4 , A u 4 >_{-1}^0.5 =  6.329020240483118e-10
Newton iteration   5energy = 8.749447285505443<A u 5 , A u 5 >_{-1}^0.5 =  1.6967201531172987e-15
loadstep 2
Newton iteration   0energy = 8.748898140386652<A u 0 , A u 0 >_{-1}^0.5 =  0.016356983393359056
Newton iteration   1energy = 8.749005259290692<A u 1 , A u 1 >_{-1}^0.5 =  0.021892894044873473
Newton iteration   2energy = 8.748766252622183<A u 2 , A u 2 >_{-1}^0.5 =  0.000208222077261969
Newton iteration   3energy = 8.748766231266895<A u 3 , A u 3 >_{-1}^0.5 =  4.890915769550513e-06
Newton iteration   4energy = 8.748766231254931<A u 4 , A u 4 >_{-1}^0.5 =  2.665249442467225e-09
Newton iteration   5energy = 8.748766231254935<A u 5 , A u 5 >_{-1}^0.5 =  2.2360660986729218e-15
loadstep 3
Newton iteration   0energy = 8.747955292062146<A u 0 , A u 0 >_{-1}^0.5 =  0.0159820733778304
Newton iteration   1energy = 8.74803542180493<A u 1 , A u 1 >_{-1}^0.5 =  0.020292399713242315
Newton iteration   2energy = 8.747830036432735<A u 2 , A u 2 >_{-1}^0.5 =  0.00026380399717611486
Newton iteration   3energy = 8.747830002128063<A u 3 , A u 3 >_{-1}^0.5 =  7.24731483392178e-06
Newton iteration   4energy = 8.747830002101788<A u 4 , A u 4 >_{-1}^0.5 =  4.744152101219956e-09
Newton iteration   5energy = 8.747830002101791<A u 5 , A u 5 >_{-1}^0.5 =  3.834758384860599e-15
loadstep 4
Newton iteration   0energy = 8.746771010509391<A u 0 , A u 0 >_{-1}^0.5 =  0.015501067150346784
Newton iteration   1energy = 8.746821856285143<A u 1 , A u 1 >_{-1}^0.5 =  0.01835991696222946
Newton iteration   2energy = 8.746653679174742<A u 2 , A u 2 >_{-1}^0.5 =  0.00029906276685253894
Newton iteration   3energy = 8.746653634982097<A u 3 , A u 3 >_{-1}^0.5 =  8.720360402018377e-06
Newton iteration   4energy = 8.746653634944062<A u 4 , A u 4 >_{-1}^0.5 =  5.243058230169497e-09
Newton iteration   5energy = 8.746653634944062<A u 5 , A u 5 >_{-1}^0.5 =  4.57624018420641e-15
loadstep 5
Newton iteration   0energy = 8.745362710869802<A u 0 , A u 0 >_{-1}^0.5 =  0.01494623240146039
Newton iteration   1energy = 8.745386462940143<A u 1 , A u 1 >_{-1}^0.5 =  0.016292996834189524
Newton iteration   2energy = 8.74525397874261<A u 2 , A u 2 >_{-1}^0.5 =  0.00031320373730301293
Newton iteration   3energy = 8.745253930142317<A u 3 , A u 3 >_{-1}^0.5 =  9.042918405812291e-06
Newton iteration   4energy = 8.745253930101422<A u 4 , A u 4 >_{-1}^0.5 =  4.2170747228818445e-09
Newton iteration   5energy = 8.74525393010142<A u 5 , A u 5 >_{-1}^0.5 =  4.4934195509996876e-15
loadstep 6
Newton iteration   0energy = 8.743748369013607<A u 0 , A u 0 >_{-1}^0.5 =  0.014347713355602996
Newton iteration   1energy = 8.743749760522784<A u 1 , A u 1 >_{-1}^0.5 =  0.014249104212014871
Newton iteration   2energy = 8.74364839737191<A u 2 , A u 2 >_{-1}^0.5 =  0.00030934606309694624
Newton iteration   3energy = 8.743648349846454<A u 3 , A u 3 >_{-1}^0.5 =  8.384888859530472e-06
Newton iteration   4energy = 8.743648349811291<A u 4 , A u 4 >_{-1}^0.5 =  2.6940148501867647e-09
Newton iteration   5energy =  8.7436483498113<A u 5 , A u 5 >_{-1}^0.5 =  4.577084252820437e-15
loadstep 7
Newton iteration   0energy = 8.741945639262823<A u 0 , A u 0 >_{-1}^0.5 =  0.013730721530226796
Newton iteration   1energy = 8.741930180324744<A u 1 , A u 1 >_{-1}^0.5 =  0.012333575792311013
Newton iteration   2energy = 8.741854213024633<A u 2 , A u 2 >_{-1}^0.5 =  0.0002921321706594058
Newton iteration   3energy = 8.74185417055718<A u 3 , A u 3 >_{-1}^0.5 =  7.130071890016913e-06
Newton iteration   4energy = 8.741854170531763<A u 4 , A u 4 >_{-1}^0.5 =  1.4434881033484502e-09
Newton iteration   5energy = 8.74185417053177<A u 5 , A u 5 >_{-1}^0.5 =  5.262958683534736e-15
loadstep 8
Newton iteration   0energy = 8.739971280231286<A u 0 , A u 0 >_{-1}^0.5 =  0.013114572255962758
Newton iteration   1energy = 8.73994411367146<A u 1 , A u 1 >_{-1}^0.5 =  0.010604017031859161
Newton iteration   2energy = 8.739887940284762<A u 2 , A u 2 >_{-1}^0.5 =  0.00026632144941452456
Newton iteration   3energy = 8.73988790493644<A u 3 , A u 3 >_{-1}^0.5 =  5.662818925120992e-06
Newton iteration   4energy = 8.739887904920405<A u 4 , A u 4 >_{-1}^0.5 =  6.720247861727614e-10
Newton iteration   5energy = 8.739887904920398<A u 5 , A u 5 >_{-1}^0.5 =  5.5915825831605006e-15
loadstep 9
Newton iteration   0energy = 8.73784083403977<A u 0 , A u 0 >_{-1}^0.5 =  0.0125129674198164
Newton iteration   1energy = 8.737806204166365<A u 1 , A u 1 >_{-1}^0.5 =  0.009082089187694535
Newton iteration   2energy = 8.73776498517593<A u 2 , A u 2 >_{-1}^0.5 =  0.00023604345317251825
Newton iteration   3energy = 8.73776495737735<A u 3 , A u 3 >_{-1}^0.5 =  4.2585795846192444e-06
Newton iteration   4energy = 8.737764957368277<A u 4 , A u 4 >_{-1}^0.5 =  2.778882710277497e-10
Newton iteration   5energy = 8.73776495736828<A u 5 , A u 5 >_{-1}^0.5 =  6.192838256475658e-15
loadstep 10
Newton iteration   0energy = 8.735568488681253<A u 0 , A u 0 >_{-1}^0.5 =  0.011934895047581391
Newton iteration   1energy = 8.735529626298675<A u 1 , A u 1 >_{-1}^0.5 =  0.007766086303887108
Newton iteration   2energy = 8.735499478251771<A u 2 , A u 2 >_{-1}^0.5 =  0.00020450110958987553
Newton iteration   3energy = 8.735499457369832<A u 3 , A u 3 >_{-1}^0.5 =  3.0649641069813007e-06
Newton iteration   4energy = 8.73549945736514<A u 4 , A u 4 >_{-1}^0.5 =  1.0317259419213303e-10
Newton iteration   5energy = 8.735499457365144<A u 5 , A u 5 >_{-1}^0.5 =  6.1435177694761e-15
loadstep 11
Newton iteration   0energy = 8.733167060537248<A u 0 , A u 0 >_{-1}^0.5 =  0.011385697188469452
Newton iteration   1energy = 8.733126283518718<A u 1 , A u 1 >_{-1}^0.5 =  0.006641150145740644
Newton iteration   2energy = 8.733104230848486<A u 2 , A u 2 >_{-1}^0.5 =  0.00017394439104879262
Newton iteration   3energy = 8.733104215732606<A u 3 , A u 3 >_{-1}^0.5 =  2.129411853086759e-06
Newton iteration   4energy = 8.733104215730345<A u 4 , A u 4 >_{-1}^0.5 =  3.432558772877624e-11
Newton iteration   5energy = 8.733104215730338<A u 5 , A u 5 >_{-1}^0.5 =  8.094250286114186e-15
loadstep 12
Newton iteration   0energy = 8.730648048952677<A u 0 , A u 0 >_{-1}^0.5 =  0.01086806034480337
Newton iteration   1energy = 8.730606940950912<A u 1 , A u 1 >_{-1}^0.5 =  0.005686383297879251
Newton iteration   2energy = 8.730590769249666<A u 2 , A u 2 >_{-1}^0.5 =  0.00014578425109884895
Newton iteration   3energy = 8.730590758628075<A u 3 , A u 3 >_{-1}^0.5 =  1.4384336718370366e-06
Newton iteration   4energy = 8.730590758627047<A u 4 , A u 4 >_{-1}^0.5 =  9.987280236896591e-12
Newton iteration   5energy = 8.730590758627043<A u 5 , A u 5 >_{-1}^0.5 =  7.875973513059426e-15
loadstep 13
Newton iteration   0energy = 8.72802172950889<A u 0 , A u 0 >_{-1}^0.5 =  0.01038282956646614
Newton iteration   1energy = 8.727981322866317<A u 1 , A u 1 >_{-1}^0.5 =  0.004879270983755723
Newton iteration   2energy = 8.727969413471362<A u 2 , A u 2 >_{-1}^0.5 =  0.00012076411719468836
Newton iteration   3energy = 8.727969406181067<A u 3 , A u 3 >_{-1}^0.5 =  9.505522832199866e-07
Newton iteration   4energy = 8.727969406180618<A u 4 , A u 4 >_{-1}^0.5 =  2.327209811059151e-12
Newton iteration   5energy = 8.727969406180616<A u 5 , A u 5 >_{-1}^0.5 =  8.366395854739112e-15
loadstep 14
Newton iteration   0energy = 8.725297264364867<A u 0 , A u 0 >_{-1}^0.5 =  0.009929630827329049
Newton iteration   1energy = 8.725258196156323<A u 1 , A u 1 >_{-1}^0.5 =  0.004198149297602768
Newton iteration   2energy = 8.72524937798614<A u 2 , A u 2 >_{-1}^0.5 =  9.914019138175112e-05
Newton iteration   3energy = 8.725249373072183<A u 3 , A u 3 >_{-1}^0.5 =  6.177438537851986e-07
Newton iteration   4energy = 8.725249373071996<A u 4 , A u 4 >_{-1}^0.5 =  2.711757828663729e-13
Newton iteration   5energy = 8.72524937307199<A u 5 , A u 5 >_{-1}^0.5 =  8.086506222001764e-15
loadstep 15
Newton iteration   0energy = 8.722482816430372<A u 0 , A u 0 >_{-1}^0.5 =  0.009507324233198547
Newton iteration   1energy = 8.72244544987052<A u 1 , A u 1 >_{-1}^0.5 =  0.0036234023936600923
Newton iteration   2energy = 8.722438879876965<A u 2 , A u 2 >_{-1}^0.5 =  8.084368163731423e-05
Newton iteration   3energy = 8.722438876609113<A u 3 , A u 3 >_{-1}^0.5 =  3.966066049271973e-07
Newton iteration   4energy = 8.722438876609038<A u 4 , A u 4 >_{-1}^0.5 =  1.5278000509753718e-13
Newton iteration   5energy = 8.722438876609038<A u 5 , A u 5 >_{-1}^0.5 =  8.08115538661459e-15
loadstep 16
Newton iteration   0energy = 8.719585659767372<A u 0 , A u 0 >_{-1}^0.5 =  0.009114322388199479
Newton iteration   1energy = 8.71955017364448<A u 1 , A u 1 >_{-1}^0.5 =  0.00313789936072171
Newton iteration   2energy = 8.719545245704236<A u 2 , A u 2 >_{-1}^0.5 =  6.561232996881842e-05
Newton iteration   3energy = 8.71954524355164<A u 3 , A u 3 >_{-1}^0.5 =  2.52533093944595e-07
Newton iteration   4energy = 8.719545243551611<A u 4 , A u 4 >_{-1}^0.5 =  1.5033040334992298e-13
Newton iteration   5energy = 8.719545243551606<A u 5 , A u 5 >_{-1}^0.5 =  8.051020566432653e-15
loadstep 17
Newton iteration   0energy = 8.71661228222845<A u 0 , A u 0 >_{-1}^0.5 =  0.008748807494135346
Newton iteration   1energy = 8.716578734485331<A u 1 , A u 1 >_{-1}^0.5 =  0.0027270119708742158
Newton iteration   2energy = 8.716575012244606<A u 2 , A u 2 >_{-1}^0.5 =  5.308808014174092e-05
Newton iteration   3energy = 8.716575010835323<A u 3 , A u 3 >_{-1}^0.5 =  1.599966209600588e-07
Newton iteration   4energy = 8.716575010835307<A u 4 , A u 4 >_{-1}^0.5 =  9.245681199048317e-14
loadstep 18
Newton iteration   0energy = 8.713568478570464<A u 0 , A u 0 >_{-1}^0.5 =  0.008408875280311978
Newton iteration   1energy = 8.713536850394119<A u 1 , A u 1 >_{-1}^0.5 =  0.0023784245288753533
Newton iteration   2energy = 8.713534018737166<A u 2 , A u 2 >_{-1}^0.5 =  4.288364628582515e-05
Newton iteration   3energy = 8.71353401781759<A u 3 , A u 3 >_{-1}^0.5 =  1.011410754526628e-07
Newton iteration   4energy = 8.71353401781757<A u 4 , A u 4 >_{-1}^0.5 =  4.8832450515969854e-14
loadstep 19
Newton iteration   0energy = 8.710459433603457<A u 0 , A u 0 >_{-1}^0.5 =  0.008092627477923432
Newton iteration   1energy = 8.710429659421148<A u 1 , A u 1 >_{-1}^0.5 =  0.002081858695703015
Newton iteration   2energy = 8.710427489790115<A u 2 , A u 2 >_{-1}^0.5 =  3.462374278328321e-05
Newton iteration   3energy = 8.71042748919065<A u 3 , A u 3 >_{-1}^0.5 =  6.393601985494953e-08
Newton iteration   4energy = 8.710427489190652<A u 4 , A u 4 >_{-1}^0.5 =  2.505219063009473e-14
loadstep 20
Newton iteration   0energy = 8.707289795678951<A u 0 , A u 0 >_{-1}^0.5 =  0.007798228855193676
Newton iteration   1energy = 8.707261783232546<A u 1 , A u 1 >_{-1}^0.5 =  0.001828780371476849
Newton iteration   2energy = 8.707260108985894<A u 2 , A u 2 >_{-1}^0.5 =  2.796754346607161e-05
Newton iteration   3energy = 8.707260108594774<A u 3 , A u 3 >_{-1}^0.5 =  4.0490580515779663e-08
Newton iteration   4energy = 8.707260108594774<A u 4 , A u 4 >_{-1}^0.5 =  1.4094429423583045e-14
loadstep 21
Newton iteration   0energy = 8.704063741206715<A u 0 , A u 0 >_{-1}^0.5 =  0.007523940275902371
Newton iteration   1energy = 8.704037384768432<A u 1 , A u 1 >_{-1}^0.5 =  0.0016121223324776503
Newton iteration   2energy = 8.704036083705963<A u 2 , A u 2 >_{-1}^0.5 =  2.2618373003579114e-05
Newton iteration   3energy = 8.70403608345015<A u 3 , A u 3 >_{-1}^0.5 =  2.57264200426525e-08
Newton iteration   4energy = 8.704036083450148<A u 4 , A u 4 >_{-1}^0.5 =  1.025503816822179e-14
loadstep 22
Newton iteration   0energy = 8.700785031058096<A u 0 , A u 0 >_{-1}^0.5 =  0.007268135817663741
Newton iteration   1energy = 8.700760219966702<A u 1 , A u 1 >_{-1}^0.5 =  0.0014260372524824256
Newton iteration   2energy = 8.700759201928879<A u 2 , A u 2 >_{-1}^0.5 =  1.8325434222126603e-05
Newton iteration   3energy = 8.700759201760949<A u 3 , A u 3 >_{-1}^0.5 =  1.6417609086959264e-08
Newton iteration   4energy = 8.70075920176095<A u 4 , A u 4 >_{-1}^0.5 =  9.90254098112901e-15
loadstep 23
Newton iteration   0energy = 8.697457059755887<A u 0 , A u 0 >_{-1}^0.5 =  0.007029309502644591
Newton iteration   1energy = 8.697433683793736<A u 1 , A u 1 >_{-1}^0.5 =  0.0012656853969031537
Newton iteration   2energy = 8.69743288184044<A u 2 , A u 2 >_{-1}^0.5 =  1.4881058448227105e-05
Newton iteration   3energy = 8.69743288172972<A u 3 , A u 3 >_{-1}^0.5 =  1.05321833182215e-08
Newton iteration   4energy = 8.697432881729718<A u 4 , A u 4 >_{-1}^0.5 =  9.588291840221449e-15
loadstep 24
Newton iteration   0energy = 8.694082898322856<A u 0 , A u 0 >_{-1}^0.5 =  0.006806075429231539
Newton iteration   1energy = 8.694060850980257<A u 1 , A u 1 >_{-1}^0.5 =  0.001127056033072989
Newton iteration   2energy = 8.69406021509277<A u 2 , A u 2 >_{-1}^0.5 =  1.2115810532600391e-05
Newton iteration   3energy = 8.694060215019382<A u 3 , A u 3 >_{-1}^0.5 =  6.796446181591913e-09
Newton iteration   4energy = 8.694060215019384<A u 4 , A u 4 >_{-1}^0.5 =  1.0653141855886985e-14
loadstep 25
Newton iteration   0energy = 8.690665331596561<A u 0 , A u 0 >_{-1}^0.5 =  0.006597163862847386
Newton iteration   1energy = 8.690644511937402<A u 1 , A u 1 >_{-1}^0.5 =  0.001006819235980881
Newton iteration   2energy = 8.69064400450148<A u 2 , A u 2 >_{-1}^0.5 =  9.892890798941409e-06
Newton iteration   3energy = 8.690644004452542<A u 3 , A u 3 >_{-1}^0.5 =  4.413672136741346e-09
Newton iteration   4energy = 8.690644004452544<A u 4 , A u 4 >_{-1}^0.5 =  8.706654914525168e-15
loadstep 26
Newton iteration   0energy = 8.687206890738581<A u 0 , A u 0 >_{-1}^0.5 =  0.00640141499389159
Newton iteration   1energy = 8.68718720435108<A u 1 , A u 1 >_{-1}^0.5 =  0.0009022039607243906
Newton iteration   2energy = 8.687186796900923<A u 2 , A u 2 >_{-1}^0.5 =  8.102650665520232e-06
Newton iteration   3energy = 8.68718679686809<A u 3 , A u 3 >_{-1}^0.5 =  2.8854231418118854e-09
Newton iteration   4energy = 8.687186796868094<A u 4 , A u 4 >_{-1}^0.5 =  9.50793693421982e-15
loadstep 27
Newton iteration   0energy = 8.683709881582512<A u 0 , A u 0 >_{-1}^0.5 =  0.006217771488356258
Newton iteration   1energy = 8.683691240941258<A u 1 , A u 1 >_{-1}^0.5 =  0.0008108982398810496
Newton iteration   2energy = 8.683690911799431<A u 2 , A u 2 >_{-1}^0.5 =  6.6576303877916165e-06
Newton iteration   3energy = 8.683690911777271<A u 3 , A u 3 >_{-1}^0.5 =  1.8993156161478608e-09
Newton iteration   4energy = 8.683690911777267<A u 4 , A u 4 >_{-1}^0.5 =  9.362268095886705e-15
loadstep 28
Newton iteration   0energy = 8.680176409385007<A u 0 , A u 0 >_{-1}^0.5 =  0.006045270560225572
Newton iteration   1energy = 8.680158733842598<A u 1 , A u 1 >_{-1}^0.5 =  0.0007309677194524074
Newton iteration   2energy = 8.680158466399725<A u 2 , A u 2 >_{-1}^0.5 =  5.488278554618818e-06
Newton iteration   3energy = 8.680158466384661<A u 3 , A u 3 >_{-1}^0.5 =  1.2589535377386467e-09
Newton iteration   4energy = 8.680158466384663<A u 4 , A u 4 >_{-1}^0.5 =  9.90942431883319e-15
loadstep 29
Newton iteration   0energy = 8.676608400469208<A u 0 , A u 0 >_{-1}^0.5 =  0.005883036026966293
Newton iteration   1energy = 8.676591616023208<A u 1 , A u 1 >_{-1}^0.5 =  0.0006607892405581196
Newton iteration   2energy = 8.676591397476551<A u 2 , A u 2 >_{-1}^0.5 =  4.539372421135213e-06
Newton iteration   3energy = 8.676591397466245<A u 3 , A u 3 >_{-1}^0.5 =  8.403590576691722e-10
Newton iteration   4energy = 8.676591397466247<A u 4 , A u 4 >_{-1}^0.5 =  9.866077327214238e-15
loadstep 30
Newton iteration   0energy = 8.673007621183567<A u 0 , A u 0 >_{-1}^0.5 =  0.005730270629910569
Newton iteration   1energy = 8.67299166011491<A u 1 , A u 1 >_{-1}^0.5 =  0.0005989966873394284
Newton iteration   2energy = 8.67299148053809<A u 2 , A u 2 >_{-1}^0.5 =  3.7670865979156124e-06
Newton iteration   3energy = 8.672991480530989<A u 3 , A u 3 >_{-1}^0.5 =  5.648759494872811e-10
Newton iteration   4energy = 8.672991480530989<A u 4 , A u 4 >_{-1}^0.5 =  1.0050875893853173e-14
loadstep 31
Newton iteration   0energy = 8.66937569453993<A u 0 , A u 0 >_{-1}^0.5 =  0.0055862487812907875
Newton iteration   1energy = 8.669360494985764<A u 1 , A u 1 >_{-1}^0.5 =  0.0005444367972390969
Newton iteration   2energy = 8.66936034663853<A u 2 , A u 2 >_{-1}^0.5 =  3.136627189130437e-06
Newton iteration   3energy = 8.669360346633617<A u 3 , A u 3 >_{-1}^0.5 =  3.8233940124142637e-10
Newton iteration   4energy = 8.669360346633615<A u 4 , A u 4 >_{-1}^0.5 =  1.1734935299802074e-14
loadstep 32
Newton iteration   0energy = 8.665714114843603<A u 0 , A u 0 >_{-1}^0.5 =  0.005450309821622411
Newton iteration   1energy = 8.665699620344926<A u 1 , A u 1 >_{-1}^0.5 =  0.0004961330477172054
Newton iteration   2energy = 8.665699497158188<A u 2 , A u 2 >_{-1}^0.5 =  2.620341391709445e-06
Newton iteration   3energy = 8.665699497154765<A u 3 , A u 3 >_{-1}^0.5 =  2.6056570946754966e-10
Newton iteration   4energy = 8.665699497154764<A u 4 , A u 4 >_{-1}^0.5 =  1.217201318445093e-14
loadstep 33
Newton iteration   0energy = 8.662024260583653<A u 0 , A u 0 >_{-1}^0.5 =  0.005321851819893844
Newton iteration   1energy = 8.662010419633267<A u 1 , A u 1 >_{-1}^0.5 =  0.0004532560862173065
Newton iteration   2energy = 8.662010316822602<A u 2 , A u 2 >_{-1}^0.5 =  2.1962173093012577e-06
Newton iteration   3energy = 8.662010316820195<A u 3 , A u 3 >_{-1}^0.5 =  1.787715409258059e-10
Newton iteration   4energy = 8.662010316820183<A u 4 , A u 4 >_{-1}^0.5 =  1.067211648222395e-14
loadstep 34
Newton iteration   0energy = 8.658307405813543<A u 0 , A u 0 >_{-1}^0.5 =  0.005200325917091465
Newton iteration   1energy = 8.658294171419934<A u 1 , A u 1 >_{-1}^0.5 =  0.0004150994634587661
Newton iteration   2energy = 8.65829408519383<A u 2 , A u 2 >_{-1}^0.5 =  1.8466987982871333e-06
Newton iteration   3energy = 8.65829408519212<A u 3 , A u 3 >_{-1}^0.5 =  1.2346713844118924e-10
Newton iteration   4energy = 8.658294085192125<A u 4 , A u 4 >_{-1}^0.5 =  9.32755969194597e-15
loadstep 35
Newton iteration   0energy = 8.654564730219906<A u 0 , A u 0 >_{-1}^0.5 =  0.005085231193936819
Newton iteration   1energy = 8.654552059495636<A u 1 , A u 1 >_{-1}^0.5 =  0.00038105966948391123
Newton iteration   2energy = 8.654551986834138<A u 2 , A u 2 >_{-1}^0.5 =  1.557751764245773e-06
Newton iteration   3energy = 8.654551986832924<A u 3 , A u 3 >_{-1}^0.5 =  8.582341612129994e-11
Newton iteration   4energy = 8.654551986832924<A u 4 , A u 4 >_{-1}^0.5 =  1.2058191498589807e-14
loadstep 36
Newton iteration   0energy = 8.650797328048808<A u 0 , A u 0 >_{-1}^0.5 =  0.004976110032586554
Newton iteration   1energy = 8.65078518182817<A u 1 , A u 1 >_{-1}^0.5 =  0.00035061966629611104
Newton iteration   2energy = 8.650785120313985<A u 2 , A u 2 >_{-1}^0.5 =  1.3181296369092865e-06
Newton iteration   3energy = 8.650785120313117<A u 3 , A u 3 >_{-1}^0.5 =  6.003349278006359e-11
Newton iteration   4energy = 8.650785120313119<A u 4 , A u 4 >_{-1}^0.5 =  1.0325850670695882e-14
loadstep 37
Newton iteration   0energy = 8.647006216035676<A u 0 , A u 0 >_{-1}^0.5 =  0.004872543936238474
Newton iteration   1energy = 8.646994558523108<A u 1 , A u 1 >_{-1}^0.5 =  0.00032333526738206875
Newton iteration   2energy = 8.646994506212032<A u 2 , A u 2 >_{-1}^0.5 =  1.1187957572450256e-06
Newton iteration   3energy = 8.646994506211405<A u 3 , A u 3 >_{-1}^0.5 =  4.2252692019247613e-11
Newton iteration   4energy = 8.646994506211412<A u 4 , A u 4 >_{-1}^0.5 =  1.0729852040909942e-14
loadstep 38
Newton iteration   0energy = 8.64319234046425<A u 0 , A u 0 >_{-1}^0.5 =  0.004774149768405117
Newton iteration   1energy = 8.64318113891363<A u 1 , A u 1 >_{-1}^0.5 =  0.00029882384028847404
Newton iteration   2energy = 8.643181094234647<A u 2 , A u 2 >_{-1}^0.5 =  9.52469007074102e-07
Newton iteration   3energy = 8.643181094234198<A u 3 , A u 3 >_{-1}^0.5 =  2.99157638633773e-11
Newton iteration   4energy = 8.643181094234194<A u 4 , A u 4 >_{-1}^0.5 =  1.231791869358724e-14
loadstep 39
Newton iteration   0energy = 8.639356583463016<A u 0 , A u 0 >_{-1}^0.5 =  0.004680576373940036
Newton iteration   1energy = 8.639345807886512<A u 1 , A u 1 >_{-1}^0.5 =  0.0002767549095867613
Newton iteration   2energy = 8.639345769564418<A u 2 , A u 2 >_{-1}^0.5 =  8.132660428051996e-07
Newton iteration   3energy = 8.639345769564084<A u 3 , A u 3 >_{-1}^0.5 =  2.1305856722228868e-11
Newton iteration   4energy = 8.639345769564079<A u 4 , A u 4 >_{-1}^0.5 =  1.1818176358974371e-14
loadstep 40
Newton iteration   0energy = 8.635499768632432<A u 0 , A u 0 >_{-1}^0.5 =  0.004591501544822213
Newton iteration   1energy = 8.635489391537332<A u 1 , A u 1 >_{-1}^0.5 =  0.0002568423180182777
Newton iteration   2energy = 8.635489358532457<A u 2 , A u 2 >_{-1}^0.5 =  6.96419178009762e-07
Newton iteration   3energy = 8.635489358532212<A u 3 , A u 3 >_{-1}^0.5 =  1.5262192556902303e-11
Newton iteration   4energy = 8.635489358532213<A u 4 , A u 4 >_{-1}^0.5 =  1.1024939938001828e-14
loadstep 41
Newton iteration   0energy = 8.631622666083985<A u 0 , A u 0 >_{-1}^0.5 =  0.004506629296485266
Newton iteration   1energy = 8.631612662235378<A u 1 , A u 1 >_{-1}^0.5 =  0.0002388376690438732
Newton iteration   2energy = 8.631612633696458<A u 2 , A u 2 >_{-1}^0.5 =  5.980535273693957e-07
Newton iteration   3energy = 8.631612633696278<A u 3 , A u 3 >_{-1}^0.5 =  1.099135182257061e-11
Newton iteration   4energy = 8.631612633696287<A u 4 , A u 4 >_{-1}^0.5 =  1.1420765638026738e-14
loadstep 42
Newton iteration   0energy = 8.627725996961052<A u 0 , A u 0 >_{-1}^0.5 =  0.0044256874227469566
Newton iteration   1energy = 8.627716343168219<A u 1 , A u 1 >_{-1}^0.5 =  0.00022252482582335286
Newton iteration   2energy = 8.627716318395358<A u 2 , A u 2 >_{-1}^0.5 =  5.150106027527706e-07
Newton iteration   3energy = 8.627716318395228<A u 3 , A u 3 >_{-1}^0.5 =  7.959435264709924e-12
Newton iteration   4energy = 8.627716318395228<A u 4 , A u 4 >_{-1}^0.5 =  1.1578943244195082e-14
loadstep 43
Newton iteration   0energy = 8.62381043750256<A u 0 , A u 0 >_{-1}^0.5 =  0.0043484253001886426
Newton iteration   1energy = 8.62380111242687<A u 1 , A u 1 >_{-1}^0.5 =  0.00020771528351786156
Newton iteration   2energy = 8.623801090842262<A u 2 , A u 2 >_{-1}^0.5 =  4.447083520833389e-07
Newton iteration   3energy = 8.623801090842166<A u 3 , A u 3 >_{-1}^0.5 =  5.793345816132156e-12
Newton iteration   4energy = 8.623801090842163<A u 4 , A u 4 >_{-1}^0.5 =  1.0945054837429887e-14
loadstep 44
Newton iteration   0energy = 8.619876622702083<A u 0 , A u 0 >_{-1}^0.5 =  0.004274611915556383
Newton iteration   1energy = 8.619867606684437<A u 1 , A u 1 >_{-1}^0.5 =  0.0001942442655680472
Newton iteration   2energy = 8.619867587809216<A u 2 , A u 2 >_{-1}^0.5 =  3.850298436002284e-07
Newton iteration   3energy = 8.619867587809129<A u 3 , A u 3 >_{-1}^0.5 =  4.240958949701815e-12
Newton iteration   4energy = 8.619867587809136<A u 4 , A u 4 >_{-1}^0.5 =  1.1418242765222334e-14
loadstep 45
Newton iteration   0energy = 8.615925149608909<A u 0 , A u 0 >_{-1}^0.5 =  0.004204034092581162
Newton iteration   1energy = 8.615916424514648<A u 1 , A u 1 >_{-1}^0.5 =  0.00018196742192939653
Newton iteration   2energy = 8.615916407950385<A u 2 , A u 2 >_{-1}^0.5 =  3.3423451071494996e-07
Newton iteration   3energy = 8.61591640795033<A u 3 , A u 3 >_{-1}^0.5 =  3.1185096160350177e-12
Newton iteration   4energy = 8.615916407950332<A u 4 , A u 4 >_{-1}^0.5 =  1.110429334265253e-14
loadstep 46
Newton iteration   0energy = 8.611956580310858<A u 0 , A u 0 >_{-1}^0.5 =  0.004136494896624677
Newton iteration   1energy = 8.611948129390502<A u 1 , A u 1 >_{-1}^0.5 =  0.0001707580288323152
Newton iteration   2energy = 8.611948114804498<A u 2 , A u 2 >_{-1}^0.5 =  2.9088719186477544e-07
Newton iteration   3energy = 8.611948114804452<A u 3 , A u 3 >_{-1}^0.5 =  2.305393316626788e-12
Newton iteration   4energy = 8.611948114804456<A u 4 , A u 4 >_{-1}^0.5 =  1.2157063268037797e-14
loadstep 47
Newton iteration   0energy = 8.607971444634586<A u 0 , A u 0 >_{-1}^0.5 =  0.004071812198364899
Newton iteration   1energy = 8.607963252398571<A u 1 , A u 1 >_{-1}^0.5 =  0.0001605046079768612
Newton iteration   2energy = 8.607963239511943<A u 2 , A u 2 >_{-1}^0.5 =  2.5380125196407897e-07
Newton iteration   3energy = 8.60796323951191<A u 3 , A u 3 >_{-1}^0.5 =  1.710252507370915e-12
Newton iteration   4energy = 8.607963239511916<A u 4 , A u 4 >_{-1}^0.5 =  1.2290069453583734e-14
loadstep 48
Newton iteration   0energy = 8.603970242593698<A u 0 , A u 0 >_{-1}^0.5 =  0.0040098173792995325
Newton iteration   1energy = 8.603962294699814<A u 1 , A u 1 >_{-1}^0.5 =  0.00015110889702384532
Newton iteration   2energy = 8.60396228327801<A u 2 , A u 2 >_{-1}^0.5 =  2.219928560793886e-07
Newton iteration   3energy = 8.603962283277987<A u 3 , A u 3 >_{-1}^0.5 =  1.2781909165814276e-12
Newton iteration   4energy = 8.603962283277989<A u 4 , A u 4 >_{-1}^0.5 =  1.2774778602252051e-14
loadstep 49
Newton iteration   0energy = 8.599953446612274<A u 0 , A u 0 >_{-1}^0.5 =  0.003950354164065159
Newton iteration   1energy = 8.599945729764308<A u 1 , A u 1 >_{-1}^0.5 =  0.00014248411538807357
Newton iteration   2energy = 8.599945719609346<A u 2 , A u 2 >_{-1}^0.5 =  1.9464412525932455e-07
Newton iteration   3energy = 8.599945719609325<A u 3 , A u 3 >_{-1}^0.5 =  9.577059269412203e-13
Newton iteration   4energy = 8.599945719609325<A u 4 , A u 4 >_{-1}^0.5 =  1.1386571464267781e-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

\[E(v) = \int_{\Omega} \varepsilon \vert \nabla v \vert^2~+~v^2(1-v^2) ~ dx\]

i.e. the solution to the Allen-Cahn equation solves

\[\partial_t u = \frac{\delta E}{\delta u}\]

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:

\[M u^{n+1} - M u^n = \Delta t \underbrace{\frac{\delta E}{\delta u}}_{=:A(u)} (u^{n+1})\]

which we can interpreted as a nonlinear minimization problem again with the energy

\[E^{IE}(v) = \int_{\Omega} \frac{\varepsilon}{2} \vert \nabla v \vert^2~+~v^2(1-v^2) + \frac{1}{2\Delta t} \vert v - u^n \vert^2 ~ dx\]

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.4145019207496362<A u 0 , A u 0 >_{-1}^0.5 =  0.28092704638147636
Newton iteration   1energy = 0.37689785802772957<A u 1 , A u 1 >_{-1}^0.5 =  0.019174370471939796
Newton iteration   2energy = 0.3767134210404821<A u 2 , A u 2 >_{-1}^0.5 =  9.628937134596328e-05
Newton iteration   3energy = 0.3767134164045804<A u 3 , A u 3 >_{-1}^0.5 =  2.505456303796458e-09
Newton iteration   4energy = 0.3767134164045804<A u 4 , A u 4 >_{-1}^0.5 =  2.8167247591431503e-16
t =  0.1
Newton iteration   0energy = 0.34388128652385935<A u 0 , A u 0 >_{-1}^0.5 =  0.2360393474078292
Newton iteration   1energy = 0.31710944329874896<A u 1 , A u 1 >_{-1}^0.5 =  0.013442999343193951
Newton iteration   2energy = 0.31701887934635165<A u 2 , A u 2 >_{-1}^0.5 =  4.660092984274442e-05
Newton iteration   3energy = 0.31701887826051933<A u 3 , A u 3 >_{-1}^0.5 =  5.768048486573859e-10
Newton iteration   4energy = 0.3170188782605194<A u 4 , A u 4 >_{-1}^0.5 =  3.354660656138913e-16
t =  0.2
Newton iteration   0energy = 0.295494356513846<A u 0 , A u 0 >_{-1}^0.5 =  0.18345925931027088
Newton iteration   1energy = 0.2791640303389012<A u 1 , A u 1 >_{-1}^0.5 =  0.008014651163108922
Newton iteration   2energy = 0.27913186993623224<A u 2 , A u 2 >_{-1}^0.5 =  1.6250158077613474e-05
Newton iteration   3energy = 0.279131869804198<A u 3 , A u 3 >_{-1}^0.5 =  6.857117247134904e-11
Newton iteration   4energy = 0.279131869804198<A u 4 , A u 4 >_{-1}^0.5 =  3.7828954071306115e-16
t =  0.30000000000000004
Newton iteration   0energy = 0.26692789507920534<A u 0 , A u 0 >_{-1}^0.5 =  0.1334965893056886
Newton iteration   1energy = 0.25820503551107077<A u 1 , A u 1 >_{-1}^0.5 =  0.004188513106581715
Newton iteration   2energy = 0.258196257629024<A u 2 , A u 2 >_{-1}^0.5 =  4.3667568189871645e-06
Newton iteration   3energy = 0.2581962576194896<A u 3 , A u 3 >_{-1}^0.5 =  4.850620349308043e-12
Newton iteration   4energy = 0.25819625761948956<A u 4 , A u 4 >_{-1}^0.5 =  3.345785440454107e-16
t =  0.4
Newton iteration   0energy = 0.25204311423689185<A u 0 , A u 0 >_{-1}^0.5 =  0.09236175483868572
Newton iteration   1energy = 0.24783887867786306<A u 1 , A u 1 >_{-1}^0.5 =  0.0019843467589302334
Newton iteration   2energy = 0.2478369092241839<A u 2 , A u 2 >_{-1}^0.5 =  9.685217012146076e-07
Newton iteration   3energy = 0.24783690922371493<A u 3 , A u 3 >_{-1}^0.5 =  2.34741928405964e-13
Newton iteration   4energy = 0.24783690922371482<A u 4 , A u 4 >_{-1}^0.5 =  3.7019931635429417e-16
t =  0.5
Newton iteration   0energy = 0.24499322447001157<A u 0 , A u 0 >_{-1}^0.5 =  0.06164684190451959
Newton iteration   1energy = 0.24311100787346115<A u 1 , A u 1 >_{-1}^0.5 =  0.0008779623506489436
Newton iteration   2energy = 0.24311062240965625<A u 2 , A u 2 >_{-1}^0.5 =  1.8822078759980443e-07
Newton iteration   3energy = 0.24311062240963857<A u 3 , A u 3 >_{-1}^0.5 =  8.812738401378623e-15
t =  0.6
Newton iteration   0energy = 0.24187354814794007<A u 0 , A u 0 >_{-1}^0.5 =  0.0401663587565137
Newton iteration   1energy = 0.2410718102821203<A u 1 , A u 1 >_{-1}^0.5 =  0.000371536748024391
Newton iteration   2energy = 0.24107174125819195<A u 2 , A u 2 >_{-1}^0.5 =  3.366894131780417e-08
Newton iteration   3energy = 0.24107174125819136<A u 3 , A u 3 >_{-1}^0.5 =  5.177430126156407e-16
t =  0.7
Newton iteration   0energy = 0.24055438873764573<A u 0 , A u 0 >_{-1}^0.5 =  0.02578203385924664
Newton iteration   1energy = 0.2402233339155409<A u 1 , A u 1 >_{-1}^0.5 =  0.00015331214259509088
Newton iteration   2energy = 0.2402233221629405<A u 2 , A u 2 >_{-1}^0.5 =  5.795968720638723e-09
Newton iteration   3energy = 0.24022332216294048<A u 3 , A u 3 >_{-1}^0.5 =  4.1383921569936535e-16
t =  0.7999999999999999
Newton iteration   0energy = 0.2400118618581594<A u 0 , A u 0 >_{-1}^0.5 =  0.016425332383409572
Newton iteration   1energy = 0.23987730469401894<A u 1 , A u 1 >_{-1}^0.5 =  6.283809116183802e-05
Newton iteration   2energy = 0.23987730271968508<A u 2 , A u 2 >_{-1}^0.5 =  1.0154930579076878e-09
Newton iteration   3energy = 0.23987730271968513<A u 3 , A u 3 >_{-1}^0.5 =  4.6394360215478465e-16
t =  0.8999999999999999
Newton iteration   0energy = 0.2397915819363539<A u 0 , A u 0 >_{-1}^0.5 =  0.010464445156609927
Newton iteration   1energy = 0.2397369188905994<A u 1 , A u 1 >_{-1}^0.5 =  2.620620881243329e-05
Newton iteration   2energy = 0.23973691854721507<A u 2 , A u 2 >_{-1}^0.5 =  1.9994608625477876e-10
Newton iteration   3energy = 0.23973691854721502<A u 3 , A u 3 >_{-1}^0.5 =  4.712449072357031e-16
t =  0.9999999999999999
Newton iteration   0energy = 0.23970186094053136<A u 0 , A u 0 >_{-1}^0.5 =  0.006735415826965045
Newton iteration   1energy = 0.2396792028920524<A u 1 , A u 1 >_{-1}^0.5 =  1.1556763084997694e-05
Newton iteration   2energy = 0.23967920282527277<A u 2 , A u 2 >_{-1}^0.5 =  5.099460594642426e-11
Newton iteration   3energy = 0.2396792028252729<A u 3 , A u 3 >_{-1}^0.5 =  4.3603056960577796e-16
t =  1.0999999999999999
Newton iteration   0energy = 0.23966435830447483<A u 0 , A u 0 >_{-1}^0.5 =  0.004452542361403728
Newton iteration   1energy = 0.23965445350959919<A u 1 , A u 1 >_{-1}^0.5 =  5.694142646688917e-06
Newton iteration   2energy = 0.23965445349338754<A u 2 , A u 2 >_{-1}^0.5 =  1.772503968582708e-11
Newton iteration   3energy = 0.2396544534933875<A u 3 , A u 3 >_{-1}^0.5 =  4.506057912655227e-16
t =  1.2
Newton iteration   0energy = 0.23964767142737936<A u 0 , A u 0 >_{-1}^0.5 =  0.003097908141817561
Newton iteration   1energy = 0.23964287580252738<A u 1 , A u 1 >_{-1}^0.5 =  3.2840536759779764e-06
Newton iteration   2energy = 0.23964287579713486<A u 2 , A u 2 >_{-1}^0.5 =  7.767219511989633e-12
Newton iteration   3energy = 0.2396428757971348<A u 3 , A u 3 >_{-1}^0.5 =  4.61045832186731e-16
t =  1.3
Newton iteration   0energy = 0.2396393498836377<A u 0 , A u 0 >_{-1}^0.5 =  0.002326255780763519
Newton iteration   1energy = 0.23963664545354452<A u 1 , A u 1 >_{-1}^0.5 =  2.2181767038734202e-06
Newton iteration   2energy = 0.23963664545108435<A u 2 , A u 2 >_{-1}^0.5 =  3.983596215905177e-12
Newton iteration   3energy = 0.23963664545108426<A u 3 , A u 3 >_{-1}^0.5 =  4.282835092824085e-16
t =  1.4000000000000001
Newton iteration   0energy = 0.2396344792626695<A u 0 , A u 0 >_{-1}^0.5 =  0.0019006816819442077
Newton iteration   1energy = 0.2396326736515232<A u 1 , A u 1 >_{-1}^0.5 =  1.687946260850493e-06
Newton iteration   2energy = 0.23963267365009858<A u 2 , A u 2 >_{-1}^0.5 =  2.2982453014628886e-12
Newton iteration   3energy = 0.23963267365009855<A u 3 , A u 3 >_{-1}^0.5 =  4.3568724144101285e-16
t =  1.5000000000000002
Newton iteration   0energy = 0.2396311154900338<A u 0 , A u 0 >_{-1}^0.5 =  0.0016629280504841238
Newton iteration   1energy = 0.23962973322336592<A u 1 , A u 1 >_{-1}^0.5 =  1.3855651852122846e-06
Newton iteration   2energy = 0.2396297332224059<A u 2 , A u 2 >_{-1}^0.5 =  1.4586272866410796e-12
Newton iteration   3energy = 0.23962973322240597<A u 3 , A u 3 >_{-1}^0.5 =  4.4042630649306477e-16
t =  1.6000000000000003
Newton iteration   0energy = 0.23962848049094232<A u 0 , A u 0 >_{-1}^0.5 =  0.0015187632040499007
Newton iteration   1energy = 0.2396273274180997<A u 1 , A u 1 >_{-1}^0.5 =  1.1887244241389382e-06
Newton iteration   2energy = 0.23962732741739323<A u 2 , A u 2 >_{-1}^0.5 =  1.0010925224110844e-12
Newton iteration   3energy = 0.23962732741739318<A u 3 , A u 3 >_{-1}^0.5 =  4.4047895924105704e-16
t =  1.7000000000000004
Newton iteration   0energy = 0.2396262539867423<A u 0 , A u 0 >_{-1}^0.5 =  0.0014193843873494107
Newton iteration   1energy = 0.23962524682330955<A u 1 , A u 1 >_{-1}^0.5 =  1.045632909422474e-06
Newton iteration   2energy = 0.2396252468227629<A u 2 , A u 2 >_{-1}^0.5 =  7.300861400170568e-13
Newton iteration   3energy = 0.23962524682276293<A u 3 , A u 3 >_{-1}^0.5 =  4.513659338716933e-16
t =  1.8000000000000005
Newton iteration   0energy = 0.23962429644294805<A u 0 , A u 0 >_{-1}^0.5 =  0.0013419591604952733
Newton iteration   1energy = 0.2396233961271811<A u 1 , A u 1 >_{-1}^0.5 =  9.33053216472548e-07
Newton iteration   2energy = 0.2396233961267457<A u 2 , A u 2 >_{-1}^0.5 =  5.563795108964307e-13
Newton iteration   3energy = 0.23962339612674574<A u 3 , A u 3 >_{-1}^0.5 =  4.0552927438094465e-16
t =  1.9000000000000006
Newton iteration   0energy = 0.23962254072403263<A u 0 , A u 0 >_{-1}^0.5 =  0.0012763226584933272
Newton iteration   1energy = 0.2396217263037931<A u 1 , A u 1 >_{-1}^0.5 =  8.399033658894825e-07
Newton iteration   2energy = 0.23962172630344045<A u 2 , A u 2 >_{-1}^0.5 =  4.3696359967523316e-13
Newton iteration   3energy = 0.23962172630344042<A u 3 , A u 3 >_{-1}^0.5 =  4.279057390248914e-16
t =  2.0000000000000004
Newton iteration   0energy = 0.2396209495967649<A u 0 , A u 0 >_{-1}^0.5 =  0.0012179715961899576
Newton iteration   1energy = 0.23962020792824323<A u 1 , A u 1 >_{-1}^0.5 =  7.604668960240027e-07
Newton iteration   2energy = 0.23962020792795402<A u 2 , A u 2 >_{-1}^0.5 =  3.502994241571864e-13
Newton iteration   3energy = 0.2396202079279541<A u 3 , A u 3 >_{-1}^0.5 =  4.1540976898622703e-16
t =  2.1000000000000005
Newton iteration   0energy = 0.2396194989264497<A u 0 , A u 0 >_{-1}^0.5 =  0.0011648358763689138
Newton iteration   1energy = 0.23961882055016812<A u 1 , A u 1 >_{-1}^0.5 =  6.914942047541799e-07
Newton iteration   2energy = 0.23961882054992892<A u 2 , A u 2 >_{-1}^0.5 =  2.849344039398136e-13
Newton iteration   3energy = 0.23961882054992895<A u 3 , A u 3 >_{-1}^0.5 =  4.022060791912109e-16
t =  2.2000000000000006
Newton iteration   0energy = 0.2396181709174179<A u 0 , A u 0 >_{-1}^0.5 =  0.001115880689979333
Newton iteration   1energy = 0.23961754835794208<A u 1 , A u 1 >_{-1}^0.5 =  6.309368258332487e-07
Newton iteration   2energy = 0.23961754835774315<A u 2 , A u 2 >_{-1}^0.5 =  2.342351024452693e-13
Newton iteration   3energy = 0.2396175483577431<A u 3 , A u 3 >_{-1}^0.5 =  4.124775316997188e-16
t =  2.3000000000000007
Newton iteration   0energy = 0.23961695130021216<A u 0 , A u 0 >_{-1}^0.5 =  0.0010705168654718392
Newton iteration   1energy = 0.2396163783254567<A u 1 , A u 1 >_{-1}^0.5 =  5.773776868941566e-07
Newton iteration   2energy = 0.23961637832529006<A u 2 , A u 2 >_{-1}^0.5 =  1.9415448405273936e-13
Newton iteration   3energy = 0.23961637832529<A u 3 , A u 3 >_{-1}^0.5 =  4.0997221812292823e-16
t =  2.400000000000001
Newton iteration   0energy = 0.23961582808585116<A u 0 , A u 0 >_{-1}^0.5 =  0.0010283540627855545
Newton iteration   1energy = 0.23961529935305362<A u 1 , A u 1 >_{-1}^0.5 =  5.297627567863049e-07
Newton iteration   2energy = 0.23961529935291334<A u 2 , A u 2 >_{-1}^0.5 =  1.6199821162823026e-13
Newton iteration   3energy = 0.23961529935291334<A u 3 , A u 3 >_{-1}^0.5 =  4.0039485505058225e-16
t =  2.500000000000001
Newton iteration   0energy = 0.2396147909550374<A u 0 , A u 0 >_{-1}^0.5 =  0.0009890970729080236
Newton iteration   1energy = 0.2396143018177979<A u 1 , A u 1 >_{-1}^0.5 =  4.872666035318775e-07
Newton iteration   2energy = 0.2396143018176792<A u 2 , A u 2 >_{-1}^0.5 =  1.3598853043606795e-13
Newton iteration   3energy = 0.2396143018176792<A u 3 , A u 3 >_{-1}^0.5 =  4.323276194821206e-16
t =  2.600000000000001
Newton iteration   0energy = 0.23961383091454508<A u 0 , A u 0 >_{-1}^0.5 =  0.0009525015914657844
Newton iteration   1energy = 0.23961337730105753<A u 1 , A u 1 >_{-1}^0.5 =  4.4921981868305184e-07
Newton iteration   2energy = 0.23961337730095666<A u 2 , A u 2 >_{-1}^0.5 =  1.1473288840449472e-13
Newton iteration   3energy = 0.2396133773009567<A u 3 , A u 3 >_{-1}^0.5 =  4.1675889114543924e-16
t =  2.700000000000001
Newton iteration   0energy = 0.2396129400737677<A u 0 , A u 0 >_{-1}^0.5 =  0.0009183547757921798
Newton iteration   1energy = 0.23961251839967956<A u 1 , A u 1 >_{-1}^0.5 =  4.150665657909605e-07
Newton iteration   2energy = 0.2396125183995935<A u 2 , A u 2 >_{-1}^0.5 =  9.724524553808296e-14
t =  2.800000000000001
Newton iteration   0energy = 0.2396121114812304<A u 0 , A u 0 >_{-1}^0.5 =  0.0008864662194052857
Newton iteration   1energy = 0.23961171858168248<A u 1 , A u 1 >_{-1}^0.5 =  3.843377621229476e-07
Newton iteration   2energy = 0.23961171858160873<A u 2 , A u 2 >_{-1}^0.5 =  8.279056742710236e-14
t =  2.9000000000000012
Newton iteration   0energy = 0.2396113389953494<A u 0 , A u 0 >_{-1}^0.5 =  0.0008566633749443014
Newton iteration   1energy = 0.2396109720692427<A u 1 , A u 1 >_{-1}^0.5 =  3.5663295477607706e-07
Newton iteration   2energy = 0.23961097206917908<A u 2 , A u 2 >_{-1}^0.5 =  7.079233340119339e-14
t =  3.0000000000000013
Newton iteration   0energy = 0.2396106171776509<A u 0 , A u 0 >_{-1}^0.5 =  0.0008287889263646606
Newton iteration   1energy = 0.23961027374068344<A u 1 , A u 1 >_{-1}^0.5 =  3.316073784868388e-07
Newton iteration   2energy = 0.2396102737406285<A u 2 , A u 2 >_{-1}^0.5 =  6.084230609935835e-14
t =  3.1000000000000014
Newton iteration   0energy = 0.23960994120243975<A u 0 , A u 0 >_{-1}^0.5 =  0.000802699050678995
Newton iteration   1energy = 0.23960961904696895<A u 1 , A u 1 >_{-1}^0.5 =  3.0896230208916104e-07
Newton iteration   2energy = 0.2396096190469213<A u 2 , A u 2 >_{-1}^0.5 =  5.2419355816600374e-14
t =  3.2000000000000015
Newton iteration   0energy = 0.23960930677943418<A u 0 , A u 0 >_{-1}^0.5 =  0.0007782621114844118
Newton iteration   1energy = 0.23960900393990864<A u 1 , A u 1 >_{-1}^0.5 =  2.8843758042950464e-07
Newton iteration   2energy = 0.239609003939867<A u 2 , A u 2 >_{-1}^0.5 =  4.53837460691867e-14
t =  3.3000000000000016
Newton iteration   0energy = 0.23960871008705956<A u 0 , A u 0 >_{-1}^0.5 =  0.0007553575814402505
Newton iteration   1energy = 0.2396084248101213<A u 1 , A u 1 >_{-1}^0.5 =  2.6980575459079707e-07
Newton iteration   2energy = 0.23960842481008487<A u 2 , A u 2 >_{-1}^0.5 =  3.943490918739899e-14
t =  3.4000000000000017
Newton iteration   0energy = 0.239608147714714<A u 0 , A u 0 >_{-1}^0.5 =  0.0007338751008235469
Newton iteration   1energy = 0.23960787843327308<A u 1 , A u 1 >_{-1}^0.5 =  2.528672818809477e-07
Newton iteration   2energy = 0.23960787843324113<A u 2 , A u 2 >_{-1}^0.5 =  3.4395575841844475e-14
t =  3.5000000000000018
Newton iteration   0energy = 0.2396076166126835<A u 0 , A u 0 >_{-1}^0.5 =  0.0007137136279143667
Newton iteration   1energy = 0.23960736192339643<A u 1 , A u 1 >_{-1}^0.5 =  2.3744661572988932e-07
Newton iteration   2energy = 0.23960736192336823<A u 2 , A u 2 >_{-1}^0.5 =  3.010172589440937e-14
t =  3.600000000000002
Newton iteration   0energy = 0.23960711404861693<A u 0 , A u 0 >_{-1}^0.5 =  0.0006947806591329083
Newton iteration   1energy = 0.23960687269229805<A u 1 , A u 1 >_{-1}^0.5 =  2.2338894231226247e-07
Newton iteration   2energy = 0.23960687269227302<A u 2 , A u 2 >_{-1}^0.5 =  2.6431184772178026e-14
t =  3.700000000000002
Newton iteration   0energy = 0.23960663756966022<A u 0 , A u 0 >_{-1}^0.5 =  0.0006769915073033805
Newton iteration   1energy = 0.2396064084142239<A u 1 , A u 1 >_{-1}^0.5 =  2.1055743624060828e-07
Newton iteration   2energy = 0.2396064084142018<A u 2 , A u 2 >_{-1}^0.5 =  2.3344047294241317e-14
t =  3.800000000000002
Newton iteration   0energy = 0.23960618496947494<A u 0 , A u 0 >_{-1}^0.5 =  0.0006602686315022897
Newton iteration   1energy = 0.23960596699506795<A u 1 , A u 1 >_{-1}^0.5 =  1.988309330958618e-07
Newton iteration   2energy = 0.2396059669950483<A u 2 , A u 2 >_{-1}^0.5 =  2.0667323036294112e-14
t =  3.900000000000002
Newton iteration   0energy = 0.23960575425948313<A u 0 , A u 0 >_{-1}^0.5 =  0.0006445410144724198
Newton iteration   1energy = 0.23960554654551278<A u 1 , A u 1 >_{-1}^0.5 =  1.881019423294816e-07
Newton iteration   2energy = 0.2396055465454951<A u 2 , A u 2 >_{-1}^0.5 =  1.8392439447062177e-14
t =  4.000000000000002
Newton iteration   0energy = 0.239605343643775<A u 0 , A u 0 >_{-1}^0.5 =  0.0006297435848349288
Newton iteration   1energy = 0.2396051453575803<A u 1 , A u 1 >_{-1}^0.5 =  1.7827494164571733e-07
Newton iteration   2energy = 0.23960514535756447<A u 2 , A u 2 >_{-1}^0.5 =  1.6359534775821174e-14
t =  4.100000000000001
Newton iteration   0energy = 0.23960495149718894<A u 0 , A u 0 >_{-1}^0.5 =  0.000615816681932275
Newton iteration   1energy = 0.2396047618841374<A u 1 , A u 1 >_{-1}^0.5 =  1.6926490629353927e-07
Newton iteration   2energy = 0.23960476188412316<A u 2 , A u 2 >_{-1}^0.5 =  1.4650955748249466e-14
t =  4.200000000000001
Newton iteration   0energy = 0.23960457634614438<A u 0 , A u 0 >_{-1}^0.5 =  0.000602705561393757
Newton iteration   1energy = 0.23960439472096595<A u 1 , A u 1 >_{-1}^0.5 =  1.6099603651134076e-07
Newton iteration   2energy = 0.23960439472095302<A u 2 , A u 2 >_{-1}^0.5 =  1.316632014806186e-14
t =  4.300000000000001
Newton iteration   0energy = 0.23960421685186575<A u 0 , A u 0 >_{-1}^0.5 =  0.0005903599395996324
Newton iteration   1energy = 0.23960404259105958<A u 1 , A u 1 >_{-1}^0.5 =  1.534006526259395e-07
Newton iteration   2energy = 0.2396040425910478<A u 2 , A u 2 >_{-1}^0.5 =  1.1891481034967456e-14
t =  4.4
Newton iteration   0energy = 0.2396038717956791<A u 0 , A u 0 >_{-1}^0.5 =  0.0005787335752184119
Newton iteration   1energy = 0.23960370433085504<A u 1 , A u 1 >_{-1}^0.5 =  1.4641823370105469e-07
Newton iteration   2energy = 0.23960370433084427<A u 2 , A u 2 >_{-1}^0.5 =  1.0716509618600795e-14
t =  4.5
Newton iteration   0energy = 0.23960354006611384<A u 0 , A u 0 >_{-1}^0.5 =  0.0005677838859552442
Newton iteration   1energy = 0.23960337887814379<A u 1 , A u 1 >_{-1}^0.5 =  1.3999457888852992e-07
Newton iteration   2energy = 0.23960337887813393<A u 2 , A u 2 >_{-1}^0.5 =  9.745816221516653e-15
t =  4.6
Newton iteration   0energy = 0.2396032206475711<A u 0 , A u 0 >_{-1}^0.5 =  0.0005574715986072078
Newton iteration   1energy = 0.23960306526144695<A u 1 , A u 1 >_{-1}^0.5 =  1.3408107469814374e-07
Newton iteration   2energy = 0.2396030652614379<A u 2 , A u 2 >_{-1}^0.5 =  8.896636967396773e-15
t =  4.699999999999999
Newton iteration   0energy = 0.23960291261035707<A u 0 , A u 0 >_{-1}^0.5 =  0.0005477604304859979
Newton iteration   1energy = 0.23960276259066243<A u 1 , A u 1 >_{-1}^0.5 =  1.2863405339167213e-07
Newton iteration   2energy = 0.23960276259065416<A u 2 , A u 2 >_{-1}^0.5 =  8.158359737324676e-15
t =  4.799999999999999
Newton iteration   0energy = 0.23960261510190303<A u 0 , A u 0 >_{-1}^0.5 =  0.0005386168002506355
Newton iteration   1energy = 0.2396024700488202<A u 1 , A u 1 >_{-1}^0.5 =  1.2361423087280676e-07
Newton iteration   2energy = 0.2396024700488126<A u 2 , A u 2 >_{-1}^0.5 =  7.475013030957406e-15
t =  4.899999999999999
Newton iteration   0energy = 0.23960232733902043<A u 0 , A u 0 >_{-1}^0.5 =  0.0005300095661919717
Newton iteration   1energy = 0.2396021868848042<A u 1 , A u 1 >_{-1}^0.5 =  1.1898621270787481e-07
Newton iteration   2energy = 0.2396021868847971<A u 2 , A u 2 >_{-1}^0.5 =  6.9022263020530444e-15
t =  4.999999999999998

Minimal energy extension (postscript in unit-2.1.3 )

\[u \in V^{ho,disc}, \quad u^{lo,cont} \in V^{lo,cont}, \quad \lambda \in V^{lo,disc},\]
[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 = FESpace([fes_ho, fes_lo, fes_lam])
uho, ulo, lam = fes.TrialFunction()
\[\int_{\Omega} \frac12 \Vert \nabla u \Vert^2 - u + \sum_T \sum_{V \in V(T)} ((u-u^{lo})\cdot \lambda)|_{V} \longrightarrow \operatorname{min}!\]
[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.39392955469293095
Newton iteration  1
err =  1.7898870223932246e-15

The minimization problem is solved by the solution of the PDE:

\[\int_{\Omega} \nabla u \cdot \nabla v = \int_{\Omega} 1 \cdot v \quad \forall ~ v \in V^{ho,disc}\]

under the constraint

\[u(v) = u^{lo}(v) \quad \text{ for all vertices } v \in V(T) \text{ for all } T.\]
[ ]: