Skip to content

Commit

Permalink
Merge pull request #27344 from miaoyinb/detailPatternError
Browse files Browse the repository at this point in the history
More detailed error messages for inconsistent pitch metadata
  • Loading branch information
GiudGiud authored Apr 13, 2024
2 parents 9a9a3dc + 04f9496 commit f4aebfe
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
15 changes: 10 additions & 5 deletions framework/src/utils/FormattedTable.C
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ FormattedTable::printNoDataRow(char intersect_char,
std::vector<std::string>::iterator & col_end) const
{
out.fill(fill_char);
out << std::right << intersect_char << std::setw(_column_width + 2) << intersect_char;
out << std::right << intersect_char;
if (_output_time)
out << std::setw(_column_width + 2) << intersect_char;
for (auto header_it = col_begin; header_it != col_end; ++header_it)
out << std::setw(col_widths[*header_it] + 2) << intersect_char;
out << "\n";
Expand Down Expand Up @@ -306,8 +308,10 @@ FormattedTable::printTablePiece(std::ostream & out,
* Print out the header row
*/
printRowDivider(out, col_widths, col_begin, col_end);
out << "|" << std::setw(_column_width) << std::left << " time"
<< " |";
out << "|";
if (_output_time)
out << std::setw(_column_width) << std::left << " time"
<< " |";
for (auto header_it = col_begin; header_it != col_end; ++header_it)
out << " " << std::setw(col_widths[*header_it]) << *header_it << "|";
out << "\n";
Expand All @@ -328,8 +332,9 @@ FormattedTable::printTablePiece(std::ostream & out,
// Now print the remaining data rows
for (; data_it != _data.end(); ++data_it)
{
out << "|" << std::right << std::setw(_column_width) << std::scientific << data_it->first
<< " |";
out << "|";
if (_output_time)
out << std::right << std::setw(_column_width) << std::scientific << data_it->first << " |";
for (auto header_it = col_begin; header_it != col_end; ++header_it)
{
auto & tmp = data_it->second;
Expand Down
12 changes: 12 additions & 0 deletions modules/reactor/include/meshgenerators/PolygonMeshGeneratorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,16 @@ class PolygonMeshGeneratorBase : public MeshGenerator
singleBdryLayerParams modifiedSingleBdryLayerParamsCreator(
const singleBdryLayerParams & original_single_bdry_layer_params,
const unsigned int order) const;

/**
* Generate a string that contains the detailed metadata information for inconsistent input mesh
* metadata error messages
* @param input_names list of input mesh generator names
* @param metadata_vals list of input mesh metadata values
* @param metadata_name name of the input mesh metadata
* @return a string that contains the detailed metadata information
*/
std::string pitchMetaDataErrorGenerator(const std::vector<MeshGeneratorName> & input_names,
const std::vector<Real> & metadata_vals,
const std::string & metadata_name) const;
};
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,17 @@ PatternedCartesianMeshGenerator::generate()
if (!MooseUtils::absoluteFuzzyEqual(
*std::max_element(pattern_pitch_array.begin(), pattern_pitch_array.end()),
*std::min_element(pattern_pitch_array.begin(), pattern_pitch_array.end())))
mooseError("In PatternedCartesianMeshGenerator ",
_name,
": pattern_pitch metadata values of all input mesh generators must be identical "
"when pattern_boundary is 'none' and generate_core_metadata is true.");
mooseError(
"In PatternedCartesianMeshGenerator ",
_name,
": pattern_pitch metadata values of all input mesh generators must be identical when "
"pattern_boundary is 'none' and generate_core_metadata is true. Please check the "
"parameters of the mesh generators that produce the input meshes. "
"Note that some of these mesh generator, such as "
"CartesianConcentricCircleAdaptiveBoundaryMeshGenerator and FlexiblePatternGenerator,"
"may have different definitions of square size in their input parameters. Please refer "
"to the documentation of these mesh generators.",
pitchMetaDataErrorGenerator(_input_names, pattern_pitch_array, "pattern_pitch_meta"));
else
{
_pattern_pitch = pattern_pitch_array.front();
Expand Down Expand Up @@ -477,7 +484,9 @@ PatternedCartesianMeshGenerator::generate()
*std::min_element(pitch_array.begin(), pitch_array.end())))
mooseError("In PatternedCartesianMeshGenerator ",
_name,
": pitch metadata values of all input mesh generators must be identical.");
": pitch metadata values of all input mesh generators must be identical. Please "
"check the parameters of the mesh generators that produce the input meshes.",
pitchMetaDataErrorGenerator(_input_names, pitch_array, "pitch_meta"));
setMeshProperty("input_pitch_meta", pitch_array.front());
if (*std::max_element(num_sectors_per_side_array.begin(), num_sectors_per_side_array.end()) !=
*std::min_element(num_sectors_per_side_array.begin(), num_sectors_per_side_array.end()))
Expand Down
20 changes: 15 additions & 5 deletions modules/reactor/src/meshgenerators/PatternedHexMeshGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,17 @@ PatternedHexMeshGenerator::generate()
if (!MooseUtils::absoluteFuzzyEqual(
*std::max_element(pattern_pitch_array.begin(), pattern_pitch_array.end()),
*std::min_element(pattern_pitch_array.begin(), pattern_pitch_array.end())))
mooseError("In PatternedHexMeshGenerator ",
_name,
": pattern_pitch metadata values of all input mesh generators must be identical "
"when pattern_boundary is 'none' and generate_core_metadata is true.");
mooseError(
"In PatternedHexMeshGenerator ",
_name,
": pattern_pitch metadata values of all input mesh generators must be identical "
"when pattern_boundary is 'none' and generate_core_metadata is true. Please check the "
"parameters of the mesh generators that produce the input meshes."
"Note that some of these mesh generators, such as "
"HexagonConcentricCircleAdaptiveBoundaryMeshGenerator and FlexiblePatternGenerator,"
"may have different definitions of hexagon size in their input parameters. Please refer "
"to the documentation of these mesh generators.",
pitchMetaDataErrorGenerator(_input_names, pattern_pitch_array, "pattern_pitch_meta"));
else
{
_pattern_pitch = pattern_pitch_array.front();
Expand Down Expand Up @@ -476,7 +483,10 @@ PatternedHexMeshGenerator::generate()
*std::min_element(pitch_array.begin(), pitch_array.end())))
mooseError("In PatternedHexMeshGenerator ",
_name,
": pitch metadata values of all input mesh generators must be identical.");
": pitch metadata values of all input mesh generators must be identical. Please "
"check the "
"parameters of the mesh generators that produce the input meshes.",
pitchMetaDataErrorGenerator(_input_names, pitch_array, "pitch_meta"));
setMeshProperty("input_pitch_meta", pitch_array.front());
if (*std::max_element(num_sectors_per_side_array.begin(), num_sectors_per_side_array.end()) !=
*std::min_element(num_sectors_per_side_array.begin(), num_sectors_per_side_array.end()))
Expand Down
21 changes: 21 additions & 0 deletions modules/reactor/src/meshgenerators/PolygonMeshGeneratorBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#include "PolygonMeshGeneratorBase.h"
#include "MooseUtils.h"
#include "FormattedTable.h"

#include <cmath>
#include <iomanip>

InputParameters
PolygonMeshGeneratorBase::validParams()
Expand Down Expand Up @@ -1738,3 +1740,22 @@ PolygonMeshGeneratorBase::modifiedSingleBdryLayerParamsCreator(
mod_single_bdry_layer_params.bias = std::pow(mod_single_bdry_layer_params.bias, 1.0 / order);
return mod_single_bdry_layer_params;
}

std::string
PolygonMeshGeneratorBase::pitchMetaDataErrorGenerator(
const std::vector<MeshGeneratorName> & input_names,
const std::vector<Real> & metadata_vals,
const std::string & metadata_name) const
{
FormattedTable table;
for (unsigned int i = 0; i < input_names.size(); i++)
{
table.addRow(i);
table.addData<std::string>("input name", (std::string)input_names[i]);
table.addData<Real>(metadata_name, metadata_vals[i]);
}
table.outputTimeColumn(false);
std::stringstream detailed_error;
table.printTable(detailed_error);
return "\n" + detailed_error.str();
}

0 comments on commit f4aebfe

Please sign in to comment.