COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-mesh-actions-fieldcreation.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::FieldCreation"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/Log.hpp"
13 #include "common/OptionList.hpp"
14 #include "common/Core.hpp"
15 #include "common/PE/debug.hpp"
16 #include "common/PE/Comm.hpp"
17 
18 #include "math/Consts.hpp"
19 
22 #include "mesh/actions/Rotate.hpp"
23 
24 #include "mesh/MeshWriter.hpp"
25 #include "mesh/Mesh.hpp"
26 #include "mesh/Region.hpp"
27 #include "mesh/Dictionary.hpp"
28 #include "mesh/Field.hpp"
30 
31 using namespace cf3;
32 using namespace cf3::common;
33 using namespace cf3::mesh;
34 using namespace cf3::mesh::actions;
35 using namespace cf3::common::PE;
36 
38 
40 {
43  {
44  m_argc = boost::unit_test::framework::master_test_suite().argc;
45  m_argv = boost::unit_test::framework::master_test_suite().argv;
46  }
47 
50  {
51  }
52 
54 
55  int m_argc;
56  char** m_argv;
57 
60 };
61 
63 
65 
66 BOOST_FIXTURE_TEST_SUITE( TestFieldCreation_TestSuite, TestFieldCreation_Fixture )
67 
68 
70 //BOOST_AUTO_TEST_CASE( Init )
71 //{
72 // Core::instance().initiate(m_argc,m_argv);
73 // PE::Comm::instance().init(m_argc,m_argv);
74 //}
75 
76 
79 {
80  Core::instance().initiate(m_argc,m_argv);
81 
83  mesh_generator->options().set("mesh",Core::instance().root().uri()/"rect");
84  mesh_generator->options().set("lengths",std::vector<Real>(2,2*math::Consts::pi()));
85  mesh_generator->options().set("nb_cells",std::vector<Uint>(2,10));
86  Mesh& rect = mesh_generator->generate();
87 
88  boost::shared_ptr<Rotate> rotate_mesh = allocate_component<Rotate>("rotate_mesh");
89  rotate_mesh->options().set("mesh",rect.handle());
90  rotate_mesh->options().set("angle",math::Consts::pi()/4.);
91  rotate_mesh->options().set("axis_point",std::vector<Real>(2,math::Consts::pi()));
92  rotate_mesh->execute();
93 
94  boost::shared_ptr<CreateField> create_field = allocate_component<CreateField>("create_field");
95  std::vector<std::string> functions;
96  functions.push_back("f=cos(x)+cos(y)");
97  functions.push_back("U[2]=[x,y]");
98  create_field->options().set("functions",functions);
99  create_field->options().set("name",std::string("field"));
100  create_field->options().set("dict",rect.geometry_fields().uri());
101  create_field->transform(rect);
102 
103  Field& field = *rect.geometry_fields().get_child("field")->handle<Field>();
104  Field& grad = rect.geometry_fields().create_field("grad","dfdx,dudx,dvdx,dfdy,dudy,dvdy");
105 
106  boost::shared_ptr<ComputeFieldGradient> compute_gradient = allocate_component<ComputeFieldGradient>("compute_gradient");
107 
108  compute_gradient->options().set("mesh",rect.handle());
109  compute_gradient->options().set("field",field.handle());
110  compute_gradient->options().set("field_gradient",grad.handle());
111 
112  compute_gradient->execute();
113 
114  std::vector<URI> fields;
115  fields.push_back(field.uri());
116  fields.push_back(grad.uri());
117  rect.write_mesh("file:out-utest-mesh-actions-fieldcreation.msh",fields);
118 }
119 
121 
122 //BOOST_AUTO_TEST_CASE( Terminate )
123 //{
124 // PE::Comm::instance().finalize();
125 // Core::instance().terminate();
126 //}
127 
129 
130 BOOST_AUTO_TEST_SUITE_END()
131 
132 
void write_mesh(const common::URI &file, const std::vector< common::URI > fields=std::vector< common::URI >())
Definition: Mesh.cpp:391
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
Definition: Dictionary.cpp:178
static Handle< Mesh > mesh
common values accessed by all tests goes here
URI uri() const
Construct the full path.
Definition: Component.cpp:248
common::URI uri(ComponentWrapper &self)
tuple root
Definition: coolfluid.py:24
Generate a simple carthesian P1 mesh without grading.
~TestFieldCreation_Fixture()
common tear-down for each test case
Real pi()
Definition of the Pi constant.
Definition: Consts.hpp:48
Mesh & generate()
generate, wraps execute() and returns the mesh reference
Basic Classes for Mesh applications used by COOLFluiD.
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
void initiate(int argc, char **argv)
Definition: Core.cpp:98
int m_argc
possibly common functions used on the tests below
Top-level namespace for coolfluid.
Definition: Action.cpp:18
BOOST_AUTO_TEST_CASE(execute)
std::vector< URI > fields
common::Component & root() const
Gives the default root component.
Definition: Core.cpp:145
Action derived classes for mesh manipulations.
Classes offering a MPI interface for COOLFluiD.
Definition: all_gather.hpp:39
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
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
TestFieldCreation_Fixture()
common setup for each test case
Send comments to:
COOLFluiD Web Admin