LCOV - code coverage report
Current view: top level - src/functormaterials - FunctorChangeFunctorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 36 38 94.7 %
Date: 2025-11-03 17:23:24 Functions: 6 24 25.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 "FunctorChangeFunctorMaterial.h"
      11             : 
      12             : registerMooseObject("MooseApp", FunctorChangeFunctorMaterial);
      13             : registerMooseObject("MooseApp", ADFunctorChangeFunctorMaterial);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17       29869 : FunctorChangeFunctorMaterialTempl<is_ad>::validParams()
      18             : {
      19       29869 :   InputParameters params = FunctorMaterial::validParams();
      20       89607 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
      21             : 
      22      119476 :   params.addRequiredParam<MooseFunctorName>("functor", "Functor for which to compute the change");
      23      119476 :   MooseEnum change_over("time_step nonlinear fixed_point");
      24      119476 :   change_over.addDocumentation("time_step", "Over the time step");
      25      119476 :   change_over.addDocumentation("nonlinear", "Over the nonlinear iteration");
      26      119476 :   change_over.addDocumentation("fixed_point", "Over the MultiApp fixed point iteration");
      27      119476 :   params.addRequiredParam<MooseEnum>(
      28             :       "change_over", change_over, "Interval over which to compute the change");
      29      119476 :   params.addRequiredParam<bool>("take_absolute_value",
      30             :                                 "If true, take the absolute value of the change.");
      31      119476 :   params.addRequiredParam<std::string>("prop_name",
      32             :                                        "The name to give the functor material property");
      33             : 
      34       29869 :   params.addClassDescription(
      35             :       "Adds a functor material property that computes the change in a functor value over a time "
      36             :       "step, fixed point iteration, or nonlinear iteration.");
      37             : 
      38       59738 :   return params;
      39       59738 : }
      40             : 
      41             : template <bool is_ad>
      42          70 : FunctorChangeFunctorMaterialTempl<is_ad>::FunctorChangeFunctorMaterialTempl(
      43             :     const InputParameters & parameters)
      44             :   : FunctorMaterial(parameters),
      45          70 :     _functor(getFunctor<GenericReal<is_ad>>("functor")),
      46         140 :     _ref_state(referenceState(getParam<MooseEnum>("change_over"))),
      47         140 :     _take_absolute_value(getParam<bool>("take_absolute_value")),
      48         210 :     _prop_name(getParam<std::string>("prop_name"))
      49             : {
      50          70 :   const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
      51          70 :   addFunctorProperty<GenericReal<is_ad>>(
      52             :       _prop_name,
      53        9164 :       [this](const auto & r, const auto & t) -> GenericReal<is_ad>
      54             :       {
      55             :         mooseAssert(t == Moose::currentState(),
      56             :                     "The functor properties defined by (AD)FunctorChangeFunctorMaterial objects "
      57             :                     "may only be evaluated at the current state.");
      58             : 
      59        9164 :         const auto change = _functor(r, t) - _functor(r, _ref_state);
      60        9164 :         if (_take_absolute_value)
      61             :         {
      62             :           using std::abs;
      63           0 :           return abs(change);
      64             :         }
      65             :         else
      66        9164 :           return change;
      67        9164 :       },
      68             :       clearance_schedule);
      69          70 : }
      70             : 
      71             : template <bool is_ad>
      72             : Moose::StateArg
      73          70 : FunctorChangeFunctorMaterialTempl<is_ad>::referenceState(const MooseEnum & change_over) const
      74             : {
      75          70 :   if (change_over == "time_step")
      76          14 :     return Moose::oldState();
      77          56 :   else if (change_over == "nonlinear")
      78             :   {
      79          14 :     _fe_problem.needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
      80          14 :     return Moose::previousNonlinearState();
      81             :   }
      82          42 :   else if (change_over == "fixed_point")
      83             :   {
      84          42 :     _fe_problem.needSolutionState(1, Moose::SolutionIterationType::FixedPoint);
      85          42 :     return Moose::previousFixedPointState();
      86             :   }
      87             :   else
      88           0 :     mooseError("Invalid value");
      89             : }
      90             : 
      91             : template class FunctorChangeFunctorMaterialTempl<false>;
      92             : template class FunctorChangeFunctorMaterialTempl<true>;

Generated by: LCOV version 1.14