Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Dirichlet BC control of the Stokes equations http://www.doln-adjoint.org/en/latest/document...

Dirichlet BC control of the Stokes equations


Section author: Simon W. Funke <simon@simula.no>, Andr Massing <massing@simula.no>

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

subject to the Stokes equations

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:

from dolfin import *


from dolfin_adjoint import *

Next, we load the mesh. The mesh was generated with mshr; see make-mesh.py in the same directory.

mesh_xdmf = XDMFFile(mpi_comm_world(), "rectangle-less-circle.xdmf")


mesh = Mesh()
mesh_xdmf.read(mesh)

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_h = VectorElement("CG", mesh.ufl_cell(), 2)


Q_h = FiniteElement("CG", mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, V_h * Q_h)
V, Q = W.split()

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

facet_marker = FacetFunction("size_t", mesh)


facet_marker.set_all(10)
Circle().mark(facet_marker, 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.

# Set parameter values


nu = Constant(1) # Viscosity coefficient
gamma = Constant(10) # Nitsche penalty parameter
n = FacetNormal(mesh)
h = CellSize(mesh)

# Define boundary conditions


u_inflow = Expression(("x[1]*(10-x[1])/25", "0"))
noslip = DirichletBC(W.sub(0), (0, 0),
"on_boundary && (x[1] >= 9.9 || x[1] < 0.1)")
inflow = DirichletBC(W.sub(0), u_inflow, "on_boundary && x[0] <= 0.1")
bcs = [inflow, noslip]

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

a(u, p; v, q) = (u), (v) (u)n, vcircle


p, divv + pn, vcircle q, divu
L(u, p; v, q) = 0
Note that we only need to include boundary integrals over the circle, as other boundary terms vanish due to the
application of strong Dirichlet conditions.

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)

J = Functional(1./2*inner(grad(u), grad(u))*dx + alpha/2*inner(g, g)*ds(2))


m = Control(g)
Jhat = ReducedFunctional(J, m)

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

At iterate 10 f= 1.98909D+01 |proj g|= 1.12697D-04

At iterate 11 f= 1.98909D+01 |proj g|= 7.03065D-05

* * *

Tit = total number of iterations


Tnf = total number of function evaluations
Tnint = total number of segments explored during Cauchy searches
Skip = number of BFGS updates skipped
Nact = number of active bounds at final generalized Cauchy point
Projg = norm of the final projected gradient
F = final function value

* * *

N Tit Tnf Tnint Skip Nact Projg F


14384 11 13 1 0 0 7.031D-05 1.989D+01
F = 19.890932240156282

CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH

Cauchy time 0.000E+00 seconds.


Subspace minimization time 0.000E+00 seconds.
Line search time 0.000E+00 seconds.

3 of 5 10/03/2017 22:40
Dirichlet BC control of the Stokes equations http://www.doln-adjoint.org/en/latest/document...

Total User time 0.000E+00 seconds.

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.

The next image shows the associated velocity:

And the nal image shows the pressure:

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

You might also like