LCOV - code coverage report
Current view: top level - src/series - FunctionalBasisInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose functional_expansion_tools: #32971 (54bef8) with base c6cf66 Lines: 45 51 88.2 %
Date: 2026-05-29 20:36:43 Functions: 12 15 80.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 "FunctionalBasisInterface.h"
      11             : 
      12             : MooseEnum FunctionalBasisInterface::_domain_options("x=0 y=1 z=2");
      13             : 
      14             : /*
      15             :  * The default constructor is used to initialize a series before knowing the number of terms in the
      16             :  * series. This is called from the CSBI, and in the body of the CSBI constructor, setNumberOfTerms()
      17             :  * is used to after-the-fact perform the same initializations that would be done with the
      18             :  * non-default constructor.
      19             :  */
      20         208 : FunctionalBasisInterface::FunctionalBasisInterface()
      21         208 :   : _is_cache_invalid(true), _is_generation(false)
      22             : {
      23         208 : }
      24             : 
      25             : /*
      26             :  * The non-default constructor should be used to initialize a series if the number of terms is
      27             :  * known, such as with a single series.
      28             :  */
      29         228 : FunctionalBasisInterface::FunctionalBasisInterface(const unsigned int number_of_terms)
      30         228 :   : _number_of_terms(number_of_terms),
      31         228 :     _is_cache_invalid(true),
      32         456 :     _basis_evaluation(_number_of_terms, 0.0),
      33         228 :     _is_generation(false)
      34             : {
      35             :   _basis_evaluation.shrink_to_fit();
      36         228 : }
      37             : 
      38             : Real
      39           0 : FunctionalBasisInterface::operator[](std::size_t index) const
      40             : {
      41           0 :   return (index > _basis_evaluation.size() ? 0.0 : _basis_evaluation[index]);
      42             : }
      43             : 
      44             : bool
      45      213832 : FunctionalBasisInterface::isGeneration() const
      46             : {
      47      213832 :   return _is_generation;
      48             : }
      49             : 
      50             : bool
      51      375181 : FunctionalBasisInterface::isExpansion() const
      52             : {
      53      375181 :   return !_is_generation;
      54             : }
      55             : 
      56             : const std::vector<Real> &
      57      375181 : FunctionalBasisInterface::getAllGeneration()
      58             : {
      59      375181 :   if (isExpansion() || isCacheInvalid())
      60             :   {
      61      375181 :     clearBasisEvaluation(_number_of_terms);
      62             : 
      63      375181 :     evaluateGeneration();
      64             : 
      65      375181 :     _is_generation = true;
      66      375181 :     _is_cache_invalid = false;
      67             :   }
      68             : 
      69      375181 :   return _basis_evaluation;
      70             : }
      71             : 
      72             : const std::vector<Real> &
      73      213832 : FunctionalBasisInterface::getAllExpansion()
      74             : {
      75      213832 :   if (isGeneration() || isCacheInvalid())
      76             :   {
      77      213832 :     clearBasisEvaluation(_number_of_terms);
      78             : 
      79      213832 :     evaluateExpansion();
      80             : 
      81      213832 :     _is_generation = false;
      82      213832 :     _is_cache_invalid = false;
      83             :   }
      84             : 
      85      213832 :   return _basis_evaluation;
      86             : }
      87             : 
      88             : std::size_t
      89     1938230 : FunctionalBasisInterface::getNumberOfTerms() const
      90             : {
      91     1938230 :   return _number_of_terms;
      92             : }
      93             : 
      94             : Real
      95           0 : FunctionalBasisInterface::getGeneration()
      96             : {
      97             :   // Use getAllGeneration() which will lazily evaluate the series as needed
      98           0 :   return getAllGeneration().back();
      99             : }
     100             : 
     101             : Real
     102           6 : FunctionalBasisInterface::getGenerationSeriesSum()
     103             : {
     104             :   Real sum = 0.0;
     105             : 
     106             :   // Use getAllGeneration() which will lazily evaluate the series as needed
     107       30984 :   for (auto term : getAllGeneration())
     108       30978 :     sum += term;
     109             : 
     110           6 :   return sum;
     111             : }
     112             : 
     113             : Real
     114           0 : FunctionalBasisInterface::getExpansion()
     115             : {
     116             :   // Use getAllExpansion() which will lazily evaluate the series as needed
     117           0 :   return getAllExpansion().back();
     118             : }
     119             : 
     120             : Real
     121           8 : FunctionalBasisInterface::getExpansionSeriesSum()
     122             : {
     123             :   Real sum = 0.0;
     124             : 
     125             :   // Use getAllExpansion() which will lazily evaluate the series as needed
     126       31211 :   for (auto term : getAllExpansion())
     127       31203 :     sum += term;
     128             : 
     129           8 :   return sum;
     130             : }
     131             : 
     132             : Real
     133      258559 : FunctionalBasisInterface::load(std::size_t index) const
     134             : {
     135      258559 :   return _basis_evaluation[index];
     136             : }
     137             : 
     138             : void
     139     2820360 : FunctionalBasisInterface::save(std::size_t index, Real value)
     140             : {
     141     2820360 :   _basis_evaluation[index] = value;
     142     2820360 : }
     143             : 
     144             : void
     145      589217 : FunctionalBasisInterface::clearBasisEvaluation(const unsigned int & number_of_terms)
     146             : {
     147      589217 :   _basis_evaluation.assign(number_of_terms, 0.0);
     148             :   _basis_evaluation.shrink_to_fit();
     149      589217 : }

Generated by: LCOV version 1.14