https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComponentMaterialPropertyInterface.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#include "Factory.h"
12#include "FEProblemBase.h"
13
16{
17 auto params = ActionComponent::validParams();
18 params.addParam<std::vector<std::string>>(
19 "property_names",
20 {},
21 "List of material properties that should be defined on this ActionComponent");
22 params.addParam<std::vector<MooseFunctorName>>(
23 "property_values",
24 {},
25 "Functors that provide the values of the material property on this ActionComponent");
26
27 // TODO: make the Physics set these three parameters
28 params.addParam<bool>("use_ad_for_properties",
29 true,
30 "Whether to use automatic differentiation for the properties defined");
31 params.addParam<bool>("define_material_properties",
32 true,
33 "If true, define material properties from the values provided");
34 params.addParam<bool>("define_functor_properties",
35 true,
36 "If true, define functor properties from the values provided");
37
38 params.addParamNamesToGroup("property_names property_values use_ad_for_properties "
39 "define_material_properties define_functor_properties",
40 "Material and Functor Property");
41 return params;
42}
43
45 const InputParameters & params)
46 : ActionComponent(params),
47 _property_names(getParam<std::vector<std::string>>("property_names")),
48 _property_functors(getParam<std::vector<MooseFunctorName>>("property_values")),
49 _use_ad_for_props(getParam<bool>("use_ad_for_properties"))
50{
51 addRequiredTask("add_material");
52 if (_property_names.size() != _property_functors.size())
53 paramError("property_names", "Should be the same size as property functors");
54}
55
56void
58{
59 if (getParam<bool>("define_material_properties") && _property_names.size())
60 {
61 // Add a material that makes material properties available on the blocks of the component.
62 // The idea is to make the values/functors available under the same property name across all
63 // components. Then the Physics / kernels can just use the name of the property
64 InputParameters params = getFactory().getValidParams("MaterialFunctorConverter");
65 params.set<std::vector<SubdomainName>>("block") = _blocks;
66
67 // Type conversion
68 std::vector<MaterialPropertyName> property_names(_property_names.size());
69 std::transform(_property_names.begin(),
70 _property_names.end(),
71 property_names.begin(),
72 [](const std::string & val) { return MaterialPropertyName(val); });
74 params.set<std::vector<MaterialPropertyName>>("ad_props_out") = property_names;
75 else
76 params.set<std::vector<MaterialPropertyName>>("reg_props_out") = property_names;
77 params.set<std::vector<MooseFunctorName>>("functors_in") = _property_functors;
79 "MaterialFunctorConverter", name() + "_local_material_properties", params);
80 }
81
82 // Add a functor material that makes the functor material properties on the blocks of the
83 // component. This makes the functors available under the same functor name across all components
84 if (getParam<bool>("define_functor_properties") && _property_names.size())
85 {
86 // Add a material that makes material properties available on the blocks of the component.
87 // The idea is to make the values/functors available under the same property name across all
88 // components. Then the Physics / kernels can just use the name of the property
89 const auto mat_type = _use_ad_for_props ? "ADGenericFunctorMaterial" : "GenericFunctorMaterial";
90 InputParameters params = getFactory().getValidParams(mat_type);
91 params.set<std::vector<SubdomainName>>("block") = _blocks;
92 params.set<std::vector<std::string>>("prop_names") = _property_names;
93 params.set<std::vector<MooseFunctorName>>("prop_values") = _property_functors;
94 getProblem().addMaterial(mat_type, name() + "_local_functor_properties", params);
95 }
96}
97
98bool
99ComponentMaterialPropertyInterface::hasProperty(const std::string & property_name) const
100{
101 return std::find(_property_names.begin(), _property_names.end(), property_name) !=
102 _property_names.end();
103}
104
106const MooseFunctorName &
108 const std::string & requestor_name) const
109{
110 for (const auto i : index_range(_property_names))
111 if (_property_names[i] == property_name)
112 return _property_functors[i];
113 mooseError("Property '",
114 property_name,
115 "' was requested on Component '",
116 name(),
117 "' by Physics '",
118 requestor_name,
119 "'");
120}
Base class for components that are defined using an action.
FEProblemBase & getProblem()
Get problem from action warehouse.
Factory & getFactory() const
Get the factory to build (often physics-related but not always) objects (for example a Positions)
void addRequiredTask(const std::string &task)
Add a new required task for all physics deriving from this class NOTE: This does not register the tas...
std::vector< SubdomainName > _blocks
Names of the blocks the component is comprised of.
static InputParameters validParams()
const bool _use_ad_for_props
Whether to use automatic differentiation when defining properties.
const MooseFunctorName & getPropertyValue(const std::string &property_name, const std::string &requestor_name) const
Return the name of the functor for that property.
bool hasProperty(const std::string &property_name) const
Whether the component has a property with that name.
ComponentMaterialPropertyInterface(const InputParameters &params)
const std::vector< MooseFunctorName > _property_functors
Functor values of the material properties.
const std::vector< std::string > _property_names
Names of the material properties.
virtual void addMaterials() override
Used to add materials or functor materials on a component.
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271