LCOV - code coverage report
Current view: top level - src/materials - CoupledValueFunctionMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 39 40 97.5 %
Date: 2025-07-17 01:28:37 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 "CoupledValueFunctionMaterial.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", CoupledValueFunctionMaterial);
      14             : registerMooseObject("MooseApp", ADCoupledValueFunctionMaterial);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18       28726 : CoupledValueFunctionMaterialTempl<is_ad>::validParams()
      19             : {
      20       28726 :   InputParameters params = Material::validParams();
      21       28726 :   params.addClassDescription("Compute a function value from coupled variables");
      22       28726 :   params.addRequiredParam<FunctionName>("function",
      23             :                                         "Coupled function to evaluate with values from v");
      24       28726 :   MultiMooseEnum parameter_order_enum("X Y Z T");
      25       28726 :   params.addParam<MultiMooseEnum>("parameter_order",
      26             :                                   parameter_order_enum,
      27             :                                   "If provided, an entry per couple variable specifies "
      28             :                                   "the function argument it should apply to.");
      29       28726 :   params.addRequiredParam<MaterialPropertyName>("prop_name", "Output property name");
      30       28726 :   params.addCoupledVar(
      31             :       "v",
      32             :       "List of up to four coupled variables that are substituted for x,y,z, and t "
      33             :       "in the coupled function (or the order chosen using the `parameter_order` parameter)");
      34       57452 :   return params;
      35       28726 : }
      36             : 
      37             : template <bool is_ad>
      38         152 : CoupledValueFunctionMaterialTempl<is_ad>::CoupledValueFunctionMaterialTempl(
      39             :     const InputParameters & parameters)
      40             :   : Material(parameters),
      41         152 :     _prop(declareGenericProperty<Real, is_ad>(getParam<MaterialPropertyName>("prop_name"))),
      42         152 :     _function(getFunction("function")),
      43         152 :     _vals(coupledGenericValues<is_ad>("v")),
      44         456 :     _nvals(coupledComponents("v"))
      45             : {
      46         152 :   if (_nvals > 4)
      47           0 :     paramError("v", "Couple a maximum of four variables");
      48             : 
      49         152 :   const auto & param_order = getParam<MultiMooseEnum>("parameter_order");
      50             : 
      51             :   // no custom order is specified, use x,y,z,t
      52         152 :   if (param_order.size() == 0)
      53         327 :     for (const auto i : make_range(_nvals))
      54         222 :       _order.push_back(i);
      55          47 :   else if (param_order.size() == _nvals)
      56             :   {
      57         215 :     for (const auto i : make_range(_nvals))
      58         172 :       _order.push_back(param_order.get(i));
      59             : 
      60          43 :     std::set<unsigned int> check_doubles(_order.begin(), _order.end());
      61          43 :     if (check_doubles.size() != _nvals)
      62           4 :       paramError("parameter_order", "You must not repeat any positions.");
      63          39 :   }
      64             :   else
      65           4 :     paramError("parameter_order",
      66             :                "Specify either as many items as coupled variables, or none at all for the default "
      67             :                "order of x,y,z,t.");
      68         144 : }
      69             : 
      70             : template <bool is_ad>
      71             : void
      72      472160 : CoupledValueFunctionMaterialTempl<is_ad>::computeQpProperties()
      73             : {
      74      472160 :   Moose::GenericType<Point, is_ad> p;
      75      472160 :   GenericReal<is_ad> t = 0.0;
      76             : 
      77     1067200 :   for (const auto i : make_range(_nvals))
      78             :   {
      79      595040 :     const auto & j = _order[i];
      80      595040 :     if (j < 3)
      81      554080 :       p(j) = (*_vals[i])[_qp];
      82             :     else
      83       40960 :       t = (*_vals[i])[_qp];
      84             :   }
      85             : 
      86      472160 :   _prop[_qp] = _function.value(t, p);
      87      472160 : }
      88             : 
      89             : template class CoupledValueFunctionMaterialTempl<false>;
      90             : template class CoupledValueFunctionMaterialTempl<true>;

Generated by: LCOV version 1.14