https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15template <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
29template <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
38template <bool is_ad>
39void
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
registerMooseObject("MooseApp", PiecewiseConstantByBlockMaterial)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
MooseMesh & _mesh
Materials compute MaterialProperties.
Definition Material.h:36
static InputParameters validParams()
Definition Material.C:14
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Definition MooseMesh.C:1720
std::unordered_map< SubdomainID, Real > _sub_id_to_prop
PiecewiseConstantByBlockMaterialTempl(const InputParameters &parameters)
virtual void computeQpProperties() override
Users must override this method.