Debian Codegraph @

demo/documented/subdomains/cpp/main.cpp

raw
1 // Copyright (C) 2007-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: 2007-04-24
19 // Last changed: 2011-01-25
20 //
21 // This demo program demonstrates how to mark sub domains
22 // of a mesh and store the sub domain markers as a mesh
23 // function to a DOLFIN XML file.
24 //
25 // The sub domain markers produced by this demo program
26 // are the ones used for the Stokes demo programs.
27
28 #include <dolfin.h>
29
30 using namespace dolfin;
31
32 int main()
33 {
34 set_log_level(1);
35
36 if (dolfin::MPI::size(MPI_COMM_WORLD) > 1)
37 {
38 std::cout << "This demo does not work in parallel" << std::endl;
39 return 0;
40 }
41
42 // Sub domain for no-slip (everything except inflow and outflow)
43 class Noslip : public SubDomain
44 {
45 bool inside(const Array<double>& x, bool on_boundary) const
46 {
47 return on_boundary;
48 }
49 };
50
51 // Sub domain for inflow (right)
52 class Inflow : public SubDomain
53 {
54 bool inside(const Array<double>& x, bool on_boundary) const
55 {
56 return x[0] > 1.0 - DOLFIN_EPS && on_boundary;
57 }
58 };
59
60 // Sub domain for outflow (left)
61 class Outflow : public SubDomain
62 {
63 bool inside(const Array<double>& x, bool on_boundary) const
64 {
65 return x[0] < DOLFIN_EPS && on_boundary;
66 }
67 };
68
69 // Read mesh
70 auto mesh = std::make_shared<Mesh>("../dolfin_fine.xml.gz");
71
72 // Create mesh functions over the cell facets
73 MeshFunction<std::size_t> sub_domains(mesh, mesh->topology().dim() - 1);
74 MeshFunction<double> sub_domains_double(mesh, mesh->topology().dim() - 1);
75 MeshFunction<bool> sub_domains_bool(mesh, mesh->topology().dim() - 1);
76
77 // Mark all facets as sub domain 3
78 sub_domains = 3;
79
80 // Mark no-slip facets as sub domain 0, 0.0
81 Noslip noslip;
82 noslip.mark(sub_domains, 0);
83 noslip.mark(sub_domains_double, 0.0);
84
85 // Mark inflow as sub domain 1, 0.1
86 Inflow inflow;
87 inflow.mark(sub_domains, 1);
88 inflow.mark(sub_domains_double, 0.1);
89
90 // Mark outflow as sub domain 2, 0.2
91 Outflow outflow;
92 outflow.mark(sub_domains, 2);
93 outflow.mark(sub_domains_double, 2);
94
95 // Save sub domains to file
96 File file("subdomains.xml");
97 file << sub_domains;
98
99 // Save sub domains to file
100 // FIXME: Not implemented
101 //File file_bool("subdomains_bool.xml");
102 //file_bool << sub_domains_bool;
103
104 // Save sub domains to file
105 File file_double("subdomains_double.xml");
106 file_double << sub_domains_double;
107 }