LCOV - code coverage report
Current view: top level - src/functions - PiecewiseLinearFromVectorPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 39 46 84.8 %
Date: 2025-07-17 01:28:37 Functions: 4 8 50.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 "PiecewiseLinearFromVectorPostprocessor.h"
      11             : #include "FEProblemBase.h"
      12             : 
      13             : registerMooseObject("MooseApp", PiecewiseLinearFromVectorPostprocessor);
      14             : registerMooseObjectRenamed("MooseApp",
      15             :                            VectorPostprocessorFunction,
      16             :                            "02/03/2024 00:00",
      17             :                            PiecewiseLinearFromVectorPostprocessor);
      18             : 
      19             : InputParameters
      20       28630 : PiecewiseLinearFromVectorPostprocessor::validParams()
      21             : {
      22       28630 :   InputParameters params = Function::validParams();
      23       28630 :   params.addRequiredParam<VectorPostprocessorName>(
      24             :       "vectorpostprocessor_name", "The name of the VectorPostprocessor that you want to use");
      25       28630 :   params.addRequiredParam<std::string>(
      26             :       "argument_column",
      27             :       "VectorPostprocessor column tabulating the abscissa of the sampled function");
      28       28630 :   params.addRequiredParam<std::string>("value_column",
      29             :                                        "VectorPostprocessor column tabulating the "
      30             :                                        "ordinate (function values) of the sampled "
      31             :                                        "function");
      32       85890 :   params.addParam<bool>(
      33             :       "parallel_sync",
      34       57260 :       true,
      35             :       "Whether or not this Function should be synced to all processors when running in parallel.");
      36             : 
      37       28630 :   MooseEnum component("x=0 y=1 z=2 time=3", "time");
      38       28630 :   params.addParam<MooseEnum>(
      39             :       "component",
      40             :       component,
      41             :       "Component of the function evaluation point used to sample the VectorPostprocessor");
      42             : 
      43       28630 :   params.addClassDescription(
      44             :       "Provides piecewise linear interpolation of from two columns of a VectorPostprocessor");
      45             : 
      46       57260 :   return params;
      47       28630 : }
      48             : 
      49          52 : PiecewiseLinearFromVectorPostprocessor::PiecewiseLinearFromVectorPostprocessor(
      50          52 :     const InputParameters & parameters)
      51             :   : Function(parameters),
      52             :     VectorPostprocessorInterface(this),
      53          52 :     _argument_column(getVectorPostprocessorValue("vectorpostprocessor_name",
      54         104 :                                                  getParam<std::string>("argument_column"),
      55         104 :                                                  getParam<bool>("parallel_sync"))),
      56          52 :     _value_column(getVectorPostprocessorValue("vectorpostprocessor_name",
      57         104 :                                               getParam<std::string>("value_column"),
      58         104 :                                               getParam<bool>("parallel_sync"))),
      59          52 :     _component(getParam<MooseEnum>("component")),
      60          52 :     _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
      61         104 :     _last_update(
      62         104 :         {std::numeric_limits<Real>::lowest(), libMesh::invalid_uint, libMesh::invalid_uint})
      63             : {
      64             :   try
      65             :   {
      66          52 :     _linear_interp = std::make_unique<LinearInterpolation>(_argument_column, _value_column);
      67             :   }
      68           0 :   catch (std::domain_error & e)
      69             :   {
      70           0 :     mooseError("In PiecewiseLinearFromVectorPostprocessor ", _name, ": ", e.what());
      71           0 :   }
      72          52 : }
      73             : 
      74             : Real
      75         208 : PiecewiseLinearFromVectorPostprocessor::value(Real t, const Point & p) const
      76             : {
      77         208 :   return valueInternal(t, p);
      78             : }
      79             : 
      80             : ADReal
      81           0 : PiecewiseLinearFromVectorPostprocessor::value(const ADReal & t, const ADPoint & p) const
      82             : {
      83           0 :   return valueInternal(t, p);
      84             : }
      85             : 
      86             : template <typename T, typename P>
      87             : T
      88         208 : PiecewiseLinearFromVectorPostprocessor::valueInternal(const T & t, const P & p) const
      89             : {
      90         208 :   if (_argument_column.empty())
      91           0 :     return 0.0;
      92             : 
      93         208 :   const std::tuple<Real, unsigned int, unsigned int> now = {
      94         208 :       MetaPhysicL::raw_value(t),
      95         208 :       _fe_problem.nNonlinearIterations(/*nl_sys=*/0),
      96         208 :       _fe_problem.nLinearIterations(/*nl_sys=*/0)};
      97             : 
      98         208 :   if (now != _last_update)
      99             :   {
     100         100 :     _linear_interp->setData(_argument_column, _value_column);
     101         100 :     _last_update = now;
     102             :   }
     103             : 
     104         208 :   const T x = _component == 3 ? t : p(_component);
     105         208 :   return _linear_interp->sample(x);
     106           0 : }

Generated by: LCOV version 1.14