GRINS-0.7.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::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::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 SpeciesMassFractionsFEVariables &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
 
- 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::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 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 94 of file constant_function_dirichlet_bc_factory.h.

Constructor & Destructor Documentation

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

Definition at line 97 of file constant_function_dirichlet_bc_factory.h.

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

Definition at line 101 of file constant_function_dirichlet_bc_factory.h.

101 {}

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 SpeciesMassFractionsFEVariables. We'll match them based on the species names.

Reimplemented from GRINS::ConstantFunctionDirichletBCFactory.

Definition at line 153 of file constant_function_dirichlet_bc_factory.C.

References GRINS::SpeciesMassFractionsFEVariables::material(), and GRINS::VariablesParsing::species_mass_fractions_section().

167  {
168  // This only makes sense for SpeciesMassFractionsFEVariables in the VariableWarehouse.
169  // This call will error out if it's not there.
170  const SpeciesMassFractionsFEVariables& species_fe_var =
171  GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsFEVariables>
173 
174  const std::string& material = species_fe_var.material();
175 
176  std::string thermochem_input_str = "Materials/"+material+"/GasMixture/thermochemistry_library";
177 
178  if( !input.have_variable(thermochem_input_str) )
179  libmesh_error_msg("ERROR: Could not find input option "+thermochem_input_str+" !");
180 
181  const std::string thermochem_lib = input(thermochem_input_str, std::string("DIE!") );
182 
183  if( thermochem_lib == "cantera" )
184  {
185 #ifdef GRINS_HAVE_CANTERA
186  this->add_mole_frac_to_mass_frac<CanteraMixture>(input,section,vars_found,material,
187  species_fe_var,composite_func,vars_added);
188 #else
189  libmesh_error_msg("Error: Cantera not enabled in this configuration. Reconfigure using --with-cantera option.");
190 #endif
191  }
192  else if( thermochem_lib == "antioch" )
193  {
194 #ifdef GRINS_HAVE_ANTIOCH
195  this->add_mole_frac_to_mass_frac<AntiochChemistry>(input,section,vars_found,material,
196  species_fe_var,composite_func,vars_added);
197 #else
198  libmesh_error_msg("Error: Antioch not enabled in this configuration. Reconfigure using --with-antioch option.");
199 #endif
200  }
201  else
202  libmesh_error_msg("ERROR: Invalid thermochemistry library "+thermochem_lib+"!");
203  }
static std::string species_mass_fractions_section()
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 SpeciesMassFractionsFEVariables 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 206 of file constant_function_dirichlet_bc_factory.C.

References GRINS::SpeciesMassFractionsFEVariables::prefix(), GRINS::SpeciesMassFractionsFEVariables::species(), and GRINS::StringUtilities::split_string().

213  {
214  unsigned int n_vars_found = vars_found.size();
215 
216  // Parse in all the species mole fracs that are in the input (it is assumed non-specified are 0)
217  std::vector<libMesh::Number> species_mole_fracs(n_vars_found);
218  libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();
219  {
220  unsigned int count = 0;
221  for(std::set<std::string>::const_iterator var = vars_found.begin();
222  var != vars_found.end(); ++var )
223  {
224  species_mole_fracs[count] = input(section+"/"+(*var),invalid_num);
225  count++;
226  }
227  }
228 
229  // Make sure mole fracs sum to 1
230  libMesh::Number sum = 0.0;
231  for(unsigned int v = 0; v < n_vars_found; v++ )
232  sum += species_mole_fracs[v];
233 
234  libMesh::Number tol = std::numeric_limits<libMesh::Number>::epsilon()*10;
235  if( std::abs(sum-1.0) > tol )
236  libmesh_error_msg("ERROR: Mole fractions do not sum to 1! Found sum = "+StringUtilities::T_to_string<libMesh::Number>(sum));
237 
238  // Extract species names
239  std::vector<std::string> species_names(n_vars_found);
240  {
241  unsigned int count = 0;
242  for(std::set<std::string>::const_iterator var = vars_found.begin();
243  var != vars_found.end(); ++var )
244  {
245  std::vector<std::string> split_name;
246  // vars_found should have the form "X_<species name>"
247  StringUtilities::split_string((*var),"_",split_name);
248  libmesh_assert_equal_to(split_name[0],std::string("X"));
249  libmesh_assert_equal_to(split_name.size(),2);
250  species_names[count] = split_name[1];
251  count++;
252  }
253  }
254 
255  // Now convert to mass frac and add to composite function
258  ChemistryType chem(input,material);
259 
260  libMesh::Real M = 0.0;
261  for(unsigned int v = 0; v < n_vars_found; v++ )
262  {
263  unsigned int s = chem.species_index(species_names[v]);
264  M += species_mole_fracs[v]*chem.M(s);
265  }
266 
267  const std::string& prefix = species_fe_var.prefix();
268 
269  for(unsigned int v = 0; v < n_vars_found; v++ )
270  {
271  // Finish computing species mass fraction
272  unsigned int s = chem.species_index(species_names[v]);
273  libMesh::Number species_mass_fracs = species_mole_fracs[v]*chem.M(s)/M;
274 
275  // Add the function
276  std::vector<VariableIndex> var_idx(1,species_fe_var.species(s));
277  libMesh::ConstFunction<libMesh::Number> const_func(species_mass_fracs);
278  composite_func.attach_subfunction(const_func,var_idx);
279 
280  // Log that we added this variable
281  vars_added.insert(prefix+species_names[v]);
282  }
283  }
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 117 of file constant_function_dirichlet_bc_factory.C.

References GRINS::StringUtilities::split_string().

Referenced by set_vars_to_search_for().

120  {
121  std::vector<std::string> split_name;
122  StringUtilities::split_string(var_name,prefix,split_name);
123 
124  // split_string won't add the prefix, since it was used as the delimiter, so
125  // split_name should just have the lingering species name
126  libmesh_assert_equal_to(split_name.size(), 1);
127 
128  species_name = split_name[0];
129  }
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::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 131 of file constant_function_dirichlet_bc_factory.C.

References extract_species_name(), GRINS::SpeciesMassFractionsFEVariables::prefix(), and GRINS::VariablesParsing::species_mass_fractions_section().

133  {
134  libmesh_assert_equal_to(var_names.size(),vars_to_search_for.size());
135 
136  // This only makes sense for SpeciesMassFractionsFEVariables in the VariableWarehouse.
137  // This call will error out if it's not there.
138  const SpeciesMassFractionsFEVariables& species_fe_var =
139  GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsFEVariables>
141 
142  const std::string& prefix = species_fe_var.prefix();
143  for( unsigned int v = 0; v < var_names.size(); v++ )
144  {
145  std::string species_name;
146  this->extract_species_name(var_names[v],prefix,species_name);
147  vars_to_search_for[v] = "X_"+species_name;
148  }
149  }
void extract_species_name(const std::string &var_name, const std::string &prefix, std::string &species_name) const
static std::string species_mass_fractions_section()

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

Generated on Thu Jun 2 2016 21:52:31 for GRINS-0.7.0 by  doxygen 1.8.10