COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-solver-physics-static2dynamic.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 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 cf3::physics::PhysModel"
9 
10 #include <iostream>
11 
12 #include <boost/test/unit_test.hpp>
13 #include <boost/mpl/void.hpp>
14 
15 #include "common/CF.hpp"
16 
17 using namespace cf3;
18 
19 //----------------------------------------------------------------------------
20 // PhysModel.hpp
21 
22 class Variables;
23 
25 class PhysModel {
26 public:
27 
28  struct Properties {};
29 
30  virtual ~PhysModel() {}
31 
32  virtual Uint dim() = 0;
33  virtual Uint nb_eqs() = 0;
34 
35  virtual PhysModel::Properties* create_properties() = 0;
36 
37  virtual Variables* create_variables( const std::string& name ) = 0;
38 
39 };
40 
41 //----------------------------------------------------------------------------
42 // Variables.hpp
43 
45 class Variables {
46 public:
47  virtual ~Variables() {}
48  virtual void compute_properties( PhysModel::Properties& physp ) = 0;
49  virtual void flux_jacobian( PhysModel::Properties& physp ) = 0;
50 };
51 
52 //----------------------------------------------------------------------------
53 // VariablesT.hpp
54 
55 template < typename PHYS >
56 class VariablesT : public Variables {
57 public:
58 
59  virtual ~VariablesT() {}
60 
62  {
63  typename PHYS::PROPS& cphysp = static_cast<typename PHYS::PROPS&>( physp );
64  PHYS::compute_properties( cphysp );
65  }
66 
67  virtual void flux_jacobian( PhysModel::Properties& physp )
68  {
69  typename PHYS::PROPS& cphysp = static_cast<typename PHYS::PROPS&>( physp );
70  PHYS::flux_jacobian( cphysp );
71  }
72 
73 };
74 
75 //----------------------------------------------------------------------------
76 // Euler2D.hpp
77 
78 class Euler2D : public PhysModel {
79 public:
80 
81  enum { dimension = 2 };
82  enum { neqs = 4 };
83 
85  {
86  Real u;
87  Real v;
88  };
89 
90  virtual Uint dim() { return (Uint) dimension; }
91  virtual Uint nb_eqs() { return (Uint) neqs; }
92 
93  virtual ~Euler2D() {}
94 
96  {
97  return new Euler2D::Properties();
98  }
99 
100  virtual Variables* create_variables( const std::string& name );
101 
102 };
103 
104 //----------------------------------------------------------------------------
105 // Euler2DCons.hpp
106 
108 {
109  typedef Euler2D MODEL;
111 
112  static void compute_properties (PROPS& p )
113  {
114  p.u = 0.;
115  p.v = 10.;
116  }
117 
118  static void flux_jacobian ( PROPS& p )
119  {
120  std::cout << "u " << p.u << std::endl;
121  std::cout << "v " << p.v << std::endl;
122  }
123 };
124 
125 //----------------------------------------------------------------------------
126 // Euler2D.cpp
127 
129 {
130  if (name == "cons")
131  return new VariablesT<Euler2DCons>();
132  else
133  throw std::string("no such variable set available");
134 }
135 
136 
138 
139 BOOST_AUTO_TEST_SUITE( PhysicsSuite )
140 
141 
143 BOOST_AUTO_TEST_CASE( dynamic_api )
144 {
145  PhysModel* pmodel = new Euler2D();
146 
147  PhysModel::Properties* props = pmodel->create_properties();
148  Variables* pv = pmodel->create_variables( "cons");
149 
150  pv->compute_properties(*props);
151  pv->flux_jacobian(*props);
152 
153 }
154 
156 
157 BOOST_AUTO_TEST_CASE( static_api )
158 {
159  PhysModel* pmodel = new Euler2D();
160 
161  PhysModel::Properties* props = pmodel->create_properties();
162 
163  Euler2D::Properties* ep = static_cast<Euler2D::Properties*>(props);
164 
167 }
168 
170 
171 BOOST_AUTO_TEST_CASE( definition_of_model )
172 {
173  PhysModel* pmodel = new Euler2D();
174 
175  BOOST_CHECK_EQUAL( pmodel->dim() , (Uint) Euler2D::dimension );
176  BOOST_CHECK_EQUAL( pmodel->nb_eqs() , (Uint) Euler2D::neqs );
177 
178  BOOST_CHECK_EQUAL( (Uint) Euler2DCons::MODEL::dimension , (Uint) Euler2D::dimension );
179  BOOST_CHECK_EQUAL( (Uint) Euler2DCons::MODEL::neqs , (Uint) Euler2D::neqs );
180 }
181 
183 
184 BOOST_AUTO_TEST_SUITE_END()
185 
186 
virtual void compute_properties(PhysModel::Properties &physp)
virtual void flux_jacobian(PhysModel::Properties &physp)
std::string name(ComponentWrapper &self)
virtual void flux_jacobian(PhysModel::Properties &physp)=0
BOOST_AUTO_TEST_CASE(dynamic_api)
static void compute_properties(PROPS &p)
virtual PhysModel::Properties * create_properties()=0
virtual PhysModel::Properties * create_properties()
Top-level namespace for coolfluid.
Definition: Action.cpp:18
virtual Variables * create_variables(const std::string &name)=0
virtual Variables * create_variables(const std::string &name)
virtual Uint dim()=0
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
coolfluid3 header, included almost everywhere
virtual Uint nb_eqs()=0
static void flux_jacobian(PROPS &p)
virtual void compute_properties(PhysModel::Properties &physp)=0
Send comments to:
COOLFluiD Web Admin