GRINS-0.7.0
grins_unsteady_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 
26 // This class
28 
29 // GRINS
30 #include "grins/grins_enums.h"
31 #include "grins/solver_context.h"
32 #include "grins/multiphysics_sys.h"
35 #include "grins/solver_names.h"
36 
37 // libMesh
38 #include "libmesh/dirichlet_boundaries.h"
39 #include "libmesh/dof_map.h"
40 #include "libmesh/getpot.h"
41 #include "libmesh/euler_solver.h"
42 #include "libmesh/euler2_solver.h"
43 #include "libmesh/twostep_time_solver.h"
44 #include "libmesh/newmark_solver.h"
45 
46 // C++
47 #include <ctime>
48 
49 namespace GRINS
50 {
51 
52  UnsteadySolver::UnsteadySolver( const GetPot& input )
53  : Solver(input),
54  _time_solver_name(TimeSteppingParsing::parse_time_stepper_name(input)),
55  _n_timesteps( TimeSteppingParsing::parse_n_timesteps(input) ),
56  _backtrack_deltat( TimeSteppingParsing::parse_backtrack_deltat(input) ),
57  _theta( TimeSteppingParsing::parse_theta(input) ),
58  _deltat( TimeSteppingParsing::parse_deltat(input) ),
59  _adapt_time_step_options(input),
60  _is_second_order_in_time(false)
61  {}
62 
64  {
65  libMesh::UnsteadySolver* time_solver = NULL;
66 
68  {
69  time_solver = new libMesh::EulerSolver( *(system) );
70 
71  this->set_theta<libMesh::EulerSolver>(time_solver);
72  }
74  {
75  time_solver = new libMesh::Euler2Solver( *(system) );
76 
77  this->set_theta<libMesh::Euler2Solver>(time_solver);
78  }
80  {
81  time_solver = new libMesh::NewmarkSolver( *(system) );
83  }
84  else
85  libmesh_error_msg("ERROR: Unsupported time stepper "+_time_solver_name);
86 
88  {
89  libMesh::TwostepTimeSolver *outer_solver =
90  new libMesh::TwostepTimeSolver(*system);
91 
92  outer_solver->target_tolerance = _adapt_time_step_options.target_tolerance();
93  outer_solver->upper_tolerance = _adapt_time_step_options.upper_tolerance();
94  outer_solver->max_growth = _adapt_time_step_options.max_growth();
95  outer_solver->component_norm = _adapt_time_step_options.component_norm();
96  outer_solver->quiet = false;
97 
98  outer_solver->core_time_solver =
99  libMesh::UniquePtr<libMesh::UnsteadySolver>(time_solver);
100  system->time_solver = libMesh::UniquePtr<libMesh::TimeSolver>(outer_solver);
101  }
102  else
103  {
104  system->time_solver = libMesh::UniquePtr<libMesh::TimeSolver>(time_solver);
105  }
106 
107  time_solver->reduce_deltat_on_diffsolver_failure = this->_backtrack_deltat;
108  }
109 
111  {
112  libmesh_assert( context.system );
113 
114  context.system->deltat = this->_deltat;
115 
116  libMesh::Real sim_time;
117 
118  if( context.output_vis )
119  {
120  context.postprocessing->update_quantities( *(context.equation_system) );
121  context.vis->output( context.equation_system );
122  }
123 
124  // We may need to initialize acceleration for second order solvers
126  this->init_second_order_in_time_solvers(context);
127 
128  std::time_t first_wall_time = std::time(NULL);
129 
130  // Now we begin the timestep loop to compute the time-accurate
131  // solution of the equations.
132  for (unsigned int t_step=0; t_step < this->_n_timesteps; t_step++)
133  {
134  std::time_t latest_wall_time = std::time(NULL);
135 
136  std::cout << "==========================================================" << std::endl
137  << " Beginning time step " << t_step <<
138  ", t = " << context.system->time <<
139  ", dt = " << context.system->deltat <<
140  ", runtime = " << (latest_wall_time - first_wall_time) <<
141  std::endl
142  << "==========================================================" << std::endl;
143 
144  // If we have any solution-dependent Dirichlet boundaries, we
145  // need to update them with the current solution.
146  this->update_dirichlet_bcs(context);
147 
148  // GRVY timers contained in here (if enabled)
149  context.system->solve();
150 
151  sim_time = context.system->time;
152 
153  if( context.output_vis && !((t_step+1)%context.timesteps_per_vis) )
154  {
155  context.postprocessing->update_quantities( *(context.equation_system) );
156  context.vis->output( context.equation_system, t_step, sim_time );
157  }
158 
159  if( context.output_residual && !((t_step+1)%context.timesteps_per_vis) )
160  context.vis->output_residual( context.equation_system, context.system,
161  t_step, sim_time );
162 
163  if ( context.print_perflog && context.timesteps_per_perflog
164  && !((t_step+1)%context.timesteps_per_perflog) )
165  libMesh::perflog.print_log();
166 
167  if ( context.print_scalars )
168  this->print_scalar_vars(context);
169 
170  // Advance to the next timestep
171  context.system->time_solver->advance_timestep();
172  }
173 
174  std::time_t final_wall_time = std::time(NULL);
175  std::cout << "==========================================================" << std::endl
176  << " Ending time stepping, t = " << context.system->time <<
177  ", runtime = " << (final_wall_time - first_wall_time) <<
178  std::endl
179  << "==========================================================" << std::endl;
180 
181 
182  return;
183  }
184 
186  {
187  // FIXME: This needs to be much more efficient and intuitive.
188  bool have_nonlinear_dirichlet_bc = false;
189  bool have_time_dependence = false;
190  {
191  const libMesh::DirichletBoundaries &db =
192  *context.system->get_dof_map().get_dirichlet_boundaries();
193 
194  for (libMesh::DirichletBoundaries::const_iterator
195  it = db.begin(); it != db.end(); ++it)
196  {
197  const libMesh::DirichletBoundary* bdy = *it;
198 
199  // If we have a FEMFunctionBase, we assume nonlinearity
200  if (bdy->f_fem.get())
201  have_nonlinear_dirichlet_bc = true;
202 
203  // Check for time-dependence of FunctionBase
204  if( bdy->f.get() )
205  if( bdy->f->is_time_dependent() )
206  have_time_dependence = true;
207 
208  if( have_nonlinear_dirichlet_bc || have_time_dependence )
209  break;
210 
211  } // End loop over DirichletBoundaries
212  }
213 
214 
215  // Nonlinear Dirichlet constraints change as the solution does
216  // and time-dependent constraints have to be updated
217  if (have_nonlinear_dirichlet_bc || have_time_dependence )
218  {
219  context.system->reinit_constraints();
220  context.system->get_dof_map().enforce_constraints_exactly(*context.system);
221  context.system->get_dof_map().enforce_constraints_exactly(*context.system,
222  dynamic_cast<libMesh::UnsteadySolver*>(context.system->time_solver.get())->old_local_nonlinear_solution.get());
223  }
224  }
225 
227  {
228  // Right now, only Newmark is available so we cast directly to that
229  libMesh::TimeSolver& base_time_solver = context.system->get_time_solver();
230 
231  libMesh::NewmarkSolver& time_solver = libMesh::libmesh_cast_ref<libMesh::NewmarkSolver&>(base_time_solver);
232 
233  // If there's a restart, the acceleration should already be there
234  if( context.have_restart )
235  time_solver.set_initial_accel_avail(true);
236 
237  // Otherwise, we need to compute it
238  else
239  {
240  libMesh::out << "==========================================================" << std::endl
241  << " Computing Initital Acceleration" << std::endl
242  << "==========================================================" << std::endl;
243 
244  time_solver.compute_initial_accel();
245  }
246  }
247 
248 } // namespace GRINS
SharedPtr< libMesh::EquationSystems > equation_system
SharedPtr< PostProcessedQuantities< libMesh::Real > > postprocessing
UnsteadySolver(const GetPot &input)
static const std::string libmesh_euler2_solver()
Definition: solver_names.h:49
GRINS namespace.
unsigned int timesteps_per_perflog
virtual void init_time_solver(GRINS::MultiphysicsSystem *system)
AdaptiveTimeSteppingOptions _adapt_time_step_options
bool _is_second_order_in_time
Track whether is this a second order (in time) solver or not.
unsigned int timesteps_per_vis
GRINS::MultiphysicsSystem * system
SharedPtr< GRINS::Visualization > vis
void print_scalar_vars(SolverContext &context)
Definition: grins_solver.C:133
Interface with libMesh for solving Multiphysics problems.
virtual void solve(SolverContext &context)
static const std::string libmesh_euler_solver()
Definition: solver_names.h:46
Simple class to hold objects passed to Solver::solve.
static const std::string libmesh_newmark_solver()
Definition: solver_names.h:52
void update_dirichlet_bcs(SolverContext &context)
Updates Dirichlet boundary conditions.
void init_second_order_in_time_solvers(SolverContext &context)

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