LCOV - code coverage report
Current view: top level - src/functions - CompositeFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 23 39 59.0 %
Date: 2025-07-17 01:28:37 Functions: 3 5 60.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 "CompositeFunction.h"
      11             : 
      12             : registerMooseObject("MooseApp", CompositeFunction);
      13             : 
      14             : InputParameters
      15       14361 : CompositeFunction::validParams()
      16             : {
      17       14361 :   InputParameters params = Function::validParams();
      18       14361 :   params.addParam<std::vector<FunctionName>>("functions",
      19             :                                              "The functions to be multiplied together.");
      20       14361 :   params.addParam<Real>("scale_factor", 1.0, "Scale factor to be applied to the ordinate values");
      21       14361 :   params.addClassDescription("Multiplies an arbitrary set of functions together");
      22       14361 :   return params;
      23           0 : }
      24             : 
      25          50 : CompositeFunction::CompositeFunction(const InputParameters & parameters)
      26          50 :   : Function(parameters), FunctionInterface(this), _scale_factor(getParam<Real>("scale_factor"))
      27             : {
      28             : 
      29          50 :   const std::vector<FunctionName> & names = getParam<std::vector<FunctionName>>("functions");
      30          50 :   const unsigned int len = names.size();
      31          50 :   if (len == 0)
      32           0 :     mooseError("A composite function must reference at least one other function");
      33             : 
      34          50 :   _f.resize(len);
      35             : 
      36         150 :   for (unsigned i = 0; i < len; ++i)
      37             :   {
      38         100 :     if (name() == names[i])
      39           0 :       mooseError("A composite function must not reference itself");
      40             : 
      41         100 :     const Function * f = &getFunctionByName(names[i]);
      42         100 :     if (!f)
      43             :     {
      44           0 :       std::string msg("Error in composite function ");
      45           0 :       msg += name();
      46           0 :       msg += ".  Function ";
      47           0 :       msg += names[i];
      48           0 :       msg += " referenced but not found.";
      49           0 :       mooseError(msg);
      50           0 :     }
      51         100 :     _f[i] = f;
      52             :   }
      53          50 : }
      54             : 
      55             : Real
      56    28530336 : CompositeFunction::value(Real t, const Point & p) const
      57             : {
      58    28530336 :   Real val = _scale_factor;
      59             : 
      60    85591008 :   for (const auto & func : _f)
      61    57060672 :     val *= func->value(t, p);
      62             : 
      63    28530336 :   return val;
      64             : }
      65             : 
      66             : ADReal
      67           0 : CompositeFunction::value(const ADReal & t, const ADPoint & p) const
      68             : {
      69           0 :   ADReal val = _scale_factor;
      70             : 
      71           0 :   for (const auto & func : _f)
      72           0 :     val *= func->value(t, p);
      73             : 
      74           0 :   return val;
      75           0 : }

Generated by: LCOV version 1.14