COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-solver-actions.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 "Test module for cf3::actions"
9 
10 #include <iomanip>
11 
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/assign/list_of.hpp>
15 
16 #include "common/LibCommon.hpp"
17 
18 #include "common/Log.hpp"
19 #include "common/Core.hpp"
20 #include "common/Libraries.hpp"
21 #include "common/Environment.hpp"
22 #include "common/Group.hpp"
23 #include "common/OptionList.hpp"
24 
25 #include "mesh/Mesh.hpp"
26 #include "mesh/MeshWriter.hpp"
27 #include "mesh/MeshReader.hpp"
28 #include "mesh/MeshTransformer.hpp"
29 #include "mesh/Field.hpp"
30 #include "mesh/LoadMesh.hpp"
31 #include "mesh/Cells.hpp"
32 #include "mesh/Dictionary.hpp"
33 #include "mesh/Connectivity.hpp"
34 #include "mesh/Space.hpp"
35 
44 
45 using namespace boost::assign;
46 
47 using namespace cf3;
48 using namespace cf3::common;
49 using namespace cf3::mesh;
50 using namespace cf3::solver;
51 using namespace cf3::solver::actions;
52 
55 struct CoreInit {
56 
59  {
60  using namespace boost::unit_test::framework;
61  Core::instance().initiate( master_test_suite().argc, master_test_suite().argv);
62  }
63 
66  {
67  Core::instance().terminate();
68  }
69 
70 };
71 
73 
75 
76 
78 BOOST_AUTO_TEST_SUITE( TestActionsSuite )
79 
81 
82 BOOST_AUTO_TEST_CASE( Node_Looping_Test )
83 {
84  Core::instance().environment().options().set("log_level",(Uint)DEBUG);
85  Component& root = Core::instance().root();
86  Handle<Mesh> mesh = root.create_component<Mesh>("mesh");
87 
88  // read mesh from file
89  Core::instance().tools().get_child("LoadMesh")->handle<LoadMesh>()->load_mesh_into("../../../resources/rotation-tg-p1.neu", *mesh);
90 
91  std::vector<URI> regions = list_of(mesh->topology().uri()/URI("inlet"))
92  (mesh->topology().uri()/URI("outlet"));
93 
94 
95  // Create a loop over the inlet bc to set the inlet bc to a dirichlet condition
96  Handle<Loop> node_loop2 = root.create_component< ForAllNodes2 >("node_loop");
97 
98  node_loop2->create_loop_operation("cf3.TestActions.DummyLoopOperation");
99  node_loop2->options().set("regions",regions);
100 
101  CFinfo << "\n\n\nNode loop 2 " << CFendl;
102 
103  BOOST_CHECK_NO_THROW( node_loop2->execute() );
104 
105  BOOST_CHECK(true);
106 
107  //root.remove_component(*mesh);
108 
109 }
110 
112 
113 BOOST_AUTO_TEST_CASE( Face_Looping_Test )
114 {
115  Component& root = Core::instance().root();
116  Handle<Mesh> mesh = root.create_component<Mesh>("mesh");
117 
118  // read mesh from file
119  Core::instance().tools().get_child("LoadMesh")->handle<LoadMesh>()->load_mesh_into("../../../resources/rotation-tg-p1.neu", *mesh);
120 
121  std::vector<URI> regions = list_of(mesh->topology().uri());
122 
123  // Create inner_faces
124  boost::shared_ptr< MeshTransformer > facebuilder = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.BuildFaces","facebuilder");
125  //facebuilder->transform(mesh);
126 
127  // Create a loop over the inlet bc to set the inlet bc to a dirichlet condition
128  Handle<Loop> face_loop = root.create_component< ForAllFaces >("face_loop");
129  face_loop->create_loop_operation("cf3.TestActions.DummyLoopOperation");
130  face_loop->options().set("regions",regions);
131  CFinfo << "\n\n\nFace loop" << CFendl;
132 
133  BOOST_CHECK_NO_THROW( face_loop->execute() );
134 
135  boost::shared_ptr< MeshTransformer > info = build_component_abstract_type<MeshTransformer>("cf3.mesh.actions.Info","info");
136  info->transform(mesh);
137 
138  //root.remove_component(*mesh);
139 
140  BOOST_CHECK(true);
141 }
142 
144 
145 BOOST_AUTO_TEST_CASE ( test_CSetFieldValue )
146 {
147  Component& root = Core::instance().root();
148  Handle<Mesh> mesh = root.create_component<Mesh>("mesh2");
149 
150  // read mesh from file
151 
152  Core::instance().tools().get_child("LoadMesh")->handle<LoadMesh>()->load_mesh_into("../../../resources/rotation-tg-p1.neu", *mesh);
153 
154  BOOST_CHECK(true);
155 
156  Field& field = mesh->geometry_fields().create_field("field");
157 
158  Handle<Loop> node_loop = root.create_component< ForAllNodes2 >("node_loop");
159  node_loop->options().set("regions",std::vector<URI>(1,mesh->topology().uri()));
160 
162 // node_loop->create_loop_operation("cf3.solver.actions.CSetFieldValues");
163 // node_loop->action("cf3.solver.actions.CSetFieldValues").options().set("Field",field.uri());
164  node_loop->execute();
165 
166  BOOST_CHECK(true);
167 
168  BOOST_CHECK(find_components_recursively<Cells>(mesh->topology()).size() > 0);
169 
170  Dictionary& cells_P0 = mesh->create_discontinuous_space("cells_P0","cf3.mesh.LagrangeP0");
171  Field& volumes = cells_P0.create_field("volume");
172 
173  BOOST_CHECK(true);
174 
175 
176  Dictionary& faces_P0 = mesh->create_discontinuous_space("faces_P0", "cf3.mesh.LagrangeP0");
177  Field& areas = faces_P0.create_field("area");
178 
179 
180  BOOST_CHECK(true);
181 
182  Handle<ComputeVolume> compute_volume = root.create_component<ComputeVolume>("compute_volume");
183  BOOST_CHECK(true);
184  BOOST_CHECK( root.access_component(mesh->topology().uri()/URI("fluid/elements_cf3.mesh.LagrangeP1.Triag2D")) );
185  Elements& elems = *root.access_component(mesh->topology().uri()/URI("fluid/elements_cf3.mesh.LagrangeP1.Triag2D"))->handle<Elements>();
186  BOOST_CHECK(true);
187  compute_volume->options().set("volume",volumes.uri());
188  BOOST_CHECK(true);
189  compute_volume->options().set("elements",elems.uri());
190  BOOST_CHECK(true);
191  compute_volume->options().set("loop_index",12u);
192  BOOST_CHECK(true);
193  compute_volume->execute();
194  BOOST_CHECK(true);
195 
196  const Space& P0_space = volumes.space(elems);
197  BOOST_CHECK_EQUAL( volumes[P0_space.connectivity()[12][0]][0] , 0.0035918050864676932);
198 
199  Handle<Loop> elem_loop = root.create_component< ForAllElements >("elem_loop");
200  elem_loop->options().set("regions",std::vector<URI>(1,mesh->topology().uri()));
201 
202  elem_loop->create_loop_operation("cf3.solver.actions.ComputeVolume");
203  elem_loop->action("cf3.solver.actions.ComputeVolume").options().set("volume",volumes.uri());
204 
205  elem_loop->create_loop_operation("cf3.solver.actions.ComputeArea");
206  elem_loop->action("cf3.solver.actions.ComputeArea").options().set("area",areas.uri());
207 
208  elem_loop->execute();
209 
210  BOOST_CHECK(true);
211 
212  std::vector<URI> fields;
213  fields.push_back(volumes.uri());
214  fields.push_back(field.uri());
215  fields.push_back(areas.uri());
216  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
217  gmsh_writer->options().set("fields",fields);
218  gmsh_writer->options().set("mesh",mesh);
219  gmsh_writer->options().set("file",URI("quadtriag.msh"));
220  gmsh_writer->execute();
221 
222  // root.remove_component( *mesh ); // mesh needed for next test
223 }
224 
226 
227 BOOST_AUTO_TEST_CASE ( test_ForAllElementsT )
228 {
229  Component& root = Core::instance().root();
230  Handle< Mesh > mesh = root.get_child("mesh2")->handle<Mesh>();
231 
232 
233  BOOST_CHECK(true);
234 
235  Field& field = mesh->get_child("cells_P0")->handle<Dictionary>()->create_field("test_ForAllElementsT","var[1]");
236 
237  BOOST_CHECK(true);
238 
239  std::vector<URI> topology = list_of(mesh->topology().uri());
240 
241  Handle< ForAllElementsT<ComputeVolume> > compute_all_cell_volumes =
242  root.create_component< ForAllElementsT<ComputeVolume> > ("compute_all_cell_volumes");
243 
244  BOOST_CHECK(true);
245 
246  compute_all_cell_volumes->options().set("regions",topology);
247  BOOST_CHECK(true);
248 
249  compute_all_cell_volumes->action().options().set("volume",field.uri());
250  BOOST_CHECK(true);
251 
252  compute_all_cell_volumes->execute();
253 
254  std::vector<URI> fields;
255  fields.push_back(field.uri());
256  boost::shared_ptr< MeshWriter > gmsh_writer = build_component_abstract_type<MeshWriter>("cf3.mesh.gmsh.Writer","meshwriter");
257  gmsh_writer->options().set("fields",fields);
258  gmsh_writer->options().set("mesh",mesh);
259  gmsh_writer->options().set("file",URI("test_utest-actions_ForAllElementsT.msh"));
260  gmsh_writer->execute();
261 
262  root.remove_component( *mesh );
263 }
264 
266 
267 BOOST_AUTO_TEST_SUITE_END()
268 
269 
#define CFinfo
these are always defined
Definition: Log.hpp:104
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
Definition: Dictionary.cpp:178
LoopOperation & create_loop_operation(const std::string action_provider)
Definition: Loop.cpp:35
Dictionary & create_discontinuous_space(const std::string &space_name, const std::string &space_lib_name, const std::vector< Handle< Entities > > &entities)
Definition: Mesh.cpp:316
BOOST_AUTO_TEST_CASE(Node_Looping_Test)
Basic Classes for Solver applications used by CF.
Definition: Action.cpp:29
URI uri() const
Construct the full path.
Definition: Component.cpp:248
tuple root
Definition: coolfluid.py:24
#define CFendl
Definition: Log.hpp:109
Handle< Component > access_component(const URI &path) const
Definition: Component.cpp:487
Basic Classes for Mesh applications used by COOLFluiD.
const Handle< Space const > & space(const Handle< Entities const > &entities) const
Definition: Field.cpp:248
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
Top-level namespace for coolfluid.
Definition: Action.cpp:18
~CoreInit()
global tear-down
CoreInit()
global initiate
std::vector< URI > fields
boost::shared_ptr< Component > remove_component(const std::string &name)
Remove a (sub)component of this component.
Definition: Component.cpp:357
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
BOOST_GLOBAL_FIXTURE(GlobalFixture) BOOST_AUTO_TEST_CASE(MeshStats)
Accumulate some statistics about the cell volumes.
virtual void execute()=0
execute the action
Region & topology() const
Definition: Mesh.hpp:51
virtual void execute()
execute the action
OptionList & options()
Definition: Component.cpp:856
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
Base class for defining CF components.
Definition: Component.hpp:82
Space component class.
Definition: Space.hpp:59
void set(const std::string &pname, const boost::any &val)
Definition: OptionList.cpp:132
virtual const LoopOperation & action(const std::string &name) const
Definition: Loop.cpp:47
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
Connectivity & connectivity()
connectivity table to dictionary entries
Definition: Space.hpp:110
Send comments to:
COOLFluiD Web Admin