LCOV - code coverage report
Current view: top level - src/functions - PeriodicFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 37 41 90.2 %
Date: 2025-08-08 20:01:16 Functions: 4 8 50.0 %
Legend: Lines: hit not hit

          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       14400 : PeriodicFunction::validParams()
      19             : {
      20       14400 :   InputParameters params = Function::validParams();
      21       14400 :   params.addRequiredParam<FunctionName>(
      22             :       "base_function", "The function used as a basis for the generated periodic function.");
      23       43200 :   params.addRangeCheckedParam<Real>("period_time",
      24       28800 :                                     std::numeric_limits<Real>::max(),
      25             :                                     "period_time>0",
      26             :                                     "The period for repetition of the base function in time");
      27       43200 :   params.addRangeCheckedParam<Real>(
      28             :       "period_x",
      29       28800 :       std::numeric_limits<Real>::max(),
      30             :       "period_x>0",
      31             :       "The period for repetition of the base function in the x direction");
      32       43200 :   params.addRangeCheckedParam<Real>(
      33             :       "period_y",
      34       28800 :       std::numeric_limits<Real>::max(),
      35             :       "period_y>0",
      36             :       "The period for repetition of the base function in the y direction");
      37       43200 :   params.addRangeCheckedParam<Real>(
      38             :       "period_z",
      39       28800 :       std::numeric_limits<Real>::max(),
      40             :       "period_z>0",
      41             :       "The period for repetition of the base function in the y direction");
      42       14400 :   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       14400 :   return params;
      46           0 : }
      47             : 
      48          70 : PeriodicFunction::PeriodicFunction(const InputParameters & parameters)
      49             :   : Function(parameters),
      50             :     FunctionInterface(this),
      51          70 :     _base_function(getFunctionByName(getParam<FunctionName>("base_function"))),
      52          70 :     _period_time(getParam<Real>("period_time")),
      53          70 :     _period_x(getParam<Real>("period_x")),
      54          70 :     _period_y(getParam<Real>("period_y")),
      55         140 :     _period_z(getParam<Real>("period_z"))
      56             : {
      57          70 : }
      58             : 
      59             : Real
      60      889785 : PeriodicFunction::value(Real t, const Point & p) const
      61             : {
      62      889785 :   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      889785 : PeriodicFunction::valueInternal(const T & t, const P & p) const
      74             : {
      75      889785 :   T t_base = std::fmod(t, _period_time);
      76      889785 :   if (t_base < 0.0)
      77      395460 :     t_base += _period_time;
      78             : 
      79      889785 :   T x_base = std::fmod(p(0), _period_x);
      80      889785 :   if (x_base < 0.0)
      81      410670 :     x_base += _period_x;
      82             : 
      83      889785 :   T y_base = std::fmod(p(1), _period_y);
      84      889785 :   if (y_base < 0.0)
      85      410670 :     y_base += _period_y;
      86             : 
      87      889785 :   T z_base = std::fmod(p(2), _period_z);
      88      889785 :   if (z_base < 0.0)
      89      410670 :     z_base += _period_z;
      90             : 
      91      889785 :   P p_base(x_base, y_base, z_base);
      92             : 
      93     1779570 :   return _base_function.value(t_base, p_base);
      94           0 : }

Generated by: LCOV version 1.14