GRINS-0.7.0
Classes | Namespaces | Functions | Variables
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/dirichlet_bc_factory_function_old_style_base.h"
#include "grins/var_typedefs.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 "libmesh/zero_function.h"
#include "libmesh/composite_function.h"
Include dependency graph for test_turbulent_channel.C:

Go to the source code of this file.

Classes

class  GRINSTesting::TurbBoundFuncBase
 
class  GRINSTesting::TurbulentBdyFunctionU
 
class  GRINSTesting::TurbulentBdyFunctionNu
 
class  GRINSTesting::SATurbBCFactoryBase
 
class  GRINSTesting::SATurbUBCFactory
 
class  GRINSTesting::SATurbNuBCFactory
 

Namespaces

 GRINS
 GRINS namespace.
 
 GRINSTesting
 

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[])
 

Variables

SATurbUBCFactory GRINSTesting::grins_factory_testing_turb_u_bc ("testing_turb_u")
 
SATurbNuBCFactory GRINSTesting::grins_factory_testing_turb_nu_bc ("testing_turb_nu")
 

Function Documentation

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

Definition at line 241 of file test_turbulent_channel.C.

References GRINS::Simulation::run(), GRINSTesting::SATurbBCFactoryBase::set_turb_bc_values(), and test_error_norm().

242 {
243 
244 #ifdef GRINS_USE_GRVY_TIMERS
245  GRVY::GRVY_Timer_Class grvy_timer;
246  grvy_timer.Init("GRINS Timer");
247 #endif
248 
249  // Check command line count.
250  if( argc < 2 )
251  {
252  // TODO: Need more consistent error handling.
253  std::cerr << "Error: Must specify libMesh input file." << std::endl;
254  exit(1); // TODO: something more sophisticated for parallel runs?
255  }
256 
257  // libMesh input file should be first argument
258  std::string libMesh_input_filename = argv[1];
259 
260  // Create our GetPot object.
261  GetPot libMesh_inputfile( libMesh_input_filename );
262 
263 #ifdef GRINS_USE_GRVY_TIMERS
264  grvy_timer.BeginTimer("Initialize Solver");
265 #endif
266 
267  // Initialize libMesh library.
268  libMesh::LibMeshInit libmesh_init(argc, argv);
269 
270  // Build a 1-d turbulent_bc_system to get the bc data from files
271  libMesh::SerialMesh mesh(libmesh_init.comm());
272 
273  GetPot command_line(argc,argv);
274 
275  std::string oned_mesh = command_line("mesh-1d", "DIE!");
276  mesh.read(oned_mesh);
277 
278  // And an EquationSystems to run on it
279  libMesh::EquationSystems equation_systems (mesh);
280 
281  std::string oned_data = command_line("data-1d", "DIE!");
282  equation_systems.read(oned_data, libMesh::XdrMODE::READ,
283  libMesh::EquationSystems::READ_HEADER |
284  libMesh::EquationSystems::READ_DATA |
285  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
286 
287  // Get a reference to the system so that we can call update() on it
288  libMesh::System & turbulent_bc_system = equation_systems.get_system<libMesh::System>("flow");
289 
290  // We need to call update to put system in a consistent state
291  // with the solution that was read in
292  turbulent_bc_system.update();
293 
294  // Print information about the system to the screen.
295  equation_systems.print_info();
296 
297  // Prepare a global solution and a MeshFunction of the Turbulent system
298  libMesh::UniquePtr<libMesh::MeshFunction> turbulent_bc_values;
299 
300  libMesh::UniquePtr<libMesh::NumericVector<libMesh::Number> > turbulent_bc_soln = libMesh::NumericVector<libMesh::Number>::build(equation_systems.comm());
301 
302  std::vector<libMesh::Number> flow_soln;
303 
304  turbulent_bc_system.update_global_solution(flow_soln);
305 
306  turbulent_bc_soln->init(turbulent_bc_system.solution->size(), true, libMesh::SERIAL);
307 
308  (*turbulent_bc_soln) = flow_soln;
309 
310  std::vector<unsigned int>turbulent_bc_system_variables;
311  turbulent_bc_system_variables.push_back(0);
312  turbulent_bc_system_variables.push_back(1);
313 
314  turbulent_bc_values = libMesh::UniquePtr<libMesh::MeshFunction>
315  (new libMesh::MeshFunction(equation_systems,
316  *turbulent_bc_soln,
317  turbulent_bc_system.get_dof_map(),
318  turbulent_bc_system_variables ));
319 
320  turbulent_bc_values->init();
321 
322  GRINSTesting::SATurbBCFactoryBase::set_turb_bc_values( turbulent_bc_values.get() );
323 
324  GRINS::SimulationBuilder sim_builder;
325 
326  GRINS::Simulation grins( libMesh_inputfile,
327  sim_builder,
328  libmesh_init.comm() );
329 
330 #ifdef GRINS_USE_GRVY_TIMERS
331  grvy_timer.EndTimer("Initialize Solver");
332 
333  // Attach GRVY timer to solver
334  grins.attach_grvy_timer( &grvy_timer );
335 #endif
336 
337  // Solve
338  grins.run();
339 
340 // Get equation systems to create ExactSolution object
341  GRINS::SharedPtr<libMesh::EquationSystems> es = grins.get_equation_system();
342 
343  // Create Exact solution object and attach exact solution quantities
344  //libMesh::ExactSolution exact_sol(*es);
345 
346  // Create Exact solution object and attach exact solution quantities
347  libMesh::ExactSolution exact_sol(*es);
348 
349  libMesh::EquationSystems es_ref( es->get_mesh() );
350 
351  // Filename of file where comparison solution is stashed
352  std::string solution_file = command_line("soln-data", "DIE!");
353  es_ref.read( solution_file, libMesh::XdrMODE::DECODE,
354  libMesh::EquationSystems::READ_HEADER |
355  libMesh::EquationSystems::READ_DATA |
356  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
357 
358  exact_sol.attach_reference_solution( &es_ref );
359 
360  // Now grab the variables for which we want to compare
361  unsigned int n_vars = command_line.vector_variable_size("vars");
362  std::vector<std::string> vars(n_vars);
363  for( unsigned int v = 0; v < n_vars; v++ )
364  {
365  vars[v] = command_line("vars", "DIE!", v);
366  }
367 
368  // Now grab the norms to compute for each variable error
369  unsigned int n_norms = command_line.vector_variable_size("norms");
370  std::vector<std::string> norms(n_norms);
371  for( unsigned int n = 0; n < n_norms; n++ )
372  {
373  norms[n] = command_line("norms", "DIE!", n);
374  if( norms[n] != std::string("L2") &&
375  norms[n] != std::string("H1") )
376  {
377  std::cerr << "ERROR: Invalid norm input " << norms[n] << std::endl
378  << " Valid values are: L2" << std::endl
379  << " H1" << std::endl;
380  }
381  }
382 
383  const std::string& system_name = grins.get_multiphysics_system_name();
384 
385  // Now compute error for each variable
386  for( unsigned int v = 0; v < n_vars; v++ )
387  {
388  exact_sol.compute_error(system_name, vars[v]);
389  }
390 
391  int return_flag = 0;
392 
393  double tol = command_line("tol", 1.0e-10);
394 
395  // Now test error for each variable, for each norm
396  for( unsigned int v = 0; v < n_vars; v++ )
397  {
398  for( unsigned int n = 0; n < n_norms; n++ )
399  {
400  test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
401  }
402  }
403 
404  return return_flag;
405 }
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)
static void set_turb_bc_values(libMesh::MeshFunction *turbulent_bc_values)
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 407 of file test_turbulent_channel.C.

Referenced by main().

413 {
414  // We don't set return_flag unless we are setting it 1
415  // since this function gets called multiple times and we don't
416  // want to overwrite a previous "fail" (return_flag = 1) with
417  // a "pass" (return_flag = 0)
418 
419  double error = 0.0;
420 
421  std::cout << "==========================================================" << std::endl
422  << "Checking variable " << var << " using error norm " << norm << " with tol " << tol << "...";
423 
424  if( norm == std::string("L2") )
425  {
426  error = exact_sol.l2_error(system_name, var);
427  }
428  else if( norm == std::string("H1") )
429  {
430  error = exact_sol.h1_error(system_name, var);
431  }
432  else
433  {
434  std::cerr << "ERROR: Invalid norm " << norm << std::endl;
435  exit(1);
436  }
437 
438  if( error > tol )
439  {
440  return_flag = 1;
441 
442  std::cerr << "Tolerance exceeded for generic regression test!" << std::endl
443  << "tolerance = " << tol << std::endl
444  << "norm of error = " << error << std::endl
445  << "norm type = " << norm << std::endl
446  << "var = " << var << std::endl;
447  }
448  else
449  {
450  std::cout << "PASSED!" << std::endl
451  << "==========================================================" << std::endl;
452  }
453 
454  return;
455 }

Generated on Thu Jun 2 2016 21:52:30 for GRINS-0.7.0 by  doxygen 1.8.10