GRINS-0.6.0
test_thermally_driven_flow.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 
26 #include "grins_config.h"
27 
28 #include <iostream>
29 
30 // GRINS
31 #include "grins/mesh_builder.h"
32 #include "grins/simulation.h"
34 #include "grins/multiphysics_sys.h"
35 
36 //libMesh
37 #include "libmesh/exact_solution.h"
38 
39 // GRVY
40 #ifdef GRINS_HAVE_GRVY
41 #include "grvy.h"
42 #endif
43 
44 namespace GRINS
45 {
47  {
48  public:
49  ThermallyDrivenFlowTestBCFactory( const GetPot& input ): _input(input){};
51 
52  virtual std::map< GRINS::PhysicsName, GRINS::NBCContainer > build_neumann( libMesh::EquationSystems& equation_system );
53  private:
54  const GetPot& _input;
55  };
56 
57  class ZeroFluxBC : public NeumannFuncObj
58  {
59  public:
60 
62  virtual ~ZeroFluxBC(){};
63 
64  virtual libMesh::Point value( const AssemblyContext&, const CachedValues&, const unsigned int )
65  { return libMesh::Point(0.0,0.0,0.0); }
66 
67  virtual libMesh::Point derivative( const AssemblyContext&, const CachedValues&, const unsigned int )
68  { return libMesh::Point(0.0,0.0,0.0); }
69 
70  virtual libMesh::Point derivative( const AssemblyContext&, const CachedValues&,
71  const unsigned int, const VariableIndex )
72  { return libMesh::Point(0.0,0.0,0.0); }
73  };
74 } // namespace GRINS
75 
76 int main(int argc, char* argv[])
77 {
78 #ifdef GRINS_USE_GRVY_TIMERS
79  GRVY::GRVY_Timer_Class grvy_timer;
80  grvy_timer.Init("GRINS Timer");
81 #endif
82 
83  // Check command line count.
84  if( argc < 3 )
85  {
86  // TODO: Need more consistent error handling.
87  std::cerr << "Error: Must specify libMesh input file and solution file." << std::endl;
88  exit(1); // TODO: something more sophisticated for parallel runs?
89  }
90 
91  // libMesh input file should be first argument
92  std::string libMesh_input_filename = argv[1];
93 
94  // Create our GetPot object.
95  GetPot libMesh_inputfile( libMesh_input_filename );
96 
97 #ifdef GRINS_USE_GRVY_TIMERS
98  grvy_timer.BeginTimer("Initialize Solver");
99 #endif
100 
101  // Initialize libMesh library.
102  libMesh::LibMeshInit libmesh_init(argc, argv);
103 
104  GRINS::SimulationBuilder sim_builder;
105 
106  sim_builder.attach_bc_factory( std::tr1::shared_ptr<GRINS::BoundaryConditionsFactory>( new GRINS::ThermallyDrivenFlowTestBCFactory( libMesh_inputfile ) ) );
107 
108  GRINS::Simulation grins( libMesh_inputfile,
109  sim_builder,
110  libmesh_init.comm() );
111 
112 #ifdef GRINS_USE_GRVY_TIMERS
113  grvy_timer.EndTimer("Initialize Solver");
114 
115  // Attach GRVY timer to solver
116  grins.attach_grvy_timer( &grvy_timer );
117 #endif
118 
119  // Do solve here
120  grins.run();
121 
122  // Get equation systems to create ExactSolution object
123  std::tr1::shared_ptr<libMesh::EquationSystems> es = grins.get_equation_system();
124 
125  //es->write("foobar.xdr");
126 
127  // Create Exact solution object and attach exact solution quantities
128  libMesh::ExactSolution exact_sol(*es);
129 
130  libMesh::EquationSystems es_ref( es->get_mesh() );
131 
132  // Filename of file where comparison solution is stashed
133  std::string solution_file = std::string(argv[2]);
134  es_ref.read( solution_file );
135 
136  exact_sol.attach_reference_solution( &es_ref );
137 
138  // Compute error and get it in various norms
139  exact_sol.compute_error("GRINS", "u");
140  exact_sol.compute_error("GRINS", "v");
141 
142  if( (es->get_mesh()).mesh_dimension() == 3 )
143  exact_sol.compute_error("GRINS", "w");
144 
145  exact_sol.compute_error("GRINS", "p");
146  exact_sol.compute_error("GRINS", "T");
147 
148  double u_l2error = exact_sol.l2_error("GRINS", "u");
149  double u_h1error = exact_sol.h1_error("GRINS", "u");
150 
151  double v_l2error = exact_sol.l2_error("GRINS", "v");
152  double v_h1error = exact_sol.h1_error("GRINS", "v");
153 
154  double p_l2error = exact_sol.l2_error("GRINS", "p");
155  double p_h1error = exact_sol.h1_error("GRINS", "p");
156 
157  double T_l2error = exact_sol.l2_error("GRINS", "T");
158  double T_h1error = exact_sol.h1_error("GRINS", "T");
159 
160  double w_l2error = 0.0,
161  w_h1error = 0.0;
162 
163  if( (es->get_mesh()).mesh_dimension() == 3 )
164  {
165  w_l2error = exact_sol.l2_error("GRINS", "w");
166  w_h1error = exact_sol.h1_error("GRINS", "w");
167  }
168 
169  int return_flag = 0;
170 
171  // This is the tolerance of the iterative linear solver so
172  // it's unreasonable to expect anything better than this.
173  double tol = 8.0e-9;
174 
175  if( u_l2error > tol || u_h1error > tol ||
176  v_l2error > tol || v_h1error > tol ||
177  w_l2error > tol || w_h1error > tol ||
178  p_l2error > tol || p_h1error > tol ||
179  T_l2error > tol || T_h1error > tol )
180  {
181  return_flag = 1;
182 
183  std::cout << "Tolerance exceeded for thermally driven flow test." << std::endl
184  << "tolerance = " << tol << std::endl
185  << "u l2 error = " << u_l2error << std::endl
186  << "u h1 error = " << u_h1error << std::endl
187  << "v l2 error = " << v_l2error << std::endl
188  << "v h1 error = " << v_h1error << std::endl
189  << "w l2 error = " << w_l2error << std::endl
190  << "w h1 error = " << w_h1error << std::endl
191  << "p l2 error = " << p_l2error << std::endl
192  << "p h1 error = " << p_h1error << std::endl
193  << "T l2 error = " << T_l2error << std::endl
194  << "T h1 error = " << T_h1error << std::endl;
195  }
196 
197  return return_flag;
198 }
199 
200 
201 std::map< GRINS::PhysicsName, GRINS::NBCContainer > GRINS::ThermallyDrivenFlowTestBCFactory::build_neumann( libMesh::EquationSystems& es )
202 {
203  std::map< std::string, GRINS::NBCContainer > nbcs;
204 
205  /* Hack to work around the fact that we're using this test for the axisymmetric
206  case as well the fact I'm and idiot in the design of the axisymmetric cases. */
207  if( _input("Physics/enabled_physics", "DIE!", 1) != std::string("HeatTransfer") )
208  {
209  // Do nothing.
210  }
211  else
212  {
213  // These are hardcoded for the 2D and 3D tests, *not* the axisymmetric test.
214  const libMesh::System& system = es.get_system("GRINS");
215  const GRINS::VariableIndex T_var = system.variable_number("T");
216 
217  std::tr1::shared_ptr<GRINS::NeumannFuncObj> func( new ZeroFluxBC );
218 
219  GRINS::NBCContainer nbc_container;
220  nbc_container.set_bc_id(0);
221  nbc_container.add_var_func_pair( T_var, func );
222 
223 
224  nbcs.insert( std::pair< std::string, GRINS::NBCContainer >( "HeatTransfer", nbc_container ) );
225  }
226 
227  return nbcs;
228 }
unsigned int VariableIndex
More descriptive name of the type used for variable indices.
Definition: var_typedefs.h:40
virtual libMesh::Point derivative(const AssemblyContext &, const CachedValues &, const unsigned int, const VariableIndex)
If needed, returns the derivative with respect to other variables in the system.
virtual std::map< GRINS::PhysicsName, GRINS::NBCContainer > build_neumann(libMesh::EquationSystems &equation_system)
Builds all Neumann boundary condition function objects needed.
Object for constructing boundary condition function objects.
Definition: bc_factory.h:50
GRINS namespace.
void add_var_func_pair(VariableIndex var, std::tr1::shared_ptr< NeumannFuncObj > func)
Add boundary id and corresponding functor object to be applied on that boundary.
Definition: nbc_container.C:51
Simple helper class to setup general Neumann boundary conditions.
Definition: nbc_container.h:41
virtual libMesh::Point value(const AssemblyContext &, const CachedValues &, const unsigned int)
Returns the value of the implemented Neumann boundary condition.
int main(int argc, char *argv[])
void set_bc_id(BoundaryID bc_id)
Add variable for which this boundary condition is to be applied.
Definition: nbc_container.C:40
virtual libMesh::Point derivative(const AssemblyContext &, const CachedValues &, const unsigned int)
Returns the derivative with respect to the primary variable of the implemented Neumann boundary condi...
Base class for general, non-constant Neumann boundary conditions.
void attach_bc_factory(std::tr1::shared_ptr< BoundaryConditionsFactory > bc_factory)

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