25 #include "libmesh/utility.h" 34 params.
addClassDescription(
"Outputs material properties to various Outputs objects, based on the " 35 "parameters set in each Material");
40 params.
addParam<
bool>(
"print_automatic_aux_variable_creation",
42 "Flag to print list of aux variables created for automatic output by " 43 "MaterialOutputAction.");
49 _block_material_data(nullptr),
50 _boundary_material_data(nullptr),
51 _output_warehouse(_app.getOutputWarehouse()),
52 _output_only_on_timestep_end(_app.parameters().
get<bool>(
"use_legacy_material_output"))
60 "FEProblemBase pointer is nullptr, it is needed for auto material property output");
66 bool get_names_only =
_current_task ==
"add_output_aux_variables" ? true :
false;
74 const auto & material_ptrs =
_problem->getMaterialWarehouse().getObjects();
81 bool outputs_has_properties =
false;
82 std::set<std::string> output_object_properties;
85 for (
const auto &
act : output_actions)
96 params.
get<
bool>(
"output_material_properties"))
98 outputs_has_properties =
true;
99 std::vector<std::string> prop_names =
100 params.
get<std::vector<std::string>>(
"show_material_properties");
101 output_object_properties.insert(prop_names.begin(), prop_names.end());
106 std::set<std::string> material_names;
107 std::set<std::string> unsupported_names;
108 for (
const auto & mat : material_ptrs)
111 std::set<OutputName> outputs = mat->getOutputs();
114 std::vector<std::string> output_properties =
115 mat->getParam<std::vector<std::string>>(
"output_properties");
118 if (outputs_has_properties)
119 output_properties.insert(output_properties.end(),
120 output_object_properties.begin(),
121 output_object_properties.end());
133 if (outputs_has_properties || outputs.find(
"none") == outputs.end())
136 std::set<std::string> names = mat->getSuppliedItems();
137 if (
const auto fmat_ptr = dynamic_cast<const FunctorMaterial *>(mat.get()))
138 names.insert(fmat_ptr->getSuppliedFunctors().begin(),
139 fmat_ptr->getSuppliedFunctors().end());
141 for (
const auto &
name : names)
145 if (output_properties.empty() ||
146 std::find(output_properties.begin(), output_properties.end(),
name) !=
147 output_properties.end())
151 if (curr_material_names.size() == 0)
152 unsupported_names.insert(
name);
153 material_names.insert(curr_material_names.begin(), curr_material_names.end());
158 if (outputs.find(
"none") == outputs.end())
164 if (outputs.find(
"all") != outputs.end())
165 outputs = all_output_names;
169 for (
const auto & output_name : all_output_names)
171 if (outputs.find(output_name) != outputs.end())
179 else if (output_properties.size())
180 mooseWarning(
"Material properties output specified is not created because 'outputs' is not " 181 "set in the Material, and neither is Outputs/output_material_properties");
183 if (unsupported_names.size() > 0 && get_names_only &&
184 getParam<bool>(
"print_unsupported_prop_names"))
186 std::ostringstream oss;
187 for (
const auto &
name : unsupported_names)
188 oss <<
"\n " <<
name;
190 unsupported_names.size(),
191 " material properties:",
193 "\nare not supported for automatic output by ",
203 params.set<
MooseEnum>(
"family") =
"MONOMIAL";
206 std::ostringstream oss;
207 for (
const auto & var_name : material_names)
209 oss <<
"\n " << var_name;
210 if (
_problem->hasVariable(var_name))
211 mooseError(
"The material property output " + var_name +
212 " has the same name as an existing variable, either use the material" 213 " declare_suffix parameter to disambiguate or the output_properties parameter" 214 " to restrict the material properties to output");
215 _problem->addAuxVariable(
"MooseVariableConstMonomial", var_name, params);
218 if (material_names.size() > 0 && getParam<bool>(
"print_automatic_aux_variable_creation"))
219 _console << COLOR_CYAN <<
"The following total " << material_names.size()
220 <<
" aux variables:" << oss.str() <<
"\nare added for automatic output by " <<
type()
221 <<
"." << COLOR_DEFAULT << std::endl;
230 std::set<std::string> hide;
231 std::set_difference(material_names.begin(),
232 material_names.end(),
235 std::inserter(hide, hide.begin()));
242 std::vector<std::string>
247 std::vector<std::string> names;
250 if (hasProperty<Real>(property_name))
252 {
"MaterialRealAux",
"", {}}, property_name, property_name, material, get_names_only);
254 else if (hasADProperty<Real>(property_name))
256 {
"ADMaterialRealAux",
"", {}}, property_name, property_name, material, get_names_only);
258 else if (hasProperty<RealVectorValue>(property_name))
259 names =
outputHelper({
"MaterialRealVectorValueAux",
"xyz", {
"component"}},
265 else if (hasADProperty<RealVectorValue>(property_name))
266 names =
outputHelper({
"ADMaterialRealVectorValueAux",
"xyz", {
"component"}},
272 else if (hasProperty<RealTensorValue>(property_name))
273 names =
outputHelper({
"MaterialRealTensorValueAux",
"012", {
"row",
"column"}},
279 else if (hasADProperty<RealTensorValue>(property_name))
280 names =
outputHelper({
"ADMaterialRealTensorValueAux",
"012", {
"row",
"column"}},
286 else if (hasProperty<RankTwoTensor>(property_name))
287 names =
outputHelper({
"MaterialRankTwoTensorAux",
"012", {
"i",
"j"}},
293 else if (hasADProperty<RankTwoTensor>(property_name))
294 names =
outputHelper({
"ADMaterialRankTwoTensorAux",
"012", {
"i",
"j"}},
300 else if (hasProperty<RankFourTensor>(property_name))
301 names =
outputHelper({
"MaterialRankFourTensorAux",
"012", {
"i",
"j",
"k",
"l"}},
307 else if (hasADProperty<RankFourTensor>(property_name))
308 names =
outputHelper({
"ADMaterialRankFourTensorAux",
"012", {
"i",
"j",
"k",
"l"}},
314 else if (hasProperty<SymmetricRankTwoTensor>(property_name))
315 names =
outputHelper({
"MaterialSymmetricRankTwoTensorAux",
"012345", {
"component"}},
321 else if (hasADProperty<SymmetricRankTwoTensor>(property_name))
322 names =
outputHelper({
"ADMaterialSymmetricRankTwoTensorAux",
"012345", {
"component"}},
328 else if (hasProperty<SymmetricRankFourTensor>(property_name))
329 names =
outputHelper({
"MaterialSymmetricRankFourTensorAux",
"012345", {
"i",
"j"}},
335 else if (hasADProperty<SymmetricRankFourTensor>(property_name))
336 names =
outputHelper({
"ADMaterialSymmetricRankFourTensorAux",
"012345", {
"i",
"j"}},
343 else if (hasFunctorProperty<Real>(property_name))
344 names =
outputHelper({
"FunctorMaterialRealAux",
"", {}},
346 property_name +
"_out",
350 else if (hasFunctorProperty<ADReal>(property_name))
351 names =
outputHelper({
"ADFunctorMaterialRealAux",
"", {}},
353 property_name +
"_out",
357 else if (hasFunctorProperty<RealVectorValue>(property_name))
358 names =
outputHelper({
"FunctorMaterialRealVectorValueAux",
"xyz", {
"component"}},
360 property_name +
"_out_",
364 else if (hasFunctorProperty<ADRealVectorValue>(property_name))
365 names =
outputHelper({
"ADFunctorMaterialRealVectorValueAux",
"xyz", {
"component"}},
367 property_name +
"_out_",
374 std::vector<std::string>
376 const std::string & property_name,
377 const std::string & var_name_base,
381 const auto & [kernel_name, index_symbols, param_names] = metadata;
382 const auto dim = param_names.size();
383 const auto size = index_symbols.size();
385 std::vector<std::string> names;
387 std::array<std::size_t, 4> i;
388 for (i[3] = 0; i[3] < (
dim < 4 ? 1 :
size); ++i[3])
389 for (i[2] = 0; i[2] < (
dim < 3 ? 1 :
size); ++i[2])
390 for (i[1] = 0; i[1] < (
dim < 2 ? 1 :
size); ++i[1])
391 for (i[0] = 0; i[0] < (
dim < 1 ? 1 :
size); ++i[0])
393 std::string var_name = var_name_base;
396 names.push_back(var_name);
400 auto params =
getParams(kernel_name, property_name, var_name, material);
402 params.template set<unsigned int>(param_names[j]) = i[j];
403 _problem->addAuxKernel(kernel_name, material.
name() + var_name, params);
411 const std::string & property_name,
412 const std::string & variable_name,
421 params.
set<MaterialPropertyName>(
"property") = property_name;
423 params.
set<MooseFunctorName>(
"functor") = property_name;
425 mooseError(
"Internal error. AuxKernel has neither a `functor` nor a `property` parameter.");
427 params.
set<AuxVariableName>(
"variable") = variable_name;
434 params.
set<std::vector<BoundaryName>>(
"boundary") = material.
boundaryNames();
436 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.
A MultiMooseEnum object to hold "execute_on" flags.
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
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.
virtual const std::string & name() const
Get the name of the class.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
Creates AuxVariables and AuxKernels for automatic output of material properties.
Factory & _factory
The Factory associated with the MooseApp.
std::set< OutputName > getAllMaterialPropertyOutputNames() const
Returns all output names that support material output.
Action for creating output objects.
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.
MooseApp & _app
The MOOSE application this is associated with.
std::string stringify(const T &t)
conversion to string
MaterialOutputAction(const InputParameters ¶ms)
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.
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.
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