COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-proto-nodeloop.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 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 proto operators"
9 
10 #include <boost/accumulators/accumulators.hpp>
11 #include <boost/accumulators/statistics/stats.hpp>
12 #include <boost/accumulators/statistics/mean.hpp>
13 #include <boost/accumulators/statistics/max.hpp>
14 
15 #include <boost/foreach.hpp>
16 #include <boost/test/unit_test.hpp>
17 
18 #include "solver/Model.hpp"
19 #include "solver/Solver.hpp"
20 
27 
28 #include "common/Core.hpp"
29 #include "common/Log.hpp"
30 
31 #include "math/MatrixTypes.hpp"
32 
33 #include "mesh/Domain.hpp"
34 #include "mesh/Mesh.hpp"
35 #include "mesh/Region.hpp"
36 #include "mesh/Elements.hpp"
37 #include "mesh/MeshReader.hpp"
38 #include "mesh/ElementData.hpp"
39 #include "mesh/FieldManager.hpp"
40 #include "mesh/Dictionary.hpp"
41 
43 #include "mesh/ElementTypes.hpp"
44 
45 #include "solver/Tags.hpp"
46 
47 #include "physics/PhysModel.hpp"
48 
51 
52 using namespace cf3;
53 using namespace cf3::solver;
54 using namespace cf3::solver::actions;
55 using namespace cf3::solver::actions::Proto;
56 using namespace cf3::mesh;
57 using namespace cf3::common;
58 
59 using namespace cf3::math::Consts;
60 
62 
63 
64 BOOST_FIXTURE_TEST_SUITE( ProtoOperatorsSuite, Tools::Testing::TimedTestFixture )
65 
66 using boost::proto::lit;
67 
69 
70 BOOST_AUTO_TEST_CASE( InitFields )
71 {
73  model.create_physics("cf3.physics.DynamicModel");
74  Domain& dom = model.create_domain("Domain");
75  Mesh& mesh = *dom.create_component<Mesh>("mesh");
76  Tools::MeshGeneration::create_rectangle(mesh, 1., 1., 500, 500);
77 
78  FieldManager& field_manager = *model.create_component<FieldManager>("FieldManager");
79  field_manager.options().set("variable_manager", model.physics().variable_manager().handle<math::VariableManager>());
80 
81  FieldVariable<0, VectorField> u("u","velocity");
82  FieldVariable<2, VectorField> u_adv("u_adv", "advection");
83  FieldVariable<3, VectorField> u1("u1", "advection");
84  FieldVariable<4, VectorField> u2("u2", "advection");
85  FieldVariable<5, VectorField> u3("u3", "advection");
86 
87  // Create an action that can wrap an expression
88  ProtoAction& action = *model.create_component<ProtoAction>("ActionInit");
89  action.set_expression(nodes_expression(group(u_adv[_i] = 0., u[_i] = 1., u1[_i] = 1., u2[_i] = 1., u3[_i] = 1.)));
90  action.options().set("physical_model", model.physics().handle<physics::PhysModel>());
91  action.options().set(solver::Tags::regions(), std::vector<URI>(1, model.domain().get_child("mesh")->handle<Mesh>()->topology().uri()));
92 
93  // Create the fields
94  field_manager.create_field("velocity", mesh.geometry_fields());
95  field_manager.create_field("advection", mesh.geometry_fields());
96 
97  action.execute();
98 }
99 
100 BOOST_AUTO_TEST_CASE( LinearizeU )
101 {
103 
104  FieldVariable<0, VectorField> u("u","velocity");
105  FieldVariable<2, VectorField> u_adv("u_adv", "advection");
106  FieldVariable<3, VectorField> u1("u1", "advection");
107  FieldVariable<4, VectorField> u2("u2", "advection");
108  FieldVariable<5, VectorField> u3("u3", "advection");
109 
110  // Create an action that can wrap an expression
111  ProtoAction& action = *model->create_component<ProtoAction>("ActionU");
112  action.set_expression(nodes_expression(u_adv = 2.1875*u - 2.1875*u1 + 1.3125*u2 - 0.3125*u3));
113  action.options().set("physical_model", model->physics().handle<physics::PhysModel>());
114  action.options().set(solver::Tags::regions(), std::vector<URI>(1, model->domain().get_child("mesh")->handle<Mesh>()->topology().uri()));
115 
116  action.execute();
117 }
118 
119 BOOST_AUTO_TEST_CASE( CheckResult )
120 {
122 
123  RealVector result(2); result.setZero();
124  FieldVariable<0, VectorField> u_adv("u_adv", "advection");
125 
126  // Create an action that can wrap an expression
127  ProtoAction& action = *model->create_component<ProtoAction>("ActionCheck");
128  action.set_expression(nodes_expression(lit(result) += u_adv));
129  action.options().set("physical_model", model->physics().handle<physics::PhysModel>());
130  action.options().set(solver::Tags::regions(), std::vector<URI>(1, model->domain().get_child("mesh")->handle<Mesh>()->topology().uri()));
131 
132  action.execute();
133 
134  Handle<Mesh> mesh(model->domain().get_child("mesh"));
135  result /= mesh->geometry_fields().size();
136 
137  BOOST_CHECK_CLOSE(result[0], 1., 1e-8);
138  BOOST_CHECK_CLOSE(result[1], 1., 1e-8);
139 }
140 
142 {
143  typedef void result_type;
144 
145  SumVectorNorm() : m_sum(0.)
146  {
147  }
148 
149  template<typename VectorT>
150  void operator()(const VectorT& vec)
151  {
152  m_sum += vec.norm();
153  }
154 
155  Real m_sum;
156 };
157 
158 BOOST_AUTO_TEST_CASE( NodeFunctor )
159 {
161 
162  FieldVariable<0, VectorField> u("u","velocity");
163 
164  SumVectorNorm vec_norm;
165 
166  // Create an action that can wrap an expression
167  ProtoAction& action = *model->create_component<ProtoAction>("ActionVectorNorm");
168  action.set_expression(nodes_expression(lit(vec_norm)(u)));
169  action.options().set("physical_model", model->physics().handle<physics::PhysModel>());
170  action.options().set(solver::Tags::regions(), std::vector<URI>(1, model->domain().get_child("mesh")->handle<Mesh>()->topology().uri()));
171 
172  action.execute();
173 
174  BOOST_CHECK_CLOSE(vec_norm.m_sum, 501.*501.*sqrt(2),1e-8);
175 }
176 
177 BOOST_AUTO_TEST_SUITE_END()
178 
179 
boost::python::object get_child(ComponentWrapper &self, const std::string &name)
virtual mesh::Domain & create_domain(const std::string &name)
creates a domain in this model
Definition: Model.cpp:201
void operator()(const VectorT &vec)
external boost library namespace
virtual physics::PhysModel & create_physics(const std::string &builder)
Definition: Model.cpp:182
void set_expression(const boost::shared_ptr< Expression > &expression)
Class to encapsulate Proto actions.
Definition: ProtoAction.hpp:26
virtual physics::PhysModel & physics()
gets the physics from this model
Definition: Model.cpp:154
Base class of all functions that can be evaluated using "default" C++ semantics.
Definition: Functions.hpp:21
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
void create_rectangle(Mesh &mesh, const Real x_len, const Real y_len, const Uint x_segments, const Uint y_segments)
Create a rectangular, 2D, quad-only mesh. No buffer for creation.
Any test using this fixture (or a derivative) will be timed.
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Static functions for mathematical constants.
Definition: Consts.hpp:25
BOOST_AUTO_TEST_CASE(InitFields)
virtual mesh::Domain & domain()
gets the domain from this model
Definition: Model.cpp:161
Basic Classes for Mesh applications used by COOLFluiD.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Definition: MatrixTypes.hpp:25
tuple model
Global confifuration.
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
Top-level namespace for coolfluid.
Definition: Action.cpp:18
static boost::proto::terminal< IndexTag< boost::mpl::int_< 0 > > >::type const _i
Index looping over the dimensions of a variable.
common::Component & root() const
Gives the default root component.
Definition: Core.cpp:145
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
static Core & instance()
Definition: Core.cpp:37
Handle< Component > handle()
Get a handle to the component.
Definition: Component.hpp:179
void create_field(const std::string &tag, cf3::mesh::Dictionary &dict)
Create fields. Looks up the VariablesDescriptor with the given tag, and creates a field with the same...
boost::shared_ptr< NodesExpression< ExprT, boost::mpl::range_c< Uint, 1, 4 > > > nodes_expression(const ExprT &expr)
Definition: Expression.hpp:308
math::VariableManager & variable_manager()
Access to the VariableManager.
Definition: PhysModel.cpp:42
OptionList & options()
Definition: Component.cpp:856
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
virtual void execute()
execute the action
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
Send comments to:
COOLFluiD Web Admin