| 1 |
// Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "Ioex_ChangeSet.h" |
| 8 |
#include "Ioex_DatabaseIO.h" |
| 9 |
|
| 10 |
#include "Ioss_CodeTypes.h" // for Int64Vector, IntVector |
| 11 |
#include "Ioss_SmartAssert.h" |
| 12 |
#include <cassert> // for assert |
| 13 |
#include <cmath> // for sqrt |
| 14 |
#include <fmt/format.h> |
| 15 |
#include <fmt/ostream.h> |
| 16 |
#include <iostream> // for ostringstream |
| 17 |
#include <stdlib.h> |
| 18 |
#include <string> // for string, operator==, etc |
| 19 |
#include <vector> |
| 20 |
|
| 21 |
#include "Ioss_ChangeSetFactory.h" // for ChangeSetFactory |
| 22 |
#include "Ioss_Property.h" // for Property |
| 23 |
#include "Ioss_PropertyManager.h" // for PropertyManager |
| 24 |
#include "Ioss_Region.h" // for Region |
| 25 |
|
| 26 |
namespace Ioex { |
| 27 |
// ======================================================================== |
| 28 |
const ChangeSetFactory *ChangeSetFactory::factory() |
| 29 |
{ |
| 30 |
static ChangeSetFactory registerThis; |
| 31 |
return ®isterThis; |
| 32 |
} |
| 33 |
|
| 34 |
ChangeSetFactory::ChangeSetFactory() : Ioss::ChangeSetFactory("exodus") |
| 35 |
{ |
| 36 |
Ioss::ChangeSetFactory::alias("exodus", "exodusii"); |
| 37 |
Ioss::ChangeSetFactory::alias("exodus", "exodusII"); |
| 38 |
Ioss::ChangeSetFactory::alias("exodus", "genesis"); |
| 39 |
#if defined(PARALLEL_AWARE_EXODUS) |
| 40 |
Ioss::ChangeSetFactory::alias("exodus", "dof_exodus"); |
| 41 |
Ioss::ChangeSetFactory::alias("exodus", "dof"); |
| 42 |
#endif |
| 43 |
} |
| 44 |
|
| 45 |
Ioss::ChangeSet *ChangeSetFactory::make_ChangeSet(Ioss::Region *region) const |
| 46 |
{ |
| 47 |
return new ChangeSet(region); |
| 48 |
} |
| 49 |
|
| 50 |
Ioss::ChangeSet *ChangeSetFactory::make_ChangeSet(Ioss::DatabaseIO *db, const std::string &dbName, |
| 51 |
const std::string &dbType, |
| 52 |
unsigned fileCyclicCount) const |
| 53 |
{ |
| 54 |
return new ChangeSet(db, dbName, dbType, fileCyclicCount); |
| 55 |
} |
| 56 |
|
| 57 |
// ======================================================================== |
| 58 |
ChangeSet::ChangeSet(Ioss::Region *region) : Ioss::ChangeSet(region) |
| 59 |
{ |
| 60 |
Ioss::ChangeSet::m_supportedFormats = |
| 61 |
(Ioss::CHANGE_SET_INTERNAL_FILES | Ioss::CHANGE_SET_LINEAR_MULTI_FILES | |
| 62 |
Ioss::CHANGE_SET_CYCLIC_MULTI_FILES); |
| 63 |
} |
| 64 |
|
| 65 |
ChangeSet::ChangeSet(Ioss::DatabaseIO *db, const std::string &dbName, const std::string &dbType, |
| 66 |
unsigned fileCyclicCount) |
| 67 |
: Ioss::ChangeSet(db, dbName, dbType, fileCyclicCount) |
| 68 |
{ |
| 69 |
Ioss::ChangeSet::m_supportedFormats = |
| 70 |
(Ioss::CHANGE_SET_INTERNAL_FILES | Ioss::CHANGE_SET_LINEAR_MULTI_FILES | |
| 71 |
Ioss::CHANGE_SET_CYCLIC_MULTI_FILES); |
| 72 |
} |
| 73 |
|
| 74 |
ChangeSet::~ChangeSet() {} |
| 75 |
|
| 76 |
void ChangeSet::get_group_change_sets() |
| 77 |
{ |
| 78 |
auto iossDB = get_database(); |
| 79 |
Ioex::BaseDatabaseIO *ioexDB = dynamic_cast<Ioex::BaseDatabaseIO *>(iossDB); |
| 80 |
|
| 81 |
if (nullptr == ioexDB) { |
| 82 |
std::ostringstream errmsg; |
| 83 |
fmt::print(errmsg, "ERROR: The database file named '{}' is not Exodus format\n", |
| 84 |
iossDB->get_filename()); |
| 85 |
IOSS_ERROR(errmsg); |
| 86 |
} |
| 87 |
|
| 88 |
m_databaseFormat = Ioss::CHANGE_SET_INTERNAL_FILES; |
| 89 |
m_currentChangeSet = ioexDB->get_internal_change_set_name(); |
| 90 |
|
| 91 |
Ioss::NameList names = ioexDB->groups_describe(false); |
| 92 |
|
| 93 |
// Downshift by 1 since the first is the root group "/" |
| 94 |
int numNames = static_cast<int>(names.size()); |
| 95 |
for (int i = 0; i < numNames - 1; i++) { |
| 96 |
m_changeSetNames.push_back(names[i + 1]); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
bool ChangeSet::supports_group() |
| 101 |
{ |
| 102 |
auto iossDB = get_database(); |
| 103 |
Ioex::BaseDatabaseIO *ioexDB = dynamic_cast<Ioex::BaseDatabaseIO *>(iossDB); |
| 104 |
|
| 105 |
if (nullptr == ioexDB) { |
| 106 |
std::ostringstream errmsg; |
| 107 |
fmt::print(errmsg, "ERROR: The database file named '{}' is not Exodus format\n", |
| 108 |
iossDB->get_filename()); |
| 109 |
IOSS_ERROR(errmsg); |
| 110 |
} |
| 111 |
|
| 112 |
return ioexDB->supports_group() && (ioexDB->num_child_group() > 0); |
| 113 |
} |
| 114 |
|
| 115 |
void ChangeSet::populate_change_sets(bool loadAllFiles) |
| 116 |
{ |
| 117 |
if (supports_group()) { |
| 118 |
get_group_change_sets(); |
| 119 |
} |
| 120 |
else { |
| 121 |
Ioss::ChangeSet::populate_change_sets(loadAllFiles); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
void ChangeSet::clear_change_sets() |
| 126 |
{ |
| 127 |
m_changeSetNames.clear(); |
| 128 |
m_currentChangeSet = ""; |
| 129 |
} |
| 130 |
|
| 131 |
void ChangeSet::close_change_set(unsigned index) |
| 132 |
{ |
| 133 |
if (Ioss::CHANGE_SET_INTERNAL_FILES != m_databaseFormat) { |
| 134 |
Ioss::ChangeSet::close_change_set(index); |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
verify_change_set_index(index); |
| 139 |
|
| 140 |
auto iossDB = get_database(); |
| 141 |
if (!iossDB->open_internal_change_set(m_currentChangeSet)) { |
| 142 |
std::ostringstream errmsg; |
| 143 |
fmt::print(errmsg, "ERROR: The database file named '{}' could not open group '{}\n", |
| 144 |
iossDB->get_filename(), m_currentChangeSet); |
| 145 |
IOSS_ERROR(errmsg); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
Ioss::DatabaseIO *ChangeSet::open_change_set(unsigned index, Ioss::DatabaseUsage usage) |
| 150 |
{ |
| 151 |
if (Ioss::CHANGE_SET_INTERNAL_FILES != m_databaseFormat) { |
| 152 |
return Ioss::ChangeSet::open_change_set(index, usage); |
| 153 |
} |
| 154 |
|
| 155 |
verify_change_set_index(index); |
| 156 |
|
| 157 |
auto db = get_database(); |
| 158 |
db->open_internal_change_set(index); |
| 159 |
|
| 160 |
return db; |
| 161 |
} |
| 162 |
} // namespace Ioex |