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 "PiecewiseConstantByBlockMaterial.h" 11 : 12 : registerMooseObject("MooseApp", PiecewiseConstantByBlockMaterial); 13 : registerMooseObject("MooseApp", ADPiecewiseConstantByBlockMaterial); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 28632 : PiecewiseConstantByBlockMaterialTempl<is_ad>::validParams() 18 : { 19 28632 : auto params = Material::validParams(); 20 28632 : params.addClassDescription("Computes a property value on a per-subdomain basis"); 21 : // Somehow min gcc doesn't know the type of params here 22 28632 : params.template addRequiredParam<MaterialPropertyName>("prop_name", 23 : "The name of the property to declare"); 24 28632 : params.template addRequiredParam<std::map<std::string, Real>>( 25 : "subdomain_to_prop_value", "Map from subdomain to property value"); 26 28632 : return params; 27 0 : } 28 : 29 : template <bool is_ad> 30 78 : PiecewiseConstantByBlockMaterialTempl<is_ad>::PiecewiseConstantByBlockMaterialTempl( 31 : const InputParameters & params) 32 78 : : Material(params), _prop(declareGenericProperty<Real, is_ad>("prop_name")) 33 : { 34 234 : for (const auto & map_pr : getParam<std::map<std::string, Real>>("subdomain_to_prop_value")) 35 156 : _sub_id_to_prop.emplace(std::make_pair(_mesh.getSubdomainID(map_pr.first), map_pr.second)); 36 78 : } 37 : 38 : template <bool is_ad> 39 : void 40 39544 : PiecewiseConstantByBlockMaterialTempl<is_ad>::computeQpProperties() 41 : { 42 : mooseAssert(_current_elem, 43 : "We should be on a block which means we should definitely have a current element"); 44 39544 : auto it = _sub_id_to_prop.find(_current_elem->subdomain_id()); 45 : mooseAssert(it != _sub_id_to_prop.end(), 46 : "Block restriction must match the subdomain names passed in the " 47 : "subdomain_to_prop_value parameter"); 48 39544 : _prop[_qp] = it->second; 49 39544 : } 50 : 51 : template class PiecewiseConstantByBlockMaterialTempl<false>; 52 : template class PiecewiseConstantByBlockMaterialTempl<true>;