COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-proto-ns-assembly.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 "Tests the assembly on a single element"
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 #endif
16 #define BOOST_MPL_LIMIT_METAFUNCTION_ARITY 10
17 
18 #include "common/Core.hpp"
19 #include "common/Environment.hpp"
20 #include "common/Group.hpp"
21 
22 #include "mesh/Domain.hpp"
25 
26 #include "solver/Tags.hpp"
27 
30 #include <solver/ModelUnsteady.hpp>
31 #include <solver/Solver.hpp>
32 
33 #include <UFEM/Solver.hpp>
35 
36 using namespace cf3;
37 using namespace cf3::solver;
38 using namespace cf3::solver::actions;
39 using namespace cf3::solver::actions::Proto;
40 using namespace cf3::common;
41 using namespace cf3::mesh;
42 using namespace cf3::UFEM;
43 
44 using namespace boost;
45 
46 typedef std::vector<std::string> StringsT;
47 typedef std::vector<Uint> SizesT;
48 
50 {
51  template<Uint Dim, typename ExprT>
52  void run_model(const boost::shared_ptr<Mesh>& mesh, const ExprT& initial_condition_expression, const Real eps = 1e-10)
53  {
54  boost::shared_ptr<common::Group> root = allocate_component<Group>("Root");
55  Handle<ModelUnsteady> model = root->create_component<ModelUnsteady>("NavierStokes");
56  Domain& domain = model->create_domain("Domain");
57  physics::PhysModel& physical_model = model->create_physics("cf3.UFEM.NavierStokesPhysics");
58 
59  Handle<UFEM::Solver> solver(model->create_solver("cf3.UFEM.Solver").handle());
60  Handle<InitialConditions> ic = solver->create_initial_conditions();
61  Handle<UFEM::LSSActionUnsteady> lss_action(solver->add_unsteady_solver("cf3.UFEM.NavierStokes"));
62 
63  physical_model.options().set("density", 1.);
64  physical_model.options().set("dynamic_viscosity", 1.);
65 
66  Time& time = model->create_time();
67  time.options().set("time_step", 1.);
68 
69  ic->remove_component(lss_action->solution_tag());
70 
71  domain.add_component(mesh);
72  mesh->raise_mesh_loaded();
73 
74  solver->configure_option_recursively("regions", std::vector<URI>(1, mesh->topology().uri()));
75  math::LSS::System& lss = lss_action->create_lss();
76 
77  const std::vector<std::string> disabled_actions = boost::assign::list_of("BoundaryConditions")("SolveLSS")("Update");
78  lss_action->options().set("disabled_actions", disabled_actions);
79 
80  lss_action->options().set("use_specializations", true);
81  time.options().set("end_time", 1.);
82  solver->create_fields();
83  for_each_node<Dim>(mesh->topology(), initial_condition_expression);
84  model->simulate();
85 
86  const Uint matsize = lss.matrix()->blockcol_size()*lss.matrix()->neq();
87 
88  RealMatrix spec_result(matsize, matsize);
89  for(Uint i = 0; i != matsize; ++i)
90  for(Uint j = 0; j != matsize; ++j)
91  lss.matrix()->get_value(i, j, spec_result(i,j));
92 
93  lss_action->options().set("use_specializations", false);
94  time.options().set("end_time", 2.);
95  model->simulate();
96 
97  RealMatrix generic_result(matsize, matsize);
98  for(Uint i = 0; i != matsize; ++i)
99  for(Uint j = 0; j != matsize; ++j)
100  lss.matrix()->get_value(i, j, generic_result(i,j));
101 
102  check_close(generic_result, spec_result, eps);
103  }
104 
105  boost::shared_ptr<Mesh> create_triangle(const RealVector2& a, const RealVector2& b, const RealVector2& c)
106  {
107  // coordinates
108  boost::shared_ptr<Mesh> mesh_ptr = allocate_component<Mesh>("mesh");
109  Mesh& mesh = *mesh_ptr;
110  mesh.initialize_nodes(3, 2);
111  Dictionary& geometry_dict = mesh.geometry_fields();
112  Field& coords = geometry_dict.coordinates();
113  coords << a[0] << a[1] << b[0] << b[1] << c[0] << c[1];
114 
115  // Define the volume cells, i.e. the blocks
116  Elements& cells = mesh.topology().create_region("cells").create_elements("cf3.mesh.LagrangeP1.Triag2D", geometry_dict);
117  cells.resize(1);
118  cells.geometry_space().connectivity() << 0 << 1 << 2;
119 
120  return mesh_ptr;
121  }
122 
123  boost::shared_ptr<Mesh> create_tetra(const RealVector3& a, const RealVector3& b, const RealVector3& c, const RealVector3& d)
124  {
125  boost::shared_ptr<Mesh> mesh_ptr = allocate_component<Mesh>("mesh");
126  Mesh& mesh = *mesh_ptr;
127  // coordinates
128  mesh.initialize_nodes(4, 3);
129  Dictionary& geometry_dict = mesh.geometry_fields();
130  Field& coords = geometry_dict.coordinates();
131  coords << a[0] << a[1] << a[2] << b[0] << b[1] << b[2] << c[0] << c[1] << c[2] << d[0] << d[1] << d[2];
132 
133  // Define the volume cells, i.e. the blocks
134  Elements& cells = mesh.topology().create_region("cells").create_elements("cf3.mesh.LagrangeP1.Tetra3D", geometry_dict);
135  cells.resize(1);
136  cells.geometry_space().connectivity() << 0 << 1 << 2 << 3;
137 
138  return mesh_ptr;
139  }
140 
141  void check_close(const RealMatrix& a, const RealMatrix& b, const Real eps)
142  {
143  for(Uint i = 0; i != a.rows(); ++i)
144  for(Uint j = 0; j != a.cols(); ++j)
145  BOOST_CHECK_CLOSE(a(i,j), b(i,j), eps);
146  }
147 };
148 
149 BOOST_FIXTURE_TEST_SUITE( NavierStokesAssemblySuite, NavierStokesAssemblyFixture )
150 
152 {
153  common::PE::Comm::instance().init(boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv);
154  BOOST_CHECK_EQUAL(common::PE::Comm::instance().size(), 1);
155  Core::instance().environment().options().set("log_level", 1u);
156 }
157 
158 BOOST_AUTO_TEST_CASE( UnitTriangleUniform )
159 {
160  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
161  RealVector u_init(2); u_init << 1., 1.;
162  // TODO: Check why the triangles fail
163  //run_model<2>(create_triangle(RealVector2(0., 0.), RealVector2(1., 0.), RealVector2(0., 1.)), u = u_init);
164 }
165 
166 BOOST_AUTO_TEST_CASE( TetraUniform )
167 {
168  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
169  RealVector u_init(3); u_init << 1., 1., 1.;
170  //run_model<3>(create_tetra(RealVector3(0., 0., 0.), RealVector3(1., 0., 0.), RealVector3(0., 1., 0.), RealVector3(0., 0., 1.)), u = u_init);
171 }
172 
173 BOOST_AUTO_TEST_CASE( GenericTriangleUniform )
174 {
175  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
176  RealVector u_init(2); u_init << 1., 1.;
177  // TODO: Check why the triangles fail
178  //run_model<2>(create_triangle(RealVector2(0.2, 0.1), RealVector2(0.75, -0.1), RealVector2(0.33, 0.83)), u = u_init);
179 }
180 
181 
182 BOOST_AUTO_TEST_CASE( GenericTetraUniform )
183 {
184  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
185  RealVector u_init(3); u_init << 1., 1., 1.;
186  //run_model<3>(create_tetra(RealVector3(0.2, 0.1, -0.1), RealVector3(0.75, -0.1, 0.05), RealVector3(0.33, 0.83, 0.23), RealVector3(0.1, -0.1, 0.67)), u = u_init);
187 }
188 
189 
190 BOOST_AUTO_TEST_CASE( GenericTriangleVortex )
191 {
192  RealMatrix2 n_op; n_op << 0., 100., -100., 0.; // Linear operator to create a normal vector in 2D
193  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
194  // TODO: Check why the triangles fail
195  //run_model<2>(create_triangle(RealVector2(100.2, 100.1), RealVector2(100.75, 99.9), RealVector2(100.33, 100.83)), u = n_op*coordinates / (coordinates[0]*coordinates[0] + coordinates[1]*coordinates[1]), 0.5);
196 }
197 
198 BOOST_AUTO_TEST_CASE( GenericTetraVortex )
199 {
200  RealMatrix3 n_op; n_op << 0., 1., 0., -1., 0., 0., 0., 0., 0.; // Linear operator to create a normal vector
201  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
202  //run_model<3>(create_tetra(RealVector3(100.2, 100.1, 99.9), RealVector3(100.75, 99.9, 100.05), RealVector3(100.33, 100.83, 100.23), RealVector3(100.1, 99.9, 100.67)), u = n_op*coordinates / (coordinates[0]*coordinates[0] + coordinates[1]*coordinates[1]), 5.);
203 }
204 
205 BOOST_AUTO_TEST_SUITE_END()
void check_close(const Real a, const Real b, const Real threshold)
Check close, for testing purposes.
boost::shared_ptr< Mesh > create_tetra(const RealVector3 &a, const RealVector3 &b, const RealVector3 &c, const RealVector3 &d)
boost::shared_ptr< Mesh > create_triangle(const RealVector2 &a, const RealVector2 &b, const RealVector2 &c)
void check_close(const RealMatrix &a, const RealMatrix &b, const Real eps)
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
external boost library namespace
Space & geometry_space() const
Definition: Entities.hpp:94
Basic Classes for Solver applications used by CF.
Definition: Action.cpp:29
Handle< LSS::Matrix > matrix()
Accessor to matrix.
Definition: System.hpp:145
const Field & coordinates() const
Definition: Dictionary.cpp:481
tuple root
Definition: coolfluid.py:24
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealMatrix
Dynamic sized matrix of Real scalars.
Definition: MatrixTypes.hpp:22
void run_model(const boost::shared_ptr< Mesh > &mesh, const ExprT &initial_condition_expression, const Real eps=1e-10)
Storage for time, and time steps for unsteady simulation.
Definition: Time.hpp:26
BOOST_AUTO_TEST_CASE(InitMPI)
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.
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
std::vector< std::string > StringsT
void resize(const Uint nb_elem)
Definition: Entities.cpp:246
std::vector< Uint > SizesT
common::Environment & environment() const
Definition: Core.cpp:168
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
Eigen::Matrix< Real, 2, 2 > RealMatrix2
Fixed size 2x2 matrix.
Definition: MatrixTypes.hpp:34
Eigen::Matrix< Real, 2, 1 > RealVector2
Fixed size 2x1 column vector.
Definition: MatrixTypes.hpp:40
static Core & instance()
Definition: Core.cpp:37
Eigen::Matrix< Real, 3, 3 > RealMatrix3
Fixed size 3x3 matrix.
Definition: MatrixTypes.hpp:35
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
Most basic kernel library.
Definition: Action.cpp:19
Connectivity & connectivity()
connectivity table to dictionary entries
Definition: Space.hpp:110
Eigen::Matrix< Real, 3, 1 > RealVector3
Fixed size 3x1 column vector.
Definition: MatrixTypes.hpp:41
Send comments to:
COOLFluiD Web Admin