| 1 |
// Copyright(C) 1999-2024 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 |
#pragma once |
| 8 |
|
| 9 |
#include "Ioss_CoordinateFrame.h" // for CoordinateFrame |
| 10 |
#include "Ioss_DBUsage.h" |
| 11 |
#include "Ioss_DatabaseIO.h" // for DatabaseIO |
| 12 |
#include "Ioss_DynamicTopology.h" |
| 13 |
#include "Ioss_DynamicTopologyObserver.h" |
| 14 |
#include "Ioss_EntityType.h" // for EntityType, etc |
| 15 |
#include "Ioss_Field.h" |
| 16 |
#include "Ioss_GroupingEntity.h" // for GroupingEntity |
| 17 |
#include "Ioss_MeshType.h" |
| 18 |
#include "Ioss_Property.h" // for Property |
| 19 |
#include "Ioss_State.h" // for State |
| 20 |
#include <assert.h> |
| 21 |
#include <cstddef> // for size_t, nullptr |
| 22 |
#include <cstdint> // for int64_t |
| 23 |
|
| 24 |
#include "Ioss_CodeTypes.h" |
| 25 |
#include "Ioss_Utils.h" |
| 26 |
#include "Ioss_VariableType.h" |
| 27 |
#include "ioss_export.h" |
| 28 |
#include <functional> // for less |
| 29 |
#include <iosfwd> // for ostream |
| 30 |
#include <map> // for map, map<>::value_compare |
| 31 |
#include <memory> |
| 32 |
#include <sstream> |
| 33 |
#include <string> // for string, operator< |
| 34 |
#include <tuple> |
| 35 |
#include <utility> // for pair |
| 36 |
#include <vector> // for vector |
| 37 |
|
| 38 |
namespace Ioss { |
| 39 |
class Assembly; |
| 40 |
class Blob; |
| 41 |
class CommSet; |
| 42 |
class EdgeBlock; |
| 43 |
class EdgeSet; |
| 44 |
class ElementBlock; |
| 45 |
class ElementSet; |
| 46 |
class FaceBlock; |
| 47 |
class FaceSet; |
| 48 |
class Field; |
| 49 |
class NodeBlock; |
| 50 |
class NodeSet; |
| 51 |
class SideBlock; |
| 52 |
class SideSet; |
| 53 |
class StructuredBlock; |
| 54 |
} // namespace Ioss |
| 55 |
// Needed for node_global_to_local inline function. |
| 56 |
|
| 57 |
namespace Ioss { |
| 58 |
|
| 59 |
class CoordinateFrame; |
| 60 |
|
| 61 |
enum class MeshType; |
| 62 |
|
| 63 |
using AssemblyContainer = std::vector<Ioss::Assembly *>; |
| 64 |
using BlobContainer = std::vector<Ioss::Blob *>; |
| 65 |
|
| 66 |
using NodeBlockContainer = std::vector<NodeBlock *>; |
| 67 |
using EdgeBlockContainer = std::vector<EdgeBlock *>; |
| 68 |
using FaceBlockContainer = std::vector<FaceBlock *>; |
| 69 |
using ElementBlockContainer = std::vector<ElementBlock *>; |
| 70 |
|
| 71 |
using NodeSetContainer = std::vector<NodeSet *>; |
| 72 |
using EdgeSetContainer = std::vector<EdgeSet *>; |
| 73 |
using FaceSetContainer = std::vector<FaceSet *>; |
| 74 |
using ElementSetContainer = std::vector<ElementSet *>; |
| 75 |
|
| 76 |
using SideSetContainer = std::vector<SideSet *>; |
| 77 |
using StructuredBlockContainer = std::vector<StructuredBlock *>; |
| 78 |
using CommSetContainer = std::vector<CommSet *>; |
| 79 |
using StateTimeContainer = std::vector<double>; |
| 80 |
|
| 81 |
using CoordinateFrameContainer = std::vector<CoordinateFrame>; |
| 82 |
|
| 83 |
using AliasMap = std::map<std::string, std::string, std::less<>>; |
| 84 |
|
| 85 |
/** \brief A grouping entity that contains other grouping entities. |
| 86 |
* |
| 87 |
* Maintains a list of NodeBlocks, ElementBlocks, NodeLists, CommLists and Surfaces. |
| 88 |
* [Similar to the "Composite Pattern" in Design Patterns] All interface to |
| 89 |
* GroupingEntities is through the Region class; clients of the IO subsystem have no direct |
| 90 |
* access to the underlying GroupingEntities (other than the Region). |
| 91 |
*/ |
| 92 |
class IOSS_EXPORT Region : public GroupingEntity |
| 93 |
{ |
| 94 |
public: |
| 95 |
explicit Region(DatabaseIO *iodatabase = nullptr, const std::string &my_name = ""); |
| 96 |
|
| 97 |
~Region() override; |
| 98 |
|
| 99 |
IOSS_NODISCARD std::string type_string() const override { return "Region"; } |
| 100 |
IOSS_NODISCARD std::string short_type_string() const override { return "region"; } |
| 101 |
IOSS_NODISCARD std::string contains_string() const override { return "Entities"; } |
| 102 |
IOSS_NODISCARD EntityType type() const override { return REGION; } |
| 103 |
|
| 104 |
IOSS_NODISCARD MeshType mesh_type() const; |
| 105 |
IOSS_NODISCARD std::string mesh_type_string() const; |
| 106 |
IOSS_NODISCARD bool node_major() const; |
| 107 |
|
| 108 |
void output_summary(std::ostream &strm, bool do_transient = true) const; |
| 109 |
|
| 110 |
IOSS_NODISCARD bool supports_field_type(Ioss::EntityType fld_type) const; |
| 111 |
|
| 112 |
// Helper function... |
| 113 |
IOSS_NODISCARD int64_t node_global_to_local(int64_t global, bool must_exist = true) const; |
| 114 |
|
| 115 |
bool begin_mode(State new_state); |
| 116 |
bool end_mode(State current_state); |
| 117 |
|
| 118 |
// Add a new state at this time, return state number |
| 119 |
virtual int add_state(double time) |
| 120 |
{ |
| 121 |
IOSS_FUNC_ENTER(m_); |
| 122 |
return add_state_nl(time); |
| 123 |
} |
| 124 |
virtual int add_state_nl(double time); |
| 125 |
|
| 126 |
// Get time corresponding to specified state |
| 127 |
|
| 128 |
IOSS_NODISCARD virtual double get_state_time(int state = -1) const; |
| 129 |
IOSS_NODISCARD int get_current_state() const; |
| 130 |
double begin_state(int state); |
| 131 |
double end_state(int state); |
| 132 |
|
| 133 |
/** \brief Determine whether the metadata defining the model (nontransient, |
| 134 |
* geometry, and toploloty) has been set. |
| 135 |
* |
| 136 |
* \returns True if the metadata defining the model has been set. |
| 137 |
*/ |
| 138 |
IOSS_NODISCARD bool model_defined() const { return modelDefined; } |
| 139 |
|
| 140 |
/** \brief Determine whether the metadata related to the transient |
| 141 |
* data has been set. |
| 142 |
* |
| 143 |
* \returns True if the metadata related to the transient data has been set. |
| 144 |
*/ |
| 145 |
IOSS_NODISCARD bool transient_defined() const { return transientDefined; } |
| 146 |
|
| 147 |
/** \brief Remove all fields of the specified `role` from all entities in the region |
| 148 |
*/ |
| 149 |
void erase_fields(Field::RoleType role); |
| 150 |
|
| 151 |
// Return a pair consisting of the step (1-based) corresponding to |
| 152 |
// the maximum time on the database and the corresponding maximum |
| 153 |
// time value. Note that this may not necessarily be the last step |
| 154 |
// on the database if cycle and overlay are being used. |
| 155 |
IOSS_NODISCARD std::pair<int, double> get_max_time() const; |
| 156 |
|
| 157 |
// Return a tuple consisting of the step (1-based) corresponding to |
| 158 |
// the maximum time across all change sets on the database, the corresponding |
| 159 |
// maximum time value and the corresponding set. |
| 160 |
IOSS_NODISCARD std::tuple<std::string, int, double> get_db_max_time() const; |
| 161 |
|
| 162 |
// Return a pair consisting of the step (1-based) corresponding to |
| 163 |
// the minimum time on the database and the corresponding minimum |
| 164 |
// time value. Note that this may not necessarily be the first step |
| 165 |
// on the database if cycle and overlay are being used. |
| 166 |
IOSS_NODISCARD std::pair<int, double> get_min_time() const; |
| 167 |
|
| 168 |
// Return a tuple consisting of the step (1-based) corresponding to |
| 169 |
// the minimum time across all change sets on the database, the corresponding |
| 170 |
// minimum time value and the corresponding set. |
| 171 |
IOSS_NODISCARD std::tuple<std::string, int, double> get_db_min_time() const; |
| 172 |
|
| 173 |
// Functions for an output region... |
| 174 |
bool add(NodeBlock *node_block); |
| 175 |
bool add(EdgeBlock *edge_block); |
| 176 |
bool add(FaceBlock *face_block); |
| 177 |
bool add(ElementBlock *element_block); |
| 178 |
bool add(SideSet *sideset); |
| 179 |
bool add(NodeSet *nodeset); |
| 180 |
bool add(EdgeSet *edgeset); |
| 181 |
bool add(FaceSet *faceset); |
| 182 |
bool add(ElementSet *elementset); |
| 183 |
bool add(CommSet *commset); |
| 184 |
bool add(StructuredBlock *structured_block); |
| 185 |
bool add(Assembly *assembly); |
| 186 |
bool add(Blob *blob); |
| 187 |
bool add(const CoordinateFrame &frame); |
| 188 |
|
| 189 |
// Special purpose... |
| 190 |
bool remove(Assembly *removal); |
| 191 |
|
| 192 |
IOSS_NODISCARD const NodeBlockContainer &get_node_blocks() const; |
| 193 |
IOSS_NODISCARD const EdgeBlockContainer &get_edge_blocks() const; |
| 194 |
IOSS_NODISCARD const FaceBlockContainer &get_face_blocks() const; |
| 195 |
IOSS_NODISCARD const ElementBlockContainer &get_element_blocks() const; |
| 196 |
IOSS_NODISCARD const SideSetContainer &get_sidesets() const; |
| 197 |
IOSS_NODISCARD const NodeSetContainer &get_nodesets() const; |
| 198 |
IOSS_NODISCARD const EdgeSetContainer &get_edgesets() const; |
| 199 |
IOSS_NODISCARD const FaceSetContainer &get_facesets() const; |
| 200 |
IOSS_NODISCARD const ElementSetContainer &get_elementsets() const; |
| 201 |
IOSS_NODISCARD const CommSetContainer &get_commsets() const; |
| 202 |
IOSS_NODISCARD const StructuredBlockContainer &get_structured_blocks() const; |
| 203 |
IOSS_NODISCARD const AssemblyContainer &get_assemblies() const; |
| 204 |
IOSS_NODISCARD const BlobContainer &get_blobs() const; |
| 205 |
IOSS_NODISCARD const CoordinateFrameContainer &get_coordinate_frames() const; |
| 206 |
|
| 207 |
// Retrieve the Grouping Entity with the specified name. |
| 208 |
// Returns nullptr if the entity does not exist |
| 209 |
IOSS_NODISCARD GroupingEntity *get_entity(const std::string &my_name, EntityType io_type) const; |
| 210 |
IOSS_NODISCARD GroupingEntity *get_entity(const std::string &my_name) const; |
| 211 |
IOSS_NODISCARD NodeBlock *get_node_block(const std::string &my_name) const; |
| 212 |
IOSS_NODISCARD EdgeBlock *get_edge_block(const std::string &my_name) const; |
| 213 |
IOSS_NODISCARD FaceBlock *get_face_block(const std::string &my_name) const; |
| 214 |
IOSS_NODISCARD ElementBlock *get_element_block(const std::string &my_name) const; |
| 215 |
IOSS_NODISCARD SideSet *get_sideset(const std::string &my_name) const; |
| 216 |
IOSS_NODISCARD SideBlock *get_sideblock(const std::string &my_name) const; |
| 217 |
IOSS_NODISCARD NodeSet *get_nodeset(const std::string &my_name) const; |
| 218 |
IOSS_NODISCARD EdgeSet *get_edgeset(const std::string &my_name) const; |
| 219 |
IOSS_NODISCARD FaceSet *get_faceset(const std::string &my_name) const; |
| 220 |
IOSS_NODISCARD ElementSet *get_elementset(const std::string &my_name) const; |
| 221 |
IOSS_NODISCARD CommSet *get_commset(const std::string &my_name) const; |
| 222 |
IOSS_NODISCARD StructuredBlock *get_structured_block(const std::string &my_name) const; |
| 223 |
IOSS_NODISCARD Assembly *get_assembly(const std::string &my_name) const; |
| 224 |
IOSS_NODISCARD Blob *get_blob(const std::string &my_name) const; |
| 225 |
|
| 226 |
// Not guaranteed to be efficient... |
| 227 |
// Note that not all GroupingEntity's are guaranteed to have an 'id'... |
| 228 |
IOSS_NODISCARD GroupingEntity *get_entity(int64_t id, EntityType io_type) const; |
| 229 |
|
| 230 |
IOSS_NODISCARD const CoordinateFrame &get_coordinate_frame(int64_t id) const; |
| 231 |
|
| 232 |
// Add the name 'alias' as an alias for the database entity of |
| 233 |
// type 'type' with the name 'db_name'. Returns true if alias |
| 234 |
// added; false if problems adding alias. |
| 235 |
bool add_alias(const std::string &db_name, const std::string &alias, EntityType type); |
| 236 |
bool add_alias(const std::string &db_name, const std::string &alias); |
| 237 |
bool add_alias(const GroupingEntity *ge); |
| 238 |
IOSS_NODISCARD std::string get_alias(const std::string &alias, EntityType type) const; |
| 239 |
IOSS_NODISCARD std::string get_alias_nl(const std::string &alias, |
| 240 |
EntityType type) const; // Not locked by mutex |
| 241 |
|
| 242 |
IOSS_NODISCARD const AliasMap &get_alias_map(EntityType entity_type) const; |
| 243 |
|
| 244 |
/// Get a map containing all aliases defined for the entity with basename 'my_name' |
| 245 |
int get_aliases(const std::string &my_name, EntityType type, Ioss::NameList &aliases) const; |
| 246 |
|
| 247 |
// This routine transfers all relevant aliases from the 'this' |
| 248 |
// region and applies them to the 'to' file. |
| 249 |
void transfer_mesh_aliases(Region *to) const; |
| 250 |
|
| 251 |
// Ensure that the 'this' region has the same ids and names as the 'from' region. |
| 252 |
void synchronize_id_and_name(const Region *from, bool sync_attribute_field_names = false); |
| 253 |
|
| 254 |
// Returns true if the passed in name refers to a known Entity |
| 255 |
// defined on this region. If true, then 'type' (if non-nullptr) is |
| 256 |
// filled in with the type of the entity; if false, then type (if |
| 257 |
// non-nullptr) is set to 'INVALID' This function is defined to |
| 258 |
// consolidate several distinct implementations of this code in |
| 259 |
// client code. Because of this, the 'type' used in the client |
| 260 |
// code is repeated here instead of something more generic. |
| 261 |
IOSS_NODISCARD bool is_valid_io_entity(const std::string &my_name, unsigned int io_type, |
| 262 |
std::string *my_type = nullptr) const; |
| 263 |
|
| 264 |
void check_for_duplicate_names(const Ioss::GroupingEntity *entity) const; |
| 265 |
|
| 266 |
// Retrieve the element block that contains the specified element |
| 267 |
// The 'local_id' is the local database id (1-based), not the global id. |
| 268 |
// returns nullptr if no element block contains this element (local_id <= 0 |
| 269 |
// or greater than number of elements in database) |
| 270 |
IOSS_NODISCARD ElementBlock *get_element_block(size_t local_id) const; |
| 271 |
|
| 272 |
// Retrieve the structured block that contains the specified node |
| 273 |
// The 'global_offset' is the global offset (0-based) |
| 274 |
// returns nullptr if no structured block contains this node (local_id <= 0 |
| 275 |
// or greater than number of cell-nodes in database) |
| 276 |
IOSS_NODISCARD StructuredBlock *get_structured_block(size_t global_offset) const; |
| 277 |
|
| 278 |
// Handle implicit properties -- These are calculated from data stored |
| 279 |
// in the grouping entity instead of having an explicit value assigned. |
| 280 |
// An example would be 'element_block_count' for a region. |
| 281 |
IOSS_NODISCARD Property get_implicit_property(const std::string &my_name) const override; |
| 282 |
|
| 283 |
IOSS_NODISCARD const Ioss::NameList &get_information_records() const; |
| 284 |
void add_information_records(const Ioss::NameList &info); |
| 285 |
void add_information_record(const std::string &info); |
| 286 |
|
| 287 |
IOSS_NODISCARD const Ioss::NameList &get_qa_records() const; |
| 288 |
void add_qa_record(const std::string &code, const std::string &code_qa, |
| 289 |
const std::string &date = "", const std::string &time = ""); |
| 290 |
|
| 291 |
template <typename T, typename U> |
| 292 |
std::vector<size_t> get_entity_field_data(const std::string &field_name, |
| 293 |
const std::vector<T *> &entity_container, |
| 294 |
std::vector<U> &field_data) const; |
| 295 |
|
| 296 |
void register_mesh_modification_observer(std::shared_ptr<DynamicTopologyObserver> observer); |
| 297 |
IOSS_NODISCARD std::shared_ptr<DynamicTopologyObserver> get_mesh_modification_observer() const |
| 298 |
{ |
| 299 |
return topologyObserver; |
| 300 |
} |
| 301 |
|
| 302 |
void reset_topology_modification(); |
| 303 |
void set_topology_modification(unsigned int type); |
| 304 |
IOSS_NODISCARD unsigned int get_topology_modification() const; |
| 305 |
|
| 306 |
void start_new_output_database_entry(int steps = 0); |
| 307 |
|
| 308 |
void set_topology_change_count(unsigned int new_count) { dbChangeCount = new_count; } |
| 309 |
IOSS_NODISCARD unsigned int get_topology_change_count() const { return dbChangeCount; } |
| 310 |
|
| 311 |
void set_file_cyclic_count(unsigned int new_count) { fileCyclicCount = new_count; } |
| 312 |
IOSS_NODISCARD unsigned int get_file_cyclic_count() const { return fileCyclicCount; } |
| 313 |
|
| 314 |
void set_if_database_exists_behavior(IfDatabaseExistsBehavior if_exists) |
| 315 |
{ |
| 316 |
ifDatabaseExists = if_exists; |
| 317 |
} |
| 318 |
IOSS_NODISCARD IfDatabaseExistsBehavior get_if_database_exists_behavior() const |
| 319 |
{ |
| 320 |
return ifDatabaseExists; |
| 321 |
} |
| 322 |
|
| 323 |
IOSS_NODISCARD bool model_is_written() const { return modelWritten; } |
| 324 |
IOSS_NODISCARD bool transient_is_written() const { return transientWritten; } |
| 325 |
|
| 326 |
IOSS_NODISCARD bool load_internal_change_set_mesh(const std::string &set_name); |
| 327 |
IOSS_NODISCARD bool load_internal_change_set_mesh(const int set_index); |
| 328 |
|
| 329 |
IOSS_NODISCARD std::tuple<std::string, int, double> locate_db_state(double targetTime) const; |
| 330 |
|
| 331 |
// Reinitialize region data structures |
| 332 |
void reset_region(); |
| 333 |
|
| 334 |
protected: |
| 335 |
std::string get_internal_change_set_name() const; |
| 336 |
void update_dynamic_topology(); |
| 337 |
void clone_and_replace_output_database(int steps = 0); |
| 338 |
void add_output_database_change_set(int steps = 0, bool force_addition = false); |
| 339 |
|
| 340 |
int64_t internal_get_field_data(const Field &field, void *data, |
| 341 |
size_t data_size = 0) const override; |
| 342 |
|
| 343 |
int64_t internal_put_field_data(const Field &field, void *data, |
| 344 |
size_t data_size = 0) const override; |
| 345 |
|
| 346 |
int64_t internal_get_zc_field_data(const Field &field, void **data, |
| 347 |
size_t *data_size) const override; |
| 348 |
|
| 349 |
private: |
| 350 |
template <typename T> |
| 351 |
std::vector<size_t> internal_get_entity_field_data(const std::string &field_name, |
| 352 |
const std::vector<T *> &entity_container, |
| 353 |
void *data, size_t data_size = 0) const; |
| 354 |
|
| 355 |
// Add the name 'alias' as an alias for the database entity with the |
| 356 |
// name 'db_name'. Returns true if alias added; false if problems |
| 357 |
// adding alias. Not protected by mutex -- call internally only. |
| 358 |
bool add_alias_nl(const std::string &db_name, const std::string &alias, EntityType type); |
| 359 |
bool add_alias_nl(const GroupingEntity *ge); |
| 360 |
|
| 361 |
bool begin_mode_nl(State new_state); |
| 362 |
bool end_mode_nl(State current_state); |
| 363 |
|
| 364 |
void delete_database() override; |
| 365 |
|
| 366 |
mutable std::map<EntityType, AliasMap> aliases_; ///< Stores alias mappings |
| 367 |
|
| 368 |
// Containers for all grouping entities |
| 369 |
NodeBlockContainer nodeBlocks; |
| 370 |
EdgeBlockContainer edgeBlocks; |
| 371 |
FaceBlockContainer faceBlocks; |
| 372 |
ElementBlockContainer elementBlocks; |
| 373 |
|
| 374 |
NodeSetContainer nodeSets; |
| 375 |
EdgeSetContainer edgeSets; |
| 376 |
FaceSetContainer faceSets; |
| 377 |
ElementSetContainer elementSets; |
| 378 |
|
| 379 |
SideSetContainer sideSets; |
| 380 |
CommSetContainer commSets; |
| 381 |
CoordinateFrameContainer coordinateFrames; |
| 382 |
StructuredBlockContainer structuredBlocks; |
| 383 |
AssemblyContainer assemblies; |
| 384 |
BlobContainer blobs; |
| 385 |
mutable StateTimeContainer stateTimes; |
| 386 |
|
| 387 |
int currentState{-1}; |
| 388 |
mutable int stateCount{0}; |
| 389 |
bool modelDefined{false}; |
| 390 |
bool transientDefined{false}; |
| 391 |
|
| 392 |
std::shared_ptr<DynamicTopologyObserver> topologyObserver; |
| 393 |
|
| 394 |
unsigned int dbChangeCount{1}; //!< Used to track number of topology changes. |
| 395 |
unsigned int fileCyclicCount{ |
| 396 |
0}; //!< For cycling file-A, file-B, file-C, ..., File-A, typically restart only. |
| 397 |
IfDatabaseExistsBehavior ifDatabaseExists{DB_OVERWRITE}; |
| 398 |
|
| 399 |
bool modelWritten{false}; |
| 400 |
bool transientWritten{false}; |
| 401 |
bool fileGroupsStarted{false}; |
| 402 |
}; |
| 403 |
} // namespace Ioss |
| 404 |
|
| 405 |
/** \brief Get the index (1-based) of the currently-active state. |
| 406 |
* |
| 407 |
* \returns The index. |
| 408 |
*/ |
| 409 |
inline int Ioss::Region::get_current_state() const { return currentState; } |
| 410 |
|
| 411 |
inline bool Ioss::Region::supports_field_type(Ioss::EntityType fld_type) const |
| 412 |
{ |
| 413 |
return static_cast<unsigned int>((get_database()->entity_field_support() & fld_type) != 0U) != 0U; |
| 414 |
} |
| 415 |
|
| 416 |
inline int64_t Ioss::Region::node_global_to_local(int64_t global, bool must_exist) const |
| 417 |
{ |
| 418 |
return get_database()->node_global_to_local(global, must_exist); |
| 419 |
} |
| 420 |
|
| 421 |
/** \brief Get all information records (informative strings) for the region's database. |
| 422 |
* |
| 423 |
* \returns The informative strings. |
| 424 |
*/ |
| 425 |
inline const Ioss::NameList &Ioss::Region::get_information_records() const |
| 426 |
{ |
| 427 |
IOSS_FUNC_ENTER(m_); |
| 428 |
return get_database()->get_information_records(); |
| 429 |
} |
| 430 |
|
| 431 |
/** \brief Add multiple information records (informative strings) to the region's database. |
| 432 |
* |
| 433 |
* \param[in] info The strings to add. |
| 434 |
*/ |
| 435 |
inline void Ioss::Region::add_information_records(const Ioss::NameList &info) |
| 436 |
{ |
| 437 |
IOSS_FUNC_ENTER(m_); |
| 438 |
return get_database()->add_information_records(info); |
| 439 |
} |
| 440 |
|
| 441 |
/** \brief Add an information record (an informative string) to the region's database. |
| 442 |
* |
| 443 |
* \param[in] info The string to add. |
| 444 |
*/ |
| 445 |
inline void Ioss::Region::add_information_record(const std::string &info) |
| 446 |
{ |
| 447 |
IOSS_FUNC_ENTER(m_); |
| 448 |
return get_database()->add_information_record(info); |
| 449 |
} |
| 450 |
|
| 451 |
/** \brief Add a QA record, which consists of 4 strings, to the region's database |
| 452 |
* |
| 453 |
* The 4 function parameters correspond to the 4 QA record strings. |
| 454 |
* |
| 455 |
* \param[in] code A descriptive code name, such as the application that modified the database. |
| 456 |
* \param[in] code_qa A descriptive string, such as the version of the application that modified |
| 457 |
* the database. |
| 458 |
* \param[in] date A relevant date, such as the date the database was modified. |
| 459 |
* \param[in] time A relevant time, such as the time the database was modified. |
| 460 |
*/ |
| 461 |
inline void Ioss::Region::add_qa_record(const std::string &code, const std::string &code_qa, |
| 462 |
const std::string &date, const std::string &time) |
| 463 |
{ |
| 464 |
IOSS_FUNC_ENTER(m_); |
| 465 |
return get_database()->add_qa_record(code, code_qa, date, time); |
| 466 |
} |
| 467 |
|
| 468 |
/** \brief Get all QA records, each of which consists of 4 strings, from the region's database. |
| 469 |
* |
| 470 |
* The 4 strings that make up a database QA record are: |
| 471 |
* |
| 472 |
* 1. A descriptive code name, such as the application that modified the database. |
| 473 |
* |
| 474 |
* 2. A descriptive string, such as the version of the application that modified the database. |
| 475 |
* |
| 476 |
* 3. A relevant date, such as the date the database was modified. |
| 477 |
* |
| 478 |
* 4. A relevant time, such as the time the database was modified. |
| 479 |
* |
| 480 |
* \returns All QA records in a single vector. Every 4 consecutive elements of the |
| 481 |
* vector make up a single QA record. |
| 482 |
*/ |
| 483 |
inline const Ioss::NameList &Ioss::Region::get_qa_records() const |
| 484 |
{ |
| 485 |
IOSS_FUNC_ENTER(m_); |
| 486 |
return get_database()->get_qa_records(); |
| 487 |
} |
| 488 |
|
| 489 |
namespace Ioss { |
| 490 |
|
| 491 |
template <typename T> |
| 492 |
bool verify_field_exists_in_entity_group(const std::string &field_name, |
| 493 |
const std::vector<T *> &entity_container) |
| 494 |
{ |
| 495 |
bool found = false; |
| 496 |
Ioss::Field::RoleType role = Ioss::Field::RoleType::INTERNAL; |
| 497 |
|
| 498 |
for (const T *entity : entity_container) { |
| 499 |
if (entity->field_exists(field_name)) { |
| 500 |
Ioss::Field field = entity->get_field(field_name); |
| 501 |
|
| 502 |
if (found && field.get_role() != role) { |
| 503 |
std::ostringstream errmsg; |
| 504 |
// Would be nice to use fmt:: here, but we need to avoid using fmt includes in public |
| 505 |
// headers... |
| 506 |
errmsg << "ERROR: Field " << field.get_name() << " with role " << field.role_string() |
| 507 |
<< " on entity " << entity->name() << " does not match previously found role " |
| 508 |
<< Ioss::Field::role_string(role) << ".\n"; |
| 509 |
IOSS_ERROR(errmsg); |
| 510 |
} |
| 511 |
|
| 512 |
found = true; |
| 513 |
role = field.get_role(); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
return found; |
| 518 |
} |
| 519 |
|
| 520 |
namespace impl { |
| 521 |
template <typename T> |
| 522 |
size_t get_field_data_count_for_entities(const std::string &field_name, |
| 523 |
const std::vector<T *> &entity_container) |
| 524 |
{ |
| 525 |
size_t count = 0; |
| 526 |
|
| 527 |
for (const T *entity : entity_container) { |
| 528 |
if (entity->field_exists(field_name)) { |
| 529 |
Ioss::Field field = entity->get_field(field_name); |
| 530 |
|
| 531 |
count += entity->entity_count() * field.raw_storage()->component_count(); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
return count; |
| 536 |
} |
| 537 |
} // namespace impl |
| 538 |
} // namespace Ioss |
| 539 |
|
| 540 |
template <typename T, typename U> |
| 541 |
std::vector<size_t> Ioss::Region::get_entity_field_data(const std::string &field_name, |
| 542 |
const std::vector<T *> &entity_container, |
| 543 |
std::vector<U> &field_data) const |
| 544 |
{ |
| 545 |
bool field_exists = verify_field_exists_in_entity_group(field_name, entity_container); |
| 546 |
|
| 547 |
if (!field_exists) { |
| 548 |
return std::vector<size_t>(entity_container.size() + 1, 0); |
| 549 |
} |
| 550 |
|
| 551 |
size_t field_count = impl::get_field_data_count_for_entities(field_name, entity_container); |
| 552 |
|
| 553 |
field_data.resize(field_count); |
| 554 |
size_t data_size = field_count * sizeof(U); |
| 555 |
|
| 556 |
std::vector<size_t> offsets = |
| 557 |
internal_get_entity_field_data(field_name, entity_container, Data(field_data), data_size); |
| 558 |
|
| 559 |
assert(offsets.size() == (entity_container.size() + 1)); |
| 560 |
assert(offsets[entity_container.size()] == field_count); |
| 561 |
|
| 562 |
return offsets; |
| 563 |
} |
| 564 |
|
| 565 |
template <typename T> |
| 566 |
std::vector<size_t> |
| 567 |
Ioss::Region::internal_get_entity_field_data(const std::string &field_name, |
| 568 |
const std::vector<T *> &entity_container, void *data, |
| 569 |
size_t data_size) const |
| 570 |
{ |
| 571 |
return get_database()->get_entity_field_data(field_name, entity_container, data, data_size); |
| 572 |
} |