https://mooseframework.inl.gov
CentralDifference.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 // MOOSE includes
11 #include "CentralDifference.h"
12 #include "NonlinearSystem.h"
13 #include "FEProblem.h"
14 
15 // libMesh includes
16 #include "libmesh/nonlinear_solver.h"
17 
18 using namespace libMesh;
19 
21 
24 {
26 
27  params.addClassDescription("Implementation of explicit, Central Difference integration without "
28  "invoking any of the nonlinear solver");
29 
30  return params;
31 }
32 
34  : ActuallyExplicitEuler(parameters),
35  _du_dotdot_du(_sys.duDotDotDu()),
36  _solution_older(_sys.solutionState(2))
37 {
38  if (_solve_type == LUMPED)
39  _is_lumped = true;
40 
44 }
45 
46 void
48  const dof_id_type & dof,
49  ADReal & ad_u_dotdot) const
50 {
51  // Seeds ad_u_dotdot with _ad_dof_values and associated derivatives provided via ad_u_dot from
52  // MooseVariableData
53  ad_u_dotdot = ad_u_dot;
54 
55  computeTimeDerivativeHelper(ad_u_dot, ad_u_dotdot, _solution_old(dof), _solution_older(dof));
56 }
57 
58 void
60 {
62 
63  // _nl here so that we don't create this vector in the aux system time integrator
68 }
69 
70 void
72 {
73  if (!_sys.solutionUDot())
74  mooseError("CentralDifference: Time derivative of solution (`u_dot`) is not stored. Please "
75  "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
76 
77  if (!_sys.solutionUDotDot())
78  mooseError("CentralDifference: Time derivative of solution (`u_dotdot`) is not stored. Please "
79  "set uDotDotRequested() to true in FEProblemBase before requesting `u_dot`.");
80 
81  // Declaring u_dot and u_dotdot
82  auto & u_dot = *_sys.solutionUDot();
83  auto & u_dotdot = *_sys.solutionUDotDot();
84 
85  u_dot = *_solution;
86  u_dotdot = *_solution;
87 
88  // Computing derivatives
90 
91  // make sure _u_dotdot and _u_dot are in good state
92  u_dotdot.close();
93  u_dot.close();
94 
95  // used for Jacobian calculations
97  _du_dotdot_du = 1.0 / (_dt * _dt);
98 
99  // Computing udotdot "factor"
100  // u_dotdot_factor = u_dotdot - (u - u_old)/dt^2 = (u - 2* u_old + u_older - u + u_old) / dt^2
101  // u_dotdot_factor = (u_older - u_old)/dt^2
102  if (_sys.hasVector(_u_dotdot_factor_tag)) // so that we don't do this in the aux system
103  {
104  auto & u_dotdot_factor = _sys.getVector(_u_dotdot_factor_tag);
105  u_dotdot_factor = _sys.solutionOlder();
106  u_dotdot_factor -= _sys.solutionOld();
107  u_dotdot_factor *= 1.0 / (_dt * _dt);
108  u_dotdot_factor.close();
109  }
110 
111  // Computing udot "factor"
112  // u_dot_factor = u_dot - (u - u_old)/2/dt = (u - u_older)/ 2/ dt - (u - u_old)/2/dt
113  // u_dot_factor = (u_old - u_older)/2/dt
114  if (_sys.hasVector(_u_dot_factor_tag)) // so that we don't do this in the aux system
115  {
116  auto & u_dot_factor = _sys.getVector(_u_dot_factor_tag);
117  u_dot_factor = _sys.solutionOld();
118  u_dot_factor -= _sys.solutionOlder();
119  u_dot_factor *= 1.0 / (2.0 * _dt);
120  u_dot_factor.close();
121  }
122 }
123 
124 Real
126 {
127  return Real(1) / Real(2);
128 }
Real & _du_dotdot_du
solution vector for
virtual void setUDotDotOldRequested(const bool u_dotdot_old_requested)
Set boolean flag to true to store old solution second time derivative.
void computeTimeDerivativeHelper(T &u_dot, T2 &u_dotdot, const T3 &u_old, const T4 &u_older) const
Helper function that actually does the math for computing the time derivative.
const TagID _u_dot_factor_tag
The vector tag for the nodal multiplication factor for the residual calculation of the udot term...
void computeADTimeDerivatives(ADReal &ad_u_dot, const dof_id_type &dof, ADReal &ad_u_dotdot) const override
method for computing local automatic differentiation time derivatives
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
Definition: SystemBase.C:907
virtual void setUDotDotRequested(const bool u_dotdot_requested)
Set boolean flag to true to store solution second time derivative.
virtual void initialSetup() override
Called to setup datastructures.
bool _is_lumped
Boolean flag that is set to true if lumped mass matrix is used.
FEProblemBase & _fe_problem
Reference to the problem.
NonlinearSystemBase * _nl
Pointer to the nonlinear system, can happen that we dont have any.
SystemBase & _sys
Reference to the system this time integrator operates on.
virtual void computeTimeDerivatives() override
Computes the time derivative and the Jacobian of the time derivative.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
static InputParameters validParams()
Implements a truly explicit (no nonlinear solve) Central Difference time integration scheme...
registerMooseObject("MooseApp", CentralDifference)
NumericVector< Number > & solutionOlder()
Definition: SystemBase.h:197
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:46
Real & _dt
The current time step size.
MooseEnum _solve_type
Solve type for how mass matrix is handled.
NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const libMesh::ParallelType type)
Adds a solution length vector to the system.
virtual void setUDotOldRequested(const bool u_dot_old_requested)
Set boolean flag to true to store old solution time derivative.
const TagID _u_dotdot_factor_tag
The vector tag for the nodal multiplication factor for the residual calculation of the udotdot term...
GHOSTED
virtual NumericVector< Number > * solutionUDot()
Definition: SystemBase.h:252
virtual void disassociateVectorFromTag(NumericVector< Number > &vec, TagID tag)
Disassociate a given vector from a given tag.
virtual void close()=0
virtual Real duDotDuCoeff() const override
const NumericVector< Number > *const & _solution
const NumericVector< Number > & _solution_older
The older solution.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
Implements a truly explicit (no nonlinear solve) first-order, forward Euler time integration scheme...
const NumericVector< Number > & _solution_old
virtual NumericVector< Number > * solutionUDotDot()
Definition: SystemBase.h:253
CentralDifference(const InputParameters &parameters)
NumericVector< Number > & solutionOld()
Definition: SystemBase.h:196
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
Definition: SystemBase.C:916
virtual void initialSetup() override
Called to setup datastructures.
uint8_t dof_id_type
void computeDuDotDu()
Compute _du_dot_du.