GRINS-0.8.0
List of all members | Public Member Functions | Protected Member Functions | Private Member Functions
GRINS::QoIFactory Class Reference

#include <qoi_factory.h>

Public Member Functions

 QoIFactory ()
 
virtual ~QoIFactory ()
 
virtual SharedPtr< CompositeQoIbuild (const GetPot &input)
 

Protected Member Functions

virtual void add_qoi (const GetPot &input, const std::string &qoi_name, SharedPtr< CompositeQoI > &qois)
 
virtual void check_qoi_physics_consistency (const GetPot &input, const std::string &qoi_name)
 
virtual void echo_qoi_list (SharedPtr< CompositeQoI > &qois)
 
void consistency_helper (const std::set< std::string > &requested_physics, const std::set< std::string > &required_physics, const std::string &qoi_name)
 
void consistency_error_msg (const std::string &qoi_name, const std::set< std::string > &required_physics)
 

Private Member Functions

template<typename T >
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. More...
 

Detailed Description

Definition at line 40 of file qoi_factory.h.

Constructor & Destructor Documentation

GRINS::QoIFactory::QoIFactory ( )

Definition at line 56 of file qoi_factory.C.

57  {
58  return;
59  }
GRINS::QoIFactory::~QoIFactory ( )
virtual

Definition at line 61 of file qoi_factory.C.

62  {
63  return;
64  }

Member Function Documentation

void GRINS::QoIFactory::add_qoi ( const GetPot &  input,
const std::string &  qoi_name,
SharedPtr< CompositeQoI > &  qois 
)
protectedvirtual

Definition at line 98 of file qoi_factory.C.

References GRINS::avg_nusselt, GRINS::ChemistryBuilder::build_chemistry(), GRINS::integrated_function, GRINS::parsed_boundary, GRINS::parsed_interior, GRINS::spectroscopic_absorption, GRINS::vorticity, and GRINS::weighted_flux.

Referenced by build().

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  }
const std::string spectroscopic_absorption
Definition: qoi_names.h:36
const std::string avg_nusselt
Definition: qoi_names.h:30
const std::string vorticity
Definition: qoi_names.h:31
const std::string integrated_function
Definition: qoi_names.h:35
const std::string weighted_flux
Definition: qoi_names.h:34
const std::string parsed_boundary
Definition: qoi_names.h:32
const std::string parsed_interior
Definition: qoi_names.h:33
SharedPtr< CompositeQoI > GRINS::QoIFactory::build ( const GetPot &  input)
virtual

Definition at line 66 of file qoi_factory.C.

References add_qoi(), check_qoi_physics_consistency(), echo_qoi_list(), and GRINS::StringUtilities::split_string().

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  }
virtual void check_qoi_physics_consistency(const GetPot &input, const std::string &qoi_name)
Definition: qoi_factory.C:219
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
virtual void echo_qoi_list(SharedPtr< CompositeQoI > &qois)
Definition: qoi_factory.C:248
virtual void add_qoi(const GetPot &input, const std::string &qoi_name, SharedPtr< CompositeQoI > &qois)
Definition: qoi_factory.C:98
void GRINS::QoIFactory::check_qoi_physics_consistency ( const GetPot &  input,
const std::string &  qoi_name 
)
protectedvirtual

Definition at line 219 of file qoi_factory.C.

References GRINS::avg_nusselt, consistency_helper(), GRINS::PhysicsNaming::heat_transfer(), and GRINS::PhysicsNaming::low_mach_navier_stokes().

Referenced by build().

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  }
static PhysicsName heat_transfer()
static PhysicsName low_mach_navier_stokes()
const std::string avg_nusselt
Definition: qoi_names.h:30
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
void GRINS::QoIFactory::consistency_error_msg ( const std::string &  qoi_name,
const std::set< std::string > &  required_physics 
)
protected

Definition at line 283 of file qoi_factory.C.

Referenced by consistency_helper().

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  }
void GRINS::QoIFactory::consistency_helper ( const std::set< std::string > &  requested_physics,
const std::set< std::string > &  required_physics,
const std::string &  qoi_name 
)
protected

Definition at line 264 of file qoi_factory.C.

References consistency_error_msg().

Referenced by check_qoi_physics_consistency().

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  }
void consistency_error_msg(const std::string &qoi_name, const std::set< std::string > &required_physics)
Definition: qoi_factory.C:283
void GRINS::QoIFactory::echo_qoi_list ( SharedPtr< CompositeQoI > &  qois)
protectedvirtual
Todo:
Generalize to multiple QoI case when CompositeQoI is implemented in libMesh

Definition at line 248 of file qoi_factory.C.

Referenced by build().

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  }
template<typename T >
void GRINS::QoIFactory::get_var_value ( const GetPot &  input,
T &  value,
std::string  input_var,
default_value 
)
private

Helper function to read a required value from the input file, or error if value is missing.

Definition at line 303 of file qoi_factory.C.

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  }

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

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