https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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",
24 std::numeric_limits<Real>::max(),
25 "period_time>0",
26 "The period for repetition of the base function in time");
27 params.addRangeCheckedParam<Real>(
28 "period_x",
29 std::numeric_limits<Real>::max(),
30 "period_x>0",
31 "The period for repetition of the base function in the x direction");
32 params.addRangeCheckedParam<Real>(
33 "period_y",
34 std::numeric_limits<Real>::max(),
35 "period_y>0",
36 "The period for repetition of the base function in the y direction");
37 params.addRangeCheckedParam<Real>(
38 "period_z",
39 std::numeric_limits<Real>::max(),
40 "period_z>0",
41 "The period for repetition of the base function in the y direction");
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),
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
59Real
60PeriodicFunction::value(Real t, const Point & p) const
61{
62 return valueInternal(t, p);
63}
64
66PeriodicFunction::value(const ADReal & t, const ADPoint & p) const
67{
68 return valueInternal(t, p);
69}
70
71template <typename T, typename P>
72T
73PeriodicFunction::valueInternal(const T & t, const P & p) const
74{
75 using std::fmod;
76 T t_base = fmod(t, _period_time);
77 if (t_base < 0.0)
78 t_base += _period_time;
79
80 T x_base = fmod(p(0), _period_x);
81 if (x_base < 0.0)
82 x_base += _period_x;
83
84 T y_base = fmod(p(1), _period_y);
85 if (y_base < 0.0)
86 y_base += _period_y;
87
88 T z_base = fmod(p(2), _period_z);
89 if (z_base < 0.0)
90 z_base += _period_z;
91
92 P p_base(x_base, y_base, z_base);
93
94 return _base_function.value(t_base, p_base);
95}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("MooseApp", PeriodicFunction)
Interface for objects that need to use functions.
Base class for function objects.
Definition Function.h:30
static InputParameters validParams()
Class constructor.
Definition Function.C:16
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:30
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
PeriodicFunction(const InputParameters &parameters)
const Real _period_z
Period for repetition of the base function in the z direction.
static InputParameters validParams()
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...
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,...
const Real _period_y
Period for repetition of the base function in the y direction.
const Real _period_x
Period for repetition of the base function in the x direction.
const Function & _base_function
Function used as a basis for the periodic function.
const Real _period_time
Period for repetition of the base function in time.