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
19
22{
24
25 params.addClassDescription("Implementation of explicit, Central Difference integration without "
26 "invoking any of the nonlinear solver");
27
28 return params;
29}
30
32 : ActuallyExplicitEuler(parameters),
33 _du_dotdot_du(_sys.duDotDotDu()),
34 _solution_older(_sys.solutionState(2))
35{
36 if (_solve_type == LUMPED)
37 _is_lumped = true;
38
42}
43
44void
46 const dof_id_type & dof,
47 ADReal & ad_u_dotdot) const
48{
49 // Seeds ad_u_dotdot with _ad_dof_values and associated derivatives provided via ad_u_dot from
50 // MooseVariableData
51 ad_u_dotdot = ad_u_dot;
52
53 computeTimeDerivativeHelper(ad_u_dot, ad_u_dotdot, _solution_old(dof), _solution_older(dof));
54}
55
56void
58{
60
61 // _nl here so that we don't create this vector in the aux system time integrator
63 _nl->addVector(_u_dot_factor_tag, true, GHOSTED);
65 _nl->addVector(_u_dotdot_factor_tag, true, GHOSTED);
66}
67
68void
70{
71 if (!_sys.solutionUDot())
72 mooseError("CentralDifference: Time derivative of solution (`u_dot`) is not stored. Please "
73 "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
74
75 if (!_sys.solutionUDotDot())
76 mooseError("CentralDifference: Time derivative of solution (`u_dotdot`) is not stored. Please "
77 "set uDotDotRequested() to true in FEProblemBase before requesting `u_dot`.");
78
79 // Declaring u_dot and u_dotdot
80 auto & u_dot = *_sys.solutionUDot();
81 auto & u_dotdot = *_sys.solutionUDotDot();
82
83 u_dot = *_solution;
84 u_dotdot = *_solution;
85
86 // Computing derivatives
88
89 // make sure _u_dotdot and _u_dot are in good state
90 u_dotdot.close();
91 u_dot.close();
92
93 // used for Jacobian calculations
95 _du_dotdot_du = 1.0 / (_dt * _dt);
96
97 // Computing udotdot "factor"
98 // u_dotdot_factor = u_dotdot - (u - u_old)/dt^2 = (u - 2* u_old + u_older - u + u_old) / dt^2
99 // u_dotdot_factor = (u_older - u_old)/dt^2
100 if (_sys.hasVector(_u_dotdot_factor_tag)) // so that we don't do this in the aux system
101 {
102 auto & u_dotdot_factor = _sys.getVector(_u_dotdot_factor_tag);
103 u_dotdot_factor = _sys.solutionOlder();
104 u_dotdot_factor -= _sys.solutionOld();
105 u_dotdot_factor *= 1.0 / (_dt * _dt);
106 u_dotdot_factor.close();
107 }
108
109 // Computing udot "factor"
110 // u_dot_factor = u_dot - (u - u_old)/2/dt = (u - u_older)/ 2/ dt - (u - u_old)/2/dt
111 // u_dot_factor = (u_old - u_older)/2/dt
112 if (_sys.hasVector(_u_dot_factor_tag)) // so that we don't do this in the aux system
113 {
114 auto & u_dot_factor = _sys.getVector(_u_dot_factor_tag);
115 u_dot_factor = _sys.solutionOld();
116 u_dot_factor -= _sys.solutionOlder();
117 u_dot_factor *= 1.0 / (2.0 * _dt);
118 u_dot_factor.close();
119 }
120}
121
122Real
124{
125 return Real(1) / Real(2);
126}
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:289
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
Definition SystemBase.C:932
NumericVector< Number > & solutionOld()
Definition SystemBase.h:213
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:214
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:605
virtual NumericVector< Number > * solutionUDotDot()
Definition SystemBase.h:290
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