https://mooseframework.inl.gov
PeriodicFunction.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 
10 #include "PeriodicFunction.h"
11 #include "MooseUtils.h"
12 #include <iostream>
13 #include <limits>
14 
16 
19 {
21  params.addRequiredParam<FunctionName>(
22  "base_function", "The function used as a basis for the generated periodic function.");
23  params.addRangeCheckedParam<Real>("period_time",
25  "period_time>0",
26  "The period for repetition of the base function in time");
27  params.addRangeCheckedParam<Real>(
28  "period_x",
30  "period_x>0",
31  "The period for repetition of the base function in the x direction");
32  params.addRangeCheckedParam<Real>(
33  "period_y",
35  "period_y>0",
36  "The period for repetition of the base function in the y direction");
37  params.addRangeCheckedParam<Real>(
38  "period_z",
40  "period_z>0",
41  "The period for repetition of the base function in the y direction");
42  params.addClassDescription(
43  "Provides a periodic function by repeating a user-supplied base function in time and/or any "
44  "of the three Cartesian coordinate directions");
45  return params;
46 }
47 
49  : Function(parameters),
50  FunctionInterface(this),
51  _base_function(getFunctionByName(getParam<FunctionName>("base_function"))),
52  _period_time(getParam<Real>("period_time")),
53  _period_x(getParam<Real>("period_x")),
54  _period_y(getParam<Real>("period_y")),
55  _period_z(getParam<Real>("period_z"))
56 {
57 }
58 
59 Real
60 PeriodicFunction::value(Real t, const Point & p) const
61 {
62  return valueInternal(t, p);
63 }
64 
65 ADReal
66 PeriodicFunction::value(const ADReal & t, const ADPoint & p) const
67 {
68  return valueInternal(t, p);
69 }
70 
71 template <typename T, typename P>
72 T
73 PeriodicFunction::valueInternal(const T & t, const P & p) const
74 {
75  T t_base = std::fmod(t, _period_time);
76  if (t_base < 0.0)
77  t_base += _period_time;
78 
79  T x_base = std::fmod(p(0), _period_x);
80  if (x_base < 0.0)
81  x_base += _period_x;
82 
83  T y_base = std::fmod(p(1), _period_y);
84  if (y_base < 0.0)
85  y_base += _period_y;
86 
87  T z_base = std::fmod(p(2), _period_z);
88  if (z_base < 0.0)
89  z_base += _period_z;
90 
91  P p_base(x_base, y_base, z_base);
92 
93  return _base_function.value(t_base, p_base);
94 }
const Real _period_z
Period for repetition of the base function in the z direction.
Base class for function objects.
Definition: Function.h:36
T valueInternal(const T &t, const P &p) const
Templated function where the actual computation of the value as a function of time and spatial coordi...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:47
PeriodicFunction(const InputParameters &parameters)
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...
auto max(const L &left, const R &right)
const Real _period_y
Period for repetition of the base function in the y direction.
const Real _period_time
Period for repetition of the base function in time.
static InputParameters validParams()
const Function & _base_function
Function used as a basis for the periodic function.
registerMooseObject("MooseApp", PeriodicFunction)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real _period_x
Period for repetition of the base function in the x direction.
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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
virtual Real value(Real t, const Point &p) const
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...
Definition: Function.C:44
static InputParameters validParams()
Class constructor.
Definition: Function.C:16
Interface for objects that need to use functions.
virtual Real value(Real t, const Point &p) const override
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero...