https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
18using 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
46void
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
58void
69
70void
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
124Real
126{
127 return Real(1) / Real(2);
128}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("MooseApp", CentralDifference)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Implements a truly explicit (no nonlinear solve) first-order, forward Euler time integration scheme.
static InputParameters validParams()
Implements a truly explicit (no nonlinear solve) Central Difference time integration scheme.
CentralDifference(const InputParameters &parameters)
virtual void initialSetup() override
Called to setup datastructures.
virtual void computeTimeDerivatives() override
Computes the time derivative and the Jacobian of the time derivative.
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
static InputParameters validParams()
Real & _du_dotdot_du
solution vector for
virtual Real duDotDuCoeff() const override
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 NumericVector< Number > & _solution_older
The older solution.
virtual void initialSetup() override
Called to setup datastructures.
MooseEnum _solve_type
Solve type for how mass matrix is handled.
virtual void setUDotOldRequested(const bool u_dot_old_requested)
Set boolean flag to true to store old solution time derivative.
virtual void setUDotDotRequested(const bool u_dotdot_requested)
Set boolean flag to true to store solution second time derivative.
virtual void setUDotDotOldRequested(const bool u_dotdot_old_requested)
Set boolean flag to true to store old solution second time derivative.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
NonlinearSystemBase * _nl
Pointer to the nonlinear system, can happen that we dont have any.
const TagID _u_dotdot_factor_tag
The vector tag for the nodal multiplication factor for the residual calculation of the udotdot term.
const TagID _u_dot_factor_tag
The vector tag for the nodal multiplication factor for the residual calculation of the udot term.
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
Definition SystemBase.C:923
virtual NumericVector< Number > * solutionUDot()
Definition SystemBase.h:280
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
Definition SystemBase.C:932
NumericVector< Number > & solutionOld()
Definition SystemBase.h:204
virtual void disassociateVectorFromTag(NumericVector< Number > &vec, TagID tag)
Disassociate a given vector from a given tag.
Definition SystemBase.C:992
NumericVector< Number > & solutionOlder()
Definition SystemBase.h:205
NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const libMesh::ParallelType type)
Adds a solution length vector to the system.
Definition SystemBase.C:607
virtual NumericVector< Number > * solutionUDotDot()
Definition SystemBase.h:281
void computeDuDotDu()
Compute _du_dot_du.
const NumericVector< Number > *const & _solution
FEProblemBase & _fe_problem
Reference to the problem.
SystemBase & _sys
Reference to the system this time integrator operates on.
Real & _dt
The current time step size.
bool _is_lumped
Boolean flag that is set to true if lumped mass matrix is used.
const NumericVector< Number > & _solution_old
virtual void close()=0
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
uint8_t dof_id_type
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real