Debian Codegraph @

demo/undocumented/nonmatching-projection/cpp/main.cpp

raw
1 // Copyright (C) 2009 Garth N. Wells
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 // Modified by Anders Logg, 2011.
19 //
20 // First added: 2009-10-10
21 // Last changed: 2014-08-11
22 //
23 // This program demonstrates the L2 projection of a function onto a
24 // non-matching mesh.
25
26 #include <dolfin.h>
27 #include "P1_projection.h"
28 #include "P3.h"
29
30 using namespace dolfin;
31
32 class MyExpression : public Expression
33 {
34 public:
35
36 void eval(Array<double>& values, const Array<double>& x) const
37 {
38 values[0] = sin(10.0*x[0])*sin(10.0*x[1]);
39 }
40
41 };
42
43 int main()
44 {
45 if (dolfin::MPI::size(MPI_COMM_WORLD) > 1)
46 {
47 std::cout << "This demo does not work in parallel" << std::endl;
48 return 0;
49 }
50
51 // Create meshes
52 auto mesh0 = std::make_shared<UnitSquareMesh>(16, 16);
53 auto mesh1 = std::make_shared<UnitSquareMesh>(64, 64);
54
55 // Create P3 function space
56 auto V0 = std::make_shared<P3::FunctionSpace>(mesh0);
57
58 // Interpolate expression into V0
59 MyExpression e;
60 auto f0 = std::make_shared<Function>(V0);
61 f0->interpolate(e);
62
63 // Define variational problem
64 auto V1 = std::make_shared<P1_projection::FunctionSpace>(mesh1);
65 P1_projection::BilinearForm a(V1, V1);
66 P1_projection::LinearForm L(V1, f0);
67
68 // Compute solution
69 Function f1(V1);
70 solve(a == L, f1);
71
72 // Plot results
73 XDMFFile("f0.xdmf").write(*f0);
74 XDMFFile("f1.xdmf").write(f1);
75
76 return 0;
77 }