COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-actions-integral.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Tests mesh::actions::SurfaceIntegral"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/OptionList.hpp"
13 #include "common/Core.hpp"
14 #include "common/PE/Comm.hpp"
15 
19 
20 #include "mesh/Mesh.hpp"
21 #include "mesh/Region.hpp"
22 #include "mesh/Dictionary.hpp"
23 #include "mesh/Field.hpp"
25 
26 using namespace cf3;
27 using namespace cf3::common;
28 using namespace cf3::mesh;
29 using namespace cf3::mesh::actions;
30 
32 
34 {
37  {
38  m_argc = boost::unit_test::framework::master_test_suite().argc;
39  m_argv = boost::unit_test::framework::master_test_suite().argv;
40  }
41 
44  {
45  }
46 
48 
49  int m_argc;
50  char** m_argv;
51 
52 };
53 
55 
56 BOOST_FIXTURE_TEST_SUITE( TestSuite, TestFixture )
57 
58 
61 {
62  Core::instance().initiate(m_argc,m_argv);
63  PE::Comm::instance().init(m_argc,m_argv);
64 }
65 
67 
68 BOOST_AUTO_TEST_CASE( IntegrateOnSquare )
69 {
70  // Create a P1 square mesh with side 10.
72  mesh_generator->options().set("mesh",Core::instance().root().uri()/"mesh");
73  mesh_generator->options().set("lengths",std::vector<Real>(2,10.));
74  mesh_generator->options().set("nb_cells",std::vector<Uint>(2,5));
75  Mesh& mesh = mesh_generator->generate();
76 
77  // Create a field with value 1. everywhere
78  boost::shared_ptr<CreateField> create_field = allocate_component<CreateField>("create_field");
79  std::vector<std::string> functions;
80  functions.push_back("f=1.");
81  create_field->options().set("functions",functions);
82  create_field->options().set("name",std::string("field"));
83  create_field->options().set("dict",mesh.geometry_fields().uri());
84  create_field->transform(mesh);
85  Field& field = *mesh.geometry_fields().get_child("field")->handle<Field>();
86 
87  // Surface Integral of the field. It should return the total line length = 4*10.
88  boost::shared_ptr<SurfaceIntegral> surface_integration = allocate_component<SurfaceIntegral>("surface_integration");
89  surface_integration->options().set("order",1u);
90  Real surface_integral = surface_integration->integrate(field, std::vector< Handle<Region> >(1, mesh.topology().handle<Region>()) );
91  BOOST_CHECK_EQUAL(surface_integral,40.);
92 
93  // Volume Integral of the field. It should return the total area = 10*10.
94  boost::shared_ptr<VolumeIntegral> volume_integration = allocate_component<VolumeIntegral>("volume_integration");
95  volume_integration->options().set("order",1u);
96  Real volume_integral = volume_integration->integrate(field, std::vector< Handle<Region> >(1, mesh.topology().handle<Region>()) );
97  BOOST_CHECK_EQUAL(volume_integral,100.);
98 }
99 
100 BOOST_AUTO_TEST_CASE( IntegrateOnCube )
101 {
102  // Create a P1 square mesh with side 10.
104  mesh_generator->options().set("mesh",Core::instance().root().uri()/"cube");
105  mesh_generator->options().set("lengths",std::vector<Real>(3,10.));
106  mesh_generator->options().set("nb_cells",std::vector<Uint>(3,5));
107  Mesh& mesh = mesh_generator->generate();
108 
109  // Create a field with value 1. everywhere
110  boost::shared_ptr<CreateField> create_field = allocate_component<CreateField>("create_field");
111  std::vector<std::string> functions;
112  functions.push_back("f=1.");
113  create_field->options().set("functions",functions);
114  create_field->options().set("name",std::string("field"));
115  create_field->options().set("dict",mesh.geometry_fields().uri());
116  create_field->transform(mesh);
117  Field& field = *mesh.geometry_fields().get_child("field")->handle<Field>();
118 
119  // Surface Integral of the field. It should return the total line length = 6*10*10.
120  boost::shared_ptr<SurfaceIntegral> surface_integration = allocate_component<SurfaceIntegral>("surface_integration");
121  surface_integration->options().set("order",1u);
122  // Real surface_integral = surface_integration->integrate(field, std::vector< Handle<Region> >(1, mesh.topology().handle<Region>()) );
123  // BOOST_CHECK_EQUAL(surface_integral,600.);
124 
125  // Volume Integral of the field. It should return the total area = 10*10*10.
126  boost::shared_ptr<VolumeIntegral> volume_integration = allocate_component<VolumeIntegral>("volume_integration");
127  volume_integration->options().set("order",1u);
128  Real volume_integral = volume_integration->integrate(field, std::vector< Handle<Region> >(1, mesh.topology().handle<Region>()) );
129  BOOST_CHECK_EQUAL(volume_integral,1000.);
130 }
131 
133 
135 {
138 }
139 
141 
142 BOOST_AUTO_TEST_SUITE_END()
143 
144 
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
int m_argc
possibly common functions used on the tests below
TestFixture()
common setup for each test case
URI uri() const
Construct the full path.
Definition: Component.cpp:248
common::URI uri(ComponentWrapper &self)
tuple root
Definition: coolfluid.py:24
void terminate()
Definition: Core.cpp:131
Generate a simple carthesian P1 mesh without grading.
Mesh & generate()
generate, wraps execute() and returns the mesh reference
Basic Classes for Mesh applications used by COOLFluiD.
BOOST_AUTO_TEST_CASE(Initiate)
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
void initiate(int argc, char **argv)
Definition: Core.cpp:98
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
common::Component & root() const
Gives the default root component.
Definition: Core.cpp:145
Action derived classes for mesh manipulations.
Region & topology() const
Definition: Mesh.hpp:51
static Core & instance()
Definition: Core.cpp:37
Handle< Component > handle()
Get a handle to the component.
Definition: Component.hpp:179
OptionList & options()
Definition: Component.cpp:856
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
static Comm & instance()
Return a reference to the current PE.
Definition: Comm.cpp:44
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
Definition: Component.cpp:568
Most basic kernel library.
Definition: Action.cpp:19
~TestFixture()
common tear-down for each test case
Send comments to:
COOLFluiD Web Admin