LCOV - code coverage report
Current view: top level - src/series - FunctionalBasisInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose functional_expansion_tools: #31405 (292dce) with base fef103 Lines: 45 51 88.2 %
Date: 2025-09-04 07:53:29 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         396 : FunctionalBasisInterface::FunctionalBasisInterface()
      21         396 :   : _is_cache_invalid(true), _is_generation(false)
      22             : {
      23         396 : }
      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         416 : FunctionalBasisInterface::FunctionalBasisInterface(const unsigned int number_of_terms)
      30         416 :   : _number_of_terms(number_of_terms),
      31         416 :     _is_cache_invalid(true),
      32         832 :     _basis_evaluation(_number_of_terms, 0.0),
      33         416 :     _is_generation(false)
      34             : {
      35             :   _basis_evaluation.shrink_to_fit();
      36         416 : }
      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      320284 : FunctionalBasisInterface::isGeneration() const
      46             : {
      47      320284 :   return _is_generation;
      48             : }
      49             : 
      50             : bool
      51      562045 : FunctionalBasisInterface::isExpansion() const
      52             : {
      53      562045 :   return !_is_generation;
      54             : }
      55             : 
      56             : const std::vector<Real> &
      57      562045 : FunctionalBasisInterface::getAllGeneration()
      58             : {
      59      562045 :   if (isExpansion() || isCacheInvalid())
      60             :   {
      61      562045 :     clearBasisEvaluation(_number_of_terms);
      62             : 
      63      562045 :     evaluateGeneration();
      64             : 
      65      562045 :     _is_generation = true;
      66      562045 :     _is_cache_invalid = false;
      67             :   }
      68             : 
      69      562045 :   return _basis_evaluation;
      70             : }
      71             : 
      72             : const std::vector<Real> &
      73      320284 : FunctionalBasisInterface::getAllExpansion()
      74             : {
      75      320284 :   if (isGeneration() || isCacheInvalid())
      76             :   {
      77      320284 :     clearBasisEvaluation(_number_of_terms);
      78             : 
      79      320284 :     evaluateExpansion();
      80             : 
      81      320284 :     _is_generation = false;
      82      320284 :     _is_cache_invalid = false;
      83             :   }
      84             : 
      85      320284 :   return _basis_evaluation;
      86             : }
      87             : 
      88             : std::size_t
      89     2871966 : FunctionalBasisInterface::getNumberOfTerms() const
      90             : {
      91     2871966 :   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      386623 : FunctionalBasisInterface::load(std::size_t index) const
     134             : {
     135      386623 :   return _basis_evaluation[index];
     136             : }
     137             : 
     138             : void
     139     4192692 : FunctionalBasisInterface::save(std::size_t index, Real value)
     140             : {
     141     4192692 :   _basis_evaluation[index] = value;
     142     4192692 : }
     143             : 
     144             : void
     145      882721 : FunctionalBasisInterface::clearBasisEvaluation(const unsigned int & number_of_terms)
     146             : {
     147      882721 :   _basis_evaluation.assign(number_of_terms, 0.0);
     148             :   _basis_evaluation.shrink_to_fit();
     149      882721 : }

Generated by: LCOV version 1.14