Debian Codegraph @

demo/undocumented/ale/cpp/main.cpp

raw
1 // Copyright (C) 2008-2009 Solveig Bruvoll and 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-02
19 // Last changed: 2012-07-05
20 //
21 // This demo demonstrates how to move the vertex coordinates
22 // of a boundary mesh and then updating the interior vertex
23 // coordinates of the original mesh by suitably interpolating
24 // the vertex coordinates (useful for implementation of ALE
25 // methods).
26
27 #include <dolfin.h>
28
29 using namespace dolfin;
30
31 int main()
32 {
33 // Create mesh
34 auto mesh = std::make_shared<UnitSquareMesh>(20, 20);
35
36 // Create boundary mesh
37 BoundaryMesh boundary(*mesh, "exterior");
38
39 // Move vertices in boundary
40 MeshGeometry& geometry = boundary.geometry();
41
42 std::vector<double> x(2);
43 for (VertexIterator v(boundary); !v.end(); ++v)
44 {
45 std::size_t i = v->index();
46 x[0] = geometry.x(i, 0)*3.0;
47 x[1] = geometry.x(i, 1) + 0.1*sin(5.0*x[0]);
48 geometry.set(i, x.data());
49 }
50
51 // Move mesh
52 ALE::move(mesh, boundary);
53
54 // Write mesh to file
55 File file("mesh_deformed.pvd");
56 file << *mesh;
57
58 return 0;
59 }