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 
14 template <>
17 {
19  params.addRequiredCoupledVar("variable_to_integrate", "The variable to be integrated");
20  params.addParam<Real>("coefficient", 1.0, "A simple coefficient");
21  params.addParam<unsigned int>(
22  "order", 2, "The order of global truncation error: midpoint=1, trapazoidal=2, Simpson=3");
23  return params;
24 }
25 
27  : AuxKernel(parameters),
28  _coef(getParam<Real>("coefficient")),
29  _order(getParam<unsigned int>("order"))
30 {
31  switch (_order)
32  {
33  case 1:
34  _integration_coef.push_back(1.0);
35  _coupled_vars.push_back(&coupledValue("variable_to_integrate"));
36  break;
37  case 2:
38  _integration_coef.push_back(0.5);
39  _integration_coef.push_back(0.5);
40  _coupled_vars.push_back(&coupledValue("variable_to_integrate"));
41  _coupled_vars.push_back(&coupledValueOld("variable_to_integrate"));
42  break;
43  case 3:
44  _integration_coef.push_back(1.0 / 3.0);
45  _integration_coef.push_back(4.0 / 3.0);
46  _integration_coef.push_back(1.0 / 3.0);
47  _coupled_vars.push_back(&coupledValue("variable_to_integrate"));
48  _coupled_vars.push_back(&coupledValueOld("variable_to_integrate"));
49  _coupled_vars.push_back(&coupledValueOlder("variable_to_integrate"));
50  break;
51  default:
52  mooseError("VariableTimeIntegrationAux: unknown time integraiton order specfied");
53  }
54 }
55 
56 Real
58 {
59  Real integral = getIntegralValue();
60 
61  if (_order == 3)
62  return _u_older[_qp] + _coef * integral;
63 
64  return _u_old[_qp] + _coef * integral;
65 }
66 
67 Real
69 {
70  Real integral_value = 0.0;
71 
72  for (unsigned int i = 0; i < _order; ++i)
73  integral_value += _integration_coef[i] * (*_coupled_vars[i])[_qp] * _dt;
74 
82  if (_order == 3 && _dt != _dt_old)
83  {
84  Real x0 = 0.0;
85  Real x1 = _dt_old;
86  Real x2 = _dt + _dt_old;
87  Real y0 = (*_coupled_vars[2])[_qp];
88  Real y1 = (*_coupled_vars[1])[_qp];
89  Real y2 = (*_coupled_vars[0])[_qp];
90  Real term1 = (x2 - x0) * (y0 + (x2 - x0) * (y1 - y0) / (2.0 * (x1 - x0)));
91  Real term2 = (2.0 * x2 * x2 - x0 * x2 - x0 * x0 + 3.0 * x0 * x1 - 3.0 * x1 * x2) / 6.0;
92  Real term3 = (y2 - y1) / (x2 - x1) - (y1 - y0) / (x1 - x0);
93  integral_value = term1 + term2 * term3;
94  }
95 
96  return integral_value;
97 }
const OutputTools< ComputeValueType >::VariableValue & _u_older
Holds the t-2 solution at the current quadrature point.
Definition: AuxKernel.h:179
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...
const OutputTools< ComputeValueType >::VariableValue & _u_old
Holds the previous solution at the current quadrature point.
Definition: AuxKernel.h:176
Real & _dt
Time step size.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
VariableTimeIntegrationAux(const InputParameters &parameters)
registerMooseObject("MooseApp", VariableTimeIntegrationAux)
InputParameters validParams< VariableTimeIntegrationAux >()
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:25
std::vector< const VariableValue * > _coupled_vars
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0)
Returns value of a coupled variable.
Definition: Coupleable.C:361
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
virtual const VariableValue & coupledValueOld(const std::string &var_name, unsigned int comp=0)
Returns an old value from previous time step of a coupled variable.
Definition: Coupleable.C:457
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:219
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...
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:33
virtual const VariableValue & coupledValueOlder(const std::string &var_name, unsigned int comp=0)
Returns an old value from two time steps previous of a coupled variable.
Definition: Coupleable.C:484
An AuxKernel that can be used to integrate a field variable in time using a variety of different inte...