LCOV - code coverage report
Current view: top level - src/materials - GenericFunctionMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 29 31 93.5 %
Date: 2025-08-08 20:01:16 Functions: 9 10 90.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 "GenericFunctionMaterial.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", GenericFunctionMaterial);
      14             : registerMooseObject("MooseApp", ADGenericFunctionMaterial);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18       31420 : GenericFunctionMaterialTempl<is_ad>::validParams()
      19             : {
      20       31420 :   InputParameters params = Material::validParams();
      21       31420 :   params.addClassDescription("Material object for declaring properties that are populated by "
      22             :                              "evaluation of Function object.");
      23       31420 :   params.addParam<std::vector<std::string>>("prop_names",
      24             :                                             "The names of the properties this material will have");
      25       31420 :   params.addParam<std::vector<FunctionName>>("prop_values",
      26             :                                              "The corresponding names of the "
      27             :                                              "functions that are going to provide "
      28             :                                              "the values for the variables");
      29       31420 :   return params;
      30           0 : }
      31             : 
      32             : template <bool is_ad>
      33        2211 : GenericFunctionMaterialTempl<is_ad>::GenericFunctionMaterialTempl(
      34             :     const InputParameters & parameters)
      35             :   : Material(parameters),
      36        2211 :     _prop_names(getParam<std::vector<std::string>>("prop_names")),
      37        4422 :     _prop_values(getParam<std::vector<FunctionName>>("prop_values"))
      38             : {
      39        2211 :   unsigned int num_names = _prop_names.size();
      40        2211 :   unsigned int num_values = _prop_values.size();
      41             : 
      42        2211 :   if (num_names != num_values)
      43           0 :     mooseError(
      44             :         "Number of prop_names must match the number of prop_values for a GenericFunctionMaterial!");
      45             : 
      46        2211 :   _num_props = num_names;
      47             : 
      48        2211 :   _properties.resize(num_names);
      49        2211 :   _functions.resize(num_names);
      50             : 
      51        5292 :   for (unsigned int i = 0; i < _num_props; i++)
      52             :   {
      53        3081 :     _properties[i] = &declareGenericProperty<Real, is_ad>(_prop_names[i]);
      54        3081 :     _functions[i] = &getFunctionByName(_prop_values[i]);
      55             :   }
      56        2211 : }
      57             : 
      58             : template <bool is_ad>
      59             : void
      60      733644 : GenericFunctionMaterialTempl<is_ad>::initQpStatefulProperties()
      61             : {
      62      733644 :   computeQpFunctions();
      63      733644 : }
      64             : 
      65             : template <bool is_ad>
      66             : void
      67    11520394 : GenericFunctionMaterialTempl<is_ad>::computeQpProperties()
      68             : {
      69    11520394 :   computeQpFunctions();
      70    11520394 : }
      71             : 
      72             : template <bool is_ad>
      73             : void
      74    12254038 : GenericFunctionMaterialTempl<is_ad>::computeQpFunctions()
      75             : {
      76    24528228 :   for (unsigned int i = 0; i < _num_props; i++)
      77    12274190 :     (*_properties[i])[_qp] = (*_functions[i]).value(_t, _q_point[_qp]);
      78    12254038 : }
      79             : 
      80             : template class GenericFunctionMaterialTempl<false>;
      81             : template class GenericFunctionMaterialTempl<true>;

Generated by: LCOV version 1.14