Professional Documents
Culture Documents
Nits Che
Nits Che
This example demonstrates how to optimise Dirichlet boundary conditions with the optimisation framework in doln-
adjoint using the Nitsche method.
A detailed introduction to the Nitsche method and its applications can be found in [2E-Nit71], [2E-Han05], [2E-BH07].
Problem definition
Consider the problem of minimising the compliance
1
2 2 in
min u u dx + g2 ds
g,u,p
u + p = 0 in
div u = 0 in
and Dirichlet boundary conditions
u = g on cirlce
u = f on in
u = 0 on walls
p = 0 on out
2
where is the domain of interest (visualised below), u : is the unknown velocity, p : is the
unknown pressure, is the viscosity, is the regularisation parameter, f denotes the value for the Dirichlet inow
boundary condition, and g is the control variable that species the Dirichlet boundary condition on the circle.
Physically, this setup corresponds to minimising the loss of ow energy into heat by actively controlling the in/outow
at the circle boundary. To avoid excessive control solutions, non-zero control values are penalised via the regularisation
term.
Implementation
First, the dolfin and dolfin_adjoint modules are imported:
Next, we load the mesh. The mesh was generated with mshr; see make-mesh.py in the same directory.
Then, we dene the discrete function spaces. A Taylor-Hood nite-element pair is a suitable choice for the Stokes
1 of 5 10/03/2017 22:40
Dirichlet BC control of the Stokes equations http://www.doln-adjoint.org/en/latest/document...
equations. The control function is the Dirichlet boundary value on the velocity eld and is hence be a function on the
velocity space (note: FEniCS cannot restrict functions to boundaries, hence the control is dened over the entire
domain).
v, q = TestFunctions(W)
x = TrialFunction(W)
u, p = split(x)
s = Function(W, name="State")
g = Function(V.collapse(), name="Control")
The Nitsche method requires the computation of boundary integrals over circle . Therefore, we need to create a
measure for these integrals, which will be accessible as ds(2) in the denition of the variational formulation.
class Circle(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and (x[0]-10)**2 + (x[1]-5)**2 < 3**2
ds = ds(subdomain_data=facet_marker)
Now we dene some parameters, including the Nitsche penalty parameter (typically 10), the mesh element size h,
the normal direction at the boundary n, and the strong Dirichlet boundary conditions apart from the circle boundary
where we will enforce the boundary condition via the Nitsche method.
The Dirichlet condition at the circle is enforced by the Nitsche approach. To begin with we derive the standard weak
formulation of the Stokes problem: Find u, p such that for all test functions v, q
a(u, p; v, q) = L(u, p; v, q)
with
To apply the symmetric Nitsche approach on the circle boundary, we introduce new boundary terms to the left hand
side a such that the resulting problem becomes symmetric, plus the Nitsche term h u, vcircle . Furthermore, we add
the same terms to the right hand side L with u substituted by the boundary value g. This yields the weak formulation:
a(u, v) = (u), (v) (u)n, vcircle (v)n, ucircle + u, vcircle
h
p, divv + pn, vcircle q, divu + qn, ucircle
L(u, v) = (v)n, gcircle + g, vcircle + qn, gcircle
h
In code, this becomes:
a = (nu*inner(grad(u), grad(v))*dx
2 of 5 10/03/2017 22:40
Dirichlet BC control of the Stokes equations http://www.doln-adjoint.org/en/latest/document...
- nu*inner(grad(u)*n, v)*ds(2)
- nu*inner(grad(v)*n, u)*ds(2)
+ gamma/h*nu*inner(u, v)*ds(2)
- inner(p, div(v))*dx
+ inner(p*n, v)*ds(2)
- inner(q, div(u))*dx
+ inner(q*n, u)*ds(2)
)
L = (- nu*inner(grad(v)*n, g)*ds(2)
+ gamma/h*nu*inner(g, v)*ds(2)
+ inner(q*n, g)*ds(2)
)
Next we assemble and solve the system once to record it with dolin-adjoint.
A, b = assemble_system(a, L, bcs)
solve(A, s.vector(), b)
Next we dene the functional of interest J , the optimisation parameter g, and derive the create the reduced functional.
u, p = split(s)
alpha = Constant(10)
Now, everything is set up to run the optimisation and to plot the results. By default, minimize uses the L-BFGS-B
algorithm.
g_opt = minimize(Jhat)
plot(g_opt, title="Optimised boundary")
g.assign(g_opt)
A, b = assemble_system(a, L, bcs)
solve(A, s.vector(), b)
plot(s.sub(0), title="Velocity")
plot(s.sub(1), title="Pressure")
interactive()
Results
The example code can be found in examples/stokes-bc-control in the dolfin-adjoint source tree, and executed
as follows:
$ python stokes-bc-control.pystokes_bc_control.py
...
At iterate 9 f= 1.98909D+01 |proj g|= 6.05347D-04
* * *
* * *
CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH
3 of 5 10/03/2017 22:40
Dirichlet BC control of the Stokes equations http://www.doln-adjoint.org/en/latest/document...
The results are visualised in the following images. The rst image shows the optimised control function, i.e. the
Dirichlet values on the circle boundary which minimise the loss of ow energy into heat.
4 of 5 10/03/2017 22:40
Dirichlet BC control of the Stokes equations http://www.doln-adjoint.org/en/latest/document...
[2E-BH07] Y.Bazilevs and T.J.R. Hughes. Weak imposition of Dirichlet boundary conditions in uid mechanics.
Computers & Fluids, 36(1):1226, 2007. doi:10.1016/j.compuid.2005.07.012.
[2E-Han05] PHansbo. Nitsches method for interface problems in computational mechanics. GAMM-Mitteilungen,
28(2):183206, 2005.
[2E-Nit71] J.Nitsche. ber ein Variationsprinzip zur Lsung von Dirichlet-Problemen bei Verwendung von
Teilrumen, die keinen Randbedingungen unterworfen sind. In Abhandlungen aus dem Mathematischen
Seminar der Universitt Hamburg, volume36, 915. Springer, 1971. doi:10.1007/BF02995904.
5 of 5 10/03/2017 22:40