GRINS-0.8.0
Classes | Namespaces | Functions
test_turbulent_channel.C File Reference
#include "grins_config.h"
#include <iostream>
#include "grins/runner.h"
#include "grins/mesh_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[])
 

Function Documentation

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

Definition at line 232 of file test_turbulent_channel.C.

References GRINS::Runner::get_command_line(), GRINS::Simulation::get_equation_system(), GRINS::Runner::get_input_file(), GRINS::Runner::get_libmesh_init(), GRINS::Simulation::get_multiphysics_system_name(), GRINS::Runner::get_simulation(), GRINS::Runner::init(), GRINS::Runner::run(), GRINSTesting::SATurbBCFactoryBase::set_turb_bc_values(), and test_error_norm().

233 {
234  // Factories needed for run
235  GRINSTesting::SATurbUBCFactory grins_factory_testing_turb_u_bc("testing_turb_u");
236  GRINSTesting::SATurbNuBCFactory grins_factory_testing_turb_nu_bc("testing_turb_nu");
237 
238  // Need only
239  GRINS::Runner grins(argc,argv);
240 
241  const GetPot & command_line = grins.get_command_line();
242 
243  const GetPot & inputfile = grins.get_input_file();
244 
245  // Don't flag our command-line-specific variables as UFOs later
246  inputfile.have_variable("mesh-1d");
247  inputfile.have_variable("data-1d");
248  inputfile.have_variable("soln-data");
249  inputfile.have_variable("vars");
250  inputfile.have_variable("norms");
251  inputfile.have_variable("tol");
252 
253  const libMesh::LibMeshInit & libmesh_init = grins.get_libmesh_init();
254 
255  // Build a 1-d turbulent_bc_system to get the bc data from files
256  libMesh::SerialMesh mesh(libmesh_init.comm());
257 
258  std::string oned_mesh = command_line("mesh-1d", "DIE!");
259  mesh.read(oned_mesh);
260 
261  // And an EquationSystems to run on it
262  libMesh::EquationSystems equation_systems (mesh);
263 
264  std::string oned_data = command_line("data-1d", "DIE!");
265  equation_systems.read(oned_data, libMesh::XdrMODE::READ,
266  libMesh::EquationSystems::READ_HEADER |
267  libMesh::EquationSystems::READ_DATA |
268  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
269 
270  // Get a reference to the system so that we can call update() on it
271  libMesh::System & turbulent_bc_system = equation_systems.get_system<libMesh::System>("flow");
272 
273  // We need to call update to put system in a consistent state
274  // with the solution that was read in
275  turbulent_bc_system.update();
276 
277  // Print information about the system to the screen.
278  equation_systems.print_info();
279 
280  // Prepare a global solution and a MeshFunction of the Turbulent system
281  libMesh::UniquePtr<libMesh::MeshFunction> turbulent_bc_values;
282 
283  libMesh::UniquePtr<libMesh::NumericVector<libMesh::Number> > turbulent_bc_soln = libMesh::NumericVector<libMesh::Number>::build(equation_systems.comm());
284 
285  std::vector<libMesh::Number> flow_soln;
286 
287  turbulent_bc_system.update_global_solution(flow_soln);
288 
289  turbulent_bc_soln->init(turbulent_bc_system.solution->size(), true, libMesh::SERIAL);
290 
291  (*turbulent_bc_soln) = flow_soln;
292 
293  std::vector<unsigned int>turbulent_bc_system_variables;
294  turbulent_bc_system_variables.push_back(0);
295  turbulent_bc_system_variables.push_back(1);
296 
297  turbulent_bc_values = libMesh::UniquePtr<libMesh::MeshFunction>
298  (new libMesh::MeshFunction(equation_systems,
299  *turbulent_bc_soln,
300  turbulent_bc_system.get_dof_map(),
301  turbulent_bc_system_variables ));
302 
303  turbulent_bc_values->init();
304 
305  GRINSTesting::SATurbBCFactoryBase::set_turb_bc_values( turbulent_bc_values.get() );
306 
307  // Initialize
308  grins.init();
309 
310  // Solve
311  grins.run();
312 
313  GRINS::Simulation & sim = grins.get_simulation();
314 
315  // Get equation systems to create ExactSolution object
316  GRINS::SharedPtr<libMesh::EquationSystems> es = sim.get_equation_system();
317 
318  // Create Exact solution object and attach exact solution quantities
319  //libMesh::ExactSolution exact_sol(*es);
320 
321  // Create Exact solution object and attach exact solution quantities
322  libMesh::ExactSolution exact_sol(*es);
323 
324  libMesh::EquationSystems es_ref( es->get_mesh() );
325 
326  // Filename of file where comparison solution is stashed
327  std::string solution_file = command_line("soln-data", "DIE!");
328  es_ref.read( solution_file, libMesh::XdrMODE::DECODE,
329  libMesh::EquationSystems::READ_HEADER |
330  libMesh::EquationSystems::READ_DATA |
331  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
332 
333  exact_sol.attach_reference_solution( &es_ref );
334 
335  // Now grab the variables for which we want to compare
336  unsigned int n_vars = command_line.vector_variable_size("vars");
337  std::vector<std::string> vars(n_vars);
338  for( unsigned int v = 0; v < n_vars; v++ )
339  {
340  vars[v] = command_line("vars", "DIE!", v);
341  }
342 
343  // Now grab the norms to compute for each variable error
344  unsigned int n_norms = command_line.vector_variable_size("norms");
345  std::vector<std::string> norms(n_norms);
346  for( unsigned int n = 0; n < n_norms; n++ )
347  {
348  norms[n] = command_line("norms", "DIE!", n);
349  if( norms[n] != std::string("L2") &&
350  norms[n] != std::string("H1") )
351  {
352  std::cerr << "ERROR: Invalid norm input " << norms[n] << std::endl
353  << " Valid values are: L2" << std::endl
354  << " H1" << std::endl;
355  }
356  }
357 
358  const std::string& system_name = sim.get_multiphysics_system_name();
359 
360  // Now compute error for each variable
361  for( unsigned int v = 0; v < n_vars; v++ )
362  {
363  exact_sol.compute_error(system_name, vars[v]);
364  }
365 
366  int return_flag = 0;
367 
368  double tol = command_line("tol", 1.0e-10);
369 
370  // Now test error for each variable, for each norm
371  for( unsigned int v = 0; v < n_vars; v++ )
372  {
373  for( unsigned int n = 0; n < n_norms; n++ )
374  {
375  test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
376  }
377  }
378 
379  return return_flag;
380 }
SharedPtr< libMesh::EquationSystems > get_equation_system()
Definition: simulation.C:393
const std::string & get_multiphysics_system_name() const
Definition: simulation.h:185
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)
Class to encapsulate initializing and running GRINS Simulation.
Definition: runner.h:47
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 382 of file test_turbulent_channel.C.

Referenced by main().

388 {
389  // We don't set return_flag unless we are setting it 1
390  // since this function gets called multiple times and we don't
391  // want to overwrite a previous "fail" (return_flag = 1) with
392  // a "pass" (return_flag = 0)
393 
394  double error = 0.0;
395 
396  std::cout << "==========================================================" << std::endl
397  << "Checking variable " << var << " using error norm " << norm << " with tol " << tol << "...";
398 
399  if( norm == std::string("L2") )
400  {
401  error = exact_sol.l2_error(system_name, var);
402  }
403  else if( norm == std::string("H1") )
404  {
405  error = exact_sol.h1_error(system_name, var);
406  }
407  else
408  {
409  std::cerr << "ERROR: Invalid norm " << norm << std::endl;
410  exit(1);
411  }
412 
413  if( error > tol )
414  {
415  return_flag = 1;
416 
417  std::cerr << "Tolerance exceeded for generic regression test!" << std::endl
418  << "tolerance = " << tol << std::endl
419  << "norm of error = " << error << std::endl
420  << "norm type = " << norm << std::endl
421  << "var = " << var << std::endl;
422  }
423  else
424  {
425  std::cout << "PASSED!" << std::endl
426  << "==========================================================" << std::endl;
427  }
428 
429  return;
430 }

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