GRINS-0.8.0
materials_parsing.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 // These functions
27 
28 // GRINS
29 #include "grins/common.h"
30 #include "grins/physics_naming.h"
31 #include "grins/parameter_user.h"
32 
33 namespace GRINS
34 {
35  void MaterialsParsing::viscosity_model( const GetPot& input,
36  const std::string& /*physics*/,
37  const std::string& material,
38  std::string& model )
39  {
40  if( !input.have_variable("Materials/"+material+"/Viscosity/model") )
41  {
42  libmesh_error_msg("Error: Could not find Materials/"+material+"/Viscosity/model in input file.");
43  }
44 
45  model = input( "Materials/"+material+"/Viscosity/model", "DIE!" );
46 
47  return;
48  }
49 
51  const std::string& /*physics*/,
52  const std::string& material,
53  std::string& model )
54  {
55  if( !input.have_variable("Materials/"+material+"/ThermalConductivity/model") )
56  {
57  libmesh_error_msg("Error: Could not find Materials/"+material+"/ThermalConductivity/model in input file.");
58  }
59 
60  model = input( "Materials/"+material+"/ThermalConductivity/model", "DIE!" );
61 
62  return;
63  }
64 
65  void MaterialsParsing::specific_heat_model( const GetPot& input,
66  const std::string& /*physics*/,
67  const std::string& material,
68  std::string& model )
69  {
70  if( !input.have_variable("Materials/"+material+"/SpecificHeat/model") )
71  {
72  libmesh_error_msg("Error: Could not find Materials/"+material+"/SpecificHeat/model in input file.");
73  }
74 
75  model = input( "Materials/"+material+"/SpecificHeat/model", "DIE!" );
76  }
77 
78  void MaterialsParsing::turb_viscosity_model( const GetPot& input,
79  const std::string& /*physics*/,
80  const std::string& material,
81  std::string& model )
82  {
83  if( !input.have_variable("Materials/"+material+"/Viscosity/turb_visc_model") )
84  {
85  libmesh_error_msg("Error: Could not find Materials/"+material+"/Viscosity/turb_visc_model in input file.");
86  }
87 
88  model = input( "Materials/"+material+"/Viscosity/turb_visc_model", "DIE!" );
89  }
90 
91  void MaterialsParsing::stress_strain_model( const GetPot& input,
92  const std::string& /*physics*/,
93  const std::string& material,
94  std::string& model,
95  std::string& strain_energy )
96  {
97  if( !input.have_variable("Materials/"+material+"/StressStrainLaw/model") )
98  {
99  libmesh_error_msg("Error: Could not find Materials/"+material+"/StressStrainLaw/model in input file!");
100  }
101 
102  model = input("Materials/"+material+"/StressStrainLaw/model", "DIE!");
103  strain_energy = input("Materials/"+material+"/StressStrainLaw/strain_energy", "none");
104  // These options are deprecated
105  if( model == std::string( "HookesLaw" ) )
106  {
107  std::string warning = "WARNING: Detected model HookesLaw. This is DEPRECATED!\n";
108  warning += " Please update to use hookes_law.\n";
109  grins_warning(warning);
110 
111  model = std::string("hookes_law");
112  }
113 
114  if( model == std::string( "MooneyRivlin" ) )
115  {
116  std::string warning = "WARNING: Detected model MooneyRivlin. This is DEPRECATED!\n";
117  warning += " Please update model to use incompressible_hyperelasticity and\n";
118  warning += " set strain_energy to mooney_rivlin.\n";
119  grins_warning(warning);
120 
121  model = std::string("incompressible_hyperelasticity");
122  strain_energy = std::string("mooney_rivlin");
123  }
124  }
125 
126  void MaterialsParsing::read_density( const std::string& core_physics_name,
127  const GetPot& input,
128  ParameterUser& params,
129  libMesh::Real& rho )
130  {
131  bool have_material = MaterialsParsing::have_material(input,core_physics_name);
132 
133  std::string material = input("Physics/"+core_physics_name+"/material", "DIE!");
134 
135  // Error if both material/Density and rho are specified
137  "Physics/"+core_physics_name+"/rho",
138  "Materials/"+material+"/Density/value" );
139 
140  // It's deprecated to have nothing and default to 1.0
141  if( !input.have_variable("Physics/"+core_physics_name+"/rho") &&
142  !have_material )
143  {
144  // For some insane reason, we'd originally tied density specifically
145  // to PhysicsNaming::incompressible_navier_stokes(), so we'll check for that first.
146  if( input.have_variable("Physics/"+PhysicsNaming::incompressible_navier_stokes()+"/rho") )
147  {
148  std::string warning = "WARNING: neither Physics/"+core_physics_name+"/rho nor\n";
149  warning += " Physics/"+core_physics_name+"/material options were detected.\n";
150  warning += " But we found Physics/"+PhysicsNaming::incompressible_navier_stokes()+"/rho so we using that.\n";
151  warning += " This behavior is DEPRECATED.\n";
152  warning += " Please update and use Physics/"+core_physics_name+"/material.\n";
153  grins_warning(warning);
154 
155  params.set_parameter
156  (rho, input,
157  "Physics/"+PhysicsNaming::incompressible_navier_stokes()+"/rho", 1.0 /*default*/);
158  }
159  // Otherwise, the insanity continued and we defaulted to 1.0
160  else
161  {
162  std::string warning = "WARNING: neither Physics/"+core_physics_name+"/rho nor\n";
163  warning += " Physics/"+core_physics_name+"/material nor\n";
164  warning += " Physics/"+PhysicsNaming::incompressible_navier_stokes()+"/rho options were detected.\n";
165  warning += " We are assuming a density value of 1.0. This is DEPRECATED.\n";
166  warning += " Please update and use Physics/"+core_physics_name+"/material.\n";
167  grins_warning(warning);
168 
169  params.set_parameter
170  (rho, input,
171  "Physics/"+core_physics_name+"/rho", 1.0 /*default*/);
172  }
173  }
174  // It's deprecated to use rho as the density input
175  else if( input.have_variable("Physics/"+core_physics_name+"/rho") )
176  {
177  MaterialsParsing::dep_input_warning( "Physics/"+core_physics_name+"/rho",
178  "Density/value" );
179 
180  params.set_parameter
181  (rho, input,
182  "Physics/"+core_physics_name+"/rho", 1.0 /*default*/);
183  }
184 
185  // This is the preferred version
186  else if( have_material )
187  {
188  if( !input.have_variable("Materials/"+material+"/Density/value") )
189  libmesh_error_msg("ERROR: Could not find Materials/"+material+"/Density/value in input!");
190 
191  params.set_parameter
192  (rho, input,
193  "Materials/"+material+"/Density/value", 0.0 /*default*/);
194  }
195  // Wat?
196  else
197  libmesh_error();
198 
199  // Let's make sure we actually got a valid density value
200  if( rho <= 0.0 )
201  {
202  libmesh_error_msg("ERROR: Detected non-positive value of density!");
203  }
204  }
205 
206  void MaterialsParsing::read_specific_heat( const std::string& core_physics_name,
207  const GetPot& input,
208  ParameterUser& params,
209  libMesh::Real& cp )
210  {
211  std::string material = input("Physics/"+core_physics_name+"/material", "DIE!");
212 
213  // Error if both material/SpecificHeat and Cp are specified
215  "Physics/"+core_physics_name+"/Cp",
216  "Materials/"+material+"/SpecificHeat/value" );
217 
218  // It's deprecated to have nothing and default to 1.0
219  if( !input.have_variable("Physics/"+core_physics_name+"/Cp") &&
220  ( !input.have_variable("Physics/"+core_physics_name+"/material") ||
221  !input.have_variable("Materials/"+material+"/SpecificHeat/value") ) )
222  {
223  // For some insane reason, we'd originally tied Cp specifically
224  // to PhysicsNaming::heat_transfer(), so we'll check for that first.
225  if( input.have_variable("Physics/"+PhysicsNaming::heat_transfer()+"/Cp") )
226  {
227  std::string warning = "WARNING: neither Physics/"+core_physics_name+"/Cp nor\n";
228  warning += " Physics/"+core_physics_name+"/material options were detected.\n";
229  warning += " But we found Physics/"+PhysicsNaming::heat_transfer()+"/Cp so we using that.\n";
230  warning += " This behavior is DEPRECATED.\n";
231  warning += " Please update and use Physics/"+core_physics_name+"/material.\n";
232  grins_warning(warning);
233 
234  params.set_parameter
235  (cp, input,
236  "Physics/"+PhysicsNaming::heat_transfer()+"/Cp", 1.0 /*default*/);
237  }
238  // Otherwise, the insanity continued and we defaulted to 1.0
239  else
240  {
241  std::string warning = "WARNING: neither Physics/"+core_physics_name+"/Cp nor\n";
242  warning += " Physics/"+core_physics_name+"/material nor\n";
243  warning += " Physics/"+PhysicsNaming::heat_transfer()+"/Cp options were detected.\n";
244  warning += " We are assuming a specific heat value of 1.0. This is DEPRECATED.\n";
245  warning += " Please update and use Physics/"+core_physics_name+"/material.\n";
246  grins_warning(warning);
247 
248  params.set_parameter
249  (cp, input,
250  "Physics/"+core_physics_name+"/Cp", 1.0 /*default*/);
251  }
252  }
253 
254  // It's deprecated to use Cp as the specific heat input
255  if( input.have_variable("Physics/"+core_physics_name+"/Cp") )
256  {
257  MaterialsParsing::dep_input_warning( "Physics/"+core_physics_name+"/Cp",
258  "SpecificHeat/value" );
259 
260  params.set_parameter
261  (cp, input,
262  "Physics/"+core_physics_name+"/Cp", 1.0 /*default*/);
263  }
264 
265  // This is the preferred version
266  if( input.have_variable("Physics/"+core_physics_name+"/material") &&
267  input.have_variable("Materials/"+material+"/SpecificHeat/value") )
268  {
269  // This function only supports reading a constant
270  if( input("Materials/"+material+"/SpecificHeat/model", "DIE!") !=
271  std::string("constant") )
272  libmesh_error_msg("ERROR: Only constant SpecificHeat model supported!");
273 
274  params.set_parameter
275  (cp, input,
276  "Materials/"+material+"/SpecificHeat/value", 0.0 /*default*/);
277  }
278 
279  // Let's make sure we actually got a valid density value
280  if( cp <= 0.0 )
281  {
282  libmesh_error_msg("ERROR: Detected non-positive value of cp!");
283  }
284  }
285 
286  void MaterialsParsing::read_property( const GetPot& input,
287  const std::string& old_option,
288  const std::string& property,
289  const std::string& core_physics,
290  ParameterUser& param_user,
291  libMesh::Real& value )
292  {
293  std::string material = MaterialsParsing::material_name(input,core_physics);
294 
295  // Can't specify both old_option and property
297  old_option,
298  "Materials/"+material+"/"+property+"/value" );
299 
300  // Deprecated
301  if( input.have_variable(old_option) )
302  {
303  MaterialsParsing::dep_input_warning( old_option,property+"/value" );
304 
305  param_user.set_parameter(value, input, old_option, 0.0 /*default*/);
306  }
307  // Preferred
308  else if( input.have_variable("Materials/"+material+"/"+property+"/value" ) )
309  {
310  param_user.set_parameter
311  (value, input, "Materials/"+material+"/"+property+"/value", 0.0 /*default*/);
312  }
313  // If nothing was set, that's an error
314  else
315  {
316  libmesh_error_msg("ERROR: No valid input found for "+property+"!");
317  }
318 
319  // Make sure value is positive
320  if( value <= 0.0 )
321  {
322  libmesh_error_msg("ERROR: Detected non-positive "+property+"!");
323  }
324  }
325 
326  void MaterialsParsing::parse_chemical_species( const GetPot& input,
327  const std::string& material,
328  std::vector<std::string>& species_names )
329  {
330  // Clear out anything the user might've put in there.
331  species_names.clear();
332 
334  "Physics/Chemistry/species",
335  "Materials/"+material+"/GasMixture/species");
336 
337  std::string species_input;
338  if( input.have_variable("Physics/Chemistry/species") )
339  {
340  MaterialsParsing::dep_input_warning("Physics/Chemistry/species","GasMixture/species");
341  species_input = "Physics/Chemistry/species";
342  }
343  else if( input.have_variable("Materials/"+material+"/GasMixture/species") )
344  {
345  species_input = "Materials/"+material+"/GasMixture/species";
346  }
347  else
348  {
349  libmesh_error_msg("ERROR: Valid input for species not found!");
350  }
351 
352  // Read variable naming info
353  unsigned int n_species = input.vector_variable_size(species_input);
354 
355  species_names.reserve(n_species);
356  for( unsigned int i = 0; i < n_species; i++ )
357  {
360  species_names.push_back( input( species_input, "DIE!", i ) );
361  }
362  }
363 
364  void MaterialsParsing::parse_species_varnames( const GetPot& input,
365  const std::string& material,
366  const std::string& prefix,
367  std::vector<std::string>& species_varnames )
368  {
369  std::vector<std::string> species_names;
370  MaterialsParsing::parse_chemical_species(input,material,species_names);
371  unsigned int n_species = species_names.size();
372  species_varnames.reserve(n_species);
373 
374  for( unsigned int i = 0; i < n_species; i++ )
375  {
376  std::string var_name = prefix+species_names[i];
377  species_varnames.push_back(var_name);
378  }
379  }
380 
381  libMesh::Real MaterialsParsing::parse_lewis_number( const GetPot& input,
382  const std::string& material )
383  {
384 
385  // Can't specify both old_option and property
387  "Physics/Antioch/Le",
388  "Materials/"+material+"/LewisNumber/value");
389 
390  libMesh::Real Le = 0.0;
391  if( input.have_variable("Physics/Antioch/Le") )
392  {
393  MaterialsParsing::dep_input_warning("Physics/Antioch/Le", "LewisNumber/value" );
394  Le = input("Physics/Antioch/Le", 0.0);
395  }
396  else if( input.have_variable("Materials/"+material+"/LewisNumber/value") )
397  {
398  Le = input("Materials/"+material+"/LewisNumber/value", 0.0);
399  }
400  else
401  {
402  libmesh_error_msg("ERROR: Could not find value input for LewisNumber!");
403  }
404 
405  return Le;
406  }
407 
409  const std::string& material )
410  {
411  // Can't specify both old_option and property
413  "Physics/Chemistry/chem_file",
414  "Materials/"+material+"/GasMixture/kinetics_data");
415 
416  std::string filename;
417  if( input.have_variable("Physics/Chemistry/chem_file") )
418  {
419  MaterialsParsing::dep_input_warning("Physics/Chemistry/chem_file",
420  "GasMixture/kinetics_data" );
421 
422  filename = input("Physics/Chemistry/chem_file","DIE!");
423  }
424  else if( input.have_variable("Materials/"+material+"/GasMixture/kinetics_data") )
425  {
426  filename = input("Materials/"+material+"/GasMixture/kinetics_data", "DIE!");
427  }
428  else
429  {
430  libmesh_error_msg("ERROR: Could not find valid input for kinetics_data!");
431  }
432 
433  return filename;
434  }
435 
436  void MaterialsParsing::dep_input_warning( const std::string& old_option,
437  const std::string& property )
438  {
439  std::string warning = "WARNING: Input option "+old_option+" is DEPRECATED!\n";
440  warning += " Please update to use Materials/MATERIAL_NAME/"+property+"\n";
441  grins_warning(warning);
442  }
443 
444  void MaterialsParsing::duplicate_input_test( const GetPot& input,
445  const std::string& option1,
446  const std::string& option2 )
447  {
448  if( input.have_variable(option1) &&
449  input.have_variable(option2) )
450  {
451  libmesh_error_msg("ERROR: Can't specify both "+option1+" and "+option2+"!");
452  }
453  }
454 
455 } // end namespace GRINS
virtual void set_parameter(libMesh::Number &param_variable, const GetPot &input, const std::string &param_name, libMesh::Number param_default)
Each subclass can simultaneously read a parameter value from.
static void parse_species_varnames(const GetPot &input, const std::string &material, const std::string &prefix, std::vector< std::string > &species_names)
Helper function for parsing the chemical species and setting variable name.
static PhysicsName heat_transfer()
#define grins_warning(message)
Definition: common.h:34
static void viscosity_model(const GetPot &input, const std::string &physics, const std::string &material, std::string &model)
Parse the viscosity model for the given material.
static void stress_strain_model(const GetPot &input, const std::string &, const std::string &material, std::string &model, std::string &strain_energy)
Parse the stress-strain model for the given material.
static void read_density(const std::string &core_physics_name, const GetPot &input, ParameterUser &params, libMesh::Real &rho)
Helper function to reading density from input.
GRINS namespace.
static void turb_viscosity_model(const GetPot &input, const std::string &physics, const std::string &material, std::string &model)
Parse the turbulence viscosity model for the given material.
static void read_specific_heat(const std::string &core_physics_name, const GetPot &input, ParameterUser &params, libMesh::Real &cp)
Helper function to reading scalar specific heat from input.
static libMesh::Real parse_lewis_number(const GetPot &input, const std::string &material)
static void specific_heat_model(const GetPot &input, const std::string &physics, const std::string &material, std::string &model)
Parse the specific heat model for the given material.
ParameterUser base class. Utility methods for subclasses.
static void parse_chemical_species(const GetPot &input, const std::string &material, std::vector< std::string > &species_names)
Helper function for parsing the chemical species.
static void dep_input_warning(const std::string &old_option, const std::string &property)
Helper function for parsing/maintaing backward compatibility.
static PhysicsName incompressible_navier_stokes()
static std::string parse_chemical_kinetics_datafile_name(const GetPot &input, const std::string &material)
static void duplicate_input_test(const GetPot &input, const std::string &option1, const std::string &option2)
Helper function for parsing/maintaing backward compatibility.
static void read_property(const GetPot &input, const std::string &old_option, const std::string &property, const std::string &core_physics, ParameterUser &param_user, libMesh::Real &value)
Helper function for parsing/maintaing backward compatibility.
static std::string material_name(const GetPot &input, const std::string &physics)
Get the name of the material in the Physics/physics section.
static bool have_material(const GetPot &input, const std::string &physics)
Check if Physics/physics section has a material variable.
static void thermal_conductivity_model(const GetPot &input, const std::string &physics, const std::string &material, std::string &model)
Parse the conductivity model for the given material.

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