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

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