GRINS-0.8.0
qoi_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
26 #include "grins/qoi_factory.h"
27 
28 // GRINS
29 #include "grins/string_utils.h"
30 #include "grins/physics_naming.h"
31 #include "grins/qoi_names.h"
33 #include "grins/vorticity.h"
38 #include "grins/hitran.h"
39 #include "grins/absorption_coeff.h"
42 
43 #if GRINS_HAVE_ANTIOCH
45 #endif
46 
47 #if GRINS_HAVE_CANTERA
48 #include "grins/cantera_mixture.h"
49 #endif
50 
51 // libMesh
52 #include "libmesh/parsed_function.h"
53 
54 namespace GRINS
55 {
57  {
58  return;
59  }
60 
62  {
63  return;
64  }
65 
66  SharedPtr<CompositeQoI> QoIFactory::build(const GetPot& input)
67  {
68  std::string qoi_list = input("QoI/enabled_qois", "none" );
69 
70  std::vector<std::string> qoi_names;
71 
72  if( qoi_list != std::string("none") )
73  {
74  StringUtilities::split_string( qoi_list, std::string(" "), qoi_names );
75  }
76 
77  SharedPtr<CompositeQoI> qois( new CompositeQoI );
78 
79  if( !qoi_names.empty() )
80  {
81  for( std::vector<std::string>::const_iterator name = qoi_names.begin();
82  name != qoi_names.end(); ++name )
83  {
84  this->add_qoi( input, *name, qois );
85 
86  this->check_qoi_physics_consistency( input, *name );
87  }
88 
89  if( input( "screen-options/echo_qoi", false ) )
90  {
91  this->echo_qoi_list( qois );
92  }
93  }
94 
95  return qois;
96  }
97 
98  void QoIFactory::add_qoi( const GetPot& input, const std::string& qoi_name, SharedPtr<CompositeQoI>& qois )
99  {
100  QoIBase* qoi = NULL;
101 
102  if( qoi_name == avg_nusselt )
103  {
104  qoi = new AverageNusseltNumber( avg_nusselt );
105  }
106 
107  else if( qoi_name == parsed_boundary )
108  {
109  qoi = new ParsedBoundaryQoI( parsed_boundary );
110  }
111 
112  else if( qoi_name == parsed_interior )
113  {
114  qoi = new ParsedInteriorQoI( parsed_interior );
115  }
116 
117  else if( qoi_name == vorticity )
118  {
119  qoi = new Vorticity( vorticity );
120  }
121 
122  else if( qoi_name == weighted_flux )
123  {
124  qoi = new WeightedFluxQoI( weighted_flux );
125  }
126 
127  else if( qoi_name == integrated_function )
128  {
129  std::string function;
130  if (input.have_variable("QoI/IntegratedFunction/function"))
131  function = input("QoI/IntegratedFunction/function", "");
132  else
133  libmesh_error_msg("ERROR: Could not find function to integrate");
134 
135  unsigned int p_level = input("QoI/IntegratedFunction/quadrature_level", 2);
136 
137  SharedPtr<libMesh::FunctionBase<libMesh::Real> > f = new libMesh::ParsedFunction<libMesh::Real>(function);
138 
139  qoi = new IntegratedFunction<libMesh::FunctionBase<libMesh::Real> >(input,p_level,f,"IntegratedFunction",integrated_function);
140  }
141 
142  else if ( qoi_name == spectroscopic_absorption )
143  {
144  std::string material;
145  this->get_var_value<std::string>(input,material,"QoI/SpectroscopicAbsorption/material","NoMaterial!");
146 
147  std::string hitran_data;
148  this->get_var_value<std::string>(input,hitran_data,"QoI/SpectroscopicAbsorption/hitran_data_file","");
149 
150  std::string hitran_partition;
151  this->get_var_value<std::string>(input,hitran_partition,"QoI/SpectroscopicAbsorption/hitran_partition_function_file","");
152 
153  libMesh::Real T_min,T_max,T_step;
154  std::string partition_temp_var = "QoI/SpectroscopicAbsorption/partition_temperatures";
155  if (input.have_variable(partition_temp_var))
156  {
157  T_min = input(partition_temp_var, 0.0, 0);
158  T_max = input(partition_temp_var, 0.0, 1);
159  T_step = input(partition_temp_var, 0.0, 2);
160  }
161  else
162  libmesh_error_msg("ERROR: Could not find tenmperature range specification for partition functions: "+partition_temp_var+" 'T_min T_max T_step'");
163 
164  SharedPtr<HITRAN> hitran( new HITRAN(hitran_data,hitran_partition,T_min,T_max,T_step) );
165 
166  std::string species;
167  this->get_var_value<std::string>(input,species,"QoI/SpectroscopicAbsorption/species_of_interest","");
168 
169  SharedPtr<FEMFunctionAndDerivativeBase<libMesh::Real> > absorb;
170 
171  libMesh::Real thermo_pressure = -1.0;
172  bool calc_thermo_pressure = input("QoI/SpectroscopicAbsorption/calc_thermo_pressure", false );
173  if (!calc_thermo_pressure)
174  thermo_pressure = input("Materials/"+material+"/ThermodynamicPressure/value", 0.0 );
175 
176  libMesh::Real nu_desired;
177  this->get_var_value<libMesh::Real>(input,nu_desired,"QoI/SpectroscopicAbsorption/desired_wavenumber",0.0);
178 
179  libMesh::Real nu_min;
180  this->get_var_value<libMesh::Real>(input,nu_min,"QoI/SpectroscopicAbsorption/min_wavenumber",0.0);
181 
182  libMesh::Real nu_max;
183  this->get_var_value<libMesh::Real>(input,nu_max,"QoI/SpectroscopicAbsorption/max_wavenumber",0.0);
184 
185  ChemistryBuilder chem_builder;
186 
187 #if GRINS_HAVE_ANTIOCH
188  libMesh::UniquePtr<AntiochChemistry> chem_ptr;
189  chem_builder.build_chemistry(input,material,chem_ptr);
190  SharedPtr<AntiochChemistry> chem(chem_ptr.release());
191 
192  absorb = new AbsorptionCoeff<AntiochChemistry>(chem,hitran,nu_min,nu_max,nu_desired,species,thermo_pressure);
193 #elif GRINS_HAVE_CANTERA
194  libMesh::UniquePtr<CanteraMixture> chem_ptr;
195  chem_builder.build_chemistry(input,material,chem_ptr);
196  SharedPtr<CanteraMixture> chem(chem_ptr.release());
197 
198  absorb = new AbsorptionCoeff<CanteraMixture>(chem,hitran,nu_min,nu_max,nu_desired,species,thermo_pressure);
199 #else
200  libmesh_error_msg("ERROR: GRINS must be built with either Antioch or Cantera to use the SpectroscopicAbsorption QoI");
201 #endif
202 
203  qoi = new SpectroscopicAbsorption(input,qoi_name,absorb);
204  }
205 
206  else
207  {
208  libMesh::err << "Error: Invalid QoI name " << qoi_name << std::endl;
209  libmesh_error();
210  }
211 
212  libmesh_assert(qoi);
213 
214  qois->add_qoi( *qoi );
215 
216  return;
217  }
218 
219  void QoIFactory::check_qoi_physics_consistency( const GetPot& input,
220  const std::string& qoi_name )
221  {
222  int num_physics = input.vector_variable_size("Physics/enabled_physics");
223 
224  // This should be checked other places, but let's be double sure.
225  libmesh_assert(num_physics > 0);
226 
227  std::set<std::string> requested_physics;
228  std::set<std::string> required_physics;
229 
230  // Build Physics name set
231  for( int i = 0; i < num_physics; i++ )
232  {
233  requested_physics.insert( input("Physics/enabled_physics", "NULL", i ) );
234  }
235 
236  /* If it's Nusselt, we'd better have HeatTransfer or LowMachNavierStokes.
237  HeatTransfer implicitly requires fluids, so no need to check for those. `*/
238  if( qoi_name == avg_nusselt )
239  {
240  required_physics.insert(PhysicsNaming::heat_transfer());
241  required_physics.insert(PhysicsNaming::low_mach_navier_stokes());
242  this->consistency_helper( requested_physics, required_physics, qoi_name );
243  }
244 
245  return;
246  }
247 
248  void QoIFactory::echo_qoi_list( SharedPtr<CompositeQoI>& qois )
249  {
251  std::cout << "==========================================================" << std::endl
252  << "List of Enabled QoIs:" << std::endl;
253 
254  for( unsigned int q = 0; q < qois->n_qois(); q++ )
255  {
256  std::cout << qois->get_qoi(q).name() << std::endl;
257  }
258 
259  std::cout << "==========================================================" << std::endl;
260 
261  return;
262  }
263 
264  void QoIFactory::consistency_helper( const std::set<std::string>& requested_physics,
265  const std::set<std::string>& required_physics,
266  const std::string& qoi_name )
267  {
268  bool physics_found = false;
269  for( std::set<std::string>::const_iterator name = required_physics.begin();
270  name != required_physics.end();
271  name++ )
272  {
273  if( requested_physics.find( (*name) ) != requested_physics.end() )
274  physics_found = true;
275  }
276 
277  if( !physics_found )
278  this->consistency_error_msg( qoi_name, required_physics );
279 
280  return;
281  }
282 
283  void QoIFactory::consistency_error_msg( const std::string& qoi_name,
284  const std::set<std::string>& required_physics )
285  {
286  libMesh::err << "================================================================" << std::endl
287  << "QoI " << qoi_name << std::endl
288  << "requires one of the following physics which were not found:" <<std::endl;
289 
290  for( std::set<std::string>::const_iterator name = required_physics.begin();
291  name != required_physics.end();
292  name++ )
293  {
294  libMesh::err << *name << std::endl;
295  }
296 
297  libMesh::err << "================================================================" << std::endl;
298 
299  libmesh_error();
300  }
301 
302  template<typename T>
303  void QoIFactory::get_var_value( const GetPot & input, T & value, std::string input_var, T default_value )
304  {
305  if (input.have_variable(input_var))
306  value = input(input_var, default_value);
307  else
308  libmesh_error_msg("ERROR: Could not find required input parameter: "+input_var);
309  }
310 
311  template void QoIFactory::get_var_value<std::string>( const GetPot &, std::string &, std::string, std::string);
312  template void QoIFactory::get_var_value<libMesh::Real>( const GetPot &, libMesh::Real &, std::string, libMesh::Real);
313 
314 } //namespace GRINS
virtual SharedPtr< CompositeQoI > build(const GetPot &input)
Definition: qoi_factory.C:66
static PhysicsName heat_transfer()
virtual void check_qoi_physics_consistency(const GetPot &input, const std::string &qoi_name)
Definition: qoi_factory.C:219
void consistency_error_msg(const std::string &qoi_name, const std::set< std::string > &required_physics)
Definition: qoi_factory.C:283
Vorticity QoI.
Definition: vorticity.h:44
const std::string spectroscopic_absorption
Definition: qoi_names.h:36
static PhysicsName low_mach_navier_stokes()
const std::string avg_nusselt
Definition: qoi_names.h:30
const std::string vorticity
Definition: qoi_names.h:31
GRINS namespace.
Parsed Interior QoI.
const std::string integrated_function
Definition: qoi_names.h:35
Parsed Boundary QoI.
void get_var_value(const GetPot &input, T &value, std::string input_var, T default_value)
Helper function to read a required value from the input file, or error if value is missing...
Definition: qoi_factory.C:303
virtual ~QoIFactory()
Definition: qoi_factory.C:61
QoI class for absorption calculations using the Beer-Lambert Law.
Evaluates the Beer-Lambert Law at a given point in space.
const std::string weighted_flux
Definition: qoi_names.h:34
HITRAN interface object.
Definition: hitran.h:58
const std::string parsed_boundary
Definition: qoi_names.h:32
void build_chemistry(const GetPot &input, const std::string &material, libMesh::UniquePtr< ChemistryType > &chem_ptr)
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
const std::string parsed_interior
Definition: qoi_names.h:33
virtual void echo_qoi_list(SharedPtr< CompositeQoI > &qois)
Definition: qoi_factory.C:248
void consistency_helper(const std::set< std::string > &requested_physics, const std::set< std::string > &required_physics, const std::string &qoi_name)
Definition: qoi_factory.C:264
virtual void add_qoi(const GetPot &input, const std::string &qoi_name, SharedPtr< CompositeQoI > &qois)
Definition: qoi_factory.C:98

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