COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-proto-navier-stokes.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 #include "common/Core.hpp"
13 #include "common/Environment.hpp"
14 
15 #include "mesh/Domain.hpp"
16 
17 #include "solver/ModelUnsteady.hpp"
18 #include "solver/Time.hpp"
19 #include "solver/Tags.hpp"
20 
24 #include "solver/CriterionTime.hpp"
26 
28 #include "mesh/MeshGenerator.hpp"
29 
31 #include "UFEM/Solver.hpp"
32 #include "UFEM/Tags.hpp"
34 
35 #include "NavierStokes.hpp"
36 #include "math/LSS/ZeroLSS.hpp"
37 #include "math/LSS/SolveLSS.hpp"
38 
39 using namespace cf3;
40 using namespace cf3::solver;
41 using namespace cf3::solver::actions;
42 using namespace cf3::solver::actions::Proto;
43 using namespace cf3::common;
44 using namespace cf3::math::Consts;
45 using namespace cf3::mesh;
46 using namespace cf3::UFEM;
47 
48 using namespace boost;
49 
50 typedef std::vector<std::string> StringsT;
51 typedef std::vector<Uint> SizesT;
52 
53 BOOST_AUTO_TEST_SUITE( ProtoStokesArtifDissSuite )
54 
55 inline void
56 check_close(const Real a, const Real b, const Real threshold)
57 {
58  BOOST_CHECK_SMALL(a - b, threshold);
59 }
60 
61 static boost::proto::terminal< void(*)(Real, Real, Real) >::type const _check_close = {&check_close};
62 
64 {
65  common::PE::Comm::instance().init(boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv);
66  BOOST_CHECK_EQUAL(common::PE::Comm::instance().size(), 1);
67 }
68 
69 // Solve the Stokes equations with artificial dissipation
70 BOOST_AUTO_TEST_CASE( ProtoNavierStokes )
71 {
72  // debug output
73  Core::instance().environment().options().set("log_level", 1u);
74 
75  const Real length = 5.;
76  const Real height = 2.;
77  const Uint x_segments = 25;
78  const Uint y_segments = 10;
79 
80  const Real start_time = 0.;
81  const Real end_time = 5.;
82  const Real dt = 1.;
83  Real t = start_time;
84  const Uint write_interval = 5000;
85  const Real invdt = 1. / dt;
86 
87  const Real mu = 1.;
88  const Real rho = 1.;
89 
90  const std::vector<Real> u_wall(2, 0.);
91  const Real p0 = 10.;
92  const Real p1 = 0.;
93  const Real c = 0.5*(p0 - p1) / (rho * mu * length);
94  const RealVector2 u_max(c, 0.);
95 
96  // Parabolic expression for the inlet
97  std::stringstream parabole_str;
98  parabole_str << "y*(" << height << "-y)*" << c;
99  std::vector<std::string> parabole_functions(2, "0");
100  parabole_functions[0] = parabole_str.str();
101 
102 
103  // List of (Navier-)Stokes creation functions, with their names
104  const std::vector<std::string> names = boost::assign::list_of("stokes_artifdiss")("stokes_pspg")("navier_stokes_pspg")("navier_stokes_supg");
105  typedef boost::shared_ptr< ProtoAction > (*FactoryT)(LSSActionUnsteady&);
106  std::vector<FactoryT> factories = boost::assign::list_of(&stokes_artifdiss)(&stokes_pspg)(&navier_stokes_pspg)(&navier_stokes_supg);
107 
108  // Loop over all model types
109  for(Uint i = 0; i != names.size(); ++i)
110  {
111  std::cout << "\n################################## Running test for model " << names[i] << "##################################\n" << std::endl;
112  // Setup a model
114  Domain& domain = model.create_domain("Domain");
115  UFEM::Solver& solver = *model.create_component<UFEM::Solver>("Solver");
116  Handle<UFEM::LSSActionUnsteady> lss_action(solver.add_unsteady_solver("cf3.UFEM.LSSActionUnsteady"));
117  lss_action->set_solution_tag("navier_stokes_solution");
118  Handle<common::ActionDirector> ic(solver.get_child("InitialConditions"));
119 
120  boost::shared_ptr<solver::actions::Iterate> time_loop = allocate_component<solver::actions::Iterate>("TimeLoop");
121  time_loop->create_component<solver::CriterionTime>("CriterionTime");
122 
123  // Expression variables
124  FieldVariable<0, VectorField> u("Velocity", "navier_stokes_solution");
125  FieldVariable<1, ScalarField> p("Pressure", "navier_stokes_solution");
126  FieldVariable<2, VectorField> u_adv("AdvectionVelocity", "linearized_velocity");
127  FieldVariable<3, ScalarField> nu_eff("EffectiveViscosity", "navier_stokes_viscosity");
128 
129  PhysicsConstant nu("kinematic_viscosity");
130 
131  // Velocity initial condition
132  boost::shared_ptr<UFEM::ParsedFunctionExpression> vel_init = allocate_component<UFEM::ParsedFunctionExpression>("InitializeVelocity");
133  vel_init->set_expression(nodes_expression(u = vel_init->vector_function()));
134  vel_init->options().set("value", parabole_functions);
135 
136  *ic << create_proto_action("InitializePressure", nodes_expression(p = 0.)) << vel_init;
137 
138  // BC
139  boost::shared_ptr<UFEM::BoundaryConditions> bc = allocate_component<UFEM::BoundaryConditions>("BoundaryConditions");
140  bc->set_solution_tag("navier_stokes_solution");
141 
142  // build up the solver out of different actions
143  *lss_action
144  << create_proto_action("AdvectionVel", nodes_expression(u_adv = u))
145  << create_proto_action("InitNu", nodes_expression(nu_eff = nu))
146  << allocate_component<math::LSS::ZeroLSS>("ZeroLSS")
147  << factories[i](*lss_action)
148  << bc
149  << allocate_component<math::LSS::SolveLSS>("SolveLSS")
150  << create_proto_action("IncrementU", nodes_expression(u += lss_action->solution(u)))
151  << create_proto_action("IncrementP", nodes_expression(p += lss_action->solution(p)));
152  solver
153  << create_proto_action("CheckP", nodes_expression(_check_close(p, p0 * (length - coordinates[0]) / length + p1 * coordinates[1] / length, 1.)))
154  << create_proto_action("CheckU", nodes_expression(_check_close(u[0], c * coordinates[1] * (height - coordinates[1]), 5e-2)))
155  << create_proto_action("CheckV", nodes_expression(_check_close(u[1], 0., 6e-3)));
156 
158 
159  // Setup physics
160  physics::PhysModel& physical_model = model.create_physics("cf3.UFEM.NavierStokesPhysics");
161  if(is_not_null(ns_solver))
162  {
163  ns_solver->options().set("physical_model", physical_model.handle<physics::PhysModel>());
164  }
165  physical_model.options().set("density", rho);
166  physical_model.options().set("dynamic_viscosity", mu);
167 
168  // Setup mesh
169  boost::shared_ptr<MeshGenerator> create_rectangle = build_component_abstract_type<MeshGenerator>("cf3.mesh.SimpleMeshGenerator","create_line");
170  create_rectangle->options().set("mesh",domain.uri()/"Mesh");
171  std::vector<Real> lengths(2); lengths[XX] = length; lengths[YY] = height;
172  std::vector<Uint> nb_cells(2); nb_cells[XX] = x_segments; nb_cells[YY] = y_segments;
173  create_rectangle->options().set("lengths",lengths);
174  create_rectangle->options().set("nb_cells",nb_cells);
175  Mesh& mesh = create_rectangle->generate();
176 
177  solver.configure_option_recursively("regions", std::vector<URI>(1, mesh.topology().uri()));
178 
179  if(is_not_null(ns_solver))
180  {
181  ns_solver->options().set("lss", lss_action->get_child("LSS"));
182  }
183 
184  // Boundary conditions
185  bc->add_constant_bc("left", "Pressure", p0);
186  bc->add_constant_bc("right", "Pressure", p1);
187  bc->add_constant_bc("bottom", "Velocity", u_wall);
188  bc->add_constant_bc("top", "Velocity", u_wall);
189  bc->add_function_bc("left", "Velocity")->options().set("value", parabole_functions);
190  //bc->add_function_bc("right", "Velocity")->options().set("value", parabole_functions);
191 
192  // Configure timings
193  Time& time = model.create_time();
194  time.options().set("time_step", dt);
195  time.options().set("end_time", end_time);
196 
197  // Run the solver
198  model.simulate();
199 
200  domain.write_mesh("ns-test-" + names[i] + ".pvtu");
201  }
202 }
203 
204 BOOST_AUTO_TEST_SUITE_END()
boost::shared_ptr< solver::actions::Proto::ProtoAction > stokes_pspg(LSSActionUnsteady &solver)
Assembly for the Stokes equations, stabilized with PSPG.
Time & create_time(const std::string &name="Time")
Create Time component.
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
Handle< common::Action > add_unsteady_solver(const std::string &builder_name)
Definition: Solver.cpp:138
void configure_option_recursively(const std::string &optname, const boost::any &val)
Definition: Component.cpp:1157
boost::shared_ptr< solver::actions::Proto::ProtoAction > navier_stokes_pspg(LSSActionUnsteady &solver)
Assembly for the Navier-Stokes equations, stabilized with PSPG.
void check_close(const Real a, const Real b, const Real threshold)
Basic Classes for Solver applications used by CF.
Definition: Action.cpp:29
URI uri() const
Construct the full path.
Definition: Component.cpp:248
boost::shared_ptr< solver::actions::Proto::ProtoAction > navier_stokes_supg(LSSActionUnsteady &solver)
Assembly for the Navier-Stokes equations, stabilized with SUPG.
static boost::proto::terminal< void(*)(Real, Real, Real) >::type const _check_close
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
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Static functions for mathematical constants.
Definition: Consts.hpp:25
Definition: Defs.hpp:17
std::vector< Uint > SizesT
Refers to a value from the physical model.
Storage for time, and time steps for unsteady simulation.
Definition: Time.hpp:26
Basic Classes for Mesh applications used by COOLFluiD.
tuple model
Global confifuration.
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
boost::shared_ptr< solver::actions::Proto::ProtoAction > stokes_artifdiss(LSSActionUnsteady &solver)
Assembly for the Stokes equations, stabilized with artificial dissipation.
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.
BOOST_AUTO_TEST_CASE(InitMPI)
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
common::Component & root() const
Gives the default root component.
Definition: Core.cpp:145
common::Environment & environment() const
Definition: Core.cpp:168
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
Handle< Component > handle()
Get a handle to the component.
Definition: Component.hpp:179
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
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
std::vector< std::string > StringsT
Send comments to:
COOLFluiD Web Admin