COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-proto-systems.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 heat-conduction related proto operations"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #define BOOST_PROTO_MAX_ARITY 10
13 #ifdef BOOST_MPL_LIMIT_METAFUNCTION_ARITY
14  #undef BOOST_MPL_LIMIT_METAFUNCTION_ARITY
15  #define BOOST_MPL_LIMIT_METAFUNCTION_ARITY 10
16 #endif
17 
18 #include "common/Core.hpp"
19 #include "common/Environment.hpp"
20 
21 #include "mesh/Domain.hpp"
22 
23 #include "solver/ModelUnsteady.hpp"
24 #include "solver/Time.hpp"
25 
29 #include "solver/CriterionTime.hpp"
31 
33 #include "mesh/MeshGenerator.hpp"
34 
36 #include "UFEM/Solver.hpp"
37 #include "UFEM/Tags.hpp"
38 #include "math/LSS/ZeroLSS.hpp"
39 #include "math/LSS/SolveLSS.hpp"
40 
41 using namespace cf3;
42 using namespace cf3::solver;
43 using namespace cf3::solver::actions;
44 using namespace cf3::solver::actions::Proto;
45 using namespace cf3::common;
46 using namespace cf3::math::Consts;
47 using namespace cf3::mesh;
48 
49 using namespace boost;
50 
51 typedef std::vector<std::string> StringsT;
52 typedef std::vector<Uint> SizesT;
53 
54 BOOST_AUTO_TEST_SUITE( ProtoSystemSuite )
55 
57 {
58  common::PE::Comm::instance().init(boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv);
59  BOOST_CHECK_EQUAL(common::PE::Comm::instance().size(), 1);
60 }
61 
62 BOOST_AUTO_TEST_CASE( ProtoSystem )
63 {
64  const Real length = 5.;
65  std::vector<Real> outside_temp(2, 1.);
66  RealVector initial_temp(2); initial_temp << 100., 200.;
67  const Uint nb_segments = 10;
68  const Real end_time = 0.5;
69  const Real dt = 0.1;
70  const boost::proto::literal<RealVector> alpha(RealVector2(1., 2.));
71 
72  // Setup a model
74  Domain& domain = model.create_domain("Domain");
75  UFEM::Solver& solver = *model.create_component<UFEM::Solver>("Solver");
76  Handle<UFEM::LSSActionUnsteady> lss_action(solver.add_unsteady_solver("cf3.UFEM.LSSActionUnsteady"));
77  Handle<common::ActionDirector> ic(solver.get_child("InitialConditions"));
78 
79  // Proto placeholders
80  FieldVariable<0, VectorField> v("VectorVariable", UFEM::Tags::solution());
81 
82  // Allowed elements (reducing this list improves compile times)
83  boost::mpl::vector1<mesh::LagrangeP1::Quad2D> allowed_elements;
84 
85  // BCs
86  boost::shared_ptr<UFEM::BoundaryConditions> bc = allocate_component<UFEM::BoundaryConditions>("BoundaryConditions");
87 
88  // build up the solver out of different actions
89  *ic << create_proto_action("Initialize", nodes_expression(v = initial_temp));
90 
91  *lss_action
92  << allocate_component<math::LSS::ZeroLSS>("ZeroLSS")
93  << create_proto_action
94  (
95  "Assembly",
96  elements_expression // assembly
97  (
98  allowed_elements,
99  group
100  (
101  _A = _0, _T = _0,
103  (
104  _A(v[_i], v[_i]) += transpose(nabla(v)) * alpha[_i] * nabla(v),
105  _T(v[_i], v[_i]) += lss_action->invdt() * (transpose(N(v)) * N(v))
106  ),
107  lss_action->system_matrix += _T + 0.5 * _A,
108  lss_action->system_rhs += -(_A * _x)
109  )
110  )
111  )
112  << bc
113  << allocate_component<math::LSS::SolveLSS>("SolveLSS")
114  << create_proto_action("Increment", nodes_expression(v += lss_action->solution(v)));
115 
116  // Setup physics
117  model.create_physics("cf3.physics.DynamicModel");
118 
119  // Setup mesh
120  boost::shared_ptr<MeshGenerator> create_rectangle = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","create_line");
121  create_rectangle->options().set("mesh",domain.uri()/"Mesh");
122  std::vector<Real> lengths(2); lengths[XX] = length; lengths[YY] = 0.5*length;
123  std::vector<Uint> nb_cells(2); nb_cells[XX] = 2*nb_segments; nb_cells[YY] = nb_segments;
124  create_rectangle->options().set("lengths",lengths);
125  create_rectangle->options().set("nb_cells",nb_cells);
126  Mesh& mesh = create_rectangle->generate();
127 
128  lss_action->options().set("regions", std::vector<URI>(1, mesh.topology().uri()));
129  ic->get_child("Initialize")->options().set("regions", std::vector<URI>(1, mesh.topology().uri()));
130 
131  bc->add_constant_bc("left", "VectorVariable", outside_temp);
132  bc->add_constant_bc("right", "VectorVariable", outside_temp);
133  bc->add_constant_bc("bottom", "VectorVariable", outside_temp);
134  bc->add_constant_bc("top", "VectorVariable", outside_temp);
135 
136  // Configure timings
137  Time& time = model.create_time();
138  time.options().set("time_step", dt);
139  time.options().set("end_time", end_time);
140 
141  // Run the solver
142  model.simulate();
143 
144  // Write result
145  domain.create_component("VTKwriter", "cf3.mesh.VTKXML.Writer");
146  domain.write_mesh(URI("systems.pvtu"));
147 };
148 
149 // Expected matrices:
150 // 82: 0.5 0 -0.5 0 0 0 0 0
151 // 82: 0 0.5 0 -0.5 0 0 0 0
152 // 82: -0.5 0 0.5 0 0 0 0 0
153 // 82: 0 -0.5 0 0.5 0 0 0 0
154 // 82: 0 0 0 0 0.5 0 -0.5 0
155 // 82: 0 0 0 0 0 0.5 0 -0.5
156 // 82: 0 0 0 0 -0.5 0 0.5 0
157 // 82: 0 0 0 0 0 -0.5 0 0.5
158 // 82:
159 // 82: 0.0078125 0.0078125 0.0078125 0.0078125 0 0 0 0
160 // 82: 0.0078125 0.0078125 0.0078125 0.0078125 0 0 0 0
161 // 82: 0.0078125 0.0078125 0.0078125 0.0078125 0 0 0 0
162 // 82: 0.0078125 0.0078125 0.0078125 0.0078125 0 0 0 0
163 // 82: 0 0 0 0 0.0078125 0.0078125 0.0078125 0.0078125
164 // 82: 0 0 0 0 0.0078125 0.0078125 0.0078125 0.0078125
165 // 82: 0 0 0 0 0.0078125 0.0078125 0.0078125 0.0078125
166 // 82: 0 0 0 0 0.0078125 0.0078125 0.0078125 0.0078125
167 
168 BOOST_AUTO_TEST_SUITE_END()
boost::proto::terminal< SFOp< ShapeFunctionOp > >::type const N
Time & create_time(const std::string &name="Time")
Create Time component.
static boost::proto::terminal< ZeroTag >::type _0
Placeholder for the zero matrix.
Definition: Terminals.hpp:209
virtual mesh::Domain & create_domain(const std::string &name)
creates a domain in this model
Definition: Model.cpp:201
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
external boost library namespace
virtual physics::PhysModel & create_physics(const std::string &builder)
Definition: Model.cpp:182
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 ...
Handle< common::Action > add_unsteady_solver(const std::string &builder_name)
Definition: Solver.cpp:138
static boost::proto::terminal< ElementSystemMatrix< boost::mpl::int_< 1 > > >::type const _T
Basic Classes for Solver applications used by CF.
Definition: Action.cpp:29
URI uri() const
Construct the full path.
Definition: Component.cpp:248
static boost::proto::terminal< ElementQuadratureTag >::type element_quadrature
Use element_quadrature(expr1, expr2, ..., exprN) to evaluate a group of expressions.
boost::shared_ptr< ElementsExpression< ExprT, ElementTypes > > elements_expression(ElementTypes, const ExprT &expr)
Definition: Expression.hpp:292
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.
Manage a collection of UFEM solvers.
Definition: Solver.hpp:31
static boost::proto::terminal< ElementRHS >::type const _x
Terminal for the element RHS vector ("b")
Static functions for mathematical constants.
Definition: Consts.hpp:25
Definition: Defs.hpp:17
Storage for time, and time steps for unsteady simulation.
Definition: Time.hpp:26
boost::proto::terminal< TransposeFunction >::type const transpose
boost::proto::terminal< SFOp< NablaOp > >::type const nabla
std::vector< std::string > StringsT
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.
std::vector< Uint > SizesT
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
virtual void simulate()
Simulates this model.
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.
BOOST_AUTO_TEST_CASE(InitMPI)
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
Eigen::Matrix< Real, 2, 1 > RealVector2
Fixed size 2x1 column vector.
Definition: MatrixTypes.hpp:40
boost::shared_ptr< ProtoAction > create_proto_action(const std::string &name, const boost::shared_ptr< Expression > &expression)
Create a new ProtoAction, immediatly setting the expression.
Region & topology() const
Definition: Mesh.hpp:51
static Core & instance()
Definition: Core.cpp:37
boost::shared_ptr< NodesExpression< ExprT, boost::mpl::range_c< Uint, 1, 4 > > > nodes_expression(const ExprT &expr)
Definition: Expression.hpp:308
Definition: Defs.hpp:17
OptionList & options()
Definition: Component.cpp:856
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
Send comments to:
COOLFluiD Web Admin