www.mooseframework.org
ImplicitMidpoint.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "ImplicitMidpoint.h"
16 #include "NonlinearSystem.h"
17 #include "FEProblem.h"
18 #include "PetscSupport.h"
19 
20 template <>
23 {
25 
26  return params;
27 }
28 
30  : TimeIntegrator(parameters),
31  _stage(1),
32  _residual_stage1(_nl.addVector("residual_stage1", false, GHOSTED))
33 {
34 }
35 
37 
38 void
40 {
41  // We are multiplying by the method coefficients in postStep(), so
42  // the time derivatives are of the same form at every stage although
43  // the current solution varies depending on the stage.
44  _u_dot = *_solution;
46  _u_dot *= 1. / _dt;
47  _u_dot.close();
48  _du_dot_du = 1. / _dt;
49 }
50 
51 void
53 {
54  Real time_new = _fe_problem.time();
55  Real time_old = _fe_problem.timeOld();
56  Real time_half = (time_new + time_old) / 2.;
57 
58  // Compute first stage
60  _console << "1st stage\n";
61  _stage = 1;
62  _fe_problem.time() = time_half;
64 
65  // Compute second stage
67  _console << "2nd stage\n";
68  _stage = 2;
69  _fe_problem.time() = time_new;
71 }
72 
73 void
74 ImplicitMidpoint::postStep(NumericVector<Number> & residual)
75 {
76  if (_stage == 1)
77  {
78  // In the standard RK notation, the stage 1 residual is given by:
79  //
80  // R := M*(Y_1 - y_n)/dt - (1/2)*f(t_n + dt/2, Y_1) = 0
81  //
82  // where:
83  // .) M is the mass matrix
84  // .) f(t_n + dt/2, Y_1) is saved in _residual_stage1
85  // .) The minus sign is baked in to the non-time residuals, so it does not appear here.
87  _residual_stage1.close();
88 
89  residual.add(1., _Re_time);
90  residual.add(0.5, _Re_non_time);
91  residual.close();
92  }
93  else if (_stage == 2)
94  {
95  // The update step. In the standard RK notation, the update
96  // residual is given by:
97  //
98  // R := M*(y_{n+1} - y_n)/dt - f(t_n + dt/2, Y_1) = 0
99  //
100  // where:
101  // .) M is the mass matrix.
102  // .) f(t_n + dt/2, Y_1) is the residual from stage 1, it has already
103  // been saved as _residual_stage1.
104  // .) The minus signs are "baked in" to the non-time residuals, so
105  // they do not appear here.
106  residual.add(1., _Re_time);
107  residual.add(1., _residual_stage1);
108  residual.close();
109  }
110  else
111  mooseError(
112  "ImplicitMidpoint::postStep(): _stage = ", _stage, ", only _stage = 1, 2 is allowed.");
113 }
NumericVector< Number > & _residual_stage1
Buffer to store non-time residual from the first stage.
virtual Real & timeOld() const
void initPetscOutput()
Reinitialize petsc output for proper linear/nonlinear iteration display.
NumericVector< Number > & _u_dot
solution vector for u^dot
NonlinearSystemBase & getNonlinearSystemBase()
FEProblemBase & _fe_problem
NumericVector< Number > & _Re_non_time
residual vector for non-time contributions
virtual Real & time() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void solve()
ImplicitMidpoint(const InputParameters &parameters)
virtual void postStep(NumericVector< Number > &residual)
Callback to the TimeIntegrator called immediately after the residuals are computed in NonlinearSystem...
InputParameters validParams< TimeIntegrator >()
InputParameters validParams< ImplicitMidpoint >()
Real & _du_dot_du
solution vector for
virtual ~ImplicitMidpoint()
Base class for time integrators.
virtual System & system() override
Get the reference to the libMesh system.
NumericVector< Number > & _Re_time
residual vector for time contributions
unsigned int _stage
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const NumericVector< Number > & _solution_old
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const NumericVector< Number > *& _solution
solution vectors
virtual void computeTimeDerivatives()