www.mooseframework.org
VariableTimeIntegrationAux.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
58 Real
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 
69 Real
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 }
static InputParameters validParams()
virtual Real computeValue() override
Compute and return the value of the aux variable.
Real & _dt_old
Size of the old time step.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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.
Definition: Coupleable.C:981
Real & _dt
Time step size.
VariableTimeIntegrationAux(const InputParameters &parameters)
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.
Definition: Coupleable.C:1003
const VariableValue & _u_old
The old variable value (zero if order == 3)
const VariableValue & _u_older
The older variable value (zero if order != 3)
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0) const
Returns value of a coupled variable.
Definition: Coupleable.C:478
registerMooseObject("MooseApp", VariableTimeIntegrationAux)
std::vector< const VariableValue * > _coupled_vars
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:230
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 addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36
void ErrorVector unsigned int
An AuxKernel that can be used to integrate a field variable in time using a variety of different inte...