Debian Codegraph @

demo/documented/bcs/cpp/main.cpp

raw
1 // Copyright (C) 2008 Anders Logg
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // First added: 2008-05-23
19 // Last changed: 2012-07-05
20 //
21 // This demo illustrates how to set boundary conditions for meshes
22 // that include boundary indicators. The mesh used in this demo was
23 // generated with VMTK (http://www.vmtk.org/).
24
25 #include <dolfin.h>
26 #include "Poisson.h"
27
28 using namespace dolfin;
29
30 int main()
31 {
32 // Create mesh and finite element
33 auto mesh = std::make_shared<Mesh>("../aneurysm.xml.gz");
34
35 // Define variational problem
36 auto f = std::make_shared<Constant>(0.0);
37 auto V = std::make_shared<Poisson::FunctionSpace>(mesh);
38 Poisson::BilinearForm a(V, V);
39 Poisson::LinearForm L(V);
40 L.f = f;
41
42 // Define boundary condition values
43 auto u0 = std::make_shared<Constant>(0.0);
44 auto u1 = std::make_shared<Constant>(1.0);
45 auto u2 = std::make_shared<Constant>(2.0);
46 auto u3 = std::make_shared<Constant>(3.0);
47
48 // Define boundary conditions
49 DirichletBC bc0(V, u0, 0);
50 DirichletBC bc1(V, u1, 1);
51 DirichletBC bc2(V, u2, 2);
52 DirichletBC bc3(V, u3, 3);
53 std::vector<const DirichletBC*> bcs{{&bc0, &bc1, &bc2, &bc3}};
54
55 // Set PETSc MUMPS paramter (this is required to prevent a memory
56 // error in some cases when using MUMPS LU solver).
57 #ifdef HAS_PETSC
58 PETScOptions::set("mat_mumps_icntl_14", 40.0);
59 #endif
60
61 // Compute solution
62 Function u(V);
63 solve(a == L, u, bcs);
64
65 // Write solution to file
66 File file("u.pvd");
67 file << u;
68
69 return 0;
70 }