LCOV - code coverage report
Current view: top level - src/functions - PeriodicFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 37 41 90.2 %
Date: 2026-05-29 20:35:17 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        3186 : PeriodicFunction::validParams()
      19             : {
      20        3186 :   InputParameters params = Function::validParams();
      21       12744 :   params.addRequiredParam<FunctionName>(
      22             :       "base_function", "The function used as a basis for the generated periodic function.");
      23       15930 :   params.addRangeCheckedParam<Real>("period_time",
      24        6372 :                                     std::numeric_limits<Real>::max(),
      25             :                                     "period_time>0",
      26             :                                     "The period for repetition of the base function in time");
      27       15930 :   params.addRangeCheckedParam<Real>(
      28             :       "period_x",
      29        6372 :       std::numeric_limits<Real>::max(),
      30             :       "period_x>0",
      31             :       "The period for repetition of the base function in the x direction");
      32       15930 :   params.addRangeCheckedParam<Real>(
      33             :       "period_y",
      34        6372 :       std::numeric_limits<Real>::max(),
      35             :       "period_y>0",
      36             :       "The period for repetition of the base function in the y direction");
      37       15930 :   params.addRangeCheckedParam<Real>(
      38             :       "period_z",
      39        6372 :       std::numeric_limits<Real>::max(),
      40             :       "period_z>0",
      41             :       "The period for repetition of the base function in the y direction");
      42        3186 :   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        3186 :   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         130 :     _period_time(getParam<Real>("period_time")),
      53         130 :     _period_x(getParam<Real>("period_x")),
      54         130 :     _period_y(getParam<Real>("period_y")),
      55         195 :     _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             :   using std::fmod;
      76      790920 :   T t_base = fmod(t, _period_time);
      77      790920 :   if (t_base < 0.0)
      78      351520 :     t_base += _period_time;
      79             : 
      80      790920 :   T x_base = fmod(p(0), _period_x);
      81      790920 :   if (x_base < 0.0)
      82      365040 :     x_base += _period_x;
      83             : 
      84      790920 :   T y_base = fmod(p(1), _period_y);
      85      790920 :   if (y_base < 0.0)
      86      365040 :     y_base += _period_y;
      87             : 
      88      790920 :   T z_base = fmod(p(2), _period_z);
      89      790920 :   if (z_base < 0.0)
      90      365040 :     z_base += _period_z;
      91             : 
      92      790920 :   P p_base(x_base, y_base, z_base);
      93             : 
      94     1581840 :   return _base_function.value(t_base, p_base);
      95           0 : }

Generated by: LCOV version 1.14