Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of Materials output system #29820

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion framework/doc/content/syntax/Materials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,14 @@ vector or tensor value.
## Material Property Output

Output of `Material` properties is enabled by setting the "outputs" parameter. The following example
creates two additional variables called "mat1" and "mat2" that will show up in the output file.
creates two additional variables called "mat1" and "mat2" that will show up in the output file. In this
example, the `exodus` name is a special keyword used to signal to MOOSE that the material properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is exodus output is the only output handling material properties?
what about Nemesis? VTK ?
The material property output goes to these too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a good point, I’m not sure let me check

should be outputted to the output object created when setting `Outputs/exodus=true`. If multiple output
Exodus objects exist in the `[Outputs]` block, one or more names can be provided to the "outputs"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Exodus objects exist in the `[Outputs]` block, one or more names can be provided to the "outputs"
[Exodus.md] objects exist in the `[Outputs]` block, one or more names can be provided to the "outputs"

parameter. In addition, the reserved output name `all` can be used to output the material property to
all Exodus objects in the `[Outputs]` block, while the reserved output name `none` can be used to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split the text between the example showing an exodus case and 'all'/'none' applying beyond just exodus

prevent the material property from being outputted to any Exodus output object. If `all` or `none`
is specified in the outputs parameter, no other additional names should be specified.

!listing output_block.i block=Materials Outputs

Expand Down
18 changes: 14 additions & 4 deletions framework/include/outputs/OutputWarehouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class OutputWarehouse : protected PerfGraphInterface
/**
* Returns true if the output object exists
* @param name The name of the output object for which to test for existence within the warehouse
* @param is_exodus Optional parameter to check if the output object associated with name must be
* Exodus type
Comment on lines +64 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we targetting exodus? Let's find a templated way

*/
bool hasOutput(const std::string & name) const;
bool hasOutput(const std::string & name, const bool is_exodus = false) const;

/**
* Calls the meshChanged method for every output object
Expand Down Expand Up @@ -117,10 +119,18 @@ class OutputWarehouse : protected PerfGraphInterface
/**
* Test that the output names exist
* @param names A vector of names to check
* This method will produce an error if any of the supplied
* names do not exist in the warehouse. Reserved names are not considered.
* @param is_exodus Optional parameter to check if all output objects associated with names are
* all Exodus type
* This method will produce an error if any of the supplied names do not exist in
* the warehouse. Reserved names are not considered.
*/
void checkOutputs(const std::set<OutputName> & names);
void checkOutputs(const std::set<OutputName> & names, const bool is_exodus = false);

/**
* Returns all output names that have an associated Exodus output object
* @return A set of all output names that have Exodus output objects
*/
const std::set<OutputName> getExodusOutputNames() const;

/**
* Return an Output object by name
Expand Down
4 changes: 2 additions & 2 deletions framework/src/actions/CheckOutputAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ CheckOutputAction::checkMaterialOutput()
// Extract the names of the output objects to which the material properties will be exported
std::set<OutputName> outputs = mat->getOutputs();

// Check that the outputs exist
_app.getOutputWarehouse().checkOutputs(outputs);
// Check that the outputs exist, and that they are of Exodus type
_app.getOutputWarehouse().checkOutputs(outputs, /* exodus = */ true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we could want to be outputting to nemesis / VTK outputs

}
}

Expand Down
28 changes: 22 additions & 6 deletions framework/src/actions/MaterialOutputAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,28 @@ MaterialOutputAction::act()
material_names.insert(curr_material_names.begin(), curr_material_names.end());
}
}
// If the material object has limited outputs, store the variables associated with the
// output objects
if (!outputs.empty())
for (const auto & output_name : outputs)
_material_variable_names_map[output_name].insert(_material_variable_names.begin(),
_material_variable_names.end());
// If the material object has explicitly defined outputs, store the variables associated with
// the output objects
if (outputs.find("none") == outputs.end())
{
// Get all available Exodus output names from OutputWarehouse
const auto & all_output_names = _output_warehouse.getExodusOutputNames();

// For reserved name "all", set outputs to match all avialable Exodus output names
if (outputs.find("all") != outputs.end())
outputs = all_output_names;

// Iterate through all available Exodus output names and update _material_variable_names_map
// based on which of these output names are found in 'outputs' parameter
for (const auto & output_name : all_output_names)
{
if (outputs.find(output_name) != outputs.end())
_material_variable_names_map[output_name].insert(_material_variable_names.begin(),
_material_variable_names.end());
else
_material_variable_names_map[output_name].insert({});
}
}
}
}
if (unsupported_names.size() > 0 && get_names_only &&
Expand Down
45 changes: 40 additions & 5 deletions framework/src/outputs/OutputWarehouse.C
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,18 @@ OutputWarehouse::addOutput(std::shared_ptr<Output> const output)
}

bool
OutputWarehouse::hasOutput(const std::string & name) const
OutputWarehouse::hasOutput(const std::string & name, const bool is_exodus) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I d rather you add a templated version over this boolean

{
return _object_map.find(name) != _object_map.end();
const auto found_object = _object_map.find(name) != _object_map.end();
if (!is_exodus || !found_object)
return found_object;
else
{
// This condition is met if output object was found and is_exodus is true
// Check if output object can be typecast to Exodus
auto * exodus = dynamic_cast<Exodus *>(_object_map.at(name));
return (exodus != NULL);
}
}

const std::set<OutputName> &
Expand Down Expand Up @@ -314,11 +323,37 @@ OutputWarehouse::buildInterfaceHideVariables(const std::string & output_name,
}

void
OutputWarehouse::checkOutputs(const std::set<OutputName> & names)
OutputWarehouse::checkOutputs(const std::set<OutputName> & names, const bool is_exodus)
{
std::string reserved_name = "";
for (const auto & name : names)
if (!isReservedName(name) && !hasOutput(name))
mooseError("The output object '", name, "' is not a defined output object");
{
const bool is_reserved_name = isReservedName(name);
if (is_reserved_name)
reserved_name = name;
if (!is_reserved_name && !hasOutput(name, is_exodus))
mooseError("The output object '",
name,
"' is not a defined ",
(is_exodus ? "Exodus " : ""),
"output object");
}
if (!reserved_name.empty() && names.size() > 1)
mooseError("When setting output name to reserved name '" + reserved_name +
"', only one entry is allowed in outputs parameter.");
}

const std::set<OutputName>
OutputWarehouse::getExodusOutputNames() const
{
std::set<OutputName> exodus_output_names;
for (const auto & pair : _object_map)
{
auto * exodus = dynamic_cast<Exodus *>(pair.second);
if (exodus != NULL)
exodus_output_names.insert(pair.first);
}
return exodus_output_names;
}

const std::set<std::string> &
Expand Down
32 changes: 16 additions & 16 deletions test/tests/materials/output/block_via_outputs.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@
[]

[Variables]
[./u]
[../]
[u]
[]
[]

[Kernels]
[./diff]
[diff]
type = CoefDiffusion
variable = u
coef = 10
[../]
[./time]
[]
[time]
type = TimeDerivative
variable = u
[../]
[]
[]

[BCs]
[./left]
[left]
type = DirichletBC
variable = u
boundary = 1
value = 0
[../]
[./right]
[]
[right]
type = DirichletBC
variable = u
boundary = 2
value = 1
[../]
[]
[]

[Materials]
[./block_1]
[block_1]
type = OutputTestMaterial
block = 1
variable = u
[../]
[./block_2]
[]
[block_2]
type = OutputTestMaterial
block = 2
variable = u
[../]
[]
[]

[Executioner]
Expand All @@ -60,9 +60,9 @@
[]

[Outputs]
[./out]
[out]
type = Exodus
output_material_properties = true
show_material_properties = real_property
[../]
[]
[]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28 changes: 14 additions & 14 deletions test/tests/materials/output/limited_via_outputs.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,43 @@
[]

[Variables]
[./u]
[../]
[u]
[]
[]

[Kernels]
[./diff]
[diff]
type = CoefDiffusion
variable = u
coef = 10
[../]
[./time]
[]
[time]
type = TimeDerivative
variable = u
[../]
[]
[]

[BCs]
[./left]
[left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
[]
[right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]
[]

[Materials]
[./test_material]
[test_material]
type = OutputTestMaterial
block = 0
variable = u
[../]
[]
[]

[Executioner]
Expand All @@ -58,9 +58,9 @@
[]

[Outputs]
[./out]
[out]
type = Exodus
output_material_properties = true
show_material_properties = 'real_property vector_property'
[../]
[]
[]
24 changes: 12 additions & 12 deletions test/tests/materials/output/output.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@
[]

[Variables]
[./u]
[../]
[u]
[]
[]

[Kernels]
[./diff]
[diff]
type = CoefDiffusion
variable = u
coef = 10
[../]
[./time]
[]
[time]
type = TimeDerivative
variable = u
[../]
[]
[]

[BCs]
[./left]
[left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
[]
[right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]
[]

[Materials]
[./test_material]
[test_material]
type = OutputTestMaterial
block = 0
variable = u
outputs = all
[../]
[]
[]

[Executioner]
Expand Down
Loading