Skip to content

Commit

Permalink
General cleanup of Material Output system
Browse files Browse the repository at this point in the history
- Fix faulty logic when materials are outputted to different files
- Make sure setting outputs = 'all none' results in an error
- Confirm that outputs = "exodus", outputs = "all", and outputs = "none" work as expected
  • Loading branch information
shikhar413 committed Feb 6, 2025
1 parent e5db198 commit fb9ecea
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 17 deletions.
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
*/
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);
}
}

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
{
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

0 comments on commit fb9ecea

Please sign in to comment.