GRINS-0.6.0
suspended_cable_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
31 #include "grins/simulation.h"
32 #include "grins/math_constants.h"
33 
34 // libMesh
35 #include "libmesh/parallel.h"
36 #include "libmesh/exact_solution.h"
37 
38 // GRVY
39 #ifdef GRINS_HAVE_GRVY
40 #include "grvy.h"
41 #endif
42 
43 // SuspendedCable
44 //#include "suspended_cable_solver_factory.h"
45 
46 // Function for getting initial temperature field
47 libMesh::Real initial_values( const libMesh::Point& p, const libMesh::Parameters &params,
48  const std::string& system_name, const std::string& unknown_name );
49 
50 int main(int argc, char* argv[])
51 {
52 #ifdef GRINS_USE_GRVY_TIMERS
53  GRVY::GRVY_Timer_Class grvy_timer;
54  grvy_timer.Init("GRINS Timer");
55 #endif
56  // Check command line count.
57  if( argc < 3 )
58  {
59  // TODO: Need more consistent error handling.
60  std::cerr << "Error: Must specify libMesh input file." << std::endl;
61  exit(1); // TODO: something more sophisticated for parallel runs?
62  }
63 
64  // libMesh input file should be first argument
65  std::string libMesh_input_filename = argv[1];
66 
67  // Create our GetPot object.
68  GetPot libMesh_inputfile( libMesh_input_filename );
69 
70  // GetPot doesn't throw an error for a nonexistent file?
71  {
72  std::ifstream i(libMesh_input_filename.c_str());
73  if (!i)
74  {
75  std::cerr << "Error: Could not read from libMesh input file "
76  << libMesh_input_filename << std::endl;
77  exit(1);
78  }
79  }
80 
81  // Initialize libMesh library.
82  libMesh::LibMeshInit libmesh_init(argc, argv);
83 
84  libMesh::out << "Starting GRINS with command:\n";
85  for (int i=0; i != argc; ++i)
86  libMesh::out << argv[i] << ' ';
87  libMesh::out << std::endl;
88 
89  GRINS::SimulationBuilder sim_builder;
90 
91  GRINS::Simulation grins( libMesh_inputfile,
92  sim_builder,
93  libmesh_init.comm() );
94 
95  std::string system_name = libMesh_inputfile( "screen-options/system_name", "GRINS" );
96 
97  // Get equation systems
98  std::tr1::shared_ptr<libMesh::EquationSystems> es = grins.get_equation_system();
99  const libMesh::System& system = es->get_system(system_name);
100 
101  libMesh::Parameters &params = es->parameters;
102 
103  system.project_solution( initial_values, NULL, params );
104 
105  grins.run();
106 
107  //es->write("suspended_cable_test.xdr");
108 
109  // Create Exact solution object and attach exact solution quantities
110  libMesh::ExactSolution exact_sol(*es);
111 
112  libMesh::EquationSystems es_ref( es->get_mesh() );
113 
114  // Filename of file where comparison solution is stashed
115  std::string solution_file = std::string(argv[2]);
116  es_ref.read( solution_file );
117 
118  exact_sol.attach_reference_solution( &es_ref );
119 
120  // Compute error and get it in various norms
121  exact_sol.compute_error(system_name, "u");
122  exact_sol.compute_error(system_name, "v");
123  exact_sol.compute_error(system_name, "w");
124 
125  double u_l2error = exact_sol.l2_error(system_name, "u");
126  double u_h1error = exact_sol.h1_error(system_name, "u");
127 
128  double v_l2error = exact_sol.l2_error(system_name, "v");
129  double v_h1error = exact_sol.h1_error(system_name, "v");
130 
131  double w_l2error = exact_sol.l2_error(system_name, "w");
132  double w_h1error = exact_sol.h1_error(system_name, "w");
133 
134  int return_flag = 0;
135 
136  double tol = 5.0e-8;
137 
138  if( u_l2error > tol || u_h1error > tol ||
139  v_l2error > tol || v_h1error > tol ||
140  w_l2error > tol || w_h1error > tol )
141  {
142  return_flag = 1;
143 
144  std::cout << "Tolerance exceeded for suspended cable test." << std::endl
145  << "tolerance = " << tol << std::endl
146  << "u l2 error = " << u_l2error << std::endl
147  << "u h1 error = " << u_h1error << std::endl
148  << "v l2 error = " << v_l2error << std::endl
149  << "v h1 error = " << v_h1error << std::endl
150  << "w l2 error = " << w_l2error << std::endl
151  << "w h1 error = " << w_h1error << std::endl;
152  }
153 
154  return return_flag;
155 }
156 
157 libMesh::Real initial_values( const libMesh::Point& p, const libMesh::Parameters &/*params*/,
158  const std::string& , const std::string& unknown_name )
159 {
160  libMesh::Real value = 0.0;
161 
162 
163  if( unknown_name == "u" )
164  {
165  value = -35*sin(GRINS::Constants::pi*p(0)/400.0);
166  }
167  else if( unknown_name == "w" )
168  {
169  value = -55*sin(GRINS::Constants::pi*p(0)/200.0);
170  }
171  else
172  {
173  value = 0.0;
174  }
175 
176  return value;
177 }
const libMesh::Real pi
libMesh::Real initial_values(const libMesh::Point &p, const libMesh::Parameters &params, const std::string &system_name, const std::string &unknown_name)
int main(int argc, char *argv[])

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