Skip to content

Commit

Permalink
IOSS: Refactor some names; add print
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed May 28, 2024
1 parent 9cf7ee5 commit 6f4d788
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 72 deletions.
2 changes: 2 additions & 0 deletions packages/seacas/libraries/ioss/src/Ioss_BasisVariableType.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace Ioss {
return m_basis_.basies[which - 1];
}

void print() const override final;

private:
std::string m_basis_type_{};
Ioss::Basis m_basis_{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace Ioss {
// If user doesn't add suffices, then 'label' will return "UNSET"
void add_suffix(size_t which, const std::string &suffix) { suffixList[which - 1] = suffix; }

void print() const override final;

private:
Ioss::NameList suffixList{};
};
Expand Down
20 changes: 6 additions & 14 deletions packages/seacas/libraries/ioss/src/Ioss_QuadratureVariableType.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace Ioss {
return VariableType::numeric_label(which, component_count(), name());
}

QuadratureVariableType(const std::string &my_name, int number_components, bool delete_me)
: Ioss::VariableType(Ioss::Utils::lowercase(my_name), number_components, delete_me),
m_quadratureType_(my_name)
QuadratureVariableType(const std::string &my_name,
const std::vector<Ioss::QuadraturePoint> &quad_points, bool delete_me)
: Ioss::VariableType(Ioss::Utils::lowercase(my_name), quad_points.size(), delete_me),
m_quadratureType_(my_name), m_quadrature_(quad_points)
{
m_quadrature_.resize(number_components);
}

QuadratureVariableType(const QuadratureVariableType &) = delete;
Expand All @@ -52,21 +52,13 @@ namespace Ioss {
{
return m_quadrature_;
}
IOSS_NODISCARD Ioss::QuadraturePoint get_quadrature(int which) const
IOSS_NODISCARD Ioss::QuadraturePoint get_quadrature_component(int which) const
{
assert(which > 0 && which <= component_count());
return m_quadrature_[which - 1];
}

void add_quadrature(int which, const Ioss::QuadraturePoint &quadrature)
{
assert(which > 0 && which <= component_count());
m_quadrature_[which - 1] = quadrature;
}
void add_quadrature(const std::vector<Ioss::QuadraturePoint> &quadrature)
{
m_quadrature_ = quadrature;
}
void print() const override final;

private:
std::string m_quadratureType_{};
Expand Down
85 changes: 56 additions & 29 deletions packages/seacas/libraries/ioss/src/Ioss_VariableType.C
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ namespace Ioss {
{
std::string low_type = Utils::lowercase(type);
registry().insert(VTM_ValuePair(low_type, this), delete_me);

// Register uppercase version also
std::string up_type = Utils::uppercase(type);
registry().insert(VTM_ValuePair(up_type, this), false);
}

VariableType::Type VariableType::type() const { return Type::UNKNOWN; }
Expand All @@ -63,13 +59,49 @@ namespace Ioss {
return fmt::format("Composed: {}*{}", baseType->type_string(), secondaryType->type_string());
}

void VariableType::print() const
{
fmt::print("\tVariableType '{}' of type '{}' with {} components.\n\n", name(), type_string(),
component_count());
}

void BasisVariableType::print() const
{
fmt::print("\tVariableType '{}' of type '{}' with {} components\n\t\tordinal subc: _dim, "
"_ordinal, _dof_ordinal, _num_dof\t xi eta zeta\n",
name(), type_string(), component_count());
for (int i = 0; i < component_count(); i++) {
auto basis = get_basis_component(i + 1);
fmt::print("\t\t {:6}\t\t{:6}\t{:6}\t{:6}\t{:6}\t\t{:6.3}\t{:6.3}\t{:6.3}\n", i + 1,
basis.subc_dim, basis.subc_ordinal, basis.subc_dof_ordinal, basis.subc_num_dof,
basis.xi, basis.eta, basis.zeta);
}
fmt::print("\n");
}

void QuadratureVariableType::print() const
{
fmt::print("\tVariableType '{}' of type '{}' with {} components\n\t\t\t xi eta zeta "
"weight\n",
name(), type_string(), component_count());
for (int i = 0; i < component_count(); i++) {
auto quad = get_quadrature_component(i + 1);
fmt::print("\t\t{}\t{:6.3}\t{:6.3}\t{:6.3}\t{:6.3}\n", i + 1, quad.xi, quad.eta, quad.zeta,
quad.weight);
}
fmt::print("\n");
}

void NamedSuffixVariableType::print() const
{
fmt::print("\tVariableType '{}' of type '{}' with {} components\n\t\tSuffices: {}\n\n", name(),
type_string(), component_count(), fmt::join(suffixList, ", "));
}

void VariableType::alias(const std::string &base, const std::string &syn)
{
registry().insert(
VTM_ValuePair(Utils::lowercase(syn), const_cast<VariableType *>(factory(base))), false);
// Register uppercase version also
std::string up_type = Utils::uppercase(syn);
registry().insert(VTM_ValuePair(up_type, const_cast<VariableType *>(factory(base))), false);
}

Registry &VariableType::registry()
Expand Down Expand Up @@ -104,21 +136,19 @@ namespace Ioss {
return names;
}

std::vector<const Ioss::VariableType *> VariableType::external_types()
std::vector<Ioss::VariableType *> VariableType::external_types(Ioss::VariableType::Type type)
{
auto vars = registry().m_deleteThese;

std::vector<const Ioss::VariableType *> user_vars;
for (const auto *var : vars) {
const auto *basis = dynamic_cast<const Ioss::BasisVariableType *>(var);
if (basis != nullptr) {
user_vars.push_back(var);
continue;
}
const auto *quad = dynamic_cast<const Ioss::QuadratureVariableType *>(var);
if (quad != nullptr) {
user_vars.push_back(var);
continue;
std::vector<Ioss::VariableType *> user_vars;
if (type == Ioss::VariableType::Type::UNKNOWN) {
user_vars = vars;
}
else {
for (auto *var : vars) {
if (var->type() == type) {
user_vars.push_back(var);
}
}
}
return user_vars;
Expand All @@ -138,8 +168,8 @@ namespace Ioss {
return registry().customFieldTypes.insert(std::make_pair(field, type)).second;
}

bool VariableType::create_named_suffix_field_type(const std::string &type_name,
const Ioss::NameList &suffices)
bool VariableType::create_named_suffix_type(const std::string &type_name,
const Ioss::NameList &suffices)
{
size_t count = suffices.size();
if (count < 1) {
Expand All @@ -162,7 +192,7 @@ namespace Ioss {
return true;
}

bool VariableType::create_basis_field_type(const std::string &type_name, const Ioss::Basis &basis)
bool VariableType::create_basis_type(const std::string &type_name, const Ioss::Basis &basis)
{
// See if the variable already exists...
std::string basis_name = Utils::lowercase(type_name);
Expand All @@ -176,9 +206,8 @@ namespace Ioss {
return true;
}

bool
VariableType::create_quadrature_field_type(const std::string &type_name,
const std::vector<Ioss::QuadraturePoint> &quad_points)
bool VariableType::create_quadrature_type(const std::string &type_name,
const std::vector<Ioss::QuadraturePoint> &quad_points)
{
size_t count = quad_points.size();
if (count < 1) {
Expand All @@ -193,10 +222,8 @@ namespace Ioss {

// Create the variable. Note that the 'true' argument means Ioss will delete
// the pointer.
auto *var_type = new QuadratureVariableType(type_name, count, true);
var_type->add_quadrature(quad_points);

return true;
auto *var_type = new QuadratureVariableType(type_name, quad_points, true);
return (var_type != nullptr);
}

bool VariableType::get_field_type_mapping(const std::string &field, std::string *type)
Expand Down
17 changes: 10 additions & 7 deletions packages/seacas/libraries/ioss/src/Ioss_VariableType.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,23 @@ namespace Ioss {
// Return a list of types that have been defined
// externally... Basically a subset of the types in the
// `Registry::m_deleteThese` list...
IOSS_NODISCARD static std::vector<const Ioss::VariableType *> external_types();

static bool create_named_suffix_field_type(const std::string &type_name,
const Ioss::NameList &suffices);
static bool create_basis_field_type(const std::string &type_name, const Ioss::Basis &basis);
static bool create_quadrature_field_type(const std::string &type_name,
const std::vector<Ioss::QuadraturePoint> &quad_points);
IOSS_NODISCARD static std::vector<Ioss::VariableType *>
external_types(Ioss::VariableType::Type type);

static bool create_named_suffix_type(const std::string &type_name,
const Ioss::NameList &suffices);
static bool create_basis_type(const std::string &type_name, const Ioss::Basis &basis);
static bool create_quadrature_type(const std::string &type_name,
const std::vector<Ioss::QuadraturePoint> &quad_points);
static bool get_field_type_mapping(const std::string &field, std::string *type);
static bool add_field_type_mapping(const std::string &raw_field, const std::string &raw_type);

VariableType(const VariableType &) = delete;
VariableType &operator=(const VariableType &) = delete;
virtual ~VariableType() = default;

virtual void print() const;

IOSS_NODISCARD int component_count() const;

// Override this function if the derived class has no suffices
Expand Down
36 changes: 18 additions & 18 deletions packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ namespace Ioex {
}
else if (exo_field.type[0] == EX_FIELD_TYPE_USER_DEFINED) {
auto suffices = Ioss::tokenize(exo_field.suffices, ",");
Ioss::VariableType::create_named_suffix_field_type(exo_field.name, suffices);
Ioss::VariableType::create_named_suffix_type(exo_field.name, suffices);
ios_field_type = exo_field.name;
}
else if (exo_field.type[0] == EX_BASIS || exo_field.type[0] == EX_QUADRATURE) {
Expand Down Expand Up @@ -2001,7 +2001,7 @@ namespace Ioex {
{
// Get all transient fields on this entity...
char default_separator = entity->get_database()->get_field_separator();
auto results_fields = entity->field_describe(Ioss::Field::TRANSIENT);
auto results_fields = entity->field_describe(Ioss::Field::TRANSIENT);
for (const auto &field_name : results_fields) {
const auto &field = entity->get_fieldref(field_name);

Expand Down Expand Up @@ -2110,8 +2110,10 @@ namespace Ioex {
}
}

void output_basis(int exoid, const Ioss::BasisVariableType *basis)
void output_basis(int exoid, const Ioss::VariableType *var)
{
const auto *basis = dynamic_cast<const Ioss::BasisVariableType *>(var);
assert(basis != nullptr);
ex_basis exo_basis{};
exo_basis.cardinality = basis->component_count();
ex_initialize_basis_struct(&exo_basis, 1, 1);
Expand All @@ -2130,14 +2132,16 @@ namespace Ioex {
ex_initialize_basis_struct(&exo_basis, 1, -1);
}

void output_quad(int exoid, const Ioss::QuadratureVariableType *quadrature)
void output_quad(int exoid, const Ioss::VariableType *var)
{
const auto *quadrature = dynamic_cast<const Ioss::QuadratureVariableType *>(var);
assert(quadrature != nullptr);
ex_quadrature exo_quadrature{};
exo_quadrature.cardinality = quadrature->component_count();
ex_initialize_quadrature_struct(&exo_quadrature, 1, 1);
Ioss::Utils::copy_string(exo_quadrature.name, quadrature->name(), EX_MAX_NAME);
for (int i = 0; i < quadrature->component_count(); i++) {
auto component = quadrature->get_quadrature(i + 1);
const auto &quad = quadrature->get_quadrature();
for (const auto &[i, component] : Ioss::enumerate(quad)) {
exo_quadrature.xi[i] = component.xi;
exo_quadrature.eta[i] = component.eta;
exo_quadrature.zeta[i] = component.zeta;
Expand All @@ -2150,18 +2154,14 @@ namespace Ioex {
void output_type_metadata(int exoid)
{
// Iterate the list and output the `quadrature` and `basis` types...
auto var_list = Ioss::VariableType::external_types();
for (auto &var : var_list) {
const auto *basis = dynamic_cast<const Ioss::BasisVariableType *>(var);
if (basis != nullptr) {
output_basis(exoid, basis);
continue;
}
const auto *quad = dynamic_cast<const Ioss::QuadratureVariableType *>(var);
if (quad != nullptr) {
output_quad(exoid, quad);
continue;
}
auto basis_list = Ioss::VariableType::external_types(Ioss::VariableType::Type::BASIS);
for (auto &var : basis_list) {
output_basis(exoid, var);
}

auto quad_list = Ioss::VariableType::external_types(Ioss::VariableType::Type::QUADRATURE);
for (auto &var : quad_list) {
output_quad(exoid, var);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ namespace Ioex {
ebasis.zeta[i]};
basis.basies.push_back(bc);
}
Ioss::VariableType::create_basis_field_type(ebasis.name, basis);
Ioss::VariableType::create_basis_type(ebasis.name, basis);
}

// deallocate any memory allocated in the 'ex_basis' structs.
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace Ioex {
equadrature.weight[i]};
quadrature.push_back(q);
}
Ioss::VariableType::create_quadrature_field_type(equadrature.name, quadrature);
Ioss::VariableType::create_quadrature_type(equadrature.name, quadrature);
}

// deallocate any memory allocated in the 'ex_quadrature' structs.
Expand Down
11 changes: 10 additions & 1 deletion packages/seacas/libraries/ioss/src/main/io_info.C
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ namespace {
void info_aliases(const Ioss::Region &region, const Ioss::GroupingEntity *ige, bool nl_pre,
bool nl_post);

void info_variable_types()
{
auto var_list = Ioss::VariableType::external_types(Ioss::VariableType::Type::UNKNOWN);
for (auto &var : var_list) {
var->print();
}
}

void file_info(const Info::Interface &interFace);
void group_info(Info::Interface &interFace);

Expand Down Expand Up @@ -206,7 +214,7 @@ namespace {
if (!custom_field.empty()) {
auto suffices = Ioss::tokenize(custom_field, ",");
if (suffices.size() > 1) {
Ioss::VariableType::create_named_suffix_field_type("UserDefined", suffices);
Ioss::VariableType::create_named_suffix_type("UserDefined", suffices);
}
}

Expand Down Expand Up @@ -346,6 +354,7 @@ namespace {
Ioss::Utils::info_property(&region, Ioss::Property::ATTRIBUTE,
"\tAttributes (Reduction): ", "\t");
Ioss::Utils::info_fields(&region, Ioss::Field::REDUCTION, "\tTransient (Reduction): ", "\t");
info_variable_types();
}

void info_assemblies(Ioss::Region &region)
Expand Down
2 changes: 1 addition & 1 deletion packages/seacas/libraries/ioss/src/main/io_shell.C
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int argc, char *argv[])
if (!interFace.customField.empty()) {
auto suffices = Ioss::tokenize(interFace.customField, ",");
if (suffices.size() > 1) {
Ioss::VariableType::create_named_suffix_field_type("UserDefined", suffices);
Ioss::VariableType::create_named_suffix_type("UserDefined", suffices);
}
}
std::string in_file = interFace.inputFile[0];
Expand Down

0 comments on commit 6f4d788

Please sign in to comment.