GRINS-0.7.0
prescribed_vector_value_dirichlet_old_style_bc_factory.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2016 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 // This class
27 
28 // GRINS
29 #include "grins/string_utils.h"
32 #include "grins/physics_naming.h"
34 
35 #ifdef GRINS_HAVE_CANTERA
36 #include "grins/cantera_mixture.h"
37 #endif
38 
39 #ifdef GRINS_HAVE_ANTIOCH
41 #endif
42 
43 // libMesh
44 #include "libmesh/composite_function.h"
45 #include "libmesh/const_function.h"
46 
47 namespace GRINS
48 {
49  libMesh::UniquePtr<libMesh::FunctionBase<libMesh::Number> >
51  MultiphysicsSystem& system,
52  std::vector<std::string>& var_names,
53  const std::string& section )
54  {
55  libmesh_assert_equal_to(DirichletBCFactoryAbstract::_bc_ids->size(), 1 );
56 
57  std::string bc_id_string = StringUtilities::T_to_string<BoundaryID>( *(_bc_ids->begin()) );
58 
59  std::string var_input_string = this->var_input_string();
60 
61  std::string input_string = section+"/"+var_input_string+"_"+bc_id_string;
62 
63  unsigned int n_comps = input.vector_variable_size(input_string);
64 
65  if( var_names.size() > n_comps )
66  libmesh_error_msg("ERROR: Insufficient number of variable components in "+input_string+"!");
67 
68  libMesh::UniquePtr<libMesh::CompositeFunction<libMesh::Number> >
70 
71  this->add_funcs(input,system,input_string,var_names,*(remapped_func.get()));
72 
73  return libMesh::UniquePtr<libMesh::FunctionBase<libMesh::Number> >(remapped_func.release());
74  }
75 
77  MultiphysicsSystem& system,
78  const std::string& input_string,
79  const std::vector<std::string>& var_names,
80  libMesh::CompositeFunction<libMesh::Number>& composite_func ) const
81  {
82  for( unsigned int n = 0; n < var_names.size(); n++ )
83  {
84  std::vector<VariableIndex> dbc_vars(1,system.variable_number(var_names[n]));
85  libMesh::Number value = input(input_string, 0.0, n);
86  libMesh::ConstFunction<libMesh::Number> const_func(value);
87  composite_func.attach_subfunction(const_func, dbc_vars);
88  }
89  }
90 
91  // To avoid compiler warnings without GRINS or Cantera
92 #if defined(GRINS_HAVE_ANTIOCH) || defined(GRINS_HAVE_CANTERA)
94  MultiphysicsSystem& /*system*/,
95  const std::string& input_string,
96  const std::vector<std::string>& var_names,
97  libMesh::CompositeFunction<libMesh::Number>& composite_func ) const
98 #else
100  MultiphysicsSystem& /*system*/,
101  const std::string& input_string,
102  const std::vector<std::string>& var_names,
103  libMesh::CompositeFunction<libMesh::Number>& /*composite_func*/ ) const
104 #endif
105  {
106  const unsigned int n_vars = var_names.size();
107 
108  // Parse in all the species mole fracs that are in the input
109  std::vector<libMesh::Number> species_mole_fracs(n_vars);
110  libMesh::Number invalid_num = std::numeric_limits<libMesh::Number>::max();
111 
112  if( input.vector_variable_size(input_string) != n_vars )
113  libmesh_error_msg("ERROR: Expected "+StringUtilities::T_to_string<unsigned int>(n_vars)+" components in "+input_string);
114 
115  for(unsigned int v = 0; v < n_vars; v++ )
116  species_mole_fracs[v] = input(input_string,invalid_num,v);
117 
118  // Make sure mole fracs sum to 1
119  libMesh::Number sum = 0.0;
120  for(unsigned int v = 0; v < n_vars; v++ )
121  sum += species_mole_fracs[v];
122 
123  libMesh::Number tol = std::numeric_limits<libMesh::Number>::epsilon()*10;
124  if( std::abs(sum-1.0) > tol )
125  libmesh_error_msg("ERROR: Mole fractions do not sum to 1! Found sum = "+StringUtilities::T_to_string<libMesh::Number>(sum));
126 
127 
128  // To avoid compiler warnings without GRINS or Cantera
129 #if defined(GRINS_HAVE_ANTIOCH) || defined(GRINS_HAVE_CANTERA)
130  // This only makes sense for SpeciesMassFractionsFEVariables in the
131  // VariableWarehouse. This call will error out if it's not there.
132  const SpeciesMassFractionsFEVariables& species_fe_var =
133  GRINSPrivate::VariableWarehouse::get_variable_subclass<SpeciesMassFractionsFEVariables>
135 #endif
136 
137  std::string thermochem_lib;
140  thermochem_lib );
141 
142  if( thermochem_lib == "cantera" )
143  {
144 #ifdef GRINS_HAVE_CANTERA
145  this->convert_mole_fracs_and_add_to_func<CanteraMixture>(input,
146  species_mole_fracs,
147  species_fe_var,
148  composite_func);
149 #else
150  libmesh_error_msg("Error: Cantera not enabled in this configuration. Reconfigure using --with-cantera option.");
151 #endif
152  }
153  else if( thermochem_lib == "antioch" )
154  {
155 #ifdef GRINS_HAVE_ANTIOCH
156  this->convert_mole_fracs_and_add_to_func<AntiochChemistry>(input,
157  species_mole_fracs,
158  species_fe_var,
159  composite_func);
160 #else
161  libmesh_error_msg("Error: Antioch not enabled in this configuration. Reconfigure using --with-antioch option.");
162 #endif
163  }
164  else
165  libmesh_error_msg("ERROR: Invalid thermochemistry library "+thermochem_lib+"!");
166  }
167 
168  template<typename ChemistryType>
171  (const GetPot& input, const std::vector<libMesh::Number>& species_mole_fracs,
172  const SpeciesMassFractionsFEVariables& species_fe_var,
173  libMesh::CompositeFunction<libMesh::Number>& composite_func) const
174  {
175  const std::string& material = species_fe_var.material();
176 
179  ChemistryType chem(input,material);
180 
181  const unsigned int n_vars = species_mole_fracs.size();
182  // Compute M
183  libMesh::Real M = 0.0;
184  for( unsigned int s = 0; s < n_vars; s++ )
185  M += species_mole_fracs[s]*chem.M(s);
186 
187  // Convert mole fractions to mass fractions and add to function
188  for( unsigned int s = 0; s < n_vars; s++ )
189  {
190  libMesh::Number species_mass_fracs =species_mole_fracs[s]*chem.M(s)/M;
191 
192  std::vector<VariableIndex> var_idx(1,species_fe_var.species(s));
193 
194  libMesh::ConstFunction<libMesh::Number> const_func(species_mass_fracs);
195  composite_func.attach_subfunction(const_func,var_idx);
196  }
197  }
198 
199  //Instantiate
200 #ifdef GRINS_HAVE_CANTERA
201  template void PrescribedMoleFractionsDirichletOldStyleBCFactory::convert_mole_fracs_and_add_to_func<CanteraMixture>(const GetPot&, const std::vector<libMesh::Number>&, const SpeciesMassFractionsFEVariables&,libMesh::CompositeFunction<libMesh::Number>& ) const;
202 #endif
203 
204 #ifdef GRINS_HAVE_ANTIOCH
205  template void PrescribedMoleFractionsDirichletOldStyleBCFactory::convert_mole_fracs_and_add_to_func<AntiochChemistry>(const GetPot&, const std::vector<libMesh::Number>&, const SpeciesMassFractionsFEVariables&,libMesh::CompositeFunction<libMesh::Number>& ) const;
206 #endif
207 
208  // Register factories
213 
214 } // end namespace GRINS
virtual void add_funcs(const GetPot &input, MultiphysicsSystem &system, const std::string &input_string, const std::vector< std::string > &var_names, libMesh::CompositeFunction< libMesh::Number > &composite_func) const
static void parse_thermochemistry_model(const GetPot &input, const std::string &physics, std::string &model)
Determine thermochemistry model type.
PrescribedDispDirichletOldStyleBCFactory grins_factory_constant_displacement_old_style("constant_displacement_old_style")
PrescribedVelDirichletOldStyleBCFactory grins_factory_prescribed_vel_old_style("prescribed_vel_old_style")
static PhysicsName reacting_low_mach_navier_stokes()
static const std::set< BoundaryID > * _bc_ids
BoundaryID for constructing a particular boundary condition.
void convert_mole_fracs_and_add_to_func(const GetPot &input, const std::vector< libMesh::Number > &species_mole_fracs, const SpeciesMassFractionsFEVariables &species_fe_var, libMesh::CompositeFunction< libMesh::Number > &composite_func) const
GRINS namespace.
static std::string species_mass_fractions_section()
Interface with libMesh for solving Multiphysics problems.
VariableIndex species(unsigned int species) const
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 the FunctionBase object for boundary condition.
PrescribedMoleFractionsDirichletOldStyleBCFactory grins_factory_prescribed_mole_fraccs_old_style("prescribed_mole_fracs_old_style")
virtual void add_funcs(const GetPot &input, MultiphysicsSystem &system, const std::string &input_string, const std::vector< std::string > &var_names, libMesh::CompositeFunction< libMesh::Number > &composite_func) const
PrescribedSpeciesDirichletOldStyleBCFactory grins_factory_prescribed_species_old_style("prescribed_species_old_style")

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