Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
PiecewiseConstantByBlockMaterial.C
Go to the documentation of this file.
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 
11 
14 
15 template <bool is_ad>
18 {
19  auto params = Material::validParams();
20  params.addClassDescription("Computes a property value on a per-subdomain basis");
21  // Somehow min gcc doesn't know the type of params here
22  params.template addRequiredParam<MaterialPropertyName>("prop_name",
23  "The name of the property to declare");
24  params.template addRequiredParam<std::map<std::string, Real>>(
25  "subdomain_to_prop_value", "Map from subdomain to property value");
26  return params;
27 }
28 
29 template <bool is_ad>
31  const InputParameters & params)
32  : Material(params), _prop(declareGenericProperty<Real, is_ad>("prop_name"))
33 {
34  for (const auto & map_pr : getParam<std::map<std::string, Real>>("subdomain_to_prop_value"))
35  _sub_id_to_prop.emplace(std::make_pair(_mesh.getSubdomainID(map_pr.first), map_pr.second));
36 }
37 
38 template <bool is_ad>
39 void
41 {
42  mooseAssert(_current_elem,
43  "We should be on a block which means we should definitely have a current element");
44  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  _prop[_qp] = it->second;
49 }
50 
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unordered_map< SubdomainID, Real > _sub_id_to_prop
MooseMesh & _mesh
Definition: MaterialBase.h:326
static InputParameters validParams()
Definition: Material.C:14
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
virtual void computeQpProperties() override
Users must override this method.
registerMooseObject("MooseApp", PiecewiseConstantByBlockMaterial)
Materials compute MaterialProperties.
Definition: Material.h:34
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
PiecewiseConstantByBlockMaterialTempl(const InputParameters &parameters)
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Definition: MooseMesh.C:1728