https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVTimeDerivative.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
11
13
16{
18 params.addClassDescription("Represents the matrix and right hand side contributions of a "
19 "time derivative term in a partial differential equation.");
20 params.addParam<MooseFunctorName>(
21 "factor", 1.0, "A multiplier on the variable within the time derivative.");
22 params.addParam<bool>(
23 "conservative_form",
24 true,
25 "Whether to assemble the time derivative of the product, d(cu)/dt, rather than the "
26 "multiplier times the transient of the variable, c du/dt. The conservative form is the "
27 "default because it is the more general of the two: where the multiplier does not vary in "
28 "time every state of it is the same value, the product form collapses to c du/dt exactly. "
29 "Where it does vary they differ, and it is the conservative form that most conservation laws "
30 "ask for. Set this to false to recover the multiplier held outside the derivative.");
31 return params;
32}
33
36 _factor(getFunctor<Real>("factor")),
37 _time_integrator(_sys.getTimeIntegrator(_var_num)),
38 _conservative_form(getParam<bool>("conservative_form")),
39 _factor_history(_time_integrator.numStatesRequired(), 0.0),
40 _state_args(_time_integrator.numStatesRequired(), determineState()),
41 _current_state(Moose::StateArg(0, Moose::SolutionIterationType::Time))
42{
43 // The integrators pair factor_history[i] with the solution i+1 steps back: implicit Euler uses
44 // factors[0] against the old solution, and BDF2 adds factors[1] against the older one. Which
45 // multiplier belongs in each slot is the whole difference between the two forms. Note that
46 // where the multiplier is constant in time the two slots hold the same number either way, so
47 // the default costs nothing and changes nothing for such a problem.
48 //
49 // c du/dt wants the one current multiplier against every solution state,
50 // c^{n+1} ( w_0 u^{n+1} + w_1 u^n + w_2 u^{n-1} ) / dt
51 //
52 // d(cu)/dt wants each multiplier taken at the same time as the solution it multiplies,
53 // ( w_0 c^{n+1} u^{n+1} + w_1 c^n u^n + w_2 c^{n-1} u^{n-1} ) / dt
54 //
55 // so slot i takes state i+1 in the conservative form and state 0 otherwise. Note that the
56 // matrix keeps the current multiplier either way, since it scales u^{n+1}; that is why it no
57 // longer reads _state_args[0], which is the old multiplier in the conservative form.
58 //
59 // Indexing the history by i, which is what this did originally, is neither: it hands every
60 // multiplier the solution one step older than itself and converges to c u' - c' u / 2, so
61 // refining the time step does not recover either answer. Implicit Euler asks for a single state
62 // and so cannot expose it; BDF2 with a multiplier that varies in time does.
63 for (const auto i : index_range(_state_args))
64 _state_args[i] =
66}
67
68Real
75
76Real
82
83void
85{
87
88 const auto elem_arg = makeElemArg(_current_elem_info->elem());
89 for (const auto i : index_range(_factor_history))
90 _factor_history[i] = _factor(elem_arg, _state_args[i]);
91}
registerMooseObject("MooseApp", LinearFVTimeDerivative)
Class used for caching additional information for elements such as the volume and centroid.
Definition ElemInfo.h:26
const Elem * elem() const
Definition ElemInfo.h:34
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
Helper method to create an elemental argument for a functor that includes whether to perform skewness...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
Finite volume kernel that contributes approximations of volumetric integral terms to the matrix and r...
virtual void setCurrentElemInfo(const ElemInfo *elem_info)
Set the current ElemInfo object.
const ElemInfo * _current_elem_info
Pointer to the current element info.
static InputParameters validParams()
Real _current_elem_volume
The coordinate-specific element volume.
dof_id_type _dof_id
The dof index for the current variable associated with the element.
Kernel that adds contributions from a time derivative term to a linear system populated using the fin...
virtual void setCurrentElemInfo(const ElemInfo *elem_info) override
Set the current ElemInfo object.
virtual Real computeMatrixContribution() override
Computes the system matrix contribution for the given variable on the current element.
const TimeIntegrator & _time_integrator
The time integrator to use in this kernel, will provide information on how many states are required i...
virtual Real computeRightHandSideContribution() override
Computes the right hand side contribution for the given variable on the current element.
std::vector< Real > _factor_history
Values of the material property multiplier, one per history slot of the time integrator.
const Moose::Functor< Real > & _factor
The functor for the material property multipler.
LinearFVTimeDerivative(const InputParameters &params)
Class constructor.
std::vector< Moose::StateArg > _state_args
State args used to fetch the entries of _factor_history above.
const Moose::StateArg _current_state
The multiplier that scales the new solution, always the current one in either form.
static InputParameters validParams()
const bool _conservative_form
Whether to assemble d(cu)/dt rather than c du/dt.
virtual Real timeDerivativeRHSContribution(dof_id_type dof_id, const std::vector< Real > &factors={}) const
The time derivative's contribution to the right hand side of a linear system.
virtual Real timeDerivativeMatrixContribution(const Real factor) const
The time derivative's contribution to the right hand side of a linear system.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
State argument for evaluating functors.