GRINS-0.7.0
default_bc_builder.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
40 
41 namespace GRINSTesting
42 {
43  class DefaultBCBuilderTest : public CppUnit::TestCase,
44  public SystemHelper,
45  public GRINS::DefaultBCBuilder // So we can test proctected methods
46  {
47  public:
49 
55 
57 
58  public:
59 
60  void tearDown()
61  {
62  this->reset_all();
63  }
64 
66  {
67  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/default_bc_builder.in";
68  GetPot input(filename);
69 
70  std::map<std::string,std::set<GRINS::BoundaryID> > bc_id_map;
71  this->parse_and_build_bc_id_map(input,bc_id_map);
72 
73  // Make sure we have the right sections
74  CPPUNIT_ASSERT_EQUAL(3,(int)bc_id_map.size());
75  CPPUNIT_ASSERT( bc_id_map.find("Hot") != bc_id_map.end() );
76  CPPUNIT_ASSERT( bc_id_map.find("Together") != bc_id_map.end() );
77  CPPUNIT_ASSERT( bc_id_map.find("Cold") != bc_id_map.end() );
78 
79  // Make sure we have the right number and values of the bc ids
80  {
81  std::set<GRINS::BoundaryID> bc_ids = bc_id_map["Hot"];
82  CPPUNIT_ASSERT_EQUAL(1,(int)bc_ids.size());
83  CPPUNIT_ASSERT(bc_ids.find(0) != bc_ids.end());
84  }
85 
86  // Make sure we have the right number and values of the bc ids
87  {
88  std::set<GRINS::BoundaryID> bc_ids = bc_id_map["Together"];
89  CPPUNIT_ASSERT_EQUAL(2,(int)bc_ids.size());
90  CPPUNIT_ASSERT(bc_ids.find(1) != bc_ids.end());
91  CPPUNIT_ASSERT(bc_ids.find(2) != bc_ids.end());
92  }
93 
94  // Make sure we have the right number and values of the bc ids
95  {
96  std::set<GRINS::BoundaryID> bc_ids = bc_id_map["Cold"];
97  CPPUNIT_ASSERT_EQUAL(1,(int)bc_ids.size());
98  CPPUNIT_ASSERT(bc_ids.find(3) != bc_ids.end());
99  }
100  }
101 
103  {
104  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/default_bc_builder.in";
105  this->setup_multiphysics_system(filename);
106 
107  std::map<std::string,std::set<GRINS::BoundaryID> > bc_id_map;
108  this->parse_and_build_bc_id_map(*_input,bc_id_map);
109 
110  // This shouldn't error
111  this->verify_bc_ids_with_mesh( *_system, bc_id_map );
112  }
113 
115  {
116  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/default_bc_builder.in";
117  this->setup_multiphysics_system(filename);
118 
119  // Now we can parse the variable sections and names
120  std::set<std::string> sections;
121  this->parse_var_sections(*_input,sections);
122 
123  // Make sure we have the right sections
124  CPPUNIT_ASSERT_EQUAL(4,(int)sections.size());
125  CPPUNIT_ASSERT( sections.find("Velocity") != sections.end() );
126  CPPUNIT_ASSERT( sections.find("Pressure") != sections.end() );
127  CPPUNIT_ASSERT( sections.find("Temperature") != sections.end() );
128  CPPUNIT_ASSERT( sections.find("SpeciesMassFractions") != sections.end() );
129  }
130 
132  {
133  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/default_bc_builder.in";
134  this->setup_multiphysics_system(filename);
135 
136  libMesh::boundary_id_type invalid_bid =
137  std::numeric_limits<libMesh::boundary_id_type>::max();
138 
139  libMesh::boundary_id_type master_id = invalid_bid;
140  libMesh::boundary_id_type slave_id = invalid_bid;
141 
142  std::string section = GRINS::BoundaryConditionNames::bc_section()+"/Together";
143 
144  this->parse_periodic_master_slave_ids(*_input,section,master_id,slave_id);
145 
146  CPPUNIT_ASSERT_EQUAL(1,(int)master_id);
147  CPPUNIT_ASSERT_EQUAL(2,(int)slave_id);
148  }
149 
151  {
152  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/default_bc_builder.in";
153  this->setup_multiphysics_system(filename);
154 
155  std::string section = GRINS::BoundaryConditionNames::bc_section()+"/Together";
156 
157  libMesh::RealVectorValue offset =
158  this->parse_periodic_offset(*_input,section);
159 
160  libMesh::Real tol = std::numeric_limits<libMesh::Real>::epsilon()*10;
161  CPPUNIT_ASSERT_DOUBLES_EQUAL(1.21,offset(0),tol);
162  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0,offset(1),tol);
163  }
164 
165  private:
166 
167  void test_for_var_name( const std::vector<std::string>& var_names,
168  const std::string& var_to_find )
169  {
170  CPPUNIT_ASSERT( std::find( var_names.begin(), var_names.end(), var_to_find ) != var_names.end() );
171  }
172 
173  };
174 
175  CPPUNIT_TEST_SUITE_REGISTRATION( DefaultBCBuilderTest );
176 
177 } // end namespace GRINSTesting
178 
179 #endif // GRINS_HAVE_CPPUNIT
void parse_and_build_bc_id_map(const GetPot &input, std::map< std::string, std::set< BoundaryID > > &bc_id_map)
CPPUNIT_TEST(test_parse_and_build_bc_id_map)
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
void setup_multiphysics_system(const std::string &filename)
Definition: system_helper.h:42
CPPUNIT_TEST_SUITE(DefaultBCBuilderTest)
void parse_var_sections(const GetPot &input, std::set< std::string > &sections)
void parse_periodic_master_slave_ids(const GetPot &input, const std::string &section, libMesh::boundary_id_type &master_id, libMesh::boundary_id_type &slave_id) const
void verify_bc_ids_with_mesh(const MultiphysicsSystem &system, const std::map< std::string, std::set< BoundaryID > > &bc_id_map) const
libMesh::RealVectorValue parse_periodic_offset(const GetPot &input, const std::string &section) const
Manages runtime construction of Dirichlet boundary conditions.
Helper class for setting up basic GRINS::MultiphysicsSystem for unit testing.
Definition: system_helper.h:38
GRINS::MultiphysicsSystem * _system
Definition: system_helper.h:63
void test_for_var_name(const std::vector< std::string > &var_names, const std::string &var_to_find)
static std::string bc_section()
Outer section name for boundary conditions section in input file.
libMesh::UniquePtr< GetPot > _input
Definition: system_helper.h:58

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