LCOV - code coverage report
Current view: top level - src/functions - LinearCombinationFunction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 28 36 77.8 %
Date: 2025-07-17 01:28:37 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       14346 : LinearCombinationFunction::validParams()
      16             : {
      17       14346 :   InputParameters params = Function::validParams();
      18       14346 :   params.addRequiredParam<std::vector<FunctionName>>(
      19             :       "functions", "This function will return Sum_over_i(w_i * functions_i)");
      20       14346 :   params.addRequiredParam<std::vector<Real>>(
      21             :       "w", "This function will return Sum_over_i(w_i * functions_i)");
      22       14346 :   params.addClassDescription("Returns the linear combination of the functions");
      23       14346 :   return params;
      24           0 : }
      25             : 
      26          44 : LinearCombinationFunction::LinearCombinationFunction(const InputParameters & parameters)
      27          44 :   : Function(parameters), FunctionInterface(this)
      28             : {
      29          44 :   const auto fname_w = getParam<FunctionName, Real>("functions", "w");
      30             : 
      31         159 :   for (const auto & fw : fname_w)
      32             :   {
      33         119 :     if (name() == fw.first)
      34           0 :       paramError("functions", "A LinearCombinationFunction must not reference itself");
      35             : 
      36         119 :     _fw.emplace_back(&getFunctionByName(fw.first), fw.second);
      37             :   }
      38          40 : }
      39             : 
      40             : Real
      41         352 : LinearCombinationFunction::value(Real t, const Point & p) const
      42             : {
      43         352 :   Real val = 0;
      44        1760 :   for (const auto & fw : _fw)
      45        1408 :     val += fw.first->value(t, p) * fw.second;
      46         352 :   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        2304 : LinearCombinationFunction::gradient(Real t, const Point & p) const
      60             : {
      61        2304 :   RealGradient g;
      62        9216 :   for (const auto & fw : _fw)
      63        6912 :     g += fw.first->gradient(t, p) * fw.second;
      64        2304 :   return g;
      65             : }
      66             : 
      67             : RealVectorValue
      68     1075200 : LinearCombinationFunction::vectorValue(Real t, const Point & p) const
      69             : {
      70     1075200 :   RealVectorValue v;
      71     3225600 :   for (const auto & fw : _fw)
      72     2150400 :     v += fw.first->vectorValue(t, p) * fw.second;
      73     1075200 :   return v;
      74             : }

Generated by: LCOV version 1.14