| 1 |
/* |
| 2 |
* Copyright(C) 1999-2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include <cstdint> |
| 12 |
#include <exodusII.h> |
| 13 |
#include <string> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
#include "Ioss_ParallelUtils.h" |
| 17 |
#include "Ioss_Utils.h" |
| 18 |
#include "ioex_export.h" |
| 19 |
|
| 20 |
namespace Ioss { |
| 21 |
class Assembly; |
| 22 |
class Blob; |
| 23 |
class EdgeBlock; |
| 24 |
class EdgeSet; |
| 25 |
class ElementBlock; |
| 26 |
class ElementSet; |
| 27 |
class FaceBlock; |
| 28 |
class FaceSet; |
| 29 |
class NodeBlock; |
| 30 |
class NodeSet; |
| 31 |
class SideBlock; |
| 32 |
class SideSet; |
| 33 |
class Region; |
| 34 |
} // namespace Ioss |
| 35 |
|
| 36 |
using entity_id = int64_t; |
| 37 |
|
| 38 |
namespace Ioss { |
| 39 |
} // namespace Ioss |
| 40 |
/*! |
| 41 |
* This set of classes provides a thin wrapper around the exodusII |
| 42 |
* internals. It supplants several of the exodusII API calls in |
| 43 |
* order to avoid ncredef calls which totally rewrite the existing |
| 44 |
* database and can be very expensive. These routines provide all |
| 45 |
* required variable, dimension, and attribute definitions to the |
| 46 |
* underlying netcdf file with only a single ncredef call. |
| 47 |
* |
| 48 |
* To use the application must create an Internals instance |
| 49 |
* and call the Internals::write_meta_data() function. This |
| 50 |
* function requires several classes as arguments including: |
| 51 |
* <ul> |
| 52 |
* <li> Mesh -- defines mesh global metadata |
| 53 |
* <li> Block -- defines metadata for each block |
| 54 |
* <li> NodeSet -- defines metadata for each nodeset |
| 55 |
* <li> SideSet -- defines metadata for each sideset |
| 56 |
* <li> CommunicationMetaData -- global metadata relating to |
| 57 |
* parallel info. |
| 58 |
* </ul> |
| 59 |
* |
| 60 |
* Calling Internals::write_meta_data(), replaces the |
| 61 |
* following exodusII and nemesis API calls: |
| 62 |
* <ul> |
| 63 |
* <li> ex_put_init(), |
| 64 |
* <li> ex_put_elem_block(), |
| 65 |
* <li> ex_put_node_set_param(), |
| 66 |
* <li> ex_put_side_set_param(), |
| 67 |
* <li> ne_put_init_info(), |
| 68 |
* <li> ne_put_loadbal_param(), |
| 69 |
* <li> ne_put_cmap_params(), |
| 70 |
* </ul> |
| 71 |
*/ |
| 72 |
namespace Ioex { |
| 73 |
struct IOEX_EXPORT NodeBlock |
| 74 |
{ |
| 75 |
explicit NodeBlock(const Ioss::NodeBlock &other); |
| 76 |
|
| 77 |
std::string name{}; |
| 78 |
entity_id id{0}; |
| 79 |
int64_t entityCount{0}; |
| 80 |
int64_t localOwnedCount{0}; |
| 81 |
int64_t attributeCount{0}; |
| 82 |
int64_t procOffset{0}; |
| 83 |
}; |
| 84 |
|
| 85 |
struct IOEX_EXPORT Assembly |
| 86 |
{ |
| 87 |
explicit Assembly(const Ioss::Assembly &other); |
| 88 |
|
| 89 |
std::string name{}; |
| 90 |
entity_id id{0}; |
| 91 |
int64_t entityCount{0}; |
| 92 |
int64_t attributeCount{0}; |
| 93 |
ex_entity_type type{}; |
| 94 |
std::vector<int64_t> memberIdList; |
| 95 |
}; |
| 96 |
|
| 97 |
struct IOEX_EXPORT Blob |
| 98 |
{ |
| 99 |
explicit Blob(const Ioss::Blob &other); |
| 100 |
|
| 101 |
std::string name{}; |
| 102 |
entity_id id{0}; |
| 103 |
int64_t entityCount{0}; |
| 104 |
int64_t localOwnedCount{0}; |
| 105 |
int64_t attributeCount{0}; |
| 106 |
int64_t procOffset{0}; |
| 107 |
}; |
| 108 |
|
| 109 |
struct IOEX_EXPORT EdgeBlock |
| 110 |
{ |
| 111 |
EdgeBlock() { Ioss::Utils::copy_string(elType, ""); } |
| 112 |
|
| 113 |
EdgeBlock(const EdgeBlock &other) |
| 114 |
: name(other.name), id(other.id), entityCount(other.entityCount), |
| 115 |
nodesPerEntity(other.nodesPerEntity), attributeCount(other.attributeCount), |
| 116 |
procOffset(other.procOffset) |
| 117 |
{ |
| 118 |
Ioss::Utils::copy_string(elType, other.elType); |
| 119 |
} |
| 120 |
|
| 121 |
explicit EdgeBlock(const Ioss::EdgeBlock &other); |
| 122 |
|
| 123 |
char elType[MAX_STR_LENGTH + 1]{}; |
| 124 |
std::string name{}; |
| 125 |
entity_id id{0}; |
| 126 |
int64_t entityCount{0}; |
| 127 |
int64_t nodesPerEntity{0}; |
| 128 |
int64_t attributeCount{0}; |
| 129 |
int64_t procOffset{0}; |
| 130 |
|
| 131 |
private: |
| 132 |
}; |
| 133 |
|
| 134 |
struct IOEX_EXPORT FaceBlock |
| 135 |
{ |
| 136 |
FaceBlock() { Ioss::Utils::copy_string(elType, ""); } |
| 137 |
|
| 138 |
FaceBlock(const FaceBlock &other) |
| 139 |
: name(other.name), id(other.id), entityCount(other.entityCount), |
| 140 |
nodesPerEntity(other.nodesPerEntity), edgesPerEntity(other.edgesPerEntity), |
| 141 |
attributeCount(other.attributeCount), procOffset(other.procOffset) |
| 142 |
{ |
| 143 |
Ioss::Utils::copy_string(elType, other.elType); |
| 144 |
} |
| 145 |
|
| 146 |
explicit FaceBlock(const Ioss::FaceBlock &other); |
| 147 |
|
| 148 |
char elType[MAX_STR_LENGTH + 1]{}; |
| 149 |
std::string name{}; |
| 150 |
entity_id id{0}; |
| 151 |
int64_t entityCount{0}; |
| 152 |
int64_t nodesPerEntity{0}; |
| 153 |
int64_t edgesPerEntity{0}; |
| 154 |
int64_t attributeCount{0}; |
| 155 |
int64_t procOffset{0}; |
| 156 |
|
| 157 |
private: |
| 158 |
}; |
| 159 |
|
| 160 |
struct IOEX_EXPORT ElemBlock |
| 161 |
{ |
| 162 |
ElemBlock() { Ioss::Utils::copy_string(elType, ""); } |
| 163 |
|
| 164 |
ElemBlock(const ElemBlock &other) |
| 165 |
: name(other.name), id(other.id), entityCount(other.entityCount), |
| 166 |
globalEntityCount(other.globalEntityCount), nodesPerEntity(other.nodesPerEntity), |
| 167 |
edgesPerEntity(other.edgesPerEntity), facesPerEntity(other.facesPerEntity), |
| 168 |
attributeCount(other.attributeCount), offset_(other.offset_), procOffset(other.procOffset) |
| 169 |
{ |
| 170 |
Ioss::Utils::copy_string(elType, other.elType); |
| 171 |
} |
| 172 |
|
| 173 |
explicit ElemBlock(const Ioss::ElementBlock &other); |
| 174 |
|
| 175 |
char elType[MAX_STR_LENGTH + 1]{}; |
| 176 |
std::string name{}; |
| 177 |
entity_id id{0}; |
| 178 |
int64_t entityCount{0}; |
| 179 |
int64_t globalEntityCount{0}; |
| 180 |
int64_t nodesPerEntity{0}; |
| 181 |
int64_t edgesPerEntity{0}; |
| 182 |
int64_t facesPerEntity{0}; |
| 183 |
int64_t attributeCount{0}; |
| 184 |
int64_t offset_{-1}; |
| 185 |
int64_t procOffset{0}; |
| 186 |
}; |
| 187 |
|
| 188 |
struct IOEX_EXPORT NodeSet |
| 189 |
{ |
| 190 |
explicit NodeSet(const Ioss::NodeSet &other); |
| 191 |
|
| 192 |
std::string name{}; |
| 193 |
entity_id id{0}; |
| 194 |
int64_t entityCount{0}; |
| 195 |
int64_t globalEntityCount{0}; |
| 196 |
int64_t localOwnedCount{0}; |
| 197 |
int64_t attributeCount{0}; |
| 198 |
int64_t dfCount{0}; |
| 199 |
int64_t procOffset{0}; |
| 200 |
}; |
| 201 |
|
| 202 |
struct IOEX_EXPORT EdgeSet |
| 203 |
{ |
| 204 |
explicit EdgeSet(const Ioss::EdgeSet &other); |
| 205 |
|
| 206 |
std::string name{}; |
| 207 |
entity_id id{0}; |
| 208 |
int64_t entityCount{0}; |
| 209 |
int64_t attributeCount{0}; |
| 210 |
int64_t dfCount{0}; |
| 211 |
int64_t procOffset{0}; |
| 212 |
}; |
| 213 |
|
| 214 |
struct IOEX_EXPORT FaceSet |
| 215 |
{ |
| 216 |
explicit FaceSet(const Ioss::FaceSet &other); |
| 217 |
|
| 218 |
std::string name{}; |
| 219 |
entity_id id{0}; |
| 220 |
int64_t entityCount{0}; |
| 221 |
int64_t attributeCount{0}; |
| 222 |
int64_t dfCount{0}; |
| 223 |
int64_t procOffset{0}; |
| 224 |
}; |
| 225 |
|
| 226 |
struct IOEX_EXPORT ElemSet |
| 227 |
{ |
| 228 |
explicit ElemSet(const Ioss::ElementSet &other); |
| 229 |
|
| 230 |
std::string name{}; |
| 231 |
entity_id id{0}; |
| 232 |
int64_t entityCount{0}; |
| 233 |
int64_t attributeCount{0}; |
| 234 |
int64_t dfCount{0}; |
| 235 |
int64_t procOffset{0}; |
| 236 |
}; |
| 237 |
|
| 238 |
struct IOEX_EXPORT SideSet |
| 239 |
{ |
| 240 |
explicit SideSet(const Ioss::SideBlock &other); |
| 241 |
explicit SideSet(const Ioss::SideSet &other); |
| 242 |
|
| 243 |
std::string name{}; |
| 244 |
entity_id id{0}; |
| 245 |
int64_t entityCount{0}; |
| 246 |
int64_t globalEntityCount{0}; |
| 247 |
int64_t dfCount{0}; |
| 248 |
int64_t procOffset{0}; |
| 249 |
int64_t dfProcOffset{0}; |
| 250 |
}; |
| 251 |
|
| 252 |
struct IOEX_EXPORT CommunicationMap |
| 253 |
{ |
| 254 |
CommunicationMap(entity_id the_id, int64_t count, char the_type) |
| 255 |
: id(the_id), entityCount(count), type(the_type) |
| 256 |
{ |
| 257 |
} |
| 258 |
entity_id id{0}; |
| 259 |
int64_t entityCount{0}; |
| 260 |
char type{'U'}; // 'n' for node, 'e' for element |
| 261 |
}; |
| 262 |
|
| 263 |
struct IOEX_EXPORT CommunicationMetaData |
| 264 |
{ |
| 265 |
std::vector<CommunicationMap> nodeMap{}; |
| 266 |
std::vector<CommunicationMap> elementMap{}; |
| 267 |
int processorId{0}; |
| 268 |
int processorCount{0}; |
| 269 |
int64_t globalNodes{0}; |
| 270 |
int64_t globalElements{0}; |
| 271 |
int64_t globalElementBlocks{0}; |
| 272 |
int64_t globalNodeSets{0}; |
| 273 |
int64_t globalSideSets{0}; |
| 274 |
int64_t nodesInternal{0}; |
| 275 |
int64_t nodesBorder{0}; |
| 276 |
int64_t nodesExternal{0}; |
| 277 |
int64_t elementsInternal{0}; |
| 278 |
int64_t elementsBorder{0}; |
| 279 |
bool outputNemesis{false}; |
| 280 |
}; |
| 281 |
|
| 282 |
class IOEX_EXPORT Redefine |
| 283 |
{ |
| 284 |
public: |
| 285 |
explicit Redefine(int exoid); |
| 286 |
Redefine(const Redefine &from) = delete; |
| 287 |
Redefine &operator=(const Redefine &from) = delete; |
| 288 |
~Redefine(); |
| 289 |
|
| 290 |
private: |
| 291 |
int exodusFilePtr; |
| 292 |
}; |
| 293 |
|
| 294 |
class IOEX_EXPORT Mesh |
| 295 |
{ |
| 296 |
public: |
| 297 |
Mesh(int dim, const char *the_title, const Ioss::ParallelUtils &util, bool file_pp) |
| 298 |
: dimensionality(dim), file_per_processor(file_pp), parallelUtil(util) |
| 299 |
{ |
| 300 |
Ioss::Utils::copy_string(title, the_title); |
| 301 |
} |
| 302 |
|
| 303 |
void populate(Ioss::Region *region); |
| 304 |
void get_global_counts(); |
| 305 |
|
| 306 |
char title[MAX_LINE_LENGTH + 1]{}; |
| 307 |
int dimensionality{}; |
| 308 |
bool file_per_processor{true}; |
| 309 |
bool use_node_map{true}; |
| 310 |
bool use_elem_map{true}; |
| 311 |
bool use_face_map{true}; |
| 312 |
bool use_edge_map{true}; |
| 313 |
bool full_nemesis_data{true}; |
| 314 |
|
| 315 |
std::vector<Assembly> assemblies{}; |
| 316 |
std::vector<Blob> blobs{}; |
| 317 |
|
| 318 |
std::vector<NodeBlock> nodeblocks{}; |
| 319 |
std::vector<EdgeBlock> edgeblocks{}; |
| 320 |
std::vector<FaceBlock> faceblocks{}; |
| 321 |
std::vector<ElemBlock> elemblocks{}; |
| 322 |
std::vector<NodeSet> nodesets{}; |
| 323 |
std::vector<EdgeSet> edgesets{}; |
| 324 |
std::vector<FaceSet> facesets{}; |
| 325 |
std::vector<ElemSet> elemsets{}; |
| 326 |
std::vector<SideSet> sidesets{}; |
| 327 |
CommunicationMetaData comm{}; |
| 328 |
Ioss::ParallelUtils parallelUtil; |
| 329 |
}; |
| 330 |
|
| 331 |
class IOEX_EXPORT Internals |
| 332 |
{ |
| 333 |
public: |
| 334 |
Internals(int exoid, int maximum_name_length, const Ioss::ParallelUtils &util); |
| 335 |
Internals(const Internals &from) = delete; |
| 336 |
Internals &operator=(const Internals &from) = delete; |
| 337 |
|
| 338 |
int initialize_state_file(Mesh &mesh, const ex_var_params &var_params, |
| 339 |
const std::string &base_filename); |
| 340 |
|
| 341 |
int write_meta_data(Mesh &mesh); |
| 342 |
|
| 343 |
/* Special use for updating assembly data in-place in existing db file */ |
| 344 |
/* See src/main/io_assembly.C for current use */ |
| 345 |
static void update_assembly_data(int exoid, std::vector<Assembly> &assemblies, int stage = 0); |
| 346 |
|
| 347 |
// Simple wrapper around `ex_copy`, but keeps users from including `exodusII.h` |
| 348 |
static void copy_database(int in_file, int out_file, bool transient_also = true); |
| 349 |
|
| 350 |
private: |
| 351 |
int put_metadata(const Mesh &mesh, const CommunicationMetaData &comm); |
| 352 |
int put_metadata(const std::vector<Assembly> &assemblies); |
| 353 |
int put_metadata(const std::vector<Blob> &blobs); |
| 354 |
int put_metadata(const std::vector<NodeBlock> &nodeblocks, bool count_only = false); |
| 355 |
int put_metadata(const std::vector<EdgeBlock> &blocks, bool count_only = false); |
| 356 |
int put_metadata(const std::vector<FaceBlock> &blocks, bool count_only = false); |
| 357 |
int put_metadata(const std::vector<ElemBlock> &blocks, bool count_only = false); |
| 358 |
|
| 359 |
int put_metadata(const std::vector<NodeSet> &nodesets, bool count_only = false); |
| 360 |
int put_metadata(const std::vector<EdgeSet> &edgesets, bool count_only = false); |
| 361 |
int put_metadata(const std::vector<FaceSet> &facesets, bool count_only = false); |
| 362 |
int put_metadata(const std::vector<ElemSet> &elemsets, bool count_only = false); |
| 363 |
|
| 364 |
int put_metadata(const std::vector<SideSet> &sidesets, bool count_only = false); |
| 365 |
|
| 366 |
int put_non_define_data(const CommunicationMetaData &comm, bool minimal_nemesis_data); |
| 367 |
int put_non_define_data(const std::vector<Assembly> &assemblies); |
| 368 |
int put_non_define_data(const std::vector<Blob> &blobs); |
| 369 |
int put_non_define_data(const std::vector<NodeBlock> &nodeblocks); |
| 370 |
int put_non_define_data(const std::vector<EdgeBlock> &blocks); |
| 371 |
int put_non_define_data(const std::vector<FaceBlock> &blocks); |
| 372 |
int put_non_define_data(const std::vector<ElemBlock> &blocks, bool output_global_data); |
| 373 |
|
| 374 |
int put_non_define_data(const std::vector<NodeSet> &nodesets, bool output_global_data); |
| 375 |
int put_non_define_data(const std::vector<EdgeSet> &edgesets); |
| 376 |
int put_non_define_data(const std::vector<FaceSet> &facesets); |
| 377 |
int put_non_define_data(const std::vector<ElemSet> &elemsets); |
| 378 |
|
| 379 |
int put_non_define_data(const std::vector<SideSet> &sidesets, bool output_global_data); |
| 380 |
|
| 381 |
int max_name_length() const { return maximumNameLength; } |
| 382 |
|
| 383 |
int exodusFilePtr{0}; |
| 384 |
int nodeMapVarID[3]{}; |
| 385 |
int elementMapVarID[2]{}; |
| 386 |
int commIndexVar{0}; |
| 387 |
int elemCommIndexVar{0}; |
| 388 |
int maximumNameLength{32}; |
| 389 |
Ioss::ParallelUtils parallelUtil; |
| 390 |
}; |
| 391 |
} // namespace Ioex |