LCOV - code coverage report
Current view: top level - src/materials - GenericConstantStdVectorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 30 36 83.3 %
Date: 2025-09-22 20:01:15 Functions: 8 10 80.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 "GenericConstantStdVectorMaterial.h"
      11             : 
      12             : registerMooseObject("MooseApp", GenericConstantStdVectorMaterial);
      13             : registerMooseObject("MooseApp", ADGenericConstantStdVectorMaterial);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17       29600 : GenericConstantStdVectorMaterialTempl<is_ad>::validParams()
      18             : {
      19             : 
      20       29600 :   InputParameters params = Material::validParams();
      21       59200 :   params.addClassDescription("Declares material properties based on names and vector values "
      22             :                              "prescribed by input parameters.");
      23      118400 :   params.addRequiredParam<std::vector<std::string>>(
      24             :       "prop_names", "The names of the properties this material will have");
      25      118400 :   params.addRequiredParam<std::vector<std::vector<Real>>>(
      26             :       "prop_values", "The values associated with the named properties. ");
      27       88800 :   params.set<MooseEnum>("constant_on") = "SUBDOMAIN";
      28       29600 :   return params;
      29           0 : }
      30             : 
      31             : template <bool is_ad>
      32          84 : GenericConstantStdVectorMaterialTempl<is_ad>::GenericConstantStdVectorMaterialTempl(
      33             :     const InputParameters & parameters)
      34             :   : Material(parameters),
      35             :     VariableSizeMaterialPropertiesInterface(parameters),
      36          84 :     _prop_names(getParam<std::vector<std::string>>("prop_names")),
      37         336 :     _prop_values(getParam<std::vector<std::vector<Real>>>("prop_values"))
      38             : {
      39          84 :   const auto num_names = _prop_names.size();
      40          84 :   const auto num_values = _prop_values.size();
      41          84 :   if (num_names != num_values)
      42           0 :     paramError("prop_values",
      43             :                "Number of vector property names (" + std::to_string(num_names) +
      44             :                    ") does not match the number of vectors of property values (" +
      45             :                    std::to_string(num_values) + ")");
      46             : 
      47          84 :   _num_props = num_names;
      48          84 :   _properties.resize(num_names);
      49             : 
      50         252 :   for (const auto i : make_range(_num_props))
      51         168 :     _properties[i] = &declareGenericProperty<std::vector<Real>, is_ad>(_prop_names[i]);
      52          84 : }
      53             : 
      54             : template <bool is_ad>
      55             : void
      56           0 : GenericConstantStdVectorMaterialTempl<is_ad>::initQpStatefulProperties()
      57             : {
      58           0 :   computeQpProperties();
      59           0 : }
      60             : 
      61             : template <bool is_ad>
      62             : void
      63          56 : GenericConstantStdVectorMaterialTempl<is_ad>::computeQpProperties()
      64             : {
      65         168 :   for (unsigned int i = 0; i < _num_props; i++)
      66             :   {
      67         112 :     auto & prop_out = (*_properties[i])[_qp];
      68         112 :     const auto & prop_in = _prop_values[i];
      69         112 :     prop_out.resize(prop_in.size());
      70         392 :     for (const auto j : index_range(prop_in))
      71         280 :       prop_out[j] = prop_in[j];
      72             :   }
      73          56 : }
      74             : 
      75             : template <bool is_ad>
      76             : std::size_t
      77         104 : GenericConstantStdVectorMaterialTempl<is_ad>::getVectorPropertySize(
      78             :     const MaterialPropertyName & prop_name) const
      79             : {
      80         156 :   for (const auto i : index_range(_prop_names))
      81         156 :     if (_prop_names[i] == prop_name)
      82         104 :       return _prop_values[i].size();
      83           0 :   paramError("prop_names", "Property '" + prop_name + "' was not defined");
      84             : }
      85             : 
      86             : template class GenericConstantStdVectorMaterialTempl<false>;
      87             : template class GenericConstantStdVectorMaterialTempl<true>;

Generated by: LCOV version 1.14