GRINS-0.6.0
Classes | Functions
test_turbulent_channel.C File Reference
#include "grins_config.h"
#include <iostream>
#include "grins/mesh_builder.h"
#include "grins/simulation.h"
#include "grins/simulation_builder.h"
#include "grins/multiphysics_sys.h"
#include "grins/parabolic_profile.h"
#include "libmesh/dirichlet_boundaries.h"
#include "libmesh/dof_map.h"
#include "libmesh/fe_base.h"
#include "libmesh/fe_interface.h"
#include "libmesh/mesh_function.h"
#include "libmesh/serial_mesh.h"
#include "libmesh/edge_edge2.h"
#include "libmesh/mesh_generation.h"
#include "libmesh/linear_implicit_system.h"
#include "libmesh/gmv_io.h"
#include "libmesh/exact_solution.h"
Include dependency graph for test_turbulent_channel.C:

Go to the source code of this file.

Classes

class  TurbulentBCFactory
 
class  TurbulentBdyFunctionU
 
class  TurbulentBdyFunctionNu
 

Functions

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)
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 169 of file test_turbulent_channel.C.

References GRINS::SimulationBuilder::attach_bc_factory(), GRINS::Simulation::run(), and test_error_norm().

170 {
171 
172 #ifdef GRINS_USE_GRVY_TIMERS
173  GRVY::GRVY_Timer_Class grvy_timer;
174  grvy_timer.Init("GRINS Timer");
175 #endif
176 
177  // Check command line count.
178  if( argc < 2 )
179  {
180  // TODO: Need more consistent error handling.
181  std::cerr << "Error: Must specify libMesh input file." << std::endl;
182  exit(1); // TODO: something more sophisticated for parallel runs?
183  }
184 
185  // libMesh input file should be first argument
186  std::string libMesh_input_filename = argv[1];
187 
188  // Create our GetPot object.
189  GetPot libMesh_inputfile( libMesh_input_filename );
190 
191 #ifdef GRINS_USE_GRVY_TIMERS
192  grvy_timer.BeginTimer("Initialize Solver");
193 #endif
194 
195  // Initialize libMesh library.
196  libMesh::LibMeshInit libmesh_init(argc, argv);
197 
198  // Build a 1-d turbulent_bc_system to get the bc data from files
199  libMesh::SerialMesh mesh(libmesh_init.comm());
200 
201  GetPot command_line(argc,argv);
202 
203  std::string oned_mesh = command_line("mesh-1d", "DIE!");
204  mesh.read(oned_mesh);
205 
206  // And an EquationSystems to run on it
207  libMesh::EquationSystems equation_systems (mesh);
208 
209  std::string oned_data = command_line("data-1d", "DIE!");
210  equation_systems.read(oned_data, libMesh::XdrMODE::READ,
211  libMesh::EquationSystems::READ_HEADER |
212  libMesh::EquationSystems::READ_DATA |
213  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
214 
215  // Get a reference to the system so that we can call update() on it
216  libMesh::System & turbulent_bc_system = equation_systems.get_system<libMesh::System>("flow");
217 
218  // We need to call update to put system in a consistent state
219  // with the solution that was read in
220  turbulent_bc_system.update();
221 
222  // Print information about the system to the screen.
223  equation_systems.print_info();
224 
225  // Prepare a global solution and a MeshFunction of the Turbulent system
226  libMesh::AutoPtr<libMesh::MeshFunction> turbulent_bc_values;
227 
228  libMesh::AutoPtr<libMesh::NumericVector<libMesh::Number> > turbulent_bc_soln = libMesh::NumericVector<libMesh::Number>::build(equation_systems.comm());
229 
230  std::vector<libMesh::Number> flow_soln;
231 
232  turbulent_bc_system.update_global_solution(flow_soln);
233 
234  turbulent_bc_soln->init(turbulent_bc_system.solution->size(), true, libMesh::SERIAL);
235 
236  (*turbulent_bc_soln) = flow_soln;
237 
238  std::vector<unsigned int>turbulent_bc_system_variables;
239  turbulent_bc_system_variables.push_back(0);
240  turbulent_bc_system_variables.push_back(1);
241 
242  turbulent_bc_values = libMesh::AutoPtr<libMesh::MeshFunction>
243  (new libMesh::MeshFunction(equation_systems,
244  *turbulent_bc_soln,
245  turbulent_bc_system.get_dof_map(),
246  turbulent_bc_system_variables ));
247 
248  turbulent_bc_values->init();
249 
250  GRINS::SimulationBuilder sim_builder;
251 
252  std::tr1::shared_ptr<TurbulentBCFactory> bc_factory( new TurbulentBCFactory(turbulent_bc_values.get()) );
253 
254  sim_builder.attach_bc_factory(bc_factory);
255 
256  GRINS::Simulation grins( libMesh_inputfile,
257  sim_builder,
258  libmesh_init.comm() );
259 
260 #ifdef GRINS_USE_GRVY_TIMERS
261  grvy_timer.EndTimer("Initialize Solver");
262 
263  // Attach GRVY timer to solver
264  grins.attach_grvy_timer( &grvy_timer );
265 #endif
266 
267  // Solve
268  grins.run();
269 
270 // Get equation systems to create ExactSolution object
271  std::tr1::shared_ptr<libMesh::EquationSystems> es = grins.get_equation_system();
272 
273  // Create Exact solution object and attach exact solution quantities
274  //libMesh::ExactSolution exact_sol(*es);
275 
276  // Create Exact solution object and attach exact solution quantities
277  libMesh::ExactSolution exact_sol(*es);
278 
279  libMesh::EquationSystems es_ref( es->get_mesh() );
280 
281  // Filename of file where comparison solution is stashed
282  std::string solution_file = command_line("soln-data", "DIE!");
283  es_ref.read( solution_file );
284 
285  exact_sol.attach_reference_solution( &es_ref );
286 
287  // Now grab the variables for which we want to compare
288  unsigned int n_vars = command_line.vector_variable_size("vars");
289  std::vector<std::string> vars(n_vars);
290  for( unsigned int v = 0; v < n_vars; v++ )
291  {
292  vars[v] = command_line("vars", "DIE!", v);
293  }
294 
295  // Now grab the norms to compute for each variable error
296  unsigned int n_norms = command_line.vector_variable_size("norms");
297  std::vector<std::string> norms(n_norms);
298  for( unsigned int n = 0; n < n_norms; n++ )
299  {
300  norms[n] = command_line("norms", "DIE!", n);
301  if( norms[n] != std::string("L2") &&
302  norms[n] != std::string("H1") )
303  {
304  std::cerr << "ERROR: Invalid norm input " << norms[n] << std::endl
305  << " Valid values are: L2" << std::endl
306  << " H1" << std::endl;
307  }
308  }
309 
310  const std::string& system_name = grins.get_multiphysics_system_name();
311 
312  // Now compute error for each variable
313  for( unsigned int v = 0; v < n_vars; v++ )
314  {
315  exact_sol.compute_error(system_name, vars[v]);
316  }
317 
318  int return_flag = 0;
319 
320  double tol = command_line("tol", 1.0e-10);
321 
322  // Now test error for each variable, for each norm
323  for( unsigned int v = 0; v < n_vars; v++ )
324  {
325  for( unsigned int n = 0; n < n_norms; n++ )
326  {
327  test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
328  }
329  }
330 
331  return return_flag;
332 }
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)
void attach_bc_factory(std::tr1::shared_ptr< BoundaryConditionsFactory > bc_factory)
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 
)

Definition at line 334 of file test_turbulent_channel.C.

Referenced by main().

340 {
341  // We don't set return_flag unless we are setting it 1
342  // since this function gets called multiple times and we don't
343  // want to overwrite a previous "fail" (return_flag = 1) with
344  // a "pass" (return_flag = 0)
345 
346  double error = 0.0;
347 
348  std::cout << "==========================================================" << std::endl
349  << "Checking variable " << var << " using error norm " << norm << " with tol " << tol << "...";
350 
351  if( norm == std::string("L2") )
352  {
353  error = exact_sol.l2_error(system_name, var);
354  }
355  else if( norm == std::string("H1") )
356  {
357  error = exact_sol.h1_error(system_name, var);
358  }
359  else
360  {
361  std::cerr << "ERROR: Invalid norm " << norm << std::endl;
362  exit(1);
363  }
364 
365  if( error > tol )
366  {
367  return_flag = 1;
368 
369  std::cerr << "Tolerance exceeded for generic regression test!" << std::endl
370  << "tolerance = " << tol << std::endl
371  << "norm of error = " << error << std::endl
372  << "norm type = " << norm << std::endl
373  << "var = " << var << std::endl;
374  }
375  else
376  {
377  std::cout << "PASSED!" << std::endl
378  << "==========================================================" << std::endl;
379  }
380 
381  return;
382 }

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