| 1 |
// Copyright (C) 2008-2009 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-07-22 |
| 19 |
// Last changed: 2010-05-03 |
| 20 |
|
| 21 |
#include <memory> |
| 22 |
#include <dolfin.h> |
| 23 |
|
| 24 |
#include "forms/Poisson2DP1.h" |
| 25 |
#include "forms/Poisson2DP2.h" |
| 26 |
#include "forms/Poisson2DP3.h" |
| 27 |
#include "forms/THStokes2D.h" |
| 28 |
#include "forms/StabStokes2D.h" |
| 29 |
#include "forms/Elasticity3D.h" |
| 30 |
#include "forms/NSEMomentum3D.h" |
| 31 |
|
| 32 |
#define SIZE_2D 256 |
| 33 |
#define SIZE_3D 32 |
| 34 |
|
| 35 |
using namespace dolfin; |
| 36 |
|
| 37 |
double bench_form(std::string form_name, double (*foo)(Form&)) |
| 38 |
{ |
| 39 |
if (form_name == "poisson1") |
| 40 |
{ |
| 41 |
auto mesh = std::make_shared<UnitSquareMesh>(SIZE_2D, SIZE_2D); |
| 42 |
auto V = std::make_shared<Poisson2DP1::FunctionSpace>(mesh); |
| 43 |
Poisson2DP1::BilinearForm form(V, V); |
| 44 |
return foo(form); |
| 45 |
} |
| 46 |
else if (form_name == "poisson2") |
| 47 |
{ |
| 48 |
auto mesh = std::make_shared<UnitSquareMesh>(SIZE_2D, SIZE_2D); |
| 49 |
auto V = std::make_shared<Poisson2DP2::FunctionSpace>(mesh); |
| 50 |
Poisson2DP2::BilinearForm form(V, V); |
| 51 |
return foo(form); |
| 52 |
} |
| 53 |
else if (form_name == "poisson3") |
| 54 |
{ |
| 55 |
auto mesh = std::make_shared<UnitSquareMesh>(SIZE_2D, SIZE_2D); |
| 56 |
auto V = std::make_shared<Poisson2DP3::FunctionSpace>(mesh); |
| 57 |
Poisson2DP3::BilinearForm form(V, V); |
| 58 |
return foo(form); |
| 59 |
} |
| 60 |
else if (form_name == "stokes") |
| 61 |
{ |
| 62 |
auto mesh = std::make_shared<UnitSquareMesh>(SIZE_2D, SIZE_2D); |
| 63 |
auto V = std::make_shared<THStokes2D::FunctionSpace>(mesh); |
| 64 |
THStokes2D::BilinearForm form(V, V); |
| 65 |
return foo(form); |
| 66 |
} |
| 67 |
else if (form_name == "stabilization") |
| 68 |
{ |
| 69 |
auto mesh = std::make_shared<UnitSquareMesh>(SIZE_2D, SIZE_2D); |
| 70 |
auto V = std::make_shared<StabStokes2D::FunctionSpace>(mesh); |
| 71 |
auto h = std::make_shared<Constant>(1.0); |
| 72 |
StabStokes2D::BilinearForm form(V, V, h); |
| 73 |
return foo(form); |
| 74 |
} |
| 75 |
else if (form_name == "elasticity") |
| 76 |
{ |
| 77 |
auto mesh = std::make_shared<UnitCubeMesh>(SIZE_3D, SIZE_3D, SIZE_3D); |
| 78 |
auto V = std::make_shared<Elasticity3D::FunctionSpace>(mesh); |
| 79 |
Elasticity3D::BilinearForm form(V, V); |
| 80 |
return foo(form); |
| 81 |
} |
| 82 |
else if (form_name == "navierstokes") |
| 83 |
{ |
| 84 |
auto mesh = std::make_shared<UnitCubeMesh>(SIZE_3D, SIZE_3D, SIZE_3D); |
| 85 |
auto V = std::make_shared<NSEMomentum3D::FunctionSpace>(mesh); |
| 86 |
auto w = std::make_shared<Constant>(1.0, 1.0, 1.0); |
| 87 |
auto d1 = std::make_shared<Constant>(1.0); |
| 88 |
auto d2 = std::make_shared<Constant>(1.0); |
| 89 |
auto k = std::make_shared<Constant>(1.0); |
| 90 |
auto nu = std::make_shared<Constant>(1.0); |
| 91 |
NSEMomentum3D::BilinearForm form(V, V, w, d1, d2, k, nu); |
| 92 |
return foo(form); |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
error("Unknown form: %s.", form_name.c_str()); |
| 97 |
} |
| 98 |
|
| 99 |
return 0.0; |
| 100 |
} |