Line data Source code
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 : 15 : registerMooseObject("MooseApp", PeriodicFunction); 16 : 17 : InputParameters 18 14390 : PeriodicFunction::validParams() 19 : { 20 14390 : InputParameters params = Function::validParams(); 21 14390 : params.addRequiredParam<FunctionName>( 22 : "base_function", "The function used as a basis for the generated periodic function."); 23 43170 : params.addRangeCheckedParam<Real>("period_time", 24 28780 : std::numeric_limits<Real>::max(), 25 : "period_time>0", 26 : "The period for repetition of the base function in time"); 27 43170 : params.addRangeCheckedParam<Real>( 28 : "period_x", 29 28780 : std::numeric_limits<Real>::max(), 30 : "period_x>0", 31 : "The period for repetition of the base function in the x direction"); 32 43170 : params.addRangeCheckedParam<Real>( 33 : "period_y", 34 28780 : std::numeric_limits<Real>::max(), 35 : "period_y>0", 36 : "The period for repetition of the base function in the y direction"); 37 43170 : params.addRangeCheckedParam<Real>( 38 : "period_z", 39 28780 : std::numeric_limits<Real>::max(), 40 : "period_z>0", 41 : "The period for repetition of the base function in the y direction"); 42 14390 : 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 14390 : return params; 46 0 : } 47 : 48 65 : PeriodicFunction::PeriodicFunction(const InputParameters & parameters) 49 : : Function(parameters), 50 : FunctionInterface(this), 51 65 : _base_function(getFunctionByName(getParam<FunctionName>("base_function"))), 52 65 : _period_time(getParam<Real>("period_time")), 53 65 : _period_x(getParam<Real>("period_x")), 54 65 : _period_y(getParam<Real>("period_y")), 55 130 : _period_z(getParam<Real>("period_z")) 56 : { 57 65 : } 58 : 59 : Real 60 790920 : PeriodicFunction::value(Real t, const Point & p) const 61 : { 62 790920 : return valueInternal(t, p); 63 : } 64 : 65 : ADReal 66 0 : PeriodicFunction::value(const ADReal & t, const ADPoint & p) const 67 : { 68 0 : return valueInternal(t, p); 69 : } 70 : 71 : template <typename T, typename P> 72 : T 73 790920 : PeriodicFunction::valueInternal(const T & t, const P & p) const 74 : { 75 790920 : T t_base = std::fmod(t, _period_time); 76 790920 : if (t_base < 0.0) 77 351520 : t_base += _period_time; 78 : 79 790920 : T x_base = std::fmod(p(0), _period_x); 80 790920 : if (x_base < 0.0) 81 365040 : x_base += _period_x; 82 : 83 790920 : T y_base = std::fmod(p(1), _period_y); 84 790920 : if (y_base < 0.0) 85 365040 : y_base += _period_y; 86 : 87 790920 : T z_base = std::fmod(p(2), _period_z); 88 790920 : if (z_base < 0.0) 89 365040 : z_base += _period_z; 90 : 91 790920 : P p_base(x_base, y_base, z_base); 92 : 93 1581840 : return _base_function.value(t_base, p_base); 94 0 : }