GRINS-0.6.0
low_mach_navier_stokes_bc_handling.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2015 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 
26 // This class
28 
29 // libMesh
30 #include "libmesh/zero_function.h"
31 #include "libmesh/dirichlet_boundaries.h"
32 #include "libmesh/dof_map.h"
33 #include "libmesh/fem_system.h"
34 
35 namespace GRINS
36 {
37 
39  const GetPot& input)
40  : BCHandlingBase(physics_name),
41  _u_var_name( input("Physics/VariableNames/u_velocity", u_var_name_default ) ),
42  _v_var_name( input("Physics/VariableNames/v_velocity", v_var_name_default ) ),
43  _w_var_name( input("Physics/VariableNames/w_velocity", w_var_name_default ) ),
44  _T_var_name( input("Physics/VariableNames/Temperature", T_var_name_default ) )
45  {
46  std::string id_str = "Physics/"+_physics_name+"/vel_bc_ids";
47  std::string bc_str = "Physics/"+_physics_name+"/vel_bc_types";
48  std::string var_str = "Physics/"+_physics_name+"/vel_bc_variables";
49  std::string val_str = "Physics/"+_physics_name+"/vel_bc_values";
50 
51  this->read_bc_data( input, id_str, bc_str, var_str, val_str );
52 
53  id_str = "Physics/"+_physics_name+"/temp_bc_ids";
54  bc_str = "Physics/"+_physics_name+"/temp_bc_types";
55  var_str = "Physics/"+_physics_name+"/temp_bc_variables";
56  val_str = "Physics/"+_physics_name+"/temp_bc_values";
57 
58  this->read_bc_data( input, id_str, bc_str, var_str, val_str );
59 
60  return;
61  }
62 
64  {
65  return;
66  }
67 
68  int LowMachNavierStokesBCHandling::string_to_int( const std::string& bc_type ) const
69  {
70  int bc_type_out;
71 
72  if( bc_type == "no_slip" )
73  bc_type_out = NO_SLIP;
74 
75  else if( bc_type == "zero_x_velocity" )
76  bc_type_out = ZERO_X_VELOCITY;
77 
78  else if( bc_type == "zero_y_velocity" )
79  bc_type_out = ZERO_Y_VELOCITY;
80 
81  else if( bc_type == "parabolic_profile" )
82  bc_type_out = PARABOLIC_PROFILE;
83 
84  else if( bc_type == "prescribed_vel" )
85  bc_type_out = PRESCRIBED_VELOCITY;
86 
87  else if( bc_type == "general_velocity" )
88  bc_type_out = GENERAL_VELOCITY;
89 
90  else if( bc_type == "isothermal" )
91  bc_type_out = ISOTHERMAL_WALL;
92 
93  else if( bc_type == "general_isothermal" )
94  bc_type_out = GENERAL_ISOTHERMAL_WALL;
95 
96  else if( bc_type == "adiabatic" )
97  bc_type_out = ADIABATIC_WALL;
98 
99  else if( bc_type == "prescribed_heat_flux" )
100  bc_type_out = PRESCRIBED_HEAT_FLUX;
101 
102  else if( bc_type == "general_heat_flux" )
103  bc_type_out = GENERAL_HEAT_FLUX;
104 
105  else
106  {
107  // Call base class to detect any physics-common boundary conditions
108  bc_type_out = BCHandlingBase::string_to_int( bc_type );
109  }
110 
111  return bc_type_out;
112  }
113 
114  void LowMachNavierStokesBCHandling::init_bc_data( const libMesh::FEMSystem& system )
115  {
116  _T_var = system.variable_number( _T_var_name );
117 
118  return;
119  }
120 
122  const std::string& bc_id_string,
123  const int bc_type,
124  const std::string& bc_vars,
125  const std::string& bc_value,
126  const GetPot& input )
127  {
128  switch(bc_type)
129  {
130  case(NO_SLIP):
131  {
132  this->set_dirichlet_bc_type( bc_id, bc_type );
133  }
134  break;
135  case(ZERO_X_VELOCITY):
136  {
137  this->set_dirichlet_bc_type( bc_id, bc_type );
138  }
139  break;
140  case(ZERO_Y_VELOCITY):
141  {
142  this->set_dirichlet_bc_type( bc_id, bc_type );
143  }
144  break;
145  case(PRESCRIBED_VELOCITY):
146  {
147  this->set_dirichlet_bc_type( bc_id, bc_type );
148 
149  /* Force the user to specify 3 velocity components regardless of dimension.
150  This should make it easier to keep things correct if we want to have
151  2D flow not be in the x-y plane. */
152  int n_vel_comps = input.vector_variable_size("Physics/"+_physics_name+"/bound_vel_"+bc_id_string);
153  if( n_vel_comps != 3 )
154  {
155  std::cerr << "Error: Must specify 3 velocity components when inputting"
156  << std::endl
157  << " prescribed velocities. Found " << n_vel_comps
158  << " velocity components."
159  << std::endl;
160  libmesh_error();
161  }
162 
163  this->set_dirichlet_bc_value( bc_id,
164  input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 0 ),
165  0 );
166 
167  this->set_dirichlet_bc_value( bc_id,
168  input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 1 ),
169  1 );
170 
171  this->set_dirichlet_bc_value( bc_id,
172  input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 2 ),
173  2 );
174  }
175  break;
176  case(PARABOLIC_PROFILE):
177  {
178  this->set_dirichlet_bc_type( bc_id, bc_type );
179 
180  // Make sure all 6 components are there
181  if( input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string) != 6 )
182  {
183  std::cerr << "Error: Must specify 6 components when inputting"
184  << std::endl
185  << " coefficients for a parabolic profile. Found "
186  << input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_"+bc_id_string)
187  << " components."
188  << std::endl;
189  libmesh_error();
190  }
191 
192  libMesh::Real a = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 0 );
193  libMesh::Real b = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 1 );
194  libMesh::Real c = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 2 );
195  libMesh::Real d = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 3 );
196  libMesh::Real e = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 4 );
197  libMesh::Real f = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 5 );
198 
199  std::string var = input( "Physics/"+_physics_name+"/parabolic_profile_var_"+bc_id_string, "DIE!" );
200 
201  GRINS::DBCContainer cont;
202  cont.add_var_name( var );
203  cont.add_bc_id( bc_id );
204 
205  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
206  func( new GRINS::ParabolicProfile(a,b,c,d,e,f) );
207  cont.set_func( func );
208  this->attach_dirichlet_bound_func( cont );
209 
210  // Set specified components of Dirichlet data to zero
211  std::string fix_var = input( "Physics/"+_physics_name+"/parabolic_profile_fix_"+bc_id_string, "DIE!" );
212 
213  GRINS::DBCContainer cont_fix;
214  cont_fix.add_var_name( fix_var );
215  cont_fix.add_bc_id( bc_id );
216 
217  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
218  func_fix( new libMesh::ZeroFunction<libMesh::Number>() );
219  cont_fix.set_func( func_fix );
220  this->attach_dirichlet_bound_func( cont_fix );
221  }
222  break;
223 
224  case(GENERAL_VELOCITY):
225  {
226  this->set_dirichlet_bc_type( bc_id, bc_type );
227 
228  // Set specified components of Dirichlet data to zero.
229  // Other component is handled in user BC factory.
230  std::string fix_var = input( "Physics/"+_physics_name+"/general_velocity_fix_"+bc_id_string, "DIE!" );
231 
232  GRINS::DBCContainer cont_fix;
233  cont_fix.add_var_name( fix_var );
234  cont_fix.add_bc_id( bc_id );
235 
236  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
237  func_fix( new libMesh::ZeroFunction<libMesh::Number>() );
238  cont_fix.set_func( func_fix );
239  this->attach_dirichlet_bound_func( cont_fix );
240  }
241  break;
242  case(ISOTHERMAL_WALL):
243  {
244  this->set_temp_bc_type( bc_id, bc_type );
245 
246  this->set_temp_bc_value( bc_id, input("Physics/"+_physics_name+"/T_wall_"+bc_id_string, 0.0 ) );
247  }
248  break;
249 
251  {
252  this->set_temp_bc_type( bc_id, bc_type );
253  }
254  break;
255 
256  case(ADIABATIC_WALL):
257  {
258  this->set_neumann_bc_type( bc_id, bc_type );
259  }
260  break;
261  case(PRESCRIBED_HEAT_FLUX):
262  {
263  this->set_neumann_bc_type( bc_id, bc_type );
264 
265  libMesh::RealGradient q_in;
266 
267  int num_q_components = input.vector_variable_size("Physics/"+_physics_name+"/q_wall_"+bc_id_string);
268 
269  for( int i = 0; i < num_q_components; i++ )
270  {
271  q_in(i) = input("Physics/"+_physics_name+"/q_wall_"+bc_id_string, 0.0, i );
272  }
273 
274  this->set_neumann_bc_value( bc_id, q_in );
275  }
276  break;
277  case(GENERAL_HEAT_FLUX):
278  {
279  this->set_neumann_bc_type( bc_id, bc_type );
280  }
281  break;
282 
283  case(AXISYMMETRIC):
284  {
285  this->set_dirichlet_bc_type( bc_id, bc_type );
286  }
287  break;
288 
289  default:
290  {
291  // Call base class to detect any physics-common boundary conditions
292  BCHandlingBase::init_bc_types( bc_id, bc_id_string, bc_type,
293  bc_vars, bc_value, input );
294  }
295  } // End switch(bc_type)
296 
297  return;
298  }
299 
301  libMesh::DofMap& dof_map,
302  BoundaryID bc_id,
303  BCType bc_type ) const
304  {
305  int dim = system->get_mesh().mesh_dimension();
306 
307  VariableIndex T_var = system->variable_number( _T_var_name );
308  VariableIndex u_var = system->variable_number( _u_var_name );
309  VariableIndex v_var = system->variable_number( _v_var_name );
310  VariableIndex w_var = -1;
311  if( dim == 3 )
312  w_var = system->variable_number( _w_var_name );
313 
314  switch( bc_type )
315  {
316  case(ZERO_X_VELOCITY):
317  {
318  std::set<BoundaryID> dbc_ids;
319  dbc_ids.insert(bc_id);
320 
321  std::vector<VariableIndex> dbc_vars;
322  dbc_vars.push_back(u_var);
323 
324  libMesh::ZeroFunction<libMesh::Number> zero;
325 
326  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
327  dbc_vars,
328  &zero );
329 
330  dof_map.add_dirichlet_boundary( no_slip_dbc );
331  }
332  break;
333  case(ZERO_Y_VELOCITY):
334  {
335  std::set<BoundaryID> dbc_ids;
336  dbc_ids.insert(bc_id);
337 
338  std::vector<VariableIndex> dbc_vars;
339  dbc_vars.push_back(v_var);
340 
341  libMesh::ZeroFunction<libMesh::Number> zero;
342 
343  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
344  dbc_vars,
345  &zero );
346 
347  dof_map.add_dirichlet_boundary( no_slip_dbc );
348  }
349  break;
350  case(NO_SLIP):
351  {
352  std::set<BoundaryID> dbc_ids;
353  dbc_ids.insert(bc_id);
354 
355  std::vector<VariableIndex> dbc_vars;
356  dbc_vars.push_back(u_var);
357  dbc_vars.push_back(v_var);
358  if(dim == 3)
359  dbc_vars.push_back(w_var);
360 
361  libMesh::ZeroFunction<libMesh::Number> zero;
362 
363  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
364  dbc_vars,
365  &zero );
366 
367  dof_map.add_dirichlet_boundary( no_slip_dbc );
368  }
369  break;
370  case(PRESCRIBED_VELOCITY):
371  {
372  std::set<BoundaryID> dbc_ids;
373  dbc_ids.insert(bc_id);
374 
375  std::vector<VariableIndex> dbc_vars;
376 
377  // This is inefficient, but it shouldn't matter because
378  // everything gets cached on the libMesh side so it should
379  // only affect performance at startup.
380  {
381  dbc_vars.push_back(u_var);
382  libMesh::ConstFunction<libMesh::Number>
383  vel_func( this->get_dirichlet_bc_value(bc_id,0) );
384 
385  libMesh::DirichletBoundary vel_dbc(dbc_ids,
386  dbc_vars,
387  &vel_func );
388 
389  dof_map.add_dirichlet_boundary( vel_dbc );
390  dbc_vars.clear();
391  }
392 
393  {
394  dbc_vars.push_back(v_var);
395  libMesh::ConstFunction<libMesh::Number>
396  vel_func( this->get_dirichlet_bc_value(bc_id,1) );
397 
398  libMesh::DirichletBoundary vel_dbc(dbc_ids,
399  dbc_vars,
400  &vel_func );
401 
402  dof_map.add_dirichlet_boundary( vel_dbc );
403  dbc_vars.clear();
404  }
405  if( dim == 3 )
406  {
407  dbc_vars.push_back(w_var);
408  libMesh::ConstFunction<libMesh::Number>
409  vel_func( this->get_dirichlet_bc_value(bc_id,2) );
410 
411  libMesh::DirichletBoundary vel_dbc(dbc_ids,
412  dbc_vars,
413  &vel_func );
414 
415  dof_map.add_dirichlet_boundary( vel_dbc );
416  }
417  }
418  break;
419  case(PARABOLIC_PROFILE):
420  // This case is handled init_dirichlet_bc_func_objs
421  break;
422 
423  case(GENERAL_VELOCITY):
424  // This case is handled in the BoundaryConditionFactory classes.
425  break;
426 
427  case(ISOTHERMAL_WALL):
428  {
429  std::set<BoundaryID> dbc_ids;
430  dbc_ids.insert(bc_id);
431 
432  std::vector<VariableIndex> dbc_vars;
433  dbc_vars.push_back(T_var);
434 
435  libMesh::ConstFunction<libMesh::Number>
436  t_func(this->get_temp_bc_value(bc_id));
437 
438  libMesh::DirichletBoundary t_dbc( dbc_ids, dbc_vars, &t_func );
439 
440  dof_map.add_dirichlet_boundary( t_dbc );
441  }
442  break;
444  // This case is handled in the BoundaryConditionFactory classes.
445  break;
446 
447  case(AXISYMMETRIC):
448  {
449  std::set<BoundaryID> dbc_ids;
450  dbc_ids.insert(bc_id);
451 
452  std::vector<VariableIndex> dbc_vars;
453  dbc_vars.push_back(u_var);
454 
455  libMesh::ZeroFunction<libMesh::Number> zero;
456 
457  libMesh::DirichletBoundary no_slip_dbc( dbc_ids,
458  dbc_vars,
459  &zero );
460 
461  dof_map.add_dirichlet_boundary( no_slip_dbc );
462  }
463  break;
464 
465  default:
466  {
467  std::cerr << "Invalid BCType " << bc_type << std::endl;
468  libmesh_error();
469  }
470 
471  }// end switch
472 
473  return;
474  }
475 
477  {
478  _temp_bc_map.push_back( std::make_pair(bc_id,bc_type) );
479  return;
480  }
481 
483  libMesh::Real value )
484  {
485  _T_values[bc_id] = value;
486  return;
487  }
488 
490  {
491  return _T_values.find(bc_id)->second;
492  }
493 
494  void LowMachNavierStokesBCHandling::init_dirichlet_bcs( libMesh::FEMSystem* system ) const
495  {
496  libMesh::DofMap& dof_map = system->get_dof_map();
497 
498  for( std::vector<std::pair<BoundaryID,BCType> >::const_iterator it = _dirichlet_bc_map.begin();
499  it != _dirichlet_bc_map.end(); it++ )
500  {
501  this->user_init_dirichlet_bcs( system, dof_map, it->first, it->second );
502  }
503 
504  for( std::vector<std::pair<BoundaryID,BCType> >::const_iterator it = _temp_bc_map.begin();
505  it != _temp_bc_map.end(); it++ )
506  {
507  this->user_init_dirichlet_bcs( system, dof_map, it->first, it->second );
508  }
509 
510  return;
511  }
512 
513 } // namespace GRINS
virtual void init_dirichlet_bcs(libMesh::FEMSystem *system) const
unsigned int VariableIndex
More descriptive name of the type used for variable indices.
Definition: var_typedefs.h:40
virtual void read_bc_data(const GetPot &input, const std::string &id_str, const std::string &bc_str, const std::string &var_str, const std::string &val_str)
Simple helper class to setup general Dirichlet boundary conditions.
Definition: dbc_container.h:49
virtual void user_init_dirichlet_bcs(libMesh::FEMSystem *system, libMesh::DofMap &dof_map, GRINS::BoundaryID bc_id, GRINS::BCType bc_type) const
libMesh::boundary_id_type BoundaryID
More descriptive name of the type used for boundary ids.
Definition: var_typedefs.h:54
void attach_dirichlet_bound_func(const GRINS::DBCContainer &dirichlet_bc)
Parabolic profile.
const std::string v_var_name_default
y-velocity
libMesh::Real get_temp_bc_value(GRINS::BoundaryID bc_id) const
void set_dirichlet_bc_value(GRINS::BoundaryID bc_id, libMesh::Real value, int component=0)
void set_neumann_bc_value(GRINS::BoundaryID bc_id, const libMesh::Point &q_in)
void add_var_name(const GRINS::VariableName &var)
Add variables that are constrained by the Dirichlet bc.
Definition: dbc_container.C:46
GRINS namespace.
virtual void init_bc_types(const GRINS::BoundaryID bc_id, const std::string &bc_id_string, const int bc_type, const std::string &bc_vars, const std::string &bc_value, const GetPot &input)
std::map< GRINS::BoundaryID, libMesh::Real > _T_values
const std::string T_var_name_default
temperature
virtual void init_bc_types(const GRINS::BoundaryID bc_id, const std::string &bc_id_string, const int bc_type, const std::string &bc_vars, const std::string &bc_value, const GetPot &input)
std::vector< std::pair< BoundaryID, BCType > > _dirichlet_bc_map
Map between boundary id and Dirichlet boundary condition type.
void set_temp_bc_value(GRINS::BoundaryID bc_id, libMesh::Real value)
std::vector< std::pair< BoundaryID, BCType > > _temp_bc_map
const std::string u_var_name_default
Default physics variable names.
virtual int string_to_int(const std::string &bc_type_in) const
virtual int string_to_int(const std::string &bc_type_in) const
virtual void init_bc_data(const libMesh::FEMSystem &system)
Override this method to initialize any system-dependent data.
Base class for reading and handling boundary conditions for physics classes.
void set_temp_bc_type(GRINS::BoundaryID bc_id, int bc_type)
void add_bc_id(const GRINS::BoundaryID bc_id)
Add boundary id's for which this Dirichlet bc is to be applied.
Definition: dbc_container.C:52
void set_func(std::tr1::shared_ptr< libMesh::FunctionBase< libMesh::Number > > func)
Add the Dirichlet bc functor.
Definition: dbc_container.C:58
void set_neumann_bc_type(GRINS::BoundaryID bc_id, int bc_type)
int BCType
Definition: bc_types.h:32
void set_dirichlet_bc_type(GRINS::BoundaryID bc_id, int bc_type)
libMesh::Real get_dirichlet_bc_value(GRINS::BoundaryID bc_id, int component=0) const
const std::string w_var_name_default
z-velocity

Generated on Mon Jun 22 2015 21:32:19 for GRINS-0.6.0 by  doxygen 1.8.9.1