From ad7454e382f79a9933cb3aab5b0feb08999098eb Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 28 Aug 2024 16:38:07 -0600 Subject: [PATCH] IOSS: Clean up formatting (clang-format) --- .../libraries/ioss/src/Ioss_DynamicTopology.h | 88 +- .../libraries/ioss/src/Ioss_StructuredBlock.C | 34 +- .../libraries/ioss/src/adios/AdiosWrapper.C | 9 +- .../ioss/src/adios/Ioad_DatabaseIO.h | 25 +- .../src/catalyst/Iocatalyst_CatalystLogging.C | 2 +- .../ioss/src/catalyst/Iocatalyst_DatabaseIO.h | 54 +- .../libraries/ioss/src/cgns/Iocgns_Utils.C | 10 +- .../libraries/ioss/src/cgns/Iocgns_Utils.h | 2 +- .../ioss/src/exodus/Ioex_BaseDatabaseIO.C | 61 +- .../ioss/src/exodus/Ioex_BaseDatabaseIO.h | 10 +- .../ioss/src/exodus/Ioex_DatabaseIO.C | 106 +- .../ioss/src/exodus/Ioex_DecompositionData.C | 19 +- .../ioss/src/exodus/Ioex_ParallelDatabaseIO.C | 8 +- .../ioss/src/exodus/Ioex_ParallelDatabaseIO.h | 3 +- .../libraries/ioss/src/exodus/Ioex_Utils.C | 2 +- .../text_mesh/Iotm_TextMeshAdjacencyGraph.h | 2 +- .../src/unit_tests/UnitTestDynamicTopology.C | 1611 ++++++++--------- 17 files changed, 1024 insertions(+), 1022 deletions(-) diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopology.h b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopology.h index 76de048fd4..3921d8e3a6 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopology.h +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopology.h @@ -20,7 +20,7 @@ #include // for ostream #include -#include // for string, operator< +#include // for string, operator< #include namespace Ioss { @@ -44,16 +44,18 @@ namespace Ioss { * - TOPOLOGY_UNKNOWN: Something else, catchall option. */ enum TopologyModified { - TOPOLOGY_SAME = ( 0), //!< No change, also used for initialization - TOPOLOGY_REORDER = (1U << 0), //!< Data structures reordered on processor, no change between procs. - TOPOLOGY_SHUFFLE = (1U << 1), //!< Globally the same, data moved among processors. - TOPOLOGY_HADAPT = (1U << 2), //!< Elements split/combined; not moved cross-proc - TOPOLOGY_GEOMETRY = (1U << 3), //!< Geometry (mesh coordinates) modified. Restart needs to know this. - TOPOLOGY_CREATEFACE = (1U << 4), //!< Face/Edge are created/deleted. - TOPOLOGY_CREATEELEM = (1U << 5), //!< Elements are created/deleted. - TOPOLOGY_CREATENODE = (1U << 6), //!< Nodes are created/deleted. - TOPOLOGY_CREATEASSEMBLY = (1U << 7), //!< Assemblies are created/deleted. - TOPOLOGY_UNKNOWN = (1U << 8), //!< Unknown change, recreate from scratch. + TOPOLOGY_SAME = (0), //!< No change, also used for initialization + TOPOLOGY_REORDER = + (1U << 0), //!< Data structures reordered on processor, no change between procs. + TOPOLOGY_SHUFFLE = (1U << 1), //!< Globally the same, data moved among processors. + TOPOLOGY_HADAPT = (1U << 2), //!< Elements split/combined; not moved cross-proc + TOPOLOGY_GEOMETRY = + (1U << 3), //!< Geometry (mesh coordinates) modified. Restart needs to know this. + TOPOLOGY_CREATEFACE = (1U << 4), //!< Face/Edge are created/deleted. + TOPOLOGY_CREATEELEM = (1U << 5), //!< Elements are created/deleted. + TOPOLOGY_CREATENODE = (1U << 6), //!< Nodes are created/deleted. + TOPOLOGY_CREATEASSEMBLY = (1U << 7), //!< Assemblies are created/deleted. + TOPOLOGY_UNKNOWN = (1U << 8), //!< Unknown change, recreate from scratch. }; enum class FileControlOption { CONTROL_NONE, CONTROL_AUTO_MULTI_FILE, CONTROL_AUTO_GROUP_FILE }; @@ -61,14 +63,13 @@ namespace Ioss { class IOSS_EXPORT DynamicTopologyObserver { public: - DynamicTopologyObserver(Region *region) - : m_region(region) {} + DynamicTopologyObserver(Region *region) : m_region(region) {} virtual ~DynamicTopologyObserver() {} - virtual void reset_topology_modification_all(); - virtual void reset_topology_modification(); - virtual void set_topology_modification(unsigned int type); + virtual void reset_topology_modification_all(); + virtual void reset_topology_modification(); + virtual void set_topology_modification(unsigned int type); virtual unsigned int get_topology_modification() const; virtual unsigned int get_cumulative_topology_modification() const; @@ -88,8 +89,8 @@ namespace Ioss { void register_region(Region *region); Region *get_region() const { return m_region; } - void register_notifier(DynamicTopologyNotifier *notifier); - DynamicTopologyNotifier* get_notifier() const { return m_notifier; } + void register_notifier(DynamicTopologyNotifier *notifier); + DynamicTopologyNotifier *get_notifier() const { return m_notifier; } virtual void define_model(); virtual void write_model(); @@ -107,9 +108,9 @@ namespace Ioss { DynamicTopologyNotifier *m_notifier{nullptr}; - void check_region() const; + void check_region() const; IOSS_NODISCARD const ParallelUtils &util() const; - void synchronize_topology_modified_flags(); + void synchronize_topology_modified_flags(); void set_topology_modification_nl(unsigned int type); @@ -117,18 +118,19 @@ namespace Ioss { DynamicTopologyObserver(); }; - class IOSS_EXPORT DynamicTopologyNotifier { public: - DynamicTopologyNotifier(const std::string& model_name) - : m_modelName(model_name) {} + DynamicTopologyNotifier(const std::string &model_name) : m_modelName(model_name) {} virtual ~DynamicTopologyNotifier() = default; std::string name() const { return m_modelName; } - std::vector> get_observers() const { return m_observers; } + std::vector> get_observers() const + { + return m_observers; + } void register_observer(std::shared_ptr observer); @@ -138,13 +140,12 @@ namespace Ioss { void set_topology_modification(unsigned int type); - template - bool has_observer_type() const + template bool has_observer_type() const { bool found = false; - for(const std::shared_ptr& observer : m_observers) { - if (dynamic_cast(observer.get()) != nullptr) { + for (const std::shared_ptr &observer : m_observers) { + if (dynamic_cast(observer.get()) != nullptr) { found = true; break; } @@ -152,13 +153,13 @@ namespace Ioss { return found; } - template + template std::vector> get_observer_type() const { std::vector> typed_observers; - for(const std::shared_ptr &observer : m_observers) { - ObserverType* typed_observer = dynamic_cast(observer.get()); + for (const std::shared_ptr &observer : m_observers) { + ObserverType *typed_observer = dynamic_cast(observer.get()); if (typed_observer != nullptr) { typed_observers.push_back(std::dynamic_pointer_cast(observer)); } @@ -168,37 +169,38 @@ namespace Ioss { } private: - const std::string m_modelName; + const std::string m_modelName; std::vector> m_observers; }; - class IOSS_EXPORT DynamicTopologyBroker { public: static DynamicTopologyBroker *broker(); - void register_model(const std::string& model_name); - void remove_model(const std::string& model_name); + void register_model(const std::string &model_name); + void remove_model(const std::string &model_name); void clear_models(); - std::shared_ptr get_notifier(const std::string& model_name) const; - std::vector> get_observers(const std::string& model_name) const; + std::shared_ptr get_notifier(const std::string &model_name) const; + std::vector> + get_observers(const std::string &model_name) const; - void register_observer(const std::string& model_name, std::shared_ptr observer); - void register_observer(const std::string& model_name, std::shared_ptr observer, Region& region); + void register_observer(const std::string &model_name, + std::shared_ptr observer); + void register_observer(const std::string &model_name, + std::shared_ptr observer, Region ®ion); - void reset_topology_modification(const std::string& model_name); - void set_topology_modification(const std::string& model_name, unsigned int type); + void reset_topology_modification(const std::string &model_name); + void set_topology_modification(const std::string &model_name, unsigned int type); private: DynamicTopologyBroker() {}; - DynamicTopologyBroker(DynamicTopologyBroker&); + DynamicTopologyBroker(DynamicTopologyBroker &); std::map> m_notifiers; }; - class IOSS_EXPORT DynamicTopologyFileControl { public: diff --git a/packages/seacas/libraries/ioss/src/Ioss_StructuredBlock.C b/packages/seacas/libraries/ioss/src/Ioss_StructuredBlock.C index 7c8891124a..de43f983ca 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_StructuredBlock.C +++ b/packages/seacas/libraries/ioss/src/Ioss_StructuredBlock.C @@ -540,14 +540,18 @@ namespace Ioss { { auto lhzc = this->m_zoneConnectivity; auto rhzc = rhs.m_zoneConnectivity; - Ioss::sort(lhzc.begin(), lhzc.end(), [](const ZoneConnectivity &l, const ZoneConnectivity &r) { - return l.m_connectionName < r.m_connectionName;}); - Ioss::sort(rhzc.begin(), rhzc.end(), [](const ZoneConnectivity &l, const ZoneConnectivity &r) { - return l.m_connectionName < r.m_connectionName;}); + Ioss::sort(lhzc.begin(), lhzc.end(), + [](const ZoneConnectivity &l, const ZoneConnectivity &r) { + return l.m_connectionName < r.m_connectionName; + }); + Ioss::sort(rhzc.begin(), rhzc.end(), + [](const ZoneConnectivity &l, const ZoneConnectivity &r) { + return l.m_connectionName < r.m_connectionName; + }); if (!vec_equal(lhzc, rhzc)) { - fmt::print(Ioss::OUTPUT(), "StructuredBlock: Zone Connectivity mismatch (size {} vs {})\n", - this->m_zoneConnectivity.size(), rhs.m_zoneConnectivity.size()); - same = false; + fmt::print(Ioss::OUTPUT(), "StructuredBlock: Zone Connectivity mismatch (size {} vs {})\n", + this->m_zoneConnectivity.size(), rhs.m_zoneConnectivity.size()); + same = false; } } @@ -558,13 +562,17 @@ namespace Ioss { { auto lhbc = this->m_boundaryConditions; auto rhbc = rhs.m_boundaryConditions; - Ioss::sort(lhbc.begin(), lhbc.end(), [](const BoundaryCondition &l, const BoundaryCondition &r) { - return l.m_bcName < r.m_bcName;}); - Ioss::sort(rhbc.begin(), rhbc.end(), [](const BoundaryCondition &l, const BoundaryCondition &r) { - return l.m_bcName < r.m_bcName;}); + Ioss::sort(lhbc.begin(), lhbc.end(), + [](const BoundaryCondition &l, const BoundaryCondition &r) { + return l.m_bcName < r.m_bcName; + }); + Ioss::sort(rhbc.begin(), rhbc.end(), + [](const BoundaryCondition &l, const BoundaryCondition &r) { + return l.m_bcName < r.m_bcName; + }); if (!vec_equal(lhbc, rhbc)) { - fmt::print(Ioss::OUTPUT(), "StructuredBlock: Boundary Conditions mismatch\n"); - same = false; + fmt::print(Ioss::OUTPUT(), "StructuredBlock: Boundary Conditions mismatch\n"); + same = false; } } diff --git a/packages/seacas/libraries/ioss/src/adios/AdiosWrapper.C b/packages/seacas/libraries/ioss/src/adios/AdiosWrapper.C index 6efb3353df..aace3d30a6 100644 --- a/packages/seacas/libraries/ioss/src/adios/AdiosWrapper.C +++ b/packages/seacas/libraries/ioss/src/adios/AdiosWrapper.C @@ -13,13 +13,12 @@ namespace Ioad { AdiosWrapper::AdiosWrapper(Ioss_MPI_Comm comm, const std::string &filename, bool is_input, unsigned long rank, const Ioss::PropertyManager &properties) #if ADIOS2_USE_MPI - : adios2::ADIOS(comm), + : adios2::ADIOS(comm), #else - : adios2::ADIOS(), + : adios2::ADIOS(), #endif - adios2::IO(IOInit(properties, is_input)), - adios2::Engine(EngineInit(filename, is_input)), m_Rank(rank), m_Communicator(comm), - m_OpenStep(false) + adios2::IO(IOInit(properties, is_input)), adios2::Engine(EngineInit(filename, is_input)), + m_Rank(rank), m_Communicator(comm), m_OpenStep(false) { } diff --git a/packages/seacas/libraries/ioss/src/adios/Ioad_DatabaseIO.h b/packages/seacas/libraries/ioss/src/adios/Ioad_DatabaseIO.h index 54b0caef8b..b21c65d3b3 100644 --- a/packages/seacas/libraries/ioss/src/adios/Ioad_DatabaseIO.h +++ b/packages/seacas/libraries/ioss/src/adios/Ioad_DatabaseIO.h @@ -60,18 +60,19 @@ namespace Ioad { size_t data_size) const override; int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data, size_t data_size) const override; - int64_t get_field_internal(const Ioss::StructuredBlock */* sb */, const Ioss::Field &/*field*/, - void */*data*/, size_t /*data_size*/) const override + int64_t get_field_internal(const Ioss::StructuredBlock * /* sb */, + const Ioss::Field & /*field*/, void * /*data*/, + size_t /*data_size*/) const override { return -1; } - int64_t get_field_internal(const Ioss::Assembly */*sb*/, const Ioss::Field &/*field*/, void */*data*/, - size_t /*data_size*/) const override + int64_t get_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/, + void * /*data*/, size_t /*data_size*/) const override { return -1; } - int64_t get_field_internal(const Ioss::Blob */*sb*/, const Ioss::Field &/*field*/, void */*data*/, - size_t /*data_size*/) const override + int64_t get_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/, + void * /*data*/, size_t /*data_size*/) const override { return -1; } @@ -120,18 +121,18 @@ namespace Ioad { size_t data_size) const override; int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data, size_t data_size) const override; - int64_t put_field_internal(const Ioss::StructuredBlock */*sb*/, const Ioss::Field &/*field*/, - void */*data*/, size_t /*data_size*/) const override + int64_t put_field_internal(const Ioss::StructuredBlock * /*sb*/, const Ioss::Field & /*field*/, + void * /*data*/, size_t /*data_size*/) const override { return -1; } - int64_t put_field_internal(const Ioss::Assembly */*sb*/, const Ioss::Field &/*field*/, void */*data*/, - size_t /*data_size*/) const override + int64_t put_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/, + void * /*data*/, size_t /*data_size*/) const override { return -1; } - int64_t put_field_internal(const Ioss::Blob */*sb*/, const Ioss::Field &/*field*/, void */*data*/, - size_t /*data_size*/) const override + int64_t put_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/, + void * /*data*/, size_t /*data_size*/) const override { return -1; } diff --git a/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_CatalystLogging.C b/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_CatalystLogging.C index a426ffe4c8..f2dd02216f 100644 --- a/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_CatalystLogging.C +++ b/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_CatalystLogging.C @@ -5,10 +5,10 @@ // See packages/seacas/LICENSE for details #include +#include #include #include #include -#include namespace Iocatalyst { diff --git a/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_DatabaseIO.h b/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_DatabaseIO.h index 743cebe6fa..d28f6a7d80 100644 --- a/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_DatabaseIO.h +++ b/packages/seacas/libraries/ioss/src/catalyst/Iocatalyst_DatabaseIO.h @@ -14,8 +14,8 @@ #include "Ioss_Region.h" // for Region, SideSetContainer, etc #include "Ioss_SideSet.h" // for SideBlockContainer, SideSet -#include "Ioss_Field.h" // for Field, etc #include "Iocatalyst_CatalystManager.h" +#include "Ioss_Field.h" // for Field, etc #include // for std::unique_ptr @@ -135,8 +135,8 @@ namespace Iocatalyst { size_t data_size) const override; int64_t get_field_internal(const Ioss::Assembly *as, const Ioss::Field &field, void *data, size_t data_size) const override; - int64_t get_field_internal(const Ioss::Blob *bl, const Ioss::Field &field, - void *data, size_t data_size) const override; + int64_t get_field_internal(const Ioss::Blob *bl, const Ioss::Field &field, void *data, + size_t data_size) const override; int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, void *data, size_t data_size) const override; @@ -144,30 +144,30 @@ namespace Iocatalyst { size_t *data_size) const override; int64_t get_zc_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, - void **data, size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void **data, + size_t *data_size) const override; int64_t get_zc_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::Assembly *as, const Ioss::Field &field, - void **data, size_t *data_size) const override; - int64_t get_zc_field_internal(const Ioss::Blob *bl, const Ioss::Field &field, - void **data, size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::Assembly *as, const Ioss::Field &field, void **data, + size_t *data_size) const override; + int64_t get_zc_field_internal(const Ioss::Blob *bl, const Ioss::Field &field, void **data, + size_t *data_size) const override; int64_t get_zc_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, void **data, size_t *data_size) const override; @@ -197,8 +197,8 @@ namespace Iocatalyst { size_t data_size) const override; int64_t put_field_internal(const Ioss::Assembly *as, const Ioss::Field &field, void *data, size_t data_size) const override; - int64_t put_field_internal(const Ioss::Blob *bl, const Ioss::Field &field, - void *data, size_t data_size) const override; + int64_t put_field_internal(const Ioss::Blob *bl, const Ioss::Field &field, void *data, + size_t data_size) const override; int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, void *data, size_t data_size) const override; diff --git a/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.C b/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.C index 84bbd54c37..92ce1d1a6b 100644 --- a/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.C +++ b/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.C @@ -1938,7 +1938,7 @@ Iocgns::Utils::resolve_processor_shared_nodes(Ioss::Region ®ion, int my_proce std::vector>> shared_nodes(blocks.size() + 1); for (auto &owner_block : blocks) { - int owner_zone = owner_block->get_property("zone").get_int(); + int owner_zone = owner_block->get_property("zone").get_int(); for (const auto &zgc : owner_block->m_zoneConnectivity) { assert(zgc.m_donorProcessor >= 0); assert(zgc.m_ownerProcessor >= 0); @@ -1950,10 +1950,10 @@ Iocgns::Utils::resolve_processor_shared_nodes(Ioss::Region ®ion, int my_proce // don't store or access any "bulk" data on it. auto donor_block = region.get_structured_block(zgc.m_donorName); assert(donor_block != nullptr); - int donor_zone = donor_block->get_property("zone").get_int(); - std::vector i_range = zgc.get_range(1); - std::vector j_range = zgc.get_range(2); - std::vector k_range = zgc.get_range(3); + int donor_zone = donor_block->get_property("zone").get_int(); + std::vector i_range = zgc.get_range(1); + std::vector j_range = zgc.get_range(2); + std::vector k_range = zgc.get_range(3); for (auto &k : k_range) { for (auto &j : j_range) { for (auto &i : i_range) { diff --git a/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.h b/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.h index 874f0dd79f..e8438dc1ec 100644 --- a/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.h +++ b/packages/seacas/libraries/ioss/src/cgns/Iocgns_Utils.h @@ -301,7 +301,7 @@ namespace Iocgns { static void write_state_meta_data(int file_ptr, const Ioss::Region ®ion, bool is_parallel_io); static size_t common_write_metadata(int file_ptr, const Ioss::Region ®ion, - std::vector &zone_offset, bool is_parallel); + std::vector &zone_offset, bool is_parallel); static size_t resolve_nodes(Ioss::Region ®ion, int my_processor, bool is_parallel); IOSS_NODISCARD static std::vector>> resolve_processor_shared_nodes(Ioss::Region ®ion, int my_processor); diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C index 5cb2caec64..d0a36c9fe0 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.C @@ -4,6 +4,7 @@ // // See packages/seacas/LICENSE for details +#include #include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include "Ioex_Utils.h" #include "Ioss_Assembly.h" @@ -88,7 +88,7 @@ namespace { template void write_attribute_names(int exoid, ex_entity_type type, const std::vector &entities); - void query_groups(int exoid, Ioss::NameList& names, bool return_full_names); + void query_groups(int exoid, Ioss::NameList &names, bool return_full_names); class AssemblyTreeFilter { @@ -508,23 +508,23 @@ namespace Ioex { bool success = false; Ioss::SerializeIO serializeIO_(this); - int exoid = get_file_pointer(); + int exoid = get_file_pointer(); - int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN); - std::vector group_name(group_name_length+1, '\0'); + int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN); + std::vector group_name(group_name_length + 1, '\0'); // Get name of this group... int idum; float rdum; - int ierr = ex_inquire(exoid, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data()); + int ierr = ex_inquire(exoid, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data()); if (ierr < 0) { std::ostringstream errmsg; - fmt::print(errmsg, "ERROR: Could not open root group of group named '{}' in file '{}'.\n", m_groupName, - get_filename()); + fmt::print(errmsg, "ERROR: Could not open root group of group named '{}' in file '{}'.\n", + m_groupName, get_filename()); IOSS_ERROR(errmsg); } - m_groupName = std::string(group_name.data()); + m_groupName = std::string(group_name.data()); m_exodusFilePtr = ex_inquire_int(exoid, EX_INQ_GROUP_ROOT); if (m_exodusFilePtr < 0) { @@ -543,7 +543,7 @@ namespace Ioex { bool success = false; Ioss::SerializeIO serializeIO_(this); - int exoid = get_file_pointer(); + int exoid = get_file_pointer(); m_groupName = group_name; ex_get_group_id(exoid, m_groupName.c_str(), &m_exodusFilePtr); @@ -564,7 +564,7 @@ namespace Ioex { if (!is_input()) { // Get existing file pointer... Ioss::SerializeIO serializeIO_(this); - int exoid = get_file_pointer(); + int exoid = get_file_pointer(); // Check name for '/' which is not allowed since it is the // separator character in a full group path @@ -3221,13 +3221,12 @@ namespace Ioex { write_coordinate_frames(get_file_pointer(), get_region()->get_coordinate_frames()); } - Ioss::NameList BaseDatabaseIO::groups_describe_nl(bool return_full_names) { Ioss::SerializeIO serializeIO_(this); Ioss::NameList names; - int group_root = ex_inquire_int(get_file_pointer(), EX_INQ_GROUP_ROOT); + int group_root = ex_inquire_int(get_file_pointer(), EX_INQ_GROUP_ROOT); query_groups(group_root, names, return_full_names); return names; @@ -3259,21 +3258,24 @@ namespace Ioex { int BaseDatabaseIO::num_child_group_nl() { Ioss::SerializeIO serializeIO_(this); - int exoid = get_file_pointer(); - exoid = ex_inquire_int(exoid, EX_INQ_GROUP_ROOT); - int num_children = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS); + int exoid = get_file_pointer(); + exoid = ex_inquire_int(exoid, EX_INQ_GROUP_ROOT); + int num_children = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS); return num_children; } bool BaseDatabaseIO::open_child_group_nl(int index) { - if(index < 0) return false; + if (index < 0) + return false; Ioss::SerializeIO serializeIO_(this); - int exoid = get_file_pointer(); - int num_children = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS); - if(num_children == 0) return true; + int exoid = get_file_pointer(); + int num_children = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS); + if (num_children == 0) + return true; - if(index >= num_children) return false; + if (index >= num_children) + return false; std::vector children(num_children); @@ -3284,8 +3286,8 @@ namespace Ioex { exoid = children[index]; - int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN); - std::vector group_name(group_name_length+1, '\0'); + int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN); + std::vector group_name(group_name_length + 1, '\0'); // Get name of this group... int idum; @@ -3296,7 +3298,7 @@ namespace Ioex { } m_exodusFilePtr = exoid; - m_groupName = std::string(group_name.data()); + m_groupName = std::string(group_name.data()); return true; } @@ -3603,13 +3605,13 @@ namespace { #endif } - void query_groups(int exoid, Ioss::NameList& names, bool return_full_names) + void query_groups(int exoid, Ioss::NameList &names, bool return_full_names) { int idum; float rdum; - int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN); - std::vector group_name(group_name_length+1, '\0'); + int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN); + std::vector group_name(group_name_length + 1, '\0'); // Get name of this group... int ierr = ex_inquire(exoid, EX_INQ_GROUP_NAME, &idum, &rdum, group_name.data()); @@ -3617,14 +3619,15 @@ namespace { Ioex::exodus_error(exoid, __LINE__, __func__, __FILE__); } - if(return_full_names) { + if (return_full_names) { std::fill(group_name.begin(), group_name.end(), '\0'); ierr = ex_inquire(exoid, EX_INQ_FULL_GROUP_NAME, &idum, &rdum, group_name.data()); if (ierr < 0) { Ioex::exodus_error(exoid, __LINE__, __func__, __FILE__); } names.push_back(std::string(group_name.data())); - } else { + } + else { names.push_back(std::string(group_name.data())); } diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.h b/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.h index b6f18fc756..3f69655746 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.h +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_BaseDatabaseIO.h @@ -101,11 +101,11 @@ namespace Ioex { void release_memory_nl() override; - int num_child_group_nl() override; - bool open_child_group_nl(int index) override; - bool open_root_group_nl() override; - bool open_group_nl(const std::string &group_name) override; - bool create_subgroup_nl(const std::string &group_name) override; + int num_child_group_nl() override; + bool open_child_group_nl(int index) override; + bool open_root_group_nl() override; + bool open_group_nl(const std::string &group_name) override; + bool create_subgroup_nl(const std::string &group_name) override; Ioss::NameList groups_describe_nl(bool return_full_names) override; bool begin_nl(Ioss::State state) override; diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_DatabaseIO.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_DatabaseIO.C index d84be09252..66658f7374 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_DatabaseIO.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_DatabaseIO.C @@ -643,8 +643,8 @@ namespace Ioex { void DatabaseIO::get_step_times_nl() { - bool exists = false; - double last_time = DBL_MAX; + bool exists = false; + double last_time = DBL_MAX; std::vector tsteps(0); if (dbUsage == Ioss::WRITE_HISTORY) { @@ -685,60 +685,62 @@ namespace Ioex { Ioss::SerializeIO serializeIO_(this); m_timestepCount = ex_inquire_int(get_file_pointer(), EX_INQ_TIME); } - // Need to sync timestep count across ranks if parallel... - if (isParallel) { - auto min_timestep_count = util().global_minmax(m_timestepCount, Ioss::ParallelUtils::DO_MIN); - if (min_timestep_count == 0) { - auto max_timestep_count = util().global_minmax(m_timestepCount, Ioss::ParallelUtils::DO_MAX); - if (max_timestep_count != 0) { - if (myProcessor == 0) { - // NOTE: Don't want to warn on all processors if the - // timestep count is zero on some, but not all ranks. - fmt::print(Ioss::WarnOut(), - "At least one database has no timesteps. No times will be read on ANY" - " database for consistency.\n"); - } - } - } - m_timestepCount = min_timestep_count; - } - - if (m_timestepCount <= 0) { - return; + // Need to sync timestep count across ranks if parallel... + if (isParallel) { + auto min_timestep_count = + util().global_minmax(m_timestepCount, Ioss::ParallelUtils::DO_MIN); + if (min_timestep_count == 0) { + auto max_timestep_count = + util().global_minmax(m_timestepCount, Ioss::ParallelUtils::DO_MAX); + if (max_timestep_count != 0) { + if (myProcessor == 0) { + // NOTE: Don't want to warn on all processors if the + // timestep count is zero on some, but not all ranks. + fmt::print(Ioss::WarnOut(), + "At least one database has no timesteps. No times will be read on ANY" + " database for consistency.\n"); + } + } } + m_timestepCount = min_timestep_count; + } - // For an exodus file, timesteps are global and are stored in the region. - // Read the timesteps and add to the region - tsteps.resize(m_timestepCount, -std::numeric_limits::max()); - - // The `EXODUS_CALL_GET_ALL_TIMES=NO` is typically only used in - // isSerialParallel mode and the client is responsible for - // making sure that the step times are handled correctly. All - // databases will know about the number of timesteps, but if - // this is skipped, then the times will all be zero. Use case - // is that in isSerialParallel, each call to - // `ex_get_all_times` for all files is performed sequentially, - // so if you have hundreds to thousands of files, the time for - // the call is additive and since timesteps are record - // variables in netCDF, accessing the data for all timesteps - // involves lseeks throughout the file. - bool call_ex_get_all_times = true; - Ioss::Utils::check_set_bool_property(properties, "EXODUS_CALL_GET_ALL_TIMES", - call_ex_get_all_times); - if (call_ex_get_all_times) { - Ioss::SerializeIO serializeIO_(this); - int error = ex_get_all_times(get_file_pointer(), Data(tsteps)); - if (error < 0) { - Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); - } + if (m_timestepCount <= 0) { + return; + } + + // For an exodus file, timesteps are global and are stored in the region. + // Read the timesteps and add to the region + tsteps.resize(m_timestepCount, -std::numeric_limits::max()); + + // The `EXODUS_CALL_GET_ALL_TIMES=NO` is typically only used in + // isSerialParallel mode and the client is responsible for + // making sure that the step times are handled correctly. All + // databases will know about the number of timesteps, but if + // this is skipped, then the times will all be zero. Use case + // is that in isSerialParallel, each call to + // `ex_get_all_times` for all files is performed sequentially, + // so if you have hundreds to thousands of files, the time for + // the call is additive and since timesteps are record + // variables in netCDF, accessing the data for all timesteps + // involves lseeks throughout the file. + bool call_ex_get_all_times = true; + Ioss::Utils::check_set_bool_property(properties, "EXODUS_CALL_GET_ALL_TIMES", + call_ex_get_all_times); + if (call_ex_get_all_times) { + Ioss::SerializeIO serializeIO_(this); + int error = ex_get_all_times(get_file_pointer(), Data(tsteps)); + if (error < 0) { + Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); } + } - // See if the "last_written_time" attribute exists and if it - // does, check that it matches the largest time in 'tsteps'. - { - Ioss::SerializeIO serializeIO_(this); - exists = Ioex::read_last_time_attribute(get_file_pointer(), &last_time); - } + // See if the "last_written_time" attribute exists and if it + // does, check that it matches the largest time in 'tsteps'. + { + Ioss::SerializeIO serializeIO_(this); + exists = Ioex::read_last_time_attribute(get_file_pointer(), &last_time); + } if (exists && isParallel) { // Assume that if it exists on 1 processor, it exists on diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_DecompositionData.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_DecompositionData.C index ee3fc6c16d..f2d09484a5 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_DecompositionData.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_DecompositionData.C @@ -291,14 +291,15 @@ namespace Ioex { "exodus", filename, Ioss::READ_RESTART, Ioss::ParallelUtils::comm_self(), properties); Ioss::Region region(dbi, "line_decomp_region"); - Ioss::DecompUtils::line_decompose( - region, m_processorCount, m_decomposition.m_method, m_decomposition.m_decompExtra, - element_to_proc_global, INT(0)); - - if (m_decomposition.m_showHWM || m_decomposition.m_showProgress) { - auto work_per_rank = Ioss::DecompUtils::get_work_per_rank(element_to_proc_global, m_processorCount); - Ioss::DecompUtils::output_decomposition_statistics(work_per_rank); - } + Ioss::DecompUtils::line_decompose(region, m_processorCount, m_decomposition.m_method, + m_decomposition.m_decompExtra, element_to_proc_global, + INT(0)); + + if (m_decomposition.m_showHWM || m_decomposition.m_showProgress) { + auto work_per_rank = + Ioss::DecompUtils::get_work_per_rank(element_to_proc_global, m_processorCount); + Ioss::DecompUtils::output_decomposition_statistics(work_per_rank); + } } // Now broadcast the parts of the `element_to_proc_global` // vector to the owning ranks in the initial linear @@ -328,7 +329,7 @@ namespace Ioex { } if (m_decomposition.m_lineDecomp) { - // Do not combine into previous if block since we want to release memory for + // Do not combine into previous if block since we want to release memory for // the local vectors in that block before allocating the large adjacency vector. generate_adjacency_list(filePtr, m_decomposition); } diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.C index 8ce9dd59b7..3467a1c25a 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.C @@ -920,7 +920,7 @@ namespace Ioex { std::vector tsteps(0); { - timestep_count = ex_inquire_int(get_file_pointer(), EX_INQ_TIME); + timestep_count = ex_inquire_int(get_file_pointer(), EX_INQ_TIME); m_timestepCount = timestep_count; if (timestep_count <= 0) { return; @@ -4809,7 +4809,7 @@ namespace Ioex { void ParallelDatabaseIO::output_processor_id_map(Ioss::Region *region, INT /*dummy*/) { std::vector proc_id(elementCount, myProcessor); - const auto &blocks = region->get_element_blocks(); + const auto &blocks = region->get_element_blocks(); for (const auto &block : blocks) { put_field_internal(block, block->get_field("proc_id"), Data(proc_id), -1); } @@ -4870,10 +4870,10 @@ namespace Ioex { add_processor_id_map(region); output_other_metadata(); if (int_byte_size_api() == 8) { - output_processor_id_map(region, int64_t(0)); + output_processor_id_map(region, int64_t(0)); } else { - output_processor_id_map(region, int(0)); + output_processor_id_map(region, int(0)); } } } diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.h b/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.h index 2ab679de54..4bf66f5895 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.h +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_ParallelDatabaseIO.h @@ -197,8 +197,7 @@ namespace Ioex { void write_entity_transient_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge, int64_t count, void *variables) const; void write_meta_data(Ioss::IfDatabaseExistsBehavior behavior) override; - template - void output_processor_id_map(Ioss::Region *region, INT /*dummy*/); + template void output_processor_id_map(Ioss::Region *region, INT /*dummy*/); // Read related metadata and store it in the region... void read_region(); diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C index 12ac92d9e6..8cf3cf2b3f 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include "Ioss_BasisVariableType.h" #include "Ioss_CoordinateFrame.h" diff --git a/packages/seacas/libraries/ioss/src/text_mesh/Iotm_TextMeshAdjacencyGraph.h b/packages/seacas/libraries/ioss/src/text_mesh/Iotm_TextMeshAdjacencyGraph.h index 253d9f47ac..093cea5f08 100644 --- a/packages/seacas/libraries/ioss/src/text_mesh/Iotm_TextMeshAdjacencyGraph.h +++ b/packages/seacas/libraries/ioss/src/text_mesh/Iotm_TextMeshAdjacencyGraph.h @@ -94,7 +94,7 @@ namespace Iotm { struct FaceConnection { FaceConnection() - : thisSide(INVALID_SIDE), thatElement(INVALID_INDEX), thatSide(INVALID_SIDE){}; + : thisSide(INVALID_SIDE), thatElement(INVALID_INDEX), thatSide(INVALID_SIDE) {}; FaceConnection(int thisSide_, IndexType otherElement_, int otherSide_) : thisSide(thisSide_), thatElement(otherElement_), thatSide(otherSide_) diff --git a/packages/seacas/libraries/ioss/src/unit_tests/UnitTestDynamicTopology.C b/packages/seacas/libraries/ioss/src/unit_tests/UnitTestDynamicTopology.C index 7d18b1e14b..6177c0c9a4 100644 --- a/packages/seacas/libraries/ioss/src/unit_tests/UnitTestDynamicTopology.C +++ b/packages/seacas/libraries/ioss/src/unit_tests/UnitTestDynamicTopology.C @@ -21,10 +21,10 @@ #include // for unlink #include "Ionit_Initializer.h" -#include "Ioss_DatabaseIO.h" // for DatabaseIO #include "Ioss_DBUsage.h" +#include "Ioss_DatabaseIO.h" // for DatabaseIO #include "Ioss_ElementBlock.h" -#include "Ioss_Field.h" // for Field, etc +#include "Ioss_Field.h" // for Field, etc #include "Ioss_FileInfo.h" #include "Ioss_IOFactory.h" #include "Ioss_NodeBlock.h" @@ -36,1076 +36,1063 @@ #include "exodus/Ioex_DatabaseIO.h" namespace { -std::string get_many_block_mesh_desc(unsigned numBlocks) -{ - std::ostringstream oss; - std::vector elementIds(numBlocks); - std::iota(elementIds.begin(), elementIds.end(), 1); - - unsigned proc = 0; - for (unsigned i = 0; i < numBlocks; ++i) { - unsigned elemId = elementIds[i]; - unsigned firstNodeId = i * 4 + 1; - oss << proc << "," << elemId << ",HEX_8,"; - for (unsigned node = firstNodeId; node < firstNodeId + 8; ++node) { - oss << node << ","; - } - unsigned blockId = i + 1; - oss << "block_" << blockId; + std::string get_many_block_mesh_desc(unsigned numBlocks) + { + std::ostringstream oss; + std::vector elementIds(numBlocks); + std::iota(elementIds.begin(), elementIds.end(), 1); + + unsigned proc = 0; + for (unsigned i = 0; i < numBlocks; ++i) { + unsigned elemId = elementIds[i]; + unsigned firstNodeId = i * 4 + 1; + oss << proc << "," << elemId << ",HEX_8,"; + for (unsigned node = firstNodeId; node < firstNodeId + 8; ++node) { + oss << node << ","; + } + unsigned blockId = i + 1; + oss << "block_" << blockId; + + if (i < numBlocks - 1) { + oss << "\n"; + } - if (i < numBlocks - 1) { - oss << "\n"; + proc++; } - proc++; - } + oss << "|coordinates:"; - oss << "|coordinates:"; + std::vector planeCoords = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0}; - std::vector planeCoords = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0}; + for (double coord : planeCoords) { + oss << coord << ","; + } - for (double coord : planeCoords) { - oss << coord << ","; - } + for (unsigned i = 1; i <= numBlocks; ++i) { + for (unsigned point = 0; point < 4; ++point) { + planeCoords[3 * point + 2] += 1; + } - for (unsigned i = 1; i <= numBlocks; ++i) { - for (unsigned point = 0; point < 4; ++point) { - planeCoords[3 * point + 2] += 1; + for (double coord : planeCoords) { + oss << coord << ","; + } } - for (double coord : planeCoords) { - oss << coord << ","; - } + return oss.str(); } - return oss.str(); -} + void define_model(const Ioss::Region &i_region, Ioss::Region &o_region) + { + Ioss::DatabaseIO *o_database = o_region.get_database(); -void define_model(const Ioss::Region &i_region, Ioss::Region &o_region) -{ - Ioss::DatabaseIO *o_database = o_region.get_database(); + o_region.begin_mode(Ioss::STATE_DEFINE_MODEL); - o_region.begin_mode(Ioss::STATE_DEFINE_MODEL); + auto &nodeblocks = o_region.get_node_blocks(); - auto& nodeblocks = o_region.get_node_blocks(); + Ioss::NodeBlock *i_nb = i_region.get_node_blocks()[0]; + int64_t spatial_dim = 3; + int64_t num_nodes = i_nb->entity_count(); + Ioss::NodeBlock *o_nb = new Ioss::NodeBlock(o_database, "nodeblock_1", num_nodes, spatial_dim); + o_region.add(o_nb); - Ioss::NodeBlock *i_nb = i_region.get_node_blocks()[0]; - int64_t spatial_dim = 3; - int64_t num_nodes = i_nb->entity_count(); - Ioss::NodeBlock *o_nb = new Ioss::NodeBlock(o_database, "nodeblock_1", num_nodes, spatial_dim); - o_region.add(o_nb); + for (Ioss::ElementBlock *i_eb : i_region.get_element_blocks()) { + Ioss::ElementBlock *o_eb = new Ioss::ElementBlock( + o_database, i_eb->name(), i_eb->topology()->name(), i_eb->entity_count()); + o_eb->property_add(i_eb->get_property("id")); + o_region.add(o_eb); + } - for (Ioss::ElementBlock *i_eb : i_region.get_element_blocks()) { - Ioss::ElementBlock *o_eb = new Ioss::ElementBlock( - o_database, i_eb->name(), i_eb->topology()->name(), i_eb->entity_count()); - o_eb->property_add(i_eb->get_property("id")); - o_region.add(o_eb); + o_region.end_mode(Ioss::STATE_DEFINE_MODEL); } - o_region.end_mode(Ioss::STATE_DEFINE_MODEL); -} + void write_model(const Ioss::Region &i_region, Ioss::Region &o_region) + { + Ioss::NodeBlock *i_nb = i_region.get_node_blocks()[0]; + Ioss::NodeBlock *o_nb = o_region.get_node_blocks()[0]; -void write_model(const Ioss::Region &i_region, Ioss::Region &o_region) -{ - Ioss::NodeBlock *i_nb = i_region.get_node_blocks()[0]; - Ioss::NodeBlock *o_nb = o_region.get_node_blocks()[0]; + o_region.begin_mode(Ioss::STATE_MODEL); + std::vector coordinates; + std::vector node_ids; + i_nb->get_field_data("ids", node_ids); + i_nb->get_field_data("mesh_model_coordinates", coordinates); - o_region.begin_mode(Ioss::STATE_MODEL); - std::vector coordinates; - std::vector node_ids; - i_nb->get_field_data("ids", node_ids); - i_nb->get_field_data("mesh_model_coordinates", coordinates); + o_nb->put_field_data("ids", node_ids); + o_nb->put_field_data("mesh_model_coordinates", coordinates); - o_nb->put_field_data("ids", node_ids); - o_nb->put_field_data("mesh_model_coordinates", coordinates); + for (Ioss::ElementBlock *i_eb : i_region.get_element_blocks()) { + Ioss::ElementBlock *o_eb = o_region.get_element_block(i_eb->name()); + std::vector elem_ids; + std::vector connectivity; - for (Ioss::ElementBlock *i_eb : i_region.get_element_blocks()) { - Ioss::ElementBlock *o_eb = o_region.get_element_block(i_eb->name()); - std::vector elem_ids; - std::vector connectivity; + i_eb->get_field_data("ids", elem_ids); + i_eb->get_field_data("connectivity", connectivity); - i_eb->get_field_data("ids", elem_ids); - i_eb->get_field_data("connectivity", connectivity); + o_eb->put_field_data("ids", elem_ids); + o_eb->put_field_data("connectivity", connectivity); + } - o_eb->put_field_data("ids", elem_ids); - o_eb->put_field_data("connectivity", connectivity); + o_region.end_mode(Ioss::STATE_MODEL); } - o_region.end_mode(Ioss::STATE_MODEL); -} - -void define_transient(const Ioss::Region &i_region, Ioss::Region &o_region, - const std::string &elemFieldName) -{ - o_region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT); + void define_transient(const Ioss::Region &i_region, Ioss::Region &o_region, + const std::string &elemFieldName) + { + o_region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT); - for (Ioss::ElementBlock *o_eb : o_region.get_element_blocks()) { - size_t num_elem = o_eb->get_property("entity_count").get_int(); - std::string storage = "scalar"; + for (Ioss::ElementBlock *o_eb : o_region.get_element_blocks()) { + size_t num_elem = o_eb->get_property("entity_count").get_int(); + std::string storage = "scalar"; - Ioss::Field field(elemFieldName, Ioss::Field::REAL, storage, 1, Ioss::Field::Field::TRANSIENT, - num_elem); - o_eb->field_add(field); + Ioss::Field field(elemFieldName, Ioss::Field::REAL, storage, 1, Ioss::Field::Field::TRANSIENT, + num_elem); + o_eb->field_add(field); + } + o_region.end_mode(Ioss::STATE_DEFINE_TRANSIENT); } - o_region.end_mode(Ioss::STATE_DEFINE_TRANSIENT); -} -int write_transient(Ioss::Region &o_region, const std::string &elemFieldName, const double time) -{ - o_region.begin_mode(Ioss::STATE_TRANSIENT); - int step = o_region.add_state(time); - o_region.begin_state(step); + int write_transient(Ioss::Region &o_region, const std::string &elemFieldName, const double time) + { + o_region.begin_mode(Ioss::STATE_TRANSIENT); + int step = o_region.add_state(time); + o_region.begin_state(step); + + for (Ioss::ElementBlock *o_eb : o_region.get_element_blocks()) { + size_t num_elem = o_eb->get_property("entity_count").get_int(); - for (Ioss::ElementBlock *o_eb : o_region.get_element_blocks()) { - size_t num_elem = o_eb->get_property("entity_count").get_int(); + std::vector field_data(num_elem); + std::vector elem_ids; - std::vector field_data(num_elem); - std::vector elem_ids; + o_eb->get_field_data("ids", elem_ids); + for (size_t i = 0; i < elem_ids.size(); i++) { + field_data[i] = (double)elem_ids[i] + 100 * time; + } - o_eb->get_field_data("ids", elem_ids); - for (size_t i = 0; i < elem_ids.size(); i++) { - field_data[i] = (double)elem_ids[i] + 100*time; + o_eb->put_field_data(elemFieldName, field_data); } - o_eb->put_field_data(elemFieldName, field_data); + o_region.end_state(step); + o_region.end_mode(Ioss::STATE_TRANSIENT); + + return step; } - o_region.end_state(step); - o_region.end_mode(Ioss::STATE_TRANSIENT); + class Observer : public Ioss::DynamicTopologyObserver + { + public: + Observer(Ioss::Region &inputRegion_, const std::string &elemFieldName_, + const Ioss::FileControlOption fileControlOption_) + : Ioss::DynamicTopologyObserver(nullptr), inputRegion(inputRegion_), + elemFieldName(elemFieldName_), fileControlOption(fileControlOption_) + { + } - return step; -} + virtual ~Observer() {} -class Observer : public Ioss::DynamicTopologyObserver -{ -public: - Observer(Ioss::Region& inputRegion_, - const std::string &elemFieldName_, - const Ioss::FileControlOption fileControlOption_) - : Ioss::DynamicTopologyObserver(nullptr) - , inputRegion(inputRegion_) - , elemFieldName(elemFieldName_) - , fileControlOption(fileControlOption_) - {} + void define_model() override { ::define_model(inputRegion, *get_region()); } - virtual ~Observer() {} + void write_model() override { ::write_model(inputRegion, *get_region()); } - void define_model() override - { - ::define_model(inputRegion, *get_region()); - } + void define_transient() override + { + ::define_transient(inputRegion, *get_region(), elemFieldName); + } - void write_model() override - { - ::write_model(inputRegion, *get_region()); - } + Ioss::FileControlOption get_control_option() const override { return fileControlOption; } - void define_transient() override - { - ::define_transient(inputRegion, *get_region(), elemFieldName); - } + private: + Observer(); + + Ioss::Region &inputRegion; + const std::string elemFieldName; + Ioss::FileControlOption fileControlOption; + }; - Ioss::FileControlOption get_control_option() const override + struct OutputParams { - return fileControlOption; - } + OutputParams(const std::string &outFile_) : outFile(outFile_) {} -private: - Observer(); + OutputParams(const std::string &outFile_, const std::string &elemFieldName_) + : outFile(outFile_), elemFieldName(elemFieldName_) + { + } - Ioss::Region& inputRegion; - const std::string elemFieldName; - Ioss::FileControlOption fileControlOption; -}; + void set_data(const std::vector &output_times_, const std::vector &output_steps_, + const std::vector &modification_steps_) + { + ASSERT_EQ(output_times_.size(), output_steps_.size()); + ASSERT_EQ(output_times_.size(), modification_steps_.size()); -struct OutputParams { - OutputParams(const std::string& outFile_) - : outFile(outFile_) {} + size_t numSteps = output_times_.size(); + for (auto i = 1; i < numSteps; i++) { + // Monotone increasing + ASSERT_TRUE(output_times_[i] > output_times_[i - 1]); + } - OutputParams(const std::string& outFile_, const std::string& elemFieldName_) - : outFile(outFile_) - , elemFieldName(elemFieldName_) {} + output_times = output_times_; + output_steps = output_steps_; + modification_steps = modification_steps_; + } - void set_data(const std::vector& output_times_, - const std::vector& output_steps_, - const std::vector& modification_steps_) - { - ASSERT_EQ(output_times_.size(), output_steps_.size()); - ASSERT_EQ(output_times_.size(), modification_steps_.size()); + void set_data(const std::vector &output_steps_, + const std::vector &modification_steps_) + { + ASSERT_EQ(output_steps_.size(), modification_steps_.size()); - size_t numSteps = output_times_.size(); - for(auto i=1; i output_times_[i-1]); + size_t numSteps = output_steps_.size(); + for (size_t i = 0; i < numSteps; i++) { + output_times.push_back((double)i); + } + output_steps = output_steps_; + modification_steps = modification_steps_; } - output_times = output_times_; - output_steps = output_steps_; - modification_steps = modification_steps_; - } + struct OutputParams &add(const double time, const bool do_output, const bool do_modification) + { + size_t numSteps = output_times.size(); + if (numSteps > 0) { + // Monotone increasing + EXPECT_TRUE(time > output_times[numSteps - 1]); + } - void set_data(const std::vector& output_steps_, - const std::vector& modification_steps_) - { - ASSERT_EQ(output_steps_.size(), modification_steps_.size()); + output_times.push_back(time); + output_steps.push_back(do_output); + modification_steps.push_back(do_modification); - size_t numSteps = output_steps_.size(); - for(size_t i=0; i 0) { - // Monotone increasing - EXPECT_TRUE(time > output_times[numSteps-1]); + void clear() + { + output_times.clear(); + output_steps.clear(); + modification_steps.clear(); } - output_times.push_back(time); - output_steps.push_back(do_output); - modification_steps.push_back(do_modification); - - return *this; - } + std::string outFile{"file.g"}; + std::string elemFieldName{"elem_field"}; + std::vector output_times; + std::vector output_steps; + std::vector modification_steps; + }; - void clear() + void do_output(Ioss::Region &o_region, const OutputParams ¶ms, size_t step, double &minTime, + int &maxStep, bool &doneOutputAfterModification) { - output_times.clear(); - output_steps.clear(); - modification_steps.clear(); - } - - std::string outFile{"file.g"}; - std::string elemFieldName{"elem_field"}; - std::vector output_times; - std::vector output_steps; - std::vector modification_steps; -}; - -void do_output(Ioss::Region &o_region, - const OutputParams& params, - size_t step, - double& minTime, - int& maxStep, - bool& doneOutputAfterModification) -{ - if(params.output_steps[step]) { - if(!doneOutputAfterModification) { - minTime = params.output_times[step]; - } + if (params.output_steps[step]) { + if (!doneOutputAfterModification) { + minTime = params.output_times[step]; + } - write_transient(o_region, params.elemFieldName, params.output_times[step]); + write_transient(o_region, params.elemFieldName, params.output_times[step]); - auto min_result = o_region.get_min_time(); - EXPECT_EQ(1, min_result.first); - EXPECT_NEAR(minTime, min_result.second, 1.0e-6); + auto min_result = o_region.get_min_time(); + EXPECT_EQ(1, min_result.first); + EXPECT_NEAR(minTime, min_result.second, 1.0e-6); - auto max_result = o_region.get_max_time(); - EXPECT_EQ(maxStep, max_result.first); - EXPECT_NEAR(params.output_times[step], max_result.second, 1.0e-6); + auto max_result = o_region.get_max_time(); + EXPECT_EQ(maxStep, max_result.first); + EXPECT_NEAR(params.output_times[step], max_result.second, 1.0e-6); - maxStep++; - doneOutputAfterModification = true; + maxStep++; + doneOutputAfterModification = true; + } } -} -void run_topology_change(const Ioss::Region& i_region, - Ioss::Region &o_region, - const OutputParams& params) -{ - auto observer = o_region.get_mesh_modification_observer(); + void run_topology_change(const Ioss::Region &i_region, Ioss::Region &o_region, + const OutputParams ¶ms) + { + auto observer = o_region.get_mesh_modification_observer(); - define_model(i_region, o_region); - write_model(i_region, o_region); + define_model(i_region, o_region); + write_model(i_region, o_region); - define_transient(i_region, o_region, params.elemFieldName); + define_transient(i_region, o_region, params.elemFieldName); - auto numSteps = params.output_steps.size(); + auto numSteps = params.output_steps.size(); - int maxStep = 1; + int maxStep = 1; - double minTime = numSteps > 0 ? params.output_times[0] : 0.0; - double maxTime = numSteps > 0 ? params.output_times[0] : 0.0; + double minTime = numSteps > 0 ? params.output_times[0] : 0.0; + double maxTime = numSteps > 0 ? params.output_times[0] : 0.0; - bool doneOutputAfterModification = true; + bool doneOutputAfterModification = true; - for(size_t i=0; iset_topology_modification(Ioss::TOPOLOGY_UNKNOWN); - maxStep = 1; - doneOutputAfterModification = false; - } + for (size_t i = 0; i < numSteps; i++) { + if (params.modification_steps[i]) { + observer->set_topology_modification(Ioss::TOPOLOGY_UNKNOWN); + maxStep = 1; + doneOutputAfterModification = false; + } - do_output(o_region, params, i, minTime, maxStep, doneOutputAfterModification); + do_output(o_region, params, i, minTime, maxStep, doneOutputAfterModification); + } } -} -void cleanup_simple_multi_files(const std::string &outFile) -{ - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + void cleanup_simple_multi_files(const std::string &outFile) + { + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - std::string file1 = Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); - unlink(file1.c_str()); + std::string file1 = + Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); + unlink(file1.c_str()); - std::string file2 = Ioss::Utils::decode_filename(outFile + "-s0002", util.parallel_rank(), util.parallel_size()); - unlink(file2.c_str()); + std::string file2 = Ioss::Utils::decode_filename(outFile + "-s0002", util.parallel_rank(), + util.parallel_size()); + unlink(file2.c_str()); - std::string file3 = Ioss::Utils::decode_filename(outFile + "-s0003", util.parallel_rank(), util.parallel_size()); - unlink(file3.c_str()); + std::string file3 = Ioss::Utils::decode_filename(outFile + "-s0003", util.parallel_rank(), + util.parallel_size()); + unlink(file3.c_str()); - std::string file4 = Ioss::Utils::decode_filename(outFile + "-s0004", util.parallel_rank(), util.parallel_size()); - unlink(file4.c_str()); -} + std::string file4 = Ioss::Utils::decode_filename(outFile + "-s0004", util.parallel_rank(), + util.parallel_size()); + unlink(file4.c_str()); + } -void run_multi_file_simple_topology_change(const OutputParams& params) -{ - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + void run_multi_file_simple_topology_change(const OutputParams ¶ms) + { + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - int numBlocks = util.parallel_size(); + int numBlocks = util.parallel_size(); - std::string meshDesc = get_many_block_mesh_desc(numBlocks); + std::string meshDesc = get_many_block_mesh_desc(numBlocks); - Ioss::PropertyManager propertyManager; + Ioss::PropertyManager propertyManager; - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", params.outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", params.outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); - auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_MULTI_FILE; - auto observer = std::make_shared(i_region, params.elemFieldName, fileControlOption); - o_region.register_mesh_modification_observer(observer); + auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_MULTI_FILE; + auto observer = std::make_shared(i_region, params.elemFieldName, fileControlOption); + o_region.register_mesh_modification_observer(observer); - run_topology_change(i_region, o_region, params); -} + run_topology_change(i_region, o_region, params); + } -TEST(TestDynamicWrite, multi_file_simple_topology_modification) -{ - std::string outFile("multiFileManyBlocks.g"); - std::string elemFieldName = "elem_field"; + TEST(TestDynamicWrite, multi_file_simple_topology_modification) + { + std::string outFile("multiFileManyBlocks.g"); + std::string elemFieldName = "elem_field"; - OutputParams params(outFile, elemFieldName); + OutputParams params(outFile, elemFieldName); - std::vector output_steps{true , true, true, true, true, true}; - std::vector modification_steps{false, true, false, true, true, false}; + std::vector output_steps{true, true, true, true, true, true}; + std::vector modification_steps{false, true, false, true, true, false}; - params.set_data(output_steps, modification_steps); + params.set_data(output_steps, modification_steps); - cleanup_simple_multi_files(outFile); - run_multi_file_simple_topology_change(params); - cleanup_simple_multi_files(outFile); -} + cleanup_simple_multi_files(outFile); + run_multi_file_simple_topology_change(params); + cleanup_simple_multi_files(outFile); + } -void cleanup_cyclic_multi_files(const std::string &outFile) -{ - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + void cleanup_cyclic_multi_files(const std::string &outFile) + { + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - std::string file1 = Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); - unlink(file1.c_str()); + std::string file1 = + Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); + unlink(file1.c_str()); - std::string file2 = Ioss::Utils::decode_filename(outFile + "-A", util.parallel_rank(), util.parallel_size()); - unlink(file2.c_str()); + std::string file2 = + Ioss::Utils::decode_filename(outFile + "-A", util.parallel_rank(), util.parallel_size()); + unlink(file2.c_str()); - std::string file3 = Ioss::Utils::decode_filename(outFile + "-B", util.parallel_rank(), util.parallel_size()); - unlink(file3.c_str()); + std::string file3 = + Ioss::Utils::decode_filename(outFile + "-B", util.parallel_rank(), util.parallel_size()); + unlink(file3.c_str()); - std::string file4 = Ioss::Utils::decode_filename(outFile + "-C", util.parallel_rank(), util.parallel_size()); - unlink(file4.c_str()); -} + std::string file4 = + Ioss::Utils::decode_filename(outFile + "-C", util.parallel_rank(), util.parallel_size()); + unlink(file4.c_str()); + } -void run_multi_file_cyclic_topology_change(const OutputParams& params) -{ - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + void run_multi_file_cyclic_topology_change(const OutputParams ¶ms) + { + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - int numBlocks = util.parallel_size(); + int numBlocks = util.parallel_size(); - std::string meshDesc = get_many_block_mesh_desc(numBlocks); + std::string meshDesc = get_many_block_mesh_desc(numBlocks); - Ioss::PropertyManager propertyManager; + Ioss::PropertyManager propertyManager; - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", params.outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", params.outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); - auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_MULTI_FILE; - auto observer = std::make_shared(i_region, params.elemFieldName, fileControlOption); - o_region.register_mesh_modification_observer(observer); + auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_MULTI_FILE; + auto observer = std::make_shared(i_region, params.elemFieldName, fileControlOption); + o_region.register_mesh_modification_observer(observer); - o_region.set_file_cyclic_count(3); - run_topology_change(i_region, o_region, params); -} + o_region.set_file_cyclic_count(3); + run_topology_change(i_region, o_region, params); + } -TEST(TestDynamicWrite, multi_file_cyclic_topology_modification) -{ - std::string outFile("cyclicMultiFileManyBlocks.g"); - std::string elemFieldName = "elem_field"; + TEST(TestDynamicWrite, multi_file_cyclic_topology_modification) + { + std::string outFile("cyclicMultiFileManyBlocks.g"); + std::string elemFieldName = "elem_field"; - OutputParams params(outFile, elemFieldName); + OutputParams params(outFile, elemFieldName); - std::vector output_times{0.0 , 0.5 , 1.5 , 1.75, 2.0 , 3.0}; - std::vector output_steps{true , true, true , true, true, true }; - std::vector modification_steps{false, true, false, true, true, false}; + std::vector output_times{0.0, 0.5, 1.5, 1.75, 2.0, 3.0}; + std::vector output_steps{true, true, true, true, true, true}; + std::vector modification_steps{false, true, false, true, true, false}; - params.set_data(output_times, output_steps, modification_steps); + params.set_data(output_times, output_steps, modification_steps); - cleanup_cyclic_multi_files(outFile); - run_multi_file_cyclic_topology_change(params); - cleanup_cyclic_multi_files(outFile); -} + cleanup_cyclic_multi_files(outFile); + run_multi_file_cyclic_topology_change(params); + cleanup_cyclic_multi_files(outFile); + } -void fill_group_gold_names(const int numFileGroups, - std::vector& gold_names, - std::vector& gold_full_names) -{ - gold_names.clear(); - gold_full_names.clear(); + void fill_group_gold_names(const int numFileGroups, std::vector &gold_names, + std::vector &gold_full_names) + { + gold_names.clear(); + gold_full_names.clear(); - gold_names.push_back("/"); - gold_full_names.push_back("/"); + gold_names.push_back("/"); + gold_full_names.push_back("/"); - for(int i=1; i<=numFileGroups; i++) { - std::ostringstream oss; - oss << Ioss::DynamicTopologyFileControl::group_prefix(); - oss << i; + for (int i = 1; i <= numFileGroups; i++) { + std::ostringstream oss; + oss << Ioss::DynamicTopologyFileControl::group_prefix(); + oss << i; - gold_names.push_back(oss.str()); - gold_full_names.push_back("/" + oss.str()); + gold_names.push_back(oss.str()); + gold_full_names.push_back("/" + oss.str()); + } } -} -void test_group_names(Ioss::DatabaseIO *database) -{ - Ioss::NameList names = database->groups_describe(false); - Ioss::NameList full_names = database->groups_describe(true); + void test_group_names(Ioss::DatabaseIO *database) + { + Ioss::NameList names = database->groups_describe(false); + Ioss::NameList full_names = database->groups_describe(true); - std::vector gold_names; - std::vector gold_full_names; + std::vector gold_names; + std::vector gold_full_names; - fill_group_gold_names(database->num_child_group(), gold_names, gold_full_names); + fill_group_gold_names(database->num_child_group(), gold_names, gold_full_names); - EXPECT_EQ(gold_names, names); - EXPECT_EQ(gold_full_names, full_names); -} + EXPECT_EQ(gold_names, names); + EXPECT_EQ(gold_full_names, full_names); + } -void cleanup_single_file(const std::string &outFile) -{ - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + void cleanup_single_file(const std::string &outFile) + { + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - std::string file1 = Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); - unlink(file1.c_str()); -} + std::string file1 = + Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); + unlink(file1.c_str()); + } -void run_single_file_simple_topology_change(const OutputParams& params) -{ - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + void run_single_file_simple_topology_change(const OutputParams ¶ms) + { + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - int numBlocks = util.parallel_size(); + int numBlocks = util.parallel_size(); - std::string meshDesc = get_many_block_mesh_desc(numBlocks); + std::string meshDesc = get_many_block_mesh_desc(numBlocks); - Ioss::PropertyManager propertyManager; + Ioss::PropertyManager propertyManager; - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); - propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", params.outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); + propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); + propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", params.outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); - auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_GROUP_FILE; - auto observer = std::make_shared(i_region, params.elemFieldName, fileControlOption); - o_region.register_mesh_modification_observer(observer); + auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_GROUP_FILE; + auto observer = std::make_shared(i_region, params.elemFieldName, fileControlOption); + o_region.register_mesh_modification_observer(observer); - run_topology_change(i_region, o_region, params); - test_group_names(o_database); -} + run_topology_change(i_region, o_region, params); + test_group_names(o_database); + } -TEST(TestDynamicWrite, single_file_simple_topology_modification) -{ - std::string outFile("singleFileManyBlocks.g"); - std::string elemFieldName = "elem_field"; + TEST(TestDynamicWrite, single_file_simple_topology_modification) + { + std::string outFile("singleFileManyBlocks.g"); + std::string elemFieldName = "elem_field"; - OutputParams params(outFile, elemFieldName); + OutputParams params(outFile, elemFieldName); - params.add(0.0, true, false) + params.add(0.0, true, false) .add(1.0, true, true) .add(2.0, true, false) .add(3.0, true, true) .add(4.0, true, true) .add(5.0, true, false); - cleanup_single_file(outFile); - run_single_file_simple_topology_change(params); - cleanup_single_file(outFile); -} - -TEST(TestDynamicWrite, single_file_groups_not_enabled) -{ - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - - int numBlocks = util.parallel_size(); - if(numBlocks > 1) GTEST_SKIP(); - - std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" - "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; - - Ioss::PropertyManager propertyManager; - - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); - - std::string outFile("singleFileGroupsNotEnabled.g"); - std::string elemFieldName = "elem_field"; - cleanup_single_file(outFile); - - // Need the line below to allow this to pass - // propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); - propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); - - auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_GROUP_FILE; - auto observer = std::make_shared(i_region, elemFieldName, fileControlOption); - EXPECT_THROW(o_region.register_mesh_modification_observer(observer), std::runtime_error); - cleanup_single_file(outFile); -} - -TEST(TestDynamicWrite, create_subgroup_with_file_reopen) -{ - std::string outFile("subgroupManyBlocks.g"); - std::string elemFieldName = "elem_field"; - - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - - std::string file1 = Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); - unlink(file1.c_str()); - - int numBlocks = util.parallel_size(); - if(numBlocks > 1) GTEST_SKIP(); - - std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" - "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; - - Ioss::PropertyManager propertyManager; - - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + cleanup_single_file(outFile); + run_single_file_simple_topology_change(params); + cleanup_single_file(outFile); + } + TEST(TestDynamicWrite, single_file_groups_not_enabled) { - propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + + int numBlocks = util.parallel_size(); + if (numBlocks > 1) + GTEST_SKIP(); + + std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" + "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; + + Ioss::PropertyManager propertyManager; + + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); + + std::string outFile("singleFileGroupsNotEnabled.g"); + std::string elemFieldName = "elem_field"; + cleanup_single_file(outFile); + + // Need the line below to allow this to pass + // propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); + propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); + Ioss::DatabaseIO *o_database = Ioss::IOFactory::create( + "exodus", outFile, Ioss::WRITE_RESULTS, Ioss::ParallelUtils::comm_world(), propertyManager); Ioss::Region o_region(o_database, "output_model"); EXPECT_TRUE(o_database != nullptr); EXPECT_TRUE(o_database->ok(true)); - o_database->create_subgroup("GROUP_1"); + + auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_GROUP_FILE; + auto observer = std::make_shared(i_region, elemFieldName, fileControlOption); + EXPECT_THROW(o_region.register_mesh_modification_observer(observer), std::runtime_error); + cleanup_single_file(outFile); } + TEST(TestDynamicWrite, create_subgroup_with_file_reopen) { - propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); + std::string outFile("subgroupManyBlocks.g"); + std::string elemFieldName = "elem_field"; + + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + + std::string file1 = + Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); + unlink(file1.c_str()); + + int numBlocks = util.parallel_size(); + if (numBlocks > 1) + GTEST_SKIP(); + + std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" + "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; + + Ioss::PropertyManager propertyManager; + + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); + + { + propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); + o_database->create_subgroup("GROUP_1"); + } - // Group pointer is automatically at first child - o_database->create_subgroup("GROUP_2"); + { + propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); - Ioss::NameList names = o_database->groups_describe(false); - Ioss::NameList full_names = o_database->groups_describe(true); + // Group pointer is automatically at first child + o_database->create_subgroup("GROUP_2"); - std::vector gold_names{"/", "GROUP_1", "GROUP_2"}; - std::vector gold_full_names{"/", "/GROUP_1", "/GROUP_1/GROUP_2"}; + Ioss::NameList names = o_database->groups_describe(false); + Ioss::NameList full_names = o_database->groups_describe(true); - EXPECT_EQ(gold_names, names); - EXPECT_EQ(gold_full_names, full_names); + std::vector gold_names{"/", "GROUP_1", "GROUP_2"}; + std::vector gold_full_names{"/", "/GROUP_1", "/GROUP_1/GROUP_2"}; + + EXPECT_EQ(gold_names, names); + EXPECT_EQ(gold_full_names, full_names); + } + + unlink(file1.c_str()); } - unlink(file1.c_str()); -} + TEST(TestDynamicWrite, create_subgroup_with_file_persistence_and_child_group) + { + std::string outFile("subgroupManyBlocks.g"); + std::string elemFieldName = "elem_field"; -TEST(TestDynamicWrite, create_subgroup_with_file_persistence_and_child_group) -{ - std::string outFile("subgroupManyBlocks.g"); - std::string elemFieldName = "elem_field"; + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + std::string file1 = + Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); + unlink(file1.c_str()); - std::string file1 = Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); - unlink(file1.c_str()); + int numBlocks = util.parallel_size(); + if (numBlocks > 1) + GTEST_SKIP(); - int numBlocks = util.parallel_size(); - if(numBlocks > 1) GTEST_SKIP(); + std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" + "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; - std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" - "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; + Ioss::PropertyManager propertyManager; - Ioss::PropertyManager propertyManager; + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + { + propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); + propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); - { - propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); - propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); + o_database->create_subgroup("GROUP_1"); - o_database->create_subgroup("GROUP_1"); + // Group pointer is at "GROUP_1" ... "GROUP_2" is a child + o_database->create_subgroup("GROUP_2"); - // Group pointer is at "GROUP_1" ... "GROUP_2" is a child - o_database->create_subgroup("GROUP_2"); + Ioss::NameList names = o_database->groups_describe(false); + Ioss::NameList full_names = o_database->groups_describe(true); - Ioss::NameList names = o_database->groups_describe(false); - Ioss::NameList full_names = o_database->groups_describe(true); + std::vector gold_names{"/", "GROUP_1", "GROUP_2"}; + std::vector gold_full_names{"/", "/GROUP_1", "/GROUP_1/GROUP_2"}; - std::vector gold_names{"/", "GROUP_1", "GROUP_2"}; - std::vector gold_full_names{"/", "/GROUP_1", "/GROUP_1/GROUP_2"}; + EXPECT_EQ(gold_names, names); + EXPECT_EQ(gold_full_names, full_names); + } - EXPECT_EQ(gold_names, names); - EXPECT_EQ(gold_full_names, full_names); + unlink(file1.c_str()); } - unlink(file1.c_str()); -} + TEST(TestDynamicWrite, create_subgroup_with_file_persistence_and_no_child_group) + { + std::string outFile("subgroupManyBlocks.g"); + std::string elemFieldName = "elem_field"; -TEST(TestDynamicWrite, create_subgroup_with_file_persistence_and_no_child_group) -{ - std::string outFile("subgroupManyBlocks.g"); - std::string elemFieldName = "elem_field"; + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); + std::string file1 = + Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); + unlink(file1.c_str()); - std::string file1 = Ioss::Utils::decode_filename(outFile, util.parallel_rank(), util.parallel_size()); - unlink(file1.c_str()); + int numBlocks = util.parallel_size(); + if (numBlocks > 1) + GTEST_SKIP(); - int numBlocks = util.parallel_size(); - if(numBlocks > 1) GTEST_SKIP(); + std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" + "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; - std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1" - "|coordinates:0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,1,1,1,1,0,1,1"; + Ioss::PropertyManager propertyManager; - Ioss::PropertyManager propertyManager; + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + { + propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); + propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); + Ioss::DatabaseIO *o_database = + Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region(o_database, "output_model"); + EXPECT_TRUE(o_database != nullptr); + EXPECT_TRUE(o_database->ok(true)); - { - propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); - propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - Ioss::DatabaseIO *o_database = Ioss::IOFactory::create("exodus", outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region(o_database, "output_model"); - EXPECT_TRUE(o_database != nullptr); - EXPECT_TRUE(o_database->ok(true)); + o_database->create_subgroup("GROUP_1"); - o_database->create_subgroup("GROUP_1"); + // Group pointer is reset to root group + EXPECT_TRUE(o_database->open_root_group()); + o_database->create_subgroup("GROUP_2"); - // Group pointer is reset to root group - EXPECT_TRUE(o_database->open_root_group()); - o_database->create_subgroup("GROUP_2"); + Ioss::NameList names = o_database->groups_describe(false); + Ioss::NameList full_names = o_database->groups_describe(true); - Ioss::NameList names = o_database->groups_describe(false); - Ioss::NameList full_names = o_database->groups_describe(true); + std::vector gold_names{"/", "GROUP_1", "GROUP_2"}; + std::vector gold_full_names{"/", "/GROUP_1", "/GROUP_2"}; - std::vector gold_names{"/", "GROUP_1", "GROUP_2"}; - std::vector gold_full_names{"/", "/GROUP_1", "/GROUP_2"}; + EXPECT_EQ(gold_names, names); + EXPECT_EQ(gold_full_names, full_names); + } - EXPECT_EQ(gold_names, names); - EXPECT_EQ(gold_full_names, full_names); + unlink(file1.c_str()); } - unlink(file1.c_str()); -} - + void run_topology_change_with_multiple_output(const Ioss::Region &i_region, + Ioss::Region &o_region1, Ioss::Region &o_region2, + const OutputParams ¶ms1, + const OutputParams ¶ms2) + { + ASSERT_EQ(params1.modification_steps, params2.modification_steps); -void run_topology_change_with_multiple_output(const Ioss::Region& i_region, - Ioss::Region &o_region1, - Ioss::Region &o_region2, - const OutputParams& params1, - const OutputParams& params2) -{ - ASSERT_EQ(params1.modification_steps, params2.modification_steps); + auto observer1 = o_region1.get_mesh_modification_observer(); + auto observer2 = o_region2.get_mesh_modification_observer(); - auto observer1 = o_region1.get_mesh_modification_observer(); - auto observer2 = o_region2.get_mesh_modification_observer(); + define_model(i_region, o_region1); + write_model(i_region, o_region1); + define_transient(i_region, o_region1, params1.elemFieldName); - define_model(i_region, o_region1); - write_model(i_region, o_region1); - define_transient(i_region, o_region1, params1.elemFieldName); + define_model(i_region, o_region2); + write_model(i_region, o_region2); + define_transient(i_region, o_region2, params2.elemFieldName); - define_model(i_region, o_region2); - write_model(i_region, o_region2); - define_transient(i_region, o_region2, params2.elemFieldName); + auto numSteps = params1.output_steps.size(); - auto numSteps = params1.output_steps.size(); + int maxStep1 = 1; + int maxStep2 = 1; - int maxStep1 = 1; - int maxStep2 = 1; + double minTime1 = numSteps > 0 ? params1.output_times[0] : 0.0; + double minTime2 = numSteps > 0 ? params2.output_times[0] : 0.0; - double minTime1 = numSteps > 0 ? params1.output_times[0] : 0.0; - double minTime2 = numSteps > 0 ? params2.output_times[0] : 0.0; + bool doneOutputAfterModification1 = true; + bool doneOutputAfterModification2 = true; - bool doneOutputAfterModification1 = true; - bool doneOutputAfterModification2 = true; + for (size_t i = 0; i < numSteps; i++) { + if (params1.modification_steps[i]) { + EXPECT_TRUE(params2.modification_steps[i]); - for(size_t i=0; iset_topology_modification(Ioss::TOPOLOGY_UNKNOWN); + maxStep1 = 1; + maxStep2 = 1; - observer1->set_topology_modification(Ioss::TOPOLOGY_UNKNOWN); - maxStep1 = 1; - maxStep2 = 1; + EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer1->get_topology_modification()); + EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer2->get_topology_modification()); - EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer1->get_topology_modification()); - EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer2->get_topology_modification()); + doneOutputAfterModification1 = false; + doneOutputAfterModification2 = false; + } - doneOutputAfterModification1 = false; - doneOutputAfterModification2 = false; + do_output(o_region1, params1, i, minTime1, maxStep1, doneOutputAfterModification1); + do_output(o_region2, params2, i, minTime2, maxStep2, doneOutputAfterModification2); } - - do_output(o_region1, params1, i, minTime1, maxStep1, doneOutputAfterModification1); - do_output(o_region2, params2, i, minTime2, maxStep2, doneOutputAfterModification2); } -} - -void run_single_file_simple_topology_change_with_multiple_output(const std::string& model, - const OutputParams& params1, - const OutputParams& params2) -{ - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - - auto broker = Ioss::DynamicTopologyBroker::broker(); - broker->register_model(model); - - int numBlocks = util.parallel_size(); - std::string meshDesc = get_many_block_mesh_desc(numBlocks); - - Ioss::PropertyManager propertyManager; - - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); - - propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); - propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - - Ioss::DatabaseIO *o_database1 = Ioss::IOFactory::create("exodus", params1.outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region1(o_database1, "region1"); - EXPECT_TRUE(o_database1 != nullptr); - EXPECT_TRUE(o_database1->ok(true)); - - auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_GROUP_FILE; - auto observer1 = std::make_shared(i_region, params1.elemFieldName, fileControlOption); - broker->register_observer(model, observer1, o_region1); - - Ioss::DatabaseIO *o_database2 = Ioss::IOFactory::create("exodus", params2.outFile, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region o_region2(o_database2, "region2"); - EXPECT_TRUE(o_database2 != nullptr); - EXPECT_TRUE(o_database2->ok(true)); - - auto observer2 = std::make_shared(i_region, params2.elemFieldName, fileControlOption); - broker->register_observer(model, observer2, o_region2); - - run_topology_change_with_multiple_output(i_region, o_region1, o_region2, params1, params2); - - test_group_names(o_database1); - test_group_names(o_database2); -} - -TEST(TestDynamicWrite, single_file_simple_topology_modification_with_multiple_output) -{ - std::string outFile1("singleFileManyBlocks1.g"); - std::string outFile2("singleFileManyBlocks2.g"); - std::string elemFieldName = "elem_field"; - std::string model = "multiple-output"; - - OutputParams params1(outFile1, elemFieldName); - - params1.add(0.0, true , false) - .add(1.0, true , true) - .add(2.0, false, false) - .add(3.0, true , true) - .add(4.0, true , false) - .add(5.0, true , true); - - OutputParams params2(outFile2, elemFieldName); - - params2.add(0.0, true , false) - .add(1.0, true , true) - .add(2.0, true , false) - .add(3.0, false, true) - .add(4.0, true , false) - .add(5.0, true , true); - - cleanup_single_file(outFile1); - cleanup_single_file(outFile2); - run_single_file_simple_topology_change_with_multiple_output(model, params1, params2); - cleanup_single_file(outFile1); - cleanup_single_file(outFile2); -} - -TEST(TestDynamicWrite, same_model_triggers_same_modification_for_all_observers) -{ - Ioss::Init::Initializer io; - Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - - std::string outFile1("sameModelManyBlocks1.g"); - std::string outFile2("sameModelManyBlocks2.g"); - std::string elemFieldName("elem_field"); - std::string model("same-model"); - - auto broker = Ioss::DynamicTopologyBroker::broker(); - broker->register_model(model); - - std::string file1 = Ioss::Utils::decode_filename(outFile1, util.parallel_rank(), util.parallel_size()); - std::string file2 = Ioss::Utils::decode_filename(outFile2, util.parallel_rank(), util.parallel_size()); - - unlink(file1.c_str()); - unlink(file2.c_str()); + void run_single_file_simple_topology_change_with_multiple_output(const std::string &model, + const OutputParams ¶ms1, + const OutputParams ¶ms2) + { + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - int numBlocks = util.parallel_size(); - if(numBlocks > 1) GTEST_SKIP(); + auto broker = Ioss::DynamicTopologyBroker::broker(); + broker->register_model(model); - std::string meshDesc = get_many_block_mesh_desc(numBlocks); + int numBlocks = util.parallel_size(); - Ioss::PropertyManager propertyManager; - - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("textmesh", meshDesc, Ioss::READ_MODEL, - Ioss::ParallelUtils::comm_world(), - propertyManager); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + std::string meshDesc = get_many_block_mesh_desc(numBlocks); + + Ioss::PropertyManager propertyManager; + + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - { propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - Ioss::DatabaseIO *o_database1 = Ioss::IOFactory::create("exodus", outFile1, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); + Ioss::DatabaseIO *o_database1 = + Ioss::IOFactory::create("exodus", params1.outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); Ioss::Region o_region1(o_database1, "region1"); EXPECT_TRUE(o_database1 != nullptr); EXPECT_TRUE(o_database1->ok(true)); auto fileControlOption = Ioss::FileControlOption::CONTROL_AUTO_GROUP_FILE; - auto observer1 = std::make_shared(i_region, elemFieldName, fileControlOption); + auto observer1 = std::make_shared(i_region, params1.elemFieldName, fileControlOption); broker->register_observer(model, observer1, o_region1); - Ioss::DatabaseIO *o_database2 = Ioss::IOFactory::create("exodus", outFile2, Ioss::WRITE_RESULTS, - Ioss::ParallelUtils::comm_world(), - propertyManager); + Ioss::DatabaseIO *o_database2 = + Ioss::IOFactory::create("exodus", params2.outFile, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); Ioss::Region o_region2(o_database2, "region2"); EXPECT_TRUE(o_database2 != nullptr); EXPECT_TRUE(o_database2->ok(true)); - auto observer2 = std::make_shared(i_region, elemFieldName, fileControlOption); + auto observer2 = std::make_shared(i_region, params2.elemFieldName, fileControlOption); broker->register_observer(model, observer2, o_region2); - EXPECT_EQ(Ioss::TOPOLOGY_SAME, observer1->get_topology_modification()); - EXPECT_EQ(Ioss::TOPOLOGY_SAME, observer2->get_topology_modification()); - - observer1->set_topology_modification(Ioss::TOPOLOGY_UNKNOWN); + run_topology_change_with_multiple_output(i_region, o_region1, o_region2, params1, params2); - EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer1->get_topology_modification()); - EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer2->get_topology_modification()); + test_group_names(o_database1); + test_group_names(o_database2); } - unlink(file1.c_str()); - unlink(file2.c_str()); -} + TEST(TestDynamicWrite, single_file_simple_topology_modification_with_multiple_output) + { + std::string outFile1("singleFileManyBlocks1.g"); + std::string outFile2("singleFileManyBlocks2.g"); + std::string elemFieldName = "elem_field"; + std::string model = "multiple-output"; -void test_single_file_simple_topology_change_data(Ioss::Region& i_region, const std::string& elemFieldName, - int gold_step, double gold_time) -{ - i_region.begin_state(gold_step); - for (Ioss::ElementBlock *i_eb : i_region.get_element_blocks()) { - size_t num_elem = i_eb->get_property("entity_count").get_int(); + OutputParams params1(outFile1, elemFieldName); - std::vector field_data(num_elem); - std::vector elem_ids; + params1.add(0.0, true, false) + .add(1.0, true, true) + .add(2.0, false, false) + .add(3.0, true, true) + .add(4.0, true, false) + .add(5.0, true, true); - i_eb->get_field_data(elemFieldName, field_data); - i_eb->get_field_data("ids", elem_ids); + OutputParams params2(outFile2, elemFieldName); - for (size_t i = 0; i < elem_ids.size(); i++) { - double gold_value = (double)elem_ids[i] + 100*gold_time; - EXPECT_NEAR(gold_value, field_data[i], 1.0e-6); - } + params2.add(0.0, true, false) + .add(1.0, true, true) + .add(2.0, true, false) + .add(3.0, false, true) + .add(4.0, true, false) + .add(5.0, true, true); + + cleanup_single_file(outFile1); + cleanup_single_file(outFile2); + run_single_file_simple_topology_change_with_multiple_output(model, params1, params2); + cleanup_single_file(outFile1); + cleanup_single_file(outFile2); } -} -void read_and_test_single_file_simple_topology_change(const OutputParams& params) -{ - Ioss::PropertyManager propertyManager; + TEST(TestDynamicWrite, same_model_triggers_same_modification_for_all_observers) + { + Ioss::Init::Initializer io; + Ioss::ParallelUtils util(Ioss::ParallelUtils::comm_world()); - Ioss::DatabaseIO *i_database = Ioss::IOFactory::create("exodus", params.outFile, Ioss::READ_RESTART, - Ioss::ParallelUtils::comm_world(), - propertyManager); + std::string outFile1("sameModelManyBlocks1.g"); + std::string outFile2("sameModelManyBlocks2.g"); + std::string elemFieldName("elem_field"); + std::string model("same-model"); - test_group_names(i_database); + auto broker = Ioss::DynamicTopologyBroker::broker(); + broker->register_model(model); - Ioss::Region i_region(i_database, "input_model"); - EXPECT_TRUE(i_database != nullptr); - EXPECT_TRUE(i_database->ok(true)); + std::string file1 = + Ioss::Utils::decode_filename(outFile1, util.parallel_rank(), util.parallel_size()); + std::string file2 = + Ioss::Utils::decode_filename(outFile2, util.parallel_rank(), util.parallel_size()); - auto numSteps = params.output_steps.size(); + unlink(file1.c_str()); + unlink(file2.c_str()); - int numMods = 0; + int numBlocks = util.parallel_size(); + if (numBlocks > 1) + GTEST_SKIP(); - int maxStep = 1; + std::string meshDesc = get_many_block_mesh_desc(numBlocks); - double minTime = numSteps > 0 ? params.output_times[0] : 0.0; - double maxTime = numSteps > 0 ? params.output_times[0] : 0.0; + Ioss::PropertyManager propertyManager; - bool doneOutputAfterModification = true; + Ioss::DatabaseIO *i_database = Ioss::IOFactory::create( + "textmesh", meshDesc, Ioss::READ_MODEL, Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); - Ioss::NameList names = i_database->groups_describe(false); + { + propertyManager.add(Ioss::Property("ENABLE_FILE_GROUPS", 1)); + propertyManager.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP)); - for(size_t i=0; iok(true)); - for(size_t j=i+1; j(i_region, elemFieldName, fileControlOption); + broker->register_observer(model, observer1, o_region1); - maxTime = params.output_times[j]; + Ioss::DatabaseIO *o_database2 = + Ioss::IOFactory::create("exodus", outFile2, Ioss::WRITE_RESULTS, + Ioss::ParallelUtils::comm_world(), propertyManager); + Ioss::Region o_region2(o_database2, "region2"); + EXPECT_TRUE(o_database2 != nullptr); + EXPECT_TRUE(o_database2->ok(true)); + + auto observer2 = std::make_shared(i_region, elemFieldName, fileControlOption); + broker->register_observer(model, observer2, o_region2); + + EXPECT_EQ(Ioss::TOPOLOGY_SAME, observer1->get_topology_modification()); + EXPECT_EQ(Ioss::TOPOLOGY_SAME, observer2->get_topology_modification()); + + observer1->set_topology_modification(Ioss::TOPOLOGY_UNKNOWN); + + EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer1->get_topology_modification()); + EXPECT_EQ(Ioss::TOPOLOGY_UNKNOWN, observer2->get_topology_modification()); } - if(params.modification_steps[i]) { - numMods++; - maxStep = 1; + unlink(file1.c_str()); + unlink(file2.c_str()); + } + + void test_single_file_simple_topology_change_data(Ioss::Region &i_region, + const std::string &elemFieldName, int gold_step, + double gold_time) + { + i_region.begin_state(gold_step); + for (Ioss::ElementBlock *i_eb : i_region.get_element_blocks()) { + size_t num_elem = i_eb->get_property("entity_count").get_int(); + + std::vector field_data(num_elem); + std::vector elem_ids; - EXPECT_TRUE(i_region.load_group_mesh(names[numMods+1])); + i_eb->get_field_data(elemFieldName, field_data); + i_eb->get_field_data("ids", elem_ids); - doneOutputAfterModification = false; + for (size_t i = 0; i < elem_ids.size(); i++) { + double gold_value = (double)elem_ids[i] + 100 * gold_time; + EXPECT_NEAR(gold_value, field_data[i], 1.0e-6); + } } + } + + void read_and_test_single_file_simple_topology_change(const OutputParams ¶ms) + { + Ioss::PropertyManager propertyManager; + + Ioss::DatabaseIO *i_database = + Ioss::IOFactory::create("exodus", params.outFile, Ioss::READ_RESTART, + Ioss::ParallelUtils::comm_world(), propertyManager); + + test_group_names(i_database); + + Ioss::Region i_region(i_database, "input_model"); + EXPECT_TRUE(i_database != nullptr); + EXPECT_TRUE(i_database->ok(true)); + + auto numSteps = params.output_steps.size(); + + int numMods = 0; + + int maxStep = 1; + + double minTime = numSteps > 0 ? params.output_times[0] : 0.0; + double maxTime = numSteps > 0 ? params.output_times[0] : 0.0; + + bool doneOutputAfterModification = true; + + Ioss::NameList names = i_database->groups_describe(false); - if(params.output_steps[i]) { - if(!doneOutputAfterModification) { - minTime = params.output_times[i]; + for (size_t i = 0; i < numSteps; i++) { + maxTime = params.output_times[i]; + + for (size_t j = i + 1; j < numSteps; j++) { + if (params.modification_steps[j]) { + maxTime = params.output_times[j - 1]; + break; + } + + maxTime = params.output_times[j]; } - auto min_result = i_region.get_min_time(); - EXPECT_EQ(1, min_result.first); - EXPECT_NEAR(minTime, min_result.second, 1.0e-6); - test_single_file_simple_topology_change_data(i_region, params.elemFieldName, 1, minTime); - if((((i+1) < numSteps) && params.modification_steps[i+1]) || (i == (numSteps-1))) { - auto max_result = i_region.get_max_time(); - EXPECT_EQ(maxStep, max_result.first); - EXPECT_NEAR(maxTime, max_result.second, 1.0e-6); + if (params.modification_steps[i]) { + numMods++; + maxStep = 1; + + EXPECT_TRUE(i_region.load_group_mesh(names[numMods + 1])); - test_single_file_simple_topology_change_data(i_region, params.elemFieldName, maxStep, maxTime); + doneOutputAfterModification = false; } - maxStep++; - doneOutputAfterModification = true; + if (params.output_steps[i]) { + if (!doneOutputAfterModification) { + minTime = params.output_times[i]; + } + auto min_result = i_region.get_min_time(); + EXPECT_EQ(1, min_result.first); + EXPECT_NEAR(minTime, min_result.second, 1.0e-6); + test_single_file_simple_topology_change_data(i_region, params.elemFieldName, 1, minTime); + + if ((((i + 1) < numSteps) && params.modification_steps[i + 1]) || (i == (numSteps - 1))) { + auto max_result = i_region.get_max_time(); + EXPECT_EQ(maxStep, max_result.first); + EXPECT_NEAR(maxTime, max_result.second, 1.0e-6); + + test_single_file_simple_topology_change_data(i_region, params.elemFieldName, maxStep, + maxTime); + } + + maxStep++; + doneOutputAfterModification = true; + } } } -} -TEST(TestDynamicRead, single_file_simple_topology_modification) -{ - std::string outFile("singleFileManyBlocks.g"); - std::string elemFieldName = "elem_field"; + TEST(TestDynamicRead, single_file_simple_topology_modification) + { + std::string outFile("singleFileManyBlocks.g"); + std::string elemFieldName = "elem_field"; - OutputParams params(outFile, elemFieldName); + OutputParams params(outFile, elemFieldName); - params.add(0.0, true, false) + params.add(0.0, true, false) .add(1.0, true, true) .add(2.0, true, false) .add(3.0, true, true) .add(4.0, true, true) .add(5.0, true, false); - cleanup_single_file(outFile); - run_single_file_simple_topology_change(params); - read_and_test_single_file_simple_topology_change(params); - cleanup_single_file(outFile); -} - -} - + cleanup_single_file(outFile); + run_single_file_simple_topology_change(params); + read_and_test_single_file_simple_topology_change(params); + cleanup_single_file(outFile); + } +} // namespace