GRINS-0.7.0
variables.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include "grins_config.h"
26 
27 #ifdef GRINS_HAVE_CPPUNIT
28 
29 #include <cppunit/extensions/HelperMacros.h>
30 #include <cppunit/TestCase.h>
31 
32 // Testing headers
33 #include "test_comm.h"
34 #include "grins_test_paths.h"
35 #include "system_helper.h"
36 
37 // GRINS
38 #include "grins/grins_enums.h"
44 
45 namespace GRINSTesting
46 {
47  class VariablesTest : public CppUnit::TestCase,
48  public SystemHelper
49  {
50  public:
52 
59 
61 
62  public:
63 
64  void tearDown()
65  {
66  this->reset_all();
67  }
68 
70  {
71  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_2d.in";
72  this->setup_multiphysics_system(filename);
73 
74  // This will add the variables to the system
75  GRINS::VelocityFEVariables vel_vars(*_input,"PhysicsNameIsDUMMYForThisTest");
76  vel_vars.init(_system);
77  CPPUNIT_ASSERT_EQUAL((unsigned int)2,_system->n_vars());
78 
79  const std::vector<std::string>& var_names = vel_vars.active_var_names();
80  this->test_vel_var_names_2d(var_names);
81 
82  // Verify the FE part
83  this->test_vel_fe_2d(*_system);
84  }
85 
87  {
88  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_3d.in";
89  this->setup_multiphysics_system(filename);
90 
91  // This will add the variables to the system
92  GRINS::VelocityFEVariables vel_vars(*_input,"PhysicsNameIsDUMMYForThisTest");
93  vel_vars.init(_system);
94  CPPUNIT_ASSERT_EQUAL((unsigned int)3,_system->n_vars());
95 
96  const std::vector<std::string>& var_names = vel_vars.active_var_names();
97  this->test_vel_var_names_3d(var_names);
98 
99  // Verify the FE part
100  this->test_vel_fe_3d(*_system);
101  }
102 
103  void test_temp()
104  {
105  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_2d.in";
106  this->setup_multiphysics_system(filename);
107 
108  // This will add the variables to the system
109  GRINS::PrimitiveTempFEVariables temp_vars(*_input,"PhysicsNameIsDUMMYForThisTest");
110  temp_vars.init(_system);
111  CPPUNIT_ASSERT_EQUAL((unsigned int)1,_system->n_vars());
112 
113  const std::vector<std::string>& var_names = temp_vars.active_var_names();
114  this->test_temp_var_names(var_names);
115 
116  // Verify the FE part
117  this->test_temp_fe(*_system);
118  }
119 
121  {
122  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_2d.in";
123  this->setup_multiphysics_system(filename);
124 
125  // This will add the variables to the system
126  GRINS::SpeciesMassFractionsFEVariables species_vars(*_input,"TestSpeciesMassFractionsVariables");
127  species_vars.init(_system);
128  CPPUNIT_ASSERT_EQUAL((unsigned int)2,_system->n_vars());
129 
130  const std::vector<std::string>& var_names = species_vars.active_var_names();
131  this->test_species_var_names(var_names);
132 
133  // Verify the FE part
134  this->test_species_fe(*_system);
135  }
136 
138  {
139  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_3d.in";
140  this->setup_multiphysics_system(filename);
141 
142  GRINS::VelocityFEVariables vel_vars(*_input,"PhysicsNameIsDUMMYForThisTest");
143  GRINS::PressureFEVariable press_vars(*_input,"PhysicsNameIsDUMMYForThisTest",true /*is_constraint_variable*/ );
144 
147 
148  // This should not throw an error
151 
152  vel_vars.init(_system);
153  press_vars.init(_system);
154 
155  {
156  const GRINS::FEVariablesBase& vel_base =
158  CPPUNIT_ASSERT(!vel_base.is_constraint_var());
159 
160  const GRINS::FEVariablesBase& press_base =
162  CPPUNIT_ASSERT(press_base.is_constraint_var());
163  }
164 
165  // Clear out the VariableWarehouse so it doesn't interfere with other tests.
167  }
168 
170  {
171  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_2d.in";
172  this->setup_multiphysics_system(filename);
173 
174  // This will add the variables to the system
175  GRINS::PressureFEVariable press_vars(*_input,"PhysicsNameIsDUMMYForThisTest");
176  press_vars.init(_system);
177  CPPUNIT_ASSERT_EQUAL((unsigned int)1,_system->n_vars());
178 
179  const std::vector<std::string>& var_names = press_vars.active_var_names();
180  this->test_press_var_names(var_names);
181 
182  // Verify the FE part
183  this->test_press_fe(*_system);
184  }
185 
186  private:
187 
188  void test_vel_var_names_2d( const std::vector<std::string>& var_names )
189  {
190  // For 2-D, we should only have 2 components
191  CPPUNIT_ASSERT_EQUAL(2,(int)var_names.size());
192  CPPUNIT_ASSERT_EQUAL(std::string("Ux"),var_names[0]);
193  CPPUNIT_ASSERT_EQUAL(std::string("Uy"),var_names[1]);
194  }
195 
196  void test_vel_var_names_3d( const std::vector<std::string>& var_names )
197  {
198  // For 3-D, we should have 3 components
199  CPPUNIT_ASSERT_EQUAL(3,(int)var_names.size());
200  CPPUNIT_ASSERT_EQUAL(std::string("Ux"),var_names[0]);
201  CPPUNIT_ASSERT_EQUAL(std::string("Uy"),var_names[1]);
202  CPPUNIT_ASSERT_EQUAL(std::string("Uz"),var_names[2]);
203  }
204 
205  void test_temp_var_names( const std::vector<std::string>& var_names )
206  {
207  CPPUNIT_ASSERT_EQUAL(1,(int)var_names.size());
208  CPPUNIT_ASSERT_EQUAL(std::string("T"),var_names[0]);
209  }
210 
211  void test_species_var_names( const std::vector<std::string>& var_names )
212  {
213  CPPUNIT_ASSERT_EQUAL(2,(int)var_names.size());
214  CPPUNIT_ASSERT_EQUAL(std::string("Y_N2"),var_names[0]);
215  CPPUNIT_ASSERT_EQUAL(std::string("Y_N"),var_names[1]);
216  }
217 
218  void test_press_var_names( const std::vector<std::string>& var_names )
219  {
220  CPPUNIT_ASSERT_EQUAL(1,(int)var_names.size());
221  CPPUNIT_ASSERT_EQUAL(std::string("p"),var_names[0]);
222  }
223 
224  void test_species_var_names_no_order( const std::vector<std::string>& var_names )
225  {
226  // For this one, we can't guarantee the order, so we check to
227  // make sure both the species are there.
228  CPPUNIT_ASSERT_EQUAL(2,(int)var_names.size());
229  CPPUNIT_ASSERT( std::find( var_names.begin(), var_names.end(),"Y_N2")
230  != var_names.end() );
231  CPPUNIT_ASSERT( std::find( var_names.begin(), var_names.end(),"Y_N")
232  != var_names.end() );
233  }
234 
235  void test_vel_fe_2d( const libMesh::System& system )
236  {
237  libMesh::Order order = system.variable_type("Ux").order;
238  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Ux").family);
239  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
240 
241  order = system.variable_type("Uy").order;
242  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Uy").family);
243  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
244  }
245 
246  void test_vel_fe_3d( const libMesh::System& system )
247  {
248  this->test_vel_fe_2d(system);
249  libMesh::Order order = system.variable_type("Uz").order;
250  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Uz").family);
251  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
252  }
253 
254  void test_temp_fe( const libMesh::System& system )
255  {
256  libMesh::Order order = system.variable_type("T").order;
257  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("T").family);
258  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
259  }
260 
261  void test_press_fe( const libMesh::System& system )
262  {
263  libMesh::Order order = system.variable_type("p").order;
264  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("p").family);
265  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
266  }
267 
268 
269  void test_species_fe( const libMesh::System& system )
270  {
271  libMesh::Order order = system.variable_type("Y_N2").order;
272  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Y_N2").family);
273  CPPUNIT_ASSERT_EQUAL(GRINSEnums::SECOND,order);
274 
275  order = system.variable_type("Y_N").order;
276  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Y_N").family);
277  CPPUNIT_ASSERT_EQUAL(GRINSEnums::SECOND,order);
278  }
279  };
280 
281  CPPUNIT_TEST_SUITE_REGISTRATION( VariablesTest );
282 
283 } // end namespace GRINSTesting
284 
285 #endif // GRINS_HAVE_CPPUNIT
virtual void init(libMesh::FEMSystem *system)
Add variables to the system.
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
void test_species_var_names_no_order(const std::vector< std::string > &var_names)
Definition: variables.C:224
void setup_multiphysics_system(const std::string &filename)
Definition: system_helper.h:42
void test_species_var_names(const std::vector< std::string > &var_names)
Definition: variables.C:211
void test_species_fe(const libMesh::System &system)
Definition: variables.C:269
CPPUNIT_TEST(test_velocity_2d)
void test_vel_fe_2d(const libMesh::System &system)
Definition: variables.C:235
virtual void init(libMesh::FEMSystem *system)
Add variables to the system.
static void check_and_register_variable(const std::string &var_name, const FEVariablesBase &variable)
First check if var_name is registered and then register.
void test_temp_var_names(const std::vector< std::string > &var_names)
Definition: variables.C:205
void test_press_fe(const libMesh::System &system)
Definition: variables.C:261
void test_press_var_names(const std::vector< std::string > &var_names)
Definition: variables.C:218
void test_vel_fe_3d(const libMesh::System &system)
Definition: variables.C:246
void test_vel_var_names_2d(const std::vector< std::string > &var_names)
Definition: variables.C:188
void test_var_constraint_and_warehouse()
Definition: variables.C:137
void test_vel_var_names_3d(const std::vector< std::string > &var_names)
Definition: variables.C:196
Helper class for setting up basic GRINS::MultiphysicsSystem for unit testing.
Definition: system_helper.h:38
GRINS::MultiphysicsSystem * _system
Definition: system_helper.h:63
static void register_variable(const std::string &var_name, const FEVariablesBase &variable)
static void clear()
Clears the var_map()
static const FEVariablesBase & get_variable(const std::string &var_name)
bool is_constraint_var() const
CPPUNIT_TEST_SUITE(VariablesTest)
const std::vector< std::string > & active_var_names() const
Return the var names that are active from this class.
libMesh::UniquePtr< GetPot > _input
Definition: system_helper.h:58
void test_temp_fe(const libMesh::System &system)
Definition: variables.C:254

Generated on Thu Jun 2 2016 21:52:28 for GRINS-0.7.0 by  doxygen 1.8.10