LCOV - code coverage report
Current view: top level - src/materials - GenericConstantMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 26 28 92.9 %
Date: 2025-07-17 01:28:37 Functions: 8 8 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 "GenericConstantMaterial.h"
      11             : 
      12             : registerMooseObject("MooseApp", GenericConstantMaterial);
      13             : registerMooseObject("MooseApp", ADGenericConstantMaterial);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17       68207 : GenericConstantMaterialTempl<is_ad>::validParams()
      18             : {
      19       68207 :   InputParameters params = Material::validParams();
      20       68207 :   params.addClassDescription(
      21             :       "Declares material properties based on names and values prescribed by input parameters.");
      22       68207 :   params.addRequiredParam<std::vector<std::string>>(
      23             :       "prop_names", "The names of the properties this material will have");
      24       68207 :   params.addRequiredParam<std::vector<Real>>("prop_values",
      25             :                                              "The values associated with the named properties");
      26       68207 :   params.set<MooseEnum>("constant_on") = "SUBDOMAIN";
      27       68207 :   params.declareControllable("prop_values");
      28       68207 :   return params;
      29           0 : }
      30             : 
      31             : template <bool is_ad>
      32        8420 : GenericConstantMaterialTempl<is_ad>::GenericConstantMaterialTempl(
      33             :     const InputParameters & parameters)
      34             :   : Material(parameters),
      35        8420 :     _prop_names(getParam<std::vector<std::string>>("prop_names")),
      36       16840 :     _prop_values(getParam<std::vector<Real>>("prop_values"))
      37             : {
      38        8420 :   unsigned int num_names = _prop_names.size();
      39        8420 :   unsigned int num_values = _prop_values.size();
      40             : 
      41        8420 :   if (num_names != num_values)
      42           0 :     mooseError(
      43             :         "Number of prop_names must match the number of prop_values for a GenericConstantMaterial!");
      44             : 
      45        8420 :   _num_props = num_names;
      46             : 
      47        8420 :   _properties.resize(num_names);
      48             : 
      49       19607 :   for (unsigned int i = 0; i < _num_props; i++)
      50       11187 :     _properties[i] = &declareGenericProperty<Real, is_ad>(_prop_names[i]);
      51        8420 : }
      52             : 
      53             : template <bool is_ad>
      54             : void
      55        4040 : GenericConstantMaterialTempl<is_ad>::initQpStatefulProperties()
      56             : {
      57        4040 :   computeQpProperties();
      58        4040 : }
      59             : 
      60             : template <bool is_ad>
      61             : void
      62     2004873 : GenericConstantMaterialTempl<is_ad>::computeQpProperties()
      63             : {
      64     5547629 :   for (unsigned int i = 0; i < _num_props; i++)
      65     3542756 :     (*_properties[i])[_qp] = _prop_values[i];
      66     2004873 : }
      67             : 
      68             : template class GenericConstantMaterialTempl<false>;
      69             : template class GenericConstantMaterialTempl<true>;

Generated by: LCOV version 1.14