34 #ifdef GRINS_HAVE_CANTERA
38 #ifdef GRINS_HAVE_ANTIOCH
43 #include "libmesh/composite_function.h"
44 #include "libmesh/const_function.h"
45 #include "libmesh/zero_function.h"
49 libMesh::UniquePtr<libMesh::FunctionBase<libMesh::Number> >
52 std::vector<std::string>& var_names,
53 const std::string& section )
55 libmesh_assert( !var_names.empty() );
58 libMesh::UniquePtr<libMesh::FunctionBase<libMesh::Number> > all_funcs;
65 std::set<std::string> vars_found;
67 std::vector<std::string> vars_to_search_for(var_names.size());
69 this->
check_for_vars(input,section,vars_to_search_for,&vars_found);
76 libMesh::cast_ref<libMesh::CompositeFunction<libMesh::Number>&>(*(all_funcs.get()));
78 std::set<std::string> vars_added;
79 this->
add_found_vars(input, system, section, vars_found, composite_func, vars_added);
82 for( std::vector<std::string>::const_iterator var = var_names.begin();
83 var < var_names.end(); ++var )
85 if( vars_added.find(*var) == vars_added.end() )
87 std::vector<VariableIndex> var_idx(1,system.variable_number(*var));
88 composite_func.attach_subfunction( libMesh::ZeroFunction<libMesh::Number>(),var_idx);
97 const std::string& section,
98 const std::set<std::string>& vars_found,
100 std::set<std::string>& vars_added )
const
102 libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();
104 for( std::set<std::string>::const_iterator var = vars_found.begin();
105 var != vars_found.end(); ++var )
107 std::vector<VariableIndex> var_idx(1,system.variable_number(*var));
109 libMesh::Number value = input(section+
"/"+(*var),invalid_num);
111 libMesh::ConstFunction<libMesh::Number> const_func(value);
112 composite_func.attach_subfunction(const_func,var_idx);
115 vars_added = vars_found;
119 const std::string& prefix,
120 std::string& species_name )
const
122 std::vector<std::string> split_name;
127 libmesh_assert_equal_to(split_name.size(), 1);
129 species_name = split_name[0];
133 const std::vector<std::string>& var_names,
134 std::vector<std::string>&vars_to_search_for )
const
136 libmesh_assert_equal_to(var_names.size(),vars_to_search_for.size());
144 GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsVariable>
147 const std::string& prefix = species_fe_var.
prefix();
148 for(
unsigned int v = 0; v < var_names.size(); v++ )
150 std::string species_name;
152 vars_to_search_for[v] =
"X_"+species_name;
157 #if defined(GRINS_HAVE_ANTIOCH) || defined(GRINS_HAVE_CANTERA)
160 const std::string& section,
161 const std::set<std::string>& vars_found,
163 std::set<std::string>& vars_added )
const
167 const std::string& section,
168 const std::set<std::string>& ,
170 std::set<std::string>& ) const
174 std::string var_section = extract_var_section(section);
179 GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsVariable>
182 const std::string& material = species_fe_var.
material();
184 std::string thermochem_input_str =
"Materials/"+material+
"/GasMixture/thermochemistry_library";
186 if( !input.have_variable(thermochem_input_str) )
187 libmesh_error_msg(
"ERROR: Could not find input option "+thermochem_input_str+
" !");
189 const std::string thermochem_lib = input(thermochem_input_str, std::string(
"DIE!") );
191 if( thermochem_lib ==
"cantera" )
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);
197 libmesh_error_msg(
"Error: Cantera not enabled in this configuration. Reconfigure using --with-cantera option.");
200 else if( thermochem_lib ==
"antioch" )
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);
206 libmesh_error_msg(
"Error: Antioch not enabled in this configuration. Reconfigure using --with-antioch option.");
210 libmesh_error_msg(
"ERROR: Invalid thermochemistry library "+thermochem_lib+
"!");
213 template<
typename ChemistryType>
215 const std::string& section,
216 const std::set<std::string>& vars_found,
217 const std::string& material,
220 std::set<std::string>& vars_added)
const
222 unsigned int n_vars_found = vars_found.size();
225 std::vector<libMesh::Number> species_mole_fracs(n_vars_found);
226 libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();
228 unsigned int count = 0;
229 for(std::set<std::string>::const_iterator var = vars_found.begin();
230 var != vars_found.end(); ++var )
232 species_mole_fracs[count] = input(section+
"/"+(*var),invalid_num);
238 libMesh::Number sum = 0.0;
239 for(
unsigned int v = 0; v < n_vars_found; v++ )
240 sum += species_mole_fracs[v];
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));
247 std::vector<std::string> species_names(n_vars_found);
249 unsigned int count = 0;
250 for(std::set<std::string>::const_iterator var = vars_found.begin();
251 var != vars_found.end(); ++var )
253 std::vector<std::string> 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];
267 libMesh::UniquePtr<ChemistryType> chem_ptr;
270 const ChemistryType & chem = *chem_ptr;
272 libMesh::Real M = 0.0;
273 for(
unsigned int v = 0; v < n_vars_found; v++ )
275 unsigned int s = chem.species_index(species_names[v]);
276 M += species_mole_fracs[v]*chem.M(s);
279 const std::string& prefix = species_fe_var.
prefix();
281 for(
unsigned int v = 0; v < n_vars_found; v++ )
284 unsigned int s = chem.species_index(species_names[v]);
285 libMesh::Number species_mass_fracs = species_mole_fracs[v]*chem.M(s)/M;
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);
293 vars_added.insert(prefix+species_names[v]);
299 std::vector<std::string> tokens;
301 return tokens.back();
305 #ifdef GRINS_HAVE_CANTERA
309 #ifdef GRINS_HAVE_ANTIOCH
310 template void MoleFractionsDirichletBCFactory::add_mole_frac_to_mass_frac<AntiochChemistry>(
const GetPot&,
const std::string&,
const std::set<std::string>&,
const std::string&,
const SpeciesMassFractionsVariable&,libMesh::CompositeFunction<libMesh::Number>&,std::set<std::string>& )
const;
virtual void set_vars_to_search_for(const std::string &, const std::vector< std::string > &var_names, std::vector< std::string > &vars_to_search_for) const
Set the vars_to_search_for, based on var_names.
VariableIndex species(unsigned int species) const
virtual void set_vars_to_search_for(const std::string §ion, const std::vector< std::string > &var_names, std::vector< std::string > &vars_to_search_for) const
We'll search for mole fractions: X_.
virtual void add_found_vars(const GetPot &input, MultiphysicsSystem &system, const std::string §ion, const std::set< std::string > &vars_found, libMesh::CompositeFunction< libMesh::Number > &composite_func, std::set< std::string > &vars_added) const
Adds the vars_found to the composite_func.
void extract_species_name(const std::string &var_name, const std::string &prefix, std::string &species_name) const
libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > build_composite_func()
const std::string & prefix() const
void add_mole_frac_to_mass_frac(const GetPot &input, const std::string §ion, 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
Interface with libMesh for solving Multiphysics problems.
void build_chemistry(const GetPot &input, const std::string &material, libMesh::UniquePtr< ChemistryType > &chem_ptr)
std::string extract_var_section(const std::string §ion) const
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
virtual libMesh::UniquePtr< libMesh::FunctionBase< libMesh::Number > > build_func(const GetPot &input, MultiphysicsSystem &system, std::vector< std::string > &var_names, const std::string §ion)
Builds ConstantFunction objects for boundary conditions.
void check_for_vars(const GetPot &input, const std::string §ion, const std::vector< std::string > &var_names, std::set< std::string > *vars_found=NULL)
Helper function.
const std::string & material() const
virtual void add_found_vars(const GetPot &input, MultiphysicsSystem &system, const std::string §ion, 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...