https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CumulativeTimeAverageFunctorAux.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
12#include <algorithm>
13
15
18{
21 "Running time-weighted mean of a functor, starting at a given simulation time.");
22
23 params.addRequiredParam<MooseFunctorName>("functor", "The variable or functor to time-average.");
24 params.addRequiredParam<Real>("start_time", "Simulation time at which averaging starts.");
25 MooseEnum schemes("implicit-euler trapezoidal-rule", "implicit-euler");
26 params.addParam<MooseEnum>(
27 "time_integration_scheme",
28 schemes,
29 "Quadrature of the time integral of the functor. 'implicit-euler' uses the current value "
30 "over each time step, 'trapezoidal-rule' the mean of the current and old values.");
31 return params;
32}
33
35 : AuxKernel(parameters),
36 _functor(getFunctor<Real>("functor")),
37 _mean_old(uOld()),
38 _start_time(getParam<Real>("start_time")),
39 _scheme(getParam<MooseEnum>("time_integration_scheme").getEnum<Scheme>()),
40 _averaging(declareRestartableData<bool>("averaging", false)),
41 _t_start(declareRestartableData<Real>("t_start", 0.0))
42{
43 if (isNodal())
44 paramError("variable", "The averaged variable must be elemental (CONSTANT MONOMIAL).");
45}
46
47void
49{
50 // Called once per time step, after time has advanced
51 if (!_averaging && _t >= _start_time)
52 {
53 _averaging = true;
54 // Include the part of the current step after start_time in the average
55 _t_start = std::max(_t - _dt, _start_time);
56 }
57}
58
59Real
61{
62 const Moose::ElemArg elem_arg{_current_elem, false};
63 const Real u = _functor(elem_arg, Moose::currentState());
64
65 if (!_averaging)
66 return u;
67
68 // Total averaging time including this step; the interval is empty at t = start_time
69 const Real T = _t - _t_start;
70 if (T <= 0)
71 return u;
72
73 // Part of the current time step after t_start
74 const Real w = std::min(_dt, T);
75
76 // Mean of the functor over that part of the time step
77 Real u_step = u;
79 {
80 // Linear interpolation of the functor at the beginning of the clipped time step
81 const Real u_old = _functor(elem_arg, Moose::oldState());
82 const Real u_begin = u + (u_old - u) * w / _dt;
83 u_step = 0.5 * (u + u_begin);
84 }
85
86 // On the first averaged time step w = T, so the old value, which is not an average, drops out
87 return _mean_old[_qp] + (u_step - _mean_old[_qp]) * w / T;
88}
registerMooseObject("MooseApp", CumulativeTimeAverageFunctorAux)
bool isNodal() const
Nodal or elemental kernel?
Definition AuxKernel.h:43
const Elem *const & _current_elem
Current element (valid only for elemental kernels)
Definition AuxKernel.h:133
unsigned int _qp
Quadrature point index.
Definition AuxKernel.h:155
static InputParameters validParams()
Definition AuxKernel.C:27
Running (time-weighted) mean of a functor (FE, FV or linear FV variable, or any functor) over [t_star...
CumulativeTimeAverageFunctorAux(const InputParameters &parameters)
const VariableValue & _mean_old
Value of the average at the previous time step.
virtual Real computeValue() override
Compute and return the value of the aux variable.
Scheme
Quadratures of the time integral of the functor over a time step, in the order of the time_integratio...
const Real _start_time
Time at which averaging starts.
virtual void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job.
Real & _t_start
Beginning of the averaging interval, never earlier than start_time.
const Scheme _scheme
Quadrature of the time integral of the functor over a time step.
const Moose::Functor< Real > & _functor
Quantity being averaged.
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 addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
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.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Real & _dt
Time step size.
StateArg oldState()
StateArg currentState()
A structure that is used to evaluate Moose functors logically at an element/cell center.