1
// Copyright (C) 2006-2008 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2006-02-09
5
// Last changed: 2008-12-12
7
// This demo solves the Stokes equations, using quadratic elements for
8
// the velocity and first degree elements for the pressure
9
// (Taylor-Hood elements). The sub domains for the different boundary
10
// conditions used in this simulation are computed by the demo program
11
// in src/demo/mesh/subdomains.
16
using namespace dolfin;
20
// Function for no-slip boundary condition for velocity
21
class Noslip : public Function
23
void eval(double* values, const double* x) const
30
// Function for inflow boundary condition for velocity
31
class Inflow : public Function
33
void eval(double* values, const double* x) const
35
values[0] = -sin(x[1]*DOLFIN_PI);
40
// Read mesh and sub domain markers
41
Mesh mesh("../../../../../data/meshes/dolfin-2.xml.gz");
44
MeshFunction<unsigned int> sub_domains(mesh, "../subdomains.xml.gz");
46
// Create function space and subspaces
47
StokesFunctionSpace W(mesh);
51
// Create functions for boundary conditions
56
// No-slip boundary condition for velocity
57
DirichletBC bc0(W0, noslip, sub_domains, 0);
59
// Inflow boundary condition for velocity
60
DirichletBC bc1(W0, inflow, sub_domains, 1);
62
// Boundary condition for pressure at outflow
63
DirichletBC bc2(W1, zero, sub_domains, 2);
65
// Collect boundary conditions
66
std::vector<BoundaryCondition*> bcs;
67
bcs.push_back(&bc0); bcs.push_back(&bc1); bcs.push_back(&bc2);
71
StokesBilinearForm a(W, W);
72
StokesLinearForm L(W);
74
VariationalProblem pde(a, L, bcs);
78
pde.set("linear solver", "direct");
87
// Save solution in VTK format
88
File ufile_pvd("velocity.pvd");
90
File pfile_pvd("pressure.pvd");