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 "ComponentMaterialPropertyInterface.h" 11 : #include "Factory.h" 12 : #include "FEProblemBase.h" 13 : 14 : InputParameters 15 550 : ComponentMaterialPropertyInterface::validParams() 16 : { 17 550 : auto params = ActionComponent::validParams(); 18 550 : params.addParam<std::vector<std::string>>( 19 : "property_names", 20 : {}, 21 : "List of material properties that should be defined on this ActionComponent"); 22 550 : 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 1650 : params.addParam<bool>("use_ad_for_properties", 29 1100 : true, 30 : "Whether to use automatic differentiation for the properties defined"); 31 1650 : params.addParam<bool>("define_material_properties", 32 1100 : true, 33 : "If true, define material properties from the values provided"); 34 1650 : params.addParam<bool>("define_functor_properties", 35 1100 : true, 36 : "If true, define functor properties from the values provided"); 37 : 38 550 : params.addParamNamesToGroup("property_names property_values use_ad_for_properties " 39 : "define_material_properties define_functor_properties", 40 : "Material and Functor Property"); 41 550 : return params; 42 0 : } 43 : 44 176 : ComponentMaterialPropertyInterface::ComponentMaterialPropertyInterface( 45 0 : const InputParameters & params) 46 : : ActionComponent(params), 47 176 : _property_names(getParam<std::vector<std::string>>("property_names")), 48 176 : _property_functors(getParam<std::vector<MooseFunctorName>>("property_values")), 49 352 : _use_ad_for_props(getParam<bool>("use_ad_for_properties")) 50 : { 51 176 : addRequiredTask("add_material"); 52 176 : if (_property_names.size() != _property_functors.size()) 53 4 : paramError("property_names", "Should be the same size as property functors"); 54 172 : } 55 : 56 : void 57 164 : ComponentMaterialPropertyInterface::addMaterials() 58 : { 59 164 : 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 56 : InputParameters params = getFactory().getValidParams("MaterialFunctorConverter"); 65 56 : params.set<std::vector<SubdomainName>>("block") = _blocks; 66 : 67 : // Type conversion 68 56 : std::vector<MaterialPropertyName> property_names(_property_names.size()); 69 56 : std::transform(_property_names.begin(), 70 : _property_names.end(), 71 : property_names.begin(), 72 56 : [](const std::string & val) { return MaterialPropertyName(val); }); 73 56 : if (_use_ad_for_props) 74 56 : params.set<std::vector<MaterialPropertyName>>("ad_props_out") = property_names; 75 : else 76 0 : params.set<std::vector<MaterialPropertyName>>("reg_props_out") = property_names; 77 56 : params.set<std::vector<MooseFunctorName>>("functors_in") = _property_functors; 78 112 : getProblem().addMaterial( 79 112 : "MaterialFunctorConverter", name() + "_local_material_properties", params); 80 56 : } 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 164 : 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 56 : const auto mat_type = _use_ad_for_props ? "ADGenericFunctorMaterial" : "GenericFunctorMaterial"; 90 56 : InputParameters params = getFactory().getValidParams(mat_type); 91 56 : params.set<std::vector<SubdomainName>>("block") = _blocks; 92 56 : params.set<std::vector<std::string>>("prop_names") = _property_names; 93 56 : params.set<std::vector<MooseFunctorName>>("prop_values") = _property_functors; 94 56 : getProblem().addMaterial(mat_type, name() + "_local_functor_properties", params); 95 56 : } 96 164 : } 97 : 98 : bool 99 0 : ComponentMaterialPropertyInterface::hasProperty(const std::string & property_name) const 100 : { 101 0 : return std::find(_property_names.begin(), _property_names.end(), property_name) != 102 0 : _property_names.end(); 103 : } 104 : 105 : /// Return the name of the functor for that property 106 : const MooseFunctorName & 107 0 : ComponentMaterialPropertyInterface::getPropertyValue(const std::string & property_name, 108 : const std::string & requestor_name) const 109 : { 110 0 : for (const auto i : index_range(_property_names)) 111 0 : if (_property_names[i] == property_name) 112 0 : return _property_functors[i]; 113 0 : mooseError("Property '", 114 : property_name, 115 : "' was requested on Component '", 116 0 : name(), 117 : "' by Physics '", 118 : requestor_name, 119 : "'"); 120 : }