| 1 |
// ISSUES: |
| 2 |
// 1. Does not handle unconnected nodes (not connected to any element) |
| 3 |
// |
| 4 |
// 2. SideSet distribution factors are klugy and may not fully work in |
| 5 |
// strange cases |
| 6 |
// |
| 7 |
// |
| 8 |
// Copyright(C) 1999-2024 National Technology & Engineering Solutions |
| 9 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 10 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 11 |
// |
| 12 |
// See packages/seacas/LICENSE for details |
| 13 |
|
| 14 |
#include "Ioss_CodeTypes.h" |
| 15 |
#include "exodus/Ioex_ParallelDatabaseIO.h" |
| 16 |
#if defined PARALLEL_AWARE_EXODUS |
| 17 |
#include <algorithm> |
| 18 |
#include <cassert> |
| 19 |
#include <cctype> |
| 20 |
#include <cfloat> |
| 21 |
#include <cstddef> |
| 22 |
#include <cstdlib> |
| 23 |
#include <cstring> |
| 24 |
#include <ctime> |
| 25 |
#include <fmt/ostream.h> |
| 26 |
#include <functional> |
| 27 |
#include <iostream> |
| 28 |
#include <limits> |
| 29 |
#include <map> |
| 30 |
#include <numeric> |
| 31 |
#include <set> |
| 32 |
#include <string> |
| 33 |
#include <tokenize.h> |
| 34 |
#ifndef _MSC_VER |
| 35 |
#include <unistd.h> |
| 36 |
#endif |
| 37 |
#include <utility> |
| 38 |
#include <vector> |
| 39 |
|
| 40 |
#include "exodus/Ioex_DecompositionData.h" |
| 41 |
#include "exodus/Ioex_Internals.h" |
| 42 |
#include "exodus/Ioex_Utils.h" |
| 43 |
#include <exodusII.h> |
| 44 |
|
| 45 |
#include "Ioss_Assembly.h" |
| 46 |
#include "Ioss_Blob.h" |
| 47 |
#include "Ioss_CommSet.h" |
| 48 |
#include "Ioss_CoordinateFrame.h" |
| 49 |
#include "Ioss_DBUsage.h" |
| 50 |
#include "Ioss_DatabaseIO.h" |
| 51 |
#include "Ioss_EdgeBlock.h" |
| 52 |
#include "Ioss_EdgeSet.h" |
| 53 |
#include "Ioss_ElementBlock.h" |
| 54 |
#include "Ioss_ElementSet.h" |
| 55 |
#include "Ioss_ElementTopology.h" |
| 56 |
#include "Ioss_EntityBlock.h" |
| 57 |
#include "Ioss_EntitySet.h" |
| 58 |
#include "Ioss_EntityType.h" |
| 59 |
#include "Ioss_FaceBlock.h" |
| 60 |
#include "Ioss_FaceSet.h" |
| 61 |
#include "Ioss_Field.h" |
| 62 |
#include "Ioss_FileInfo.h" |
| 63 |
#include "Ioss_GroupingEntity.h" |
| 64 |
#include "Ioss_Map.h" |
| 65 |
#include "Ioss_NodeBlock.h" |
| 66 |
#include "Ioss_NodeSet.h" |
| 67 |
#include "Ioss_ParallelUtils.h" |
| 68 |
#include "Ioss_Property.h" |
| 69 |
#include "Ioss_Region.h" |
| 70 |
#include "Ioss_SideBlock.h" |
| 71 |
#include "Ioss_SideSet.h" |
| 72 |
#include "Ioss_State.h" |
| 73 |
#include "Ioss_SurfaceSplit.h" |
| 74 |
#include "Ioss_Utils.h" |
| 75 |
#include "Ioss_VariableType.h" |
| 76 |
|
| 77 |
#include "Ioss_FileInfo.h" |
| 78 |
#undef MPICPP |
| 79 |
|
| 80 |
// ======================================================================== |
| 81 |
// Static internal helper functions |
| 82 |
// ======================================================================== |
| 83 |
namespace { |
| 84 |
const size_t max_line_length = MAX_LINE_LENGTH; |
| 85 |
|
| 86 |
const std::string SEP() { return std::string("@"); } // Separator for attribute offset storage |
| 87 |
const std::array<std::string, 2> complex_suffix{".re", ".im"}; |
| 88 |
|
| 89 |
void check_node_owning_processor_data(const Ioss::IntVector &nop, size_t file_node_count) |
| 90 |
{ |
| 91 |
// Verify that the nop (NodeOwningProcessor) vector is not empty and is of the correct size. |
| 92 |
// This vector specifies which rank owns each node on this rank |
| 93 |
// Throws error if problem, otherwise returns quietly. |
| 94 |
if (file_node_count == 0) { |
| 95 |
return; |
| 96 |
} |
| 97 |
if (nop.empty()) { |
| 98 |
IOSS_ERROR("ERROR: The use of the 'compose' output option requires the definition of " |
| 99 |
"the 'owning_processor'" |
| 100 |
" field prior to the output of nodal data. This field has not yet been " |
| 101 |
"defined so output is not possible." |
| 102 |
" For more information, contact [email protected].\n"); |
| 103 |
} |
| 104 |
else if (nop.size() < file_node_count) { |
| 105 |
IOSS_ERROR(fmt::format( |
| 106 |
"ERROR: The 'owning_processor' data was defined, but it is not the correct size." |
| 107 |
" Its size is {}, but it must be at least this size {}." |
| 108 |
" For more information, contact [email protected].\n", |
| 109 |
nop.size(), file_node_count)); |
| 110 |
} |
| 111 |
} |
| 112 |
void get_connectivity_data(int exoid, void *data, ex_entity_type type, ex_entity_id id, |
| 113 |
int position, int int_size_api) |
| 114 |
{ |
| 115 |
int ierr = 0; |
| 116 |
if (int_size_api == 8) { |
| 117 |
std::array<int64_t *, 3> conn{nullptr, nullptr, nullptr}; |
| 118 |
conn[position] = static_cast<int64_t *>(data); |
| 119 |
assert(1 == 0 && "Unimplemented fixme"); |
| 120 |
ierr = ex_get_conn(exoid, type, id, conn[0], conn[1], conn[2]); // FIXME |
| 121 |
} |
| 122 |
else { |
| 123 |
std::array<int *, 3> conn{nullptr, nullptr, nullptr}; |
| 124 |
conn[position] = static_cast<int *>(data); |
| 125 |
assert(1 == 0 && "Unimplemented fixme"); |
| 126 |
ierr = ex_get_conn(exoid, type, id, conn[0], conn[1], conn[2]); // FIXME |
| 127 |
} |
| 128 |
if (ierr < 0) { |
| 129 |
Ioex::exodus_error(exoid, __LINE__, __func__, __FILE__); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
template <typename T> |
| 134 |
void compute_internal_border_maps(T *entities, T *internal, size_t count, size_t entity_count) |
| 135 |
{ |
| 136 |
for (size_t ij = 0; ij < count; ij++) { |
| 137 |
internal[ij] = 1; |
| 138 |
} |
| 139 |
for (size_t J = 0; J < entity_count; J++) { |
| 140 |
internal[entities[J] - 1] = 0; |
| 141 |
} |
| 142 |
|
| 143 |
size_t b = 0; |
| 144 |
for (size_t ij = 0; ij < count; ij++) { |
| 145 |
if (internal[ij] == 0) { |
| 146 |
entities[b++] = ij + 1; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
size_t k = 0; |
| 151 |
for (size_t ij = 0; ij < count; ij++) { |
| 152 |
if (internal[ij] == 1) { |
| 153 |
internal[k++] = ij + 1; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
template <typename INT> |
| 159 |
void map_nodeset_id_data(const Ioss::IntVector &owning_processor, Ioss::Int64Vector &owned_nodes, |
| 160 |
int this_processor, const INT *ids, size_t ids_size, |
| 161 |
std::vector<INT> &file_data) |
| 162 |
{ |
| 163 |
// Determine which nodes in this nodeset are owned by this processor. |
| 164 |
// Save this mapping in the "owned_nodes" vector for use in |
| 165 |
// mapping nodeset field data (df, transient, attributes, ...) |
| 166 |
for (size_t i = 0; i < ids_size; i++) { |
| 167 |
INT node = ids[i]; |
| 168 |
if (owning_processor[node - 1] == this_processor) { |
| 169 |
file_data.push_back(ids[i]); |
| 170 |
owned_nodes.push_back(i); |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
template <typename T, typename U> |
| 176 |
void map_nodeset_data(Ioss::Int64Vector &owned_nodes, const T *data, std::vector<U> &file_data, |
| 177 |
size_t offset = 0, size_t stride = 1) |
| 178 |
{ |
| 179 |
// Pull out the locally owned nodeset data |
| 180 |
for (auto owned_node : owned_nodes) { |
| 181 |
file_data.push_back(data[stride * owned_node + offset]); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
template <typename T> |
| 186 |
void extract_data(std::vector<double> &local_data, T *data, size_t num_entity, size_t offset, |
| 187 |
size_t comp_count) |
| 188 |
{ |
| 189 |
local_data.resize(num_entity); |
| 190 |
if (comp_count == 1 && offset == 0) { |
| 191 |
for (size_t j = 0; j < num_entity; j++) { |
| 192 |
local_data[j] = data[j]; |
| 193 |
} |
| 194 |
} |
| 195 |
else { |
| 196 |
for (size_t j = 0; j < num_entity; j++) { |
| 197 |
local_data[j] = data[offset]; |
| 198 |
offset += comp_count; |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
// Ideally, there should only be a single data type for in and out |
| 204 |
// data, but in the node id map mapping, we have an int64_t coming |
| 205 |
// in and either an int or int64_t going out... |
| 206 |
template <typename T, typename U> |
| 207 |
void filter_owned_nodes(const Ioss::IntVector &owning_processor, int this_processor, |
| 208 |
const T *data, std::vector<U> &file_data, size_t offset = 0, |
| 209 |
size_t stride = 1) |
| 210 |
{ |
| 211 |
size_t index = offset; |
| 212 |
for (auto op : owning_processor) { |
| 213 |
if (op == this_processor) { |
| 214 |
file_data.push_back(data[index]); |
| 215 |
} |
| 216 |
index += stride; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
// This version can be used *if* the input and output types are the same *and* the |
| 221 |
// input `data` can be modified / overwritten. |
| 222 |
template <typename T> |
| 223 |
void filter_owned_nodes(const Ioss::IntVector &owning_processor, int this_processor, T *data) |
| 224 |
{ |
| 225 |
size_t index = 0; |
| 226 |
size_t entry = 0; |
| 227 |
for (auto op : owning_processor) { |
| 228 |
if (op == this_processor) { |
| 229 |
data[entry++] = data[index]; |
| 230 |
} |
| 231 |
index++; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
template <typename INT> |
| 236 |
void map_local_to_global_implicit(INT *data, size_t count, |
| 237 |
const std::vector<int64_t> &global_implicit_map) |
| 238 |
{ |
| 239 |
for (size_t i = 0; i < count; i++) { |
| 240 |
data[i] = global_implicit_map[data[i] - 1]; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
void update_processor_offset_property(Ioss::Region *region, const Ioex::Mesh &mesh) |
| 245 |
{ |
| 246 |
const Ioss::NodeBlockContainer &node_blocks = region->get_node_blocks(); |
| 247 |
if (!node_blocks.empty()) { |
| 248 |
node_blocks[0]->property_add( |
| 249 |
Ioss::Property("_processor_offset", mesh.nodeblocks[0].procOffset)); |
| 250 |
} |
| 251 |
const Ioss::EdgeBlockContainer &edge_blocks = region->get_edge_blocks(); |
| 252 |
for (size_t i = 0; i < edge_blocks.size(); i++) { |
| 253 |
edge_blocks[i]->property_add( |
| 254 |
Ioss::Property("_processor_offset", mesh.edgeblocks[i].procOffset)); |
| 255 |
} |
| 256 |
const Ioss::FaceBlockContainer &face_blocks = region->get_face_blocks(); |
| 257 |
for (size_t i = 0; i < face_blocks.size(); i++) { |
| 258 |
face_blocks[i]->property_add( |
| 259 |
Ioss::Property("_processor_offset", mesh.faceblocks[i].procOffset)); |
| 260 |
} |
| 261 |
|
| 262 |
int64_t offset = 0; // Offset into global element map... |
| 263 |
const Ioss::ElementBlockContainer &element_blocks = region->get_element_blocks(); |
| 264 |
for (size_t i = 0; i < element_blocks.size(); i++) { |
| 265 |
element_blocks[i]->property_add(Ioss::Property("global_map_offset", offset)); |
| 266 |
offset += mesh.elemblocks[i].entityCount; |
| 267 |
element_blocks[i]->property_add( |
| 268 |
Ioss::Property("_processor_offset", mesh.elemblocks[i].procOffset)); |
| 269 |
} |
| 270 |
|
| 271 |
const Ioss::NodeSetContainer &nodesets = region->get_nodesets(); |
| 272 |
for (size_t i = 0; i < nodesets.size(); i++) { |
| 273 |
nodesets[i]->property_add(Ioss::Property("_processor_offset", mesh.nodesets[i].procOffset)); |
| 274 |
} |
| 275 |
const Ioss::EdgeSetContainer &edgesets = region->get_edgesets(); |
| 276 |
for (size_t i = 0; i < edgesets.size(); i++) { |
| 277 |
edgesets[i]->property_add(Ioss::Property("_processor_offset", mesh.edgesets[i].procOffset)); |
| 278 |
} |
| 279 |
const Ioss::FaceSetContainer &facesets = region->get_facesets(); |
| 280 |
for (size_t i = 0; i < facesets.size(); i++) { |
| 281 |
facesets[i]->property_add(Ioss::Property("_processor_offset", mesh.facesets[i].procOffset)); |
| 282 |
} |
| 283 |
const Ioss::ElementSetContainer &elementsets = region->get_elementsets(); |
| 284 |
for (size_t i = 0; i < facesets.size(); i++) { |
| 285 |
elementsets[i]->property_add( |
| 286 |
Ioss::Property("_processor_offset", mesh.elemsets[i].procOffset)); |
| 287 |
} |
| 288 |
|
| 289 |
const Ioss::SideSetContainer &ssets = region->get_sidesets(); |
| 290 |
for (size_t i = 0; i < ssets.size(); i++) { |
| 291 |
ssets[i]->property_add(Ioss::Property("_processor_offset", mesh.sidesets[i].procOffset)); |
| 292 |
ssets[i]->property_add(Ioss::Property("processor_df_offset", mesh.sidesets[i].dfProcOffset)); |
| 293 |
|
| 294 |
// Propagate down to owned sideblocks... |
| 295 |
const Ioss::SideBlockContainer &side_blocks = ssets[i]->get_side_blocks(); |
| 296 |
for (auto &block : side_blocks) { |
| 297 |
block->property_add(Ioss::Property("_processor_offset", mesh.sidesets[i].procOffset)); |
| 298 |
block->property_add(Ioss::Property("processor_df_offset", mesh.sidesets[i].dfProcOffset)); |
| 299 |
} |
| 300 |
} |
| 301 |
const auto &blobs = region->get_blobs(); |
| 302 |
for (size_t i = 0; i < blobs.size(); i++) { |
| 303 |
blobs[i]->property_add(Ioss::Property("_processor_offset", mesh.blobs[i].procOffset)); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
template <typename T> |
| 308 |
std::vector<int64_t> get_block_to_decomp_map(const std::vector<T *> &entity_container) |
| 309 |
{ |
| 310 |
std::vector<int64_t> block_to_decomp(entity_container.size(), 0); |
| 311 |
|
| 312 |
for (size_t i = 0; i < entity_container.size(); ++i) { |
| 313 |
T *entity = entity_container[i]; |
| 314 |
block_to_decomp[i] = entity->get_property("iblk").get_int(); |
| 315 |
} |
| 316 |
|
| 317 |
return block_to_decomp; |
| 318 |
} |
| 319 |
|
| 320 |
template <typename T> |
| 321 |
std::vector<int> get_entity_field_component_count(const std::string &field_name, |
| 322 |
const std::vector<T *> &entity_container) |
| 323 |
{ |
| 324 |
size_t num_blocks = entity_container.size(); |
| 325 |
|
| 326 |
std::vector<int> block_field_component_count(num_blocks, 0); |
| 327 |
|
| 328 |
for (size_t i = 0; i < num_blocks; ++i) { |
| 329 |
T *entity = entity_container[i]; |
| 330 |
if (entity->field_exists(field_name)) { |
| 331 |
Ioss::Field field = entity->get_field(field_name); |
| 332 |
block_field_component_count[i] = field.raw_storage()->component_count(); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
return block_field_component_count; |
| 337 |
} |
| 338 |
|
| 339 |
template <typename T> |
| 340 |
size_t get_entity_field_data_size(const std::string &field_name, |
| 341 |
const std::vector<T *> &entity_container) |
| 342 |
{ |
| 343 |
size_t total_data_size = 0; |
| 344 |
for (T *entity : entity_container) { |
| 345 |
if (entity->field_exists(field_name)) { |
| 346 |
Ioss::Field field = entity->get_field(field_name); |
| 347 |
total_data_size += entity->entity_count() * field.raw_storage()->component_count() * |
| 348 |
field.get_basic_size(); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
return total_data_size; |
| 353 |
} |
| 354 |
|
| 355 |
void add_processor_id_map(Ioss::Region *region) |
| 356 |
{ |
| 357 |
const auto &blocks = region->get_element_blocks(); |
| 358 |
for (const auto &block : blocks) { |
| 359 |
block->field_add(Ioss::Field("proc_id", block->field_int_type(), "scalar", Ioss::Field::MAP)); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
} // namespace |
| 364 |
|
| 365 |
namespace Ioex { |
| 366 |
ParallelDatabaseIO::ParallelDatabaseIO(Ioss::Region *region, const std::string &filename, |
| 367 |
Ioss::DatabaseUsage db_usage, Ioss_MPI_Comm communicator, |
| 368 |
const Ioss::PropertyManager &props) |
| 369 |
: Ioex::BaseDatabaseIO(region, filename, db_usage, communicator, props) |
| 370 |
{ |
| 371 |
usingParallelIO = true; |
| 372 |
if (!is_parallel_consistent()) { |
| 373 |
IOSS_ERROR("ERROR: Parallel IO cannot be used in an application that is not guaranteeing " |
| 374 |
"parallel consistent calls of the get and put field data functions.\n" |
| 375 |
"The application created this database with a 'false' setting for the " |
| 376 |
"isParallelConsistent property."); |
| 377 |
} |
| 378 |
|
| 379 |
if (!is_input()) { |
| 380 |
// Check whether appending to or modifying existing file... |
| 381 |
if (open_create_behavior() == Ioss::DB_APPEND || |
| 382 |
open_create_behavior() == Ioss::DB_APPEND_GROUP || |
| 383 |
open_create_behavior() == Ioss::DB_MODIFY) { |
| 384 |
// Append to file if it already exists -- See if the file exists. |
| 385 |
auto file = Ioss::FileInfo(get_filename()); |
| 386 |
fileExists = file.exists(); |
| 387 |
if (fileExists && myProcessor == 0) { |
| 388 |
fmt::print(Ioss::WarnOut(), |
| 389 |
"Appending to existing database in parallel single-file " |
| 390 |
"output mode is a new capability; please check results carefully. File '{}'", |
| 391 |
get_filename()); |
| 392 |
} |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
open_root_group_nl(); |
| 397 |
open_child_group_nl(0); |
| 398 |
} |
| 399 |
|
| 400 |
ParallelDatabaseIO::~ParallelDatabaseIO() = default; |
| 401 |
|
| 402 |
void ParallelDatabaseIO::release_memory_nl() |
| 403 |
{ |
| 404 |
BaseDatabaseIO::release_memory_nl(); |
| 405 |
|
| 406 |
Ioss::Utils::clear(nodeOwningProcessor); |
| 407 |
Ioss::Utils::clear(nodeGlobalImplicitMap); |
| 408 |
Ioss::Utils::clear(elemGlobalImplicitMap); |
| 409 |
nodeGlobalImplicitMapDefined = false; |
| 410 |
elemGlobalImplicitMapDefined = false; |
| 411 |
nodesetOwnedNodes.clear(); |
| 412 |
metaDataWritten = false; |
| 413 |
try { |
| 414 |
decomp.reset(); |
| 415 |
} |
| 416 |
catch (...) { |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
bool ParallelDatabaseIO::check_valid_file_ptr(bool write_message, std::string *error_msg, |
| 421 |
int *bad_count, bool abort_if_error) const |
| 422 |
{ |
| 423 |
// Check for valid exodus_file_ptr (valid >= 0; invalid < 0) |
| 424 |
assert(isParallel); |
| 425 |
int global_file_ptr = util().global_minmax(m_exodusFilePtr, Ioss::ParallelUtils::DO_MIN); |
| 426 |
|
| 427 |
if (global_file_ptr < 0) { |
| 428 |
if (write_message || error_msg != nullptr || bad_count != nullptr) { |
| 429 |
Ioss::IntVector status; |
| 430 |
util().all_gather(m_exodusFilePtr, status); |
| 431 |
|
| 432 |
std::string open_create = is_input() ? "open input" : "create output"; |
| 433 |
if (write_message || error_msg != nullptr) { |
| 434 |
std::vector<size_t> procs; |
| 435 |
for (int i = 0; i < util().parallel_size(); i++) { |
| 436 |
if (status[i] < 0) { |
| 437 |
procs.push_back(i); |
| 438 |
} |
| 439 |
} |
| 440 |
std::string error_list = Ioss::Utils::format_id_list(procs, "--"); |
| 441 |
// See which processors could not open/create the file... |
| 442 |
std::ostringstream errmsg; |
| 443 |
fmt::print(errmsg, "ERROR: Unable to {} exodus database file '{}' on processors:\n\t{}", |
| 444 |
open_create, get_filename(), error_list); |
| 445 |
fmt::print(errmsg, "\n"); |
| 446 |
if (error_msg != nullptr) { |
| 447 |
*error_msg = errmsg.str(); |
| 448 |
} |
| 449 |
if (write_message && myProcessor == 0) { |
| 450 |
fmt::print(Ioss::OUTPUT(), "{}", errmsg.str()); |
| 451 |
} |
| 452 |
} |
| 453 |
if (bad_count != nullptr) { |
| 454 |
*bad_count = std::count_if(status.begin(), status.end(), [](int i) { return i < 0; }); |
| 455 |
} |
| 456 |
if (abort_if_error) { |
| 457 |
IOSS_ERROR(fmt::format("ERROR: Cannot {} file '{}'", open_create, get_filename())); |
| 458 |
} |
| 459 |
} |
| 460 |
return false; |
| 461 |
} |
| 462 |
return true; |
| 463 |
} |
| 464 |
|
| 465 |
bool ParallelDatabaseIO::open_input_file(bool write_message, std::string *error_msg, |
| 466 |
int *bad_count, bool abort_if_error) const |
| 467 |
{ |
| 468 |
int cpu_word_size = sizeof(double); |
| 469 |
int io_word_size = 0; |
| 470 |
float version; |
| 471 |
|
| 472 |
int mode = exodusMode; |
| 473 |
if (int_byte_size_api() == 8) { |
| 474 |
mode |= EX_ALL_INT64_API; |
| 475 |
} |
| 476 |
|
| 477 |
#if defined EX_DISKLESS |
| 478 |
// Experimental -- in memory read by netcdf library |
| 479 |
if (properties.exists("MEMORY_READ")) { |
| 480 |
mode |= EX_DISKLESS; |
| 481 |
} |
| 482 |
#endif |
| 483 |
|
| 484 |
MPI_Info info = MPI_INFO_NULL; |
| 485 |
std::string filename = get_filename(); |
| 486 |
|
| 487 |
// See bug description in thread at |
| 488 |
// https://www.open-mpi.org/community/lists/users/2015/01/26167.php and |
| 489 |
// https://prod.sandia.gov/sierra-trac/ticket/14679 |
| 490 |
// Kluge is to set cwd to pathname, open file, then set cwd back to original. |
| 491 |
// |
| 492 |
// Since several different mpi implementations are based on the |
| 493 |
// mpich code which introduced this bug, it has been difficult to |
| 494 |
// create an ifdef'd version of the fix which is only applied to the |
| 495 |
// buggy mpiio code. Therefore, we always do chdir call. Maybe in several |
| 496 |
// years, we can remove this code and everything will work... |
| 497 |
|
| 498 |
#if !defined(__IOSS_WINDOWS__) |
| 499 |
Ioss::FileInfo file(filename); |
| 500 |
std::string path = file.pathname(); |
| 501 |
filename = file.tailname(); |
| 502 |
char *current_cwd = getcwd(nullptr, 0); |
| 503 |
if (!path.empty()) { |
| 504 |
auto success = chdir(path.c_str()); |
| 505 |
if (success == -1) { |
| 506 |
if (write_message || error_msg != nullptr) { |
| 507 |
std::ostringstream errmsg; |
| 508 |
fmt::print(errmsg, |
| 509 |
"ERROR: Directory '{}' does not exist. Error in filename specification.", |
| 510 |
path); |
| 511 |
fmt::print(errmsg, "\n"); |
| 512 |
if (error_msg != nullptr) { |
| 513 |
*error_msg = errmsg.str(); |
| 514 |
} |
| 515 |
if (write_message && myProcessor == 0) { |
| 516 |
fmt::print(Ioss::OUTPUT(), "{}", errmsg.str()); |
| 517 |
} |
| 518 |
if (bad_count != nullptr) { |
| 519 |
*bad_count = 1; |
| 520 |
} |
| 521 |
if (abort_if_error) { |
| 522 |
IOSS_ERROR(errmsg); |
| 523 |
} |
| 524 |
} |
| 525 |
return false; |
| 526 |
} |
| 527 |
} |
| 528 |
#endif |
| 529 |
|
| 530 |
bool do_timer = false; |
| 531 |
Ioss::Utils::check_set_bool_property(properties, "IOSS_TIME_FILE_OPEN_CLOSE", do_timer); |
| 532 |
double t_begin = (do_timer ? Ioss::Utils::timer() : 0); |
| 533 |
|
| 534 |
int app_opt_val = ex_opts(EX_VERBOSE); |
| 535 |
m_exodusFilePtr = ex_open_par(filename.c_str(), EX_READ | mode, &cpu_word_size, &io_word_size, |
| 536 |
&version, util().communicator(), info); |
| 537 |
|
| 538 |
if (do_timer) { |
| 539 |
double t_end = Ioss::Utils::timer(); |
| 540 |
double duration = util().global_minmax(t_end - t_begin, Ioss::ParallelUtils::DO_MAX); |
| 541 |
if (myProcessor == 0) { |
| 542 |
fmt::print(Ioss::DebugOut(), "File Open Time = {} ({})\n", duration, filename); |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
#if !defined(__IOSS_WINDOWS__) |
| 547 |
if (!path.empty()) { |
| 548 |
(void)chdir(current_cwd); |
| 549 |
} |
| 550 |
std::free(current_cwd); |
| 551 |
#endif |
| 552 |
|
| 553 |
bool is_ok = check_valid_file_ptr(write_message, error_msg, bad_count, abort_if_error); |
| 554 |
|
| 555 |
if (is_ok) { |
| 556 |
finalize_file_open(); |
| 557 |
} |
| 558 |
ex_opts(app_opt_val); // Reset back to what it was. |
| 559 |
return is_ok; |
| 560 |
} |
| 561 |
|
| 562 |
bool ParallelDatabaseIO::handle_output_file(bool write_message, std::string *error_msg, |
| 563 |
int *bad_count, bool overwrite, |
| 564 |
bool abort_if_error) const |
| 565 |
{ |
| 566 |
// If 'overwrite' is false, we do not want to overwrite or clobber |
| 567 |
// the output file if it already exists since the app might be |
| 568 |
// reading the restart data from this file and then later |
| 569 |
// clobbering it and then writing restart data to the same |
| 570 |
// file. So, for output, we first check whether the file exists |
| 571 |
// and if it it and is writable, assume that we can later create a |
| 572 |
// new or append to existing file. |
| 573 |
|
| 574 |
// if 'overwrite' is true, then clobber/append |
| 575 |
|
| 576 |
if (!overwrite) { |
| 577 |
// check if file exists and is writeable. If so, return true. |
| 578 |
// Only need to check on processor 0 |
| 579 |
int int_is_ok = 0; |
| 580 |
if (myProcessor == 0) { |
| 581 |
Ioss::FileInfo file(get_filename()); |
| 582 |
int_is_ok = file.exists() && file.is_writable() ? 1 : 0; |
| 583 |
} |
| 584 |
util().broadcast(int_is_ok); |
| 585 |
|
| 586 |
if (int_is_ok == 1) { |
| 587 |
// Note that at this point, we cannot totally guarantee that |
| 588 |
// we will be able to create the file when needed, but we have |
| 589 |
// a pretty good chance. We can't guarantee creation without |
| 590 |
// creating and the app (or calling function) doesn't want us to overwrite... |
| 591 |
return true; |
| 592 |
} |
| 593 |
// File doesn't exist, so fall through and try to |
| 594 |
// create file since we won't be overwriting anything... |
| 595 |
} |
| 596 |
|
| 597 |
int cpu_word_size = sizeof(double); |
| 598 |
int io_word_size = 0; |
| 599 |
float version; |
| 600 |
|
| 601 |
int mode = exodusMode; |
| 602 |
if (int_byte_size_api() == 8) { |
| 603 |
mode |= EX_ALL_INT64_API; |
| 604 |
} |
| 605 |
|
| 606 |
#if defined EX_DISKLESS |
| 607 |
// Experimental -- in memory write by netcdf library |
| 608 |
if (properties.exists("MEMORY_WRITE")) { |
| 609 |
mode |= EX_DISKLESS; |
| 610 |
} |
| 611 |
#endif |
| 612 |
|
| 613 |
MPI_Info info = MPI_INFO_NULL; |
| 614 |
int app_opt_val = ex_opts(EX_VERBOSE); |
| 615 |
Ioss::DatabaseIO::openDatabase_nl(); |
| 616 |
|
| 617 |
std::string filename = get_dw_name(); |
| 618 |
|
| 619 |
Ioss::FileInfo file(filename); |
| 620 |
#if !defined(__IOSS_WINDOWS__) |
| 621 |
std::string path = file.pathname(); |
| 622 |
filename = file.tailname(); |
| 623 |
char *current_cwd = getcwd(nullptr, 0); |
| 624 |
(void)chdir(path.c_str()); |
| 625 |
#endif |
| 626 |
|
| 627 |
bool do_timer = false; |
| 628 |
Ioss::Utils::check_set_bool_property(properties, "IOSS_TIME_FILE_OPEN_CLOSE", do_timer); |
| 629 |
double t_begin = (do_timer ? Ioss::Utils::timer() : 0); |
| 630 |
|
| 631 |
if (fileExists) { |
| 632 |
m_exodusFilePtr = ex_open_par(filename.c_str(), EX_WRITE | mode, &cpu_word_size, |
| 633 |
&io_word_size, &version, util().communicator(), info); |
| 634 |
} |
| 635 |
else { |
| 636 |
// If the first write for this file, create it... |
| 637 |
if (int_byte_size_api() == 8) { |
| 638 |
// Check whether client actually wants 4-byte output on db |
| 639 |
// - If they specified INTEGER_SIZE_DB and the size isn't 8, |
| 640 |
// then don't change mode and use the default 4-byte output. |
| 641 |
if (properties.exists("INTEGER_SIZE_DB")) { |
| 642 |
if (properties.get("INTEGER_SIZE_DB").get_int() == 8) { |
| 643 |
mode |= EX_ALL_INT64_DB; |
| 644 |
} |
| 645 |
} |
| 646 |
else { |
| 647 |
mode |= EX_ALL_INT64_DB; |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
// Check whether we are on a NFS filesystem -- composed output is sometimes slow/hangs |
| 652 |
// on NFS |
| 653 |
if (myProcessor == 0) { |
| 654 |
if (file.is_nfs()) { |
| 655 |
fmt::print( |
| 656 |
Ioss::WarnOut(), |
| 657 |
"The database file: '{}'.\n" |
| 658 |
"\tis being written to an NFS filesystem. Some NFS filesystems have difficulty\n" |
| 659 |
"\twith parallel I/O (specifically writes). If you experience slow I/O,\n" |
| 660 |
"\ttry `export OMPI_MCA_fs_ufs_lock_algorithm=1` prior to running or\n" |
| 661 |
"\tnon-composed output or a different filesystem.\n", |
| 662 |
filename); |
| 663 |
} |
| 664 |
} |
| 665 |
m_exodusFilePtr = ex_create_par(filename.c_str(), mode, &cpu_word_size, &dbRealWordSize, |
| 666 |
util().communicator(), info); |
| 667 |
} |
| 668 |
|
| 669 |
if (do_timer) { |
| 670 |
double t_end = Ioss::Utils::timer(); |
| 671 |
double duration = util().global_minmax(t_end - t_begin, Ioss::ParallelUtils::DO_MAX); |
| 672 |
std::string open_create = fileExists ? "Open" : "Create"; |
| 673 |
if (myProcessor == 0) { |
| 674 |
fmt::print(Ioss::DebugOut(), "File {} Time = {} ({})\n", open_create, duration, filename); |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
#if !defined(__IOSS_WINDOWS__) |
| 679 |
(void)chdir(current_cwd); |
| 680 |
std::free(current_cwd); |
| 681 |
#endif |
| 682 |
|
| 683 |
bool is_ok = check_valid_file_ptr(write_message, error_msg, bad_count, abort_if_error); |
| 684 |
|
| 685 |
if (is_ok) { |
| 686 |
ex_set_max_name_length(m_exodusFilePtr, maximumNameLength); |
| 687 |
|
| 688 |
if (fileExists) { |
| 689 |
open_root_group_nl(); |
| 690 |
open_child_group_nl(0); |
| 691 |
} |
| 692 |
|
| 693 |
// Check properties handled post-create/open... |
| 694 |
if (properties.exists("COMPRESSION_METHOD")) { |
| 695 |
auto method = properties.get("COMPRESSION_METHOD").get_string(); |
| 696 |
method = Ioss::Utils::lowercase(method); |
| 697 |
ex_compression_type exo_method = EX_COMPRESS_ZLIB; |
| 698 |
if (method == "zlib" || method == "libz" || method == "gzip") { |
| 699 |
exo_method = EX_COMPRESS_ZLIB; |
| 700 |
} |
| 701 |
else if (method == "szip") { |
| 702 |
#if !defined(NC_HAS_SZIP_WRITE) |
| 703 |
#define NC_HAS_SZIP_WRITE 0 |
| 704 |
#endif |
| 705 |
#if NC_HAS_SZIP_WRITE |
| 706 |
exo_method = EX_COMPRESS_SZIP; |
| 707 |
#else |
| 708 |
if (myProcessor == 0) { |
| 709 |
fmt::print(Ioss::WarnOut(), "The NetCDF library does not have SZip compression enabled." |
| 710 |
" 'zlib' will be used instead.\n\n"); |
| 711 |
} |
| 712 |
#endif |
| 713 |
} |
| 714 |
else if (method == "zstd") { |
| 715 |
#if NC_HAS_ZSTD == 1 |
| 716 |
exo_method = EX_COMPRESS_ZSTD; |
| 717 |
#else |
| 718 |
if (myProcessor == 0) { |
| 719 |
fmt::print(Ioss::WarnOut(), |
| 720 |
"The NetCDF library does not have ZStandard compression enabled." |
| 721 |
" 'zlib' will be used instead.\n\n"); |
| 722 |
} |
| 723 |
#endif |
| 724 |
} |
| 725 |
else if (method == "bzip2") { |
| 726 |
#if NC_HAS_BZ2 == 1 |
| 727 |
exo_method = EX_COMPRESS_BZ2; |
| 728 |
#else |
| 729 |
if (myProcessor == 0) { |
| 730 |
fmt::print(Ioss::WarnOut(), |
| 731 |
"The NetCDF library does not have Bzip2 / BZ2 compression enabled." |
| 732 |
" 'zlib' will be used instead.\n\n"); |
| 733 |
} |
| 734 |
#endif |
| 735 |
} |
| 736 |
else { |
| 737 |
if (myProcessor == 0) { |
| 738 |
fmt::print(Ioss::WarnOut(), |
| 739 |
"Unrecognized compression method specified: '{}'." |
| 740 |
" 'zlib' will be used instead.\n\n", |
| 741 |
method); |
| 742 |
} |
| 743 |
} |
| 744 |
ex_set_option(m_exodusFilePtr, EX_OPT_COMPRESSION_TYPE, exo_method); |
| 745 |
} |
| 746 |
|
| 747 |
if (properties.exists("COMPRESSION_QUANTIZE_NSD")) { |
| 748 |
int quant_level = properties.get("COMPRESSION_QUANTIZE_NSD").get_int(); |
| 749 |
ex_set_option(m_exodusFilePtr, EX_OPT_QUANTIZE_NSD, quant_level); |
| 750 |
} |
| 751 |
|
| 752 |
if (properties.exists("COMPRESSION_LEVEL")) { |
| 753 |
int comp_level = properties.get("COMPRESSION_LEVEL").get_int(); |
| 754 |
ex_set_option(m_exodusFilePtr, EX_OPT_COMPRESSION_LEVEL, comp_level); |
| 755 |
} |
| 756 |
if (properties.exists("COMPRESSION_SHUFFLE")) { |
| 757 |
int shuffle = properties.get("COMPRESSION_SHUFFLE").get_int(); |
| 758 |
ex_set_option(m_exodusFilePtr, EX_OPT_COMPRESSION_SHUFFLE, shuffle); |
| 759 |
} |
| 760 |
} |
| 761 |
ex_opts(app_opt_val); // Reset back to what it was. |
| 762 |
return is_ok; |
| 763 |
} |
| 764 |
|
| 765 |
int ParallelDatabaseIO::get_file_pointer() const |
| 766 |
{ |
| 767 |
return Ioex::BaseDatabaseIO::get_file_pointer(); |
| 768 |
} |
| 769 |
|
| 770 |
int ParallelDatabaseIO::free_file_pointer() const |
| 771 |
{ |
| 772 |
int flag; |
| 773 |
MPI_Initialized(&flag); |
| 774 |
if (flag == 0) { |
| 775 |
IOSS_ERROR("ERROR: MPI is not initialized."); |
| 776 |
} |
| 777 |
|
| 778 |
// Make sure all file pointers are valid... |
| 779 |
int fp_min = util().global_minmax(m_exodusFilePtr, Ioss::ParallelUtils::DO_MIN); |
| 780 |
int fp_max = util().global_minmax(m_exodusFilePtr, Ioss::ParallelUtils::DO_MAX); |
| 781 |
if (fp_min != fp_max && fp_min < 0) { |
| 782 |
IOSS_ERROR("ERROR: Inconsistent file pointer values."); |
| 783 |
} |
| 784 |
return Ioex::BaseDatabaseIO::free_file_pointer(); |
| 785 |
} |
| 786 |
|
| 787 |
void ParallelDatabaseIO::read_meta_data_nl() |
| 788 |
{ |
| 789 |
int exoid = get_file_pointer(); // get_file_pointer() must be called first. |
| 790 |
|
| 791 |
// APPENDING: |
| 792 |
// If parallel (single file, not fpp), we have assumptions |
| 793 |
// that the writing process (ranks, mesh, decomp, vars) is the |
| 794 |
// same for the original run that created this database and |
| 795 |
// for this run which is appending to the database so the |
| 796 |
// defining of the output database should be the same except |
| 797 |
// we don't write anything since it is already there. We do |
| 798 |
// need the number of steps though... |
| 799 |
if (open_create_behavior() == Ioss::DB_APPEND || dbUsage == Ioss::QUERY_TIMESTEPS_ONLY) { |
| 800 |
get_step_times_nl(); |
| 801 |
return; |
| 802 |
} |
| 803 |
|
| 804 |
if (int_byte_size_api() == 8) { |
| 805 |
decomp = std::make_unique<DecompositionData<int64_t>>(properties, util().communicator()); |
| 806 |
} |
| 807 |
else { |
| 808 |
decomp = std::make_unique<DecompositionData<int>>(properties, util().communicator()); |
| 809 |
} |
| 810 |
assert(decomp != nullptr); |
| 811 |
decomp->decompose_model(exoid, get_filename()); |
| 812 |
|
| 813 |
read_region(); |
| 814 |
Ioex::read_exodus_basis(exoid); |
| 815 |
Ioex::read_exodus_quadrature(exoid); |
| 816 |
|
| 817 |
get_step_times_nl(); |
| 818 |
|
| 819 |
get_elemblocks(); |
| 820 |
get_nodeblocks(); |
| 821 |
get_edgeblocks(); |
| 822 |
get_faceblocks(); |
| 823 |
|
| 824 |
check_side_topology(); |
| 825 |
|
| 826 |
get_nodesets(); |
| 827 |
get_sidesets(); |
| 828 |
#if 0 |
| 829 |
get_edgesets(); |
| 830 |
get_facesets(); |
| 831 |
get_elemsets(); |
| 832 |
#endif |
| 833 |
|
| 834 |
get_commsets(); |
| 835 |
|
| 836 |
// Add assemblies now that all entities should be defined... consistent across processors |
| 837 |
// (metadata) |
| 838 |
get_assemblies(); |
| 839 |
|
| 840 |
get_blobs(); |
| 841 |
|
| 842 |
handle_groups(); |
| 843 |
|
| 844 |
add_region_fields(); |
| 845 |
|
| 846 |
if (!is_input() && open_create_behavior() == Ioss::DB_APPEND) { |
| 847 |
(void)get_map(EX_NODE_BLOCK); |
| 848 |
(void)get_map(EX_ELEM_BLOCK); |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
void ParallelDatabaseIO::read_region() |
| 853 |
{ |
| 854 |
// Add properties and fields to the 'owning' region. |
| 855 |
// Also defines member variables of this class... |
| 856 |
ex_init_params info{}; |
| 857 |
int error = ex_get_init_ext(get_file_pointer(), &info); |
| 858 |
if (error < 0) { |
| 859 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 860 |
} |
| 861 |
|
| 862 |
spatialDimension = decomp->spatial_dimension(); |
| 863 |
nodeCount = decomp->ioss_node_count(); |
| 864 |
edgeCount = 0; |
| 865 |
faceCount = 0; |
| 866 |
elementCount = decomp->ioss_elem_count(); |
| 867 |
|
| 868 |
m_groupCount[EX_NODE_BLOCK] = 1; |
| 869 |
m_groupCount[EX_EDGE_BLOCK] = info.num_edge_blk; |
| 870 |
m_groupCount[EX_FACE_BLOCK] = info.num_face_blk; |
| 871 |
m_groupCount[EX_ELEM_BLOCK] = info.num_elem_blk; |
| 872 |
|
| 873 |
m_groupCount[EX_NODE_SET] = info.num_node_sets; |
| 874 |
m_groupCount[EX_EDGE_SET] = info.num_edge_sets; |
| 875 |
m_groupCount[EX_FACE_SET] = info.num_face_sets; |
| 876 |
m_groupCount[EX_ELEM_SET] = info.num_elem_sets; |
| 877 |
|
| 878 |
m_groupCount[EX_SIDE_SET] = info.num_side_sets; |
| 879 |
m_groupCount[EX_ASSEMBLY] = info.num_assembly; |
| 880 |
m_groupCount[EX_BLOB] = info.num_blob; |
| 881 |
|
| 882 |
// Checks: node, element, blocks > 0; warning if == 0; error if < 0 |
| 883 |
check_valid_values(); |
| 884 |
|
| 885 |
Ioss::Region *this_region = get_region(); |
| 886 |
|
| 887 |
// See if any coordinate frames exist on mesh. If so, define them on region. |
| 888 |
Ioex::add_coordinate_frames(get_file_pointer(), this_region); |
| 889 |
|
| 890 |
this_region->property_add( |
| 891 |
Ioss::Property("global_node_count", static_cast<int64_t>(decomp->global_node_count()))); |
| 892 |
this_region->property_add( |
| 893 |
Ioss::Property("global_element_count", static_cast<int64_t>(decomp->global_elem_count()))); |
| 894 |
|
| 895 |
this_region->property_add(Ioss::Property(std::string("title"), info.title)); |
| 896 |
|
| 897 |
// Get QA records from database and add to qaRecords... |
| 898 |
int num_qa = ex_inquire_int(get_file_pointer(), EX_INQ_QA); |
| 899 |
if (num_qa > 0) { |
| 900 |
struct qa_element |
| 901 |
{ |
| 902 |
char *qa_record[1][4]; |
| 903 |
}; |
| 904 |
|
| 905 |
std::vector<qa_element> qa(num_qa); |
| 906 |
for (int i = 0; i < num_qa; i++) { |
| 907 |
for (int j = 0; j < 4; j++) { |
| 908 |
qa[i].qa_record[0][j] = new char[MAX_STR_LENGTH + 1]; |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
ex_get_qa(get_file_pointer(), qa[0].qa_record); |
| 913 |
for (int i = 0; i < num_qa; i++) { |
| 914 |
add_qa_record(qa[i].qa_record[0][0], qa[i].qa_record[0][1], qa[i].qa_record[0][2], |
| 915 |
qa[i].qa_record[0][3]); |
| 916 |
} |
| 917 |
for (int i = 0; i < num_qa; i++) { |
| 918 |
for (int j = 0; j < 4; j++) { |
| 919 |
delete[] qa[i].qa_record[0][j]; |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
// Get information records from database and add to informationRecords... |
| 925 |
int num_info = ex_inquire_int(get_file_pointer(), EX_INQ_INFO); |
| 926 |
if (num_info > 0) { |
| 927 |
char **info_rec = |
| 928 |
Ioex::get_name_array(num_info, max_line_length); // 'total_lines' pointers to char buffers |
| 929 |
ex_get_info(get_file_pointer(), info_rec); |
| 930 |
for (int i = 0; i < num_info; i++) { |
| 931 |
add_information_record(info_rec[i]); |
| 932 |
} |
| 933 |
Ioex::delete_name_array(info_rec, num_info); |
| 934 |
} |
| 935 |
} |
| 936 |
|
| 937 |
std::vector<double> ParallelDatabaseIO::internal_get_step_times_nl(bool setRegionTimeSteps) |
| 938 |
{ |
| 939 |
double last_time = DBL_MAX; |
| 940 |
int tstepCount = 0; |
| 941 |
int timestep_count = 0; |
| 942 |
std::vector<double> tsteps(0); |
| 943 |
|
| 944 |
int &l_timestepCount = setRegionTimeSteps ? m_timestepCount : tstepCount; |
| 945 |
|
| 946 |
{ |
| 947 |
timestep_count = ex_inquire_int(get_file_pointer(), EX_INQ_TIME); |
| 948 |
l_timestepCount = timestep_count; |
| 949 |
if (timestep_count <= 0) { |
| 950 |
return tsteps; |
| 951 |
} |
| 952 |
|
| 953 |
// For an exodusII file, timesteps are global and are stored in the region. |
| 954 |
// Read the timesteps and add to the region |
| 955 |
tsteps.resize(timestep_count); |
| 956 |
int error = ex_get_all_times(get_file_pointer(), tsteps.data()); |
| 957 |
if (error < 0) { |
| 958 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 959 |
} |
| 960 |
|
| 961 |
// See if the "last_written_time" attribute exists and if it |
| 962 |
// does, check that it matches the largest time in 'tsteps'. |
| 963 |
Ioex::read_last_time_attribute(get_file_pointer(), &last_time); |
| 964 |
} |
| 965 |
|
| 966 |
// Only add states that are less than or equal to the |
| 967 |
// 'last_time' value which is either DBL_MAX or the value of |
| 968 |
// the last time successfully written to the database and |
| 969 |
// flushed to disk. This is used to avoid corrupt data arising |
| 970 |
// from a job that crashed during the writing of the last step |
| 971 |
// on the database. Output a warning message if there is |
| 972 |
// potentially corrupt data on the database... |
| 973 |
|
| 974 |
// Check whether user or application wants to limit the times even further... |
| 975 |
// One use case is that job is restarting at a time prior to what has been |
| 976 |
// written to the results file, so want to start appending after |
| 977 |
// restart time instead of at end time on database. |
| 978 |
int max_step = properties.get_optional("APPEND_OUTPUT_AFTER_STEP", timestep_count); |
| 979 |
max_step = std::min(max_step, timestep_count); |
| 980 |
|
| 981 |
double max_time = |
| 982 |
properties.get_optional("APPEND_OUTPUT_AFTER_TIME", std::numeric_limits<double>::max()); |
| 983 |
last_time = std::min(last_time, max_time); |
| 984 |
|
| 985 |
Ioss::Region *this_region = get_region(); |
| 986 |
int numSteps = 0; |
| 987 |
for (int i = 0; i < max_step; i++) { |
| 988 |
if (tsteps[i] <= last_time) { |
| 989 |
if (setRegionTimeSteps) { |
| 990 |
this_region->add_state(tsteps[i] * timeScaleFactor); |
| 991 |
} |
| 992 |
|
| 993 |
tsteps[i] *= timeScaleFactor; |
| 994 |
numSteps++; |
| 995 |
} |
| 996 |
else { |
| 997 |
if (myProcessor == 0 && max_time == std::numeric_limits<double>::max()) { |
| 998 |
// NOTE: Don't want to warn on all processors if there are |
| 999 |
// corrupt steps on all databases, but this will only print |
| 1000 |
// a warning if there is a corrupt step on processor |
| 1001 |
// 0... Need better warnings which won't overload in the |
| 1002 |
// worst case... |
| 1003 |
fmt::print(Ioss::WarnOut(), |
| 1004 |
"Skipping step {} at time {} in database file\n\t{}.\nThe data for that step " |
| 1005 |
"is possibly corrupt.\n", |
| 1006 |
fmt::group_digits(i + 1), tsteps[i], get_filename()); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
tsteps.resize(numSteps); |
| 1012 |
return tsteps; |
| 1013 |
} |
| 1014 |
|
| 1015 |
std::vector<double> ParallelDatabaseIO::get_db_step_times_nl() |
| 1016 |
{ |
| 1017 |
return internal_get_step_times_nl(false); |
| 1018 |
} |
| 1019 |
|
| 1020 |
void ParallelDatabaseIO::get_step_times_nl() { internal_get_step_times_nl(true); } |
| 1021 |
|
| 1022 |
const Ioss::Map &ParallelDatabaseIO::get_map(ex_entity_type type) const |
| 1023 |
{ |
| 1024 |
switch (type) { |
| 1025 |
case EX_NODE_BLOCK: |
| 1026 |
case EX_NODE_SET: { |
| 1027 |
assert(decomp != nullptr); |
| 1028 |
size_t offset = decomp->decomp_node_offset(); |
| 1029 |
size_t count = decomp->decomp_node_count(); |
| 1030 |
return get_map(nodeMap, nodeCount, offset, count, EX_NODE_MAP, EX_INQ_NODE_MAP); |
| 1031 |
} |
| 1032 |
case EX_ELEM_BLOCK: |
| 1033 |
case EX_ELEM_SET: { |
| 1034 |
assert(decomp != nullptr); |
| 1035 |
size_t offset = decomp->decomp_elem_offset(); |
| 1036 |
size_t count = decomp->decomp_elem_count(); |
| 1037 |
return get_map(elemMap, elementCount, offset, count, EX_ELEM_MAP, EX_INQ_ELEM_MAP); |
| 1038 |
} |
| 1039 |
|
| 1040 |
case EX_FACE_BLOCK: |
| 1041 |
case EX_FACE_SET: return get_map(faceMap, faceCount, 0, 0, EX_FACE_MAP, EX_INQ_FACE_MAP); |
| 1042 |
|
| 1043 |
case EX_EDGE_BLOCK: |
| 1044 |
case EX_EDGE_SET: return get_map(edgeMap, edgeCount, 0, 0, EX_EDGE_MAP, EX_INQ_EDGE_MAP); |
| 1045 |
|
| 1046 |
default: |
| 1047 |
IOSS_ERROR("INTERNAL ERROR: Invalid map type. " |
| 1048 |
"Something is wrong in the Ioex::ParallelDatabaseIO::get_map() function. " |
| 1049 |
"Please report.\n"); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
|
| 1053 |
const Ioss::Map &ParallelDatabaseIO::get_map(Ioss::Map &entity_map, int64_t entity_count, |
| 1054 |
int64_t file_offset, int64_t file_count, |
| 1055 |
ex_entity_type entity_type, |
| 1056 |
ex_inquiry inquiry_type) const |
| 1057 |
{ |
| 1058 |
// Allocate space for node number map and read it in... |
| 1059 |
// Can be called multiple times, allocate 1 time only |
| 1060 |
if (entity_map.map().empty()) { |
| 1061 |
entity_map.set_size(entity_count); |
| 1062 |
|
| 1063 |
if (is_input()) { |
| 1064 |
Ioss::MapContainer file_data(file_count); |
| 1065 |
int error = 0; |
| 1066 |
// Check whether there is a "original_global_id_map" map on |
| 1067 |
// the database. If so, use it instead of the "node_num_map". |
| 1068 |
bool map_read = false; |
| 1069 |
int map_count = ex_inquire_int(get_file_pointer(), inquiry_type); |
| 1070 |
if (map_count > 0) { |
| 1071 |
char **names = Ioex::get_name_array(map_count, maximumNameLength); |
| 1072 |
int ierr = ex_get_names(get_file_pointer(), entity_type, names); |
| 1073 |
if (ierr < 0) { |
| 1074 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 1075 |
} |
| 1076 |
|
| 1077 |
if (map_count == 1 && Ioss::Utils::str_equal(names[0], "original_global_id_map")) { |
| 1078 |
if (int_byte_size_api() == 8) { |
| 1079 |
error = ex_get_partial_num_map(get_file_pointer(), entity_type, 1, file_offset + 1, |
| 1080 |
file_count, file_data.data()); |
| 1081 |
} |
| 1082 |
else { |
| 1083 |
// Ioss stores as 64-bit, read as 32-bit and copy over... |
| 1084 |
Ioss::IntVector tmp_map(file_count); |
| 1085 |
error = ex_get_partial_num_map(get_file_pointer(), entity_type, 1, file_offset + 1, |
| 1086 |
file_count, tmp_map.data()); |
| 1087 |
std::copy(tmp_map.begin(), tmp_map.end(), file_data.begin()); |
| 1088 |
} |
| 1089 |
if (error >= 0) { |
| 1090 |
map_read = true; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
Ioex::delete_name_array(names, map_count); |
| 1094 |
} |
| 1095 |
|
| 1096 |
if (!map_read) { |
| 1097 |
if (int_byte_size_api() == 8) { |
| 1098 |
error = ex_get_partial_id_map(get_file_pointer(), entity_type, file_offset + 1, |
| 1099 |
file_count, file_data.data()); |
| 1100 |
} |
| 1101 |
else { |
| 1102 |
// Ioss stores as 64-bit, read as 32-bit and copy over... |
| 1103 |
Ioss::IntVector tmp_map(file_count); |
| 1104 |
error = ex_get_partial_id_map(get_file_pointer(), entity_type, file_offset + 1, |
| 1105 |
file_count, tmp_map.data()); |
| 1106 |
std::copy(tmp_map.begin(), tmp_map.end(), file_data.begin()); |
| 1107 |
} |
| 1108 |
} |
| 1109 |
|
| 1110 |
if (error >= 0) { |
| 1111 |
if (entity_type == EX_NODE_MAP) { |
| 1112 |
decomp->communicate_node_data(file_data.data(), &entity_map.map()[1], 1); |
| 1113 |
} |
| 1114 |
else if (entity_type == EX_ELEM_MAP) { |
| 1115 |
decomp->communicate_element_data(file_data.data(), &entity_map.map()[1], 1); |
| 1116 |
} |
| 1117 |
} |
| 1118 |
else { |
| 1119 |
// Clear out the vector... |
| 1120 |
Ioss::MapContainer().swap(entity_map.map()); |
| 1121 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 1122 |
} |
| 1123 |
|
| 1124 |
// Check for sequential node map. |
| 1125 |
// If not, build the reverse G2L node map... |
| 1126 |
(void)entity_map.is_sequential(true); |
| 1127 |
entity_map.build_reverse_map(); |
| 1128 |
} |
| 1129 |
else { |
| 1130 |
// Output database; entity_map.map() not set yet... Build a default map. |
| 1131 |
entity_map.set_default(entity_count); |
| 1132 |
} |
| 1133 |
} |
| 1134 |
return entity_map; |
| 1135 |
} |
| 1136 |
|
| 1137 |
void ParallelDatabaseIO::get_elemblocks() { get_blocks(EX_ELEM_BLOCK, 0, "block"); } |
| 1138 |
|
| 1139 |
void ParallelDatabaseIO::get_faceblocks() |
| 1140 |
{ |
| 1141 |
// get_blocks(EX_FACE_BLOCK, 1, "faceblock"); |
| 1142 |
} |
| 1143 |
|
| 1144 |
void ParallelDatabaseIO::get_edgeblocks() |
| 1145 |
{ |
| 1146 |
// get_blocks(EX_EDGE_BLOCK, 2, "edgeblock"); |
| 1147 |
} |
| 1148 |
|
| 1149 |
void ParallelDatabaseIO::get_blocks(ex_entity_type entity_type, int rank_offset, |
| 1150 |
const std::string &basename) |
| 1151 |
{ |
| 1152 |
// Attributes of an X block are: (X = element, face, or edge) |
| 1153 |
// -- id |
| 1154 |
// -- name |
| 1155 |
// -- X type |
| 1156 |
// -- number of Xs |
| 1157 |
// -- number of attributes per X |
| 1158 |
// -- number of nodes per X (derivable from type) |
| 1159 |
// -- number of faces per X (derivable from type) |
| 1160 |
// -- number of edges per X (derivable from type) |
| 1161 |
|
| 1162 |
// In a parallel execution, it is possible that an X block will have |
| 1163 |
// no Xs on a particular processor... |
| 1164 |
|
| 1165 |
// NOTE: This routine may be called multiple times on a single database. |
| 1166 |
// make sure it is not dependent on being called one time only... |
| 1167 |
|
| 1168 |
// Get exodusII X block metadata |
| 1169 |
if (m_groupCount[entity_type] == 0) { |
| 1170 |
return; |
| 1171 |
} |
| 1172 |
|
| 1173 |
assert(entity_type == EX_ELEM_BLOCK); |
| 1174 |
|
| 1175 |
Ioss::Int64Vector X_block_ids(m_groupCount[entity_type]); |
| 1176 |
int used_blocks = 0; |
| 1177 |
|
| 1178 |
int error; |
| 1179 |
if ((ex_int64_status(get_file_pointer()) & EX_IDS_INT64_API) != 0) { |
| 1180 |
error = ex_get_ids(get_file_pointer(), entity_type, X_block_ids.data()); |
| 1181 |
} |
| 1182 |
else { |
| 1183 |
Ioss::IntVector tmp_set_ids(X_block_ids.size()); |
| 1184 |
error = ex_get_ids(get_file_pointer(), entity_type, tmp_set_ids.data()); |
| 1185 |
if (error >= 0) { |
| 1186 |
std::copy(tmp_set_ids.begin(), tmp_set_ids.end(), X_block_ids.begin()); |
| 1187 |
} |
| 1188 |
} |
| 1189 |
if (error < 0) { |
| 1190 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 1191 |
} |
| 1192 |
|
| 1193 |
// If the model contains assemblies, we want to retain the empty blocks since the blocks |
| 1194 |
// might be in an assembly. This is typically the case when an application is running |
| 1195 |
// in parallel, but is telling IOSS that it is "serial" (MPI_COMM_SELF) and taking care |
| 1196 |
// of synchronization at the app level instead of down here... |
| 1197 |
bool retain_empty_blocks = m_groupCount[EX_ASSEMBLY] > 0; |
| 1198 |
|
| 1199 |
// The application can override this setting using the `RETAIN_EMPTY_BLOCKS` property. |
| 1200 |
// This can either set to TRUE or FALSE... Note that `retain_empty_blocks` will not be |
| 1201 |
// changed unless the property exists. |
| 1202 |
Ioss::Utils::check_set_bool_property(properties, "RETAIN_EMPTY_BLOCKS", retain_empty_blocks); |
| 1203 |
|
| 1204 |
int nvar = std::numeric_limits<int>::max(); // Number of 'block' vars on database. Used to |
| 1205 |
// skip querying if none. |
| 1206 |
int nmap = std::numeric_limits<int>::max(); // Number of 'block' maps on database. Used to |
| 1207 |
// skip querying if none. |
| 1208 |
for (int iblk = 0; iblk < m_groupCount[entity_type]; iblk++) { |
| 1209 |
if (decomp->el_blocks[iblk].global_count() == 0 && !retain_empty_blocks) { |
| 1210 |
continue; |
| 1211 |
} |
| 1212 |
|
| 1213 |
int64_t id = decomp->el_blocks[iblk].id(); |
| 1214 |
|
| 1215 |
bool db_has_name = false; |
| 1216 |
std::string alias = Ioss::Utils::encode_entity_name(basename, id); |
| 1217 |
std::string block_name; |
| 1218 |
if (ignore_database_names()) { |
| 1219 |
block_name = alias; |
| 1220 |
} |
| 1221 |
else { |
| 1222 |
block_name = Ioex::get_entity_name(get_file_pointer(), entity_type, id, basename, |
| 1223 |
maximumNameLength, db_has_name); |
| 1224 |
} |
| 1225 |
if (get_use_generic_canonical_name()) { |
| 1226 |
std::swap(block_name, alias); |
| 1227 |
} |
| 1228 |
|
| 1229 |
std::string save_type = decomp->el_blocks[iblk].topologyType; |
| 1230 |
std::string type = Ioss::Utils::fixup_type(decomp->el_blocks[iblk].topologyType, |
| 1231 |
decomp->el_blocks[iblk].nodesPerEntity, |
| 1232 |
spatialDimension - rank_offset); |
| 1233 |
|
| 1234 |
if (decomp->el_blocks[iblk].global_count() == 0 && type.empty()) { |
| 1235 |
auto tokens = Ioss::tokenize(block_name, "_"); |
| 1236 |
if (tokens.size() >= 2) { |
| 1237 |
// Check whether last token names an X topology type... |
| 1238 |
const Ioss::ElementTopology *topology = |
| 1239 |
Ioss::ElementTopology::factory(tokens.back(), true); |
| 1240 |
if (topology != nullptr) { |
| 1241 |
type = topology->name(); |
| 1242 |
} |
| 1243 |
} |
| 1244 |
} |
| 1245 |
|
| 1246 |
if (type == "null" || type.empty()) { |
| 1247 |
// If we have no idea what the topology type for an empty |
| 1248 |
// X block is, call it "unknown" |
| 1249 |
type = "unknown"; |
| 1250 |
} |
| 1251 |
|
| 1252 |
Ioss::EntityBlock *io_block = nullptr; |
| 1253 |
if (entity_type == EX_ELEM_BLOCK) { |
| 1254 |
auto *eblock = |
| 1255 |
new Ioss::ElementBlock(this, block_name, type, decomp->el_blocks[iblk].ioss_count()); |
| 1256 |
io_block = eblock; |
| 1257 |
io_block->property_add(Ioss::Property("id", id)); |
| 1258 |
io_block->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1259 |
io_block->property_add(Ioss::Property("iblk", iblk)); // Sequence in decomp. |
| 1260 |
|
| 1261 |
if (db_has_name) { |
| 1262 |
std::string *db_name = &block_name; |
| 1263 |
if (get_use_generic_canonical_name()) { |
| 1264 |
db_name = &alias; |
| 1265 |
} |
| 1266 |
io_block->property_add(Ioss::Property("db_name", *db_name)); |
| 1267 |
} |
| 1268 |
get_region()->add(eblock); |
| 1269 |
#if 0 |
| 1270 |
} else if (entity_type == EX_FACE_BLOCK) { |
| 1271 |
Ioss::FaceBlock *fblock = new Ioss::FaceBlock(this, block_name, type, block.num_entry); |
| 1272 |
io_block = fblock; |
| 1273 |
io_block->property_add(Ioss::Property("id", id)); |
| 1274 |
io_block->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1275 |
if (db_has_name) { |
| 1276 |
std::string *db_name = &block_name; |
| 1277 |
if (get_use_generic_canonical_name()) { |
| 1278 |
db_name = &alias; |
| 1279 |
} |
| 1280 |
io_block->property_add(Ioss::Property("db_name", *db_name)); |
| 1281 |
} |
| 1282 |
get_region()->add(fblock); |
| 1283 |
} else if (entity_type == EX_EDGE_BLOCK) { |
| 1284 |
Ioss::EdgeBlock *eblock = new Ioss::EdgeBlock(this, block_name, type, block.num_entry); |
| 1285 |
io_block = eblock; |
| 1286 |
io_block->property_add(Ioss::Property("id", id)); |
| 1287 |
io_block->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1288 |
if (db_has_name) { |
| 1289 |
std::string *db_name = &block_name; |
| 1290 |
if (get_use_generic_canonical_name()) { |
| 1291 |
db_name = &alias; |
| 1292 |
} |
| 1293 |
io_block->property_add(Ioss::Property("db_name", *db_name)); |
| 1294 |
} |
| 1295 |
get_region()->add(eblock); |
| 1296 |
#endif |
| 1297 |
} |
| 1298 |
else { |
| 1299 |
IOSS_ERROR("ERROR: Invalid type in get_blocks()"); |
| 1300 |
} |
| 1301 |
|
| 1302 |
#if 0 |
| 1303 |
// See which connectivity options were defined for this block. |
| 1304 |
// X -> Node is always defined. |
| 1305 |
// X -> Face? |
| 1306 |
if (block.num_faces_per_entry > 0 && rank_offset < 1) { |
| 1307 |
std::string storage = "Real["+std::to_string(block.num_faces_per_entry)+"]"; |
| 1308 |
io_block->field_add(Ioss::Field("connectivity_face", |
| 1309 |
io_block->field_int_type(), storage, Ioss::Field::MESH)); |
| 1310 |
} |
| 1311 |
// X -> Edge? |
| 1312 |
if (block.num_edges_per_entry > 0 && rank_offset < 2) { |
| 1313 |
std::string storage = "Real["+std::to_string(block.num_edges_per_entry)+"]"; |
| 1314 |
io_block->field_add(Ioss::Field("connectivity_edge", |
| 1315 |
io_block->field_int_type(), storage, Ioss::Field::MESH)); |
| 1316 |
} |
| 1317 |
#endif |
| 1318 |
|
| 1319 |
// Maintain block order on output database... |
| 1320 |
io_block->property_add(Ioss::Property("original_block_order", used_blocks++)); |
| 1321 |
|
| 1322 |
if (save_type != "null" && save_type != "") { |
| 1323 |
io_block->property_update("original_topology_type", save_type); |
| 1324 |
} |
| 1325 |
|
| 1326 |
io_block->property_add(Ioss::Property( |
| 1327 |
"global_entity_count", static_cast<int64_t>(decomp->el_blocks[iblk].ioss_count()))); |
| 1328 |
|
| 1329 |
if (block_name != alias) { |
| 1330 |
get_region()->add_alias(block_name, alias, io_block->type()); |
| 1331 |
} |
| 1332 |
|
| 1333 |
// Check for additional variables. |
| 1334 |
add_attribute_fields(io_block, decomp->el_blocks[iblk].attributeCount, type); |
| 1335 |
if (nvar > 0) { |
| 1336 |
nvar = add_results_fields(io_block, iblk); |
| 1337 |
} |
| 1338 |
|
| 1339 |
if (entity_type == EX_ELEM_BLOCK) { |
| 1340 |
if (nmap > 0) { |
| 1341 |
nmap = |
| 1342 |
Ioex::add_map_fields(get_file_pointer(), dynamic_cast<Ioss::ElementBlock *>(io_block), |
| 1343 |
decomp->el_blocks[iblk].ioss_count(), maximumNameLength); |
| 1344 |
} |
| 1345 |
|
| 1346 |
if (!assemblyOmissions.empty() || !assemblyInclusions.empty()) { |
| 1347 |
update_block_omissions_from_assemblies(); |
| 1348 |
} |
| 1349 |
|
| 1350 |
assert(blockOmissions.empty() || blockInclusions.empty()); // Only one can be non-empty |
| 1351 |
|
| 1352 |
// Handle all block omissions or inclusions... |
| 1353 |
// This only affects the generation of surfaces... |
| 1354 |
if (!blockOmissions.empty()) { |
| 1355 |
for (const auto &name : blockOmissions) { |
| 1356 |
auto block = get_region()->get_element_block(name); |
| 1357 |
if (block) { |
| 1358 |
block->property_add(Ioss::Property(std::string("omitted"), 1)); |
| 1359 |
} |
| 1360 |
} |
| 1361 |
} |
| 1362 |
|
| 1363 |
if (!blockInclusions.empty()) { |
| 1364 |
const auto &blocks = get_region()->get_element_blocks(); |
| 1365 |
for (auto &block : blocks) { |
| 1366 |
block->property_add(Ioss::Property(std::string("omitted"), 1)); |
| 1367 |
} |
| 1368 |
|
| 1369 |
// Now, erase the property on any blocks in the inclusion list... |
| 1370 |
for (const auto &name : blockInclusions) { |
| 1371 |
auto block = get_region()->get_element_block(name); |
| 1372 |
if (block != nullptr) { |
| 1373 |
block->property_erase("omitted"); |
| 1374 |
} |
| 1375 |
} |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} |
| 1379 |
} |
| 1380 |
|
| 1381 |
void ParallelDatabaseIO::compute_node_status() const |
| 1382 |
{ |
| 1383 |
// Create a field for all nodes in the model indicating |
| 1384 |
// the connectivity 'status' of the node. The status values are: |
| 1385 |
// 0 -- node not connected to any elements |
| 1386 |
// 1 -- node only connected to omitted elements |
| 1387 |
// 2 -- node only connected to active elements |
| 1388 |
// 3 -- node at border of active and omitted elements. |
| 1389 |
|
| 1390 |
/// \todo Get working for parallel... |
| 1391 |
|
| 1392 |
if (nodeConnectivityStatusCalculated) { |
| 1393 |
return; |
| 1394 |
} |
| 1395 |
|
| 1396 |
nodeConnectivityStatus.resize(nodeCount); |
| 1397 |
|
| 1398 |
const Ioss::ElementBlockContainer &element_blocks = get_region()->get_element_blocks(); |
| 1399 |
assert(Ioss::Utils::check_block_order(element_blocks)); |
| 1400 |
|
| 1401 |
for (Ioss::ElementBlock *block : element_blocks) { |
| 1402 |
unsigned char status = 2; |
| 1403 |
if (Ioss::Utils::block_is_omitted(block)) { |
| 1404 |
status = 1; |
| 1405 |
} |
| 1406 |
|
| 1407 |
int64_t id = block->get_property("id").get_int(); |
| 1408 |
int element_nodes = block->topology()->number_nodes(); |
| 1409 |
int64_t my_element_count = block->entity_count(); |
| 1410 |
int order = block->get_property("iblk").get_int(); |
| 1411 |
if (int_byte_size_api() == 8) { |
| 1412 |
std::vector<int64_t> conn(my_element_count * element_nodes); |
| 1413 |
decomp->get_block_connectivity(get_file_pointer(), conn.data(), id, order, element_nodes); |
| 1414 |
for (auto node : conn) { |
| 1415 |
nodeConnectivityStatus[node - 1] |= status; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
else { |
| 1419 |
std::vector<int> conn(my_element_count * element_nodes); |
| 1420 |
decomp->get_block_connectivity(get_file_pointer(), conn.data(), id, order, element_nodes); |
| 1421 |
for (auto node : conn) { |
| 1422 |
nodeConnectivityStatus[node - 1] |= status; |
| 1423 |
} |
| 1424 |
} |
| 1425 |
} |
| 1426 |
nodeConnectivityStatusCalculated = true; |
| 1427 |
} |
| 1428 |
|
| 1429 |
namespace { |
| 1430 |
void get_element_sides_lists(const std::unique_ptr<DecompositionDataBase> &decomp, int exoid, |
| 1431 |
int64_t id, int int_byte_size, int64_t number_sides, |
| 1432 |
Ioss::Int64Vector &element, Ioss::Int64Vector &sides) |
| 1433 |
{ |
| 1434 |
// Check whether we already populated the element/sides vectors. |
| 1435 |
if (element.empty() && sides.empty()) { |
| 1436 |
element.resize(number_sides); |
| 1437 |
sides.resize(number_sides); |
| 1438 |
|
| 1439 |
// Easier below here if the element and sides are a known 64-bit size... |
| 1440 |
// Kluge here to do that... |
| 1441 |
if (int_byte_size == 4) { |
| 1442 |
Ioss::Field side_field("sides", Ioss::Field::INTEGER, IOSS_SCALAR(), Ioss::Field::MESH, |
| 1443 |
number_sides); |
| 1444 |
Ioss::Field elem_field("ids_raw", Ioss::Field::INTEGER, IOSS_SCALAR(), Ioss::Field::MESH, |
| 1445 |
number_sides); |
| 1446 |
|
| 1447 |
Ioss::IntVector e32(number_sides); |
| 1448 |
decomp->get_set_mesh_var(exoid, EX_SIDE_SET, id, elem_field, e32.data()); |
| 1449 |
std::copy(e32.begin(), e32.end(), element.begin()); |
| 1450 |
decomp->get_set_mesh_var(exoid, EX_SIDE_SET, id, side_field, e32.data()); |
| 1451 |
std::copy(e32.begin(), e32.end(), sides.begin()); |
| 1452 |
} |
| 1453 |
else { |
| 1454 |
Ioss::Field side_field("sides", Ioss::Field::INT64, IOSS_SCALAR(), Ioss::Field::MESH, |
| 1455 |
number_sides); |
| 1456 |
Ioss::Field elem_field("ids_raw", Ioss::Field::INT64, IOSS_SCALAR(), Ioss::Field::MESH, |
| 1457 |
number_sides); |
| 1458 |
decomp->get_set_mesh_var(exoid, EX_SIDE_SET, id, elem_field, element.data()); |
| 1459 |
decomp->get_set_mesh_var(exoid, EX_SIDE_SET, id, side_field, sides.data()); |
| 1460 |
} |
| 1461 |
} |
| 1462 |
} |
| 1463 |
} // namespace |
| 1464 |
|
| 1465 |
void ParallelDatabaseIO::get_sidesets() |
| 1466 |
{ |
| 1467 |
// This function creates all sidesets (surfaces) for a |
| 1468 |
// model. Note that a sideset contains 1 or more sideblocks |
| 1469 |
// which are homogeneous (same topology). In serial execution, |
| 1470 |
// this is fairly straightforward since there are no null sets and |
| 1471 |
// we have all the information we need. (...except see below for |
| 1472 |
// surface evolution). |
| 1473 |
// |
| 1474 |
// However, in a parallel execution, we have the possibility that a |
| 1475 |
// side set will have no sides or distribution factors on |
| 1476 |
// a particular processor. We then don't know the block topology of |
| 1477 |
// the block(s) contained in this set. We could do some |
| 1478 |
// communication and get a good idea of the topologies that are in |
| 1479 |
// the set. |
| 1480 |
|
| 1481 |
if (m_groupCount[EX_SIDE_SET] > 0) { |
| 1482 |
check_side_topology(); |
| 1483 |
|
| 1484 |
// Get exodusII sideset metadata |
| 1485 |
|
| 1486 |
// Get the names (may not exist) of all sidesets and see if they are actually |
| 1487 |
// side "blocks" (perhaps written by IO system for a restart). In that case, |
| 1488 |
// they were split by a previous run and we need to reconstruct the side "set" |
| 1489 |
// that may contain one or more of them. |
| 1490 |
Ioex::SideSetMap ss_map; |
| 1491 |
Ioex::SideSetSet ss_set; |
| 1492 |
|
| 1493 |
{ |
| 1494 |
int error; |
| 1495 |
|
| 1496 |
for (const auto &ss : decomp->side_sets) { |
| 1497 |
int64_t id = ss.id(); |
| 1498 |
std::vector<char> ss_name(maximumNameLength + 1); |
| 1499 |
error = ex_get_name(get_file_pointer(), EX_SIDE_SET, id, ss_name.data()); |
| 1500 |
if (error < 0) { |
| 1501 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 1502 |
} |
| 1503 |
if (ss_name[0] != '\0') { |
| 1504 |
Ioss::Utils::fixup_name(ss_name.data()); |
| 1505 |
Ioex::decode_surface_name(ss_map, ss_set, ss_name.data()); |
| 1506 |
} |
| 1507 |
} |
| 1508 |
} |
| 1509 |
|
| 1510 |
// Create sidesets for each entry in the ss_set... These are the |
| 1511 |
// sidesets which were probably written by a previous run of the |
| 1512 |
// IO system and are already split into homogeneous pieces... |
| 1513 |
{ |
| 1514 |
for (auto &ss_name : ss_set) { |
| 1515 |
auto *side_set = new Ioss::SideSet(this, ss_name); |
| 1516 |
get_region()->add(side_set); |
| 1517 |
int64_t id = Ioex::extract_id(ss_name); |
| 1518 |
if (id > 0) { |
| 1519 |
side_set->property_add(Ioss::Property("id", id)); |
| 1520 |
side_set->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1521 |
} |
| 1522 |
} |
| 1523 |
} |
| 1524 |
|
| 1525 |
for (int iss = 0; iss < m_groupCount[EX_SIDE_SET]; iss++) { |
| 1526 |
int64_t id = decomp->side_sets[iss].id(); |
| 1527 |
std::string sid; |
| 1528 |
Ioex::TopologyMap topo_map; |
| 1529 |
Ioex::TopologyMap side_map; // Used to determine side consistency |
| 1530 |
|
| 1531 |
Ioss::SurfaceSplitType split_type = splitType; |
| 1532 |
std::string side_set_name; |
| 1533 |
Ioss::SideSet *side_set = nullptr; |
| 1534 |
|
| 1535 |
bool db_has_name = false; |
| 1536 |
{ |
| 1537 |
std::string alias = Ioss::Utils::encode_entity_name("surface", id); |
| 1538 |
if (ignore_database_names()) { |
| 1539 |
side_set_name = alias; |
| 1540 |
} |
| 1541 |
else { |
| 1542 |
side_set_name = Ioex::get_entity_name(get_file_pointer(), EX_SIDE_SET, id, "surface", |
| 1543 |
maximumNameLength, db_has_name); |
| 1544 |
} |
| 1545 |
|
| 1546 |
if (side_set_name == "universal_sideset") { |
| 1547 |
split_type = Ioss::SPLIT_BY_DONT_SPLIT; |
| 1548 |
} |
| 1549 |
|
| 1550 |
bool in_ss_map = false; |
| 1551 |
auto SSM = ss_map.find(side_set_name); |
| 1552 |
if (SSM != ss_map.end()) { |
| 1553 |
in_ss_map = true; |
| 1554 |
std::string ess_name = (*SSM).second; |
| 1555 |
side_set = get_region()->get_sideset(ess_name); |
| 1556 |
Ioss::Utils::check_non_null(side_set, "sideset", ess_name, __func__); |
| 1557 |
} |
| 1558 |
else { |
| 1559 |
if (get_use_generic_canonical_name()) { |
| 1560 |
std::swap(side_set_name, alias); |
| 1561 |
} |
| 1562 |
side_set = new Ioss::SideSet(this, side_set_name); |
| 1563 |
side_set->property_add(Ioss::Property("id", id)); |
| 1564 |
side_set->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1565 |
if (db_has_name) { |
| 1566 |
std::string *db_name = &side_set_name; |
| 1567 |
if (get_use_generic_canonical_name()) { |
| 1568 |
db_name = &alias; |
| 1569 |
} |
| 1570 |
side_set->property_add(Ioss::Property("db_name", *db_name)); |
| 1571 |
} |
| 1572 |
get_region()->add(side_set); |
| 1573 |
|
| 1574 |
get_region()->add_alias(side_set_name, alias, Ioss::SIDESET); |
| 1575 |
get_region()->add_alias(side_set_name, Ioss::Utils::encode_entity_name("sideset", id), |
| 1576 |
Ioss::SIDESET); |
| 1577 |
} |
| 1578 |
|
| 1579 |
// split_type = SPLIT_BY_ELEMENT_BLOCK; |
| 1580 |
// split_type = SPLIT_BY_TOPOLOGIES; |
| 1581 |
// split_type = SPLIT_BY_DONT_SPLIT; |
| 1582 |
|
| 1583 |
// Determine how many side blocks compose this side set. |
| 1584 |
|
| 1585 |
int64_t number_sides = decomp->side_sets[iss].ioss_count(); |
| 1586 |
// FIXME: Support- number_distribution_factors = decomp->side_sets[iss].df_count(); |
| 1587 |
|
| 1588 |
Ioss::Int64Vector element; |
| 1589 |
Ioss::Int64Vector sides; |
| 1590 |
bool have_element_sides_lists = false; |
| 1591 |
|
| 1592 |
if (!blockOmissions.empty() || !blockInclusions.empty()) { |
| 1593 |
get_element_sides_lists(decomp, get_file_pointer(), id, int_byte_size_api(), |
| 1594 |
number_sides, element, sides); |
| 1595 |
Ioex::filter_element_list(get_region(), element, sides, true); |
| 1596 |
number_sides = element.size(); |
| 1597 |
assert(element.size() == sides.size()); |
| 1598 |
|
| 1599 |
// Determine if there are any sides left on the sideset after filtering... |
| 1600 |
int64_t global_sides = util().global_minmax(number_sides, Ioss::ParallelUtils::DO_SUM); |
| 1601 |
if (global_sides == 0) { |
| 1602 |
continue; |
| 1603 |
} |
| 1604 |
have_element_sides_lists = true; |
| 1605 |
} |
| 1606 |
|
| 1607 |
if (split_type == Ioss::SPLIT_BY_TOPOLOGIES && sideTopology.size() == 1) { |
| 1608 |
// There is only one side type for all elements in the model |
| 1609 |
topo_map[std::make_pair(sideTopology[0].first->name(), sideTopology[0].second)] = |
| 1610 |
number_sides; |
| 1611 |
} |
| 1612 |
else if (split_type == Ioss::SPLIT_BY_DONT_SPLIT) { |
| 1613 |
const Ioss::ElementTopology *mixed_topo = Ioss::ElementTopology::factory("unknown"); |
| 1614 |
topo_map[std::make_pair(std::string("unknown"), mixed_topo)] = number_sides; |
| 1615 |
} |
| 1616 |
else if (in_ss_map) { |
| 1617 |
auto tokens = Ioss::tokenize(side_set_name, "_"); |
| 1618 |
assert(tokens.size() >= 4); |
| 1619 |
// The sideset should have only a single topology which is |
| 1620 |
// given by the sideset name... |
| 1621 |
const Ioss::ElementTopology *side_topo = |
| 1622 |
Ioss::ElementTopology::factory(tokens[tokens.size() - 2]); |
| 1623 |
assert(side_topo != nullptr); |
| 1624 |
const Ioss::ElementTopology *element_topo = |
| 1625 |
Ioss::ElementTopology::factory(tokens[tokens.size() - 3], true); |
| 1626 |
std::string name; |
| 1627 |
if (element_topo != nullptr) { |
| 1628 |
name = element_topo->name(); |
| 1629 |
} |
| 1630 |
else { |
| 1631 |
// -4 -3 -2 -1 |
| 1632 |
// Name is of the form name_block_id_sidetopo_id |
| 1633 |
name = tokens[tokens.size() - 4] + "_" + tokens[tokens.size() - 3]; |
| 1634 |
} |
| 1635 |
|
| 1636 |
topo_map[std::make_pair(name, side_topo)] = number_sides; |
| 1637 |
|
| 1638 |
// We want the id to match the id on the sideset in this |
| 1639 |
// case so that the generated name will match the current |
| 1640 |
// name. Instead of converting from string to int back to |
| 1641 |
// string, we just set a variable to query later. |
| 1642 |
sid = tokens[tokens.size() - 1]; |
| 1643 |
} |
| 1644 |
else if (split_type == Ioss::SPLIT_BY_TOPOLOGIES) { |
| 1645 |
// There are multiple side types in the model. |
| 1646 |
// Iterate through the elements in the sideset, determine |
| 1647 |
// their parent element block using the blocks element |
| 1648 |
// topology and the side number, determine the side |
| 1649 |
// type. |
| 1650 |
|
| 1651 |
for (auto &side_topo : sideTopology) { |
| 1652 |
topo_map[std::make_pair(side_topo.first->name(), side_topo.second)] = 0; |
| 1653 |
side_map[std::make_pair(side_topo.first->name(), side_topo.second)] = 0; |
| 1654 |
} |
| 1655 |
|
| 1656 |
if (!have_element_sides_lists) { |
| 1657 |
get_element_sides_lists(decomp, get_file_pointer(), id, int_byte_size_api(), |
| 1658 |
number_sides, element, sides); |
| 1659 |
} |
| 1660 |
Ioex::separate_surface_element_sides(element, sides, get_region(), topo_map, side_map, |
| 1661 |
split_type, side_set_name); |
| 1662 |
} |
| 1663 |
else if (split_type == Ioss::SPLIT_BY_ELEMENT_BLOCK) { |
| 1664 |
// There are multiple side types in the model. Iterate |
| 1665 |
// through the elements in the sideset, determine their parent |
| 1666 |
// element block using blocks element topology and the side |
| 1667 |
// number, determine the side type. |
| 1668 |
|
| 1669 |
// Seed the topo_map map with <block->name, side_topo> |
| 1670 |
// pairs so we are sure that all processors have the same |
| 1671 |
// starting topo_map (size and order). |
| 1672 |
const Ioss::ElementBlockContainer &element_blocks = get_region()->get_element_blocks(); |
| 1673 |
assert(Ioss::Utils::check_block_order(element_blocks)); |
| 1674 |
|
| 1675 |
for (Ioss::ElementBlock *block : element_blocks) { |
| 1676 |
if (!Ioss::Utils::block_is_omitted(block)) { |
| 1677 |
const std::string &name = block->name(); |
| 1678 |
const Ioss::ElementTopology *common_ftopo = block->topology()->boundary_type(0); |
| 1679 |
if (common_ftopo != nullptr) { |
| 1680 |
// All sides of this element block's topology have the same topology |
| 1681 |
topo_map[std::make_pair(name, common_ftopo)] = 0; |
| 1682 |
side_map[std::make_pair(name, common_ftopo)] = 0; |
| 1683 |
} |
| 1684 |
else { |
| 1685 |
// The sides have different topology, iterate over |
| 1686 |
// them and create an entry for the unique side |
| 1687 |
// topology types |
| 1688 |
int par_dim = block->topology()->parametric_dimension(); |
| 1689 |
if (par_dim == 2 || par_dim == 3) { |
| 1690 |
int64_t my_side_count = block->topology()->number_boundaries(); |
| 1691 |
for (int64_t ii = 0; ii < my_side_count; ii++) { |
| 1692 |
const Ioss::ElementTopology *topo = block->topology()->boundary_type(ii + 1); |
| 1693 |
topo_map[std::make_pair(name, topo)] = 0; |
| 1694 |
side_map[std::make_pair(name, topo)] = 0; |
| 1695 |
} |
| 1696 |
} |
| 1697 |
} |
| 1698 |
} |
| 1699 |
} |
| 1700 |
if (!have_element_sides_lists) { |
| 1701 |
get_element_sides_lists(decomp, get_file_pointer(), id, int_byte_size_api(), |
| 1702 |
number_sides, element, sides); |
| 1703 |
} |
| 1704 |
Ioex::separate_surface_element_sides(element, sides, get_region(), topo_map, side_map, |
| 1705 |
split_type, side_set_name); |
| 1706 |
} |
| 1707 |
} |
| 1708 |
|
| 1709 |
// End of first step in splitting. Check among all processors |
| 1710 |
// to see which potential splits have sides in them... |
| 1711 |
Ioss::Int64Vector global_side_counts(topo_map.size()); |
| 1712 |
{ |
| 1713 |
int64_t i = 0; |
| 1714 |
for (auto &topo : topo_map) { |
| 1715 |
global_side_counts[i++] = topo.second; |
| 1716 |
} |
| 1717 |
|
| 1718 |
// If splitting by element block, also sync the side_map |
| 1719 |
// information which specifies whether the sideset has |
| 1720 |
// consistent sides for all elements. Only really used for |
| 1721 |
// shells, but easier to just set the value on all surfaces |
| 1722 |
// in the element block split case. |
| 1723 |
if (side_map.size() == topo_map.size()) { |
| 1724 |
global_side_counts.resize(topo_map.size() + side_map.size()); |
| 1725 |
|
| 1726 |
for (auto &side : side_map) { |
| 1727 |
global_side_counts[i++] = side.second; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
// See if any processor has non-zero count for the topo_map counts |
| 1732 |
// For the side_map, need the max value. |
| 1733 |
util().global_array_minmax(global_side_counts, Ioss::ParallelUtils::DO_MAX); |
| 1734 |
} |
| 1735 |
|
| 1736 |
// Create Side Blocks |
| 1737 |
|
| 1738 |
int64_t i = 0; |
| 1739 |
for (auto &topo : topo_map) { |
| 1740 |
if (global_side_counts[i++] > 0) { |
| 1741 |
const std::string topo_or_block_name = topo.first.first; |
| 1742 |
const Ioss::ElementTopology *side_topo = topo.first.second; |
| 1743 |
assert(side_topo != nullptr); |
| 1744 |
#if 0 |
| 1745 |
if (side_topo->parametric_dimension() == topology_dimension-1 || |
| 1746 |
split_type == Ioss::SPLIT_BY_DONT_SPLIT ) { |
| 1747 |
#else |
| 1748 |
if (true) { |
| 1749 |
#endif |
| 1750 |
int64_t my_side_count = topo.second; |
| 1751 |
|
| 1752 |
std::string side_block_name = |
| 1753 |
"surface_" + topo_or_block_name + "_" + side_topo->name(); |
| 1754 |
if (split_type == Ioss::SPLIT_BY_DONT_SPLIT) { |
| 1755 |
side_block_name = side_set_name; |
| 1756 |
} |
| 1757 |
else { |
| 1758 |
if (db_has_name) { |
| 1759 |
side_block_name = |
| 1760 |
side_set->name() + "_" + topo_or_block_name + "_" + side_topo->name(); |
| 1761 |
} |
| 1762 |
else { |
| 1763 |
if (sid.empty()) { |
| 1764 |
side_block_name = Ioss::Utils::encode_entity_name(side_block_name, id); |
| 1765 |
} |
| 1766 |
else { |
| 1767 |
side_block_name += "_"; |
| 1768 |
side_block_name += sid; |
| 1769 |
} |
| 1770 |
} |
| 1771 |
} |
| 1772 |
|
| 1773 |
Ioss::ElementBlock *block = nullptr; |
| 1774 |
// Need to get elem_topo.... |
| 1775 |
const Ioss::ElementTopology *elem_topo = nullptr; |
| 1776 |
if (split_type == Ioss::SPLIT_BY_TOPOLOGIES) { |
| 1777 |
elem_topo = Ioss::ElementTopology::factory(topo_or_block_name); |
| 1778 |
} |
| 1779 |
else if (split_type == Ioss::SPLIT_BY_ELEMENT_BLOCK) { |
| 1780 |
block = get_region()->get_element_block(topo_or_block_name); |
| 1781 |
if (block == nullptr || Ioss::Utils::block_is_omitted(block)) { |
| 1782 |
IOSS_ERROR(fmt::format( |
| 1783 |
"INTERNAL ERROR: Could not find element block '{}'. Something is wrong " |
| 1784 |
"in the Ioex::ParallelDatabaseIO class. Please report.\n", |
| 1785 |
topo_or_block_name)); |
| 1786 |
} |
| 1787 |
elem_topo = block->topology(); |
| 1788 |
} |
| 1789 |
if (split_type == Ioss::SPLIT_BY_DONT_SPLIT) { |
| 1790 |
// Most likely this is "unknown", but can be a true |
| 1791 |
// topology if there is only a single element block in |
| 1792 |
// the model. |
| 1793 |
elem_topo = Ioss::ElementTopology::factory(topo_or_block_name); |
| 1794 |
} |
| 1795 |
assert(elem_topo != nullptr); |
| 1796 |
|
| 1797 |
auto *side_block = new Ioss::SideBlock(this, side_block_name, side_topo->name(), |
| 1798 |
elem_topo->name(), my_side_count); |
| 1799 |
assert(side_block != nullptr); |
| 1800 |
side_block->property_add(Ioss::Property("id", id)); |
| 1801 |
side_block->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1802 |
side_set->add(side_block); |
| 1803 |
|
| 1804 |
// Note that all sideblocks within a specific |
| 1805 |
// sideset might have the same id. |
| 1806 |
|
| 1807 |
// If splitting by element block, need to set the |
| 1808 |
// element block member on this side block. |
| 1809 |
if (split_type == Ioss::SPLIT_BY_ELEMENT_BLOCK) { |
| 1810 |
side_block->set_parent_element_block(block); |
| 1811 |
} |
| 1812 |
|
| 1813 |
// If we calculated whether the element side is |
| 1814 |
// consistent for all sides in this block, then |
| 1815 |
// tell the block which side it is, or that they are |
| 1816 |
// inconsistent. If it wasn't calculated above, then it |
| 1817 |
// will be calculated on the fly when/if requested. |
| 1818 |
// This is to avoid reading the sideset bulk data in |
| 1819 |
// cases where we don't need to read it, but if we are |
| 1820 |
// already reading it (to split the sidesets), then use |
| 1821 |
// the data when we have it. |
| 1822 |
if (!side_map.empty()) { |
| 1823 |
// Set a property indicating which element side |
| 1824 |
// (1-based) all sides in this block are applied to. |
| 1825 |
// If they are not all assigned to the same element |
| 1826 |
// side, indicate this with a side equal to 0. |
| 1827 |
// |
| 1828 |
// (note: 'i' has already been incremented earlier in |
| 1829 |
// the loop. We need previous value here...) |
| 1830 |
int side = global_side_counts[i - 1 + topo_map.size()]; |
| 1831 |
if (side == 999) { |
| 1832 |
side = 0; |
| 1833 |
} |
| 1834 |
assert(side <= elem_topo->number_boundaries()); |
| 1835 |
side_block->set_consistent_side_number(side); |
| 1836 |
} |
| 1837 |
|
| 1838 |
// Add an alias... |
| 1839 |
get_region()->add_alias(side_block); |
| 1840 |
|
| 1841 |
if (split_type != Ioss::SPLIT_BY_DONT_SPLIT && side_set_name != "universal_sideset") { |
| 1842 |
std::string storage = "Real["; |
| 1843 |
storage += std::to_string(side_topo->number_nodes()); |
| 1844 |
storage += "]"; |
| 1845 |
side_block->field_add(Ioss::Field("distribution_factors", Ioss::Field::REAL, |
| 1846 |
storage, Ioss::Field::MESH)); |
| 1847 |
} |
| 1848 |
|
| 1849 |
if (side_set_name == "universal_sideset") { |
| 1850 |
side_block->field_add(Ioss::Field("side_ids", side_block->field_int_type(), |
| 1851 |
"scalar", Ioss::Field::MESH)); |
| 1852 |
} |
| 1853 |
|
| 1854 |
int num_attr = 0; |
| 1855 |
{ |
| 1856 |
int ierr = ex_get_attr_param(get_file_pointer(), EX_SIDE_SET, 1, &num_attr); |
| 1857 |
if (ierr < 0) { |
| 1858 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 1859 |
} |
| 1860 |
} |
| 1861 |
// Add additional fields |
| 1862 |
add_attribute_fields(side_block, num_attr, ""); |
| 1863 |
add_results_fields(side_block, iss); |
| 1864 |
} |
| 1865 |
} |
| 1866 |
} |
| 1867 |
} |
| 1868 |
} |
| 1869 |
} // namespace Ioex |
| 1870 |
|
| 1871 |
template <typename T> |
| 1872 |
void ParallelDatabaseIO::get_sets(ex_entity_type type, int64_t count, const std::string &base, |
| 1873 |
const T * /* set_type */) |
| 1874 |
{ |
| 1875 |
// Attributes of a Xset are: |
| 1876 |
// -- id |
| 1877 |
// -- name |
| 1878 |
// -- number of nodes |
| 1879 |
// -- number of distribution factors (see next comment) |
| 1880 |
// ----the #distribution factors should equal #Xs or 0, any |
| 1881 |
// other value does not make sense. If it is 0, then a substitute |
| 1882 |
// list will be created returning 1.0 for the factor |
| 1883 |
|
| 1884 |
// In a parallel execution, it is possible that a Xset will have |
| 1885 |
// no Xs or distribution factors on a particular processor... |
| 1886 |
|
| 1887 |
// Get exodusII Xset metadata |
| 1888 |
for (int64_t ins = 0; ins < count; ins++) { |
| 1889 |
int64_t id = decomp->node_sets[ins].id(); |
| 1890 |
|
| 1891 |
int num_attr = 0; |
| 1892 |
int ierr = ex_get_attr_param(get_file_pointer(), type, id, &num_attr); |
| 1893 |
if (ierr < 0) { |
| 1894 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 1895 |
} |
| 1896 |
|
| 1897 |
bool db_has_name = false; |
| 1898 |
std::string Xset_name; |
| 1899 |
std::string alias = Ioss::Utils::encode_entity_name(base + "list", id); |
| 1900 |
if (ignore_database_names()) { |
| 1901 |
Xset_name = alias; |
| 1902 |
} |
| 1903 |
else { |
| 1904 |
Xset_name = Ioex::get_entity_name(get_file_pointer(), type, id, base + "list", |
| 1905 |
maximumNameLength, db_has_name); |
| 1906 |
} |
| 1907 |
|
| 1908 |
if (get_use_generic_canonical_name()) { |
| 1909 |
std::swap(Xset_name, alias); |
| 1910 |
} |
| 1911 |
|
| 1912 |
T *Xset = new T(this, Xset_name, decomp->node_sets[ins].ioss_count()); |
| 1913 |
Xset->property_add(Ioss::Property("id", id)); |
| 1914 |
Xset->property_add(Ioss::Property("guid", util().generate_guid(id))); |
| 1915 |
if (db_has_name) { |
| 1916 |
std::string *db_name = &Xset_name; |
| 1917 |
if (get_use_generic_canonical_name()) { |
| 1918 |
db_name = &alias; |
| 1919 |
} |
| 1920 |
Xset->property_add(Ioss::Property("db_name", *db_name)); |
| 1921 |
} |
| 1922 |
get_region()->add(Xset); |
| 1923 |
get_region()->add_alias(Xset_name, alias, Xset->type()); |
| 1924 |
get_region()->add_alias(Xset_name, Ioss::Utils::encode_entity_name(base + "set", id), |
| 1925 |
Xset->type()); |
| 1926 |
add_attribute_fields(Xset, num_attr, ""); |
| 1927 |
add_results_fields(Xset, ins); |
| 1928 |
} |
| 1929 |
} |
| 1930 |
|
| 1931 |
void ParallelDatabaseIO::get_nodesets() |
| 1932 |
{ |
| 1933 |
get_sets(EX_NODE_SET, m_groupCount[EX_NODE_SET], "node", (Ioss::NodeSet *)nullptr); |
| 1934 |
} |
| 1935 |
|
| 1936 |
void ParallelDatabaseIO::get_edgesets() |
| 1937 |
{ |
| 1938 |
get_sets(EX_EDGE_SET, m_groupCount[EX_EDGE_SET], "edge", (Ioss::EdgeSet *)nullptr); |
| 1939 |
} |
| 1940 |
|
| 1941 |
void ParallelDatabaseIO::get_facesets() |
| 1942 |
{ |
| 1943 |
get_sets(EX_FACE_SET, m_groupCount[EX_FACE_SET], "face", (Ioss::FaceSet *)nullptr); |
| 1944 |
} |
| 1945 |
|
| 1946 |
void ParallelDatabaseIO::get_elemsets() |
| 1947 |
{ |
| 1948 |
get_sets(EX_ELEM_SET, m_groupCount[EX_ELEM_SET], "element", (Ioss::ElementSet *)nullptr); |
| 1949 |
} |
| 1950 |
|
| 1951 |
void ParallelDatabaseIO::get_commsets() |
| 1952 |
{ |
| 1953 |
// Attributes of a commset are: |
| 1954 |
// -- id (property) |
| 1955 |
// -- name (property) |
| 1956 |
// -- number of node--CPU pairs (field) |
| 1957 |
|
| 1958 |
// In a parallel execution, it is possible that a commset will have |
| 1959 |
// no nodes on a particular processor... |
| 1960 |
|
| 1961 |
// If this is a serial execution, there will be no communication |
| 1962 |
// nodesets, just return an empty container. |
| 1963 |
|
| 1964 |
if (isParallel) { |
| 1965 |
|
| 1966 |
// Create a single node commset |
| 1967 |
Ioss::CommSet *commset = |
| 1968 |
new Ioss::CommSet(this, "commset_node", "node", decomp->get_commset_node_size()); |
| 1969 |
commset->property_add(Ioss::Property("id", 1)); |
| 1970 |
commset->property_add(Ioss::Property("guid", util().generate_guid(1))); |
| 1971 |
get_region()->add(commset); |
| 1972 |
} |
| 1973 |
} |
| 1974 |
|
| 1975 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, |
| 1976 |
void *data, size_t data_size) const |
| 1977 |
{ |
| 1978 |
return Ioex::BaseDatabaseIO::get_field_internal(reg, field, data, data_size); |
| 1979 |
} |
| 1980 |
|
| 1981 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::NodeBlock *nb, |
| 1982 |
const Ioss::Field &field, void *data, |
| 1983 |
size_t data_size) const |
| 1984 |
{ |
| 1985 |
size_t num_to_get = field.verify(data_size); |
| 1986 |
|
| 1987 |
#ifndef NDEBUG |
| 1988 |
int64_t my_node_count = field.raw_count(); |
| 1989 |
assert(my_node_count == nodeCount); |
| 1990 |
#endif |
| 1991 |
|
| 1992 |
Ioss::Field::RoleType role = field.get_role(); |
| 1993 |
if (role == Ioss::Field::MESH) { |
| 1994 |
if (field.get_name() == "mesh_model_coordinates_x" || |
| 1995 |
field.get_name() == "mesh_model_coordinates_y" || |
| 1996 |
field.get_name() == "mesh_model_coordinates_z" || |
| 1997 |
field.get_name() == "mesh_model_coordinates") { |
| 1998 |
decomp->get_node_coordinates(get_file_pointer(), reinterpret_cast<double *>(data), field); |
| 1999 |
} |
| 2000 |
|
| 2001 |
else if (field.get_name() == "ids") { |
| 2002 |
// Map the local ids in this node block |
| 2003 |
// (1...node_count) to global node ids. |
| 2004 |
get_map(EX_NODE_BLOCK).map_implicit_data(data, field, num_to_get, 0); |
| 2005 |
} |
| 2006 |
|
| 2007 |
// The 1..global_node_count id. In a parallel-decomposed run, |
| 2008 |
// it maps the node back to its implicit position in the serial |
| 2009 |
// undecomposed mesh file. This is ONLY provided for backward- |
| 2010 |
// compatibility and should not be used unless absolutely required. |
| 2011 |
else if (field.get_name() == "implicit_ids") { |
| 2012 |
size_t offset = decomp->decomp_node_offset(); |
| 2013 |
size_t count = decomp->decomp_node_count(); |
| 2014 |
if (int_byte_size_api() == 4) { |
| 2015 |
std::vector<int> file_ids(count); |
| 2016 |
std::iota(file_ids.begin(), file_ids.end(), offset + 1); |
| 2017 |
decomp->communicate_node_data(file_ids.data(), reinterpret_cast<int *>(data), 1); |
| 2018 |
} |
| 2019 |
else { |
| 2020 |
std::vector<int64_t> file_ids(count); |
| 2021 |
std::iota(file_ids.begin(), file_ids.end(), offset + 1); |
| 2022 |
decomp->communicate_node_data(file_ids.data(), reinterpret_cast<int64_t *>(data), 1); |
| 2023 |
} |
| 2024 |
} |
| 2025 |
|
| 2026 |
else if (field.get_name() == "connectivity") { |
| 2027 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2028 |
} |
| 2029 |
else if (field.get_name() == "connectivity_raw") { |
| 2030 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2031 |
} |
| 2032 |
else if (field.get_name() == "node_connectivity_status") { |
| 2033 |
compute_node_status(); |
| 2034 |
char *status = static_cast<char *>(data); |
| 2035 |
std::copy(nodeConnectivityStatus.begin(), nodeConnectivityStatus.end(), status); |
| 2036 |
} |
| 2037 |
|
| 2038 |
else if (field.get_name() == "owning_processor") { |
| 2039 |
// If parallel, then set the "locally_owned" property on the nodeblocks. |
| 2040 |
Ioss::CommSet *css = get_region()->get_commset("commset_node"); |
| 2041 |
int *idata = static_cast<int *>(data); // Owning processor field is 4-byte int always |
| 2042 |
for (int64_t i = 0; i < nodeCount; i++) { |
| 2043 |
idata[i] = myProcessor; |
| 2044 |
} |
| 2045 |
|
| 2046 |
if (int_byte_size_api() == 8) { |
| 2047 |
// Cannot call: |
| 2048 |
// `css->get_field_data("entity_processor_raw", ent_proc);` |
| 2049 |
// directly since it will cause a deadlock (in threaded code), |
| 2050 |
// expand out into corresponding `get_field_internal` call. |
| 2051 |
Ioss::Field ep_field = css->get_field("entity_processor_raw"); |
| 2052 |
std::vector<int64_t> ent_proc(ep_field.raw_count() * |
| 2053 |
ep_field.get_component_count(Ioss::Field::InOut::INPUT)); |
| 2054 |
size_t ep_data_size = ent_proc.size() * sizeof(int64_t); |
| 2055 |
get_field_internal(css, ep_field, ent_proc.data(), ep_data_size); |
| 2056 |
for (size_t i = 0; i < ent_proc.size(); i += 2) { |
| 2057 |
int64_t node = ent_proc[i + 0]; |
| 2058 |
int64_t proc = ent_proc[i + 1]; |
| 2059 |
if (proc < idata[node - 1]) { |
| 2060 |
idata[node - 1] = proc; |
| 2061 |
} |
| 2062 |
} |
| 2063 |
} |
| 2064 |
else { |
| 2065 |
Ioss::Field ep_field = css->get_field("entity_processor_raw"); |
| 2066 |
std::vector<int> ent_proc(ep_field.raw_count() * |
| 2067 |
ep_field.get_component_count(Ioss::Field::InOut::INPUT)); |
| 2068 |
size_t ep_data_size = ent_proc.size() * sizeof(int); |
| 2069 |
get_field_internal(css, ep_field, ent_proc.data(), ep_data_size); |
| 2070 |
for (size_t i = 0; i < ent_proc.size(); i += 2) { |
| 2071 |
int node = ent_proc[i + 0]; |
| 2072 |
int proc = ent_proc[i + 1]; |
| 2073 |
if (proc < idata[node - 1]) { |
| 2074 |
idata[node - 1] = proc; |
| 2075 |
} |
| 2076 |
} |
| 2077 |
} |
| 2078 |
} |
| 2079 |
|
| 2080 |
else { |
| 2081 |
num_to_get = Ioss::Utils::field_warning(nb, field, "input"); |
| 2082 |
} |
| 2083 |
} |
| 2084 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2085 |
// Check if the specified field exists on this node block. |
| 2086 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2087 |
// exist on the database as scalars with the appropriate |
| 2088 |
// extensions. |
| 2089 |
|
| 2090 |
// Read in each component of the variable and transfer into |
| 2091 |
// 'data'. Need temporary storage area of size 'number of |
| 2092 |
// nodes in this block. |
| 2093 |
num_to_get = read_transient_field(m_variables[EX_NODE_BLOCK], field, nb, data); |
| 2094 |
} |
| 2095 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2096 |
num_to_get = read_attribute_field(field, nb, data); |
| 2097 |
} |
| 2098 |
return num_to_get; |
| 2099 |
} |
| 2100 |
|
| 2101 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, |
| 2102 |
void *data, size_t data_size) const |
| 2103 |
{ |
| 2104 |
{ |
| 2105 |
Ioss::SerializeIO serializeIO_(this); |
| 2106 |
|
| 2107 |
size_t num_to_get = field.verify(data_size); |
| 2108 |
if (num_to_get > 0) { |
| 2109 |
|
| 2110 |
Ioss::Field::RoleType role = field.get_role(); |
| 2111 |
if (role == Ioss::Field::MESH) { |
| 2112 |
if (field.get_name() == "ids") { |
| 2113 |
// Map the local ids in this node block |
| 2114 |
// (1...node_count) to global node ids. |
| 2115 |
// get_map(EX_BLOB).map_implicit_data(data, field, num_to_get, 0); |
| 2116 |
} |
| 2117 |
|
| 2118 |
else if (field.get_name() == "connectivity") { |
| 2119 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2120 |
} |
| 2121 |
else if (field.get_name() == "connectivity_raw") { |
| 2122 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2123 |
} |
| 2124 |
else { |
| 2125 |
num_to_get = Ioss::Utils::field_warning(blob, field, "input"); |
| 2126 |
} |
| 2127 |
} |
| 2128 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2129 |
// Check if the specified field exists on this blob. |
| 2130 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2131 |
// exist on the database as scalars with the appropriate |
| 2132 |
// extensions. |
| 2133 |
|
| 2134 |
// Read in each component of the variable and transfer into |
| 2135 |
// 'data'. Need temporary storage area of size 'number of |
| 2136 |
// items in this blob. |
| 2137 |
num_to_get = read_transient_field(m_variables[EX_BLOB], field, blob, data); |
| 2138 |
} |
| 2139 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2140 |
num_to_get = read_attribute_field(field, blob, data); |
| 2141 |
} |
| 2142 |
else if (role == Ioss::Field::REDUCTION) { |
| 2143 |
get_reduction_field(field, blob, data); |
| 2144 |
} |
| 2145 |
} |
| 2146 |
return num_to_get; |
| 2147 |
} |
| 2148 |
} |
| 2149 |
|
| 2150 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::Assembly *assembly, |
| 2151 |
const Ioss::Field &field, void *data, |
| 2152 |
size_t data_size) const |
| 2153 |
{ |
| 2154 |
{ |
| 2155 |
Ioss::SerializeIO serializeIO_(this); |
| 2156 |
|
| 2157 |
size_t num_to_get = field.verify(data_size); |
| 2158 |
if (num_to_get > 0) { |
| 2159 |
|
| 2160 |
Ioss::Field::RoleType role = field.get_role(); |
| 2161 |
if (role == Ioss::Field::MESH) { |
| 2162 |
if (field.get_name() == "ids") { |
| 2163 |
// Map the local ids in this node block |
| 2164 |
// (1...node_count) to global node ids. |
| 2165 |
// get_map(EX_ASSEMBLY).map_implicit_data(data, field, num_to_get, 0); |
| 2166 |
} |
| 2167 |
|
| 2168 |
else if (field.get_name() == "connectivity") { |
| 2169 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2170 |
} |
| 2171 |
else if (field.get_name() == "connectivity_raw") { |
| 2172 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2173 |
} |
| 2174 |
else { |
| 2175 |
num_to_get = Ioss::Utils::field_warning(assembly, field, "input"); |
| 2176 |
} |
| 2177 |
} |
| 2178 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2179 |
// Check if the specified field exists on this assembly. |
| 2180 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2181 |
// exist on the database as scalars with the appropriate |
| 2182 |
// extensions. |
| 2183 |
|
| 2184 |
// Read in each component of the variable and transfer into |
| 2185 |
// 'data'. Need temporary storage area of size 'number of |
| 2186 |
// items in this assembly. |
| 2187 |
num_to_get = read_transient_field(m_variables[EX_ASSEMBLY], field, assembly, data); |
| 2188 |
} |
| 2189 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2190 |
num_to_get = read_attribute_field(field, assembly, data); |
| 2191 |
} |
| 2192 |
} |
| 2193 |
return num_to_get; |
| 2194 |
} |
| 2195 |
} |
| 2196 |
|
| 2197 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::ElementBlock *eb, |
| 2198 |
const Ioss::Field &field, void *data, |
| 2199 |
size_t data_size) const |
| 2200 |
{ |
| 2201 |
|
| 2202 |
size_t num_to_get = field.verify(data_size); |
| 2203 |
|
| 2204 |
int64_t id = Ioex::get_id(eb, &ids_); |
| 2205 |
size_t my_element_count = eb->entity_count(); |
| 2206 |
Ioss::Field::RoleType role = field.get_role(); |
| 2207 |
|
| 2208 |
if (role == Ioss::Field::MESH) { |
| 2209 |
// Handle the MESH fields required for an ExodusII file model. |
| 2210 |
// (The 'genesis' portion) |
| 2211 |
|
| 2212 |
if (field.get_name() == "connectivity" || field.get_name() == "connectivity_raw") { |
| 2213 |
int element_nodes = eb->topology()->number_nodes(); |
| 2214 |
assert(field.get_component_count(Ioss::Field::InOut::INPUT) == element_nodes); |
| 2215 |
|
| 2216 |
int order = eb->get_property("iblk").get_int(); |
| 2217 |
// The connectivity is stored in a 1D array. |
| 2218 |
// The element_node index varies fastet |
| 2219 |
|
| 2220 |
decomp->get_block_connectivity(get_file_pointer(), data, id, order, element_nodes); |
| 2221 |
if (field.get_name() == "connectivity") { |
| 2222 |
get_map(EX_NODE_BLOCK).map_data(data, field, num_to_get * element_nodes); |
| 2223 |
} |
| 2224 |
} |
| 2225 |
#if 0 |
| 2226 |
else if (field.get_name() == "connectivity_face") { |
| 2227 |
int face_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 2228 |
|
| 2229 |
// The connectivity is stored in a 1D array. |
| 2230 |
// The element_face index varies fastest |
| 2231 |
if (my_element_count > 0) { |
| 2232 |
get_connectivity_data(get_file_pointer(), data, EX_ELEM_BLOCK, id, 2, int_byte_size_api()); |
| 2233 |
get_map(EX_FACE_BLOCK).map_data(data, field, num_to_get*face_count); |
| 2234 |
} |
| 2235 |
} |
| 2236 |
else if (field.get_name() == "connectivity_edge") { |
| 2237 |
int edge_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 2238 |
|
| 2239 |
// The connectivity is stored in a 1D array. |
| 2240 |
// The element_edge index varies fastest |
| 2241 |
if (my_element_count > 0) { |
| 2242 |
get_connectivity_data(get_file_pointer(), data, EX_ELEM_BLOCK, id, 1, int_byte_size_api()); |
| 2243 |
get_map(EX_EDGE_BLOCK).map_data(data, field, num_to_get*edge_count); |
| 2244 |
} |
| 2245 |
} |
| 2246 |
#endif |
| 2247 |
else if (field.get_name() == "ids" || field.get_name() == "implicit_ids") { |
| 2248 |
// Map the local ids in this element block |
| 2249 |
// (eb_offset+1...eb_offset+1+my_element_count) to global element ids. |
| 2250 |
get_map(EX_ELEM_BLOCK).map_implicit_data(data, field, num_to_get, eb->get_offset()); |
| 2251 |
} |
| 2252 |
} |
| 2253 |
else if (role == Ioss::Field::MAP) { |
| 2254 |
int component_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 2255 |
size_t eb_offset = eb->get_offset(); |
| 2256 |
|
| 2257 |
if (component_count == 1) { |
| 2258 |
// Single component -- can put data directly into return `data`; |
| 2259 |
decomp->get_user_map(get_file_pointer(), EX_ELEM_MAP, id, field.get_index(), eb_offset, |
| 2260 |
my_element_count, data); |
| 2261 |
} |
| 2262 |
else { |
| 2263 |
// Multi-component -- need read a component at a time and interleave into return `data` |
| 2264 |
if (field.is_type(Ioss::Field::INTEGER)) { |
| 2265 |
Ioss::IntVector component(my_element_count); |
| 2266 |
auto *data32 = reinterpret_cast<int *>(data); |
| 2267 |
for (int comp = 0; comp < component_count; comp++) { |
| 2268 |
decomp->get_user_map(get_file_pointer(), EX_ELEM_MAP, id, field.get_index() + comp, |
| 2269 |
eb_offset, my_element_count, component.data()); |
| 2270 |
int index = comp; |
| 2271 |
for (size_t i = 0; i < my_element_count; i++) { |
| 2272 |
data32[index] = component[i]; |
| 2273 |
index += component_count; |
| 2274 |
} |
| 2275 |
} |
| 2276 |
} |
| 2277 |
else { |
| 2278 |
Ioss::Int64Vector component(my_element_count); |
| 2279 |
auto *data64 = reinterpret_cast<int64_t *>(data); |
| 2280 |
for (int comp = 0; comp < component_count; comp++) { |
| 2281 |
decomp->get_user_map(get_file_pointer(), EX_ELEM_MAP, id, field.get_index() + comp, |
| 2282 |
eb_offset, my_element_count, component.data()); |
| 2283 |
|
| 2284 |
int index = comp; |
| 2285 |
for (size_t i = 0; i < my_element_count; i++) { |
| 2286 |
data64[index] = component[i]; |
| 2287 |
index += component_count; |
| 2288 |
} |
| 2289 |
} |
| 2290 |
} |
| 2291 |
} |
| 2292 |
#if 0 |
| 2293 |
else if (field.get_name() == "skin") { |
| 2294 |
// This is (currently) for the skinned body. It maps the |
| 2295 |
// side element on the skin to the original element/local |
| 2296 |
// side number. It is a two component field, the first |
| 2297 |
// component is the global id of the underlying element in |
| 2298 |
// the initial mesh and its local side number (1-based). |
| 2299 |
|
| 2300 |
if (field.is_type(Ioss::Field::INTEGER)) { |
| 2301 |
Ioss::IntVector element(my_element_count); |
| 2302 |
Ioss::IntVector side(my_element_count); |
| 2303 |
int *el_side = reinterpret_cast<int *>(data); |
| 2304 |
|
| 2305 |
// FIX: Hardwired map ids.... |
| 2306 |
size_t eb_offset = eb->get_offset(); |
| 2307 |
assert(1 == 0 && "Unimplemented FIXME"); |
| 2308 |
ex_get_partial_num_map(get_file_pointer(), EX_ELEM_MAP, 1, eb_offset + 1, my_element_count, |
| 2309 |
element.data()); // FIXME |
| 2310 |
ex_get_partial_num_map(get_file_pointer(), EX_ELEM_MAP, 2, eb_offset + 1, my_element_count, |
| 2311 |
side.data()); // FIXME |
| 2312 |
|
| 2313 |
int index = 0; |
| 2314 |
for (size_t i = 0; i < my_element_count; i++) { |
| 2315 |
el_side[index++] = element[i]; |
| 2316 |
el_side[index++] = side[i]; |
| 2317 |
} |
| 2318 |
} |
| 2319 |
else { |
| 2320 |
Ioss::Int64Vector element(my_element_count); |
| 2321 |
Ioss::Int64Vector side(my_element_count); |
| 2322 |
int64_t *el_side = reinterpret_cast<int64_t *>(data); |
| 2323 |
|
| 2324 |
// FIX: Hardwired map ids.... |
| 2325 |
size_t eb_offset = eb->get_offset(); |
| 2326 |
assert(1 == 0 && "Unimplemented FIXME"); |
| 2327 |
ex_get_partial_num_map(get_file_pointer(), EX_ELEM_MAP, 1, eb_offset + 1, my_element_count, |
| 2328 |
element.data()); // FIXME |
| 2329 |
ex_get_partial_num_map(get_file_pointer(), EX_ELEM_MAP, 2, eb_offset + 1, my_element_count, |
| 2330 |
side.data()); // FIXME |
| 2331 |
|
| 2332 |
size_t index = 0; |
| 2333 |
for (size_t i = 0; i < my_element_count; i++) { |
| 2334 |
el_side[index++] = element[i]; |
| 2335 |
el_side[index++] = side[i]; |
| 2336 |
} |
| 2337 |
} |
| 2338 |
} |
| 2339 |
else { |
| 2340 |
num_to_get = Ioss::Utils::field_warning(eb, field, "input"); |
| 2341 |
} |
| 2342 |
#endif |
| 2343 |
} |
| 2344 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2345 |
num_to_get = read_attribute_field(field, eb, data); |
| 2346 |
} |
| 2347 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2348 |
// Check if the specified field exists on this element block. |
| 2349 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2350 |
// exist on the database as scalars with the appropriate |
| 2351 |
// extensions. |
| 2352 |
|
| 2353 |
// Read in each component of the variable and transfer into |
| 2354 |
// 'data'. Need temporary storage area of size 'number of |
| 2355 |
// elements in this block. |
| 2356 |
num_to_get = read_transient_field(m_variables[EX_ELEM_BLOCK], field, eb, data); |
| 2357 |
} |
| 2358 |
else if (role == Ioss::Field::REDUCTION) { |
| 2359 |
num_to_get = Ioss::Utils::field_warning(eb, field, "input reduction"); |
| 2360 |
} |
| 2361 |
return num_to_get; |
| 2362 |
} |
| 2363 |
|
| 2364 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::FaceBlock *eb, |
| 2365 |
const Ioss::Field &field, void *data, |
| 2366 |
size_t data_size) const |
| 2367 |
{ |
| 2368 |
size_t num_to_get = field.verify(data_size); |
| 2369 |
|
| 2370 |
int64_t id = Ioex::get_id(eb, &ids_); |
| 2371 |
size_t my_face_count = eb->entity_count(); |
| 2372 |
Ioss::Field::RoleType role = field.get_role(); |
| 2373 |
|
| 2374 |
if (role == Ioss::Field::MESH) { |
| 2375 |
// Handle the MESH fields required for an ExodusII file model. |
| 2376 |
// (The 'genesis' portion) |
| 2377 |
|
| 2378 |
if (field.get_name() == "connectivity") { |
| 2379 |
int face_nodes = eb->topology()->number_nodes(); |
| 2380 |
assert(field.get_component_count(Ioss::Field::InOut::INPUT) == face_nodes); |
| 2381 |
|
| 2382 |
// The connectivity is stored in a 1D array. |
| 2383 |
// The face_node index varies fastet |
| 2384 |
if (my_face_count > 0) { |
| 2385 |
get_connectivity_data(get_file_pointer(), data, EX_FACE_BLOCK, id, 0, |
| 2386 |
int_byte_size_api()); |
| 2387 |
get_map(EX_NODE_BLOCK).map_data(data, field, num_to_get * face_nodes); |
| 2388 |
} |
| 2389 |
} |
| 2390 |
else if (field.get_name() == "connectivity_edge") { |
| 2391 |
int edge_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 2392 |
|
| 2393 |
// The connectivity is stored in a 1D array. |
| 2394 |
// The face_edge index varies fastest |
| 2395 |
if (my_face_count > 0) { |
| 2396 |
get_connectivity_data(get_file_pointer(), data, EX_FACE_BLOCK, id, 1, |
| 2397 |
int_byte_size_api()); |
| 2398 |
get_map(EX_EDGE_BLOCK).map_data(data, field, num_to_get * edge_count); |
| 2399 |
} |
| 2400 |
} |
| 2401 |
else if (field.get_name() == "connectivity_raw") { |
| 2402 |
// "connectivity_raw" has nodes in local id space (1-based) |
| 2403 |
assert(field.get_component_count(Ioss::Field::InOut::INPUT) == |
| 2404 |
eb->topology()->number_nodes()); |
| 2405 |
|
| 2406 |
// The connectivity is stored in a 1D array. |
| 2407 |
// The face_node index varies fastet |
| 2408 |
if (my_face_count > 0) { |
| 2409 |
get_connectivity_data(get_file_pointer(), data, EX_FACE_BLOCK, id, 0, |
| 2410 |
int_byte_size_api()); |
| 2411 |
} |
| 2412 |
} |
| 2413 |
else if (field.get_name() == "ids") { |
| 2414 |
// Map the local ids in this face block |
| 2415 |
// (eb_offset+1...eb_offset+1+my_face_count) to global face ids. |
| 2416 |
get_map(EX_FACE_BLOCK).map_implicit_data(data, field, num_to_get, eb->get_offset()); |
| 2417 |
} |
| 2418 |
else { |
| 2419 |
num_to_get = Ioss::Utils::field_warning(eb, field, "input"); |
| 2420 |
} |
| 2421 |
} |
| 2422 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2423 |
num_to_get = read_attribute_field(field, eb, data); |
| 2424 |
} |
| 2425 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2426 |
// Check if the specified field exists on this element block. |
| 2427 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2428 |
// exist on the database as scalars with the appropriate |
| 2429 |
// extensions. |
| 2430 |
|
| 2431 |
// Read in each component of the variable and transfer into |
| 2432 |
// 'data'. Need temporary storage area of size 'number of |
| 2433 |
// elements in this block. |
| 2434 |
num_to_get = read_transient_field(m_variables[EX_FACE_BLOCK], field, eb, data); |
| 2435 |
} |
| 2436 |
else if (role == Ioss::Field::REDUCTION) { |
| 2437 |
num_to_get = Ioss::Utils::field_warning(eb, field, "input reduction"); |
| 2438 |
} |
| 2439 |
return num_to_get; |
| 2440 |
} |
| 2441 |
|
| 2442 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::EdgeBlock *eb, |
| 2443 |
const Ioss::Field &field, void *data, |
| 2444 |
size_t data_size) const |
| 2445 |
{ |
| 2446 |
size_t num_to_get = field.verify(data_size); |
| 2447 |
|
| 2448 |
int64_t id = Ioex::get_id(eb, &ids_); |
| 2449 |
int64_t my_edge_count = eb->entity_count(); |
| 2450 |
Ioss::Field::RoleType role = field.get_role(); |
| 2451 |
|
| 2452 |
if (role == Ioss::Field::MESH) { |
| 2453 |
// Handle the MESH fields required for an ExodusII file model. |
| 2454 |
// (The 'genesis' portion) |
| 2455 |
|
| 2456 |
if (field.get_name() == "connectivity") { |
| 2457 |
int edge_nodes = eb->topology()->number_nodes(); |
| 2458 |
assert(field.get_component_count(Ioss::Field::InOut::INPUT) == edge_nodes); |
| 2459 |
|
| 2460 |
// The connectivity is stored in a 1D array. |
| 2461 |
// The edge_node index varies fastet |
| 2462 |
if (my_edge_count > 0) { |
| 2463 |
get_connectivity_data(get_file_pointer(), data, EX_EDGE_BLOCK, id, 0, |
| 2464 |
int_byte_size_api()); |
| 2465 |
get_map(EX_NODE_BLOCK).map_data(data, field, num_to_get * edge_nodes); |
| 2466 |
} |
| 2467 |
} |
| 2468 |
else if (field.get_name() == "connectivity_raw") { |
| 2469 |
// "connectivity_raw" has nodes in local id space (1-based) |
| 2470 |
assert(field.get_component_count(Ioss::Field::InOut::INPUT) == |
| 2471 |
eb->topology()->number_nodes()); |
| 2472 |
|
| 2473 |
// The connectivity is stored in a 1D array. |
| 2474 |
// The edge_node index varies fastet |
| 2475 |
if (my_edge_count > 0) { |
| 2476 |
get_connectivity_data(get_file_pointer(), data, EX_EDGE_BLOCK, id, 0, |
| 2477 |
int_byte_size_api()); |
| 2478 |
} |
| 2479 |
} |
| 2480 |
else if (field.get_name() == "ids") { |
| 2481 |
// Map the local ids in this edge block |
| 2482 |
// (eb_offset+1...eb_offset+1+my_edge_count) to global edge ids. |
| 2483 |
get_map(EX_EDGE_BLOCK).map_implicit_data(data, field, num_to_get, eb->get_offset()); |
| 2484 |
} |
| 2485 |
else { |
| 2486 |
num_to_get = Ioss::Utils::field_warning(eb, field, "input"); |
| 2487 |
} |
| 2488 |
} |
| 2489 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2490 |
num_to_get = read_attribute_field(field, eb, data); |
| 2491 |
} |
| 2492 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2493 |
// Check if the specified field exists on this element block. |
| 2494 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2495 |
// exist on the database as scalars with the appropriate |
| 2496 |
// extensions. |
| 2497 |
|
| 2498 |
// Read in each component of the variable and transfer into |
| 2499 |
// 'data'. Need temporary storage area of size 'number of |
| 2500 |
// elements in this block. |
| 2501 |
num_to_get = read_transient_field(m_variables[EX_EDGE_BLOCK], field, eb, data); |
| 2502 |
} |
| 2503 |
else if (role == Ioss::Field::REDUCTION) { |
| 2504 |
num_to_get = Ioss::Utils::field_warning(eb, field, "input reduction"); |
| 2505 |
} |
| 2506 |
return num_to_get; |
| 2507 |
} |
| 2508 |
|
| 2509 |
int64_t ParallelDatabaseIO::get_Xset_field_internal(const Ioss::EntitySet *ns, |
| 2510 |
const Ioss::Field &field, void *data, |
| 2511 |
size_t data_size) const |
| 2512 |
{ |
| 2513 |
int ierr; |
| 2514 |
size_t num_to_get = field.verify(data_size); |
| 2515 |
Ioss::Field::RoleType role = field.get_role(); |
| 2516 |
|
| 2517 |
// Find corresponding set in file decomp class... |
| 2518 |
if (role == Ioss::Field::MESH) { |
| 2519 |
int64_t id = Ioex::get_id(ns, &ids_); |
| 2520 |
|
| 2521 |
if (field.get_name() == "ids" || field.get_name() == "ids_raw") { |
| 2522 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 2523 |
ierr = decomp->get_set_mesh_var(get_file_pointer(), EX_NODE_SET, id, field, |
| 2524 |
static_cast<int *>(data)); |
| 2525 |
} |
| 2526 |
else { |
| 2527 |
ierr = decomp->get_set_mesh_var(get_file_pointer(), EX_NODE_SET, id, field, |
| 2528 |
static_cast<int64_t *>(data)); |
| 2529 |
} |
| 2530 |
if (ierr < 0) { |
| 2531 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 2532 |
} |
| 2533 |
|
| 2534 |
if (field.get_name() == "ids") { |
| 2535 |
// Convert the local node ids to global ids |
| 2536 |
get_map(EX_NODE_BLOCK).map_data(data, field, num_to_get); |
| 2537 |
} |
| 2538 |
} |
| 2539 |
else if (field.get_name() == "orientation") { |
| 2540 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 2541 |
ierr = decomp->get_set_mesh_var(get_file_pointer(), EX_NODE_SET, id, field, |
| 2542 |
static_cast<int *>(data)); |
| 2543 |
} |
| 2544 |
else { |
| 2545 |
ierr = decomp->get_set_mesh_var(get_file_pointer(), EX_NODE_SET, id, field, |
| 2546 |
static_cast<int64_t *>(data)); |
| 2547 |
} |
| 2548 |
if (ierr < 0) { |
| 2549 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 2550 |
} |
| 2551 |
} |
| 2552 |
else if (field.get_name() == "distribution_factors") { |
| 2553 |
ierr = decomp->get_set_mesh_double(get_file_pointer(), EX_NODE_SET, id, field, |
| 2554 |
static_cast<double *>(data)); |
| 2555 |
if (ierr < 0) { |
| 2556 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 2557 |
} |
| 2558 |
} |
| 2559 |
} |
| 2560 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 2561 |
num_to_get = read_attribute_field(field, ns, data); |
| 2562 |
} |
| 2563 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2564 |
// Check if the specified field exists on this node block. |
| 2565 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2566 |
// exist on the database as scalars with the appropriate |
| 2567 |
// extensions. |
| 2568 |
|
| 2569 |
// Read in each component of the variable and transfer into |
| 2570 |
// 'data'. Need temporary storage area of size 'number of |
| 2571 |
// nodes in this block. |
| 2572 |
ex_entity_type type = Ioex::map_exodus_type(ns->type()); |
| 2573 |
num_to_get = read_transient_field(m_variables[type], field, ns, data); |
| 2574 |
} |
| 2575 |
return num_to_get; |
| 2576 |
} |
| 2577 |
|
| 2578 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, |
| 2579 |
void *data, size_t data_size) const |
| 2580 |
{ |
| 2581 |
return get_Xset_field_internal(ns, field, data, data_size); |
| 2582 |
} |
| 2583 |
|
| 2584 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, |
| 2585 |
void *data, size_t data_size) const |
| 2586 |
{ |
| 2587 |
return get_Xset_field_internal(ns, field, data, data_size); |
| 2588 |
} |
| 2589 |
|
| 2590 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, |
| 2591 |
void *data, size_t data_size) const |
| 2592 |
{ |
| 2593 |
return get_Xset_field_internal(ns, field, data, data_size); |
| 2594 |
} |
| 2595 |
|
| 2596 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::ElementSet *ns, |
| 2597 |
const Ioss::Field &field, void *data, |
| 2598 |
size_t data_size) const |
| 2599 |
{ |
| 2600 |
return get_Xset_field_internal(ns, field, data, data_size); |
| 2601 |
} |
| 2602 |
|
| 2603 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, |
| 2604 |
void *data, size_t data_size) const |
| 2605 |
{ |
| 2606 |
size_t num_to_get = field.verify(data_size); |
| 2607 |
if (field.get_name() == "ids") { |
| 2608 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2609 |
// However, make sure that the caller gets a consistent answer, i.e., don't leave the buffer |
| 2610 |
// full of junk |
| 2611 |
memset(data, 0x00, data_size); |
| 2612 |
} |
| 2613 |
else { |
| 2614 |
num_to_get = Ioss::Utils::field_warning(ss, field, "input"); |
| 2615 |
} |
| 2616 |
return num_to_get; |
| 2617 |
} |
| 2618 |
|
| 2619 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, |
| 2620 |
void *data, size_t data_size) const |
| 2621 |
{ |
| 2622 |
size_t num_to_get = field.verify(data_size); |
| 2623 |
|
| 2624 |
// Return the <entity (node or side), processor> pair |
| 2625 |
if (field.get_name() == "entity_processor" || field.get_name() == "entity_processor_raw") { |
| 2626 |
|
| 2627 |
// Check type -- node or side |
| 2628 |
std::string type = cs->get_property("entity_type").get_string(); |
| 2629 |
|
| 2630 |
if (type == "node") { |
| 2631 |
|
| 2632 |
bool do_map = field.get_name() == "entity_processor"; |
| 2633 |
// Convert local node id to global node id and store in 'data' |
| 2634 |
const Ioss::MapContainer &map = get_map(EX_NODE_BLOCK).map(); |
| 2635 |
if (int_byte_size_api() == 4) { |
| 2636 |
decomp->get_node_entity_proc_data(static_cast<int *>(data), map, do_map); |
| 2637 |
} |
| 2638 |
else { |
| 2639 |
decomp->get_node_entity_proc_data(static_cast<int64_t *>(data), map, do_map); |
| 2640 |
} |
| 2641 |
} |
| 2642 |
else { |
| 2643 |
IOSS_ERROR(fmt::format("ERROR: Invalid commset type {}", type)); |
| 2644 |
} |
| 2645 |
} |
| 2646 |
else if (field.get_name() == "ids") { |
| 2647 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 2648 |
} |
| 2649 |
else { |
| 2650 |
num_to_get = Ioss::Utils::field_warning(cs, field, "input"); |
| 2651 |
} |
| 2652 |
return num_to_get; |
| 2653 |
} |
| 2654 |
|
| 2655 |
int64_t ParallelDatabaseIO::get_field_internal(const Ioss::SideBlock *sb, |
| 2656 |
const Ioss::Field &field, void *data, |
| 2657 |
size_t data_size) const |
| 2658 |
{ |
| 2659 |
int64_t num_to_get = field.verify(data_size); |
| 2660 |
int ierr = 0; |
| 2661 |
|
| 2662 |
int64_t id = Ioex::get_id(sb, &ids_); |
| 2663 |
int64_t entity_count = sb->entity_count(); |
| 2664 |
if (num_to_get != entity_count) { |
| 2665 |
IOSS_ERROR("ERROR: Partial field input not yet implemented for side blocks"); |
| 2666 |
} |
| 2667 |
|
| 2668 |
auto &set = decomp->get_decomp_set(EX_SIDE_SET, id); |
| 2669 |
|
| 2670 |
int64_t number_sides = set.ioss_count(); |
| 2671 |
int64_t number_distribution_factors = set.df_count(); |
| 2672 |
|
| 2673 |
Ioss::Field::RoleType role = field.get_role(); |
| 2674 |
if (role == Ioss::Field::MESH) { |
| 2675 |
|
| 2676 |
// In exodusII, we may have split the sideset into multiple |
| 2677 |
// side blocks if there are multiple side topologies in the |
| 2678 |
// sideset. Because of this, the passed in 'data' may not be |
| 2679 |
// large enough to hold the data residing in the sideset and we |
| 2680 |
// may need to allocate a temporary array... This can be checked |
| 2681 |
// by comparing the size of the sideset with the 'side_count' of |
| 2682 |
// the side block. |
| 2683 |
|
| 2684 |
// Get size of data stored on the file... |
| 2685 |
// FIX 64: FIX THIS -- STORING INT IN DOUBLE WON'T WORK |
| 2686 |
if (field.get_name() == "side_ids" && sb->name() == "universal_sideset") { |
| 2687 |
// The side ids are being stored as the distribution factor |
| 2688 |
// field on the universal sideset. There should be no other |
| 2689 |
// side sets that request this field... (Eventually, |
| 2690 |
// create an id field to store this info. |
| 2691 |
|
| 2692 |
if (number_distribution_factors == num_to_get) { |
| 2693 |
std::vector<double> real_ids(num_to_get); |
| 2694 |
Ioss::Field df_field("distribution_factor", Ioss::Field::REAL, "scalar", |
| 2695 |
Ioss::Field::MESH, num_to_get); |
| 2696 |
decomp->get_set_mesh_double(get_file_pointer(), EX_SIDE_SET, id, df_field, |
| 2697 |
real_ids.data()); |
| 2698 |
|
| 2699 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 2700 |
// Need to convert 'double' to 'int' for Sierra use... |
| 2701 |
int *ids = static_cast<int *>(data); |
| 2702 |
for (int64_t i = 0; i < num_to_get; i++) { |
| 2703 |
ids[i] = static_cast<int>(real_ids[i]); |
| 2704 |
} |
| 2705 |
} |
| 2706 |
else { |
| 2707 |
// Need to convert 'double' to 'int' for Sierra use... |
| 2708 |
int64_t *ids = static_cast<int64_t *>(data); |
| 2709 |
for (int64_t i = 0; i < num_to_get; i++) { |
| 2710 |
ids[i] = static_cast<int64_t>(real_ids[i]); |
| 2711 |
} |
| 2712 |
} |
| 2713 |
} |
| 2714 |
} |
| 2715 |
|
| 2716 |
else if (field.get_name() == "side_ids") { |
| 2717 |
} |
| 2718 |
|
| 2719 |
else if (field.get_name() == "ids") { |
| 2720 |
// In exodusII, the 'side set' is stored as a sideset. A |
| 2721 |
// sideset has a list of elements and a corresponding local |
| 2722 |
// element side (1-based) The side id is: side_id = |
| 2723 |
// 10*element_id + local_side_number This assumes that all |
| 2724 |
// sides in a sideset are boundary sides. Since we |
| 2725 |
// only have a single array, we need to allocate an extra array |
| 2726 |
// to store all of the data. Note also that the element_id is |
| 2727 |
// the global id but only the local id is stored so we need to |
| 2728 |
// map from local_to_global prior to generating the side id... |
| 2729 |
|
| 2730 |
Ioss::Field el_side = sb->get_field("element_side"); |
| 2731 |
std::vector<char> element_side(2 * number_sides * int_byte_size_api()); |
| 2732 |
get_field_internal(sb, el_side, element_side.data(), element_side.size()); |
| 2733 |
|
| 2734 |
// At this point, have the 'element_side' data containing |
| 2735 |
// the global element ids and the sides... Iterate |
| 2736 |
// through to generate the ids... |
| 2737 |
if (int_byte_size_api() == 4) { |
| 2738 |
int64_t int_max = std::numeric_limits<int>::max(); |
| 2739 |
int *ids = static_cast<int *>(data); |
| 2740 |
int *els = reinterpret_cast<int *>(element_side.data()); |
| 2741 |
size_t idx = 0; |
| 2742 |
for (int64_t iel = 0; iel < 2 * entity_count; iel += 2) { |
| 2743 |
int64_t new_id = static_cast<int64_t>(10) * els[iel] + els[iel + 1]; |
| 2744 |
if (new_id > int_max) { |
| 2745 |
IOSS_ERROR(fmt::format( |
| 2746 |
"ERROR: accessing the sideset field 'ids'\n" |
| 2747 |
"\t\thas exceeded the integer bounds for entity {}, local side id {}.\n" |
| 2748 |
"\t\tTry using 64-bit mode to read the file '{}'.\n", |
| 2749 |
els[iel], els[iel + 1], get_filename())); |
| 2750 |
} |
| 2751 |
|
| 2752 |
ids[idx++] = static_cast<int>(new_id); |
| 2753 |
} |
| 2754 |
} |
| 2755 |
else { |
| 2756 |
int64_t *ids = static_cast<int64_t *>(data); |
| 2757 |
int64_t *els = reinterpret_cast<int64_t *>(element_side.data()); |
| 2758 |
size_t idx = 0; |
| 2759 |
for (int64_t iel = 0; iel < 2 * entity_count; iel += 2) { |
| 2760 |
int64_t new_id = 10 * els[iel] + els[iel + 1]; |
| 2761 |
ids[idx++] = new_id; |
| 2762 |
} |
| 2763 |
} |
| 2764 |
} |
| 2765 |
else if (field.get_name() == "element_side" || field.get_name() == "element_side_raw") { |
| 2766 |
// In exodusII, the 'side set' is stored as a sideset. A sideset |
| 2767 |
// has a list of elements and a corresponding local element side |
| 2768 |
// (1-based) |
| 2769 |
|
| 2770 |
// Since we only have a single array, we need to allocate an extra |
| 2771 |
// array to store all of the data. Note also that the element_id |
| 2772 |
// is the global id but only the local id is stored so we need to |
| 2773 |
// map from local_to_global prior to generating the side id... |
| 2774 |
|
| 2775 |
// Get the element number map (1-based)... |
| 2776 |
const Ioss::MapContainer &map = get_map(EX_ELEM_BLOCK).map(); |
| 2777 |
|
| 2778 |
// Allocate space for local side number and element numbers |
| 2779 |
// numbers. |
| 2780 |
|
| 2781 |
// See if edges or faces... |
| 2782 |
int64_t side_offset = Ioss::Utils::get_side_offset(sb); |
| 2783 |
|
| 2784 |
if (sb->owner()->block_count() == 1 && number_sides == entity_count) { |
| 2785 |
|
| 2786 |
if (int_byte_size_api() == 4) { |
| 2787 |
int *element_side = static_cast<int *>(data); |
| 2788 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, field, element_side); |
| 2789 |
for (int64_t iel = 1; iel < 2 * entity_count; iel += 2) { |
| 2790 |
element_side[iel] = element_side[iel] - side_offset; |
| 2791 |
} |
| 2792 |
} |
| 2793 |
else { |
| 2794 |
int64_t *element_side = static_cast<int64_t *>(data); |
| 2795 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, field, element_side); |
| 2796 |
for (int64_t iel = 1; iel < 2 * entity_count; iel += 2) { |
| 2797 |
element_side[iel] = element_side[iel] - side_offset; |
| 2798 |
} |
| 2799 |
} |
| 2800 |
} |
| 2801 |
else { |
| 2802 |
// Need a larger vector to get the entire sideset and then filter down to the correct |
| 2803 |
// size... |
| 2804 |
std::vector<char> element(number_sides * int_byte_size_api()); |
| 2805 |
std::vector<char> sides(number_sides * int_byte_size_api()); |
| 2806 |
if (int_byte_size_api() == 4) { |
| 2807 |
Ioss::Field elem_field("ids", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 2808 |
number_sides); |
| 2809 |
Ioss::Field side_field("sides", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 2810 |
number_sides); |
| 2811 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 2812 |
reinterpret_cast<int *>(element.data())); |
| 2813 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 2814 |
reinterpret_cast<int *>(sides.data())); |
| 2815 |
} |
| 2816 |
else { |
| 2817 |
Ioss::Field elem_field("ids", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, |
| 2818 |
number_sides); |
| 2819 |
Ioss::Field side_field("sides", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, |
| 2820 |
number_sides); |
| 2821 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 2822 |
reinterpret_cast<int64_t *>(element.data())); |
| 2823 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 2824 |
reinterpret_cast<int64_t *>(sides.data())); |
| 2825 |
} |
| 2826 |
|
| 2827 |
Ioss::IntVector is_valid_side; |
| 2828 |
Ioss::Utils::calculate_sideblock_membership(is_valid_side, sb, int_byte_size_api(), |
| 2829 |
element.data(), sides.data(), number_sides, |
| 2830 |
get_region()); |
| 2831 |
|
| 2832 |
int64_t index = 0; |
| 2833 |
if (int_byte_size_api() == 4) { |
| 2834 |
int *element_side = static_cast<int *>(data); |
| 2835 |
int *element32 = reinterpret_cast<int *>(element.data()); |
| 2836 |
int *sides32 = reinterpret_cast<int *>(sides.data()); |
| 2837 |
for (int64_t iel = 0; iel < number_sides; iel++) { |
| 2838 |
if (is_valid_side[iel] == 1) { |
| 2839 |
// This side belongs in the side block |
| 2840 |
element_side[index++] = element32[iel]; |
| 2841 |
element_side[index++] = sides32[iel] - side_offset; |
| 2842 |
} |
| 2843 |
} |
| 2844 |
} |
| 2845 |
else { |
| 2846 |
int64_t *element_side = static_cast<int64_t *>(data); |
| 2847 |
int64_t *element64 = reinterpret_cast<int64_t *>(element.data()); |
| 2848 |
int64_t *sides64 = reinterpret_cast<int64_t *>(sides.data()); |
| 2849 |
for (int64_t iel = 0; iel < number_sides; iel++) { |
| 2850 |
if (is_valid_side[iel] == 1) { |
| 2851 |
// This side belongs in the side block |
| 2852 |
element_side[index++] = element64[iel]; |
| 2853 |
element_side[index++] = sides64[iel] - side_offset; |
| 2854 |
} |
| 2855 |
} |
| 2856 |
} |
| 2857 |
assert(index / 2 == entity_count); |
| 2858 |
} |
| 2859 |
if (field.get_name() == "element_side") { |
| 2860 |
if (int_byte_size_api() == 4) { |
| 2861 |
int *element_side = static_cast<int *>(data); |
| 2862 |
for (int64_t iel = 0; iel < 2 * entity_count; iel += 2) { |
| 2863 |
element_side[iel] = map[element_side[iel]]; |
| 2864 |
} |
| 2865 |
} |
| 2866 |
else { |
| 2867 |
int64_t *element_side = static_cast<int64_t *>(data); |
| 2868 |
for (int64_t iel = 0; iel < 2 * entity_count; iel += 2) { |
| 2869 |
element_side[iel] = map[element_side[iel]]; |
| 2870 |
} |
| 2871 |
} |
| 2872 |
} |
| 2873 |
} |
| 2874 |
else if (field.get_name() == "connectivity") { |
| 2875 |
// The side connectivity needs to be generated 'on-the-fly' from |
| 2876 |
// the element number and local side of that element. A sideset |
| 2877 |
// can span multiple element blocks, and contain multiple side |
| 2878 |
// types; the side block contains side of similar topology. |
| 2879 |
ierr = get_side_connectivity(sb, id, entity_count, data, true); |
| 2880 |
if (ierr < 0) { |
| 2881 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 2882 |
} |
| 2883 |
} |
| 2884 |
else if (field.get_name() == "connectivity_raw") { |
| 2885 |
// The side connectivity needs to be generated 'on-the-fly' from |
| 2886 |
// the element number and local side of that element. A sideset |
| 2887 |
// can span multiple element blocks, and contain multiple side |
| 2888 |
// types; the side block contains side of similar topology. |
| 2889 |
ierr = get_side_connectivity(sb, id, entity_count, data, false); |
| 2890 |
if (ierr < 0) { |
| 2891 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 2892 |
} |
| 2893 |
} |
| 2894 |
else if (field.get_name() == "distribution_factors") { |
| 2895 |
ierr = get_side_distributions(sb, id, entity_count, static_cast<double *>(data), |
| 2896 |
data_size / sizeof(double)); |
| 2897 |
if (ierr < 0) { |
| 2898 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 2899 |
} |
| 2900 |
} |
| 2901 |
else { |
| 2902 |
num_to_get = Ioss::Utils::field_warning(sb, field, "input"); |
| 2903 |
} |
| 2904 |
} |
| 2905 |
else if (role == Ioss::Field::TRANSIENT) { |
| 2906 |
// Check if the specified field exists on this block. |
| 2907 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 2908 |
// exist on the database as scalars with the appropriate |
| 2909 |
// extensions. |
| 2910 |
|
| 2911 |
if (sb->owner()->block_count() == 1 && number_sides == entity_count) { |
| 2912 |
num_to_get = read_transient_field(m_variables[EX_SIDE_SET], field, sb, data); |
| 2913 |
} |
| 2914 |
else { |
| 2915 |
// Need to read all values for the specified field and then |
| 2916 |
// filter down to the elements actually in this side block. |
| 2917 |
|
| 2918 |
Ioss::IntVector is_valid_side; |
| 2919 |
// Need a larger vector to get the entire sideset and then filter down to the correct |
| 2920 |
// size... |
| 2921 |
std::vector<char> element(number_sides * int_byte_size_api()); |
| 2922 |
std::vector<char> sides(number_sides * int_byte_size_api()); |
| 2923 |
if (int_byte_size_api() == 4) { |
| 2924 |
Ioss::Field elem_field("ids", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 2925 |
number_sides); |
| 2926 |
Ioss::Field side_field("sides", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 2927 |
number_sides); |
| 2928 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 2929 |
reinterpret_cast<int *>(element.data())); |
| 2930 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 2931 |
reinterpret_cast<int *>(sides.data())); |
| 2932 |
} |
| 2933 |
else { |
| 2934 |
Ioss::Field elem_field("ids", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, |
| 2935 |
number_sides); |
| 2936 |
Ioss::Field side_field("sides", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, |
| 2937 |
number_sides); |
| 2938 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 2939 |
reinterpret_cast<int64_t *>(element.data())); |
| 2940 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 2941 |
reinterpret_cast<int64_t *>(sides.data())); |
| 2942 |
} |
| 2943 |
Ioss::Utils::calculate_sideblock_membership(is_valid_side, sb, int_byte_size_api(), |
| 2944 |
element.data(), sides.data(), number_sides, |
| 2945 |
get_region()); |
| 2946 |
|
| 2947 |
num_to_get = read_ss_transient_field(field, id, data, is_valid_side); |
| 2948 |
} |
| 2949 |
} |
| 2950 |
return num_to_get; |
| 2951 |
} |
| 2952 |
|
| 2953 |
int64_t ParallelDatabaseIO::write_attribute_field(const Ioss::Field &field, |
| 2954 |
const Ioss::GroupingEntity *ge, |
| 2955 |
void *data) const |
| 2956 |
{ |
| 2957 |
std::string att_name = ge->name() + SEP() + field.get_name(); |
| 2958 |
int64_t num_entity = ge->entity_count(); |
| 2959 |
int64_t offset = field.get_index(); |
| 2960 |
|
| 2961 |
int64_t id = Ioex::get_id(ge, &ids_); |
| 2962 |
assert(offset > 0); |
| 2963 |
assert(offset - 1 + field.get_component_count(Ioss::Field::InOut::OUTPUT) <= |
| 2964 |
ge->get_property("attribute_count").get_int()); |
| 2965 |
|
| 2966 |
size_t proc_offset = ge->get_optional_property("_processor_offset", 0); |
| 2967 |
int64_t file_count = ge->get_optional_property("locally_owned_count", num_entity); |
| 2968 |
|
| 2969 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 2970 |
assert(ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::INTEGER || |
| 2971 |
ioss_type == Ioss::Field::INT64); |
| 2972 |
|
| 2973 |
if (ioss_type == Ioss::Field::INT64) { |
| 2974 |
Ioss::Utils::check_int_to_real_overflow(field, (int64_t *)data, num_entity); |
| 2975 |
} |
| 2976 |
|
| 2977 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 2978 |
|
| 2979 |
ex_entity_type type = Ioex::map_exodus_type(ge->type()); |
| 2980 |
if (type == EX_NODAL) { |
| 2981 |
for (int i = 0; i < comp_count; i++) { |
| 2982 |
std::vector<double> file_data; |
| 2983 |
file_data.reserve(file_count); |
| 2984 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 2985 |
if (ioss_type == Ioss::Field::REAL) { |
| 2986 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, static_cast<double *>(data), |
| 2987 |
file_data, i, comp_count); |
| 2988 |
} |
| 2989 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 2990 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, static_cast<int *>(data), file_data, |
| 2991 |
i, comp_count); |
| 2992 |
} |
| 2993 |
else if (ioss_type == Ioss::Field::INT64) { |
| 2994 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, static_cast<int64_t *>(data), |
| 2995 |
file_data, i, comp_count); |
| 2996 |
} |
| 2997 |
int ierr = ex_put_partial_one_attr(get_file_pointer(), type, id, proc_offset + 1, |
| 2998 |
file_count, offset + i, file_data.data()); |
| 2999 |
if (ierr < 0) { |
| 3000 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3001 |
} |
| 3002 |
} |
| 3003 |
} |
| 3004 |
else if (type == EX_NODE_SET) { |
| 3005 |
for (int i = 0; i < comp_count; i++) { |
| 3006 |
std::vector<double> file_data; |
| 3007 |
file_data.reserve(file_count); |
| 3008 |
if (ioss_type == Ioss::Field::REAL) { |
| 3009 |
map_nodeset_data(nodesetOwnedNodes[ge], static_cast<double *>(data), file_data, i, |
| 3010 |
comp_count); |
| 3011 |
} |
| 3012 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 3013 |
map_nodeset_data(nodesetOwnedNodes[ge], static_cast<int *>(data), file_data, i, |
| 3014 |
comp_count); |
| 3015 |
} |
| 3016 |
else if (ioss_type == Ioss::Field::INT64) { |
| 3017 |
map_nodeset_data(nodesetOwnedNodes[ge], static_cast<int64_t *>(data), file_data, i, |
| 3018 |
comp_count); |
| 3019 |
} |
| 3020 |
|
| 3021 |
int ierr = ex_put_partial_one_attr(get_file_pointer(), type, id, proc_offset + 1, |
| 3022 |
file_count, offset + i, file_data.data()); |
| 3023 |
if (ierr < 0) { |
| 3024 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3025 |
} |
| 3026 |
} |
| 3027 |
} |
| 3028 |
else { |
| 3029 |
assert(file_count == num_entity); |
| 3030 |
std::vector<double> file_data(file_count); |
| 3031 |
for (int i = 0; i < comp_count; i++) { |
| 3032 |
if (ioss_type == Ioss::Field::REAL) { |
| 3033 |
extract_data(file_data, static_cast<double *>(data), num_entity, i, comp_count); |
| 3034 |
} |
| 3035 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 3036 |
extract_data(file_data, static_cast<int *>(data), num_entity, i, comp_count); |
| 3037 |
} |
| 3038 |
else if (ioss_type == Ioss::Field::INT64) { |
| 3039 |
extract_data(file_data, static_cast<int64_t *>(data), num_entity, i, comp_count); |
| 3040 |
} |
| 3041 |
|
| 3042 |
int ierr = ex_put_partial_one_attr(get_file_pointer(), type, id, proc_offset + 1, |
| 3043 |
file_count, offset + i, file_data.data()); |
| 3044 |
if (ierr < 0) { |
| 3045 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3046 |
} |
| 3047 |
} |
| 3048 |
} |
| 3049 |
return num_entity; |
| 3050 |
} |
| 3051 |
|
| 3052 |
int64_t ParallelDatabaseIO::read_attribute_field(const Ioss::Field &field, |
| 3053 |
const Ioss::GroupingEntity *ge, void *data) const |
| 3054 |
{ |
| 3055 |
int64_t num_entity = ge->entity_count(); |
| 3056 |
|
| 3057 |
int attribute_count = ge->get_property("attribute_count").get_int(); |
| 3058 |
int64_t id = Ioex::get_id(ge, &ids_); |
| 3059 |
|
| 3060 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 3061 |
if (ioss_type == Ioss::Field::INTEGER || ioss_type == Ioss::Field::INT64) { |
| 3062 |
IOSS_ERROR("INTERNAL ERROR: Integer attribute fields are not yet handled for read. " |
| 3063 |
"Please report.\n"); |
| 3064 |
} |
| 3065 |
|
| 3066 |
std::string att_name = ge->name() + SEP() + field.get_name(); |
| 3067 |
ex_entity_type type = Ioex::map_exodus_type(ge->type()); |
| 3068 |
int64_t offset = field.get_index(); |
| 3069 |
assert(offset - 1 + field.get_component_count(Ioss::Field::InOut::INPUT) <= attribute_count); |
| 3070 |
if (offset == 1 && field.get_component_count(Ioss::Field::InOut::INPUT) == attribute_count) { |
| 3071 |
// Read all attributes in one big chunk... |
| 3072 |
int ierr = decomp->get_attr(get_file_pointer(), type, id, attribute_count, |
| 3073 |
static_cast<double *>(data)); |
| 3074 |
if (ierr < 0) { |
| 3075 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3076 |
} |
| 3077 |
} |
| 3078 |
else { |
| 3079 |
// Read a subset of the attributes. If scalar, read one; |
| 3080 |
// if higher-order (vector3d, ..) read each component and |
| 3081 |
// put into correct location... |
| 3082 |
if (field.get_component_count(Ioss::Field::InOut::INPUT) == 1) { |
| 3083 |
int ierr = |
| 3084 |
decomp->get_one_attr(get_file_pointer(), type, id, offset, static_cast<double *>(data)); |
| 3085 |
if (ierr < 0) { |
| 3086 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3087 |
} |
| 3088 |
} |
| 3089 |
else { |
| 3090 |
// Multi-component... |
| 3091 |
// Need a local memory space to read data into and |
| 3092 |
// then push that into the user-supplied data block... |
| 3093 |
std::vector<double> local_data(num_entity); |
| 3094 |
int comp_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 3095 |
double *rdata = static_cast<double *>(data); |
| 3096 |
for (int i = 0; i < comp_count; i++) { |
| 3097 |
int ierr = |
| 3098 |
decomp->get_one_attr(get_file_pointer(), type, id, offset + i, local_data.data()); |
| 3099 |
if (ierr < 0) { |
| 3100 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3101 |
} |
| 3102 |
|
| 3103 |
size_t k = i; |
| 3104 |
for (int64_t j = 0; j < num_entity; j++) { |
| 3105 |
rdata[k] = local_data[j]; |
| 3106 |
k += comp_count; |
| 3107 |
} |
| 3108 |
} |
| 3109 |
} |
| 3110 |
} |
| 3111 |
return num_entity; |
| 3112 |
} |
| 3113 |
|
| 3114 |
int64_t ParallelDatabaseIO::read_transient_field(const Ioex::VariableNameMap &variables, |
| 3115 |
const Ioss::Field &field, |
| 3116 |
const Ioss::GroupingEntity *ge, void *data) const |
| 3117 |
{ |
| 3118 |
// Read into a double variable since that is all ExodusII can store... |
| 3119 |
size_t num_entity = ge->entity_count(); |
| 3120 |
std::vector<double> temp(num_entity); |
| 3121 |
|
| 3122 |
size_t step = get_current_state(); |
| 3123 |
|
| 3124 |
// get number of components, cycle through each component |
| 3125 |
// and add suffix to base 'field_name'. Look up index |
| 3126 |
// of this name in 'nodeVariables' map |
| 3127 |
size_t comp_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 3128 |
|
| 3129 |
for (size_t i = 0; i < comp_count; i++) { |
| 3130 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::INPUT, i + 1); |
| 3131 |
if (lowerCaseVariableNames) { |
| 3132 |
Ioss::Utils::fixup_name(var_name); |
| 3133 |
} |
| 3134 |
|
| 3135 |
// Read the variable... |
| 3136 |
ex_entity_type type = Ioex::map_exodus_type(ge->type()); |
| 3137 |
int64_t id = Ioex::get_id(ge, &ids_); |
| 3138 |
int ierr = 0; |
| 3139 |
auto var_iter = variables.find(var_name); |
| 3140 |
if (var_iter == variables.end()) { |
| 3141 |
IOSS_ERROR(fmt::format("ERROR: Could not find field '{}'\n", var_name)); |
| 3142 |
} |
| 3143 |
size_t var_index = var_iter->second; |
| 3144 |
assert(var_index > 0); |
| 3145 |
if (type == EX_BLOB) { |
| 3146 |
size_t offset = ge->get_property("_processor_offset").get_int(); |
| 3147 |
ierr = ex_get_partial_var(get_file_pointer(), step, type, var_index, id, offset + 1, |
| 3148 |
num_entity, temp.data()); |
| 3149 |
} |
| 3150 |
else { |
| 3151 |
ierr = decomp->get_var(get_file_pointer(), step, type, var_index, id, num_entity, temp); |
| 3152 |
} |
| 3153 |
if (ierr < 0) { |
| 3154 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3155 |
} |
| 3156 |
|
| 3157 |
// Transfer to 'data' array. |
| 3158 |
size_t k = 0; |
| 3159 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 3160 |
int *ivar = static_cast<int *>(data); |
| 3161 |
for (size_t j = i; j < num_entity * comp_count; j += comp_count) { |
| 3162 |
ivar[j] = static_cast<int>(temp[k++]); |
| 3163 |
} |
| 3164 |
} |
| 3165 |
else if (field.get_type() == Ioss::Field::INT64) { // FIX 64 UNSAFE |
| 3166 |
int64_t *ivar = static_cast<int64_t *>(data); |
| 3167 |
for (size_t j = i; j < num_entity * comp_count; j += comp_count) { |
| 3168 |
ivar[j] = static_cast<int64_t>(temp[k++]); |
| 3169 |
} |
| 3170 |
} |
| 3171 |
else if (field.get_type() == Ioss::Field::REAL) { |
| 3172 |
double *rvar = static_cast<double *>(data); |
| 3173 |
for (size_t j = i; j < num_entity * comp_count; j += comp_count) { |
| 3174 |
rvar[j] = temp[k++]; |
| 3175 |
} |
| 3176 |
} |
| 3177 |
else { |
| 3178 |
IOSS_ERROR(fmt::format("IOSS_ERROR: Field storage type must be either integer or double.\n" |
| 3179 |
" Field '{}' is invalid.\n", |
| 3180 |
field.get_name())); |
| 3181 |
} |
| 3182 |
assert(k == num_entity); |
| 3183 |
} |
| 3184 |
return num_entity; |
| 3185 |
} |
| 3186 |
|
| 3187 |
int64_t ParallelDatabaseIO::read_ss_transient_field(const Ioss::Field &field, int64_t id, |
| 3188 |
void *variables, |
| 3189 |
Ioss::IntVector &is_valid_side) const |
| 3190 |
{ |
| 3191 |
size_t num_valid_sides = 0; |
| 3192 |
size_t my_side_count = is_valid_side.size(); |
| 3193 |
std::vector<double> temp(my_side_count); |
| 3194 |
|
| 3195 |
size_t step = get_current_state(); |
| 3196 |
|
| 3197 |
// get number of components, cycle through each component |
| 3198 |
// and add suffix to base 'field_name'. Look up index |
| 3199 |
// of this name in 'nodeVariables' map |
| 3200 |
size_t comp_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 3201 |
|
| 3202 |
for (size_t i = 0; i < comp_count; i++) { |
| 3203 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::INPUT, i + 1); |
| 3204 |
if (lowerCaseVariableNames) { |
| 3205 |
Ioss::Utils::fixup_name(var_name); |
| 3206 |
} |
| 3207 |
|
| 3208 |
// Read the variable... |
| 3209 |
int ierr = 0; |
| 3210 |
auto var_iter = m_variables[EX_SIDE_SET].find(var_name); |
| 3211 |
if (var_iter == m_variables[EX_SIDE_SET].end()) { |
| 3212 |
IOSS_ERROR(fmt::format("ERROR: Could not find Sideset field '{}'\n", var_name)); |
| 3213 |
} |
| 3214 |
size_t var_index = var_iter->second; |
| 3215 |
assert(var_index > 0); |
| 3216 |
ierr = decomp->get_var(get_file_pointer(), step, EX_SIDE_SET, var_index, id, my_side_count, |
| 3217 |
temp); |
| 3218 |
if (ierr < 0) { |
| 3219 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3220 |
} |
| 3221 |
|
| 3222 |
// Transfer to 'variables' array. |
| 3223 |
size_t j = i; |
| 3224 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 3225 |
int *ivar = static_cast<int *>(variables); |
| 3226 |
for (size_t k = 0; k < my_side_count; k++) { |
| 3227 |
if (is_valid_side[k] == 1) { |
| 3228 |
ivar[j] = static_cast<int>(temp[k]); |
| 3229 |
j += comp_count; |
| 3230 |
} |
| 3231 |
} |
| 3232 |
} |
| 3233 |
else if (field.get_type() == Ioss::Field::INT64) { // FIX 64 UNSAFE |
| 3234 |
int64_t *ivar = static_cast<int64_t *>(variables); |
| 3235 |
for (size_t k = 0; k < my_side_count; k++) { |
| 3236 |
if (is_valid_side[k] == 1) { |
| 3237 |
ivar[j] = static_cast<int64_t>(temp[k]); |
| 3238 |
j += comp_count; |
| 3239 |
} |
| 3240 |
} |
| 3241 |
} |
| 3242 |
else if (field.get_type() == Ioss::Field::REAL) { |
| 3243 |
double *rvar = static_cast<double *>(variables); |
| 3244 |
for (size_t k = 0; k < my_side_count; k++) { |
| 3245 |
if (is_valid_side[k] == 1) { |
| 3246 |
rvar[j] = temp[k]; |
| 3247 |
j += comp_count; |
| 3248 |
} |
| 3249 |
} |
| 3250 |
} |
| 3251 |
else { |
| 3252 |
IOSS_ERROR(fmt::format("IOSS_ERROR: Field storage type must be either integer or double.\n" |
| 3253 |
" Field '{}' is invalid.\n", |
| 3254 |
field.get_name())); |
| 3255 |
} |
| 3256 |
if (i + 1 == comp_count) { |
| 3257 |
num_valid_sides = j / comp_count; |
| 3258 |
} |
| 3259 |
} |
| 3260 |
return num_valid_sides; |
| 3261 |
} |
| 3262 |
|
| 3263 |
int64_t ParallelDatabaseIO::get_side_connectivity(const Ioss::SideBlock *sb, int64_t id, |
| 3264 |
int64_t /*unused*/, void *fconnect, |
| 3265 |
bool map_ids) const |
| 3266 |
{ |
| 3267 |
// Get size of data stored on the file... |
| 3268 |
ex_set set_param[1]; |
| 3269 |
set_param[0].id = id; |
| 3270 |
set_param[0].type = EX_SIDE_SET; |
| 3271 |
set_param[0].entry_list = nullptr; |
| 3272 |
set_param[0].extra_list = nullptr; |
| 3273 |
set_param[0].distribution_factor_list = nullptr; |
| 3274 |
int ierr = ex_get_sets(get_file_pointer(), 1, set_param); |
| 3275 |
if (ierr < 0) { |
| 3276 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3277 |
} |
| 3278 |
|
| 3279 |
int64_t number_sides = set_param[0].num_entry; |
| 3280 |
|
| 3281 |
// Allocate space for element and local side number |
| 3282 |
assert(number_sides > 0); |
| 3283 |
|
| 3284 |
// Need a larger vector to get the entire sideset and then filter down to the correct size... |
| 3285 |
std::vector<char> element(number_sides * int_byte_size_api()); |
| 3286 |
std::vector<char> side(number_sides * int_byte_size_api()); |
| 3287 |
if (int_byte_size_api() == 4) { |
| 3288 |
Ioss::Field elem_field("ids", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 3289 |
number_sides); |
| 3290 |
Ioss::Field side_field("sides", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 3291 |
number_sides); |
| 3292 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 3293 |
reinterpret_cast<int *>(element.data())); |
| 3294 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 3295 |
reinterpret_cast<int *>(side.data())); |
| 3296 |
} |
| 3297 |
else { |
| 3298 |
Ioss::Field elem_field("ids", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, number_sides); |
| 3299 |
Ioss::Field side_field("sides", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, |
| 3300 |
number_sides); |
| 3301 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 3302 |
reinterpret_cast<int64_t *>(element.data())); |
| 3303 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 3304 |
reinterpret_cast<int64_t *>(side.data())); |
| 3305 |
} |
| 3306 |
|
| 3307 |
Ioss::IntVector is_valid_side; |
| 3308 |
Ioss::Utils::calculate_sideblock_membership(is_valid_side, sb, int_byte_size_api(), |
| 3309 |
(void *)element.data(), (void *)side.data(), |
| 3310 |
number_sides, get_region()); |
| 3311 |
|
| 3312 |
std::vector<char> elconnect; |
| 3313 |
int64_t elconsize = 0; // Size of currently allocated connectivity block |
| 3314 |
Ioss::ElementBlock *conn_block = nullptr; // Block that we currently |
| 3315 |
// have connectivity for |
| 3316 |
|
| 3317 |
Ioss::ElementBlock *block = nullptr; |
| 3318 |
|
| 3319 |
int *element32 = nullptr; |
| 3320 |
int64_t *element64 = nullptr; |
| 3321 |
int *side32 = nullptr; |
| 3322 |
int64_t *side64 = nullptr; |
| 3323 |
|
| 3324 |
int *elconn32 = nullptr; |
| 3325 |
int64_t *elconn64 = nullptr; |
| 3326 |
int *fconn32 = nullptr; |
| 3327 |
int64_t *fconn64 = nullptr; |
| 3328 |
|
| 3329 |
if (int_byte_size_api() == 4) { |
| 3330 |
element32 = reinterpret_cast<int *>(element.data()); |
| 3331 |
side32 = reinterpret_cast<int *>(side.data()); |
| 3332 |
fconn32 = reinterpret_cast<int *>(fconnect); |
| 3333 |
} |
| 3334 |
else { |
| 3335 |
element64 = reinterpret_cast<int64_t *>(element.data()); |
| 3336 |
side64 = reinterpret_cast<int64_t *>(side.data()); |
| 3337 |
fconn64 = reinterpret_cast<int64_t *>(fconnect); |
| 3338 |
} |
| 3339 |
|
| 3340 |
Ioss::IntVector side_elem_map; // Maps the side into the elements |
| 3341 |
// connectivity array |
| 3342 |
int64_t current_side = -1; |
| 3343 |
int nelnode = 0; |
| 3344 |
int nfnodes = 0; |
| 3345 |
int ieb = 0; |
| 3346 |
size_t offset = 0; |
| 3347 |
for (int64_t iel = 0; iel < number_sides; iel++) { |
| 3348 |
if (is_valid_side[iel] == 1) { |
| 3349 |
|
| 3350 |
int64_t elem_id = 0; |
| 3351 |
if (int_byte_size_api() == 4) { |
| 3352 |
elem_id = element32[iel]; |
| 3353 |
} |
| 3354 |
else { |
| 3355 |
elem_id = element64[iel]; |
| 3356 |
} |
| 3357 |
|
| 3358 |
// ensure we have correct connectivity |
| 3359 |
block = get_region()->get_element_block(elem_id); |
| 3360 |
if (conn_block != block) { |
| 3361 |
int64_t nelem = block->entity_count(); |
| 3362 |
nelnode = block->topology()->number_nodes(); |
| 3363 |
// Used to map element number into position in connectivity array. |
| 3364 |
// E.g., element 97 is the (97-offset)th element in this block and |
| 3365 |
// is stored in array index (97-offset-1). |
| 3366 |
offset = block->get_offset() + 1; |
| 3367 |
if (elconsize < nelem * nelnode) { |
| 3368 |
elconsize = nelem * nelnode; |
| 3369 |
elconnect.resize(elconsize * int_byte_size_api()); |
| 3370 |
if (int_byte_size_api() == 4) { |
| 3371 |
elconn32 = reinterpret_cast<int *>(elconnect.data()); |
| 3372 |
} |
| 3373 |
else { |
| 3374 |
elconn64 = reinterpret_cast<int64_t *>(elconnect.data()); |
| 3375 |
} |
| 3376 |
} |
| 3377 |
if (map_ids) { |
| 3378 |
get_field_internal(block, block->get_field("connectivity"), elconnect.data(), |
| 3379 |
nelem * nelnode * int_byte_size_api()); |
| 3380 |
} |
| 3381 |
else { |
| 3382 |
get_field_internal(block, block->get_field("connectivity_raw"), elconnect.data(), |
| 3383 |
nelem * nelnode * int_byte_size_api()); |
| 3384 |
} |
| 3385 |
conn_block = block; |
| 3386 |
current_side = -1; |
| 3387 |
} |
| 3388 |
|
| 3389 |
// NOTE: Element connectivity is returned with nodes in global id space if "map_ids" false, |
| 3390 |
// otherwise it is in local space. |
| 3391 |
int64_t side_id = 0; |
| 3392 |
if (int_byte_size_api() == 4) { |
| 3393 |
side_id = side32[iel]; |
| 3394 |
} |
| 3395 |
else { |
| 3396 |
side_id = side64[iel]; |
| 3397 |
} |
| 3398 |
|
| 3399 |
if (current_side != side_id) { |
| 3400 |
side_elem_map = block->topology()->boundary_connectivity(side_id); |
| 3401 |
current_side = side_id; |
| 3402 |
nfnodes = block->topology()->boundary_type(side_id)->number_nodes(); |
| 3403 |
} |
| 3404 |
for (int inode = 0; inode < nfnodes; inode++) { |
| 3405 |
size_t index = (elem_id - offset) * nelnode + side_elem_map[inode]; |
| 3406 |
if (int_byte_size_api() == 4) { |
| 3407 |
fconn32[ieb++] = elconn32[index]; |
| 3408 |
} |
| 3409 |
else { |
| 3410 |
fconn64[ieb++] = elconn64[index]; |
| 3411 |
} |
| 3412 |
} |
| 3413 |
} |
| 3414 |
} |
| 3415 |
return ierr; |
| 3416 |
} |
| 3417 |
|
| 3418 |
// Get distribution factors for the specified side block |
| 3419 |
int64_t ParallelDatabaseIO::get_side_distributions(const Ioss::SideBlock *sb, int64_t id, |
| 3420 |
int64_t my_side_count, double *dist_fact, |
| 3421 |
size_t /* data_size */) const |
| 3422 |
{ |
| 3423 |
// Allocate space for elements and local side numbers |
| 3424 |
// Get size of data stored on the file... |
| 3425 |
|
| 3426 |
auto &set = decomp->get_decomp_set(EX_SIDE_SET, id); |
| 3427 |
int64_t number_sides = set.ioss_count(); |
| 3428 |
int64_t number_distribution_factors = set.df_count(); |
| 3429 |
|
| 3430 |
const Ioss::ElementTopology *ftopo = sb->topology(); |
| 3431 |
int nfnodes = ftopo->number_nodes(); |
| 3432 |
|
| 3433 |
if (set.distributionFactorConstant) { |
| 3434 |
// Fill in the array with the constant value... |
| 3435 |
for (int64_t i = 0; i < nfnodes * my_side_count; i++) { |
| 3436 |
dist_fact[i] = set.distributionFactorValue; |
| 3437 |
} |
| 3438 |
return 0; |
| 3439 |
} |
| 3440 |
|
| 3441 |
// Take care of the easy situation -- If 'side_count' == |
| 3442 |
// 'number_sides' then the sideset is stored in a single sideblock |
| 3443 |
// and all distribution factors on the database are transferred |
| 3444 |
// 1-to-1 into 'dist_fact' array. |
| 3445 |
int64_t entity_count = sb->entity_count(); |
| 3446 |
if (sb->owner()->block_count() == 1 && number_sides == entity_count) { |
| 3447 |
assert(number_sides == 0 || number_distribution_factors % number_sides == 0); |
| 3448 |
assert(number_sides == 0 || number_distribution_factors / number_sides == nfnodes); |
| 3449 |
if (number_sides * nfnodes != number_distribution_factors && |
| 3450 |
number_sides != number_distribution_factors) { |
| 3451 |
IOSS_ERROR(fmt::format("ERROR: SideBlock '{}' has incorrect distribution factor count.\n" |
| 3452 |
"\tThere are {} '{}' sides with {} nodes per side, but there are {}" |
| 3453 |
" distribution factors which is not correct.\n" |
| 3454 |
"\tThere should be either {} or {} distribution factors.\n", |
| 3455 |
sb->name(), number_sides, ftopo->name(), nfnodes, |
| 3456 |
number_distribution_factors, number_sides, number_sides * nfnodes)); |
| 3457 |
} |
| 3458 |
std::string storage = "Real[" + std::to_string(nfnodes) + "]"; |
| 3459 |
Ioss::Field dist("distribution_factors", Ioss::Field::REAL, storage, Ioss::Field::MESH, |
| 3460 |
number_sides); |
| 3461 |
decomp->get_set_mesh_double(get_file_pointer(), EX_SIDE_SET, id, dist, dist_fact); |
| 3462 |
return 0; |
| 3463 |
} |
| 3464 |
|
| 3465 |
std::string storage = "Real[" + std::to_string(nfnodes) + "]"; |
| 3466 |
Ioss::Field field("distribution_factors", Ioss::Field::REAL, storage, Ioss::Field::MESH, |
| 3467 |
number_distribution_factors / nfnodes); |
| 3468 |
std::vector<double> dist(number_distribution_factors); |
| 3469 |
decomp->get_set_mesh_double(get_file_pointer(), EX_SIDE_SET, id, field, dist.data()); |
| 3470 |
|
| 3471 |
// Another easy situation (and common for exodusII) is if the input |
| 3472 |
// distribution factors are all the same value (typically 1). In |
| 3473 |
// that case, we only have to fill in the output array with that |
| 3474 |
// value. |
| 3475 |
{ |
| 3476 |
double value = number_distribution_factors > 0 ? dist[0] : 0.0; |
| 3477 |
bool constant = true; |
| 3478 |
for (auto df : dist) { |
| 3479 |
if (df != value) { |
| 3480 |
constant = false; |
| 3481 |
break; |
| 3482 |
} |
| 3483 |
} |
| 3484 |
|
| 3485 |
constant = util().global_minmax(constant ? 1 : 0, Ioss::ParallelUtils::DO_MIN); |
| 3486 |
|
| 3487 |
if (constant) { |
| 3488 |
if (value == 0.0) { |
| 3489 |
value = 1.0; // Take care of some buggy mesh generators |
| 3490 |
} |
| 3491 |
for (int64_t j = 0; j < my_side_count * nfnodes; j++) { |
| 3492 |
dist_fact[j] = value; |
| 3493 |
} |
| 3494 |
return 0; |
| 3495 |
} |
| 3496 |
} |
| 3497 |
|
| 3498 |
// If we get to here, the underlying sideset contains multiple side |
| 3499 |
// topologies and the distribution factors are non-constant. Need to |
| 3500 |
// allocate space to store all distribution factors and then pull |
| 3501 |
// out those that are applied to sides with the correct topology. |
| 3502 |
|
| 3503 |
// Allocate space for element and local side number (this is bulk |
| 3504 |
// data...) |
| 3505 |
//---- |
| 3506 |
std::vector<char> element(number_sides * int_byte_size_api()); |
| 3507 |
std::vector<char> sides(number_sides * int_byte_size_api()); |
| 3508 |
if (int_byte_size_api() == 4) { |
| 3509 |
Ioss::Field elem_field("ids", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 3510 |
number_sides); |
| 3511 |
Ioss::Field side_field("sides", Ioss::Field::INTEGER, "scalar", Ioss::Field::MESH, |
| 3512 |
number_sides); |
| 3513 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 3514 |
reinterpret_cast<int *>(element.data())); |
| 3515 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 3516 |
reinterpret_cast<int *>(sides.data())); |
| 3517 |
} |
| 3518 |
else { |
| 3519 |
Ioss::Field elem_field("ids", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, number_sides); |
| 3520 |
Ioss::Field side_field("sides", Ioss::Field::INT64, "scalar", Ioss::Field::MESH, |
| 3521 |
number_sides); |
| 3522 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, elem_field, |
| 3523 |
reinterpret_cast<int64_t *>(element.data())); |
| 3524 |
decomp->get_set_mesh_var(get_file_pointer(), EX_SIDE_SET, id, side_field, |
| 3525 |
reinterpret_cast<int64_t *>(sides.data())); |
| 3526 |
} |
| 3527 |
//---- |
| 3528 |
|
| 3529 |
Ioss::IntVector is_valid_side; |
| 3530 |
Ioss::Utils::calculate_sideblock_membership(is_valid_side, sb, int_byte_size_api(), |
| 3531 |
element.data(), sides.data(), number_sides, |
| 3532 |
get_region()); |
| 3533 |
|
| 3534 |
int64_t ieb = 0; // counter for distribution factors in this sideblock |
| 3535 |
int64_t idb = 0; // counter for distribution factors read from database |
| 3536 |
Ioss::ElementBlock *block = nullptr; |
| 3537 |
|
| 3538 |
int *element32 = nullptr; |
| 3539 |
int64_t *element64 = nullptr; |
| 3540 |
int *side32 = nullptr; |
| 3541 |
int64_t *side64 = nullptr; |
| 3542 |
|
| 3543 |
if (int_byte_size_api() == 4) { |
| 3544 |
element32 = reinterpret_cast<int *>(element.data()); |
| 3545 |
side32 = reinterpret_cast<int *>(sides.data()); |
| 3546 |
} |
| 3547 |
else { |
| 3548 |
element64 = reinterpret_cast<int64_t *>(element.data()); |
| 3549 |
side64 = reinterpret_cast<int64_t *>(sides.data()); |
| 3550 |
} |
| 3551 |
|
| 3552 |
for (int64_t iel = 0; iel < number_sides; iel++) { |
| 3553 |
int64_t elem_id = 0; |
| 3554 |
int64_t side_id = 0; |
| 3555 |
if (int_byte_size_api() == 4) { |
| 3556 |
elem_id = element32[iel]; |
| 3557 |
side_id = side32[iel]; |
| 3558 |
} |
| 3559 |
else { |
| 3560 |
elem_id = element64[iel]; |
| 3561 |
side_id = side64[iel]; |
| 3562 |
} |
| 3563 |
|
| 3564 |
if (block == nullptr || !block->contains(elem_id)) { |
| 3565 |
block = get_region()->get_element_block(elem_id); |
| 3566 |
} |
| 3567 |
|
| 3568 |
if (block == nullptr) { |
| 3569 |
IOSS_ERROR(fmt::format( |
| 3570 |
"INTERNAL ERROR: Could not find element block containing element with id {}." |
| 3571 |
" Something is wrong in the Ioex::ParallelDatabaseIO class. Please report.\n", |
| 3572 |
elem_id)); |
| 3573 |
} |
| 3574 |
|
| 3575 |
const Ioss::ElementTopology *topo = block->topology()->boundary_type(side_id); |
| 3576 |
|
| 3577 |
if (topo == nullptr) { |
| 3578 |
IOSS_ERROR("INTERNAL ERROR: Could not find topology of element block boundary. " |
| 3579 |
"Something is wrong in the Ioex::ParallelDatabaseIO class. Please report.\n"); |
| 3580 |
} |
| 3581 |
|
| 3582 |
int nside_nodes = topo->number_nodes(); |
| 3583 |
|
| 3584 |
if (is_valid_side[iel] == 1) { |
| 3585 |
// This side belongs in the sideblock |
| 3586 |
for (int64_t i = 0; i < nside_nodes; i++) { |
| 3587 |
dist_fact[ieb++] = dist[idb++]; |
| 3588 |
} |
| 3589 |
} |
| 3590 |
else { |
| 3591 |
// Skip over unused 'dist' factors |
| 3592 |
idb += topo->number_nodes(); |
| 3593 |
} |
| 3594 |
} |
| 3595 |
|
| 3596 |
assert(ieb == my_side_count * nfnodes); |
| 3597 |
// If the following assert fails, it may be due to bug in Patran |
| 3598 |
// which writes too many distribution factors to the database in a |
| 3599 |
// mixed element case. Note that this is checked earlier also with a |
| 3600 |
// better error message. |
| 3601 |
assert(idb == number_distribution_factors); |
| 3602 |
return 0; |
| 3603 |
} |
| 3604 |
|
| 3605 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, |
| 3606 |
void *data, size_t data_size) const |
| 3607 |
{ |
| 3608 |
return Ioex::BaseDatabaseIO::put_field_internal(reg, field, data, data_size); |
| 3609 |
} |
| 3610 |
|
| 3611 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::NodeBlock *nb, |
| 3612 |
const Ioss::Field &field, void *data, |
| 3613 |
size_t data_size) const |
| 3614 |
{ |
| 3615 |
size_t num_to_get = field.verify(data_size); |
| 3616 |
|
| 3617 |
size_t proc_offset = nb->get_optional_property("_processor_offset", 0); |
| 3618 |
size_t file_count = nb->get_optional_property("locally_owned_count", num_to_get); |
| 3619 |
|
| 3620 |
Ioss::Field::RoleType role = field.get_role(); |
| 3621 |
|
| 3622 |
if (role == Ioss::Field::MESH) { |
| 3623 |
if (field.get_name() == "owning_processor") { |
| 3624 |
// Set the nodeOwningProcessor vector for all nodes on this processor. |
| 3625 |
// Value is the processor that owns the node. |
| 3626 |
|
| 3627 |
// NOTE: The owning_processor field is always int32 |
| 3628 |
nodeOwningProcessor.reserve(num_to_get); |
| 3629 |
int *owned = (int *)data; |
| 3630 |
for (size_t i = 0; i < num_to_get; i++) { |
| 3631 |
nodeOwningProcessor.push_back(owned[i]); |
| 3632 |
} |
| 3633 |
|
| 3634 |
// Now create the "implicit local" to "implicit global" |
| 3635 |
// map which maps data from its local implicit position |
| 3636 |
// to its implicit (1..num_global_node) position in the |
| 3637 |
// global file. This is needed for the global-to-local |
| 3638 |
// mapping of element connectivity and nodeset nodelists. |
| 3639 |
create_implicit_global_map(); |
| 3640 |
} |
| 3641 |
|
| 3642 |
else if (field.get_name() == "mesh_model_coordinates_x") { |
| 3643 |
double *rdata = static_cast<double *>(data); |
| 3644 |
std::vector<double> file_data; |
| 3645 |
file_data.reserve(file_count); |
| 3646 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 3647 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, file_data); |
| 3648 |
|
| 3649 |
int ierr = ex_put_partial_coord_component(get_file_pointer(), proc_offset + 1, file_count, |
| 3650 |
1, file_data.data()); |
| 3651 |
if (ierr < 0) { |
| 3652 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3653 |
} |
| 3654 |
} |
| 3655 |
|
| 3656 |
else if (field.get_name() == "mesh_model_coordinates_y") { |
| 3657 |
double *rdata = static_cast<double *>(data); |
| 3658 |
std::vector<double> file_data; |
| 3659 |
file_data.reserve(file_count); |
| 3660 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 3661 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, file_data); |
| 3662 |
int ierr = ex_put_partial_coord_component(get_file_pointer(), proc_offset + 1, file_count, |
| 3663 |
2, file_data.data()); |
| 3664 |
if (ierr < 0) { |
| 3665 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3666 |
} |
| 3667 |
} |
| 3668 |
|
| 3669 |
else if (field.get_name() == "mesh_model_coordinates_z") { |
| 3670 |
double *rdata = static_cast<double *>(data); |
| 3671 |
std::vector<double> file_data; |
| 3672 |
file_data.reserve(file_count); |
| 3673 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 3674 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, file_data); |
| 3675 |
int ierr = ex_put_partial_coord_component(get_file_pointer(), proc_offset + 1, file_count, |
| 3676 |
3, file_data.data()); |
| 3677 |
if (ierr < 0) { |
| 3678 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3679 |
} |
| 3680 |
} |
| 3681 |
|
| 3682 |
else if (field.get_name() == "mesh_model_coordinates") { |
| 3683 |
// Data required by upper classes store x0, y0, z0, ... xn, yn, zn |
| 3684 |
// Data stored in exodusII file is x0, ..., xn, y0, ..., yn, z0, ..., zn |
| 3685 |
// so we have to allocate some scratch memory to read in the data |
| 3686 |
// and then map into supplied 'data' |
| 3687 |
std::vector<double> x; |
| 3688 |
std::vector<double> y; |
| 3689 |
std::vector<double> z; |
| 3690 |
|
| 3691 |
x.reserve(file_count > 0 ? file_count : 1); |
| 3692 |
if (spatialDimension > 1) { |
| 3693 |
y.reserve(file_count > 0 ? file_count : 1); |
| 3694 |
} |
| 3695 |
if (spatialDimension == 3) { |
| 3696 |
z.reserve(file_count > 0 ? file_count : 1); |
| 3697 |
} |
| 3698 |
|
| 3699 |
// Cast 'data' to correct size -- double |
| 3700 |
double *rdata = static_cast<double *>(data); |
| 3701 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 3702 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, x, 0, spatialDimension); |
| 3703 |
if (spatialDimension > 1) { |
| 3704 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, y, 1, spatialDimension); |
| 3705 |
} |
| 3706 |
if (spatialDimension == 3) { |
| 3707 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, z, 2, spatialDimension); |
| 3708 |
} |
| 3709 |
|
| 3710 |
int ierr = ex_put_partial_coord(get_file_pointer(), proc_offset + 1, file_count, x.data(), |
| 3711 |
y.data(), z.data()); |
| 3712 |
if (ierr < 0) { |
| 3713 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3714 |
} |
| 3715 |
} |
| 3716 |
else if (field.get_name() == "ids") { |
| 3717 |
// The ids coming in are the global ids; their position is the |
| 3718 |
// local id -1 (That is, data[0] contains the global id of local |
| 3719 |
// node 1) |
| 3720 |
|
| 3721 |
// Another 'const-cast' since we are modifying the database just |
| 3722 |
// for efficiency; which the client does not see... |
| 3723 |
handle_node_ids(data, num_to_get, proc_offset, file_count); |
| 3724 |
} |
| 3725 |
else if (field.get_name() == "connectivity") { |
| 3726 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 3727 |
} |
| 3728 |
else if (field.get_name() == "connectivity_raw") { |
| 3729 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 3730 |
} |
| 3731 |
else if (field.get_name() == "node_connectivity_status") { |
| 3732 |
// Do nothing, input only field. |
| 3733 |
} |
| 3734 |
else if (field.get_name() == "implicit_ids") { |
| 3735 |
// Do nothing, input only field. |
| 3736 |
} |
| 3737 |
else { |
| 3738 |
return Ioss::Utils::field_warning(nb, field, "mesh output"); |
| 3739 |
} |
| 3740 |
} |
| 3741 |
else if (role == Ioss::Field::TRANSIENT) { |
| 3742 |
// Check if the specified field exists on this node block. |
| 3743 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 3744 |
// exist on the database as scalars with the appropriate |
| 3745 |
// extensions. |
| 3746 |
|
| 3747 |
// Transfer each component of the variable into 'data' and then |
| 3748 |
// output. Need temporary storage area of size 'number of |
| 3749 |
// nodes in this block. |
| 3750 |
write_nodal_transient_field(field, nb, num_to_get, data); |
| 3751 |
} |
| 3752 |
else if (role == Ioss::Field::REDUCTION) { |
| 3753 |
store_reduction_field(field, nb, data); |
| 3754 |
} |
| 3755 |
return num_to_get; |
| 3756 |
} |
| 3757 |
|
| 3758 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, |
| 3759 |
void *data, size_t data_size) const |
| 3760 |
{ |
| 3761 |
{ |
| 3762 |
Ioss::SerializeIO serializeIO_(this); |
| 3763 |
|
| 3764 |
size_t num_to_get = field.verify(data_size); |
| 3765 |
if (num_to_get > 0) { |
| 3766 |
|
| 3767 |
Ioss::Field::RoleType role = field.get_role(); |
| 3768 |
|
| 3769 |
if (role == Ioss::Field::MESH) { |
| 3770 |
if (field.get_name() == "ids") { |
| 3771 |
// The ids coming in are the global ids; their position is the |
| 3772 |
// local id -1 (That is, data[0] contains the global id of local |
| 3773 |
// node 1) |
| 3774 |
// handle_node_ids(data, num_to_get); |
| 3775 |
} |
| 3776 |
else if (field.get_name() == "connectivity") { |
| 3777 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 3778 |
} |
| 3779 |
else if (field.get_name() == "connectivity_raw") { |
| 3780 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 3781 |
} |
| 3782 |
else if (field.get_name() == "node_connectivity_status") { |
| 3783 |
// Do nothing, input only field. |
| 3784 |
} |
| 3785 |
else if (field.get_name() == "implicit_ids") { |
| 3786 |
// Do nothing, input only field. |
| 3787 |
} |
| 3788 |
else { |
| 3789 |
return Ioss::Utils::field_warning(blob, field, "mesh output"); |
| 3790 |
} |
| 3791 |
} |
| 3792 |
else if (role == Ioss::Field::TRANSIENT) { |
| 3793 |
// Check if the specified field exists on this node block. |
| 3794 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 3795 |
// exist on the database as scalars with the appropriate |
| 3796 |
// extensions. |
| 3797 |
|
| 3798 |
// Transfer each component of the variable into 'data' and then |
| 3799 |
// output. Need temporary storage area of size 'number of |
| 3800 |
// nodes in this block. |
| 3801 |
write_entity_transient_field(field, blob, num_to_get, data); |
| 3802 |
} |
| 3803 |
else if (role == Ioss::Field::REDUCTION) { |
| 3804 |
store_reduction_field(field, blob, data); |
| 3805 |
} |
| 3806 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 3807 |
num_to_get = write_attribute_field(field, blob, data); |
| 3808 |
} |
| 3809 |
} |
| 3810 |
return num_to_get; |
| 3811 |
} |
| 3812 |
} |
| 3813 |
|
| 3814 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::Assembly *assembly, |
| 3815 |
const Ioss::Field &field, void *data, |
| 3816 |
size_t data_size) const |
| 3817 |
{ |
| 3818 |
{ |
| 3819 |
Ioss::SerializeIO serializeIO_(this); |
| 3820 |
|
| 3821 |
size_t num_to_get = field.verify(data_size); |
| 3822 |
if (num_to_get > 0) { |
| 3823 |
|
| 3824 |
Ioss::Field::RoleType role = field.get_role(); |
| 3825 |
|
| 3826 |
if (role == Ioss::Field::MESH) { |
| 3827 |
if (field.get_name() == "ids") { |
| 3828 |
// The ids coming in are the global ids; their position is the |
| 3829 |
// local id -1 (That is, data[0] contains the global id of local |
| 3830 |
// node 1) |
| 3831 |
// handle_node_ids(data, num_to_get); |
| 3832 |
} |
| 3833 |
else if (field.get_name() == "connectivity") { |
| 3834 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 3835 |
} |
| 3836 |
else if (field.get_name() == "connectivity_raw") { |
| 3837 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 3838 |
} |
| 3839 |
else if (field.get_name() == "node_connectivity_status") { |
| 3840 |
// Do nothing, input only field. |
| 3841 |
} |
| 3842 |
else if (field.get_name() == "implicit_ids") { |
| 3843 |
// Do nothing, input only field. |
| 3844 |
} |
| 3845 |
else { |
| 3846 |
return Ioss::Utils::field_warning(assembly, field, "mesh output"); |
| 3847 |
} |
| 3848 |
} |
| 3849 |
else if (role == Ioss::Field::TRANSIENT) { |
| 3850 |
// Check if the specified field exists on this node block. |
| 3851 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 3852 |
// exist on the database as scalars with the appropriate |
| 3853 |
// extensions. |
| 3854 |
|
| 3855 |
// Transfer each component of the variable into 'data' and then |
| 3856 |
// output. Need temporary storage area of size 'number of |
| 3857 |
// nodes in this block. |
| 3858 |
write_entity_transient_field(field, assembly, num_to_get, data); |
| 3859 |
} |
| 3860 |
else if (role == Ioss::Field::REDUCTION) { |
| 3861 |
store_reduction_field(field, assembly, data); |
| 3862 |
} |
| 3863 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 3864 |
num_to_get = write_attribute_field(field, assembly, data); |
| 3865 |
} |
| 3866 |
} |
| 3867 |
return num_to_get; |
| 3868 |
} |
| 3869 |
} |
| 3870 |
|
| 3871 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::ElementBlock *eb, |
| 3872 |
const Ioss::Field &field, void *data, |
| 3873 |
size_t data_size) const |
| 3874 |
{ |
| 3875 |
size_t num_to_get = field.verify(data_size); |
| 3876 |
|
| 3877 |
int ierr = 0; |
| 3878 |
|
| 3879 |
// Get the element block id and element count |
| 3880 |
int64_t id = Ioex::get_id(eb, &ids_); |
| 3881 |
int64_t my_element_count = eb->entity_count(); |
| 3882 |
Ioss::Field::RoleType role = field.get_role(); |
| 3883 |
|
| 3884 |
auto proc_offset = eb->get_optional_property("_processor_offset", 0); |
| 3885 |
auto file_count = eb->get_optional_property("locally_owned_count", num_to_get); |
| 3886 |
|
| 3887 |
if (role == Ioss::Field::MESH) { |
| 3888 |
// Handle the MESH fields required for an ExodusII file model. |
| 3889 |
// (The 'genesis' portion) |
| 3890 |
if (field.get_name() == "connectivity") { |
| 3891 |
// Map element connectivity from global node id to local node id. |
| 3892 |
int element_nodes = eb->topology()->number_nodes(); |
| 3893 |
|
| 3894 |
// Maps global to local |
| 3895 |
nodeMap.reverse_map_data(data, field, num_to_get * element_nodes); |
| 3896 |
|
| 3897 |
// Maps local to "global_implicit" |
| 3898 |
if (int_byte_size_api() == 4) { |
| 3899 |
map_local_to_global_implicit(reinterpret_cast<int *>(data), num_to_get * element_nodes, |
| 3900 |
nodeGlobalImplicitMap); |
| 3901 |
} |
| 3902 |
else { |
| 3903 |
map_local_to_global_implicit(reinterpret_cast<int64_t *>(data), |
| 3904 |
num_to_get * element_nodes, nodeGlobalImplicitMap); |
| 3905 |
} |
| 3906 |
|
| 3907 |
ierr = ex_put_partial_conn(get_file_pointer(), EX_ELEM_BLOCK, id, proc_offset + 1, |
| 3908 |
file_count, data, nullptr, nullptr); |
| 3909 |
if (ierr < 0) { |
| 3910 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3911 |
} |
| 3912 |
} |
| 3913 |
else if (field.get_name() == "connectivity_edge") { |
| 3914 |
// Map element connectivity from global edge id to local edge id. |
| 3915 |
int element_edges = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 3916 |
edgeMap.reverse_map_data(data, field, num_to_get * element_edges); |
| 3917 |
ierr = ex_put_conn(get_file_pointer(), EX_ELEM_BLOCK, id, nullptr, data, nullptr); |
| 3918 |
if (ierr < 0) { |
| 3919 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3920 |
} |
| 3921 |
} |
| 3922 |
else if (field.get_name() == "connectivity_face") { |
| 3923 |
// Map element connectivity from global face id to local face id. |
| 3924 |
int element_faces = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 3925 |
faceMap.reverse_map_data(data, field, num_to_get * element_faces); |
| 3926 |
ierr = ex_put_conn(get_file_pointer(), EX_ELEM_BLOCK, id, nullptr, nullptr, data); |
| 3927 |
if (ierr < 0) { |
| 3928 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3929 |
} |
| 3930 |
} |
| 3931 |
else if (field.get_name() == "connectivity_raw") { |
| 3932 |
// Element connectivity is already in local node id, map local to "global_implicit" |
| 3933 |
int element_nodes = eb->topology()->number_nodes(); |
| 3934 |
if (int_byte_size_api() == 4) { |
| 3935 |
map_local_to_global_implicit(reinterpret_cast<int *>(data), num_to_get * element_nodes, |
| 3936 |
nodeGlobalImplicitMap); |
| 3937 |
} |
| 3938 |
else { |
| 3939 |
map_local_to_global_implicit(reinterpret_cast<int64_t *>(data), |
| 3940 |
num_to_get * element_nodes, nodeGlobalImplicitMap); |
| 3941 |
} |
| 3942 |
|
| 3943 |
ierr = ex_put_partial_conn(get_file_pointer(), EX_ELEM_BLOCK, id, proc_offset + 1, |
| 3944 |
file_count, data, nullptr, nullptr); |
| 3945 |
if (ierr < 0) { |
| 3946 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 3947 |
} |
| 3948 |
} |
| 3949 |
else if (field.get_name() == "ids") { |
| 3950 |
size_t glob_map_offset = eb->get_property("global_map_offset").get_int(); |
| 3951 |
handle_element_ids(eb, data, num_to_get, glob_map_offset + proc_offset, file_count); |
| 3952 |
} |
| 3953 |
else if (field.get_name() == "implicit_ids") { |
| 3954 |
// Do nothing, input only field. |
| 3955 |
} |
| 3956 |
} |
| 3957 |
else if (role == Ioss::Field::MAP) { |
| 3958 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 3959 |
for (int comp = 0; comp < comp_count; comp++) { |
| 3960 |
std::vector<char> component(my_element_count * int_byte_size_api()); |
| 3961 |
|
| 3962 |
if (int_byte_size_api() == 4) { |
| 3963 |
int *data32 = reinterpret_cast<int *>(data); |
| 3964 |
int *comp32 = reinterpret_cast<int *>(component.data()); |
| 3965 |
|
| 3966 |
int index = comp; |
| 3967 |
for (int64_t i = 0; i < my_element_count; i++) { |
| 3968 |
comp32[i] = data32[index]; |
| 3969 |
index += comp_count; |
| 3970 |
} |
| 3971 |
} |
| 3972 |
else { |
| 3973 |
int64_t *data64 = reinterpret_cast<int64_t *>(data); |
| 3974 |
int64_t *comp64 = reinterpret_cast<int64_t *>(component.data()); |
| 3975 |
|
| 3976 |
int index = comp; |
| 3977 |
for (int64_t i = 0; i < my_element_count; i++) { |
| 3978 |
comp64[i] = data64[index]; |
| 3979 |
index += comp_count; |
| 3980 |
} |
| 3981 |
} |
| 3982 |
int map_index = -1 * (field.get_index() + |
| 3983 |
comp); // Negative since specifying index, not id to exodus API. |
| 3984 |
|
| 3985 |
size_t global_map_offset = eb->get_property("global_map_offset").get_int(); |
| 3986 |
ierr = ex_put_partial_num_map(get_file_pointer(), EX_ELEM_MAP, map_index, |
| 3987 |
global_map_offset + proc_offset + 1, file_count, |
| 3988 |
component.data()); |
| 3989 |
} |
| 3990 |
} |
| 3991 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 3992 |
num_to_get = write_attribute_field(field, eb, data); |
| 3993 |
} |
| 3994 |
else if (role == Ioss::Field::TRANSIENT) { |
| 3995 |
// Check if the specified field exists on this element block. |
| 3996 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 3997 |
// exist on the database as scalars with the appropriate |
| 3998 |
// extensions. |
| 3999 |
|
| 4000 |
// Transfer each component of the variable into 'data' and then |
| 4001 |
// output. Need temporary storage area of size 'number of |
| 4002 |
// elements in this block. |
| 4003 |
auto global_entity_count = eb->get_property("global_entity_count").get_int(); |
| 4004 |
if (global_entity_count > 0) { |
| 4005 |
write_entity_transient_field(field, eb, my_element_count, data); |
| 4006 |
} |
| 4007 |
} |
| 4008 |
else if (role == Ioss::Field::REDUCTION) { |
| 4009 |
store_reduction_field(field, eb, data); |
| 4010 |
} |
| 4011 |
return num_to_get; |
| 4012 |
} |
| 4013 |
|
| 4014 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::FaceBlock *eb, |
| 4015 |
const Ioss::Field &field, void *data, |
| 4016 |
size_t data_size) const |
| 4017 |
{ |
| 4018 |
size_t num_to_get = field.verify(data_size); |
| 4019 |
|
| 4020 |
int ierr = 0; |
| 4021 |
|
| 4022 |
// Get the face block id and face count |
| 4023 |
int64_t id = Ioex::get_id(eb, &ids_); |
| 4024 |
int64_t my_face_count = eb->entity_count(); |
| 4025 |
Ioss::Field::RoleType role = field.get_role(); |
| 4026 |
|
| 4027 |
if (role == Ioss::Field::MESH) { |
| 4028 |
// Handle the MESH fields required for an ExodusII file model. |
| 4029 |
// (The 'genesis' portion) |
| 4030 |
if (field.get_name() == "connectivity") { |
| 4031 |
if (my_face_count > 0) { |
| 4032 |
// Map face connectivity from global node id to local node id. |
| 4033 |
int face_nodes = eb->topology()->number_nodes(); |
| 4034 |
nodeMap.reverse_map_data(data, field, num_to_get * face_nodes); |
| 4035 |
ierr = ex_put_conn(get_file_pointer(), EX_FACE_BLOCK, id, data, nullptr, nullptr); |
| 4036 |
if (ierr < 0) { |
| 4037 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4038 |
} |
| 4039 |
} |
| 4040 |
} |
| 4041 |
else if (field.get_name() == "connectivity_edge") { |
| 4042 |
if (my_face_count > 0) { |
| 4043 |
// Map face connectivity from global edge id to local edge id. |
| 4044 |
// Do it in 'data' ... |
| 4045 |
int face_edges = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 4046 |
edgeMap.reverse_map_data(data, field, num_to_get * face_edges); |
| 4047 |
ierr = ex_put_conn(get_file_pointer(), EX_FACE_BLOCK, id, nullptr, data, nullptr); |
| 4048 |
if (ierr < 0) { |
| 4049 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4050 |
} |
| 4051 |
} |
| 4052 |
} |
| 4053 |
else if (field.get_name() == "connectivity_raw") { |
| 4054 |
// Do nothing, input only field. |
| 4055 |
} |
| 4056 |
else if (field.get_name() == "ids") { |
| 4057 |
handle_face_ids(eb, data, num_to_get); |
| 4058 |
} |
| 4059 |
else { |
| 4060 |
num_to_get = Ioss::Utils::field_warning(eb, field, "mesh output"); |
| 4061 |
} |
| 4062 |
} |
| 4063 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 4064 |
num_to_get = write_attribute_field(field, eb, data); |
| 4065 |
} |
| 4066 |
else if (role == Ioss::Field::TRANSIENT) { |
| 4067 |
// Check if the specified field exists on this face block. |
| 4068 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 4069 |
// exist on the database as scalars with the appropriate |
| 4070 |
// extensions. |
| 4071 |
|
| 4072 |
// Transfer each component of the variable into 'data' and then |
| 4073 |
// output. Need temporary storage area of size 'number of |
| 4074 |
// faces in this block. |
| 4075 |
write_entity_transient_field(field, eb, my_face_count, data); |
| 4076 |
} |
| 4077 |
else if (role == Ioss::Field::REDUCTION) { |
| 4078 |
store_reduction_field(field, eb, data); |
| 4079 |
} |
| 4080 |
return num_to_get; |
| 4081 |
} |
| 4082 |
|
| 4083 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::EdgeBlock *eb, |
| 4084 |
const Ioss::Field &field, void *data, |
| 4085 |
size_t data_size) const |
| 4086 |
{ |
| 4087 |
size_t num_to_get = field.verify(data_size); |
| 4088 |
|
| 4089 |
int ierr = 0; |
| 4090 |
|
| 4091 |
// Get the edge block id and edge count |
| 4092 |
int64_t id = Ioex::get_id(eb, &ids_); |
| 4093 |
int64_t my_edge_count = eb->entity_count(); |
| 4094 |
Ioss::Field::RoleType role = field.get_role(); |
| 4095 |
|
| 4096 |
if (role == Ioss::Field::MESH) { |
| 4097 |
// Handle the MESH fields required for an ExodusII file model. (The 'genesis' portion) |
| 4098 |
if (field.get_name() == "connectivity") { |
| 4099 |
if (my_edge_count > 0) { |
| 4100 |
// Map edge connectivity from global node id to local node id. |
| 4101 |
int edge_nodes = eb->topology()->number_nodes(); |
| 4102 |
nodeMap.reverse_map_data(data, field, num_to_get * edge_nodes); |
| 4103 |
ierr = ex_put_conn(get_file_pointer(), EX_EDGE_BLOCK, id, data, nullptr, nullptr); |
| 4104 |
if (ierr < 0) { |
| 4105 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4106 |
} |
| 4107 |
} |
| 4108 |
} |
| 4109 |
else if (field.get_name() == "connectivity_raw") { |
| 4110 |
// Do nothing, input only field. |
| 4111 |
} |
| 4112 |
else if (field.get_name() == "ids") { |
| 4113 |
handle_edge_ids(eb, data, num_to_get); |
| 4114 |
} |
| 4115 |
else { |
| 4116 |
num_to_get = Ioss::Utils::field_warning(eb, field, "mesh output"); |
| 4117 |
} |
| 4118 |
} |
| 4119 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 4120 |
num_to_get = write_attribute_field(field, eb, data); |
| 4121 |
} |
| 4122 |
else if (role == Ioss::Field::TRANSIENT) { |
| 4123 |
// Check if the specified field exists on this edge block. |
| 4124 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 4125 |
// exist on the database as scalars with the appropriate |
| 4126 |
// extensions. |
| 4127 |
|
| 4128 |
// Transfer each component of the variable into 'data' and then |
| 4129 |
// output. Need temporary storage area of size 'number of |
| 4130 |
// edges in this block. |
| 4131 |
write_entity_transient_field(field, eb, my_edge_count, data); |
| 4132 |
} |
| 4133 |
else if (role == Ioss::Field::REDUCTION) { |
| 4134 |
store_reduction_field(field, eb, data); |
| 4135 |
} |
| 4136 |
return num_to_get; |
| 4137 |
} |
| 4138 |
|
| 4139 |
int64_t ParallelDatabaseIO::handle_node_ids(void *ids, int64_t num_to_get, size_t /* offset */, |
| 4140 |
size_t /*count*/) const |
| 4141 |
{ |
| 4142 |
/*! |
| 4143 |
* There are two modes we need to support in this routine: |
| 4144 |
* 1. Initial definition of node map (local->global) and |
| 4145 |
* nodeMap.reverse (global->local). |
| 4146 |
* 2. Redefinition of node map via 'reordering' of the original |
| 4147 |
* map when the nodes on this processor are the same, but their |
| 4148 |
* order is changed (or count because of ghosting) |
| 4149 |
* |
| 4150 |
* So, there will be two maps the 'nodeMap.map' map is a 'direct lookup' |
| 4151 |
* map which maps current local position to global id and the |
| 4152 |
* 'nodeMap.reverse' is an associative lookup which maps the |
| 4153 |
* global id to 'original local'. There is also a |
| 4154 |
* 'nodeMap.reorder' which is direct lookup and maps current local |
| 4155 |
* position to original local. |
| 4156 |
|
| 4157 |
* The ids coming in are the global ids; their position is the |
| 4158 |
* "local id-1" (That is, data[0] contains the global id of local |
| 4159 |
* node 1 in this node block). |
| 4160 |
* |
| 4161 |
* int local_position = nodeMap.reverse[NodeMap[i+1]] |
| 4162 |
* (the nodeMap.map and nodeMap.reverse are 1-based) |
| 4163 |
* |
| 4164 |
* To determine which map to update on a call to this function, we |
| 4165 |
* use the following heuristics: |
| 4166 |
* -- If the database state is 'STATE_MODEL:', then update the |
| 4167 |
* 'nodeMap.reverse' and 'nodeMap.map' |
| 4168 |
* |
| 4169 |
* -- If the database state is not STATE_MODEL, then leave the |
| 4170 |
* 'nodeMap.reverse' and 'nodeMap.map' alone since they correspond to the |
| 4171 |
* information already written to the database. [May want to add a |
| 4172 |
* STATE_REDEFINE_MODEL] |
| 4173 |
* |
| 4174 |
* -- In both cases, update the nodeMap.reorder |
| 4175 |
* |
| 4176 |
* NOTE: The mapping is done on TRANSIENT fields only; MODEL fields |
| 4177 |
* should be in the original order... |
| 4178 |
*/ |
| 4179 |
nodeMap.set_size(num_to_get); |
| 4180 |
|
| 4181 |
bool in_define = (dbState == Ioss::STATE_MODEL) || (dbState == Ioss::STATE_DEFINE_MODEL); |
| 4182 |
if (int_byte_size_api() == 4) { |
| 4183 |
nodeMap.set_map(static_cast<int *>(ids), num_to_get, 0, in_define); |
| 4184 |
} |
| 4185 |
else { |
| 4186 |
nodeMap.set_map(static_cast<int64_t *>(ids), num_to_get, 0, in_define); |
| 4187 |
} |
| 4188 |
|
| 4189 |
nodeMap.set_defined(true); |
| 4190 |
return num_to_get; |
| 4191 |
} |
| 4192 |
|
| 4193 |
int64_t ParallelDatabaseIO::handle_element_ids(const Ioss::ElementBlock *eb, void *ids, |
| 4194 |
size_t num_to_get, size_t offset, |
| 4195 |
size_t count) const |
| 4196 |
{ |
| 4197 |
if (dbState == Ioss::STATE_MODEL) { |
| 4198 |
if (elemGlobalImplicitMap.empty()) { |
| 4199 |
elemGlobalImplicitMap.resize(elementCount); |
| 4200 |
} |
| 4201 |
// Build the implicit_global map used to map an elements |
| 4202 |
// local-implicit position to the global-implicit |
| 4203 |
// position. Primarily used for sideset elements. 'count' |
| 4204 |
// Elements starting at 'eb_offset' map to the global implicit |
| 4205 |
// position of 'offset' |
| 4206 |
int64_t eb_offset = eb->get_offset(); |
| 4207 |
for (size_t i = 0; i < count; i++) { |
| 4208 |
elemGlobalImplicitMap[eb_offset + i] = offset + i + 1; |
| 4209 |
} |
| 4210 |
elemGlobalImplicitMapDefined = true; |
| 4211 |
} |
| 4212 |
|
| 4213 |
elemMap.set_size(elementCount); |
| 4214 |
return handle_block_ids(eb, EX_ELEM_MAP, elemMap, ids, num_to_get, offset); |
| 4215 |
} |
| 4216 |
|
| 4217 |
int64_t ParallelDatabaseIO::handle_face_ids(const Ioss::FaceBlock *eb, void *ids, |
| 4218 |
size_t num_to_get) const |
| 4219 |
{ |
| 4220 |
faceMap.set_size(faceCount); |
| 4221 |
return handle_block_ids(eb, EX_FACE_MAP, faceMap, ids, num_to_get, 0); |
| 4222 |
} |
| 4223 |
|
| 4224 |
int64_t ParallelDatabaseIO::handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, |
| 4225 |
size_t num_to_get) const |
| 4226 |
{ |
| 4227 |
edgeMap.set_size(edgeCount); |
| 4228 |
return handle_block_ids(eb, EX_EDGE_MAP, edgeMap, ids, num_to_get, 0); |
| 4229 |
} |
| 4230 |
|
| 4231 |
void ParallelDatabaseIO::write_nodal_transient_field(const Ioss::Field &field, |
| 4232 |
const Ioss::NodeBlock *nb, int64_t count, |
| 4233 |
void *variables) const |
| 4234 |
{ |
| 4235 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 4236 |
assert(ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::INTEGER || |
| 4237 |
ioss_type == Ioss::Field::INT64 || ioss_type == Ioss::Field::COMPLEX); |
| 4238 |
|
| 4239 |
if (ioss_type == Ioss::Field::INT64) { |
| 4240 |
Ioss::Utils::check_int_to_real_overflow(field, (int64_t *)variables, count); |
| 4241 |
} |
| 4242 |
|
| 4243 |
// Note that if the field's basic type is COMPLEX, then each component of |
| 4244 |
// the VariableType is a complex variable consisting of a real and |
| 4245 |
// imaginary part. Since exodus cannot handle complex variables, |
| 4246 |
// we have to output a (real and imaginary) X (number of |
| 4247 |
// components) fields. For example, if V is a 3d vector of complex |
| 4248 |
// data, the data in the 'variables' array are v_x, v.im_x, v_y, |
| 4249 |
// v.im_y, v_z, v.im_z which need to be output in six separate |
| 4250 |
// exodus fields. These fields were already defined in |
| 4251 |
// "write_results_metadata". |
| 4252 |
|
| 4253 |
std::vector<double> temp(count); |
| 4254 |
|
| 4255 |
int step = get_current_state(); |
| 4256 |
step = get_database_step(step); |
| 4257 |
|
| 4258 |
// get number of components, cycle through each component |
| 4259 |
// and add suffix to base 'field_name'. Look up index |
| 4260 |
// of this name in 'm_variables[EX_NODE_BLOCK]' map |
| 4261 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 4262 |
|
| 4263 |
int re_im = 1; |
| 4264 |
if (ioss_type == Ioss::Field::COMPLEX) { |
| 4265 |
re_im = 2; |
| 4266 |
} |
| 4267 |
for (int complex_comp = 0; complex_comp < re_im; complex_comp++) { |
| 4268 |
std::string field_name = field.get_name(); |
| 4269 |
if (re_im == 2) { |
| 4270 |
field_name += complex_suffix[complex_comp]; |
| 4271 |
} |
| 4272 |
|
| 4273 |
for (int i = 0; i < comp_count; i++) { |
| 4274 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::OUTPUT, i + 1); |
| 4275 |
|
| 4276 |
auto var_iter = m_variables[EX_NODE_BLOCK].find(var_name); |
| 4277 |
if (var_iter == m_variables[EX_NODE_BLOCK].end()) { |
| 4278 |
IOSS_ERROR(fmt::format("ERROR: Could not find nodal variable '{}'\n", var_name)); |
| 4279 |
} |
| 4280 |
|
| 4281 |
int var_index = var_iter->second; |
| 4282 |
|
| 4283 |
size_t begin_offset = (re_im * i) + complex_comp; |
| 4284 |
size_t stride = re_im * comp_count; |
| 4285 |
size_t num_out = 0; |
| 4286 |
|
| 4287 |
if (ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::COMPLEX) { |
| 4288 |
num_out = nodeMap.map_field_to_db_scalar_order(static_cast<double *>(variables), temp, |
| 4289 |
begin_offset, count, stride, 0); |
| 4290 |
} |
| 4291 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 4292 |
num_out = nodeMap.map_field_to_db_scalar_order(static_cast<int *>(variables), temp, |
| 4293 |
begin_offset, count, stride, 0); |
| 4294 |
} |
| 4295 |
else if (ioss_type == Ioss::Field::INT64) { |
| 4296 |
num_out = nodeMap.map_field_to_db_scalar_order(static_cast<int64_t *>(variables), temp, |
| 4297 |
begin_offset, count, stride, 0); |
| 4298 |
} |
| 4299 |
|
| 4300 |
if (num_out != static_cast<size_t>(nodeCount)) { |
| 4301 |
IOSS_ERROR(fmt::format( |
| 4302 |
"ERROR: Problem outputting nodal variable '{}' with index = {} to file '{}' on " |
| 4303 |
"processor {}\n" |
| 4304 |
"\tShould have output {} values, but instead only output {} values.\n", |
| 4305 |
var_name, var_index, get_filename(), myProcessor, fmt::group_digits(nodeCount), |
| 4306 |
fmt::group_digits(num_out))); |
| 4307 |
} |
| 4308 |
|
| 4309 |
// Write the variable... |
| 4310 |
size_t proc_offset = nb->get_optional_property("_processor_offset", 0); |
| 4311 |
size_t file_count = nb->get_optional_property("locally_owned_count", num_out); |
| 4312 |
|
| 4313 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 4314 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, temp.data()); |
| 4315 |
int ierr = ex_put_partial_var(get_file_pointer(), step, EX_NODE_BLOCK, var_index, 0, |
| 4316 |
proc_offset + 1, file_count, temp.data()); |
| 4317 |
if (ierr < 0) { |
| 4318 |
std::ostringstream errmsg; |
| 4319 |
fmt::print(errmsg, |
| 4320 |
"Problem outputting nodal variable '{}' with index = {} to file '{}' on " |
| 4321 |
"processor {}\n", |
| 4322 |
var_name, var_index, get_filename(), myProcessor); |
| 4323 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__, errmsg.str()); |
| 4324 |
} |
| 4325 |
} |
| 4326 |
} |
| 4327 |
} |
| 4328 |
|
| 4329 |
void ParallelDatabaseIO::write_entity_transient_field(const Ioss::Field &field, |
| 4330 |
const Ioss::GroupingEntity *ge, |
| 4331 |
int64_t count, void *variables) const |
| 4332 |
{ |
| 4333 |
static Ioss::Map non_element_map; // Used as an empty map for ge->type() != element block. |
| 4334 |
std::vector<double> temp(count); |
| 4335 |
|
| 4336 |
int step = get_current_state(); |
| 4337 |
step = get_database_step(step); |
| 4338 |
|
| 4339 |
Ioss::Map *map = nullptr; |
| 4340 |
int64_t eb_offset = 0; |
| 4341 |
if (ge->type() == Ioss::ELEMENTBLOCK) { |
| 4342 |
const Ioss::ElementBlock *elb = dynamic_cast<const Ioss::ElementBlock *>(ge); |
| 4343 |
Ioss::Utils::check_dynamic_cast(elb); |
| 4344 |
eb_offset = elb->get_offset(); |
| 4345 |
map = &elemMap; |
| 4346 |
} |
| 4347 |
else { |
| 4348 |
map = &non_element_map; |
| 4349 |
} |
| 4350 |
|
| 4351 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 4352 |
assert(ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::INTEGER || |
| 4353 |
ioss_type == Ioss::Field::INT64 || ioss_type == Ioss::Field::COMPLEX); |
| 4354 |
|
| 4355 |
if (ioss_type == Ioss::Field::INT64) { |
| 4356 |
Ioss::Utils::check_int_to_real_overflow(field, (int64_t *)variables, count); |
| 4357 |
} |
| 4358 |
|
| 4359 |
// Note that if the field's basic type is COMPLEX, then each component of |
| 4360 |
// the VariableType is a complex variable consisting of a real and |
| 4361 |
// imaginary part. Since exodus cannot handle complex variables, |
| 4362 |
// we have to output a (real and imaginary) X (number of |
| 4363 |
// components) fields. For example, if V is a 3d vector of complex |
| 4364 |
// data, the data in the 'variables' array are v_x, v.im_x, v_y, |
| 4365 |
// v.im_y, v_z, v.im_z which need to be output in six separate |
| 4366 |
// exodus fields. These fields were already defined in |
| 4367 |
// "write_results_metadata". |
| 4368 |
|
| 4369 |
// get number of components, cycle through each component |
| 4370 |
// and add suffix to base 'field_name'. Look up index |
| 4371 |
// of this name in 'm_variables[type]' map |
| 4372 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 4373 |
ex_entity_type type = Ioex::map_exodus_type(ge->type()); |
| 4374 |
|
| 4375 |
int re_im = 1; |
| 4376 |
if (ioss_type == Ioss::Field::COMPLEX) { |
| 4377 |
re_im = 2; |
| 4378 |
} |
| 4379 |
for (int complex_comp = 0; complex_comp < re_im; complex_comp++) { |
| 4380 |
std::string field_name = field.get_name(); |
| 4381 |
if (re_im == 2) { |
| 4382 |
field_name += complex_suffix[complex_comp]; |
| 4383 |
} |
| 4384 |
|
| 4385 |
for (int i = 0; i < comp_count; i++) { |
| 4386 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::OUTPUT, i + 1); |
| 4387 |
|
| 4388 |
auto var_iter = m_variables[type].find(var_name); |
| 4389 |
if (var_iter == m_variables[type].end()) { |
| 4390 |
IOSS_ERROR(fmt::format("ERROR: Could not find field '{}'\n", var_name)); |
| 4391 |
} |
| 4392 |
int var_index = var_iter->second; |
| 4393 |
assert(var_index > 0); |
| 4394 |
|
| 4395 |
// var is a [count,comp,re_im] array; re_im = 1(real) or 2(complex) |
| 4396 |
// beg_offset = (re_im*i)+complex_comp |
| 4397 |
// number_values = count |
| 4398 |
// stride = re_im*comp_count |
| 4399 |
int64_t begin_offset = (re_im * i) + complex_comp; |
| 4400 |
int64_t stride = re_im * comp_count; |
| 4401 |
|
| 4402 |
if (ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::COMPLEX) { |
| 4403 |
map->map_field_to_db_scalar_order(static_cast<double *>(variables), temp, begin_offset, |
| 4404 |
count, stride, eb_offset); |
| 4405 |
} |
| 4406 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 4407 |
map->map_field_to_db_scalar_order(static_cast<int *>(variables), temp, begin_offset, |
| 4408 |
count, stride, eb_offset); |
| 4409 |
} |
| 4410 |
else if (ioss_type == Ioss::Field::INT64) { |
| 4411 |
map->map_field_to_db_scalar_order(static_cast<int64_t *>(variables), temp, begin_offset, |
| 4412 |
count, stride, eb_offset); |
| 4413 |
} |
| 4414 |
|
| 4415 |
// Write the variable... |
| 4416 |
size_t proc_offset = ge->get_optional_property("_processor_offset", 0); |
| 4417 |
size_t file_count = ge->get_optional_property("locally_owned_count", count); |
| 4418 |
|
| 4419 |
int64_t id = Ioex::get_id(ge, &ids_); |
| 4420 |
int ierr; |
| 4421 |
if (type == EX_SIDE_SET) { |
| 4422 |
size_t offset = ge->get_property("set_offset").get_int(); |
| 4423 |
ierr = ex_put_partial_var(get_file_pointer(), step, type, var_index, id, |
| 4424 |
proc_offset + offset + 1, count, temp.data()); |
| 4425 |
} |
| 4426 |
else if (type == EX_NODE_SET) { |
| 4427 |
std::vector<double> file_data; |
| 4428 |
file_data.reserve(file_count); |
| 4429 |
map_nodeset_data(nodesetOwnedNodes[ge], temp.data(), file_data); |
| 4430 |
ierr = ex_put_partial_var(get_file_pointer(), step, type, var_index, id, proc_offset + 1, |
| 4431 |
file_count, file_data.data()); |
| 4432 |
} |
| 4433 |
else { |
| 4434 |
ierr = ex_put_partial_var(get_file_pointer(), step, type, var_index, id, proc_offset + 1, |
| 4435 |
file_count, temp.data()); |
| 4436 |
} |
| 4437 |
|
| 4438 |
if (ierr < 0) { |
| 4439 |
std::ostringstream extra_info; |
| 4440 |
fmt::print(extra_info, "Outputting component {} of field '{}' at step {} on {} '{}'.", i, |
| 4441 |
field_name, fmt::group_digits(step), ge->type_string(), ge->name()); |
| 4442 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__, extra_info.str()); |
| 4443 |
} |
| 4444 |
} |
| 4445 |
} |
| 4446 |
} |
| 4447 |
|
| 4448 |
int64_t ParallelDatabaseIO::put_Xset_field_internal(const Ioss::EntitySet *ns, |
| 4449 |
const Ioss::Field &field, void *data, |
| 4450 |
size_t data_size) const |
| 4451 |
{ |
| 4452 |
size_t entity_count = ns->entity_count(); |
| 4453 |
size_t num_to_get = field.verify(data_size); |
| 4454 |
|
| 4455 |
int64_t id = Ioex::get_id(ns, &ids_); |
| 4456 |
Ioss::Field::RoleType role = field.get_role(); |
| 4457 |
|
| 4458 |
if (role == Ioss::Field::MESH) { |
| 4459 |
|
| 4460 |
void *out_data = data; |
| 4461 |
std::vector<int> i32data; |
| 4462 |
std::vector<int64_t> i64data; |
| 4463 |
std::vector<double> dbldata; |
| 4464 |
|
| 4465 |
size_t proc_offset = ns->get_optional_property("_processor_offset", 0); |
| 4466 |
size_t file_count = ns->get_optional_property("locally_owned_count", num_to_get); |
| 4467 |
|
| 4468 |
ex_entity_type type = Ioex::map_exodus_type(ns->type()); |
| 4469 |
if (field.get_name() == "ids" || field.get_name() == "ids_raw") { |
| 4470 |
// Map node id from global node id to local node id. |
| 4471 |
// Do it in 'data' ... |
| 4472 |
|
| 4473 |
if (field.get_name() == "ids") { |
| 4474 |
nodeMap.reverse_map_data(data, field, num_to_get); |
| 4475 |
} |
| 4476 |
|
| 4477 |
if (type == EX_NODE_SET) { |
| 4478 |
nodesetOwnedNodes[ns].reserve(file_count); |
| 4479 |
if (int_byte_size_api() == 4) { |
| 4480 |
i32data.reserve(file_count); |
| 4481 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 4482 |
map_nodeset_id_data(nodeOwningProcessor, nodesetOwnedNodes[ns], myProcessor, |
| 4483 |
reinterpret_cast<int *>(data), num_to_get, i32data); |
| 4484 |
assert(i32data.size() == file_count); |
| 4485 |
// Maps local to "global_implicit" |
| 4486 |
map_local_to_global_implicit(i32data.data(), file_count, nodeGlobalImplicitMap); |
| 4487 |
out_data = i32data.data(); |
| 4488 |
} |
| 4489 |
else { |
| 4490 |
i64data.reserve(file_count); |
| 4491 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 4492 |
map_nodeset_id_data(nodeOwningProcessor, nodesetOwnedNodes[ns], myProcessor, |
| 4493 |
reinterpret_cast<int64_t *>(data), num_to_get, i64data); |
| 4494 |
assert(i64data.size() == file_count); |
| 4495 |
map_local_to_global_implicit(i64data.data(), file_count, nodeGlobalImplicitMap); |
| 4496 |
out_data = i64data.data(); |
| 4497 |
} |
| 4498 |
} |
| 4499 |
int ierr = ex_put_partial_set(get_file_pointer(), type, id, proc_offset + 1, file_count, |
| 4500 |
out_data, nullptr); |
| 4501 |
if (ierr < 0) { |
| 4502 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4503 |
} |
| 4504 |
} |
| 4505 |
else if (field.get_name() == "orientation") { |
| 4506 |
int ierr = ex_put_partial_set(get_file_pointer(), type, id, proc_offset + 1, file_count, |
| 4507 |
nullptr, out_data); |
| 4508 |
if (ierr < 0) { |
| 4509 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4510 |
} |
| 4511 |
} |
| 4512 |
else if (field.get_name() == "distribution_factors") { |
| 4513 |
int ierr = 0; |
| 4514 |
if (type == EX_NODE_SET) { |
| 4515 |
map_nodeset_data(nodesetOwnedNodes[ns], reinterpret_cast<double *>(data), dbldata); |
| 4516 |
ierr = ex_put_partial_set_dist_fact(get_file_pointer(), type, id, proc_offset + 1, |
| 4517 |
file_count, dbldata.data()); |
| 4518 |
} |
| 4519 |
else { |
| 4520 |
ierr = ex_put_partial_set_dist_fact(get_file_pointer(), type, id, proc_offset + 1, |
| 4521 |
num_to_get, static_cast<double *>(out_data)); |
| 4522 |
} |
| 4523 |
if (ierr < 0) { |
| 4524 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4525 |
} |
| 4526 |
} |
| 4527 |
else { |
| 4528 |
num_to_get = Ioss::Utils::field_warning(ns, field, "output"); |
| 4529 |
} |
| 4530 |
} |
| 4531 |
else if (role == Ioss::Field::TRANSIENT) { |
| 4532 |
// Check if the specified field exists on this element block. |
| 4533 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 4534 |
// exist on the database as scalars with the appropriate |
| 4535 |
// extensions. |
| 4536 |
|
| 4537 |
// Transfer each component of the variable into 'data' and then |
| 4538 |
// output. Need temporary storage area of size 'number of |
| 4539 |
// elements in this block. |
| 4540 |
write_entity_transient_field(field, ns, entity_count, data); |
| 4541 |
} |
| 4542 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 4543 |
num_to_get = write_attribute_field(field, ns, data); |
| 4544 |
} |
| 4545 |
else if (role == Ioss::Field::REDUCTION) { |
| 4546 |
store_reduction_field(field, ns, data); |
| 4547 |
} |
| 4548 |
return num_to_get; |
| 4549 |
} |
| 4550 |
|
| 4551 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, |
| 4552 |
void *data, size_t data_size) const |
| 4553 |
{ |
| 4554 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 4555 |
} |
| 4556 |
|
| 4557 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, |
| 4558 |
void *data, size_t data_size) const |
| 4559 |
{ |
| 4560 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 4561 |
} |
| 4562 |
|
| 4563 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, |
| 4564 |
void *data, size_t data_size) const |
| 4565 |
{ |
| 4566 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 4567 |
} |
| 4568 |
|
| 4569 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::ElementSet *ns, |
| 4570 |
const Ioss::Field &field, void *data, |
| 4571 |
size_t data_size) const |
| 4572 |
{ |
| 4573 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 4574 |
} |
| 4575 |
|
| 4576 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, |
| 4577 |
void * /* data */, size_t data_size) const |
| 4578 |
{ |
| 4579 |
size_t num_to_get = field.verify(data_size); |
| 4580 |
if (field.get_name() == "ids") { |
| 4581 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 4582 |
} |
| 4583 |
else { |
| 4584 |
num_to_get = Ioss::Utils::field_warning(ss, field, "output"); |
| 4585 |
} |
| 4586 |
return num_to_get; |
| 4587 |
} |
| 4588 |
|
| 4589 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::CommSet * /*cs*/, |
| 4590 |
const Ioss::Field &field, void * /*data*/, |
| 4591 |
size_t data_size) const |
| 4592 |
{ |
| 4593 |
size_t num_to_get = field.verify(data_size); |
| 4594 |
return num_to_get; |
| 4595 |
} |
| 4596 |
|
| 4597 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::SideBlock *sb, |
| 4598 |
const Ioss::Field &field, void *data, |
| 4599 |
size_t data_size) const |
| 4600 |
{ |
| 4601 |
size_t num_to_get = field.verify(data_size); |
| 4602 |
int64_t id = Ioex::get_id(sb, &ids_); |
| 4603 |
|
| 4604 |
size_t entity_count = sb->entity_count(); |
| 4605 |
size_t offset = sb->get_property("set_offset").get_int(); |
| 4606 |
|
| 4607 |
Ioss::Field::RoleType role = field.get_role(); |
| 4608 |
|
| 4609 |
if (role == Ioss::Field::MESH) { |
| 4610 |
if (field.get_name() == "side_ids" && sb->name() == "universal_sideset") { |
| 4611 |
// The side ids are being stored as the distribution factor |
| 4612 |
// field on the universal sideset. There should be no other |
| 4613 |
// side sets that request this field... (Eventually, |
| 4614 |
// create an id field to store this info. |
| 4615 |
|
| 4616 |
// Need to convert 'ints' to 'double' for storage on mesh... |
| 4617 |
// FIX 64 |
| 4618 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 4619 |
int *ids = static_cast<int *>(data); |
| 4620 |
std::vector<double> real_ids(num_to_get); |
| 4621 |
for (size_t i = 0; i < num_to_get; i++) { |
| 4622 |
real_ids[i] = static_cast<double>(ids[i]); |
| 4623 |
} |
| 4624 |
int ierr = ex_put_partial_set_dist_fact(get_file_pointer(), EX_SIDE_SET, id, offset + 1, |
| 4625 |
entity_count, real_ids.data()); |
| 4626 |
if (ierr < 0) { |
| 4627 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4628 |
} |
| 4629 |
} |
| 4630 |
else { |
| 4631 |
int64_t *ids = static_cast<int64_t *>(data); |
| 4632 |
std::vector<double> real_ids(num_to_get); |
| 4633 |
for (size_t i = 0; i < num_to_get; i++) { |
| 4634 |
real_ids[i] = static_cast<double>(ids[i]); |
| 4635 |
} |
| 4636 |
int ierr = ex_put_partial_set_dist_fact(get_file_pointer(), EX_SIDE_SET, id, offset + 1, |
| 4637 |
entity_count, real_ids.data()); |
| 4638 |
if (ierr < 0) { |
| 4639 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4640 |
} |
| 4641 |
} |
| 4642 |
} |
| 4643 |
|
| 4644 |
else if (field.get_name() == "side_ids") { |
| 4645 |
} |
| 4646 |
|
| 4647 |
else if (field.get_name() == "ids") { |
| 4648 |
// ============================================================= |
| 4649 |
// NOTE: Code is currently commented out since we have |
| 4650 |
// redundant ways of getting the data (element/side) out to |
| 4651 |
// the database. The 'ids' field method relies on a numbering |
| 4652 |
// kluge, so for now trying the 'element_side' field... |
| 4653 |
// ============================================================= |
| 4654 |
} |
| 4655 |
|
| 4656 |
else if (field.get_name() == "distribution_factors") { |
| 4657 |
int ierr; |
| 4658 |
size_t df_offset = sb->get_property("set_df_offset").get_int(); |
| 4659 |
size_t proc_df_offset = sb->get_property("processor_df_offset").get_int(); |
| 4660 |
size_t df_count = sb->get_property("distribution_factor_count").get_int(); |
| 4661 |
ierr = ex_put_partial_set_dist_fact(get_file_pointer(), EX_SIDE_SET, id, |
| 4662 |
proc_df_offset + df_offset + 1, df_count, |
| 4663 |
static_cast<double *>(data)); |
| 4664 |
if (ierr < 0) { |
| 4665 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4666 |
} |
| 4667 |
} |
| 4668 |
else if (field.get_name() == "element_side") { |
| 4669 |
// In exodusII, the 'side block' is stored as a sideset. A |
| 4670 |
// sideset has a list of elements and a corresponding local |
| 4671 |
// element side (1-based) |
| 4672 |
|
| 4673 |
// The 'data' passed into the function is stored as a |
| 4674 |
// 2D vector e0,f0,e1,f1,... (e=element, f=side) |
| 4675 |
|
| 4676 |
// To avoid overwriting the passed in data, we allocate |
| 4677 |
// two arrays to store the data for this sideset. |
| 4678 |
|
| 4679 |
// The element_id passed in is the global id; we need to |
| 4680 |
// output the local id. |
| 4681 |
|
| 4682 |
// Allocate space for local side number and element numbers |
| 4683 |
// numbers. |
| 4684 |
// See if edges or faces... |
| 4685 |
size_t side_offset = Ioss::Utils::get_side_offset(sb); |
| 4686 |
|
| 4687 |
size_t index = 0; |
| 4688 |
|
| 4689 |
size_t proc_offset = sb->get_optional_property("_processor_offset", 0); |
| 4690 |
|
| 4691 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 4692 |
Ioss::IntVector element(num_to_get); |
| 4693 |
Ioss::IntVector side(num_to_get); |
| 4694 |
int *el_side = reinterpret_cast<int *>(data); |
| 4695 |
|
| 4696 |
for (size_t i = 0; i < num_to_get; i++) { |
| 4697 |
element[i] = elemMap.global_to_local(el_side[index++]); |
| 4698 |
side[i] = el_side[index++] + side_offset; |
| 4699 |
} |
| 4700 |
|
| 4701 |
map_local_to_global_implicit(element.data(), num_to_get, elemGlobalImplicitMap); |
| 4702 |
int ierr = |
| 4703 |
ex_put_partial_set(get_file_pointer(), EX_SIDE_SET, id, proc_offset + offset + 1, |
| 4704 |
num_to_get, element.data(), side.data()); |
| 4705 |
if (ierr < 0) { |
| 4706 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4707 |
} |
| 4708 |
} |
| 4709 |
else { |
| 4710 |
Ioss::Int64Vector element(num_to_get); |
| 4711 |
Ioss::Int64Vector side(num_to_get); |
| 4712 |
int64_t *el_side = reinterpret_cast<int64_t *>(data); |
| 4713 |
|
| 4714 |
for (size_t i = 0; i < num_to_get; i++) { |
| 4715 |
element[i] = elemMap.global_to_local(el_side[index++]); |
| 4716 |
side[i] = el_side[index++] + side_offset; |
| 4717 |
} |
| 4718 |
|
| 4719 |
map_local_to_global_implicit(element.data(), num_to_get, elemGlobalImplicitMap); |
| 4720 |
int ierr = |
| 4721 |
ex_put_partial_set(get_file_pointer(), EX_SIDE_SET, id, proc_offset + offset + 1, |
| 4722 |
num_to_get, element.data(), side.data()); |
| 4723 |
if (ierr < 0) { |
| 4724 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4725 |
} |
| 4726 |
} |
| 4727 |
} |
| 4728 |
else if (field.get_name() == "element_side_raw") { |
| 4729 |
// In exodusII, the 'side block' is stored as a sideset. A |
| 4730 |
// sideset has a list of elements and a corresponding local |
| 4731 |
// element side (1-based) |
| 4732 |
|
| 4733 |
// The 'data' passed into the function is stored as a |
| 4734 |
// 2D vector e0,f0,e1,f1,... (e=element, f=side) |
| 4735 |
|
| 4736 |
// To avoid overwriting the passed in data, we allocate |
| 4737 |
// two arrays to store the data for this sideset. |
| 4738 |
|
| 4739 |
// The element_id passed in is the local id. |
| 4740 |
|
| 4741 |
// See if edges or faces... |
| 4742 |
size_t side_offset = Ioss::Utils::get_side_offset(sb); |
| 4743 |
|
| 4744 |
size_t index = 0; |
| 4745 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 4746 |
Ioss::IntVector element(num_to_get); |
| 4747 |
Ioss::IntVector side(num_to_get); |
| 4748 |
int *el_side = reinterpret_cast<int *>(data); |
| 4749 |
|
| 4750 |
for (size_t i = 0; i < num_to_get; i++) { |
| 4751 |
element[i] = el_side[index++]; |
| 4752 |
side[i] = el_side[index++] + side_offset; |
| 4753 |
} |
| 4754 |
|
| 4755 |
int ierr = ex_put_partial_set(get_file_pointer(), EX_SIDE_SET, id, offset + 1, |
| 4756 |
entity_count, element.data(), side.data()); |
| 4757 |
if (ierr < 0) { |
| 4758 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4759 |
} |
| 4760 |
} |
| 4761 |
else { |
| 4762 |
Ioss::Int64Vector element(num_to_get); |
| 4763 |
Ioss::Int64Vector side(num_to_get); |
| 4764 |
int64_t *el_side = reinterpret_cast<int64_t *>(data); |
| 4765 |
|
| 4766 |
for (size_t i = 0; i < num_to_get; i++) { |
| 4767 |
element[i] = el_side[index++]; |
| 4768 |
side[i] = el_side[index++] + side_offset; |
| 4769 |
} |
| 4770 |
|
| 4771 |
int ierr = ex_put_partial_set(get_file_pointer(), EX_SIDE_SET, id, offset + 1, |
| 4772 |
entity_count, element.data(), side.data()); |
| 4773 |
if (ierr < 0) { |
| 4774 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4775 |
} |
| 4776 |
} |
| 4777 |
} |
| 4778 |
else if (field.get_name() == "connectivity") { |
| 4779 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 4780 |
} |
| 4781 |
else if (field.get_name() == "connectivity_raw") { |
| 4782 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 4783 |
} |
| 4784 |
else { |
| 4785 |
num_to_get = Ioss::Utils::field_warning(sb, field, "output"); |
| 4786 |
} |
| 4787 |
} |
| 4788 |
else if (role == Ioss::Field::TRANSIENT) { |
| 4789 |
// Check if the specified field exists on this block. |
| 4790 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 4791 |
// exist on the database as scalars with the appropriate |
| 4792 |
// extensions. |
| 4793 |
|
| 4794 |
// Transfer each component of the variable into 'data' and then |
| 4795 |
// output. Need temporary storage area of size 'number of |
| 4796 |
// entities in this block. |
| 4797 |
write_entity_transient_field(field, sb, entity_count, data); |
| 4798 |
} |
| 4799 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 4800 |
num_to_get = write_attribute_field(field, sb, data); |
| 4801 |
} |
| 4802 |
else if (role == Ioss::Field::REDUCTION) { |
| 4803 |
store_reduction_field(field, sb, data); |
| 4804 |
} |
| 4805 |
return num_to_get; |
| 4806 |
} |
| 4807 |
|
| 4808 |
template <typename INT> void ParallelDatabaseIO::output_processor_id_map(Ioss::Region *region) |
| 4809 |
{ |
| 4810 |
std::vector<INT> proc_id(elementCount, myProcessor); |
| 4811 |
const auto &blocks = region->get_element_blocks(); |
| 4812 |
for (const auto &block : blocks) { |
| 4813 |
put_field_internal(block, block->get_field("proc_id"), Data(proc_id), 0); |
| 4814 |
} |
| 4815 |
} |
| 4816 |
|
| 4817 |
void ParallelDatabaseIO::write_meta_data(Ioss::IfDatabaseExistsBehavior behavior) |
| 4818 |
{ |
| 4819 |
Ioss::Region *region = get_region(); |
| 4820 |
common_write_metadata(behavior); |
| 4821 |
|
| 4822 |
char the_title[max_line_length + 1]; |
| 4823 |
|
| 4824 |
// Title... |
| 4825 |
if (region->property_exists("title")) { |
| 4826 |
std::string title_str = region->get_property("title").get_string(); |
| 4827 |
Ioss::Utils::copy_string(the_title, title_str); |
| 4828 |
} |
| 4829 |
else { |
| 4830 |
Ioss::Utils::copy_string(the_title, "IOSS Default Output Title"); |
| 4831 |
} |
| 4832 |
|
| 4833 |
bool file_per_processor = false; |
| 4834 |
Ioex::Mesh mesh(spatialDimension, the_title, util(), file_per_processor); |
| 4835 |
mesh.populate(region); |
| 4836 |
|
| 4837 |
if (behavior != Ioss::DB_APPEND && behavior != Ioss::DB_MODIFY) { |
| 4838 |
bool omit_qa = false; |
| 4839 |
Ioss::Utils::check_set_bool_property(properties, "OMIT_QA_RECORDS", omit_qa); |
| 4840 |
if (!omit_qa) { |
| 4841 |
put_qa(); |
| 4842 |
} |
| 4843 |
|
| 4844 |
bool omit_info = false; |
| 4845 |
Ioss::Utils::check_set_bool_property(properties, "OMIT_INFO_RECORDS", omit_info); |
| 4846 |
if (!omit_info) { |
| 4847 |
put_info(); |
| 4848 |
} |
| 4849 |
|
| 4850 |
// Write the metadata to the exodusII file... |
| 4851 |
Ioex::Internals data(get_file_pointer(), maximumNameLength, util()); |
| 4852 |
mesh.comm.outputNemesis = false; |
| 4853 |
|
| 4854 |
int ierr = data.write_meta_data(mesh); |
| 4855 |
|
| 4856 |
if (ierr < 0) { |
| 4857 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4858 |
} |
| 4859 |
} |
| 4860 |
|
| 4861 |
metaDataWritten = true; |
| 4862 |
|
| 4863 |
// Set the processor offset property. Specifies where in the global list, the data from this |
| 4864 |
// processor begins... |
| 4865 |
update_processor_offset_property(region, mesh); |
| 4866 |
|
| 4867 |
if (behavior != Ioss::DB_APPEND && behavior != Ioss::DB_MODIFY) { |
| 4868 |
output_node_map(); |
| 4869 |
add_processor_id_map(region); |
| 4870 |
output_other_metadata(); |
| 4871 |
if (int_byte_size_api() == 8) { |
| 4872 |
output_processor_id_map<int64_t>(region); |
| 4873 |
} |
| 4874 |
else { |
| 4875 |
output_processor_id_map<int>(region); |
| 4876 |
} |
| 4877 |
} |
| 4878 |
} |
| 4879 |
|
| 4880 |
void ParallelDatabaseIO::create_implicit_global_map() const |
| 4881 |
{ |
| 4882 |
// If the node is locally owned, then its position is basically |
| 4883 |
// determined by removing all shared nodes from the list and |
| 4884 |
// then compressing the list. This location plus the proc_offset |
| 4885 |
// gives its location in the global-implicit file. |
| 4886 |
// |
| 4887 |
// Do this over in the DecompositionData class since it has |
| 4888 |
// several utilities in place for MPI communication. |
| 4889 |
|
| 4890 |
DecompositionData<int64_t> compose(Ioss::PropertyManager(), util().communicator()); |
| 4891 |
int64_t locally_owned_count = 0; |
| 4892 |
int64_t processor_offset = 0; |
| 4893 |
compose.create_implicit_global_map(nodeOwningProcessor, nodeGlobalImplicitMap, nodeMap, |
| 4894 |
&locally_owned_count, &processor_offset); |
| 4895 |
|
| 4896 |
nodeGlobalImplicitMapDefined = true; |
| 4897 |
const Ioss::NodeBlockContainer &node_blocks = get_region()->get_node_blocks(); |
| 4898 |
if (!node_blocks[0]->property_exists("locally_owned_count")) { |
| 4899 |
node_blocks[0]->property_add(Ioss::Property("locally_owned_count", locally_owned_count)); |
| 4900 |
} |
| 4901 |
if (!node_blocks[0]->property_exists("_processor_offset")) { |
| 4902 |
node_blocks[0]->property_add(Ioss::Property("_processor_offset", processor_offset)); |
| 4903 |
} |
| 4904 |
|
| 4905 |
output_node_map(); |
| 4906 |
} |
| 4907 |
|
| 4908 |
void ParallelDatabaseIO::output_node_map() const |
| 4909 |
{ |
| 4910 |
// Write the partial nodemap to the database... This is called |
| 4911 |
// two times -- once from create_implicit_global_map() and once |
| 4912 |
// from write_meta_data(). It will only output the map if |
| 4913 |
// the metadata has been written to the output database AND if |
| 4914 |
// the nodeMap.map and nodeGlobalImplicitMap are defined. |
| 4915 |
|
| 4916 |
if (metaDataWritten) { |
| 4917 |
const Ioss::NodeBlockContainer &node_blocks = get_region()->get_node_blocks(); |
| 4918 |
if (node_blocks.empty()) { |
| 4919 |
return; |
| 4920 |
} |
| 4921 |
assert(node_blocks[0]->property_exists("_processor_offset")); |
| 4922 |
assert(node_blocks[0]->property_exists("locally_owned_count")); |
| 4923 |
size_t processor_offset = node_blocks[0]->get_property("_processor_offset").get_int(); |
| 4924 |
size_t locally_owned_count = node_blocks[0]->get_property("locally_owned_count").get_int(); |
| 4925 |
|
| 4926 |
int ierr = 0; |
| 4927 |
if (nodeMap.defined() && nodeGlobalImplicitMapDefined) { |
| 4928 |
|
| 4929 |
if (int_byte_size_api() == 4) { |
| 4930 |
std::vector<int> file_ids; |
| 4931 |
file_ids.reserve(locally_owned_count); |
| 4932 |
check_node_owning_processor_data(nodeOwningProcessor, locally_owned_count); |
| 4933 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, &nodeMap.map()[1], file_ids); |
| 4934 |
ierr = ex_put_partial_id_map(get_file_pointer(), EX_NODE_MAP, processor_offset + 1, |
| 4935 |
locally_owned_count, file_ids.data()); |
| 4936 |
} |
| 4937 |
else { |
| 4938 |
std::vector<int64_t> file_ids; |
| 4939 |
file_ids.reserve(locally_owned_count); |
| 4940 |
check_node_owning_processor_data(nodeOwningProcessor, locally_owned_count); |
| 4941 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, &nodeMap.map()[1], file_ids); |
| 4942 |
ierr = ex_put_partial_id_map(get_file_pointer(), EX_NODE_MAP, processor_offset + 1, |
| 4943 |
locally_owned_count, file_ids.data()); |
| 4944 |
} |
| 4945 |
} |
| 4946 |
if (ierr < 0) { |
| 4947 |
Ioex::exodus_error(get_file_pointer(), __LINE__, __func__, __FILE__); |
| 4948 |
} |
| 4949 |
} |
| 4950 |
} |
| 4951 |
|
| 4952 |
void ParallelDatabaseIO::check_valid_values() const |
| 4953 |
{ |
| 4954 |
std::vector<int64_t> counts{nodeCount, elementCount, m_groupCount[EX_ELEM_BLOCK]}; |
| 4955 |
std::vector<int64_t> all_counts; |
| 4956 |
util().all_gather(counts, all_counts); |
| 4957 |
// Get minimum value in `all_counts`. If >0, then don't need to check further... |
| 4958 |
auto min_val = *std::min_element(all_counts.begin(), all_counts.end()); |
| 4959 |
|
| 4960 |
if (myProcessor == 0) { |
| 4961 |
size_t proc_count = all_counts.size() / 3; |
| 4962 |
|
| 4963 |
if (min_val < 0) { |
| 4964 |
static std::array<std::string, 3> label{"node", "element", "element block"}; |
| 4965 |
// Error on one or more of the counts... |
| 4966 |
for (size_t j = 0; j < 3; j++) { |
| 4967 |
std::vector<size_t> bad_proc; |
| 4968 |
for (size_t i = 0; i < proc_count; i++) { |
| 4969 |
if (all_counts[3 * i + j] < 0) { |
| 4970 |
bad_proc.push_back(i); |
| 4971 |
} |
| 4972 |
} |
| 4973 |
|
| 4974 |
if (!bad_proc.empty()) { |
| 4975 |
IOSS_ERROR(fmt::format("ERROR: Negative {} count on {} processor{}:\n\t{}\n\n", |
| 4976 |
label[j], bad_proc.size(), bad_proc.size() > 1 ? "s" : "", |
| 4977 |
Ioss::Utils::format_id_list(bad_proc, ":"))); |
| 4978 |
} |
| 4979 |
} |
| 4980 |
} |
| 4981 |
|
| 4982 |
// Now check for warning (count == 0) |
| 4983 |
if (min_val <= 0) { |
| 4984 |
static std::array<std::string, 3> label{"nodes or elements", "elements", "element blocks"}; |
| 4985 |
// Possible warning on one or more of the counts... |
| 4986 |
// Note that it is possible to have nodes on a processor with no elements, |
| 4987 |
// but not possible to have elements if no nodes... |
| 4988 |
for (size_t j = 0; j < 3; j++) { |
| 4989 |
std::vector<size_t> bad_proc; |
| 4990 |
for (size_t i = 0; i < proc_count; i++) { |
| 4991 |
if (all_counts[3 * i + j] == 0) { |
| 4992 |
bad_proc.push_back(i); |
| 4993 |
} |
| 4994 |
} |
| 4995 |
|
| 4996 |
if (!bad_proc.empty()) { |
| 4997 |
fmt::print(Ioss::WarnOut(), "No {} on processor{}:\n\t{}\n\n", label[j], |
| 4998 |
bad_proc.size() > 1 ? "s" : "", Ioss::Utils::format_id_list(bad_proc, ":")); |
| 4999 |
if (j == 0) { |
| 5000 |
break; |
| 5001 |
} |
| 5002 |
} |
| 5003 |
} |
| 5004 |
} |
| 5005 |
} |
| 5006 |
else { // All other processors; need to abort if negative count |
| 5007 |
if (min_val < 0) { |
| 5008 |
IOSS_ERROR(""); |
| 5009 |
} |
| 5010 |
} |
| 5011 |
} |
| 5012 |
|
| 5013 |
std::vector<size_t> ParallelDatabaseIO::get_entity_connectivity_field_data( |
| 5014 |
const std::string &field_name, const std::vector<Ioss::ElementBlock *> &elem_blocks, |
| 5015 |
void *data, size_t data_size) const |
| 5016 |
{ |
| 5017 |
std::vector<int64_t> block_to_decomp = get_block_to_decomp_map(elem_blocks); |
| 5018 |
|
| 5019 |
ElementBlockBatchReader batchReader(decomp.get()); |
| 5020 |
|
| 5021 |
size_t num_to_get = batchReader.get_connectivity_size(block_to_decomp); |
| 5022 |
size_t expected_data_size = num_to_get * decomp->int_size(); |
| 5023 |
|
| 5024 |
if (data_size < expected_data_size) { |
| 5025 |
IOSS_ERROR(fmt::format( |
| 5026 |
"ERROR: Connectivity data size {} on region {} is less than expected size {}\n\n", |
| 5027 |
data_size, get_region()->name(), expected_data_size)); |
| 5028 |
} |
| 5029 |
|
| 5030 |
std::vector<size_t> offsets = |
| 5031 |
batchReader.get_connectivity(get_file_pointer(), block_to_decomp, data); |
| 5032 |
|
| 5033 |
if (field_name == "connectivity") { |
| 5034 |
Ioss::Field::BasicType type = |
| 5035 |
decomp->int_size() == sizeof(int) ? Ioss::Field::INTEGER : Ioss::Field::INT64; |
| 5036 |
get_map(EX_NODE_BLOCK).map_data(data, type, num_to_get); |
| 5037 |
} |
| 5038 |
|
| 5039 |
return offsets; |
| 5040 |
} |
| 5041 |
|
| 5042 |
template <typename T> |
| 5043 |
std::vector<Ioex::BlockFieldData> |
| 5044 |
ParallelDatabaseIO::get_entity_block_field_data(const Ioex::VariableNameMap &variables, |
| 5045 |
const std::string &field_name, |
| 5046 |
const std::vector<T *> &entity_container) const |
| 5047 |
{ |
| 5048 |
size_t num_blocks = entity_container.size(); |
| 5049 |
|
| 5050 |
std::vector<Ioex::BlockFieldData> block_data(num_blocks); |
| 5051 |
|
| 5052 |
for (size_t iblk = 0; iblk < num_blocks; ++iblk) { |
| 5053 |
T *entity = entity_container[iblk]; |
| 5054 |
block_data[iblk].id = Ioex::get_id(entity, &ids_); |
| 5055 |
|
| 5056 |
if (entity->field_exists(field_name)) { |
| 5057 |
Ioss::Field field = entity->get_field(field_name); |
| 5058 |
|
| 5059 |
size_t comp_count = field.get_component_count(Ioss::Field::InOut::INPUT); |
| 5060 |
block_data[iblk].comp_count = comp_count; |
| 5061 |
|
| 5062 |
for (size_t j = 0; j < comp_count; j++) { |
| 5063 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::INPUT, j + 1); |
| 5064 |
if (lowerCaseVariableNames) { |
| 5065 |
Ioss::Utils::fixup_name(var_name); |
| 5066 |
} |
| 5067 |
|
| 5068 |
auto var_iter = variables.find(var_name); |
| 5069 |
if (var_iter == variables.end()) { |
| 5070 |
IOSS_ERROR(fmt::format("ERROR: Could not find field '{}' on block '{}'\n", var_name, |
| 5071 |
entity->name())); |
| 5072 |
} |
| 5073 |
size_t var_index = var_iter->second; |
| 5074 |
assert(var_index > 0); |
| 5075 |
|
| 5076 |
block_data[iblk].var_name.push_back(var_name); |
| 5077 |
block_data[iblk].var_index.push_back(var_index); |
| 5078 |
} |
| 5079 |
} |
| 5080 |
} |
| 5081 |
|
| 5082 |
return block_data; |
| 5083 |
} |
| 5084 |
|
| 5085 |
std::vector<size_t> ParallelDatabaseIO::get_entity_transient_field_data( |
| 5086 |
const Ioex::VariableNameMap &variables, const std::string &field_name, |
| 5087 |
const std::vector<Ioss::ElementBlock *> &elem_blocks, void *data) const |
| 5088 |
{ |
| 5089 |
std::vector<int64_t> block_to_decomp = get_block_to_decomp_map(elem_blocks); |
| 5090 |
|
| 5091 |
ElementBlockBatchReader batchReader(decomp.get()); |
| 5092 |
|
| 5093 |
std::vector<int> block_field_component_count = |
| 5094 |
get_entity_field_component_count(field_name, elem_blocks); |
| 5095 |
std::vector<size_t> ioss_offset = |
| 5096 |
batchReader.get_offset(block_to_decomp, block_field_component_count); |
| 5097 |
|
| 5098 |
size_t num_blocks = elem_blocks.size(); |
| 5099 |
|
| 5100 |
std::vector<BlockFieldData> block_data = |
| 5101 |
get_entity_block_field_data(variables, field_name, elem_blocks); |
| 5102 |
|
| 5103 |
std::vector<double> temp(ioss_offset[num_blocks]); |
| 5104 |
batchReader.get_field_data(get_file_pointer(), temp.data(), block_to_decomp, |
| 5105 |
get_current_state(), block_data); |
| 5106 |
|
| 5107 |
double *rvar = static_cast<double *>(data); |
| 5108 |
int *ivar = static_cast<int *>(data); |
| 5109 |
int64_t *i64var = static_cast<int64_t *>(data); |
| 5110 |
|
| 5111 |
for (size_t iblk = 0; iblk < num_blocks; iblk++) { |
| 5112 |
Ioss::ElementBlock *entity = elem_blocks[iblk]; |
| 5113 |
size_t comp_count = block_data[iblk].comp_count; |
| 5114 |
|
| 5115 |
if (entity->field_exists(field_name)) { |
| 5116 |
Ioss::Field field = entity->get_field(field_name); |
| 5117 |
size_t num_entity = entity->entity_count(); |
| 5118 |
|
| 5119 |
for (size_t comp = 0; comp < comp_count; comp++) { |
| 5120 |
// Transfer to 'data' array. |
| 5121 |
size_t k = ioss_offset[iblk] + comp * num_entity; |
| 5122 |
size_t j = ioss_offset[iblk] + comp; |
| 5123 |
|
| 5124 |
const size_t j_limit = ioss_offset[iblk + 1]; |
| 5125 |
|
| 5126 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 5127 |
for (; j < j_limit; j += comp_count) { |
| 5128 |
ivar[j] = static_cast<int>(temp[k++]); |
| 5129 |
} |
| 5130 |
} |
| 5131 |
else if (field.get_type() == Ioss::Field::INT64) { // FIX 64 UNSAFE |
| 5132 |
for (; j < j_limit; j += comp_count) { |
| 5133 |
i64var[j] = static_cast<int64_t>(temp[k++]); |
| 5134 |
} |
| 5135 |
} |
| 5136 |
else if (field.get_type() == Ioss::Field::REAL) { |
| 5137 |
for (; j < j_limit; j += comp_count) { |
| 5138 |
rvar[j] = temp[k++]; |
| 5139 |
} |
| 5140 |
} |
| 5141 |
else { |
| 5142 |
IOSS_ERROR( |
| 5143 |
fmt::format("IOSS_ERROR: Field storage type must be either integer or double.\n" |
| 5144 |
" Field '{}' is invalid.\n", |
| 5145 |
field.get_name())); |
| 5146 |
} |
| 5147 |
} |
| 5148 |
|
| 5149 |
if (ioss_offset[iblk + 1] >= ioss_offset[iblk]) { |
| 5150 |
size_t field_byte_size = field.get_basic_size(); |
| 5151 |
size_t block_data_offset = ioss_offset[iblk] * field_byte_size; |
| 5152 |
|
| 5153 |
field.transform((char *)data + block_data_offset); |
| 5154 |
} |
| 5155 |
} |
| 5156 |
} |
| 5157 |
|
| 5158 |
return ioss_offset; |
| 5159 |
} |
| 5160 |
|
| 5161 |
std::vector<size_t> |
| 5162 |
ParallelDatabaseIO::get_entity_field_data(const std::string &field_name, |
| 5163 |
const std::vector<Ioss::ElementBlock *> &elem_blocks, |
| 5164 |
void *data, size_t data_size) const |
| 5165 |
{ |
| 5166 |
if (field_name == "connectivity" || field_name == "connectivity_raw") { |
| 5167 |
return get_entity_connectivity_field_data(field_name, elem_blocks, data, data_size); |
| 5168 |
} |
| 5169 |
|
| 5170 |
size_t expected_data_size = get_entity_field_data_size(field_name, elem_blocks); |
| 5171 |
|
| 5172 |
if (data_size < expected_data_size) { |
| 5173 |
IOSS_ERROR(fmt::format( |
| 5174 |
"ERROR: Field {} with data size {} on region {} is less than expected size {}\n\n", |
| 5175 |
field_name, data_size, get_region()->name(), expected_data_size)); |
| 5176 |
} |
| 5177 |
|
| 5178 |
return get_entity_transient_field_data(m_variables[EX_ELEM_BLOCK], field_name, elem_blocks, |
| 5179 |
data); |
| 5180 |
} |
| 5181 |
|
| 5182 |
} // namespace Ioex |
| 5183 |
#else |
| 5184 |
IOSS_MAYBE_UNUSED const char ioss_exodus_parallel_database_unused_symbol_dummy = '\0'; |
| 5185 |
#endif |