COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-proto-internals.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 
26 
27 #include "common/Core.hpp"
28 #include "common/Log.hpp"
29 
30 #include "math/MatrixTypes.hpp"
31 
32 #include "mesh/Domain.hpp"
33 #include "mesh/Mesh.hpp"
34 #include "mesh/Region.hpp"
35 #include "mesh/Elements.hpp"
36 #include "mesh/MeshReader.hpp"
37 #include "mesh/ElementData.hpp"
38 #include "mesh/FieldManager.hpp"
39 #include "mesh/Dictionary.hpp"
40 
42 #include "mesh/ElementTypes.hpp"
43 
44 #include "physics/PhysModel.hpp"
45 
49 
50 using namespace cf3;
51 using namespace cf3::solver::actions::Proto;
52 
53 using namespace cf3::math::Consts;
54 
56 inline void check_close(const RealMatrix2& a, const RealMatrix2& b, const Real threshold)
57 {
58  for(Uint i = 0; i != a.rows(); ++i)
59  for(Uint j = 0; j != a.cols(); ++j)
60  BOOST_CHECK_CLOSE(a(i,j), b(i,j), threshold);
61 }
62 
63 static boost::proto::terminal< void(*)(const RealMatrix2&, const RealMatrix2&, Real) >::type const _check_close = {&check_close};
64 
66 
68 typedef boost::mpl::vector3< mesh::LagrangeP1::Line1D,
72 
73 typedef boost::mpl::vector5< mesh::LagrangeP1::Line1D,
79 
80 BOOST_AUTO_TEST_SUITE( ProtoOperatorsSuite )
81 
82 template<typename T>
84 {
85  std::cout << common::demangle(typeid(T).name()) << std::endl;
86 }
87 
88 template<typename T>
89 void print_type()
90 {
91  std::cout << common::demangle(typeid(T).name()) << std::endl;
92 }
93 
94 template<typename ExprT>
95 void print_variables(const ExprT&)
96 {
97  print_type<typename ExpressionProperties<ExprT>::VariablesT>();
98 }
99 
100 template<typename GrammarT, typename ExprT>
101 bool get_result(const GrammarT&, const ExprT&)
102 {
103  return boost::result_of<GrammarT(ExprT)>::type::value;
104 }
105 
107 
108 BOOST_AUTO_TEST_CASE( EquationVars )
109 {
110  static const boost::proto::terminal< RestrictToElementTypeTag< boost::mpl::vector0<> > >::type for_generic_elements = {};
111 
112  Real tau_ps, tau_su, tau_bulk;
113  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_u_solution");
114  FieldVariable<1, ScalarField> p("Pressure", "navier_stokes_p_solution");
115  FieldVariable<2, VectorField> u_adv("AdvectionVelocity", "linearized_velocity");
116  FieldVariable<3, VectorField> u1("AdvectionVelocity1", "linearized_velocity");
117  FieldVariable<4, VectorField> u2("AdvectionVelocity2", "linearized_velocity");
118  FieldVariable<5, VectorField> u3("AdvectionVelocity3", "linearized_velocity");
119  FieldVariable<6, ScalarField> nu_eff("EffectiveViscosity", "navier_stokes_viscosity");
120  PhysicsConstant rho("density");
121  PhysicsConstant nu("kinematic_viscosity");
122 
124  (
125  _A = _0, _T = _0, _a = _0,
126  for_generic_elements
127  (
129  (
130  _A(u[_i], u[_i]) += nu_eff * transpose(nabla(u)) * nabla(u) + transpose(N(u) + tau_su*u_adv*nabla(u)) * u_adv*nabla(u), // Diffusion + advection
131  _a[u[_i]] += transpose(N(u) + tau_su*u_adv*nabla(u)) * nabla(p)[_i] / rho * nodal_values(p), // Pressure gradient (standard and SUPG)
132  _A(u[_i], u[_j]) += transpose((tau_bulk + 0.33333333333333*nu_eff)*nabla(u)[_i] // Bulk viscosity and second viscosity effect
133  + 0.5*u_adv[_i]*(N(u) + tau_su*u_adv*nabla(u))) * nabla(u)[_j], // skew symmetric part of advection (standard +SUPG)
134  _T(u[_i], u[_i]) += transpose(N(u) + tau_su*u_adv*nabla(u)) * N(u) // Time, standard and SUPG
135  )
136  )
137  ));
138 }
139 
140 BOOST_AUTO_TEST_CASE( SubExpressions )
141 {
142  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_u_solution");
143  BOOST_CHECK(!get_result(solver::actions::Proto::detail::HasEvalVar<0>(), _A(u[_i], u[_i]) += transpose(N(u))*N(u)));
144  BOOST_CHECK(get_result(solver::actions::Proto::detail::HasEvalVar<0>(), _A(u[_i], u[_i]) += transpose(N(u)) * u*nabla(u)));
145 }
146 
147 BOOST_AUTO_TEST_SUITE_END()
148 
149 
boost::proto::terminal< SFOp< ShapeFunctionOp > >::type const N
std::string name(ComponentWrapper &self)
static boost::proto::terminal< ZeroTag >::type _0
Placeholder for the zero matrix.
Definition: Terminals.hpp:209
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Tetra3D.hpp:36
static boost::proto::terminal< ElementSystemMatrix< boost::mpl::int_< 0 > > >::type const _A
Some predefined element matrices (more can be user-defined, but you have to change the number in the ...
boost::mpl::vector3< mesh::LagrangeP1::Line1D, mesh::LagrangeP1::Quad2D, mesh::LagrangeP1::Hexa3D > HigherIntegrationElements
List of all supported shapefunctions that allow high order integration.
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Triag2D.hpp:36
static boost::proto::terminal< ElementSystemMatrix< boost::mpl::int_< 1 > > >::type const _T
void print_type(T)
static boost::proto::terminal< NodalValuesTag >::type const nodal_values
static boost::proto::terminal< ElementQuadratureTag >::type element_quadrature
Use element_quadrature(expr1, expr2, ..., exprN) to evaluate a group of expressions.
void print_variables(const ExprT &)
Static functions for mathematical constants.
Definition: Consts.hpp:25
void check_close(const RealMatrix2 &a, const RealMatrix2 &b, const Real threshold)
Check close, for testing purposes.
static boost::proto::terminal< IndexTag< boost::mpl::int_< 1 > > >::type const _j
Index looping over the dimensions of a variable.
Refers to a value from the physical model.
boost::proto::terminal< TransposeFunction >::type const transpose
boost::proto::terminal< SFOp< NablaOp > >::type const nabla
Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing the ...
Definition: Line1D.hpp:36
static boost::proto::terminal< void(*)(const RealMatrix2 &, const RealMatrix2 &, Real) >::type const _check_close
bool get_result(const GrammarT &, const ExprT &)
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.
boost::mpl::vector5< mesh::LagrangeP1::Line1D, mesh::LagrangeP1::Triag2D, mesh::LagrangeP1::Quad2D, mesh::LagrangeP1::Hexa3D, mesh::LagrangeP1::Tetra3D > VolumeTypes
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
static boost::proto::terminal< ElementVector< boost::mpl::int_< 0 > > >::type const _a
Eigen::Matrix< Real, 2, 2 > RealMatrix2
Fixed size 2x2 matrix.
Definition: MatrixTypes.hpp:34
BOOST_AUTO_TEST_CASE(EquationVars)
2D Lagrange P1 Quadrilateral Element type This class provides the lagrangian shape function describin...
Definition: Quad2D.hpp:37
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Definition: Hexa3D.hpp:36
std::string demangle(const char *type)
Function to demangle the return of typeid()
Definition: TypeInfo.cpp:22
Send comments to:
COOLFluiD Web Admin