https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VariableTimeIntegrationAux.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("Integrates a field variable in time.");
19 params.addRequiredCoupledVar("variable_to_integrate", "The variable to be integrated");
20 params.addParam<Real>("coefficient", 1.0, "A simple coefficient multiplying the integral");
21 params.addParam<unsigned int>(
22 "order", 2, "The order of global truncation error: midpoint=1, trapezoidal=2, Simpson=3");
23 return params;
24}
25
27 : AuxKernel(parameters),
28 _coef(getParam<Real>("coefficient")),
29 _order(getParam<unsigned int>("order")),
30 _u_old(_order != 3 ? uOld() : genericZeroValue<false>()),
31 _u_older(_order == 3 ? uOlder() : genericZeroValue<false>())
32{
33 switch (_order)
34 {
35 case 1:
36 _integration_coef.push_back(1.0);
37 _coupled_vars.push_back(&coupledValue("variable_to_integrate"));
38 break;
39 case 2:
40 _integration_coef.push_back(0.5);
41 _integration_coef.push_back(0.5);
42 _coupled_vars.push_back(&coupledValue("variable_to_integrate"));
43 _coupled_vars.push_back(&coupledValueOld("variable_to_integrate"));
44 break;
45 case 3:
46 _integration_coef.push_back(1.0 / 3.0);
47 _integration_coef.push_back(4.0 / 3.0);
48 _integration_coef.push_back(1.0 / 3.0);
49 _coupled_vars.push_back(&coupledValue("variable_to_integrate"));
50 _coupled_vars.push_back(&coupledValueOld("variable_to_integrate"));
51 _coupled_vars.push_back(&coupledValueOlder("variable_to_integrate"));
52 break;
53 default:
54 mooseError("VariableTimeIntegrationAux: unknown time integration order specified");
55 }
56}
57
58Real
60{
61 Real integral = getIntegralValue();
62
63 if (_order == 3)
64 return _u_older[_qp] + _coef * integral;
65
66 return _u_old[_qp] + _coef * integral;
67}
68
69Real
71{
72 Real integral_value = 0.0;
73
74 for (unsigned int i = 0; i < _order; ++i)
75 integral_value += _integration_coef[i] * (*_coupled_vars[i])[_qp] * _dt;
76
84 if (_order == 3 && _dt != _dt_old)
85 {
86 Real x0 = 0.0;
87 Real x1 = _dt_old;
88 Real x2 = _dt + _dt_old;
89 Real y0 = (*_coupled_vars[2])[_qp];
90 Real y1 = (*_coupled_vars[1])[_qp];
91 Real y2 = (*_coupled_vars[0])[_qp];
92 Real term1 = (x2 - x0) * (y0 + (x2 - x0) * (y1 - y0) / (2.0 * (x1 - x0)));
93 Real term2 = (2.0 * x2 * x2 - x0 * x2 - x0 * x0 + 3.0 * x0 * x1 - 3.0 * x1 * x2) / 6.0;
94 Real term3 = (y2 - y1) / (x2 - x1) - (y1 - y0) / (x1 - x0);
95 integral_value = term1 + term2 * term3;
96 }
97
98 return integral_value;
99}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", VariableTimeIntegrationAux)
void ErrorVector unsigned int
unsigned int _qp
Quadrature point index.
Definition AuxKernel.h:155
static InputParameters validParams()
Definition AuxKernel.C:27
virtual const VariableValue & coupledValueOld(const std::string &var_name, unsigned int comp=0) const
Returns an old value from previous time step of a coupled variable.
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0) const
Returns value of a coupled variable.
Definition Coupleable.C:528
virtual const VariableValue & coupledValueOlder(const std::string &var_name, unsigned int comp=0) const
Returns an old value from two time steps previous of a coupled variable.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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.
Real & _dt
Time step size.
Real & _dt_old
Size of the old time step.
An AuxKernel that can be used to integrate a field variable in time using a variety of different inte...
virtual Real computeValue() override
Compute and return the value of the aux variable.
VariableTimeIntegrationAux(const InputParameters &parameters)
static InputParameters validParams()
const VariableValue & _u_old
The old variable value (zero if order == 3)
const VariableValue & _u_older
The older variable value (zero if order != 3)
std::vector< const VariableValue * > _coupled_vars