GRINS-0.8.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-2017 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 <libmesh/ignore_warnings.h>
30 #include <cppunit/extensions/HelperMacros.h>
31 #include <cppunit/TestCase.h>
32 #include <libmesh/restore_warnings.h>
33 
34 // Testing headers
35 #include "test_comm.h"
36 #include "grins_test_paths.h"
37 #include "system_helper.h"
38 
39 // GRINS
40 #include "grins/grins_enums.h"
43 #include "grins/single_variable.h"
45 #include "grins/variable_builder.h"
47 
48 // Ignore warnings from auto_ptr in CPPUNIT_TEST_SUITE_END()
49 #include <libmesh/ignore_warnings.h>
50 
51 namespace GRINSTesting
52 {
53  class VariablesTest : public CppUnit::TestCase,
54  public SystemHelper
55  {
56  public:
58 
62 
64 
65  public:
66 
67  void tearDown()
68  {
69  this->reset_all();
70  }
71 
73  {
74  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_2d.in";
75  this->setup_multiphysics_system(filename);
76 
78 
84 
85  // Clear out the VariableWarehouse so it doesn't interfere with other tests.
87  }
88 
90  {
91  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_3d.in";
92  this->setup_multiphysics_system(filename);
93 
95 
96  const GRINS::FEVariablesBase& vel_vars =
98 
99  GRINS::FEVariablesBase& press_vars =
101  press_vars.set_is_constraint_var(true);
102 
103  CPPUNIT_ASSERT(!vel_vars.is_constraint_var());
104  CPPUNIT_ASSERT(press_vars.is_constraint_var());
105 
106  // Clear out the VariableWarehouse so it doesn't interfere with other tests.
108  }
109 
111  {
112  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/variables_arbitrary_names.in";
113  this->setup_multiphysics_system(filename);
114 
116 
117  this->test_all_variables( "MySpeed",
118  "TestingIsSoHot",
119  "MassFractions",
120  "SoMuchPressure",
121  "ForeverAlone" );
122 
123  // Clear out the VariableWarehouse so it doesn't interfere with other tests.
125  }
126 
127  private:
128 
129  void test_all_variables( const std::string& velocity_name,
130  const std::string& temp_name,
131  const std::string& species_name,
132  const std::string& press_name,
133  const std::string& single_var_name )
134  {
135  // There should be 7 variables generated from that input file
136  CPPUNIT_ASSERT_EQUAL((unsigned int)7,_system->n_vars());
137 
138  // Check Velocity variables
139  {
140  const GRINS::FEVariablesBase& vel_vars =
142 
143  const std::vector<std::string>& var_names = vel_vars.active_var_names();
144  this->test_vel_var_names_2d(var_names);
145 
146  // Verify the FE part
147  this->test_vel_fe_2d(*_system);
148  }
149 
150  // Check Temperature variables
151  {
152  const GRINS::FEVariablesBase& temp_vars =
154 
155  const std::vector<std::string>& var_names = temp_vars.active_var_names();
156  this->test_temp_var_names(var_names);
157 
158  // Verify the FE part
159  this->test_temp_fe(*_system);
160  }
161 
162  // Check SpeciesMassFractions variables
163  {
164  const GRINS::FEVariablesBase& species_vars =
166 
167  const std::vector<std::string>& var_names = species_vars.active_var_names();
168  this->test_species_var_names(var_names);
169 
170  // Verify the FE part
171  this->test_species_fe(*_system);
172  }
173 
174  // Check Pressure variable
175  {
176  const GRINS::FEVariablesBase& press_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  // Check Single variable
187  {
188  const GRINS::FEVariablesBase& single_var =
190 
191  const std::vector<std::string>& var_names = single_var.active_var_names();
192  CPPUNIT_ASSERT_EQUAL(1,(int)var_names.size());
193  CPPUNIT_ASSERT_EQUAL(std::string("u"),var_names[0]);
194 
195  // Verify the FE part
196  libMesh::Order order = _system->variable_type("u").order;
197  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,_system->variable_type("u").family);
198  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
199  }
200  }
201 
202  void test_vel_var_names_2d( const std::vector<std::string>& var_names )
203  {
204  // For 2-D, we should only have 2 components
205  CPPUNIT_ASSERT_EQUAL(2,(int)var_names.size());
206  CPPUNIT_ASSERT_EQUAL(std::string("Ux"),var_names[0]);
207  CPPUNIT_ASSERT_EQUAL(std::string("Uy"),var_names[1]);
208  }
209 
210  void test_vel_var_names_3d( const std::vector<std::string>& var_names )
211  {
212  // For 3-D, we should have 3 components
213  CPPUNIT_ASSERT_EQUAL(3,(int)var_names.size());
214  CPPUNIT_ASSERT_EQUAL(std::string("Ux"),var_names[0]);
215  CPPUNIT_ASSERT_EQUAL(std::string("Uy"),var_names[1]);
216  CPPUNIT_ASSERT_EQUAL(std::string("Uz"),var_names[2]);
217  }
218 
219  void test_temp_var_names( const std::vector<std::string>& var_names )
220  {
221  CPPUNIT_ASSERT_EQUAL(1,(int)var_names.size());
222  CPPUNIT_ASSERT_EQUAL(std::string("T"),var_names[0]);
223  }
224 
225  void test_species_var_names( const std::vector<std::string>& var_names )
226  {
227  CPPUNIT_ASSERT_EQUAL(2,(int)var_names.size());
228  CPPUNIT_ASSERT_EQUAL(std::string("Y_N2"),var_names[0]);
229  CPPUNIT_ASSERT_EQUAL(std::string("Y_N"),var_names[1]);
230  }
231 
232  void test_press_var_names( const std::vector<std::string>& var_names )
233  {
234  CPPUNIT_ASSERT_EQUAL(1,(int)var_names.size());
235  CPPUNIT_ASSERT_EQUAL(std::string("p"),var_names[0]);
236  }
237 
238  void test_species_var_names_no_order( const std::vector<std::string>& var_names )
239  {
240  // For this one, we can't guarantee the order, so we check to
241  // make sure both the species are there.
242  CPPUNIT_ASSERT_EQUAL(2,(int)var_names.size());
243  CPPUNIT_ASSERT( std::find( var_names.begin(), var_names.end(),"Y_N2")
244  != var_names.end() );
245  CPPUNIT_ASSERT( std::find( var_names.begin(), var_names.end(),"Y_N")
246  != var_names.end() );
247  }
248 
249  void test_vel_fe_2d( const libMesh::System& system )
250  {
251  libMesh::Order order = system.variable_type("Ux").order;
252  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Ux").family);
253  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
254 
255  order = system.variable_type("Uy").order;
256  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Uy").family);
257  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
258  }
259 
260  void test_vel_fe_3d( const libMesh::System& system )
261  {
262  this->test_vel_fe_2d(system);
263  libMesh::Order order = system.variable_type("Uz").order;
264  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Uz").family);
265  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
266  }
267 
268  void test_temp_fe( const libMesh::System& system )
269  {
270  libMesh::Order order = system.variable_type("T").order;
271  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("T").family);
272  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
273  }
274 
275  void test_press_fe( const libMesh::System& system )
276  {
277  libMesh::Order order = system.variable_type("p").order;
278  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("p").family);
279  CPPUNIT_ASSERT_EQUAL(GRINSEnums::FIRST,order);
280  }
281 
282 
283  void test_species_fe( const libMesh::System& system )
284  {
285  libMesh::Order order = system.variable_type("Y_N2").order;
286  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Y_N2").family);
287  CPPUNIT_ASSERT_EQUAL(GRINSEnums::SECOND,order);
288 
289  order = system.variable_type("Y_N").order;
290  CPPUNIT_ASSERT_EQUAL(GRINSEnums::LAGRANGE,system.variable_type("Y_N").family);
291  CPPUNIT_ASSERT_EQUAL(GRINSEnums::SECOND,order);
292  }
293  };
294 
295  CPPUNIT_TEST_SUITE_REGISTRATION( VariablesTest );
296 
297 } // end namespace GRINSTesting
298 
299 #endif // GRINS_HAVE_CPPUNIT
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
void test_species_var_names_no_order(const std::vector< std::string > &var_names)
Definition: variables.C:238
void setup_multiphysics_system(const std::string &filename)
Definition: system_helper.h:42
CPPUNIT_TEST(test_variable_builder)
void test_species_var_names(const std::vector< std::string > &var_names)
Definition: variables.C:225
void test_species_fe(const libMesh::System &system)
Definition: variables.C:283
static std::string temperature_section()
void test_vel_fe_2d(const libMesh::System &system)
Definition: variables.C:249
void test_all_variables(const std::string &velocity_name, const std::string &temp_name, const std::string &species_name, const std::string &press_name, const std::string &single_var_name)
Definition: variables.C:129
void test_temp_var_names(const std::vector< std::string > &var_names)
Definition: variables.C:219
void test_press_fe(const libMesh::System &system)
Definition: variables.C:275
void test_press_var_names(const std::vector< std::string > &var_names)
Definition: variables.C:232
void test_vel_fe_3d(const libMesh::System &system)
Definition: variables.C:260
static std::string velocity_section()
static FEVariablesBase & get_variable(const std::string &var_name)
static std::string species_mass_fractions_section()
void test_vel_var_names_2d(const std::vector< std::string > &var_names)
Definition: variables.C:202
static void build_variables(const GetPot &input, MultiphysicsSystem &system)
static std::string pressure_section()
void test_vel_var_names_3d(const std::vector< std::string > &var_names)
Definition: variables.C:210
Helper class for setting up basic GRINS::MultiphysicsSystem for unit testing.
Definition: system_helper.h:38
GRINS::MultiphysicsSystem * _system
Definition: system_helper.h:67
static std::string single_var_section()
static void clear()
Clears the var_map()
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.
void set_is_constraint_var(bool is_constraint_var)
Set whether or not this is a "constraint" variable.
libMesh::UniquePtr< GetPot > _input
Definition: system_helper.h:62
void test_temp_fe(const libMesh::System &system)
Definition: variables.C:268

Generated on Tue Dec 19 2017 12:47:29 for GRINS-0.8.0 by  doxygen 1.8.9.1