LCOV - code coverage report
Current view: top level - src/materials - FunctionMaterialBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 1f9d31 Lines: 39 42 92.9 %
Date: 2025-09-02 20:01:20 Functions: 6 6 100.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 "FunctionMaterialBase.h"
      11             : 
      12             : template <bool is_ad>
      13             : InputParameters
      14       91743 : FunctionMaterialBase<is_ad>::validParams()
      15             : {
      16       91743 :   InputParameters params = Material::validParams();
      17      183486 :   params.addClassDescription("Material providing a functionalized/parsed material property");
      18             : 
      19      550458 :   params.addDeprecatedParam<std::string>(
      20             :       "f_name", "Name of the parsed material property", "f_name is deprecated, use property_name");
      21             :   // TODO Make required once deprecation is handled, see #19119
      22      275229 :   params.addParam<std::string>("property_name", "F", "Name of the parsed material property");
      23       91743 :   return params;
      24           0 : }
      25             : 
      26             : template <bool is_ad>
      27        4713 : FunctionMaterialBase<is_ad>::FunctionMaterialBase(const InputParameters & parameters)
      28             :   : DerivativeMaterialInterface<Material>(parameters),
      29       18852 :     _F_name(getRenamedParam<std::string>("f_name", "property_name")),
      30        9426 :     _prop_F(&declareGenericProperty<Real, is_ad>(_F_name))
      31             : {
      32             :   // fetch names and numbers of all coupled variables
      33        4713 :   _mapping_is_unique = true;
      34        9990 :   for (const auto & var_param : _pars.getCoupledVariableParamNames())
      35             :   {
      36             :     // find the variable in the list of coupled variables
      37        5277 :     const auto it = _coupled_vars.find(var_param);
      38             : 
      39             :     // no MOOSE variable was provided for this coupling, add to a list of variables set to constant
      40             :     // default values
      41        5277 :     if (it == _coupled_vars.end())
      42             :     {
      43        1896 :       if (_pars.hasDefaultCoupledValue(var_param))
      44           0 :         _arg_constant_defaults.push_back(var_param);
      45        1896 :       continue;
      46             :     }
      47        3381 :     const auto & vars = it->second;
      48             : 
      49             :     // check if we have a 1:1 mapping between parameters and variables
      50        3381 :     if (vars.size() != 1)
      51         210 :       _mapping_is_unique = false;
      52             : 
      53             :     // iterate over all components
      54        7014 :     for (const auto comp : index_range(vars))
      55             :     {
      56             :       mooseAssert(vars[comp], "Null variable");
      57        3633 :       const auto & var_name = vars[comp]->name();
      58             :       // make sure each nonlinear variable is coupled in only once
      59        3633 :       if (std::find(_arg_names.begin(), _arg_names.end(), var_name) != _arg_names.end())
      60           0 :         mooseError("A nonlinear variable can only be coupled in once.");
      61             : 
      62             :       // insert the map values
      63        3633 :       const auto number = coupled(var_param, comp);
      64        3633 :       _arg_names.push_back(var_name);
      65        3633 :       _arg_numbers.push_back(number);
      66        3633 :       _arg_param_names.push_back(var_param);
      67        3633 :       if (_mapping_is_unique)
      68        3171 :         _arg_param_numbers.push_back(-1);
      69             :       else
      70         462 :         _arg_param_numbers.push_back(comp);
      71             : 
      72             :       // populate number -> arg index lookup table
      73        3633 :       const auto idx = libMeshVarNumberRemap(number);
      74        3633 :       if (idx >= _arg_index.size())
      75        3633 :         _arg_index.resize(idx + 1, -1);
      76             : 
      77        3633 :       _arg_index[idx] = _args.size();
      78             : 
      79             :       // get variable value
      80        3633 :       _args.push_back(&coupledGenericValue(var_param, comp));
      81             :     }
      82             :   }
      83             : 
      84        4713 :   _nargs = _arg_names.size();
      85        4713 : }
      86             : 
      87             : template <bool is_ad>
      88             : const GenericVariableValue<is_ad> &
      89        1950 : FunctionMaterialBase<is_ad>::coupledGenericValue(const std::string & var_name, unsigned int comp)
      90             : {
      91        1950 :   return coupledValue(var_name, comp);
      92             : }
      93             : 
      94             : template <>
      95             : const GenericVariableValue<true> &
      96        1683 : FunctionMaterialBase<true>::coupledGenericValue(const std::string & var_name, unsigned int comp)
      97             : {
      98        1683 :   return adCoupledValue(var_name, comp);
      99             : }
     100             : 
     101             : // explicit instantiation
     102             : template class FunctionMaterialBase<false>;
     103             : template class FunctionMaterialBase<true>;

Generated by: LCOV version 1.14