GRINS-0.7.0
old_style_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 // This class
27 
28 // GRINS
29 #include "grins/common.h"
30 #include "grins/var_typedefs.h"
31 #include "grins/physics_naming.h"
32 #include "grins/multiphysics_sys.h"
42 
43 // libMesh
44 #include "libmesh/dof_map.h"
45 #include "libmesh/getpot.h"
46 
47 namespace GRINS
48 {
49  void OldStyleBCBuilder::build_bcs( const GetPot& input, MultiphysicsSystem& system,
50  std::vector<SharedPtr<NeumannBCContainer> >& neumann_bcs )
51  {
52  // Warn about deprecation of this horrid style
53  {
54  std::string warning = "WARNING: Specifying boundary conditions in the\n";
55  warning += " Physics sections is DEPRECATED! Please\n";
56  warning += " update your input file to new the newer\n";
57  warning += " style. See the examples for an illustration.\n";
58 
59  grins_warning(warning);
60  }
61 
62  libMesh::DofMap& dof_map = system.get_dof_map();
63 
64  const PhysicsList& physics_list = system.get_physics_list();
65 
66  std::set<std::string> basic_physics;
67  this->build_basic_physics(basic_physics);
68 
69  std::set<std::string> vel_and_temp_physics;
70  this->build_vel_and_temp_physics(vel_and_temp_physics);
71 
72  std::set<std::string> reacting_physics;
73  this->build_reacting_physics(reacting_physics);
74 
75  for( PhysicsListIter physics_iter = physics_list.begin();
76  physics_iter != physics_list.end();
77  physics_iter++ )
78  {
79  std::string physics_name = physics_iter->first;
80  std::string raw_physics_name = PhysicsNaming::extract_physics(physics_name);
81 
82  std::string section_name = "Physics/"+physics_name;
83 
84  if( basic_physics.find( raw_physics_name ) != basic_physics.end() )
85  {
86  this->construct_bcs_old_style(input,
87  system,
88  raw_physics_name,
89  section_name,
90  "bc_ids",
91  "bc_types",
92  "bc_values",
93  "bc_variables",
94  dof_map,
95  neumann_bcs);
96  }
97 
98  if( (vel_and_temp_physics.find( raw_physics_name ) != vel_and_temp_physics.end()) ||
99  (reacting_physics.find( raw_physics_name ) != reacting_physics.end()) )
100  {
101  this->construct_bcs_old_style(input,
102  system,
103  raw_physics_name,
104  section_name,
105  "vel_bc_ids",
106  "vel_bc_types",
107  "vel_bc_values",
108  "vel_bc_variables",
109  dof_map,
110  neumann_bcs);
111 
112  this->construct_bcs_old_style(input,
113  system,
114  raw_physics_name,
115  section_name,
116  "temp_bc_ids",
117  "temp_bc_types",
118  "temp_bc_values",
119  "temp_bc_variables",
120  dof_map,
121  neumann_bcs);
122  }
123 
124  if( reacting_physics.find( raw_physics_name ) != reacting_physics.end() )
125  {
126  this->construct_bcs_old_style(input,
127  system,
128  raw_physics_name,
129  section_name,
130  "species_bc_ids",
131  "species_bc_types",
132  "species_bc_values",
133  "species_bc_variables",
134  dof_map,
135  neumann_bcs);
136  }
137  }
138  }
139 
140  const FEVariablesBase* OldStyleBCBuilder::determine_variable_group( const std::string& raw_physics_name,
141  const std::string& bc_type_str,
142  std::string& var_section )
143  {
144  if( bc_type_str == std::string("bc_types") )
145  {
146  if( raw_physics_name == PhysicsNaming::incompressible_navier_stokes() ||
147  raw_physics_name == PhysicsNaming::stokes() )
148  var_section = VariablesParsing::velocity_section();
149  else if( raw_physics_name == PhysicsNaming::heat_conduction() ||
150  raw_physics_name == PhysicsNaming::heat_transfer() ||
151  raw_physics_name == PhysicsNaming::axisymmetric_heat_transfer() )
153  else if( raw_physics_name == PhysicsNaming::spalart_allmaras() )
154  var_section = VariablesParsing::turbulence_section();
155  else if( raw_physics_name == PhysicsNaming::elastic_membrane() ||
156  raw_physics_name == PhysicsNaming::elastic_cable() )
158  else if( raw_physics_name == PhysicsNaming::convection_diffusion() )
159  var_section = VariablesParsing::generic_section()+":"+raw_physics_name;
160  else
161  libmesh_error();
162  }
163  else if( bc_type_str == std::string("vel_bc_types") )
164  var_section = VariablesParsing::velocity_section();
165 
166  else if( bc_type_str == std::string("temp_bc_types") )
168 
169  else if( bc_type_str == std::string("species_bc_types") )
171 
172  else
173  libmesh_error();
174 
176  }
177 
179  MultiphysicsSystem& system,
180  const std::string& raw_physics_name,
181  const std::string& section_name,
182  const std::string& bc_id_str,
183  const std::string& bc_type_str,
184  const std::string& bc_value_str,
185  const std::string& bc_var_str,
186  libMesh::DofMap& dof_map,
187  std::vector<SharedPtr<NeumannBCContainer> >& neumann_bcs )
188  {
189  unsigned int num_ids = input.vector_variable_size(section_name+"/"+bc_id_str);
190  unsigned int num_types = input.vector_variable_size(section_name+"/"+bc_type_str);
191 
192  if( num_ids != num_types )
193  libmesh_error_msg("Error: Must specify equal number of boundary ids and boundary conditions");
194 
195  for( unsigned int i = 0; i < num_ids; i++ )
196  {
197  // Parse the bc type, add "_old_style" at the end to distinguish for deprecated construction
198  std::string bc_type = input(section_name+"/"+bc_type_str, std::string("DIE!"), i );
199  bc_type += "_old_style";
200 
201  BoundaryID bc_id = input(section_name+"/"+bc_id_str, -1, i );
202 
203  // If this is a periodic boundary condition, we can immediately
204  // apply and move to the next one
205  if( bc_type == std::string("periodic_old_style") )
206  {
207  this->build_periodic_bc( input, section_name, bc_id, dof_map );
208  continue;
209  }
210 
211  // We use the set for compatibility with the BCFactories
212  std::set<BoundaryID> bc_ids;
213  bc_ids.insert(bc_id);
214 
215  std::string variable_group_name;
216 
217  const FEVariablesBase* fe_var_ptr = this->determine_variable_group( raw_physics_name,
218  bc_type_str,
219  variable_group_name );
220 
221  libmesh_assert(fe_var_ptr);
222 
223  // We need the var_names for the old style parsing
224  std::vector<std::string> var_names;
225  var_names = fe_var_ptr->active_var_names();
226 
227  // Axisymmetric is special. It depends on the variable type.
228  // So, we prepend the type with the variable name in that
229  // case.
230  if( bc_type == "axisymmetric_old_style" )
231  bc_type = variable_group_name+"_"+bc_type;
232 
233 
234  // For these types of boundary conditions, we need to treat one
235  // variable at a time, so extract the relevant one.
236  if( bc_type == std::string("parsed_dirichlet_old_style") ||
237  bc_type == std::string("constant_dirichlet_old_style") ||
238  bc_type == std::string("parsed_fem_dirichlet_old_style") ||
239  bc_type == std::string("parsed_neumann_old_style") )
240  {
241  var_names.clear();
242  var_names.resize(1, input(section_name+"/"+bc_var_str, std::string("DIE!"), i ) );
243  }
244 
245  if( this->is_dirichlet_bc_type(bc_type) )
246  {
247  // Tell the old style DirichletBCFactory where to parse the value of the BC
248  this->set_dirichlet_bc_factory_old_style_quantities<libMesh::FunctionBase<libMesh::Number> >
249  ( bc_value_str, i, var_names );
250  this->set_dirichlet_bc_factory_old_style_quantities<libMesh::FEMFunctionBase<libMesh::Number> >
251  ( bc_value_str, i, var_names );
252 
253  this->construct_dbc_core( input, system, bc_ids, *fe_var_ptr,
254  section_name, bc_type, dof_map );
255  }
256  else if( this->is_neumann_bc_type(bc_type) )
257  {
258  // Tell the old style NeumannBCFactory where to parse the value of the BC
259  this->set_neumann_bc_factory_old_style_quantities<libMesh::FunctionBase<libMesh::Number> >
260  ( bc_value_str, i, var_names );
261  this->set_neumann_bc_factory_old_style_quantities<libMesh::FEMFunctionBase<libMesh::Number> >
262  ( bc_value_str, i, var_names );
263 
264  this->construct_nbc_core( input, system, bc_ids, *fe_var_ptr,
265  section_name, bc_type, neumann_bcs );
266  }
267  else
268  libmesh_error_msg("ERROR: Invalid bc_type "+bc_type+"!");
269 
270  }
271  }
272 
273  void OldStyleBCBuilder::build_basic_physics( std::set<std::string>& physics_names )
274  {
275  physics_names.insert(PhysicsNaming::incompressible_navier_stokes());
276  physics_names.insert(PhysicsNaming::stokes());
277  physics_names.insert(PhysicsNaming::elastic_membrane());
278  physics_names.insert(PhysicsNaming::elastic_cable());
279  physics_names.insert(PhysicsNaming::convection_diffusion());
280  physics_names.insert(PhysicsNaming::spalart_allmaras());
281  physics_names.insert(PhysicsNaming::axisymmetric_heat_transfer());
282  physics_names.insert(PhysicsNaming::heat_conduction());
283  physics_names.insert(PhysicsNaming::heat_transfer());
284  }
285 
286  void OldStyleBCBuilder::build_vel_and_temp_physics( std::set<std::string>& physics_names )
287  {
288  physics_names.insert(PhysicsNaming::low_mach_navier_stokes());
289  }
290 
291  void OldStyleBCBuilder::build_reacting_physics( std::set<std::string>& physics_names )
292  {
293  physics_names.insert(PhysicsNaming::reacting_low_mach_navier_stokes());
294  }
295 
296  void OldStyleBCBuilder::build_periodic_bc( const GetPot& input,
297  const std::string& section,
298  BoundaryID bc_id,
299  libMesh::DofMap& dof_map )
300  {
301  std::string wall_input = section+"/periodic_wall_";
302  wall_input += StringUtilities::T_to_string<BoundaryID>(bc_id);
303 
304  if( input.have_variable(wall_input) )
305  {
306  libMesh::boundary_id_type invalid_bid =
307  std::numeric_limits<libMesh::boundary_id_type>::max();
308 
309  libMesh::boundary_id_type slave_id = invalid_bid;
310  libMesh::boundary_id_type master_id = invalid_bid;
311 
312  if( input.vector_variable_size(wall_input) != 2 )
313  libmesh_error_msg("ERROR: "+wall_input+" must have only 2 components!");
314 
315  master_id = bc_id;
316 
317  if( input(wall_input,invalid_bid,0) == bc_id )
318  slave_id = input(wall_input,invalid_bid,1);
319  else
320  slave_id = input(wall_input,invalid_bid,0);
321 
322  std::string offset_input = section+"/periodic_offset_";
323  offset_input += StringUtilities::T_to_string<BoundaryID>(bc_id);
324 
325  if( !input.have_variable(offset_input) )
326  libmesh_error_msg("ERROR: Could not find "+offset_input+"!");
327 
328  unsigned int n_comps = input.vector_variable_size(offset_input);
329 
330  libMesh::Real invalid_real = std::numeric_limits<libMesh::Real>::max();
331 
332  libMesh::RealVectorValue offset_vector;
333  for( unsigned int i = 0; i < n_comps; i++ )
334  offset_vector(i) = input(offset_input,invalid_real,i);
335 
336  this->add_periodic_bc_to_dofmap( master_id, slave_id,
337  offset_vector, dof_map );
338  }
339  }
340 
341  template<typename FunctionType>
343  unsigned int value_idx,
344  const std::vector<std::string>& var_names )
345  {
349  }
350 
351  template<typename FunctionType>
353  unsigned int value_idx,
354  const std::vector<std::string>& /*var_names*/ )
355  {
358  //ParsedFunctionNeumannOldStyleBCFactory<FunctionType>::set_var_names_old_style( var_names );
359  }
360 
361  // Instantiate
362  template void OldStyleBCBuilder::set_dirichlet_bc_factory_old_style_quantities<libMesh::FunctionBase<libMesh::Number> >( const std::string&, unsigned int, const std::vector<std::string>& );
363  template void OldStyleBCBuilder::set_dirichlet_bc_factory_old_style_quantities<libMesh::FEMFunctionBase<libMesh::Number> >( const std::string&, unsigned int, const std::vector<std::string>& );
364  template void OldStyleBCBuilder::set_neumann_bc_factory_old_style_quantities<libMesh::FunctionBase<libMesh::Number> >( const std::string&, unsigned int, const std::vector<std::string>& );
365  template void OldStyleBCBuilder::set_neumann_bc_factory_old_style_quantities<libMesh::FEMFunctionBase<libMesh::Number> >( const std::string&, unsigned int, const std::vector<std::string>& );
366 
367 } // end namespace GRINS
static PhysicsName heat_transfer()
void construct_dbc_core(const GetPot &input, MultiphysicsSystem &system, const std::set< BoundaryID > &bc_ids, const FEVariablesBase &fe_var, const std::string &section, const std::string &bc_type, libMesh::DofMap &dof_map)
Definition: bc_builder.C:76
void construct_nbc_core(const GetPot &input, MultiphysicsSystem &system, const std::set< BoundaryID > &bc_ids, const FEVariablesBase &fe_var, const std::string &section, const std::string &bc_type, std::vector< SharedPtr< NeumannBCContainer > > &neumann_bcs)
Definition: bc_builder.C:106
static void set_var_names_old_style(const std::vector< std::string > &var_names)
static void set_value_var_old_style(const std::string &value_var)
Input variable for parsing old style.
static PhysicsName reacting_low_mach_navier_stokes()
void build_vel_and_temp_physics(std::set< std::string > &physics_names)
static std::string temperature_section()
static PhysicsName spalart_allmaras()
static std::string displacement_section()
libMesh::boundary_id_type BoundaryID
More descriptive name of the type used for boundary ids.
Definition: var_typedefs.h:56
bool is_dirichlet_bc_type(const std::string &bc_type)
Definition: bc_builder.C:139
static PhysicsName low_mach_navier_stokes()
#define grins_warning(message)
Definition: common.h:34
static PhysicsName elastic_cable()
void set_neumann_bc_factory_old_style_quantities(const std::string &bc_value_str, unsigned int value_idx, const std::vector< std::string > &var_names)
void add_periodic_bc_to_dofmap(libMesh::boundary_id_type master_id, libMesh::boundary_id_type slave_id, const libMesh::RealVectorValue &offset_vector, libMesh::DofMap &dof_map)
Definition: bc_builder.C:151
void construct_bcs_old_style(const GetPot &input, MultiphysicsSystem &system, const std::string &raw_physics_name, const std::string &section_name, const std::string &bc_id_str, const std::string &bc_type_str, const std::string &bc_value_str, const std::string &bc_var_str, libMesh::DofMap &dof_map, std::vector< SharedPtr< NeumannBCContainer > > &neumann_bcs)
static void set_value_var_old_style(const std::string &value_var)
Input variable for parsing old style.
GRINS namespace.
static PhysicsName elastic_membrane()
void set_dirichlet_bc_factory_old_style_quantities(const std::string &bc_value_str, unsigned int value_idx, const std::vector< std::string > &var_names)
static std::string extract_physics(const std::string &full_name)
Extract the physics name from the full_name.
static std::string velocity_section()
void build_reacting_physics(std::set< std::string > &physics_names)
static std::string species_mass_fractions_section()
static void set_value_index_old_style(unsigned int idx)
Input variable index for parsing old style.
static PhysicsName convection_diffusion()
void build_periodic_bc(const GetPot &input, const std::string &section_name, BoundaryID bc_id, libMesh::DofMap &dof_map)
Interface with libMesh for solving Multiphysics problems.
const FEVariablesBase * determine_variable_group(const std::string &raw_physics_name, const std::string &bc_type_str, std::string &var_section)
Determine the FEVariable type from the raw_physics_name.
std::map< std::string, SharedPtr< GRINS::Physics > > PhysicsList
Container for GRINS::Physics object pointers.
Definition: var_typedefs.h:59
static PhysicsName incompressible_navier_stokes()
static PhysicsName stokes()
void build_basic_physics(std::set< std::string > &physics_names)
static PhysicsName axisymmetric_heat_transfer()
static const FEVariablesBase & get_variable(const std::string &var_name)
static std::string turbulence_section()
const std::vector< std::string > & active_var_names() const
Return the var names that are active from this class.
static PhysicsName heat_conduction()
bool is_neumann_bc_type(const std::string &bc_type)
Definition: bc_builder.C:145
std::map< std::string, SharedPtr< GRINS::Physics > >::const_iterator PhysicsListIter
Iterator for PhysicsList.
Definition: var_typedefs.h:62
static std::string generic_section()
const PhysicsList & get_physics_list() const
static void set_value_index_old_style(unsigned int idx)
Input variable index for parsing old style.
virtual void build_bcs(const GetPot &input, MultiphysicsSystem &system, std::vector< SharedPtr< NeumannBCContainer > > &neumann_bcs)

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