From a37070b8bef9c05c2ce0e2b8b65a0f8940f38f82 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:04:40 +0000 Subject: [PATCH] Committing clang-format changes --- .../ioss/src/Ioss_DynamicTopologyBroker.C | 144 ++++---- .../ioss/src/Ioss_DynamicTopologyBroker.h | 46 +-- .../src/Ioss_DynamicTopologyFileControl.C | 146 ++++---- .../src/Ioss_DynamicTopologyFileControl.h | 74 ++-- .../ioss/src/Ioss_DynamicTopologyNotifier.C | 72 ++-- .../ioss/src/Ioss_DynamicTopologyNotifier.h | 78 ++--- .../ioss/src/Ioss_DynamicTopologyObserver.C | 327 +++++++++--------- .../ioss/src/Ioss_DynamicTopologyObserver.h | 96 ++--- .../src/Ioss_DynamicTopologyStateLocator.C | 286 ++++++++------- .../src/Ioss_DynamicTopologyStateLocator.h | 94 ++--- 10 files changed, 680 insertions(+), 683 deletions(-) diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.C b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.C index a98fc9b390..a6652d4e6b 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.C +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.C @@ -7,105 +7,105 @@ #include "Ioss_DynamicTopologyBroker.h" #include "Ioss_Region.h" -#include #include +#include #include #include #include namespace Ioss { -DynamicTopologyBroker* DynamicTopologyBroker::broker() -{ - static DynamicTopologyBroker broker_; - return &broker_; -} - -void DynamicTopologyBroker::register_model(const std::string& model_name) -{ - auto iter = m_notifiers.find(model_name); - if(iter != m_notifiers.end()) { - return; + DynamicTopologyBroker *DynamicTopologyBroker::broker() + { + static DynamicTopologyBroker broker_; + return &broker_; } - m_notifiers[model_name] = std::make_shared(model_name); -} + void DynamicTopologyBroker::register_model(const std::string &model_name) + { + auto iter = m_notifiers.find(model_name); + if (iter != m_notifiers.end()) { + return; + } -std::shared_ptr -DynamicTopologyBroker::get_notifier(const std::string& model_name) const -{ - auto iter = m_notifiers.find(model_name); - if(iter != m_notifiers.end()) { - return iter->second; + m_notifiers[model_name] = std::make_shared(model_name); } - return {}; -} + std::shared_ptr + DynamicTopologyBroker::get_notifier(const std::string &model_name) const + { + auto iter = m_notifiers.find(model_name); + if (iter != m_notifiers.end()) { + return iter->second; + } -std::vector> -DynamicTopologyBroker::get_observers(const std::string& model_name) const -{ - std::vector> observers; + return {}; + } - auto notifier = get_notifier(model_name); + std::vector> + DynamicTopologyBroker::get_observers(const std::string &model_name) const + { + std::vector> observers; - if(notifier) { - return notifier->get_observers(); - } + auto notifier = get_notifier(model_name); - return observers; -} + if (notifier) { + return notifier->get_observers(); + } -void DynamicTopologyBroker::remove_model(const std::string& model_name) -{ - auto iter = m_notifiers.find(model_name); - if(iter != m_notifiers.end()) { - m_notifiers.erase(iter); + return observers; } -} -void DynamicTopologyBroker::clear_models() -{ - m_notifiers.clear(); -} + void DynamicTopologyBroker::remove_model(const std::string &model_name) + { + auto iter = m_notifiers.find(model_name); + if (iter != m_notifiers.end()) { + m_notifiers.erase(iter); + } + } -void DynamicTopologyBroker::register_observer(const std::string& model_name, - std::shared_ptr observer) -{ - auto notifier = get_notifier(model_name); + void DynamicTopologyBroker::clear_models() { m_notifiers.clear(); } - if(!notifier) { - register_model(model_name); - notifier = get_notifier(model_name); - } + void DynamicTopologyBroker::register_observer(const std::string &model_name, + std::shared_ptr observer) + { + auto notifier = get_notifier(model_name); - notifier->register_observer(observer); -} + if (!notifier) { + register_model(model_name); + notifier = get_notifier(model_name); + } -void DynamicTopologyBroker::register_observer(const std::string& model_name, - std::shared_ptr observer, - Region& region) -{ - region.register_mesh_modification_observer(observer); - register_observer(model_name, observer); -} + notifier->register_observer(observer); + } -void DynamicTopologyBroker::reset_topology_modification(const std::string& model_name) -{ - auto notifier = get_notifier(model_name); + void DynamicTopologyBroker::register_observer(const std::string &model_name, + std::shared_ptr observer, + Region ®ion) + { + region.register_mesh_modification_observer(observer); + register_observer(model_name, observer); + } - if(!notifier) return; + void DynamicTopologyBroker::reset_topology_modification(const std::string &model_name) + { + auto notifier = get_notifier(model_name); - notifier->reset_topology_modification(); -} + if (!notifier) + return; -void DynamicTopologyBroker::set_topology_modification(const std::string& model_name, unsigned int type) -{ - auto notifier = get_notifier(model_name); + notifier->reset_topology_modification(); + } - if(!notifier) return; + void DynamicTopologyBroker::set_topology_modification(const std::string &model_name, + unsigned int type) + { + auto notifier = get_notifier(model_name); - notifier->set_topology_modification(type); -} + if (!notifier) + return; + + notifier->set_topology_modification(type); + } -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.h b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.h index bf6b4ceae7..06fc4b6358 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.h +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyBroker.h @@ -25,34 +25,34 @@ #include // for string, operator< namespace Ioss { -class Region; + class Region; -class IOSS_EXPORT DynamicTopologyBroker -{ -public: - static DynamicTopologyBroker *broker(); + 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 clear_models(); + 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 ®ion); + 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 &); + private: + DynamicTopologyBroker() {}; + DynamicTopologyBroker(DynamicTopologyBroker &); - std::map> m_notifiers; -}; + std::map> m_notifiers; + }; -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.C b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.C index 1045efa221..096323de3d 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.C +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.C @@ -91,81 +91,81 @@ namespace { namespace Ioss { -DynamicTopologyFileControl::DynamicTopologyFileControl(Region *region) - : m_region(region) - , m_fileCyclicCount(region->get_file_cyclic_count()) - , m_ifDatabaseExists(region->get_if_database_exists_behavior()) - , m_dbChangeCount(region->get_topology_change_count()) -{ - if(nullptr == region) { - std::ostringstream errmsg; - fmt::print(errmsg, "ERROR: null region passed in as argument to DynamicTopologyFileControl"); - IOSS_ERROR(errmsg); + DynamicTopologyFileControl::DynamicTopologyFileControl(Region *region) + : m_region(region), m_fileCyclicCount(region->get_file_cyclic_count()), + m_ifDatabaseExists(region->get_if_database_exists_behavior()), + m_dbChangeCount(region->get_topology_change_count()) + { + if (nullptr == region) { + std::ostringstream errmsg; + fmt::print(errmsg, "ERROR: null region passed in as argument to DynamicTopologyFileControl"); + IOSS_ERROR(errmsg); + } + + m_ioDB = region->get_property("base_filename").get_string(); + m_dbType = region->get_property("database_type").get_string(); } - m_ioDB = region->get_property("base_filename").get_string(); - m_dbType = region->get_property("database_type").get_string(); -} - -const ParallelUtils &DynamicTopologyFileControl::util() const -{ - return m_region->get_database()->util(); -} - -bool DynamicTopologyFileControl::file_exists(const std::string &filename, - const std::string &db_type, - Ioss::DatabaseUsage db_usage) -{ - return ::file_exists(util(), filename, db_type, db_usage); -} - -std::string DynamicTopologyFileControl::get_unique_linear_filename(Ioss::DatabaseUsage db_usage) -{ - std::string filename = m_ioDB; - - do { - // Run this loop at least once for all files. If this is an automatic - // restart, then make sure that the generated file does not already exist, - // so keep running the loop until we generate a filename that doesn't exist... - std::ostringstream tmp_filename; - tmp_filename << m_ioDB; - - // Don't append the "-s000X" the first time in case the base filename doesn't - // exist -- we want write to the name specified by the user if at all possible and - // once that exists, then start adding on the suffix... - if (m_dbChangeCount > 1) { - tmp_filename << "-s" << std::setw(4) << std::setfill('0') << m_dbChangeCount; - } - filename = tmp_filename.str(); - ++m_dbChangeCount; - } while(file_exists(filename, m_dbType, db_usage)); - --m_dbChangeCount; - return filename; -} - -std::string DynamicTopologyFileControl::get_internal_file_change_set_name(unsigned int step) -{ - std::ostringstream change_setname; - change_setname << change_set_prefix(); - change_setname << step; - return change_setname.str(); -} - -std::string DynamicTopologyFileControl::get_cyclic_database_filename(const std::string& baseFileName, - unsigned int fileCyclicCount, - unsigned int step) -{ - return ChangeSet::get_cyclic_database_filename(baseFileName, fileCyclicCount, step); -} - -std::string DynamicTopologyFileControl::get_linear_database_filename(const std::string& baseFileName, - unsigned int step) -{ - return ChangeSet::get_linear_database_filename(baseFileName, step); -} - -std::string DynamicTopologyFileControl::construct_database_filename(int& step, Ioss::DatabaseUsage db_usage) -{ + const ParallelUtils &DynamicTopologyFileControl::util() const + { + return m_region->get_database()->util(); + } + + bool DynamicTopologyFileControl::file_exists(const std::string &filename, + const std::string &db_type, + Ioss::DatabaseUsage db_usage) + { + return ::file_exists(util(), filename, db_type, db_usage); + } + + std::string DynamicTopologyFileControl::get_unique_linear_filename(Ioss::DatabaseUsage db_usage) + { + std::string filename = m_ioDB; + + do { + // Run this loop at least once for all files. If this is an automatic + // restart, then make sure that the generated file does not already exist, + // so keep running the loop until we generate a filename that doesn't exist... + std::ostringstream tmp_filename; + tmp_filename << m_ioDB; + + // Don't append the "-s000X" the first time in case the base filename doesn't + // exist -- we want write to the name specified by the user if at all possible and + // once that exists, then start adding on the suffix... + if (m_dbChangeCount > 1) { + tmp_filename << "-s" << std::setw(4) << std::setfill('0') << m_dbChangeCount; + } + filename = tmp_filename.str(); + ++m_dbChangeCount; + } while (file_exists(filename, m_dbType, db_usage)); + --m_dbChangeCount; + return filename; + } + + std::string DynamicTopologyFileControl::get_internal_file_change_set_name(unsigned int step) + { + std::ostringstream change_setname; + change_setname << change_set_prefix(); + change_setname << step; + return change_setname.str(); + } + + std::string DynamicTopologyFileControl::get_cyclic_database_filename( + const std::string &baseFileName, unsigned int fileCyclicCount, unsigned int step) + { + return ChangeSet::get_cyclic_database_filename(baseFileName, fileCyclicCount, step); + } + + std::string + DynamicTopologyFileControl::get_linear_database_filename(const std::string &baseFileName, + unsigned int step) + { + return ChangeSet::get_linear_database_filename(baseFileName, step); + } + + std::string DynamicTopologyFileControl::construct_database_filename(int &step, + Ioss::DatabaseUsage db_usage) + { // Filename will be of the form -- ioDB-sxxxx where xxxx is step // number. Assume maximum of 9999 steps (will do more, but won't have // good lineup of step numbers. diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.h b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.h index e80a69e456..8a4a95a84e 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.h +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.h @@ -23,55 +23,55 @@ #include // for string, operator< namespace Ioss { -class Region; + class Region; -class IOSS_EXPORT DynamicTopologyFileControl -{ -public: - DynamicTopologyFileControl(Region *region); + class IOSS_EXPORT DynamicTopologyFileControl + { + public: + DynamicTopologyFileControl(Region *region); - void clone_and_replace_output_database(int steps = 0); - void add_output_database_change_set(int steps = 0); + void clone_and_replace_output_database(int steps = 0); + void add_output_database_change_set(int steps = 0); - static std::string change_set_prefix() { return "IOSS_FILE_GROUP-"; } + static std::string change_set_prefix() { return "IOSS_FILE_GROUP-"; } - DatabaseIO *get_database() const; + DatabaseIO *get_database() const; - static std::string get_cyclic_database_filename(const std::string &baseFileName, - unsigned int fileCyclicCount, - unsigned int step); + static std::string get_cyclic_database_filename(const std::string &baseFileName, + unsigned int fileCyclicCount, + unsigned int step); - static std::string get_linear_database_filename(const std::string &baseFileName, - unsigned int step); + static std::string get_linear_database_filename(const std::string &baseFileName, + unsigned int step); - static std::string get_internal_file_change_set_name(unsigned int step); + static std::string get_internal_file_change_set_name(unsigned int step); - unsigned int get_topology_change_count() const { return m_dbChangeCount; } - unsigned int get_file_cyclic_count() const { return m_fileCyclicCount; } - IfDatabaseExistsBehavior get_if_database_exists_behavior() const { return m_ifDatabaseExists; } + unsigned int get_topology_change_count() const { return m_dbChangeCount; } + unsigned int get_file_cyclic_count() const { return m_fileCyclicCount; } + IfDatabaseExistsBehavior get_if_database_exists_behavior() const { return m_ifDatabaseExists; } -private: - Region *m_region{nullptr}; - std::string m_ioDB; - std::string m_dbType; + private: + Region *m_region{nullptr}; + std::string m_ioDB; + std::string m_dbType; - PropertyManager m_properties; + PropertyManager m_properties; - unsigned int m_fileCyclicCount; - IfDatabaseExistsBehavior m_ifDatabaseExists; - unsigned int m_dbChangeCount; + unsigned int m_fileCyclicCount; + IfDatabaseExistsBehavior m_ifDatabaseExists; + unsigned int m_dbChangeCount; - IOSS_NODISCARD const ParallelUtils &util() const; + IOSS_NODISCARD const ParallelUtils &util() const; - std::string get_unique_linear_filename(DatabaseUsage db_usage); - std::string construct_database_filename(int &step, DatabaseUsage db_usage); - bool file_exists(const std::string &filename, const std::string &db_type, - DatabaseUsage db_usage); - bool abort_if_exists(const std::string &filename, const std::string &db_type, - DatabaseUsage db_usage); + std::string get_unique_linear_filename(DatabaseUsage db_usage); + std::string construct_database_filename(int &step, DatabaseUsage db_usage); + bool file_exists(const std::string &filename, const std::string &db_type, + DatabaseUsage db_usage); + bool abort_if_exists(const std::string &filename, const std::string &db_type, + DatabaseUsage db_usage); - DatabaseIO *clone_output_database(int steps); - bool replace_output_database(DatabaseIO *db); -}; + DatabaseIO *clone_output_database(int steps); + bool replace_output_database(DatabaseIO *db); + }; -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.C b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.C index ecb86aeb36..294d04cde1 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.C +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.C @@ -6,52 +6,54 @@ #include "Ioss_DynamicTopologyNotifier.h" -#include #include +#include #include #include #include namespace Ioss { -struct DynamicTopologyObserverCompare { - bool operator()(const std::shared_ptr & lhs, - const std::shared_ptr & rhs) const { - assert(lhs && (lhs->get_region() != nullptr)); - assert(rhs && (rhs->get_region() != nullptr)); - return (lhs->get_region() < rhs->get_region()); + struct DynamicTopologyObserverCompare + { + bool operator()(const std::shared_ptr &lhs, + const std::shared_ptr &rhs) const + { + assert(lhs && (lhs->get_region() != nullptr)); + assert(rhs && (rhs->get_region() != nullptr)); + return (lhs->get_region() < rhs->get_region()); + } + }; + + void DynamicTopologyNotifier::register_observer(std::shared_ptr observer) + { + observer->register_notifier(this); + m_observers.push_back(observer); + std::sort(m_observers.begin(), m_observers.end(), DynamicTopologyObserverCompare()); } -}; - -void DynamicTopologyNotifier::register_observer(std::shared_ptr observer) -{ - observer->register_notifier(this); - m_observers.push_back(observer); - std::sort(m_observers.begin(), m_observers.end(), DynamicTopologyObserverCompare()); -} - -void DynamicTopologyNotifier::unregister_observer(std::shared_ptr observer) -{ - auto iter = std::find(m_observers.begin(), m_observers.end(), observer); - if (iter != m_observers.end()) { - (*iter)->register_notifier(nullptr); - m_observers.erase(iter); - } -} -void DynamicTopologyNotifier::reset_topology_modification() -{ - for(std::shared_ptr& observer : m_observers) { - observer->reset_topology_modification(); + void + DynamicTopologyNotifier::unregister_observer(std::shared_ptr observer) + { + auto iter = std::find(m_observers.begin(), m_observers.end(), observer); + if (iter != m_observers.end()) { + (*iter)->register_notifier(nullptr); + m_observers.erase(iter); + } } -} -void DynamicTopologyNotifier::set_topology_modification(unsigned int type) -{ - for(std::shared_ptr& observer : m_observers) { - observer->set_topology_modification(type); + void DynamicTopologyNotifier::reset_topology_modification() + { + for (std::shared_ptr &observer : m_observers) { + observer->reset_topology_modification(); + } } -} + void DynamicTopologyNotifier::set_topology_modification(unsigned int type) + { + for (std::shared_ptr &observer : m_observers) { + observer->set_topology_modification(type); + } + } -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.h b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.h index 7385831580..ca6703c518 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.h +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyNotifier.h @@ -25,59 +25,59 @@ namespace Ioss { -class IOSS_EXPORT DynamicTopologyNotifier -{ -public: - DynamicTopologyNotifier(const std::string &model_name) : m_modelName(model_name) {} + class IOSS_EXPORT DynamicTopologyNotifier + { + public: + DynamicTopologyNotifier(const std::string &model_name) : m_modelName(model_name) {} - virtual ~DynamicTopologyNotifier() = default; + virtual ~DynamicTopologyNotifier() = default; - std::string name() const { return m_modelName; } + 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); + void register_observer(std::shared_ptr observer); - void unregister_observer(std::shared_ptr observer); + void unregister_observer(std::shared_ptr observer); - void reset_topology_modification(); + void reset_topology_modification(); - void set_topology_modification(unsigned int type); + void set_topology_modification(unsigned int type); - template bool has_observer_type() const - { - bool found = false; + template bool has_observer_type() const + { + bool found = false; - for (const std::shared_ptr &observer : m_observers) { - if (dynamic_cast(observer.get()) != nullptr) { - found = true; - break; + for (const std::shared_ptr &observer : m_observers) { + if (dynamic_cast(observer.get()) != nullptr) { + found = true; + break; + } } + return found; } - return found; - } - template - std::vector> get_observer_type() const - { - std::vector> typed_observers; + 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()); - if (typed_observer != nullptr) { - typed_observers.push_back(std::dynamic_pointer_cast(observer)); + 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)); + } } - } - return typed_observers; - } + return typed_observers; + } -private: - const std::string m_modelName; - std::vector> m_observers; -}; + private: + const std::string m_modelName; + std::vector> m_observers; + }; -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.C b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.C index 9db3bfabbe..3f7b0f6e37 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.C +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.C @@ -8,8 +8,8 @@ #include "Ioss_DBUsage.h" #include "Ioss_DatabaseIO.h" #include "Ioss_DynamicTopology.h" -#include "Ioss_DynamicTopologyObserver.h" #include "Ioss_DynamicTopologyNotifier.h" +#include "Ioss_DynamicTopologyObserver.h" #include "Ioss_FileInfo.h" #include "Ioss_IOFactory.h" #include "Ioss_ParallelUtils.h" @@ -25,194 +25,191 @@ #include #include - namespace Ioss { -bool DynamicTopologyObserver::needs_new_output_file() const -{ - // See what type of topology modification has occurred. If a - // simple REORDER, then we don't need a new file, just have to - // inform database of new order; otherwise, need a new file (for - // ExodusII). Baseline implementation - - if ((get_topology_modification() & Ioss::TOPOLOGY_HADAPT) || - (get_topology_modification() & Ioss::TOPOLOGY_CREATEFACE) || - (get_topology_modification() & Ioss::TOPOLOGY_CREATEELEM) || - (get_topology_modification() & Ioss::TOPOLOGY_CREATENODE) || - (get_topology_modification() & Ioss::TOPOLOGY_UNKNOWN) || - (get_topology_modification() & Ioss::TOPOLOGY_SHUFFLE)) { - // See if database has been written to since being opened... - if (get_cumulative_topology_modification() != 0) { - return true; + bool DynamicTopologyObserver::needs_new_output_file() const + { + // See what type of topology modification has occurred. If a + // simple REORDER, then we don't need a new file, just have to + // inform database of new order; otherwise, need a new file (for + // ExodusII). Baseline implementation + + if ((get_topology_modification() & Ioss::TOPOLOGY_HADAPT) || + (get_topology_modification() & Ioss::TOPOLOGY_CREATEFACE) || + (get_topology_modification() & Ioss::TOPOLOGY_CREATEELEM) || + (get_topology_modification() & Ioss::TOPOLOGY_CREATENODE) || + (get_topology_modification() & Ioss::TOPOLOGY_UNKNOWN) || + (get_topology_modification() & Ioss::TOPOLOGY_SHUFFLE)) { + // See if database has been written to since being opened... + if (get_cumulative_topology_modification() != 0) { + return true; + } } + return false; } - return false; -} - -void DynamicTopologyObserver::verify_region_is_registered() const -{ - if(nullptr == m_region) { - std::ostringstream errmsg; - fmt::print(errmsg, - "ERROR: A region has not been registered with the " - "Dynamic Topology Observer.\n\n"); - IOSS_ERROR(errmsg); - } -} - -void DynamicTopologyObserver::register_region(Region *region) -{ - if(nullptr != region && nullptr != m_region && region != m_region) { - std::ostringstream errmsg; - fmt::print(errmsg, - "ERROR: Attempt to re-register different region on " - "Dynamic Topology Observer.\n\n"); - IOSS_ERROR(errmsg); - } - - m_region = region; -} - -void DynamicTopologyObserver::register_notifier(DynamicTopologyNotifier *notifier) -{ - if(nullptr != notifier && nullptr != m_notifier && notifier != m_notifier) { - std::ostringstream errmsg; - fmt::print(errmsg, - "ERROR: Attempt to re-register different notifier on " - "Dynamic Topology Observer.\n\n"); - IOSS_ERROR(errmsg); - } - - m_notifier = notifier; -} - -void DynamicTopologyObserver::set_cumulative_topology_modification(unsigned int type) -{ m_cumulativeTopologyModification = type; } - -unsigned int DynamicTopologyObserver::get_cumulative_topology_modification() const -{ return m_cumulativeTopologyModification; } - -unsigned int DynamicTopologyObserver::get_topology_modification() const -{ return m_topologyModification; } - -void DynamicTopologyObserver::set_topology_modification_nl(unsigned int type) -{ - m_topologyModification |= type; - m_cumulativeTopologyModification |= type; -} - -void DynamicTopologyObserver::sync_topology_modification(unsigned int modFlag, unsigned int cumulativeModFlag) -{ - m_topologyModification = modFlag; - m_cumulativeTopologyModification = cumulativeModFlag; -} - -void DynamicTopologyObserver::set_topology_modification(unsigned int type) -{ - if(!(m_topologyModification & type)) { - set_topology_modification_nl(type); - - if(nullptr != m_notifier) { - for(auto observer : m_notifier->get_observers()) { - observer->set_topology_modification_nl(type); - } + + void DynamicTopologyObserver::verify_region_is_registered() const + { + if (nullptr == m_region) { + std::ostringstream errmsg; + fmt::print(errmsg, "ERROR: A region has not been registered with the " + "Dynamic Topology Observer.\n\n"); + IOSS_ERROR(errmsg); + } + } + + void DynamicTopologyObserver::register_region(Region *region) + { + if (nullptr != region && nullptr != m_region && region != m_region) { + std::ostringstream errmsg; + fmt::print(errmsg, "ERROR: Attempt to re-register different region on " + "Dynamic Topology Observer.\n\n"); + IOSS_ERROR(errmsg); + } + + m_region = region; + } + + void DynamicTopologyObserver::register_notifier(DynamicTopologyNotifier *notifier) + { + if (nullptr != notifier && nullptr != m_notifier && notifier != m_notifier) { + std::ostringstream errmsg; + fmt::print(errmsg, "ERROR: Attempt to re-register different notifier on " + "Dynamic Topology Observer.\n\n"); + IOSS_ERROR(errmsg); } + + m_notifier = notifier; + } + + void DynamicTopologyObserver::set_cumulative_topology_modification(unsigned int type) + { + m_cumulativeTopologyModification = type; } -} -void DynamicTopologyObserver::reset_topology_modification() -{ - m_topologyModification = TOPOLOGY_SAME; -} + unsigned int DynamicTopologyObserver::get_cumulative_topology_modification() const + { + return m_cumulativeTopologyModification; + } -void DynamicTopologyObserver::reset_topology_modification_all() -{ - if(m_topologyModification != TOPOLOGY_SAME) { - reset_topology_modification(); + unsigned int DynamicTopologyObserver::get_topology_modification() const + { + return m_topologyModification; + } + + void DynamicTopologyObserver::set_topology_modification_nl(unsigned int type) + { + m_topologyModification |= type; + m_cumulativeTopologyModification |= type; + } - if(nullptr != m_notifier) { - for(auto observer : m_notifier->get_observers()) { - observer->reset_topology_modification(); + void DynamicTopologyObserver::sync_topology_modification(unsigned int modFlag, + unsigned int cumulativeModFlag) + { + m_topologyModification = modFlag; + m_cumulativeTopologyModification = cumulativeModFlag; + } + + void DynamicTopologyObserver::set_topology_modification(unsigned int type) + { + if (!(m_topologyModification & type)) { + set_topology_modification_nl(type); + + if (nullptr != m_notifier) { + for (auto observer : m_notifier->get_observers()) { + observer->set_topology_modification_nl(type); + } } } } -} - -bool DynamicTopologyObserver::is_topology_modified() const -{ return m_topologyModification != TOPOLOGY_SAME; } - -const ParallelUtils &DynamicTopologyObserver::util() const -{ - verify_region_is_registered(); - return m_region->get_database()->util(); -} - -void DynamicTopologyObserver::synchronize_topology_modified_flags() -{ - verify_region_is_registered(); - int num_processors = m_region->get_database()->parallel_size(); - // Synchronize the topology flags between all processors in case - // it has not been set consistently. - if (num_processors > 1) { - static unsigned int buffer[2]; - buffer[0] = m_cumulativeTopologyModification; - buffer[1] = m_topologyModification; - - util().attribute_reduction(2*sizeof(unsigned int), reinterpret_cast(buffer)); - - m_cumulativeTopologyModification = buffer[0]; - m_topologyModification = buffer[1]; - } -} - -int DynamicTopologyObserver::get_cumulative_topology_modification_field() -{ - verify_region_is_registered(); - const std::string variable_name = topology_modification_change_name(); - - int ivalue = 0; - - if (m_region->field_exists(variable_name)) { - Field topo_field = m_region->get_field(variable_name); - if (topo_field.get_type() == Field::INTEGER) { - m_region->get_field_data(variable_name, &ivalue, sizeof(int)); - } else { - double value; - m_region->get_field_data(variable_name, &value, sizeof(double)); - ivalue = (int)value; + + void DynamicTopologyObserver::reset_topology_modification() + { + m_topologyModification = TOPOLOGY_SAME; + } + + void DynamicTopologyObserver::reset_topology_modification_all() + { + if (m_topologyModification != TOPOLOGY_SAME) { + reset_topology_modification(); + + if (nullptr != m_notifier) { + for (auto observer : m_notifier->get_observers()) { + observer->reset_topology_modification(); + } + } } } - int num_processors = m_region->get_database()->parallel_size(); - // Synchronize the value between all processors in case - // it has not been set consistently. - if (num_processors > 1) { - unsigned int buffer[1]; - buffer[0] = ivalue; + bool DynamicTopologyObserver::is_topology_modified() const + { + return m_topologyModification != TOPOLOGY_SAME; + } - util().attribute_reduction(sizeof(unsigned int), reinterpret_cast(buffer)); + const ParallelUtils &DynamicTopologyObserver::util() const + { + verify_region_is_registered(); + return m_region->get_database()->util(); + } - ivalue = (int)buffer[0]; + void DynamicTopologyObserver::synchronize_topology_modified_flags() + { + verify_region_is_registered(); + int num_processors = m_region->get_database()->parallel_size(); + // Synchronize the topology flags between all processors in case + // it has not been set consistently. + if (num_processors > 1) { + static unsigned int buffer[2]; + buffer[0] = m_cumulativeTopologyModification; + buffer[1] = m_topologyModification; + + util().attribute_reduction(2 * sizeof(unsigned int), reinterpret_cast(buffer)); + + m_cumulativeTopologyModification = buffer[0]; + m_topologyModification = buffer[1]; + } } - m_cumulativeTopologyModification = ivalue; + int DynamicTopologyObserver::get_cumulative_topology_modification_field() + { + verify_region_is_registered(); + const std::string variable_name = topology_modification_change_name(); + + int ivalue = 0; - return ivalue; -} + if (m_region->field_exists(variable_name)) { + Field topo_field = m_region->get_field(variable_name); + if (topo_field.get_type() == Field::INTEGER) { + m_region->get_field_data(variable_name, &ivalue, sizeof(int)); + } + else { + double value; + m_region->get_field_data(variable_name, &value, sizeof(double)); + ivalue = (int)value; + } + } -void DynamicTopologyObserver::define_model() -{ + int num_processors = m_region->get_database()->parallel_size(); + // Synchronize the value between all processors in case + // it has not been set consistently. + if (num_processors > 1) { + unsigned int buffer[1]; + buffer[0] = ivalue; -} + util().attribute_reduction(sizeof(unsigned int), reinterpret_cast(buffer)); -void DynamicTopologyObserver::write_model() -{ + ivalue = (int)buffer[0]; + } + + m_cumulativeTopologyModification = ivalue; + + return ivalue; + } -} + void DynamicTopologyObserver::define_model() {} -void DynamicTopologyObserver::define_transient() -{ + void DynamicTopologyObserver::write_model() {} -} + void DynamicTopologyObserver::define_transient() {} -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.h b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.h index 8222673ad5..6bb08cd018 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.h +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyObserver.h @@ -23,71 +23,71 @@ #include // for string, operator< namespace Ioss { -class Region; -class DynamicTopologyNotifier; + class Region; + class DynamicTopologyNotifier; -class IOSS_EXPORT DynamicTopologyObserver -{ -public: - DynamicTopologyObserver(Region *region) : m_region(region) {} + class IOSS_EXPORT DynamicTopologyObserver + { + public: + DynamicTopologyObserver(Region *region) : m_region(region) {} - virtual ~DynamicTopologyObserver() {} + virtual ~DynamicTopologyObserver() {} - virtual void reset_topology_modification_all(); - virtual void reset_topology_modification(); - virtual void set_topology_modification(unsigned int type); - virtual void sync_topology_modification(unsigned int modFlag, unsigned int cumulativeModFlag); - virtual unsigned int get_topology_modification() const; + virtual void reset_topology_modification_all(); + virtual void reset_topology_modification(); + virtual void set_topology_modification(unsigned int type); + virtual void sync_topology_modification(unsigned int modFlag, unsigned int cumulativeModFlag); + virtual unsigned int get_topology_modification() const; - virtual unsigned int get_cumulative_topology_modification() const; - virtual void set_cumulative_topology_modification(unsigned int type); + virtual unsigned int get_cumulative_topology_modification() const; + virtual void set_cumulative_topology_modification(unsigned int type); - int get_cumulative_topology_modification_field(); + int get_cumulative_topology_modification_field(); - virtual bool is_topology_modified() const; - virtual bool is_automatic_restart() const { return m_automaticRestart; } - virtual bool is_restart_requested() const { return m_restartRequested; } + virtual bool is_topology_modified() const; + virtual bool is_automatic_restart() const { return m_automaticRestart; } + virtual bool is_restart_requested() const { return m_restartRequested; } - void set_automatic_restart(bool flag) { m_automaticRestart = flag; } - void set_restart_requested(bool flag) { m_restartRequested = flag; } + void set_automatic_restart(bool flag) { m_automaticRestart = flag; } + void set_restart_requested(bool flag) { m_restartRequested = flag; } - static const std::string topology_modification_change_name() - { - return std::string("CUMULATIVE_TOPOLOGY_MODIFICATION"); - } + static const std::string topology_modification_change_name() + { + return std::string("CUMULATIVE_TOPOLOGY_MODIFICATION"); + } - void register_region(Region *region); - Region *get_region() const { return m_region; } + 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(); - virtual void define_transient(); + virtual void define_model(); + virtual void write_model(); + virtual void define_transient(); - virtual FileControlOption get_control_option() const { return FileControlOption::CONTROL_NONE; } + virtual FileControlOption get_control_option() const { return FileControlOption::CONTROL_NONE; } - virtual bool needs_new_output_file() const; + virtual bool needs_new_output_file() const; -protected: - Region *m_region{nullptr}; - unsigned int m_topologyModification{TOPOLOGY_SAME}; - unsigned int m_cumulativeTopologyModification{TOPOLOGY_SAME}; + protected: + Region *m_region{nullptr}; + unsigned int m_topologyModification{TOPOLOGY_SAME}; + unsigned int m_cumulativeTopologyModification{TOPOLOGY_SAME}; - bool m_automaticRestart{false}; - bool m_restartRequested{false}; + bool m_automaticRestart{false}; + bool m_restartRequested{false}; - DynamicTopologyNotifier *m_notifier{nullptr}; + DynamicTopologyNotifier *m_notifier{nullptr}; - void verify_region_is_registered() const; - IOSS_NODISCARD const ParallelUtils &util() const; - void synchronize_topology_modified_flags(); + void verify_region_is_registered() const; + IOSS_NODISCARD const ParallelUtils &util() const; + void synchronize_topology_modified_flags(); - void set_topology_modification_nl(unsigned int type); + void set_topology_modification_nl(unsigned int type); -private: - DynamicTopologyObserver(); -}; + private: + DynamicTopologyObserver(); + }; -} +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.C b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.C index 5629f123c0..672b1a8015 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.C +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.C @@ -22,158 +22,156 @@ namespace Ioss { -DynamicTopologyStateLocator::DynamicTopologyStateLocator(Region *region, bool loadAllFiles) - : m_database(region->get_database()), - m_ioDB(region->get_property("base_filename").get_string()), - m_dbType(region->get_property("database_type").get_string()), - m_fileCyclicCount(region->get_file_cyclic_count()), m_loadAllFiles(loadAllFiles) -{ -} - -DynamicTopologyStateLocator::DynamicTopologyStateLocator(Ioss::DatabaseIO *db, - const std::string &dbName, - const std::string &dbType, - unsigned fileCyclicCount, - bool loadAllFiles) - : m_database(db), m_ioDB(dbName), m_dbType(dbType), m_fileCyclicCount(fileCyclicCount), - m_loadAllFiles(loadAllFiles) -{ -} - -DynamicTopologyStateLocator::DynamicTopologyStateLocator(Ioss::DatabaseIO *db, - unsigned fileCyclicCount, - bool loadAllFiles) - : m_database(db), - m_ioDB(db->get_property_manager().get_optional("base_filename", db->get_filename())), - m_dbType(db->get_property_manager().get_optional("database_type", "")), - m_fileCyclicCount(fileCyclicCount), m_loadAllFiles(loadAllFiles) -{ -} - -DynamicTopologyStateLocator::~DynamicTopologyStateLocator() {} - -const ParallelUtils &DynamicTopologyStateLocator::util() const { return get_database()->util(); } - -DatabaseIO *DynamicTopologyStateLocator::get_database() const { return m_database; } - -std::tuple -DynamicTopologyStateLocator::locate_db_state(double targetTime) const -{ - auto db = get_database(); - DatabaseState loc(db); - - locate_db_state_impl(targetTime, loc); - - return std::make_tuple(loc.changeSet, loc.state, loc.time); -} - -std::tuple DynamicTopologyStateLocator::get_db_max_time() const -{ - auto db = get_database(); - DatabaseState loc(db); - - double init_time = -std::numeric_limits::max(); - StateLocatorCompare compare = [](double a, double b) { return (a > b); }; - - get_db_time_impl(init_time, compare, loc); - - return std::make_tuple(loc.changeSet, loc.state, loc.time); -} - -std::tuple DynamicTopologyStateLocator::get_db_min_time() const -{ - auto db = get_database(); - DatabaseState loc(db); - - double init_time = std::numeric_limits::max(); - StateLocatorCompare compare = [](double a, double b) { return (a < b); }; - - get_db_time_impl(init_time, compare, loc); - - return std::make_tuple(loc.changeSet, loc.state, loc.time); -} - -void DynamicTopologyStateLocator::locate_state_impl(Ioss::DatabaseIO *db, double targetTime, - StateLocatorCompare comparator, - DatabaseState &loc) const -{ - std::vector timesteps = db->get_db_step_times(); - int stepCount = timesteps.size(); - - double minTimeDiff = - loc.state < 0 ? std::numeric_limits::max() : std::fabs(loc.time - targetTime); - - for (int istep = 1; istep <= stepCount; istep++) { - double stateTime = timesteps[istep - 1]; - double stepTimeDiff = std::fabs(stateTime - targetTime); - if (comparator(stepTimeDiff, minTimeDiff)) { - minTimeDiff = stepTimeDiff; - loc.time = stateTime; - loc.state = istep; - loc.changeSet = db->supports_internal_change_set() ? db->get_internal_change_set_name() - : db->get_filename(); - } + DynamicTopologyStateLocator::DynamicTopologyStateLocator(Region *region, bool loadAllFiles) + : m_database(region->get_database()), + m_ioDB(region->get_property("base_filename").get_string()), + m_dbType(region->get_property("database_type").get_string()), + m_fileCyclicCount(region->get_file_cyclic_count()), m_loadAllFiles(loadAllFiles) + { } -} - -void DynamicTopologyStateLocator::locate_state(Ioss::DatabaseIO *db, double targetTime, - DatabaseState &loc) const -{ - if (targetTime < 0.0) { - // Round towards 0 - StateLocatorCompare compare = [](double a, double b) { return (a <= b); }; - locate_state_impl(db, targetTime, compare, loc); + + DynamicTopologyStateLocator::DynamicTopologyStateLocator(Ioss::DatabaseIO *db, + const std::string &dbName, + const std::string &dbType, + unsigned fileCyclicCount, + bool loadAllFiles) + : m_database(db), m_ioDB(dbName), m_dbType(dbType), m_fileCyclicCount(fileCyclicCount), + m_loadAllFiles(loadAllFiles) + { } - else { - // Round towards 0 - StateLocatorCompare compare = [](double a, double b) { return (a < b); }; - locate_state_impl(db, targetTime, compare, loc); + + DynamicTopologyStateLocator::DynamicTopologyStateLocator(Ioss::DatabaseIO *db, + unsigned fileCyclicCount, + bool loadAllFiles) + : m_database(db), + m_ioDB(db->get_property_manager().get_optional("base_filename", db->get_filename())), + m_dbType(db->get_property_manager().get_optional("database_type", "")), + m_fileCyclicCount(fileCyclicCount), m_loadAllFiles(loadAllFiles) + { } -} - -void DynamicTopologyStateLocator::locate_db_state_impl(double targetTime, - DatabaseState &loc) const -{ - auto changeSet = - Ioss::ChangeSetFactory::create(m_database, m_ioDB, m_dbType, m_fileCyclicCount); - changeSet->populate_change_sets(m_loadAllFiles); - - for (size_t csIndex = 0; csIndex < changeSet->size(); csIndex++) { - auto csdb = changeSet->open_change_set(csIndex, Ioss::QUERY_TIMESTEPS_ONLY); - locate_state(csdb, targetTime, loc); - changeSet->close_change_set(csIndex); + + DynamicTopologyStateLocator::~DynamicTopologyStateLocator() {} + + const ParallelUtils &DynamicTopologyStateLocator::util() const { return get_database()->util(); } + + DatabaseIO *DynamicTopologyStateLocator::get_database() const { return m_database; } + + std::tuple + DynamicTopologyStateLocator::locate_db_state(double targetTime) const + { + auto db = get_database(); + DatabaseState loc(db); + + locate_db_state_impl(targetTime, loc); + + return std::make_tuple(loc.changeSet, loc.state, loc.time); } -} - -void DynamicTopologyStateLocator::get_db_time_impl(double init_time, - StateLocatorCompare comparator, - DatabaseState &loc) const -{ - auto changeSet = - Ioss::ChangeSetFactory::create(m_database, m_ioDB, m_dbType, m_fileCyclicCount); - changeSet->populate_change_sets(m_loadAllFiles); - - double best_time = init_time; - - for (size_t csIndex = 0; csIndex < changeSet->size(); csIndex++) { - auto csdb = changeSet->open_change_set(csIndex, Ioss::QUERY_TIMESTEPS_ONLY); - - std::vector timesteps = csdb->get_db_step_times(); - int stepCount = static_cast(timesteps.size()); - - for (int i = 1; i <= stepCount; i++) { - if (comparator(timesteps[i - 1], best_time)) { - loc.time = timesteps[i - 1]; - loc.state = i; - loc.changeSet = changeSet->get_change_set_name(csIndex); - best_time = timesteps[i - 1]; + + std::tuple DynamicTopologyStateLocator::get_db_max_time() const + { + auto db = get_database(); + DatabaseState loc(db); + + double init_time = -std::numeric_limits::max(); + StateLocatorCompare compare = [](double a, double b) { return (a > b); }; + + get_db_time_impl(init_time, compare, loc); + + return std::make_tuple(loc.changeSet, loc.state, loc.time); + } + + std::tuple DynamicTopologyStateLocator::get_db_min_time() const + { + auto db = get_database(); + DatabaseState loc(db); + + double init_time = std::numeric_limits::max(); + StateLocatorCompare compare = [](double a, double b) { return (a < b); }; + + get_db_time_impl(init_time, compare, loc); + + return std::make_tuple(loc.changeSet, loc.state, loc.time); + } + + void DynamicTopologyStateLocator::locate_state_impl(Ioss::DatabaseIO *db, double targetTime, + StateLocatorCompare comparator, + DatabaseState &loc) const + { + std::vector timesteps = db->get_db_step_times(); + int stepCount = timesteps.size(); + + double minTimeDiff = + loc.state < 0 ? std::numeric_limits::max() : std::fabs(loc.time - targetTime); + + for (int istep = 1; istep <= stepCount; istep++) { + double stateTime = timesteps[istep - 1]; + double stepTimeDiff = std::fabs(stateTime - targetTime); + if (comparator(stepTimeDiff, minTimeDiff)) { + minTimeDiff = stepTimeDiff; + loc.time = stateTime; + loc.state = istep; + loc.changeSet = db->supports_internal_change_set() ? db->get_internal_change_set_name() + : db->get_filename(); } } + } + + void DynamicTopologyStateLocator::locate_state(Ioss::DatabaseIO *db, double targetTime, + DatabaseState &loc) const + { + if (targetTime < 0.0) { + // Round towards 0 + StateLocatorCompare compare = [](double a, double b) { return (a <= b); }; + locate_state_impl(db, targetTime, compare, loc); + } + else { + // Round towards 0 + StateLocatorCompare compare = [](double a, double b) { return (a < b); }; + locate_state_impl(db, targetTime, compare, loc); + } + } - changeSet->close_change_set(csIndex); + void DynamicTopologyStateLocator::locate_db_state_impl(double targetTime, + DatabaseState &loc) const + { + auto changeSet = + Ioss::ChangeSetFactory::create(m_database, m_ioDB, m_dbType, m_fileCyclicCount); + changeSet->populate_change_sets(m_loadAllFiles); + + for (size_t csIndex = 0; csIndex < changeSet->size(); csIndex++) { + auto csdb = changeSet->open_change_set(csIndex, Ioss::QUERY_TIMESTEPS_ONLY); + locate_state(csdb, targetTime, loc); + changeSet->close_change_set(csIndex); + } } -} + void DynamicTopologyStateLocator::get_db_time_impl(double init_time, + StateLocatorCompare comparator, + DatabaseState &loc) const + { + auto changeSet = + Ioss::ChangeSetFactory::create(m_database, m_ioDB, m_dbType, m_fileCyclicCount); + changeSet->populate_change_sets(m_loadAllFiles); + + double best_time = init_time; + + for (size_t csIndex = 0; csIndex < changeSet->size(); csIndex++) { + auto csdb = changeSet->open_change_set(csIndex, Ioss::QUERY_TIMESTEPS_ONLY); + + std::vector timesteps = csdb->get_db_step_times(); + int stepCount = static_cast(timesteps.size()); + + for (int i = 1; i <= stepCount; i++) { + if (comparator(timesteps[i - 1], best_time)) { + loc.time = timesteps[i - 1]; + loc.state = i; + loc.changeSet = changeSet->get_change_set_name(csIndex); + best_time = timesteps[i - 1]; + } + } -} + changeSet->close_change_set(csIndex); + } + } +} // namespace Ioss diff --git a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.h b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.h index 1bd8e41fb1..557772c155 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.h +++ b/packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyStateLocator.h @@ -23,62 +23,62 @@ #include // for string, operator< namespace Ioss { -class Region; - -class IOSS_EXPORT DynamicTopologyStateLocator -{ -public: - DynamicTopologyStateLocator(Region *region, bool loadAllFiles = true); - DynamicTopologyStateLocator(Ioss::DatabaseIO *db, const std::string &dbName, - const std::string &dbType, unsigned fileCyclicCount = 0, - bool loadAllFiles = true); - DynamicTopologyStateLocator(Ioss::DatabaseIO *db, unsigned fileCyclicCount = 0, - bool loadAllFiles = true); - - virtual ~DynamicTopologyStateLocator(); - DynamicTopologyStateLocator() = delete; - DynamicTopologyStateLocator(const DynamicTopologyStateLocator &) = delete; - - DatabaseIO *get_database() const; - - std::tuple locate_db_state(double targetTime) const; - std::tuple get_db_min_time() const; - std::tuple get_db_max_time() const; - -private: - struct DatabaseState + class Region; + + class IOSS_EXPORT DynamicTopologyStateLocator { - DatabaseState(Ioss::DatabaseIO *db) + public: + DynamicTopologyStateLocator(Region *region, bool loadAllFiles = true); + DynamicTopologyStateLocator(Ioss::DatabaseIO *db, const std::string &dbName, + const std::string &dbType, unsigned fileCyclicCount = 0, + bool loadAllFiles = true); + DynamicTopologyStateLocator(Ioss::DatabaseIO *db, unsigned fileCyclicCount = 0, + bool loadAllFiles = true); + + virtual ~DynamicTopologyStateLocator(); + DynamicTopologyStateLocator() = delete; + DynamicTopologyStateLocator(const DynamicTopologyStateLocator &) = delete; + + DatabaseIO *get_database() const; + + std::tuple locate_db_state(double targetTime) const; + std::tuple get_db_min_time() const; + std::tuple get_db_max_time() const; + + private: + struct DatabaseState { - if (!db->supports_internal_change_set()) { - changeSet = db->get_filename(); + DatabaseState(Ioss::DatabaseIO *db) + { + if (!db->supports_internal_change_set()) { + changeSet = db->get_filename(); + } } - } - std::string changeSet{"/"}; - int state{-1}; - double time{-std::numeric_limits::max()}; - }; + std::string changeSet{"/"}; + int state{-1}; + double time{-std::numeric_limits::max()}; + }; - using StateLocatorCompare = std::function; + using StateLocatorCompare = std::function; - void locate_state_impl(Ioss::DatabaseIO *db, double targetTime, StateLocatorCompare comparator, - DatabaseState &loc) const; + void locate_state_impl(Ioss::DatabaseIO *db, double targetTime, StateLocatorCompare comparator, + DatabaseState &loc) const; - void locate_state(Ioss::DatabaseIO *db, double targetTime, DatabaseState &loc) const; + void locate_state(Ioss::DatabaseIO *db, double targetTime, DatabaseState &loc) const; - void locate_db_state_impl(double targetTime, DatabaseState &loc) const; + void locate_db_state_impl(double targetTime, DatabaseState &loc) const; - void get_db_time_impl(double init_time, StateLocatorCompare comparator, - DatabaseState &loc) const; + void get_db_time_impl(double init_time, StateLocatorCompare comparator, + DatabaseState &loc) const; - IOSS_NODISCARD const ParallelUtils &util() const; + IOSS_NODISCARD const ParallelUtils &util() const; - Ioss::DatabaseIO *m_database{nullptr}; - std::string m_ioDB; - std::string m_dbType; - unsigned m_fileCyclicCount{0}; - bool m_loadAllFiles{true}; -}; + Ioss::DatabaseIO *m_database{nullptr}; + std::string m_ioDB; + std::string m_dbType; + unsigned m_fileCyclicCount{0}; + bool m_loadAllFiles{true}; + }; -} +} // namespace Ioss