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

Generated by: LCOV version 1.14