From 6f4d78876b4a304d582265d5b9ff6d81a5b0e743 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Tue, 28 May 2024 12:52:23 -0600 Subject: [PATCH] IOSS: Refactor some names; add print --- .../ioss/src/Ioss_BasisVariableType.h | 2 + .../ioss/src/Ioss_NamedSuffixVariableType.h | 2 + .../ioss/src/Ioss_QuadratureVariableType.h | 20 ++--- .../libraries/ioss/src/Ioss_VariableType.C | 85 ++++++++++++------- .../libraries/ioss/src/Ioss_VariableType.h | 17 ++-- .../ioss/src/exodus/Ioex_BaseDatabaseIO.C | 36 ++++---- .../libraries/ioss/src/exodus/Ioex_Utils.C | 4 +- .../seacas/libraries/ioss/src/main/io_info.C | 11 ++- .../seacas/libraries/ioss/src/main/io_shell.C | 2 +- 9 files changed, 107 insertions(+), 72 deletions(-) diff --git a/packages/seacas/libraries/ioss/src/Ioss_BasisVariableType.h b/packages/seacas/libraries/ioss/src/Ioss_BasisVariableType.h index 21fde8f39a..7a78e1cfa0 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_BasisVariableType.h +++ b/packages/seacas/libraries/ioss/src/Ioss_BasisVariableType.h @@ -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_{}; diff --git a/packages/seacas/libraries/ioss/src/Ioss_NamedSuffixVariableType.h b/packages/seacas/libraries/ioss/src/Ioss_NamedSuffixVariableType.h index edaf696b63..c81c922d40 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_NamedSuffixVariableType.h +++ b/packages/seacas/libraries/ioss/src/Ioss_NamedSuffixVariableType.h @@ -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{}; }; diff --git a/packages/seacas/libraries/ioss/src/Ioss_QuadratureVariableType.h b/packages/seacas/libraries/ioss/src/Ioss_QuadratureVariableType.h index d53c06eefd..ea52aeded2 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_QuadratureVariableType.h +++ b/packages/seacas/libraries/ioss/src/Ioss_QuadratureVariableType.h @@ -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 &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; @@ -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 &quadrature) - { - m_quadrature_ = quadrature; - } + void print() const override final; private: std::string m_quadratureType_{}; diff --git a/packages/seacas/libraries/ioss/src/Ioss_VariableType.C b/packages/seacas/libraries/ioss/src/Ioss_VariableType.C index 8fed4ec835..c14a7cfa15 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_VariableType.C +++ b/packages/seacas/libraries/ioss/src/Ioss_VariableType.C @@ -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; } @@ -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(factory(base))), false); - // Register uppercase version also - std::string up_type = Utils::uppercase(syn); - registry().insert(VTM_ValuePair(up_type, const_cast(factory(base))), false); } Registry &VariableType::registry() @@ -104,21 +136,19 @@ namespace Ioss { return names; } - std::vector VariableType::external_types() + std::vector VariableType::external_types(Ioss::VariableType::Type type) { auto vars = registry().m_deleteThese; - std::vector user_vars; - for (const auto *var : vars) { - const auto *basis = dynamic_cast(var); - if (basis != nullptr) { - user_vars.push_back(var); - continue; - } - const auto *quad = dynamic_cast(var); - if (quad != nullptr) { - user_vars.push_back(var); - continue; + std::vector 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; @@ -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) { @@ -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); @@ -176,9 +206,8 @@ namespace Ioss { return true; } - bool - VariableType::create_quadrature_field_type(const std::string &type_name, - const std::vector &quad_points) + bool VariableType::create_quadrature_type(const std::string &type_name, + const std::vector &quad_points) { size_t count = quad_points.size(); if (count < 1) { @@ -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) diff --git a/packages/seacas/libraries/ioss/src/Ioss_VariableType.h b/packages/seacas/libraries/ioss/src/Ioss_VariableType.h index 945b0e6e39..994334b6e1 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_VariableType.h +++ b/packages/seacas/libraries/ioss/src/Ioss_VariableType.h @@ -89,13 +89,14 @@ 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 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 &quad_points); + IOSS_NODISCARD static std::vector + 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 &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); @@ -103,6 +104,8 @@ namespace Ioss { 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 diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C index 642a42d616..5e73880d35 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C @@ -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) { @@ -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); @@ -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(var); + assert(basis != nullptr); ex_basis exo_basis{}; exo_basis.cardinality = basis->component_count(); ex_initialize_basis_struct(&exo_basis, 1, 1); @@ -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(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; @@ -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(var); - if (basis != nullptr) { - output_basis(exoid, basis); - continue; - } - const auto *quad = dynamic_cast(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); } } diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C index 3ae1712490..d922e6fafd 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C @@ -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. @@ -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. diff --git a/packages/seacas/libraries/ioss/src/main/io_info.C b/packages/seacas/libraries/ioss/src/main/io_info.C index ebb32cd788..c8f25eaf60 100644 --- a/packages/seacas/libraries/ioss/src/main/io_info.C +++ b/packages/seacas/libraries/ioss/src/main/io_info.C @@ -83,6 +83,14 @@ namespace { void info_aliases(const Ioss::Region ®ion, 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); @@ -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); } } @@ -346,6 +354,7 @@ namespace { Ioss::Utils::info_property(®ion, Ioss::Property::ATTRIBUTE, "\tAttributes (Reduction): ", "\t"); Ioss::Utils::info_fields(®ion, Ioss::Field::REDUCTION, "\tTransient (Reduction): ", "\t"); + info_variable_types(); } void info_assemblies(Ioss::Region ®ion) diff --git a/packages/seacas/libraries/ioss/src/main/io_shell.C b/packages/seacas/libraries/ioss/src/main/io_shell.C index 251fe49cf6..b4f7f5e76e 100644 --- a/packages/seacas/libraries/ioss/src/main/io_shell.C +++ b/packages/seacas/libraries/ioss/src/main/io_shell.C @@ -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];