GRINS-0.7.0
steady_mesh_adaptive_solver.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2016 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 // This class
27 
28 // C++
29 #include <iomanip>
30 
31 // GRINS
32 #include "grins/solver_context.h"
33 #include "grins/multiphysics_sys.h"
34 #include "grins/common.h"
35 
36 // libMesh
37 #include "libmesh/error_vector.h"
38 #include "libmesh/steady_solver.h"
39 #include "libmesh/adjoint_refinement_estimator.h"
40 
41 namespace GRINS
42 {
43 
45  : Solver(input),
46  MeshAdaptiveSolverBase( input )
47  {
48  return;
49  }
50 
52  {
53  return;
54  }
55 
57  {
58  libMesh::SteadySolver* time_solver = new libMesh::SteadySolver( *(system) );
59 
60  system->time_solver = libMesh::UniquePtr<libMesh::TimeSolver>( time_solver );
61 
62  return;
63  }
64 
66  {
67  // If we are computing QoI error estimates, we have to be using
68  // the Adjoint Refinement Error Estimator
70  if(context.error_estimator->type() != libMesh::ADJOINT_REFINEMENT)
71  {
72  std::string error_message = "You asked for QoI error estimates but did not use an Adjoint Refinement Error Estimator!\n";
73  error_message += "Please use the ADJOINT_REFINEMENT option for the estimator_type if you want QoI error estimates.\n";
74  std::cout<<error_message<<std::endl;
75  libmesh_error();
76  }
77  }
78 
80  {
81  // Check that our error estimator options are consistent
83 
84  // Mesh and mesh refinement
85  libMesh::MeshBase& mesh = context.equation_system->get_mesh();
86  this->build_mesh_refinement( mesh );
87 
89  std::cout << "==========================================================" << std::endl
91  << " adaptive refinements" << std::endl
92  << "==========================================================" << std::endl;
93 
94  // GRVY timers contained in here (if enabled)
95  for ( unsigned int r_step = 0; r_step < _mesh_adaptivity_options.max_refinement_steps(); r_step++ )
96  {
97  std::cout << "==========================================================" << std::endl
98  << "Adaptive Refinement Step " << r_step << std::endl
99  << "==========================================================" << std::endl;
100 
101  // Solve the forward problem
102  context.system->solve();
103 
104  if( context.output_vis )
105  {
106  context.postprocessing->update_quantities( *(context.equation_system) );
107  context.vis->output( context.equation_system );
108  }
109 
110  // Solve adjoint system
111  if(context.do_adjoint_solve)
112  this->steady_adjoint_solve(context);
113 
114  if(context.output_adjoint)
115  context.vis->output_adjoint(context.equation_system, context.system);
116 
117  if( context.output_residual )
118  {
119  context.vis->output_residual( context.equation_system, context.system );
120  }
121 
122  // Now we construct the data structures for the mesh refinement process
123  libMesh::ErrorVector error;
124  this->estimate_error_for_amr( context, error );
125 
126  // Get the global error estimate if you can and are asked to
128  for(unsigned int i = 0; i != context.system->qoi.size(); i++)
129  {
130  libMesh::AdjointRefinementEstimator* adjoint_ref_error_estimator = libMesh::libmesh_cast_ptr<libMesh::AdjointRefinementEstimator*>( context.error_estimator.get() );
131  std::cout<<"The error estimate for QoI("<<i<<") is: "<<adjoint_ref_error_estimator->get_global_QoI_error_estimate(i)<<std::endl;
132  }
133 
134  // Check for convergence of error
135  bool converged = this->check_for_convergence( context, error );
136 
137  if( converged )
138  {
139  // Break out of adaptive loop
140  std::cout << "==========================================================" << std::endl
141  << "Convergence detected!" << std::endl
142  << "==========================================================" << std::endl;
143  break;
144  }
145  else
146  {
147  // Only bother refining if we're on the last step.
149  {
150  this->perform_amr(context, error);
151 
152  // It's helpful to print the qoi along the way, but only do it if the user
153  // asks for it
154  if( context.print_qoi )
155  this->print_qoi(context,std::cout);
156  }
157  }
158 
159  } // r_step for-loop
160 
161  return;
162  }
163 
165  (SolverContext& context,
166  const libMesh::QoISet& qoi_indices,
167  const libMesh::ParameterVector& parameters_in,
168  libMesh::SensitivityData& sensitivities) const
169  {
170  context.system->adjoint_qoi_parameter_sensitivity
171  (qoi_indices, parameters_in, sensitivities);
172  }
173 
175  (SolverContext& context,
176  const libMesh::QoISet& qoi_indices,
177  const libMesh::ParameterVector& parameters_in,
178  libMesh::SensitivityData& sensitivities) const
179  {
180  context.system->forward_qoi_parameter_sensitivity
181  (qoi_indices, parameters_in, sensitivities);
182 
183  if( context.output_residual_sensitivities )
184  context.vis->output_residual_sensitivities
185  ( context.equation_system, context.system, parameters_in );
186 
187  if( context.output_solution_sensitivities )
188  context.vis->output_solution_sensitivities
189  ( context.equation_system, context.system, parameters_in );
190  }
191 
192 
193 } // end namespace GRINS
virtual void forward_qoi_parameter_sensitivity(SolverContext &context, const libMesh::QoISet &qoi_indices, const libMesh::ParameterVector &parameters_in, libMesh::SensitivityData &sensitivities) const
SharedPtr< libMesh::EquationSystems > equation_system
virtual void solve(SolverContext &context)
SharedPtr< PostProcessedQuantities< libMesh::Real > > postprocessing
void build_mesh_refinement(libMesh::MeshBase &mesh)
void check_qoi_error_option_consistency(SolverContext &context)
void perform_amr(SolverContext &context, const libMesh::ErrorVector &error)
void estimate_error_for_amr(SolverContext &context, libMesh::ErrorVector &error)
void steady_adjoint_solve(SolverContext &context)
Do steady version of adjoint solve.
Definition: grins_solver.C:123
bool check_for_convergence(SolverContext &context, const libMesh::ErrorVector &error) const
SharedPtr< libMesh::ErrorEstimator > error_estimator
GRINS namespace.
GRINS::MultiphysicsSystem * system
SharedPtr< GRINS::Visualization > vis
Interface with libMesh for solving Multiphysics problems.
void print_qoi(SolverContext &context, std::ostream &output)
Definition: grins_solver.C:155
ErrorEstimatorOptions _error_estimator_options
Simple class to hold objects passed to Solver::solve.
unsigned int max_refinement_steps() const
MeshAdaptivityOptions _mesh_adaptivity_options
virtual void adjoint_qoi_parameter_sensitivity(SolverContext &context, const libMesh::QoISet &qoi_indices, const libMesh::ParameterVector &parameters_in, libMesh::SensitivityData &sensitivities) const
virtual void init_time_solver(MultiphysicsSystem *system)

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