GRINS-0.6.0
inc_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 // GRINS
31 
32 // libMesh
33 #include "libmesh/zero_function.h"
34 #include "libmesh/dirichlet_boundaries.h"
35 #include "libmesh/dof_map.h"
36 #include "libmesh/fem_system.h"
37 
38 namespace GRINS
39 {
40 
42  const GetPot& input)
43  : BCHandlingBase(physics_name),
44  _flow_vars(input)
45  {
46  std::string id_str = "Physics/"+_physics_name+"/bc_ids";
47  std::string bc_str = "Physics/"+_physics_name+"/bc_types";
48  std::string var_str = "Physics/"+_physics_name+"/bc_variables";
49  std::string val_str = "Physics/"+_physics_name+"/bc_values";
50 
51  this->read_bc_data( input, id_str, bc_str, var_str, val_str );
52 
53  return;
54  }
55 
57  {
58  return;
59  }
60 
61  int IncompressibleNavierStokesBCHandling::string_to_int( const std::string& bc_type ) const
62  {
63  int bc_type_out;
64 
65  if( bc_type == "no_slip" )
66  bc_type_out = NO_SLIP;
67 
68  else if( bc_type == "prescribed_vel" )
69  bc_type_out = PRESCRIBED_VELOCITY;
70 
71  else if( bc_type == "parabolic_profile" )
72  bc_type_out = PARABOLIC_PROFILE;
73 
74  else if( bc_type == "general_velocity" )
75  bc_type_out = GENERAL_VELOCITY;
76 
77  else
78  {
79  // Call base class to detect any physics-common boundary conditions
80  bc_type_out = BCHandlingBase::string_to_int( bc_type );
81  }
82 
83  return bc_type_out;
84  }
85 
86  void IncompressibleNavierStokesBCHandling::init_bc_data( const libMesh::FEMSystem& system )
87  {
88  _flow_vars.init(const_cast<libMesh::FEMSystem*>(&system));
89 
90  return;
91  }
92 
94  const std::string& bc_id_string,
95  const int bc_type,
96  const std::string& bc_vars,
97  const std::string& bc_value,
98  const GetPot& input )
99  {
100  switch(bc_type)
101  {
102  case(NO_SLIP):
103  {
104  this->set_dirichlet_bc_type( bc_id, bc_type );
105  }
106  break;
107  case(PRESCRIBED_VELOCITY):
108  {
109  this->set_dirichlet_bc_type( bc_id, bc_type );
110 
111  /* Force the user to specify 3 velocity components regardless of dimension.
112  This should make it easier to keep things correct if we want to have
113  2D flow not be in the x-y plane. */
114  int n_vel_comps = input.vector_variable_size("Physics/"+_physics_name+"/bound_vel_"+bc_id_string);
115  if( n_vel_comps != 3 )
116  {
117  std::cerr << "Error: Must specify 3 velocity components when inputting"
118  << std::endl
119  << " prescribed velocities. Found " << n_vel_comps
120  << " velocity components."
121  << std::endl;
122  libmesh_error();
123  }
124 
125  this->set_dirichlet_bc_value( bc_id,
126  input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 0 ),
127  0 );
128 
129  this->set_dirichlet_bc_value( bc_id,
130  input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 1 ),
131  1 );
132 
133 #if LIBMESH_DIM > 2
134  this->set_dirichlet_bc_value( bc_id,
135  input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 2 ),
136  2 );
137 #endif
138  }
139  break;
140  case(PARABOLIC_PROFILE):
141  {
142  this->set_dirichlet_bc_type( bc_id, bc_type );
143 
144  // Make sure all 6 components are there
145  if( input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string) != 6 )
146  {
147  std::cerr << "Error: Must specify 6 components when inputting"
148  << std::endl
149  << " coefficients for a parabolic profile. Found "
150  << input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_"+bc_id_string)
151  << " components."
152  << std::endl;
153  libmesh_error();
154  }
155 
156  libMesh::Real a = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 0 );
157  libMesh::Real b = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 1 );
158  libMesh::Real c = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 2 );
159  libMesh::Real d = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 3 );
160  libMesh::Real e = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 4 );
161  libMesh::Real f = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 5 );
162 
163  std::string var = input( "Physics/"+_physics_name+"/parabolic_profile_var_"+bc_id_string, "DIE!" );
164 
165  if( var == "DIE!" )
166  {
167  std::cerr << "Error: Mush specify a variable name to which apply parabolic profile through parabolic_profile_var input option." << std::endl;
168  libmesh_error();
169  }
170 
171  DBCContainer cont;
172  cont.add_var_name( var );
173  cont.add_bc_id( bc_id );
174 
175  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> > func( new ParabolicProfile(a,b,c,d,e,f) );
176  cont.set_func( func );
177  this->attach_dirichlet_bound_func( cont );
178 
179  // Set specified components of Dirichlet data to zero
180  std::string fix_var = input( "Physics/"+_physics_name+"/parabolic_profile_fix_"+bc_id_string, "DIE!" );
181 
182  if( fix_var == "DIE!" )
183  {
184  std::cerr << "Error: Mush specify a variable name to fix for parabolic profile through parabolic_profile_fix input option." << std::endl;
185  libmesh_error();
186  }
187 
188  DBCContainer cont_fix;
189  cont_fix.add_var_name( fix_var );
190  cont_fix.add_bc_id( bc_id );
191 
192  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
193  func_fix( new libMesh::ZeroFunction<libMesh::Number>() );
194  cont_fix.set_func( func_fix );
195  this->attach_dirichlet_bound_func( cont_fix );
196  }
197  break;
198 
199  case(GENERAL_VELOCITY):
200  {
201  this->set_dirichlet_bc_type( bc_id, bc_type );
202  }
203  break;
204 
205  case(AXISYMMETRIC):
206  {
207  this->set_dirichlet_bc_type( bc_id, bc_type );
208  }
209  break;
210 
211  default:
212  {
213  // Call base class to detect any physics-common boundary conditions
214  BCHandlingBase::init_bc_types( bc_id, bc_id_string, bc_type,
215  bc_vars, bc_value, input );
216  }
217  } // End switch(bc_type)
218 
219  return;
220  }
221 
223  libMesh::DofMap& dof_map,
224  BoundaryID bc_id,
225  BCType bc_type ) const
226  {
227  int dim = system->get_mesh().mesh_dimension();
228 
229  VariableIndex u_var = _flow_vars.u_var();
230  VariableIndex v_var = _flow_vars.v_var();
231  VariableIndex w_var = -1;
232  if( dim == 3 )
233  w_var = _flow_vars.w_var();
234 
235  switch( bc_type )
236  {
237  case(NO_SLIP):
238  {
239  std::set<BoundaryID> dbc_ids;
240  dbc_ids.insert(bc_id);
241 
242  std::vector<VariableIndex> dbc_vars;
243  dbc_vars.push_back(u_var);
244  dbc_vars.push_back(v_var);
245  if(dim == 3)
246  dbc_vars.push_back(w_var);
247 
248  libMesh::ZeroFunction<libMesh::Number> zero;
249 
250  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
251  dbc_vars,
252  &zero );
253 
254  dof_map.add_dirichlet_boundary( no_slip_dbc );
255  }
256  break;
257  case(PRESCRIBED_VELOCITY):
258  {
259  std::set<BoundaryID> dbc_ids;
260  dbc_ids.insert(bc_id);
261 
262  std::vector<VariableIndex> dbc_vars;
263 
264  // This is inefficient, but it shouldn't matter because
265  // everything gets cached on the libMesh side so it should
266  // only affect performance at startup.
267  {
268  dbc_vars.push_back(u_var);
269  libMesh::ConstFunction<libMesh::Number>
270  vel_func( this->get_dirichlet_bc_value(bc_id,0) );
271 
272  libMesh::DirichletBoundary vel_dbc(dbc_ids,
273  dbc_vars,
274  &vel_func );
275 
276  dof_map.add_dirichlet_boundary( vel_dbc );
277  dbc_vars.clear();
278  }
279 
280  {
281  dbc_vars.push_back(v_var);
282  libMesh::ConstFunction<libMesh::Number>
283  vel_func( this->get_dirichlet_bc_value(bc_id,1) );
284 
285  libMesh::DirichletBoundary vel_dbc(dbc_ids,
286  dbc_vars,
287  &vel_func );
288 
289  dof_map.add_dirichlet_boundary( vel_dbc );
290  dbc_vars.clear();
291  }
292  if( dim == 3 )
293  {
294  dbc_vars.push_back(w_var);
295  libMesh::ConstFunction<libMesh::Number>
296  vel_func( this->get_dirichlet_bc_value(bc_id,2) );
297 
298  libMesh::DirichletBoundary vel_dbc(dbc_ids,
299  dbc_vars,
300  &vel_func );
301 
302  dof_map.add_dirichlet_boundary( vel_dbc );
303  }
304  }
305  break;
306  case(PARABOLIC_PROFILE):
307  // This case is handled init_dirichlet_bc_func_objs
308  break;
309 
310  case(GENERAL_VELOCITY):
311  // This case is handled in the init_dirichlet_bc_func_objs
312  break;
313 
314  case(AXISYMMETRIC):
315  {
316  std::set<BoundaryID> dbc_ids;
317  dbc_ids.insert(bc_id);
318 
319  std::vector<VariableIndex> dbc_vars;
320  dbc_vars.push_back(u_var);
321 
322  libMesh::ZeroFunction<libMesh::Number> zero;
323 
324  libMesh::DirichletBoundary no_slip_dbc( dbc_ids,
325  dbc_vars,
326  &zero );
327 
328  dof_map.add_dirichlet_boundary( no_slip_dbc );
329  }
330  break;
331 
332  default:
333  {
334  std::cerr << "Invalid BCType " << bc_type << std::endl;
335  libmesh_error();
336  }
337 
338  }// end switch
339 
340  return;
341  }
342 
343 } // namespace GRINS
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
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)
virtual void init_bc_data(const libMesh::FEMSystem &system)
Override this method to initialize any system-dependent data.
Parabolic profile.
void set_dirichlet_bc_value(GRINS::BoundaryID bc_id, libMesh::Real value, int component=0)
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(libMesh::FEMSystem *system)
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)
virtual void user_init_dirichlet_bcs(libMesh::FEMSystem *system, libMesh::DofMap &dof_map, GRINS::BoundaryID bc_id, GRINS::BCType bc_type) const
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)
virtual int string_to_int(const std::string &bc_type_in) const
virtual int string_to_int(const std::string &bc_type_in) const
Base class for reading and handling boundary conditions for physics classes.
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
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

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