LCOV - code coverage report
Current view: top level - src/functormaterials - GenericFunctorTimeDerivativeMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 27 30 90.0 %
Date: 2025-07-17 01:28:37 Functions: 5 22 22.7 %
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 "GenericFunctorTimeDerivativeMaterial.h"
      11             : 
      12             : registerMooseObject("MooseApp", GenericFunctorTimeDerivativeMaterial);
      13             : registerMooseObject("MooseApp", ADGenericFunctorTimeDerivativeMaterial);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17       28555 : GenericFunctorTimeDerivativeMaterialTempl<is_ad>::validParams()
      18             : {
      19       28555 :   InputParameters params = FunctorMaterial::validParams();
      20       57110 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS};
      21       28555 :   params.addClassDescription(
      22             :       "FunctorMaterial object for declaring properties that are populated by evaluation of "
      23             :       "time derivatives of Functors objects. (such as variables, constants, postprocessors). "
      24             :       "The time derivative is only returned if the 'dot' functor routine is implemented.");
      25       28555 :   params.addParam<std::vector<std::string>>("prop_names",
      26             :                                             "The names of the properties this material will have");
      27             : 
      28       28555 :   params.addParam<std::vector<MooseFunctorName>>("prop_values",
      29             :                                                  "The corresponding names of the "
      30             :                                                  "functors which gradient are going to provide "
      31             :                                                  "the values for the variables");
      32       28555 :   return params;
      33       28555 : }
      34             : 
      35             : template <bool is_ad>
      36          13 : GenericFunctorTimeDerivativeMaterialTempl<is_ad>::GenericFunctorTimeDerivativeMaterialTempl(
      37             :     const InputParameters & parameters)
      38             :   : FunctorMaterial(parameters),
      39          13 :     _prop_names(getParam<std::vector<std::string>>("prop_names")),
      40          13 :     _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values")),
      41          26 :     _num_props(_prop_names.size())
      42             : {
      43          13 :   unsigned int num_values = _prop_values.size();
      44             : 
      45          13 :   if (_num_props != num_values)
      46           0 :     mooseError("Number of prop_names must match the number of prop_values for a "
      47             :                "GenericFunctorTimeDerivativeMaterial!");
      48             : 
      49             :   // Check that there is no name conflict, a common mistake with this object
      50          65 :   for (const auto i : make_range(_num_props))
      51         260 :     for (const auto j : make_range(num_values))
      52         208 :       if (_prop_names[i] == _prop_values[j])
      53           0 :         paramError("prop_names",
      54             :                    "prop_names should not be the same as any of the prop_values. They"
      55             :                    " can both be functors, and functors may not have the same name.");
      56             : 
      57          13 :   _functors.resize(_num_props);
      58             : 
      59          65 :   for (const auto i : make_range(_num_props))
      60             :   {
      61          52 :     if (_fe_problem.hasPostprocessor(_prop_values[i]))
      62           0 :       paramError("prop_names", "Postprocessors should not be used in this functor material");
      63          52 :     _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]);
      64             :   }
      65             : 
      66          13 :   const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end());
      67          65 :   for (const auto i : make_range(_num_props))
      68          52 :     addFunctorProperty<GenericReal<is_ad>>(
      69             :         _prop_names[i],
      70         768 :         [this, i](const auto & r, const auto & t) -> GenericReal<is_ad>
      71         768 :         { return (*_functors[i]).dot(r, t); },
      72             :         clearance_schedule);
      73          13 : }
      74             : 
      75             : template class GenericFunctorTimeDerivativeMaterialTempl<false>;
      76             : template class GenericFunctorTimeDerivativeMaterialTempl<true>;

Generated by: LCOV version 1.14