GRINS-0.6.0
axisym_reacting_low_mach_regression.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2015 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 #include "grins_config.h"
26 
27 #include <iostream>
28 
29 // GRINS
30 #include "grins/simulation.h"
32 
33 // libMesh
34 #include "libmesh/parallel.h"
35 #include "libmesh/exact_solution.h"
36 
37 // Function for getting initial temperature field
38 libMesh::Real
39 initial_values( const libMesh::Point& p, const libMesh::Parameters &params,
40  const std::string& system_name, const std::string& unknown_name );
41 
42 int run( int argc, char* argv[], const GetPot& input, GetPot& command_line );
43 
44 void test_error_norm( libMesh::ExactSolution& exact_sol,
45  const std::string& system_name,
46  const std::string& var,
47  const std::string& norm,
48  const double tol,
49  int& return_flag );
50 
51 int main(int argc, char* argv[])
52 {
53  GetPot command_line(argc,argv);
54 
55  if( !command_line.have_variable("input") )
56  {
57  std::cerr << "ERROR: Must specify input file on command line with input=<file>." << std::endl;
58  exit(1);
59  }
60 
61  if( !command_line.have_variable("soln-data") )
62  {
63  std::cerr << "ERROR: Must specify solution data on command line with soln-data=<file>." << std::endl;
64  exit(1);
65  }
66 
67  if( !command_line.have_variable("vars") )
68  {
69  std::cerr << "ERROR: Must specify variables on command line with vars='var1 var2'" << std::endl;
70  exit(1);
71  }
72 
73  if( !command_line.have_variable("norms") )
74  {
75  std::cerr << "ERROR: Must specify error norms on command line with norms='L2 H1'" << std::endl;
76  exit(1);
77  }
78 
79  if( !command_line.have_variable("tol") )
80  {
81  std::cerr << "ERROR: Must specify test tolerance on command line with tol=<tol>" << std::endl;
82  exit(1);
83  }
84 
85  // libMesh input file should be first argument
86  std::string libMesh_input_filename = command_line("input", "DIE!");
87 
88  {
89  std::ifstream i(libMesh_input_filename.c_str());
90  if (!i)
91  {
92  std::cerr << "Error: Could not read from libMesh input file "
93  << libMesh_input_filename << std::endl;
94  exit(1);
95  }
96  }
97 
98  // Create our GetPot object.
99  GetPot libMesh_inputfile( libMesh_input_filename );
100 
101  int return_flag = 0;
102 
103  std::string chem_lib = libMesh_inputfile("Physics/ReactingLowMachNavierStokes/thermochemistry_library", "DIE!");
104 
105  if( chem_lib == std::string("cantera") )
106  {
107 #ifdef GRINS_HAVE_CANTERA
108  return_flag = run(argc,argv,libMesh_inputfile,command_line);
109 #else
110  return_flag = 77;
111 #endif
112  }
113  else if( chem_lib == std::string("antioch") )
114  {
115 #ifdef GRINS_HAVE_ANTIOCH
116  return_flag = run(argc,argv,libMesh_inputfile,command_line);
117 #else
118  return_flag = 77;
119 #endif
120  }
121  else
122  {
123  return_flag = 1;
124  }
125 
126  return return_flag;
127 }
128 
129 int run( int argc, char* argv[], const GetPot& input, GetPot& command_line )
130 {
131  // Initialize libMesh library.
132  libMesh::LibMeshInit libmesh_init(argc, argv);
133 
134  GRINS::SimulationBuilder sim_builder;
135 
136  GRINS::Simulation grins( input,
137  sim_builder,
138  libmesh_init.comm() );
139 
140  //FIXME: We need to move this to within the Simulation object somehow...
141  std::string restart_file = input( "restart-options/restart_file", "none" );
142 
143  if( restart_file == "none" )
144  {
145  // Asssign initial temperature value
146  std::string system_name = input( "screen-options/system_name", "GRINS" );
147  std::tr1::shared_ptr<libMesh::EquationSystems> es = grins.get_equation_system();
148  const libMesh::System& system = es->get_system(system_name);
149 
150  libMesh::Parameters &params = es->parameters;
151 
152  libMesh::Real& w_N2 = params.set<libMesh::Real>( "w_N2" );
153  w_N2 = input( "Physics/ReactingLowMachNavierStokes/bound_species_0", 0.0, 0.0 );
154 
155  libMesh::Real& w_N = params.set<libMesh::Real>( "w_N" );
156  w_N = input( "Physics/ReactingLowMachNavierStokes/bound_species_0", 0.0, 1.0 );
157 
158  system.project_solution( initial_values, NULL, params );
159  }
160 
161  grins.run();
162 
163  // Get equation systems to create ExactSolution object
164  std::tr1::shared_ptr<libMesh::EquationSystems> es = grins.get_equation_system();
165 
166  // Create Exact solution object and attach exact solution quantities
167  libMesh::ExactSolution exact_sol(*es);
168 
169  libMesh::EquationSystems es_ref( es->get_mesh() );
170 
171  // Filename of file where comparison solution is stashed
172  std::string solution_file = command_line("soln-data", "DIE!");
173  es_ref.read( solution_file );
174 
175  exact_sol.attach_reference_solution( &es_ref );
176 
177  // Now grab the variables for which we want to compare
178  unsigned int n_vars = command_line.vector_variable_size("vars");
179  std::vector<std::string> vars(n_vars);
180  for( unsigned int v = 0; v < n_vars; v++ )
181  {
182  vars[v] = command_line("vars", "DIE!", v);
183  }
184 
185  // Now grab the norms to compute for each variable error
186  unsigned int n_norms = command_line.vector_variable_size("norms");
187  std::vector<std::string> norms(n_norms);
188  for( unsigned int n = 0; n < n_norms; n++ )
189  {
190  norms[n] = command_line("norms", "DIE!", n);
191  if( norms[n] != std::string("L2") &&
192  norms[n] != std::string("H1") )
193  {
194  std::cerr << "ERROR: Invalid norm input " << norms[n] << std::endl
195  << " Valid values are: L2" << std::endl
196  << " H1" << std::endl;
197  }
198  }
199 
200  const std::string& system_name = grins.get_multiphysics_system_name();
201 
202  // Now compute error for each variable
203  for( unsigned int v = 0; v < n_vars; v++ )
204  {
205  exact_sol.compute_error(system_name, vars[v]);
206  }
207 
208  int return_flag = 0;
209 
210  double tol = command_line("tol", 1.0e-10);
211 
212  // Now test error for each variable, for each norm
213  for( unsigned int v = 0; v < n_vars; v++ )
214  {
215  for( unsigned int n = 0; n < n_norms; n++ )
216  {
217  test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
218  }
219  }
220 
221  return return_flag;
222 }
223 
224 libMesh::Real
225 initial_values( const libMesh::Point& p, const libMesh::Parameters &params,
226  const std::string& , const std::string& unknown_name )
227 {
228  libMesh::Real value = 0.0;
229 
230  if( unknown_name == "w_N2" )
231  value = params.get<libMesh::Real>("w_N2");
232 
233  else if( unknown_name == "w_N" )
234  value = params.get<libMesh::Real>("w_N");
235 
236  else if( unknown_name == "T" )
237  value = 300;
238 
239  else if( unknown_name == "u" )
240  {
241  const libMesh::Real x = p(0);
242  value = 1.0*(-x*x+1);
243  }
244 
245  else
246  value = 0.0;
247 
248  return value;
249 }
250 
251 void test_error_norm( libMesh::ExactSolution& exact_sol,
252  const std::string& system_name,
253  const std::string& var,
254  const std::string& norm,
255  const double tol,
256  int& return_flag )
257 {
258  // We don't set return_flag unless we are setting it 1
259  // since this function gets called multiple times and we don't
260  // want to overwrite a previous "fail" (return_flag = 1) with
261  // a "pass" (return_flag = 0)
262 
263  double error = 0.0;
264 
265  std::cout << "==========================================================" << std::endl
266  << "Checking variable " << var << " using error norm " << norm << " with tol " << tol << "...";
267 
268  if( norm == std::string("L2") )
269  {
270  error = exact_sol.l2_error(system_name, var);
271  }
272  else if( norm == std::string("H1") )
273  {
274  error = exact_sol.h1_error(system_name, var);
275  }
276  else
277  {
278  std::cerr << "ERROR: Invalid norm " << norm << std::endl;
279  exit(1);
280  }
281 
282  if( error > tol )
283  {
284  return_flag = 1;
285 
286  std::cerr << "Tolerance exceeded for generic regression test!" << std::endl
287  << "tolerance = " << tol << std::endl
288  << "norm of error = " << error << std::endl
289  << "norm type = " << norm << std::endl
290  << "var = " << var << std::endl;
291  }
292  else
293  {
294  std::cout << "PASSED!" << std::endl
295  << "==========================================================" << std::endl;
296  }
297 
298  return;
299 }
libMesh::Real initial_values(const libMesh::Point &p, const libMesh::Parameters &params, const std::string &system_name, const std::string &unknown_name)
int run(int argc, char *argv[], const GetPot &input, GetPot &command_line)
int main(int argc, char *argv[])
void test_error_norm(libMesh::ExactSolution &exact_sol, const std::string &system_name, const std::string &var, const std::string &norm, const double tol, int &return_flag)

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1