GRINS-0.6.0
solid_mechanics_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  SolidMechanicsBCHandling::SolidMechanicsBCHandling( const std::string& physics_name,
38  const GetPot& input )
39  : BCHandlingBase(physics_name),
40  _disp_vars(input)
41  {
42  std::string id_str = "Physics/"+_physics_name+"/bc_ids";
43  std::string bc_str = "Physics/"+_physics_name+"/bc_types";
44  std::string var_str = "Physics/"+_physics_name+"/bc_variables";
45  std::string val_str = "Physics/"+_physics_name+"/bc_values";
46 
47  this->read_bc_data( input, id_str, bc_str, var_str, val_str );
48 
49  return;
50  }
51 
53  {
54  return;
55  }
56 
57  int SolidMechanicsBCHandling::string_to_int( const std::string& bc_type ) const
58  {
59  int bc_type_out;
60 
61  if( bc_type == "pinned" )
62  bc_type_out = PINNED;
63 
64  else if( bc_type == "constant_displacement" )
65  bc_type_out = CONSTANT_DISPLACEMENT;
66 
67  else if( bc_type == "roller_x" )
68  bc_type_out = ROLLER_X;
69 
70  else if( bc_type == "roller_y" )
71  bc_type_out = ROLLER_Y;
72 
73  else if( bc_type == "roller_z" )
74  bc_type_out = ROLLER_Z;
75 
76  else if( bc_type == "yz_symmetry" )
77  bc_type_out = SYMMETRY_YZ;
78 
79  else if( bc_type == "xz_symmetry" )
80  bc_type_out = SYMMETRY_XZ;
81 
82  else if( bc_type == "xy_symmetry" )
83  bc_type_out = SYMMETRY_XY;
84 
85  else if( bc_type == "constant_traction" )
86  bc_type_out = CONSTANT_TRACTION;
87 
88  else
89  {
90  // Call base class to detect any physics-common boundary conditions
91  bc_type_out = BCHandlingBase::string_to_int( bc_type );
92  }
93 
94  return bc_type_out;
95  }
96 
97  void SolidMechanicsBCHandling::init_bc_data( const libMesh::FEMSystem& system )
98  {
99  _disp_vars.init(const_cast<libMesh::FEMSystem*>(&system));
100 
101  return;
102  }
103 
105  const std::string& bc_id_string,
106  const int bc_type,
107  const std::string& bc_vars,
108  const std::string& bc_value,
109  const GetPot& input )
110  {
111  switch(bc_type)
112  {
113  case(PINNED):
114  {
115  this->set_dirichlet_bc_type( bc_id, bc_type );
116  }
117  break;
118 
119  case(CONSTANT_DISPLACEMENT):
120  {
121  this->set_dirichlet_bc_type( bc_id, bc_type );
122 
123  int n_disp_comps = input.vector_variable_size("Physics/"+_physics_name+"/displacement_"+bc_id_string);
124 
125  if( _disp_vars.have_v() )
126  {
127  if( n_disp_comps < 2 )
128  {
129  std::cerr << "Error: Must specify at least 2 displacement components for 2-D problem." << std::endl;
130  libmesh_error();
131  }
132  }
133 
134  if( _disp_vars.have_w() )
135  {
136  if( n_disp_comps < 3 )
137  {
138  std::cerr << "Error: Must specify 3 displacement components for 3-D problem." << std::endl;
139  libmesh_error();
140  }
141  }
142 
143  for( int i = 0; i < n_disp_comps; i++ )
144  {
145  this->set_dirichlet_bc_value( bc_id,
146  input("Physics/"+_physics_name+"/displacement_"+bc_id_string, 0.0, i ),
147  i );
148  }
149  }
150  break;
151 
152  case(ROLLER_X):
153  case(ROLLER_Y):
154  case(ROLLER_Z):
155  case(SYMMETRY_YZ):
156  case(SYMMETRY_XZ):
157  case(SYMMETRY_XY):
158  {
159  this->set_dirichlet_bc_type( bc_id, bc_type );
160  }
161  break;
162 
163  case(CONSTANT_TRACTION):
164  {
165  this->set_neumann_bc_type( bc_id, bc_type );
166 
167  libMesh::Gradient t_in;
168 
169  int num_t_components = input.vector_variable_size("Physics/"+_physics_name+"/traction_"+bc_id_string);
170 
171  if( num_t_components < 3 )
172  {
173  std::cerr << "Error: Expecting 3 components when specifying traction!" << std::endl
174  << " Found " << num_t_components << " components." << std::endl;
175  libmesh_error();
176  }
177 
178  for( int i = 0; i < num_t_components; i++ )
179  {
180  t_in(i) = input("Physics/"+_physics_name+"/traction_"+bc_id_string, 0.0, i );
181  }
182 
183  this->set_neumann_bc_value( bc_id, t_in );
184  }
185  break;
186 
187  default:
188  {
189  // Call base class to detect any physics-common boundary conditions
190  BCHandlingBase::init_bc_types( bc_id, bc_id_string, bc_type,
191  bc_vars, bc_value, input );
192  }
193 
194  }// End switch(bc_type)
195 
196  return;
197  }
198 
199  void SolidMechanicsBCHandling::user_init_dirichlet_bcs( libMesh::FEMSystem* system,
200  libMesh::DofMap& dof_map,
201  BoundaryID bc_id,
202  BCType bc_type ) const
203  {
204  VariableIndex u_var = _disp_vars.u_var();
205  libmesh_assert(system->has_variable(_disp_vars.u_var_name()));
206 
207  VariableIndex v_var;
208  if( _disp_vars.have_v() )
209  {
210  v_var = _disp_vars.v_var();
211  libmesh_assert(system->has_variable(_disp_vars.v_var_name()));
212  }
213 
214  VariableIndex w_var;
215  if( _disp_vars.have_w() )
216  {
217  w_var = _disp_vars.w_var();
218  libmesh_assert(system->has_variable(_disp_vars.w_var_name()));
219  }
220 
221  switch( bc_type )
222  {
223  case(PINNED):
224  {
225  std::set<BoundaryID> dbc_ids;
226  dbc_ids.insert(bc_id);
227 
228  std::vector<VariableIndex> dbc_vars;
229  dbc_vars.push_back(u_var);
230 
231  if( _disp_vars.have_v() )
232  dbc_vars.push_back(v_var);
233 
234  if( _disp_vars.have_w() )
235  dbc_vars.push_back(w_var);
236 
237  libMesh::ZeroFunction<libMesh::Number> zero;
238 
239  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
240  dbc_vars,
241  &zero );
242 
243  dof_map.add_dirichlet_boundary( no_slip_dbc );
244  }
245  break;
246 
247  case(CONSTANT_DISPLACEMENT):
248  {
249  std::set<BoundaryID> dbc_ids;
250  dbc_ids.insert(bc_id);
251 
252  std::vector<VariableIndex> dbc_vars;
253 
254  // This is inefficient, but it shouldn't matter because
255  // everything gets cached on the libMesh side so it should
256  // only affect performance at startup.
257  {
258  dbc_vars.push_back(u_var);
259  libMesh::ConstFunction<libMesh::Number>
260  disp_func( this->get_dirichlet_bc_value(bc_id,0) );
261 
262  libMesh::DirichletBoundary disp_dbc(dbc_ids,
263  dbc_vars,
264  &disp_func );
265 
266  dof_map.add_dirichlet_boundary( disp_dbc );
267  dbc_vars.clear();
268  }
269 
270  if( _disp_vars.have_v() )
271  {
272  dbc_vars.push_back(v_var);
273  libMesh::ConstFunction<libMesh::Number>
274  disp_func( this->get_dirichlet_bc_value(bc_id,1) );
275 
276  libMesh::DirichletBoundary disp_dbc(dbc_ids,
277  dbc_vars,
278  &disp_func );
279 
280  dof_map.add_dirichlet_boundary( disp_dbc );
281  dbc_vars.clear();
282  }
283 
284  if( _disp_vars.have_w() )
285  {
286  dbc_vars.push_back(w_var);
287  libMesh::ConstFunction<libMesh::Number>
288  disp_func( this->get_dirichlet_bc_value(bc_id,2) );
289 
290  libMesh::DirichletBoundary disp_dbc(dbc_ids,
291  dbc_vars,
292  &disp_func );
293 
294  dof_map.add_dirichlet_boundary( disp_dbc );
295  }
296  }
297  break;
298 
299  // Roller is free to move in the x-direction, so pin y and z-directions
300  case(ROLLER_X):
301  {
302  std::set<BoundaryID> dbc_ids;
303  dbc_ids.insert(bc_id);
304 
305  std::vector<VariableIndex> dbc_vars;
306 
307  if( _disp_vars.have_v() )
308  dbc_vars.push_back(v_var);
309 
310  if( _disp_vars.have_w() )
311  dbc_vars.push_back(w_var);
312 
313  libMesh::ZeroFunction<libMesh::Number> zero;
314 
315  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
316  dbc_vars,
317  &zero );
318 
319  dof_map.add_dirichlet_boundary( no_slip_dbc );
320  }
321  break;
322 
323  // Roller is free to move in the y-direction, so pin x and z-directions
324  case(ROLLER_Y):
325  {
326  std::set<BoundaryID> dbc_ids;
327  dbc_ids.insert(bc_id);
328 
329  std::vector<VariableIndex> dbc_vars;
330  dbc_vars.push_back(u_var);
331 
332  if( _disp_vars.have_w() )
333  dbc_vars.push_back(w_var);
334 
335  libMesh::ZeroFunction<libMesh::Number> zero;
336 
337  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
338  dbc_vars,
339  &zero );
340 
341  dof_map.add_dirichlet_boundary( no_slip_dbc );
342  }
343  break;
344 
345  // Roller is free to move in the z-direction, so pin x and y-directions
346  case(ROLLER_Z):
347  {
348  std::set<BoundaryID> dbc_ids;
349  dbc_ids.insert(bc_id);
350 
351  std::vector<VariableIndex> dbc_vars;
352  dbc_vars.push_back(u_var);
353  dbc_vars.push_back(v_var);
354 
355  libMesh::ZeroFunction<libMesh::Number> zero;
356 
357  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
358  dbc_vars,
359  &zero );
360 
361  dof_map.add_dirichlet_boundary( no_slip_dbc );
362  }
363  break;
364 
365  // Symmetric about YZ-plane so pin x-direction
366  case(SYMMETRY_YZ):
367  {
368  std::set<BoundaryID> dbc_ids;
369  dbc_ids.insert(bc_id);
370 
371  std::vector<VariableIndex> dbc_vars;
372  dbc_vars.push_back(u_var);
373 
374  libMesh::ZeroFunction<libMesh::Number> zero;
375 
376  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
377  dbc_vars,
378  &zero );
379 
380  dof_map.add_dirichlet_boundary( no_slip_dbc );
381  }
382  break;
383 
384  // Symmetric about XZ-plane so pin y-direction
385  case(SYMMETRY_XZ):
386  {
387  std::set<BoundaryID> dbc_ids;
388  dbc_ids.insert(bc_id);
389 
390  std::vector<VariableIndex> dbc_vars;
391  dbc_vars.push_back(v_var);
392 
393  libMesh::ZeroFunction<libMesh::Number> zero;
394 
395  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
396  dbc_vars,
397  &zero );
398 
399  dof_map.add_dirichlet_boundary( no_slip_dbc );
400  }
401  break;
402 
403  // Symmetric about XY-plane so pin z-direction
404  case(SYMMETRY_XY):
405  {
406  std::set<BoundaryID> dbc_ids;
407  dbc_ids.insert(bc_id);
408 
409  std::vector<VariableIndex> dbc_vars;
410  dbc_vars.push_back(w_var);
411 
412  libMesh::ZeroFunction<libMesh::Number> zero;
413 
414  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
415  dbc_vars,
416  &zero );
417 
418  dof_map.add_dirichlet_boundary( no_slip_dbc );
419  }
420  break;
421 
422  default:
423  {
424  std::cerr << "Invalid BCType " << bc_type << std::endl;
425  libmesh_error();
426  }
427 
428  }// end switch
429 
430  return;
431  }
432 
434  const GRINS::CachedValues& /*cache*/,
435  const bool /*request_jacobian*/,
436  const BoundaryID bc_id,
437  const BCType bc_type ) const
438  {
439  switch( bc_type )
440  {
441  case(CONSTANT_TRACTION):
442  {
443  const libMesh::Point& traction = this->get_neumann_bc_value(bc_id);
444 
445  _bound_conds.apply_neumann_normal( context, _disp_vars.u_var(), 1.0, traction(0) );
446 
447  if( _disp_vars.have_v() )
448  _bound_conds.apply_neumann_normal( context, _disp_vars.v_var(), 1.0, traction(1) );
449 
450  if( _disp_vars.have_w() )
451  _bound_conds.apply_neumann_normal( context, _disp_vars.w_var(), 1.0, traction(2) );
452  }
453  break;
454 
455  default:
456  {
457  std::cerr << "Error: Invalid Neumann BC type for " << _physics_name
458  << std::endl;
459  libmesh_error();
460  }
461 
462  } // switch( bc_type )
463 
464  return;
465  }
466 
467 } // end namespace GRINS
virtual void user_init_dirichlet_bcs(libMesh::FEMSystem *system, libMesh::DofMap &dof_map, GRINS::BoundaryID bc_id, GRINS::BCType bc_type) 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)
void apply_neumann_normal(AssemblyContext &context, const VariableIndex var, const libMesh::Real sign, const FEShape &value) const
Applies Neumann boundary conditions for the constant case.
libMesh::boundary_id_type BoundaryID
More descriptive name of the type used for boundary ids.
Definition: var_typedefs.h:54
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)
GRINS namespace.
const libMesh::Point & get_neumann_bc_value(GRINS::BoundaryID bc_id) 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)
const std::string & w_var_name() const
void init(libMesh::FEMSystem *system)
Initialize System variables.
virtual int string_to_int(const std::string &bc_type_in) const
GRINS::BoundaryConditions _bound_conds
Object that stashes generic boundary condition types.
virtual void user_apply_neumann_bcs(AssemblyContext &context, const GRINS::CachedValues &cache, const bool request_jacobian, const GRINS::BoundaryID bc_id, const GRINS::BCType bc_type) const
Base class for reading and handling boundary conditions for physics classes.
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 init_bc_data(const libMesh::FEMSystem &system)
Override this method to initialize any system-dependent data.
virtual int string_to_int(const std::string &bc_type_in) const
const std::string & v_var_name() const
void set_neumann_bc_type(GRINS::BoundaryID bc_id, int bc_type)
int BCType
Definition: bc_types.h:32
const std::string & u_var_name() const
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