GRINS-0.8.0
List of all members | Public Member Functions | Protected Member Functions
GRINS::MoleFractionsDirichletBCFactory Class Reference

Parses mole fraction values and converts to mass fractions. More...

#include <constant_function_dirichlet_bc_factory.h>

Inheritance diagram for GRINS::MoleFractionsDirichletBCFactory:
Inheritance graph
[legend]
Collaboration diagram for GRINS::MoleFractionsDirichletBCFactory:
Collaboration graph
[legend]

Public Member Functions

 MoleFractionsDirichletBCFactory (const std::string &bc_type_name)
 
 ~MoleFractionsDirichletBCFactory ()
 
- Public Member Functions inherited from GRINS::ConstantFunctionDirichletBCFactory
 ConstantFunctionDirichletBCFactory (const std::string &bc_type_name)
 
 ~ConstantFunctionDirichletBCFactory ()
 
- Public Member Functions inherited from GRINS::DirichletBCFactoryFunctionBase< libMesh::FunctionBase< libMesh::Number > >
 DirichletBCFactoryFunctionBase (const std::string &bc_type_name)
 
 ~DirichletBCFactoryFunctionBase ()
 
- Public Member Functions inherited from GRINS::DirichletBCFactoryAbstract
 DirichletBCFactoryAbstract (const std::string &bc_type_name)
 
 ~DirichletBCFactoryAbstract ()
 
- Public Member Functions inherited from GRINS::BCFactoryAbstract< libMesh::DirichletBoundary >
 BCFactoryAbstract (const std::string &bc_type_name)
 
 ~BCFactoryAbstract ()
 
- Public Member Functions inherited from GRINS::FactoryWithGetPot< libMesh::DirichletBoundary >
 FactoryWithGetPot (const std::string &name)
 
 ~FactoryWithGetPot ()
 
- Public Member Functions inherited from GRINS::FactoryAbstract< libMesh::DirichletBoundary >
virtual ~FactoryAbstract ()
 
- Public Member Functions inherited from GRINS::ParsedFunctionFactoryHelper< libMesh::FunctionBase< libMesh::Number > >
 ParsedFunctionFactoryHelper ()
 
 ~ParsedFunctionFactoryHelper ()
 

Protected Member Functions

virtual void add_found_vars (const GetPot &input, MultiphysicsSystem &system, const std::string &section, const std::set< std::string > &vars_found, libMesh::CompositeFunction< libMesh::Number > &composite_func, std::set< std::string > &vars_added) const
 Here, we're expected vars_found to correspond to mole fractions and we'll add mass fractions. More...
 
virtual void set_vars_to_search_for (const std::string &section, const std::vector< std::string > &var_names, std::vector< std::string > &vars_to_search_for) const
 We'll search for mole fractions: X_<species_name>. More...
 
template<typename ChemistryType >
void add_mole_frac_to_mass_frac (const GetPot &input, const std::string &section, const std::set< std::string > &vars_found, const std::string &material, const SpeciesMassFractionsVariable &species_fe_var, libMesh::CompositeFunction< libMesh::Number > &composite_func, std::set< std::string > &vars_added) const
 
void extract_species_name (const std::string &var_name, const std::string &prefix, std::string &species_name) const
 
std::string extract_var_section (const std::string &section) const
 
- Protected Member Functions inherited from GRINS::ConstantFunctionDirichletBCFactory
virtual libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > build_func (const GetPot &input, MultiphysicsSystem &system, std::vector< std::string > &var_names, const std::string &section)
 Builds ConstantFunction objects for boundary conditions. More...
 
- Protected Member Functions inherited from GRINS::DirichletBCFactoryFunctionBase< libMesh::FunctionBase< libMesh::Number > >
libMesh::UniquePtr< libMesh::DirichletBoundary > make_dirichlet_boundary (const std::set< BoundaryID > &bc_ids, const libMesh::System &system, libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > &func, const std::vector< VariableIndex > &var_indices)
 Dispatch, based on FunctionType, to the correct DirchletBoundary construction. More...
 
virtual const std::vector< std::string > & get_var_names () const
 Helper function that can be overridded in subclasses. More...
 
- Protected Member Functions inherited from GRINS::DirichletBCFactoryAbstract
void check_for_vars (const GetPot &input, const std::string &section, const std::vector< std::string > &var_names, std::set< std::string > *vars_found=NULL)
 Helper function. More...
 
- Protected Member Functions inherited from GRINS::BCFactoryAbstract< libMesh::DirichletBoundary >
void check_for_multiple_expressions (const GetPot &input, const std::string &section, const std::string &var_name) const
 Ensure that there is only one expression for the [Section/var_name] variable. More...
 
void build_var_indices (const MultiphysicsSystem &system, const std::vector< std::string > &var_names, std::vector< VariableIndex > &var_indices) const
 
virtual void check_state () const
 Helper function to reduce code duplication. More...
 
virtual void reset_state ()
 Helper function to redue code duplication. More...
 
- Protected Member Functions inherited from GRINS::FactoryAbstract< libMesh::DirichletBoundary >
 FactoryAbstract (const std::string &name)
 Constructor is protected. Use the build() method to construct Base objects. More...
 
- Protected Member Functions inherited from GRINS::ParsedFunctionFactoryHelper< libMesh::FunctionBase< libMesh::Number > >
libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > build_parsed_func (const MultiphysicsSystem &system, const std::string &expression)
 
libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > build_composite_func ()
 

Additional Inherited Members

- Static Public Member Functions inherited from GRINS::BCFactoryAbstract< libMesh::DirichletBoundary >
static void set_system (MultiphysicsSystem &system)
 
static void set_bc_ids (const std::set< BoundaryID > &bc_ids)
 Boundary id for the current boundary condition section. More...
 
static void set_fe_var (const FEVariablesBase &fe_var)
 Active variable for the current boundary condition. More...
 
static void set_section (const std::string &section)
 Sets the current section of the input file. More...
 
static bool have_bc_type (const std::string &bc_type)
 
- Static Public Member Functions inherited from GRINS::FactoryWithGetPot< libMesh::DirichletBoundary >
static void set_getpot (const GetPot &input)
 
- Static Public Member Functions inherited from GRINS::FactoryAbstract< libMesh::DirichletBoundary >
static libMesh::UniquePtr< libMesh::DirichletBoundary > build (const std::string &name)
 Use this method to build objects of type Base. More...
 
- Static Protected Member Functions inherited from GRINS::FactoryAbstract< libMesh::DirichletBoundary >
static FactoryAbstract< libMesh::DirichletBoundary > & get_factory (const std::string &name)
 Helper method that looks up the factory and returns it if present, or error if it's not. More...
 
static DerivedType & get_factory_subclass (const std::string &name)
 Like get_factory, but will downcast to DerivedType. More...
 
static std::map< std::string, FactoryAbstract< libMesh::DirichletBoundary > * > & factory_map ()
 
- Static Protected Attributes inherited from GRINS::BCFactoryAbstract< libMesh::DirichletBoundary >
static MultiphysicsSystem_system
 We store only a raw pointer here because we can't make a copy. More...
 
static const std::set< BoundaryID > * _bc_ids
 BoundaryID for constructing a particular boundary condition. More...
 
static const FEVariablesBase_fe_var
 The FEVariablesBase class associated with the boundary condition being built. More...
 
static std::string _section
 
- Static Protected Attributes inherited from GRINS::FactoryWithGetPot< libMesh::DirichletBoundary >
static const GetPot * _input
 We store only a raw pointer here because we can't make a copy. More...
 

Detailed Description

Parses mole fraction values and converts to mass fractions.

Only valid for SpeciesMassFraction FEVariables.

Definition at line 95 of file constant_function_dirichlet_bc_factory.h.

Constructor & Destructor Documentation

GRINS::MoleFractionsDirichletBCFactory::MoleFractionsDirichletBCFactory ( const std::string &  bc_type_name)
inline

Definition at line 98 of file constant_function_dirichlet_bc_factory.h.

100  {}
GRINS::MoleFractionsDirichletBCFactory::~MoleFractionsDirichletBCFactory ( )
inline

Definition at line 102 of file constant_function_dirichlet_bc_factory.h.

102 {}

Member Function Documentation

void GRINS::MoleFractionsDirichletBCFactory::add_found_vars ( const GetPot &  input,
MultiphysicsSystem system,
const std::string &  section,
const std::set< std::string > &  vars_found,
libMesh::CompositeFunction< libMesh::Number > &  composite_func,
std::set< std::string > &  vars_added 
) const
protectedvirtual

Here, we're expected vars_found to correspond to mole fractions and we'll add mass fractions.

vars_found should have things like X_N, etc. The prefix will be "X_" for mole fractions. Then, we'll add mass fractions, using the corresponding names in the SpeciesMassFractionsVariable. We'll match them based on the species names.

Reimplemented from GRINS::ConstantFunctionDirichletBCFactory.

Definition at line 158 of file constant_function_dirichlet_bc_factory.C.

References GRINS::SpeciesMassFractionsVariable::material().

172  {
173  // Strip out the Variable name from the section
174  std::string var_section = extract_var_section(section);
175 
176  // This only makes sense for SpeciesMassFractionsVariable in the VariableWarehouse.
177  // This call will error out if it's not there.
178  const SpeciesMassFractionsVariable& species_fe_var =
179  GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsVariable>
180  (var_section);
181 
182  const std::string& material = species_fe_var.material();
183 
184  std::string thermochem_input_str = "Materials/"+material+"/GasMixture/thermochemistry_library";
185 
186  if( !input.have_variable(thermochem_input_str) )
187  libmesh_error_msg("ERROR: Could not find input option "+thermochem_input_str+" !");
188 
189  const std::string thermochem_lib = input(thermochem_input_str, std::string("DIE!") );
190 
191  if( thermochem_lib == "cantera" )
192  {
193 #ifdef GRINS_HAVE_CANTERA
194  this->add_mole_frac_to_mass_frac<CanteraMixture>(input,section,vars_found,material,
195  species_fe_var,composite_func,vars_added);
196 #else
197  libmesh_error_msg("Error: Cantera not enabled in this configuration. Reconfigure using --with-cantera option.");
198 #endif
199  }
200  else if( thermochem_lib == "antioch" )
201  {
202 #ifdef GRINS_HAVE_ANTIOCH
203  this->add_mole_frac_to_mass_frac<AntiochChemistry>(input,section,vars_found,material,
204  species_fe_var,composite_func,vars_added);
205 #else
206  libmesh_error_msg("Error: Antioch not enabled in this configuration. Reconfigure using --with-antioch option.");
207 #endif
208  }
209  else
210  libmesh_error_msg("ERROR: Invalid thermochemistry library "+thermochem_lib+"!");
211  }
std::string extract_var_section(const std::string &section) const
template<typename ChemistryType >
template void GRINS::MoleFractionsDirichletBCFactory::add_mole_frac_to_mass_frac< AntiochChemistry > ( const GetPot &  input,
const std::string &  section,
const std::set< std::string > &  vars_found,
const std::string &  material,
const SpeciesMassFractionsVariable species_fe_var,
libMesh::CompositeFunction< libMesh::Number > &  composite_func,
std::set< std::string > &  vars_added 
) const
protected
Todo:
We should have a ChemsitryWarehouse or something to just grab this from one place instead of rebuilding.

Definition at line 214 of file constant_function_dirichlet_bc_factory.C.

References GRINS::ChemistryBuilder::build_chemistry(), GRINS::SpeciesMassFractionsVariable::prefix(), GRINS::SpeciesMassFractionsVariable::species(), and GRINS::StringUtilities::split_string().

221  {
222  unsigned int n_vars_found = vars_found.size();
223 
224  // Parse in all the species mole fracs that are in the input (it is assumed non-specified are 0)
225  std::vector<libMesh::Number> species_mole_fracs(n_vars_found);
226  libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();
227  {
228  unsigned int count = 0;
229  for(std::set<std::string>::const_iterator var = vars_found.begin();
230  var != vars_found.end(); ++var )
231  {
232  species_mole_fracs[count] = input(section+"/"+(*var),invalid_num);
233  count++;
234  }
235  }
236 
237  // Make sure mole fracs sum to 1
238  libMesh::Number sum = 0.0;
239  for(unsigned int v = 0; v < n_vars_found; v++ )
240  sum += species_mole_fracs[v];
241 
242  libMesh::Number tol = std::numeric_limits<libMesh::Number>::epsilon()*10;
243  if( std::abs(sum-1.0) > tol )
244  libmesh_error_msg("ERROR: Mole fractions do not sum to 1! Found sum = "+StringUtilities::T_to_string<libMesh::Number>(sum));
245 
246  // Extract species names
247  std::vector<std::string> species_names(n_vars_found);
248  {
249  unsigned int count = 0;
250  for(std::set<std::string>::const_iterator var = vars_found.begin();
251  var != vars_found.end(); ++var )
252  {
253  std::vector<std::string> split_name;
254  // vars_found should have the form "X_<species name>"
255  StringUtilities::split_string((*var),"_",split_name);
256  libmesh_assert_equal_to(split_name[0],std::string("X"));
257  libmesh_assert_equal_to(split_name.size(),2);
258  species_names[count] = split_name[1];
259  count++;
260  }
261  }
262 
263  // Now convert to mass frac and add to composite function
266  ChemistryBuilder chem_builder;
267  libMesh::UniquePtr<ChemistryType> chem_ptr;
268  chem_builder.build_chemistry(input,material,chem_ptr);
269 
270  const ChemistryType & chem = *chem_ptr;
271 
272  libMesh::Real M = 0.0;
273  for(unsigned int v = 0; v < n_vars_found; v++ )
274  {
275  unsigned int s = chem.species_index(species_names[v]);
276  M += species_mole_fracs[v]*chem.M(s);
277  }
278 
279  const std::string& prefix = species_fe_var.prefix();
280 
281  for(unsigned int v = 0; v < n_vars_found; v++ )
282  {
283  // Finish computing species mass fraction
284  unsigned int s = chem.species_index(species_names[v]);
285  libMesh::Number species_mass_fracs = species_mole_fracs[v]*chem.M(s)/M;
286 
287  // Add the function
288  std::vector<VariableIndex> var_idx(1,species_fe_var.species(s));
289  libMesh::ConstFunction<libMesh::Number> const_func(species_mass_fracs);
290  composite_func.attach_subfunction(const_func,var_idx);
291 
292  // Log that we added this variable
293  vars_added.insert(prefix+species_names[v]);
294  }
295  }
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
void GRINS::MoleFractionsDirichletBCFactory::extract_species_name ( const std::string &  var_name,
const std::string &  prefix,
std::string &  species_name 
) const
protected

Definition at line 118 of file constant_function_dirichlet_bc_factory.C.

References GRINS::StringUtilities::split_string().

Referenced by set_vars_to_search_for().

121  {
122  std::vector<std::string> split_name;
123  StringUtilities::split_string(var_name,prefix,split_name);
124 
125  // split_string won't add the prefix, since it was used as the delimiter, so
126  // split_name should just have the lingering species name
127  libmesh_assert_equal_to(split_name.size(), 1);
128 
129  species_name = split_name[0];
130  }
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
std::string GRINS::MoleFractionsDirichletBCFactory::extract_var_section ( const std::string &  section) const
protected

Definition at line 297 of file constant_function_dirichlet_bc_factory.C.

References GRINS::StringUtilities::split_string().

Referenced by set_vars_to_search_for().

298  {
299  std::vector<std::string> tokens;
300  StringUtilities::split_string(section,"/",tokens);
301  return tokens.back();
302  }
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
void GRINS::MoleFractionsDirichletBCFactory::set_vars_to_search_for ( const std::string &  section,
const std::vector< std::string > &  var_names,
std::vector< std::string > &  vars_to_search_for 
) const
protectedvirtual

We'll search for mole fractions: X_<species_name>.

We extract the species name from var_names and then set the corresponding vars_to_search_for to X_<species_name>.

Reimplemented from GRINS::ConstantFunctionDirichletBCFactory.

Definition at line 132 of file constant_function_dirichlet_bc_factory.C.

References extract_species_name(), extract_var_section(), and GRINS::SpeciesMassFractionsVariable::prefix().

135  {
136  libmesh_assert_equal_to(var_names.size(),vars_to_search_for.size());
137 
138  // Strip out the Variable name from the section
139  std::string var_section = extract_var_section(section);
140 
141  // This only makes sense for SpeciesMassFractionsVariable in the VariableWarehouse.
142  // This call will error out if it's not there.
143  const SpeciesMassFractionsVariable& species_fe_var =
144  GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsVariable>
145  (var_section);
146 
147  const std::string& prefix = species_fe_var.prefix();
148  for( unsigned int v = 0; v < var_names.size(); v++ )
149  {
150  std::string species_name;
151  this->extract_species_name(var_names[v],prefix,species_name);
152  vars_to_search_for[v] = "X_"+species_name;
153  }
154  }
void extract_species_name(const std::string &var_name, const std::string &prefix, std::string &species_name) const
std::string extract_var_section(const std::string &section) const

The documentation for this class was generated from the following files:

Generated on Tue Dec 19 2017 12:47:31 for GRINS-0.8.0 by  doxygen 1.8.9.1