GRINS-0.6.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-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 // This class
27 
28 // GRINS
29 #include "grins/solver_context.h"
30 #include "grins/multiphysics_sys.h"
31 #include "grins/composite_qoi.h"
32 
33 // libMesh
34 #include "libmesh/error_vector.h"
35 #include "libmesh/steady_solver.h"
36 
37 namespace GRINS
38 {
39 
41  : MeshAdaptiveSolverBase( input )
42  {
43  return;
44  }
45 
47  {
48  return;
49  }
50 
52  {
53  libMesh::SteadySolver* time_solver = new libMesh::SteadySolver( *(system) );
54 
55  system->time_solver = libMesh::AutoPtr<libMesh::TimeSolver>( time_solver );
56 
57  return;
58  }
59 
61  {
62  // Mesh and mesh refinement
63  libMesh::MeshBase& mesh = context.equation_system->get_mesh();
64  this->build_mesh_refinement( mesh );
65 
67  std::cout << "==========================================================" << std::endl
68  << "Performing " << this->_max_refinement_steps << " adaptive refinements" << std::endl
69  << "==========================================================" << std::endl;
70 
71  // GRVY timers contained in here (if enabled)
72  for ( unsigned int r_step = 0; r_step < this->_max_refinement_steps; r_step++ )
73  {
74  std::cout << "==========================================================" << std::endl
75  << "Adaptive Refinement Step " << r_step << std::endl
76  << "==========================================================" << std::endl;
77 
78  // Solve the forward problem
79  context.system->solve();
80 
81  if( context.output_vis )
82  {
83  context.postprocessing->update_quantities( *(context.equation_system) );
84  context.vis->output( context.equation_system );
85  }
86 
87  // Solve adjoint system
88  if(context.do_adjoint_solve)
89  this->steady_adjoint_solve(context);
90 
91  if(context.output_adjoint)
92  context.vis->output_adjoint(context.equation_system, context.system);
93 
94  if( context.output_residual )
95  {
96  context.vis->output_residual( context.equation_system, context.system );
97  }
98 
99  // Now we construct the data structures for the mesh refinement process
100  libMesh::ErrorVector error;
101 
102  std::cout << "==========================================================" << std::endl
103  << "Estimating error" << std::endl
104  << "==========================================================" << std::endl;
105  context.error_estimator->estimate_error( *context.system, error );
106 
107  // Plot error vector
108  if( this->_plot_cell_errors )
109  {
110  error.plot_error( this->_error_plot_prefix+".exo", mesh );
111  }
112 
113  // Check for convergence of error
114  std::cout << "==========================================================" << std::endl
115  << "Checking convergence" << std::endl
116  << "==========================================================" << std::endl;
117  bool converged = this->check_for_convergence( context, error );
118 
119  if( converged )
120  {
121  // Break out of adaptive loop
122  std::cout << "==========================================================" << std::endl
123  << "Convergence detected!" << std::endl
124  << "==========================================================" << std::endl;
125  break;
126  }
127  else
128  {
129  // Only bother refining if we're on the last step.
130  if( r_step < this->_max_refinement_steps -1 )
131  {
132  std::cout << "==========================================================" << std::endl
133  << "Performing Mesh Refinement" << std::endl
134  << "==========================================================" << std::endl;
135 
136  this->flag_elements_for_refinement( error );
137  _mesh_refinement->refine_and_coarsen_elements();
138 
139  // Dont forget to reinit the system after each adaptive refinement!
140  context.equation_system->reinit();
141 
142  // This output cannot be toggled in the input file.
143  std::cout << "==========================================================" << std::endl
144  << "Refined mesh to " << std::setw(12) << mesh.n_active_elem()
145  << " active elements" << std::endl
146  << " " << std::setw(16) << context.system->n_active_dofs()
147  << " active dofs" << std::endl
148  << "==========================================================" << std::endl;
149 
150  // It's helpful to print the qoi along the way, but only do it if the user
151  // asks for it
152  if( context.print_qoi )
153  {
154  context.system->assemble_qoi();
155  const CompositeQoI* my_qoi = libMesh::libmesh_cast_ptr<const CompositeQoI*>(context.system->get_qoi());
156  my_qoi->output_qoi( std::cout );
157  std::cout << std::endl;
158  }
159  }
160  }
161 
162  } // r_step for-loop
163 
164  return;
165  }
166 
168  (SolverContext& context,
169  const libMesh::QoISet& qoi_indices,
170  const libMesh::ParameterVector& parameters_in,
171  libMesh::SensitivityData& sensitivities) const
172  {
173  context.system->adjoint_qoi_parameter_sensitivity
174  (qoi_indices, parameters_in, sensitivities);
175  }
176 
178  (SolverContext& context,
179  const libMesh::QoISet& qoi_indices,
180  const libMesh::ParameterVector& parameters_in,
181  libMesh::SensitivityData& sensitivities) const
182  {
183  context.system->forward_qoi_parameter_sensitivity
184  (qoi_indices, parameters_in, sensitivities);
185 
186  if( context.output_residual_sensitivities )
187  context.vis->output_residual_sensitivities
188  ( context.equation_system, context.system, parameters_in );
189 
190  if( context.output_solution_sensitivities )
191  context.vis->output_solution_sensitivities
192  ( context.equation_system, context.system, parameters_in );
193  }
194 
195 
196 } // 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
boost::scoped_ptr< libMesh::MeshRefinement > _mesh_refinement
virtual void solve(SolverContext &context)
void build_mesh_refinement(libMesh::MeshBase &mesh)
void steady_adjoint_solve(SolverContext &context)
Do steady version of adjoint solve.
Definition: grins_solver.C:105
bool check_for_convergence(SolverContext &context, const libMesh::ErrorVector &error) const
std::tr1::shared_ptr< libMesh::EquationSystems > equation_system
GRINS namespace.
std::tr1::shared_ptr< libMesh::ErrorEstimator > error_estimator
void flag_elements_for_refinement(const libMesh::ErrorVector &error)
GRINS::MultiphysicsSystem * system
Interface with libMesh for solving Multiphysics problems.
std::tr1::shared_ptr< PostProcessedQuantities< libMesh::Real > > postprocessing
void output_qoi(std::ostream &out) const
Basic output for computed QoI's.
std::tr1::shared_ptr< GRINS::Visualization > vis
Simple class to hold objects passed to Solver::solve.
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 Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1