LCOV - code coverage report
Current view: top level - src/functions - LinearCombinationFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 28 36 77.8 %
Date: 2025-08-08 20:01:16 Functions: 5 7 71.4 %
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 "LinearCombinationFunction.h"
      11             : 
      12             : registerMooseObject("MooseApp", LinearCombinationFunction);
      13             : 
      14             : InputParameters
      15       14352 : LinearCombinationFunction::validParams()
      16             : {
      17       14352 :   InputParameters params = Function::validParams();
      18       14352 :   params.addRequiredParam<std::vector<FunctionName>>(
      19             :       "functions", "This function will return Sum_over_i(w_i * functions_i)");
      20       14352 :   params.addRequiredParam<std::vector<Real>>(
      21             :       "w", "This function will return Sum_over_i(w_i * functions_i)");
      22       14352 :   params.addClassDescription("Returns the linear combination of the functions");
      23       14352 :   return params;
      24           0 : }
      25             : 
      26          47 : LinearCombinationFunction::LinearCombinationFunction(const InputParameters & parameters)
      27          47 :   : Function(parameters), FunctionInterface(this)
      28             : {
      29          47 :   const auto fname_w = getParam<FunctionName, Real>("functions", "w");
      30             : 
      31         171 :   for (const auto & fw : fname_w)
      32             :   {
      33         128 :     if (name() == fw.first)
      34           0 :       paramError("functions", "A LinearCombinationFunction must not reference itself");
      35             : 
      36         128 :     _fw.emplace_back(&getFunctionByName(fw.first), fw.second);
      37             :   }
      38          43 : }
      39             : 
      40             : Real
      41         418 : LinearCombinationFunction::value(Real t, const Point & p) const
      42             : {
      43         418 :   Real val = 0;
      44        2090 :   for (const auto & fw : _fw)
      45        1672 :     val += fw.first->value(t, p) * fw.second;
      46         418 :   return val;
      47             : }
      48             : 
      49             : ADReal
      50           0 : LinearCombinationFunction::value(const ADReal & t, const ADPoint & p) const
      51             : {
      52           0 :   ADReal val = 0.0;
      53           0 :   for (const auto & fw : _fw)
      54           0 :     val += fw.first->value(t, p) * fw.second;
      55           0 :   return val;
      56           0 : }
      57             : 
      58             : RealGradient
      59        2736 : LinearCombinationFunction::gradient(Real t, const Point & p) const
      60             : {
      61        2736 :   RealGradient g;
      62       10944 :   for (const auto & fw : _fw)
      63        8208 :     g += fw.first->gradient(t, p) * fw.second;
      64        2736 :   return g;
      65             : }
      66             : 
      67             : RealVectorValue
      68     1209600 : LinearCombinationFunction::vectorValue(Real t, const Point & p) const
      69             : {
      70     1209600 :   RealVectorValue v;
      71     3628800 :   for (const auto & fw : _fw)
      72     2419200 :     v += fw.first->vectorValue(t, p) * fw.second;
      73     1209600 :   return v;
      74             : }

Generated by: LCOV version 1.14