26 #include "libmesh/utility.h" 35 params.
addClassDescription(
"Outputs material properties to various Outputs objects, based on the " 36 "parameters set in each Material");
41 params.
addParam<
bool>(
"print_automatic_aux_variable_creation",
43 "Flag to print list of aux variables created for automatic output by " 44 "MaterialOutputAction.");
50 _block_material_data(nullptr),
51 _boundary_material_data(nullptr),
52 _output_warehouse(_app.getOutputWarehouse()),
53 _output_only_on_timestep_end(_app.parameters().
get<bool>(
"use_legacy_material_output"))
61 "FEProblemBase pointer is nullptr, it is needed for auto material property output");
67 bool get_names_only =
_current_task ==
"add_output_aux_variables" ? true :
false;
75 const auto & material_ptrs =
_problem->getMaterialWarehouse().getObjects();
82 bool outputs_has_properties =
false;
83 std::set<std::string> output_object_properties;
86 for (
const auto &
act : output_actions)
97 params.
get<
bool>(
"output_material_properties"))
99 outputs_has_properties =
true;
100 std::vector<std::string> prop_names =
101 params.
get<std::vector<std::string>>(
"show_material_properties");
102 output_object_properties.insert(prop_names.begin(), prop_names.end());
107 std::set<std::string> material_names;
108 std::set<std::string> unsupported_names;
109 for (
const auto & mat : material_ptrs)
112 std::set<OutputName> outputs = mat->getOutputs();
115 std::vector<std::string> output_properties =
116 mat->getParam<std::vector<std::string>>(
"output_properties");
119 if (outputs_has_properties)
120 output_properties.insert(output_properties.end(),
121 output_object_properties.begin(),
122 output_object_properties.end());
134 if (outputs_has_properties || outputs.find(
"none") == outputs.end())
137 std::set<std::string> names = mat->getSuppliedItems();
138 if (
const auto fmat_ptr = dynamic_cast<const FunctorMaterial *>(mat.get()))
139 names.insert(fmat_ptr->getSuppliedFunctors().begin(),
140 fmat_ptr->getSuppliedFunctors().end());
142 for (
const auto &
name : names)
146 if (output_properties.empty() ||
147 std::find(output_properties.begin(), output_properties.end(),
name) !=
148 output_properties.end())
152 if (curr_material_names.size() == 0)
153 unsupported_names.insert(
name);
154 material_names.insert(curr_material_names.begin(), curr_material_names.end());
159 if (outputs.find(
"none") == outputs.end())
165 if (outputs.find(
"all") != outputs.end())
166 outputs = all_output_names;
170 for (
const auto & output_name : all_output_names)
172 if (outputs.find(output_name) != outputs.end())
180 else if (output_properties.size())
181 mooseWarning(
"Material properties output specified is not created because 'outputs' is not " 182 "set in the Material, and neither is Outputs/output_material_properties");
184 if (unsupported_names.size() > 0 && get_names_only &&
185 getParam<bool>(
"print_unsupported_prop_names"))
187 std::ostringstream oss;
188 for (
const auto &
name : unsupported_names)
189 oss <<
"\n " <<
name;
191 unsupported_names.size(),
192 " material properties:",
194 "\nare not supported for automatic output by ",
204 params.set<
MooseEnum>(
"family") =
"MONOMIAL";
207 std::ostringstream oss;
208 for (
const auto & var_name : material_names)
210 oss <<
"\n " << var_name;
211 if (
_problem->hasVariable(var_name))
212 mooseError(
"The material property output " + var_name +
213 " has the same name as an existing variable, either use the material" 214 " declare_suffix parameter to disambiguate or the output_properties parameter" 215 " to restrict the material properties to output");
216 _problem->addAuxVariable(
"MooseVariableConstMonomial", var_name, params);
219 if (material_names.size() > 0 && getParam<bool>(
"print_automatic_aux_variable_creation"))
220 _console << COLOR_CYAN <<
"The following total " << material_names.size()
221 <<
" aux variables:" << oss.str() <<
"\nare added for automatic output by " <<
type()
222 <<
"." << COLOR_DEFAULT << std::endl;
231 std::set<std::string> hide;
232 std::set_difference(material_names.begin(),
233 material_names.end(),
236 std::inserter(hide, hide.begin()));
243 std::vector<std::string>
248 std::vector<std::string> names;
251 if (hasProperty<Real>(property_name))
253 {
"MaterialRealAux",
"", {}}, property_name, property_name, material, get_names_only);
255 else if (hasADProperty<Real>(property_name))
257 {
"ADMaterialRealAux",
"", {}}, property_name, property_name, material, get_names_only);
259 else if (hasProperty<RealVectorValue>(property_name))
260 names =
outputHelper({
"MaterialRealVectorValueAux",
"xyz", {
"component"}},
266 else if (hasADProperty<RealVectorValue>(property_name))
267 names =
outputHelper({
"ADMaterialRealVectorValueAux",
"xyz", {
"component"}},
273 else if (
hasProperty<std::vector<Real>>(property_name))
274 names =
outputHelper({
"MaterialStdVectorAux",
"variable_size", {
"index"}},
281 names =
outputHelper({
"ADMaterialStdVectorAux",
"variable_size", {
"index"}},
287 else if (hasProperty<RealTensorValue>(property_name))
288 names =
outputHelper({
"MaterialRealTensorValueAux",
"012", {
"row",
"column"}},
294 else if (hasADProperty<RealTensorValue>(property_name))
295 names =
outputHelper({
"ADMaterialRealTensorValueAux",
"012", {
"row",
"column"}},
301 else if (hasProperty<RankTwoTensor>(property_name))
302 names =
outputHelper({
"MaterialRankTwoTensorAux",
"012", {
"i",
"j"}},
308 else if (hasADProperty<RankTwoTensor>(property_name))
309 names =
outputHelper({
"ADMaterialRankTwoTensorAux",
"012", {
"i",
"j"}},
315 else if (hasProperty<RankFourTensor>(property_name))
316 names =
outputHelper({
"MaterialRankFourTensorAux",
"012", {
"i",
"j",
"k",
"l"}},
322 else if (hasADProperty<RankFourTensor>(property_name))
323 names =
outputHelper({
"ADMaterialRankFourTensorAux",
"012", {
"i",
"j",
"k",
"l"}},
329 else if (hasProperty<SymmetricRankTwoTensor>(property_name))
330 names =
outputHelper({
"MaterialSymmetricRankTwoTensorAux",
"012345", {
"component"}},
336 else if (hasADProperty<SymmetricRankTwoTensor>(property_name))
337 names =
outputHelper({
"ADMaterialSymmetricRankTwoTensorAux",
"012345", {
"component"}},
343 else if (hasProperty<SymmetricRankFourTensor>(property_name))
344 names =
outputHelper({
"MaterialSymmetricRankFourTensorAux",
"012345", {
"i",
"j"}},
350 else if (hasADProperty<SymmetricRankFourTensor>(property_name))
351 names =
outputHelper({
"ADMaterialSymmetricRankFourTensorAux",
"012345", {
"i",
"j"}},
358 else if (hasFunctorProperty<Real>(property_name))
359 names =
outputHelper({
"FunctorMaterialRealAux",
"", {}},
361 property_name +
"_out",
365 else if (hasFunctorProperty<ADReal>(property_name))
366 names =
outputHelper({
"ADFunctorMaterialRealAux",
"", {}},
368 property_name +
"_out",
372 else if (hasFunctorProperty<RealVectorValue>(property_name))
373 names =
outputHelper({
"FunctorMaterialRealVectorValueAux",
"xyz", {
"component"}},
375 property_name +
"_out_",
379 else if (hasFunctorProperty<ADRealVectorValue>(property_name))
380 names =
outputHelper({
"ADFunctorMaterialRealVectorValueAux",
"xyz", {
"component"}},
382 property_name +
"_out_",
389 std::vector<std::string>
391 const std::string & property_name,
392 const std::string & var_name_base,
396 const auto & [kernel_name, index_symbols, param_names] = metadata;
397 const auto dim = param_names.size();
398 const auto size = index_symbols.size();
399 auto size_inner =
size;
402 bool variable_size =
false;
403 std::string variable_size_symbols;
404 if (index_symbols ==
"variable_size")
406 variable_size =
true;
408 const auto *
const vsmi =
415 mooseWarning(
"Vector material property '" + property_name +
"' will not be output as we " +
416 (vsmi ?
"have a 0-size vector during the simulation setup." 417 :
"do not know the size of the vector at initialization. Add the " 418 "'VariableSizeMaterialPropertiesInterface' as a base class of the " 419 "Material defining the vector property and implement the " 420 "get...Size(property_name) routine. Note that " 421 "the size must be known during the simulation setup phase."));
426 variable_size_symbols += std::to_string(i);
429 std::vector<std::string> names;
431 std::array<std::size_t, 4> i;
432 for (i[3] = 0; i[3] < (
dim < 4 ? 1 :
size); ++i[3])
433 for (i[2] = 0; i[2] < (
dim < 3 ? 1 :
size); ++i[2])
434 for (i[1] = 0; i[1] < (
dim < 2 ? 1 :
size); ++i[1])
435 for (i[0] = 0; i[0] < (
dim < 1 ? 1 : size_inner); ++i[0])
437 std::string var_name = var_name_base;
438 const auto & symbols = variable_size ? variable_size_symbols : index_symbols;
442 names.push_back(var_name);
446 auto params =
getParams(kernel_name, property_name, var_name, material);
448 params.template set<unsigned int>(param_names[j]) = i[j];
449 _problem->addAuxKernel(kernel_name, material.
name() + var_name, params);
457 const std::string & property_name,
458 const std::string & variable_name,
467 params.
set<MaterialPropertyName>(
"property") = property_name;
469 params.
set<MooseFunctorName>(
"functor") = property_name;
471 mooseError(
"Internal error. AuxKernel has neither a `functor` nor a `property` parameter.");
473 params.
set<AuxVariableName>(
"variable") = variable_name;
480 params.
set<std::vector<BoundaryName>>(
"boundary") = material.
boundaryNames();
482 params.
set<std::vector<SubdomainName>>(
"block") = material.
blocks();
virtual std::vector< std::string > materialOutput(const std::string &property_name, const MaterialBase &material, bool get_names_only)
A function to be overriden by derived actions to handle a set of material property types...
std::map< OutputName, std::set< std::string > > _material_variable_names_map
Map of output names and list of variables associated with the output.
static InputParameters validParams()
unsigned int size(THREAD_ID tid=0) const
Return how many kernels we store in the current warehouse.
OutputWarehouse & _output_warehouse
Reference to the OutputWarehouse.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
A MultiMooseEnum object to hold "execute_on" flags.
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
Factory & _factory
The Factory associated with the MooseApp.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
std::set< std::string > _material_variable_names
variables for the current MaterialBase object
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
const ExecFlagType EXEC_TIMESTEP_END
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
Creates AuxVariables and AuxKernels for automatic output of material properties.
std::set< OutputName > getAllMaterialPropertyOutputNames() const
Returns all output names that support material output.
Action for creating output objects.
const std::string & name() const
Get the name of the class.
static InputParameters validParams()
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
InputParameters getParams(const std::string &type, const std::string &property_name, const std::string &variable_name, const MaterialBase &material)
A method for retrieving and partially filling the InputParameters object for an AuxVariable.
const std::string & type() const
Get the type of this class.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
const std::string & _current_task
The current action (even though we have separate instances for each action)
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
bool hasProperty(const std::string &property_name)
Helper method for testing if the material exists as a block or boundary material. ...
MooseApp & _app
The MOOSE application this is associated with.
std::string stringify(const T &t)
conversion to string
virtual std::size_t getVectorPropertySize(const MaterialPropertyName &) const =0
Return the size of the variable size vector material property that the material defines.
bool hasADProperty(const std::string &property_name)
Helper method for testing if the material exists as a block or boundary material. ...
MaterialOutputAction(const InputParameters ¶ms)
Interface class to return the size of material properties that do not have a fixed size...
const MaterialData * _block_material_data
Pointer the MaterialData object storing the block restricted materials.
const std::vector< SubdomainName > & blocks() const
Return the block names for this object.
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
IntRange< T > make_range(T beg, T end)
const bool _output_only_on_timestep_end
Output only on TIMESTEP_END, not on INITIAL?
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...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
void addInterfaceHideVariables(const std::string &output_name, const std::set< std::string > &variable_names)
Insert variable names for hiding via the OutoutInterface.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
std::vector< std::string > outputHelper(const OutputMetaData &metadata, const std::string &property_name, const std::string &var_name_base, const MaterialBase &material, bool get_names_only)
Universal output object setup function.
const std::vector< BoundaryName > & boundaryNames() const
Return the boundary names for this object.
MaterialBases compute MaterialProperties.
registerMooseAction("MooseApp", MaterialOutputAction, "add_output_aux_variables")
const MaterialData * _boundary_material_data
Pointer the MaterialData object storing the boundary restricted materials.
const ExecFlagType EXEC_INITIAL