COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-proto-heat.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 //explained in boost doc
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 "math/LSS/System.hpp"
22 
23 #include "mesh/Domain.hpp"
24 
26 #include "solver/Model.hpp"
27 
28 #include "math/LSS/SolveLSS.hpp"
29 #include <math/LSS/ZeroLSS.hpp>
30 
33 
35 
37 
38 #include "UFEM/LSSAction.hpp"
39 #include "UFEM/Solver.hpp"
40 #include "UFEM/Tags.hpp"
41 
42 using namespace cf3;
43 using namespace cf3::solver;
44 using namespace cf3::solver::actions;
45 using namespace cf3::solver::actions::Proto;
46 using namespace cf3::common;
47 using namespace cf3::math::Consts;
48 using namespace cf3::mesh;
49 
50 using namespace boost;
51 
52 
53 typedef std::vector<std::string> StringsT;
54 typedef std::vector<Uint> SizesT;
55 
57 inline void
58 check_close(const Real a, const Real b, const Real threshold)
59 {
60  BOOST_CHECK_CLOSE(a, b, threshold);
61 }
62 
63 static boost::proto::terminal< void(*)(Real, Real, Real) >::type const _check_close = {&check_close};
64 
65 struct ProtoHeatFixture
66 {
68  root( Core::instance().root() )
69  {
70  }
71 
72  Component& root;
73 };
74 
75 BOOST_FIXTURE_TEST_SUITE( ProtoHeatSuite, ProtoHeatFixture )
76 
78 {
79  common::PE::Comm::instance().init(boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv);
80  BOOST_CHECK_EQUAL(common::PE::Comm::instance().size(), 1);
81 }
82 
83 BOOST_AUTO_TEST_CASE( Heat1DComponent )
84 {
85  Core::instance().environment().options().set("log_level", 4u);
86 
87  // Parameters
88  Real length = 5.;
89  const Uint nb_segments = 5 ;
90 
91  // Setup a model
92  Model& model = *root.create_component<Model>("Model");
93  Domain& domain = model.create_domain("Domain");
94  UFEM::Solver& solver = *model.create_component<UFEM::Solver>("Solver");
95 
96  Handle<UFEM::LSSAction> lss_action(solver.add_direct_solver("cf3.UFEM.LSSAction"));
97 
98  // Proto placeholders
99  FieldVariable<0, ScalarField> temperature("Temperature", UFEM::Tags::solution());
100 
101  // Allowed elements (reducing this list improves compile times)
102  boost::mpl::vector1<mesh::LagrangeP1::Line1D> allowed_elements;
103 
104  // BCs
105  boost::shared_ptr<UFEM::BoundaryConditions> bc = allocate_component<UFEM::BoundaryConditions>("BoundaryConditions");
106 
107  // add the top-level actions (assembly, BC and solve)
108  *lss_action
110  (
111  "Assembly",
113  (
114  allowed_elements,
115  group
116  (
117  _A = _0,
118  element_quadrature( _A(temperature) += transpose(nabla(temperature)) * nabla(temperature) ),
119  lss_action->system_matrix += _A
120  )
121  )
122  )
123  << bc
124  << allocate_component<math::LSS::SolveLSS>("SolveLSS")
125  << create_proto_action("Increment", nodes_expression(temperature += lss_action->solution(temperature)))
126  << create_proto_action("Output", nodes_expression(_cout << "T(" << coordinates(0,0) << ") = " << temperature << "\n"))
127  << create_proto_action("CheckResult", nodes_expression(_check_close(temperature, 10. + 25.*(coordinates(0,0) / length), 1e-6)));
128 
129  // Setup physics
130  model.create_physics("cf3.UFEM.NavierStokesPhysics");
131 
132  // Setup mesh
133  // Mesh& mesh = *domain.create_component<Mesh>("Mesh");
134  // Tools::MeshGeneration::create_line(mesh, length, nb_segments);
135  boost::shared_ptr<MeshGenerator> create_line = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","create_line");
136  create_line->options().set("mesh",domain.uri()/"Mesh");
137  create_line->options().set("lengths",std::vector<Real>(DIM_1D, length));
138  create_line->options().set("nb_cells",std::vector<Uint>(DIM_1D, nb_segments));
139  Mesh& mesh = create_line->generate();
140 
141  lss_action->options().set("regions", std::vector<URI>(1, mesh.topology().uri()));
142 
143  // Set boundary conditions
144  bc->add_constant_bc("xneg", "Temperature", 10.);
145  bc->add_constant_bc("xpos", "Temperature", 35.);
146 
147  // Run the solver
148  model.simulate();
149 }
150 
152 
153 BOOST_AUTO_TEST_SUITE_END()
154 
155 
static boost::proto::terminal< ZeroTag >::type _0
Placeholder for the zero matrix.
Definition: Terminals.hpp:209
void create_line(Mesh &mesh, const Real x_len, const Uint x_segments)
Create a 1D line mesh.
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_direct_solver(const std::string &builder_name)
Definition: Solver.cpp:128
This header collects all the headers needed for the linear system solver, also including configure-ti...
std::vector< Uint > SizesT
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.
tuple root
Definition: coolfluid.py:24
boost::shared_ptr< ElementsExpression< ExprT, ElementTypes > > elements_expression(ElementTypes, const ExprT &expr)
Definition: Expression.hpp:292
Manage a collection of UFEM solvers.
Definition: Solver.hpp:31
static boost::proto::terminal< void(*)(Real, Real, Real) >::type const _check_close
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
static boost::proto::terminal< std::ostream & >::type _cout
Wrap std::cout.
Definition: Terminals.hpp:219
BOOST_AUTO_TEST_CASE(InitMPI)
Static functions for mathematical constants.
Definition: Consts.hpp:25
void check_close(const Real a, const Real b, const Real threshold)
Check close, for testing purposes.
boost::proto::terminal< TransposeFunction >::type const transpose
boost::proto::terminal< SFOp< NablaOp > >::type const nabla
Basic Classes for Mesh applications used by COOLFluiD.
tuple model
Global confifuration.
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
std::vector< std::string > StringsT
common::Environment & environment() const
Definition: Core.cpp:168
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
virtual void simulate()
Simulates this model.
Definition: Model.cpp:132
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
OptionList & options()
Definition: Component.cpp:856
static Comm & instance()
Return a reference to the current PE.
Definition: Comm.cpp:44
Base class for defining CF components.
Definition: Component.hpp:82
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