33 #include "libmesh/composite_function.h"
34 #include "libmesh/composite_fem_function.h"
35 #include "libmesh/fem_context.h"
36 #include "libmesh/fem_system.h"
37 #include "libmesh/dof_map.h"
38 #include "libmesh/dirichlet_boundaries.h"
39 #include "libmesh/periodic_boundary.h"
40 #include "libmesh/dof_map.h"
41 #include "libmesh/const_function.h"
42 #include "libmesh/parsed_function.h"
43 #include "libmesh/parsed_fem_function.h"
50 : _num_periodic_bcs(0),
51 _physics_name( physics_name )
74 const std::string& bc_str,
75 const std::string& var_str,
76 const std::string& val_str)
78 int num_ids = input.vector_variable_size(id_str);
79 int num_bcs = input.vector_variable_size(bc_str);
83 if( num_ids != num_bcs )
85 std::cerr <<
"Error: Must specify equal number of boundary ids and boundary conditions"
90 for(
int i = 0; i < num_ids; i++ )
92 int bc_id = input(id_str, -1, i );
93 std::string bc_type_in = input(bc_str,
"NULL", i );
99 std::string bc_id_string = ss.str();
101 std::string bc_val = input(val_str, std::string(
""), i );
103 std::string bc_vars = input(var_str, std::string(
""), i );
105 this->
init_bc_types( bc_id, bc_id_string, bc_type, bc_vars, bc_val, input );
118 libMesh::DofMap& dof_map = system->get_dof_map();
120 for( std::vector< DBCContainer >::const_iterator
129 std::vector<VariableName> var_names = (*it).get_var_names();
131 std::vector<VariableIndex> dbc_vars;
133 for( std::vector<VariableName>::const_iterator name = var_names.begin();
134 name != var_names.end();
137 dbc_vars.push_back( system->variable_number( *name ) );
141 std::set<BoundaryID> bc_ids = (*it).get_bc_ids();
144 std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
145 func = (*it).get_func();
151 remapped_func.attach_subfunction(*func, dbc_vars);
156 libMesh::DirichletBoundary dbc( bc_ids, dbc_vars,
159 dof_map.add_dirichlet_boundary( dbc );
164 const std::string& func_string = (*it).get_fem_func_string();
166 libmesh_assert_not_equal_to(func_string,
"");
170 libMesh::ParsedFEMFunction<libMesh::Number>
171 func(*system, func_string);
173 libMesh::CompositeFEMFunction<libMesh::Number> remapped_func;
174 remapped_func.attach_subfunction(func, dbc_vars);
179 libMesh::DirichletBoundary dbc( bc_ids, dbc_vars,
183 dof_map.add_dirichlet_boundary( dbc );
192 libMesh::DofMap& dof_map = system->get_dof_map();
194 for( std::vector<std::pair<BoundaryID,BCType> >::const_iterator it =
_dirichlet_bc_map.begin();
209 std::cerr <<
"==========================================================" << std::endl
210 <<
"Error: Inconsistency in perioidic boundary conditions." << std::endl
212 <<
" only " <<
_periodic_bcs.size() <<
" pairs of data " << std::endl
213 <<
" were set." << std::endl
214 <<
"==========================================================" << std::endl;
218 libMesh::DofMap& dof_map = system->get_dof_map();
220 for( std::vector< PBCContainer >::const_iterator it =
_periodic_bcs.begin();
224 libMesh::PeriodicBoundary bc( it->get_offset_vector() );
225 bc.myboundary = it->get_master_bcid();
226 bc.pairedboundary = it->get_slave_bcid();
228 dof_map.add_periodic_boundary( bc );
236 const bool request_jacobian,
239 std::map< BoundaryID, BCType>::const_iterator
247 bc_id, bc_map_it->second );
275 return (_dirichlet_values.find(bc_id)->second)(component);
286 if( bc_type_in ==
"periodic" )
290 else if( bc_type_in ==
"constant_dirichlet" )
294 else if( bc_type_in ==
"parsed_dirichlet" )
298 else if( bc_type_in ==
"parsed_fem_dirichlet" )
302 else if( bc_type_in ==
"axisymmetric" )
309 std::cerr <<
"==========================================================" << std::endl
310 <<
"Error: Invalid bc_type " << bc_type_in << std::endl
312 <<
"==========================================================" << std::endl;
319 const std::string& bc_id_string,
321 const std::string& bc_vars,
322 const std::string& bc_value,
323 const GetPot& input )
334 int pbc_size = input.vector_variable_size(
"Physics/"+
_physics_name+
"/periodic_wall_"+bc_id_string );
335 if( pbc_size == 0 )
break;
340 std::cerr <<
"=========================================================="
341 <<
"Error: Must specify exactly two boundary condition ids " << std::endl
342 <<
" for periodic boundary conditions. Found " << pbc_size << std::endl
343 <<
"==========================================================" << std::endl;
347 int id0 = input(
"Physics/"+
_physics_name+
"/periodic_wall_"+bc_id_string, -1, 0 );
348 int id1 = input(
"Physics/"+
_physics_name+
"/periodic_wall_"+bc_id_string, -1, 1 );
350 if( id0 == -1 || id1 == -1 )
352 std::cerr <<
"=========================================================="
353 <<
"Error: Default bc id detected for periodic bc." << std::endl
354 <<
" Please explicitly set periodic bc ids." << std::endl
355 <<
" Detected ids " << id0 <<
", " << id1 << std::endl
356 <<
" for bc id = " << bc_id << std::endl
357 <<
"==========================================================" << std::endl;
368 else if( id1 == bc_id )
376 std::cerr <<
"=========================================================="
377 <<
"Error: At least one of the bcs must be the master id." << std::endl
378 <<
" Detected master id = " << bc_id << std::endl
379 <<
" Found bc ids (" << id0 <<
"," << id1 <<
")." << std::endl
380 <<
"==========================================================" << std::endl;
386 int offset_size = input.vector_variable_size(
"Physics/"+
_physics_name+
"/periodic_offset_"+bc_id_string );
387 if( offset_size == 0 )
390 std::cerr <<
"=========================================================="
391 <<
"Error: Offset vector not found for bc id " << bc_id << std::endl
392 <<
"==========================================================" << std::endl;
395 libMesh::RealVectorValue offset_vector;
396 for(
int i = 0; i < offset_size; i++ )
398 offset_vector(i) = input(
"Physics/"+
_physics_name+
"/periodic_offset_"+bc_id_string, 0.0, i );
418 libMesh::Number bc_val_num = StringUtilities::string_to_T<libMesh::Number>(bc_value);
421 (std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
422 (
new libMesh::ConstFunction<libMesh::Number>(bc_val_num)));
437 (std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
438 (
new libMesh::ParsedFunction<libMesh::Number>(bc_value)));
460 std::cerr <<
"=========================================================="
461 <<
"Error: Invalid BC type for " <<
_physics_name << std::endl
462 <<
" Detected BC type was " << bc_type << std::endl
463 <<
"==========================================================" << std::endl;
void set_master_bcid(const GRINS::BoundaryID bc_id)
Add variables that are constrained by the Dirichlet bc.
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)
virtual void user_init_dirichlet_bcs(libMesh::FEMSystem *system, libMesh::DofMap &dof_map, GRINS::BoundaryID bc_id, GRINS::BCType bc_type) const
Simple helper class to setup general Dirichlet boundary conditions.
std::vector< GRINS::PBCContainer > _periodic_bcs
Simple helper class to setup periodic boundary conditions.
libMesh::boundary_id_type BoundaryID
More descriptive name of the type used for boundary ids.
void attach_dirichlet_bound_func(const GRINS::DBCContainer &dirichlet_bc)
std::vector< GRINS::DBCContainer > _dirichlet_bound_funcs
void set_fem_func_string(const std::string &s)
virtual void apply_neumann_bcs(AssemblyContext &context, const GRINS::CachedValues &cache, const bool request_jacobian, const GRINS::BoundaryID bc_id) const
virtual ~BCHandlingBase()
std::map< GRINS::BoundaryID, libMesh::Point > _dirichlet_values
Stash prescribed Dirichlet boundary values.
void attach_neumann_bound_func(GRINS::NBCContainer &neumann_bcs)
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.
unsigned int _num_periodic_bcs
void set_slave_bcid(const GRINS::BoundaryID bc_id)
Simple helper class to setup general Neumann boundary conditions.
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.
virtual void init_dirichlet_bcs(libMesh::FEMSystem *system) const
virtual int string_to_int(const std::string &bc_type_in) const
BoundaryID get_bc_id() const
virtual void init_periodic_bcs(libMesh::FEMSystem *system) const
static bool _axisymmetric
Flag to cache whether or not there is an axisymmetric boundary present.
virtual void init_dirichlet_bc_func_objs(libMesh::FEMSystem *system) const
std::map< GRINS::BoundaryID, GRINS::NBCContainer > _neumann_bound_funcs
void set_offset_vector(const libMesh::RealVectorValue &offset_vector)
virtual void init_bc_data(const libMesh::FEMSystem &system)
Override this method to initialize any system-dependent data.
std::map< GRINS::BoundaryID, libMesh::Point > _q_values
Stash prescribed boundary fluxes.
void add_bc_id(const GRINS::BoundaryID bc_id)
Add boundary id's for which this Dirichlet bc is to be applied.
std::map< GRINS::BoundaryID, GRINS::BCType > _neumann_bc_map
Map between boundary id and Neumann boundary condition type.
void set_func(std::tr1::shared_ptr< libMesh::FunctionBase< libMesh::Number > > func)
Add the Dirichlet bc functor.
void set_neumann_bc_type(GRINS::BoundaryID bc_id, int bc_type)
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
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
std::string _physics_name