| 1 |
// Copyright (C) 2010 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: 2010-02-08 |
| 19 |
// Last changed: 2012-07-05 |
| 20 |
// |
| 21 |
// This program demonstrates extrapolation of a P1 function to a P2 |
| 22 |
// function on the same mesh. This is useful for postprocessing a |
| 23 |
// computed dual approximation for use in an error estimate. |
| 24 |
|
| 25 |
#include <dolfin.h> |
| 26 |
#include "P1.h" |
| 27 |
#include "P2.h" |
| 28 |
|
| 29 |
using namespace dolfin; |
| 30 |
|
| 31 |
class Dual : public Expression |
| 32 |
{ |
| 33 |
public: |
| 34 |
|
| 35 |
void eval(Array<double>& values, const Array<double>& x) const |
| 36 |
{ |
| 37 |
values[0] = sin(5.0*x[0])*sin(5.0*x[1]); |
| 38 |
} |
| 39 |
|
| 40 |
}; |
| 41 |
|
| 42 |
int main() |
| 43 |
{ |
| 44 |
if (dolfin::MPI::size(MPI_COMM_WORLD) > 1) |
| 45 |
{ |
| 46 |
std::cout << "This demo does not work in parallel" << std::endl; |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
// Create mesh and function spaces |
| 51 |
auto mesh = std::make_shared<UnitSquareMesh>(8, 8); |
| 52 |
auto P1 = std::make_shared<P1::FunctionSpace>(mesh); |
| 53 |
auto P2 = std::make_shared<P2::FunctionSpace>(mesh); |
| 54 |
|
| 55 |
// Create exact dual |
| 56 |
Dual dual; |
| 57 |
|
| 58 |
// Create P1 approximation of exact dual |
| 59 |
Function z1(P1); |
| 60 |
z1.interpolate(dual); |
| 61 |
|
| 62 |
// Create P2 approximation from P1 approximation |
| 63 |
Function z2(P2); |
| 64 |
z2.extrapolate(z1); |
| 65 |
|
| 66 |
// Output extrapolations |
| 67 |
XDMFFile("z1.xdmf").write(z1); |
| 68 |
XDMFFile("z2.xdmf").write(z2); |
| 69 |
|
| 70 |
return 0; |
| 71 |
} |