| 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 "exonull/Ioexnl_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 "exonull/Ioexnl_DecompositionData.h" |
| 41 |
#include "exonull/Ioexnl_Internals.h" |
| 42 |
#include "exonull/Ioexnl_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 |
void check_node_owning_processor_data(const Ioss::IntVector &nop, size_t file_node_count) |
| 87 |
{ |
| 88 |
// Verify that the nop (NodeOwningProcessor) vector is not empty and is of the correct size. |
| 89 |
// This vector specifies which rank owns each node on this rank |
| 90 |
// Throws error if problem, otherwise returns quietly. |
| 91 |
if (file_node_count == 0) { |
| 92 |
return; |
| 93 |
} |
| 94 |
if (nop.empty()) { |
| 95 |
std::ostringstream errmsg; |
| 96 |
fmt::print(errmsg, "ERROR: The use of the 'compose' output option requires the definition of " |
| 97 |
"the 'owning_processor'" |
| 98 |
" field prior to the output of nodal data. This field has not yet been " |
| 99 |
"defined so output is not possible." |
| 100 |
" For more information, contact [email protected].\n"); |
| 101 |
IOSS_ERROR(errmsg); |
| 102 |
} |
| 103 |
else if (nop.size() < file_node_count) { |
| 104 |
std::ostringstream errmsg; |
| 105 |
fmt::print(errmsg, |
| 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 |
IOSS_ERROR(errmsg); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
template <typename T> |
| 115 |
void compute_internal_border_maps(T *entities, T *internal, size_t count, size_t entity_count) |
| 116 |
{ |
| 117 |
for (size_t ij = 0; ij < count; ij++) { |
| 118 |
internal[ij] = 1; |
| 119 |
} |
| 120 |
for (size_t J = 0; J < entity_count; J++) { |
| 121 |
internal[entities[J] - 1] = 0; |
| 122 |
} |
| 123 |
|
| 124 |
size_t b = 0; |
| 125 |
for (size_t ij = 0; ij < count; ij++) { |
| 126 |
if (internal[ij] == 0) { |
| 127 |
entities[b++] = ij + 1; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
size_t k = 0; |
| 132 |
for (size_t ij = 0; ij < count; ij++) { |
| 133 |
if (internal[ij] == 1) { |
| 134 |
internal[k++] = ij + 1; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
template <typename INT> |
| 140 |
void map_nodeset_id_data(const Ioss::IntVector &owning_processor, Ioss::Int64Vector &owned_nodes, |
| 141 |
int this_processor, const INT *ids, size_t ids_size, |
| 142 |
std::vector<INT> &file_data) |
| 143 |
{ |
| 144 |
// Determine which nodes in this nodeset are owned by this processor. |
| 145 |
// Save this mapping in the "owned_nodes" vector for use in |
| 146 |
// mapping nodeset field data (df, transient, attributes, ...) |
| 147 |
for (size_t i = 0; i < ids_size; i++) { |
| 148 |
INT node = ids[i]; |
| 149 |
if (owning_processor[node - 1] == this_processor) { |
| 150 |
file_data.push_back(ids[i]); |
| 151 |
owned_nodes.push_back(i); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
template <typename T, typename U> |
| 157 |
void map_nodeset_data(Ioss::Int64Vector &owned_nodes, const T *data, std::vector<U> &file_data, |
| 158 |
size_t offset = 0, size_t stride = 1) |
| 159 |
{ |
| 160 |
// Pull out the locally owned nodeset data |
| 161 |
for (auto owned_node : owned_nodes) { |
| 162 |
file_data.push_back(data[stride * owned_node + offset]); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
template <typename T> |
| 167 |
void extract_data(std::vector<double> &local_data, T *data, size_t num_entity, size_t offset, |
| 168 |
size_t comp_count) |
| 169 |
{ |
| 170 |
local_data.resize(num_entity); |
| 171 |
if (comp_count == 1 && offset == 0) { |
| 172 |
for (size_t j = 0; j < num_entity; j++) { |
| 173 |
local_data[j] = data[j]; |
| 174 |
} |
| 175 |
} |
| 176 |
else { |
| 177 |
for (size_t j = 0; j < num_entity; j++) { |
| 178 |
local_data[j] = data[offset]; |
| 179 |
offset += comp_count; |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
// Ideally, there should only be a single data type for in and out |
| 185 |
// data, but in the node id map mapping, we have an int64_t coming |
| 186 |
// in and either an int or int64_t going out... |
| 187 |
template <typename T, typename U> |
| 188 |
void filter_owned_nodes(const Ioss::IntVector &owning_processor, int this_processor, |
| 189 |
const T *data, std::vector<U> &file_data, size_t offset = 0, |
| 190 |
size_t stride = 1) |
| 191 |
{ |
| 192 |
size_t index = offset; |
| 193 |
for (auto op : owning_processor) { |
| 194 |
if (op == this_processor) { |
| 195 |
file_data.push_back(data[index]); |
| 196 |
} |
| 197 |
index += stride; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
// This version can be used *if* the input and output types are the same *and* the |
| 202 |
// input `data` can be modified / overwritten. |
| 203 |
template <typename T> |
| 204 |
void filter_owned_nodes(const Ioss::IntVector &owning_processor, int this_processor, T *data) |
| 205 |
{ |
| 206 |
size_t index = 0; |
| 207 |
size_t entry = 0; |
| 208 |
for (auto op : owning_processor) { |
| 209 |
if (op == this_processor) { |
| 210 |
data[entry++] = data[index]; |
| 211 |
} |
| 212 |
index++; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
template <typename INT> |
| 217 |
void map_local_to_global_implicit(INT *data, size_t count, |
| 218 |
const std::vector<int64_t> &global_implicit_map) |
| 219 |
{ |
| 220 |
for (size_t i = 0; i < count; i++) { |
| 221 |
data[i] = global_implicit_map[data[i] - 1]; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
void update_processor_offset_property(Ioss::Region *region, const Ioexnl::Mesh &mesh) |
| 226 |
{ |
| 227 |
const Ioss::NodeBlockContainer &node_blocks = region->get_node_blocks(); |
| 228 |
if (!node_blocks.empty()) { |
| 229 |
node_blocks[0]->property_add( |
| 230 |
Ioss::Property("_processor_offset", mesh.nodeblocks[0].procOffset)); |
| 231 |
} |
| 232 |
const Ioss::EdgeBlockContainer &edge_blocks = region->get_edge_blocks(); |
| 233 |
for (size_t i = 0; i < edge_blocks.size(); i++) { |
| 234 |
edge_blocks[i]->property_add( |
| 235 |
Ioss::Property("_processor_offset", mesh.edgeblocks[i].procOffset)); |
| 236 |
} |
| 237 |
const Ioss::FaceBlockContainer &face_blocks = region->get_face_blocks(); |
| 238 |
for (size_t i = 0; i < face_blocks.size(); i++) { |
| 239 |
face_blocks[i]->property_add( |
| 240 |
Ioss::Property("_processor_offset", mesh.faceblocks[i].procOffset)); |
| 241 |
} |
| 242 |
|
| 243 |
int64_t offset = 0; // Offset into global element map... |
| 244 |
const Ioss::ElementBlockContainer &element_blocks = region->get_element_blocks(); |
| 245 |
for (size_t i = 0; i < element_blocks.size(); i++) { |
| 246 |
element_blocks[i]->property_add(Ioss::Property("global_map_offset", offset)); |
| 247 |
offset += mesh.elemblocks[i].entityCount; |
| 248 |
element_blocks[i]->property_add( |
| 249 |
Ioss::Property("_processor_offset", mesh.elemblocks[i].procOffset)); |
| 250 |
} |
| 251 |
|
| 252 |
const Ioss::NodeSetContainer &nodesets = region->get_nodesets(); |
| 253 |
for (size_t i = 0; i < nodesets.size(); i++) { |
| 254 |
nodesets[i]->property_add(Ioss::Property("_processor_offset", mesh.nodesets[i].procOffset)); |
| 255 |
} |
| 256 |
const Ioss::EdgeSetContainer &edgesets = region->get_edgesets(); |
| 257 |
for (size_t i = 0; i < edgesets.size(); i++) { |
| 258 |
edgesets[i]->property_add(Ioss::Property("_processor_offset", mesh.edgesets[i].procOffset)); |
| 259 |
} |
| 260 |
const Ioss::FaceSetContainer &facesets = region->get_facesets(); |
| 261 |
for (size_t i = 0; i < facesets.size(); i++) { |
| 262 |
facesets[i]->property_add(Ioss::Property("_processor_offset", mesh.facesets[i].procOffset)); |
| 263 |
} |
| 264 |
const Ioss::ElementSetContainer &elementsets = region->get_elementsets(); |
| 265 |
for (size_t i = 0; i < facesets.size(); i++) { |
| 266 |
elementsets[i]->property_add( |
| 267 |
Ioss::Property("_processor_offset", mesh.elemsets[i].procOffset)); |
| 268 |
} |
| 269 |
|
| 270 |
const Ioss::SideSetContainer &ssets = region->get_sidesets(); |
| 271 |
for (size_t i = 0; i < ssets.size(); i++) { |
| 272 |
ssets[i]->property_add(Ioss::Property("_processor_offset", mesh.sidesets[i].procOffset)); |
| 273 |
ssets[i]->property_add(Ioss::Property("processor_df_offset", mesh.sidesets[i].dfProcOffset)); |
| 274 |
|
| 275 |
// Propagate down to owned sideblocks... |
| 276 |
const Ioss::SideBlockContainer &side_blocks = ssets[i]->get_side_blocks(); |
| 277 |
for (auto &block : side_blocks) { |
| 278 |
block->property_add(Ioss::Property("_processor_offset", mesh.sidesets[i].procOffset)); |
| 279 |
block->property_add(Ioss::Property("processor_df_offset", mesh.sidesets[i].dfProcOffset)); |
| 280 |
} |
| 281 |
} |
| 282 |
const auto &blobs = region->get_blobs(); |
| 283 |
for (size_t i = 0; i < blobs.size(); i++) { |
| 284 |
blobs[i]->property_add(Ioss::Property("_processor_offset", mesh.blobs[i].procOffset)); |
| 285 |
} |
| 286 |
} |
| 287 |
} // namespace |
| 288 |
|
| 289 |
namespace Ioexnl { |
| 290 |
ParallelDatabaseIO::ParallelDatabaseIO(Ioss::Region *region, const std::string &filename, |
| 291 |
Ioss::DatabaseUsage db_usage, Ioss_MPI_Comm communicator, |
| 292 |
const Ioss::PropertyManager &props) |
| 293 |
: Ioexnl::BaseDatabaseIO(region, filename, db_usage, communicator, props) |
| 294 |
{ |
| 295 |
} |
| 296 |
|
| 297 |
void ParallelDatabaseIO::release_memory_nl() |
| 298 |
{ |
| 299 |
free_file_pointer(); |
| 300 |
nodeMap.release_memory(); |
| 301 |
edgeMap.release_memory(); |
| 302 |
faceMap.release_memory(); |
| 303 |
elemMap.release_memory(); |
| 304 |
Ioss::Utils::clear(nodeOwningProcessor); |
| 305 |
Ioss::Utils::clear(nodeGlobalImplicitMap); |
| 306 |
Ioss::Utils::clear(elemGlobalImplicitMap); |
| 307 |
nodeGlobalImplicitMapDefined = false; |
| 308 |
elemGlobalImplicitMapDefined = false; |
| 309 |
nodesetOwnedNodes.clear(); |
| 310 |
try { |
| 311 |
decomp.reset(); |
| 312 |
} |
| 313 |
catch (...) { |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
bool ParallelDatabaseIO::check_valid_file_ptr(bool, std::string *, int *, bool) const |
| 318 |
{ |
| 319 |
return true; |
| 320 |
} |
| 321 |
|
| 322 |
bool ParallelDatabaseIO::handle_output_file(bool write_message, std::string *error_msg, |
| 323 |
int *bad_count, bool overwrite, |
| 324 |
bool abort_if_error) const |
| 325 |
{ |
| 326 |
return true; |
| 327 |
} |
| 328 |
|
| 329 |
int ParallelDatabaseIO::get_file_pointer() const |
| 330 |
{ |
| 331 |
return Ioexnl::BaseDatabaseIO::get_file_pointer(); |
| 332 |
} |
| 333 |
|
| 334 |
int ParallelDatabaseIO::free_file_pointer() const |
| 335 |
{ |
| 336 |
return Ioexnl::BaseDatabaseIO::free_file_pointer(); |
| 337 |
} |
| 338 |
|
| 339 |
void ParallelDatabaseIO::read_meta_data_nl() {} |
| 340 |
|
| 341 |
int64_t ParallelDatabaseIO::write_attribute_field(const Ioss::Field &field, |
| 342 |
const Ioss::GroupingEntity *ge, |
| 343 |
void *data) const |
| 344 |
{ |
| 345 |
int64_t num_entity = ge->entity_count(); |
| 346 |
IOSS_MAYBE_UNUSED int64_t offset = field.get_index(); |
| 347 |
|
| 348 |
assert(offset > 0); |
| 349 |
assert(offset - 1 + field.get_component_count(Ioss::Field::InOut::OUTPUT) <= |
| 350 |
ge->get_property("attribute_count").get_int()); |
| 351 |
|
| 352 |
int64_t file_count = ge->get_optional_property("locally_owned_count", num_entity); |
| 353 |
|
| 354 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 355 |
assert(ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::INTEGER || |
| 356 |
ioss_type == Ioss::Field::INT64); |
| 357 |
|
| 358 |
if (ioss_type == Ioss::Field::INT64) { |
| 359 |
Ioss::Utils::check_int_to_real_overflow(field, (int64_t *)data, num_entity); |
| 360 |
} |
| 361 |
|
| 362 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 363 |
|
| 364 |
ex_entity_type type = Ioexnl::map_exodus_type(ge->type()); |
| 365 |
if (type == EX_NODAL) { |
| 366 |
for (int i = 0; i < comp_count; i++) { |
| 367 |
std::vector<double> file_data; |
| 368 |
file_data.reserve(file_count); |
| 369 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 370 |
if (ioss_type == Ioss::Field::REAL) { |
| 371 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, static_cast<double *>(data), |
| 372 |
file_data, i, comp_count); |
| 373 |
} |
| 374 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 375 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, static_cast<int *>(data), file_data, |
| 376 |
i, comp_count); |
| 377 |
} |
| 378 |
else if (ioss_type == Ioss::Field::INT64) { |
| 379 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, static_cast<int64_t *>(data), |
| 380 |
file_data, i, comp_count); |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
else if (type == EX_NODE_SET) { |
| 385 |
for (int i = 0; i < comp_count; i++) { |
| 386 |
std::vector<double> file_data; |
| 387 |
file_data.reserve(file_count); |
| 388 |
if (ioss_type == Ioss::Field::REAL) { |
| 389 |
map_nodeset_data(nodesetOwnedNodes[ge], static_cast<double *>(data), file_data, i, |
| 390 |
comp_count); |
| 391 |
} |
| 392 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 393 |
map_nodeset_data(nodesetOwnedNodes[ge], static_cast<int *>(data), file_data, i, |
| 394 |
comp_count); |
| 395 |
} |
| 396 |
else if (ioss_type == Ioss::Field::INT64) { |
| 397 |
map_nodeset_data(nodesetOwnedNodes[ge], static_cast<int64_t *>(data), file_data, i, |
| 398 |
comp_count); |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
else { |
| 403 |
assert(file_count == num_entity); |
| 404 |
std::vector<double> file_data(file_count); |
| 405 |
for (int i = 0; i < comp_count; i++) { |
| 406 |
if (ioss_type == Ioss::Field::REAL) { |
| 407 |
extract_data(file_data, static_cast<double *>(data), num_entity, i, comp_count); |
| 408 |
} |
| 409 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 410 |
extract_data(file_data, static_cast<int *>(data), num_entity, i, comp_count); |
| 411 |
} |
| 412 |
else if (ioss_type == Ioss::Field::INT64) { |
| 413 |
extract_data(file_data, static_cast<int64_t *>(data), num_entity, i, comp_count); |
| 414 |
} |
| 415 |
} |
| 416 |
} |
| 417 |
return num_entity; |
| 418 |
} |
| 419 |
|
| 420 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, |
| 421 |
void *data, size_t data_size) const |
| 422 |
{ |
| 423 |
return Ioexnl::BaseDatabaseIO::put_field_internal(reg, field, data, data_size); |
| 424 |
} |
| 425 |
|
| 426 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::NodeBlock *nb, |
| 427 |
const Ioss::Field &field, void *data, |
| 428 |
size_t data_size) const |
| 429 |
{ |
| 430 |
size_t num_to_get = field.verify(data_size); |
| 431 |
|
| 432 |
size_t proc_offset = nb->get_optional_property("_processor_offset", 0); |
| 433 |
size_t file_count = nb->get_optional_property("locally_owned_count", num_to_get); |
| 434 |
|
| 435 |
Ioss::Field::RoleType role = field.get_role(); |
| 436 |
|
| 437 |
if (role == Ioss::Field::MESH) { |
| 438 |
if (field.get_name() == "owning_processor") { |
| 439 |
// Set the nodeOwningProcessor vector for all nodes on this processor. |
| 440 |
// Value is the processor that owns the node. |
| 441 |
|
| 442 |
// NOTE: The owning_processor field is always int32 |
| 443 |
nodeOwningProcessor.reserve(num_to_get); |
| 444 |
int *owned = (int *)data; |
| 445 |
for (size_t i = 0; i < num_to_get; i++) { |
| 446 |
nodeOwningProcessor.push_back(owned[i]); |
| 447 |
} |
| 448 |
|
| 449 |
// Now create the "implicit local" to "implicit global" |
| 450 |
// map which maps data from its local implicit position |
| 451 |
// to its implicit (1..num_global_node) position in the |
| 452 |
// global file. This is needed for the global-to-local |
| 453 |
// mapping of element connectivity and nodeset nodelists. |
| 454 |
create_implicit_global_map(); |
| 455 |
} |
| 456 |
|
| 457 |
else if (field.get_name() == "mesh_model_coordinates_x") { |
| 458 |
double *rdata = static_cast<double *>(data); |
| 459 |
std::vector<double> file_data; |
| 460 |
file_data.reserve(file_count); |
| 461 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 462 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, file_data); |
| 463 |
} |
| 464 |
|
| 465 |
else if (field.get_name() == "mesh_model_coordinates_y") { |
| 466 |
double *rdata = static_cast<double *>(data); |
| 467 |
std::vector<double> file_data; |
| 468 |
file_data.reserve(file_count); |
| 469 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 470 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, file_data); |
| 471 |
} |
| 472 |
|
| 473 |
else if (field.get_name() == "mesh_model_coordinates_z") { |
| 474 |
double *rdata = static_cast<double *>(data); |
| 475 |
std::vector<double> file_data; |
| 476 |
file_data.reserve(file_count); |
| 477 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 478 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, file_data); |
| 479 |
} |
| 480 |
|
| 481 |
else if (field.get_name() == "mesh_model_coordinates") { |
| 482 |
// Data required by upper classes store x0, y0, z0, ... xn, yn, zn |
| 483 |
// Data stored in exodusII file is x0, ..., xn, y0, ..., yn, z0, ..., zn |
| 484 |
// so we have to allocate some scratch memory to read in the data |
| 485 |
// and then map into supplied 'data' |
| 486 |
std::vector<double> x; |
| 487 |
std::vector<double> y; |
| 488 |
std::vector<double> z; |
| 489 |
|
| 490 |
x.reserve(file_count > 0 ? file_count : 1); |
| 491 |
if (spatialDimension > 1) { |
| 492 |
y.reserve(file_count > 0 ? file_count : 1); |
| 493 |
} |
| 494 |
if (spatialDimension == 3) { |
| 495 |
z.reserve(file_count > 0 ? file_count : 1); |
| 496 |
} |
| 497 |
|
| 498 |
// Cast 'data' to correct size -- double |
| 499 |
double *rdata = static_cast<double *>(data); |
| 500 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 501 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, x, 0, spatialDimension); |
| 502 |
if (spatialDimension > 1) { |
| 503 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, y, 1, spatialDimension); |
| 504 |
} |
| 505 |
if (spatialDimension == 3) { |
| 506 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, rdata, z, 2, spatialDimension); |
| 507 |
} |
| 508 |
} |
| 509 |
else if (field.get_name() == "ids") { |
| 510 |
// The ids coming in are the global ids; their position is the |
| 511 |
// local id -1 (That is, data[0] contains the global id of local |
| 512 |
// node 1) |
| 513 |
|
| 514 |
// Another 'const-cast' since we are modifying the database just |
| 515 |
// for efficiency; which the client does not see... |
| 516 |
handle_node_ids(data, num_to_get, proc_offset, file_count); |
| 517 |
} |
| 518 |
else if (field.get_name() == "connectivity") { |
| 519 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 520 |
} |
| 521 |
else if (field.get_name() == "connectivity_raw") { |
| 522 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 523 |
} |
| 524 |
else if (field.get_name() == "node_connectivity_status") { |
| 525 |
// Do nothing, input only field. |
| 526 |
} |
| 527 |
else if (field.get_name() == "implicit_ids") { |
| 528 |
// Do nothing, input only field. |
| 529 |
} |
| 530 |
else { |
| 531 |
return Ioss::Utils::field_warning(nb, field, "mesh output"); |
| 532 |
} |
| 533 |
} |
| 534 |
else if (role == Ioss::Field::TRANSIENT) { |
| 535 |
// Check if the specified field exists on this node block. |
| 536 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 537 |
// exist on the database as scalars with the appropriate |
| 538 |
// extensions. |
| 539 |
|
| 540 |
// Transfer each component of the variable into 'data' and then |
| 541 |
// output. Need temporary storage area of size 'number of |
| 542 |
// nodes in this block. |
| 543 |
write_nodal_transient_field(field, nb, num_to_get, data); |
| 544 |
} |
| 545 |
else if (role == Ioss::Field::REDUCTION) { |
| 546 |
store_reduction_field(field, nb, data); |
| 547 |
} |
| 548 |
return num_to_get; |
| 549 |
} |
| 550 |
|
| 551 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, |
| 552 |
void *data, size_t data_size) const |
| 553 |
{ |
| 554 |
size_t num_to_get = field.verify(data_size); |
| 555 |
if (num_to_get > 0) { |
| 556 |
|
| 557 |
Ioss::Field::RoleType role = field.get_role(); |
| 558 |
|
| 559 |
if (role == Ioss::Field::MESH) { |
| 560 |
if (field.get_name() == "ids") { |
| 561 |
// The ids coming in are the global ids; their position is the |
| 562 |
// local id -1 (That is, data[0] contains the global id of local |
| 563 |
// node 1) |
| 564 |
// handle_node_ids(data, num_to_get); |
| 565 |
} |
| 566 |
else if (field.get_name() == "connectivity") { |
| 567 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 568 |
} |
| 569 |
else if (field.get_name() == "connectivity_raw") { |
| 570 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 571 |
} |
| 572 |
else if (field.get_name() == "node_connectivity_status") { |
| 573 |
// Do nothing, input only field. |
| 574 |
} |
| 575 |
else if (field.get_name() == "implicit_ids") { |
| 576 |
// Do nothing, input only field. |
| 577 |
} |
| 578 |
else { |
| 579 |
return Ioss::Utils::field_warning(blob, field, "mesh output"); |
| 580 |
} |
| 581 |
} |
| 582 |
else if (role == Ioss::Field::TRANSIENT) { |
| 583 |
// Check if the specified field exists on this node block. |
| 584 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 585 |
// exist on the database as scalars with the appropriate |
| 586 |
// extensions. |
| 587 |
|
| 588 |
// Transfer each component of the variable into 'data' and then |
| 589 |
// output. Need temporary storage area of size 'number of |
| 590 |
// nodes in this block. |
| 591 |
write_entity_transient_field(field, blob, num_to_get, data); |
| 592 |
} |
| 593 |
else if (role == Ioss::Field::REDUCTION) { |
| 594 |
store_reduction_field(field, blob, data); |
| 595 |
} |
| 596 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 597 |
num_to_get = write_attribute_field(field, blob, data); |
| 598 |
} |
| 599 |
} |
| 600 |
return num_to_get; |
| 601 |
} |
| 602 |
|
| 603 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::Assembly *assembly, |
| 604 |
const Ioss::Field &field, void *data, |
| 605 |
size_t data_size) const |
| 606 |
{ |
| 607 |
size_t num_to_get = field.verify(data_size); |
| 608 |
if (num_to_get > 0) { |
| 609 |
|
| 610 |
Ioss::Field::RoleType role = field.get_role(); |
| 611 |
|
| 612 |
if (role == Ioss::Field::MESH) { |
| 613 |
if (field.get_name() == "ids") { |
| 614 |
// The ids coming in are the global ids; their position is the |
| 615 |
// local id -1 (That is, data[0] contains the global id of local |
| 616 |
// node 1) |
| 617 |
// handle_node_ids(data, num_to_get); |
| 618 |
} |
| 619 |
else if (field.get_name() == "connectivity") { |
| 620 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 621 |
} |
| 622 |
else if (field.get_name() == "connectivity_raw") { |
| 623 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 624 |
} |
| 625 |
else if (field.get_name() == "node_connectivity_status") { |
| 626 |
// Do nothing, input only field. |
| 627 |
} |
| 628 |
else if (field.get_name() == "implicit_ids") { |
| 629 |
// Do nothing, input only field. |
| 630 |
} |
| 631 |
else { |
| 632 |
return Ioss::Utils::field_warning(assembly, field, "mesh output"); |
| 633 |
} |
| 634 |
} |
| 635 |
else if (role == Ioss::Field::TRANSIENT) { |
| 636 |
// Check if the specified field exists on this node block. |
| 637 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 638 |
// exist on the database as scalars with the appropriate |
| 639 |
// extensions. |
| 640 |
|
| 641 |
// Transfer each component of the variable into 'data' and then |
| 642 |
// output. Need temporary storage area of size 'number of |
| 643 |
// nodes in this block. |
| 644 |
write_entity_transient_field(field, assembly, num_to_get, data); |
| 645 |
} |
| 646 |
else if (role == Ioss::Field::REDUCTION) { |
| 647 |
store_reduction_field(field, assembly, data); |
| 648 |
} |
| 649 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 650 |
num_to_get = write_attribute_field(field, assembly, data); |
| 651 |
} |
| 652 |
} |
| 653 |
return num_to_get; |
| 654 |
} |
| 655 |
|
| 656 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::ElementBlock *eb, |
| 657 |
const Ioss::Field &field, void *data, |
| 658 |
size_t data_size) const |
| 659 |
{ |
| 660 |
size_t num_to_get = field.verify(data_size); |
| 661 |
|
| 662 |
// Get the element block id and element count |
| 663 |
int64_t my_element_count = eb->entity_count(); |
| 664 |
Ioss::Field::RoleType role = field.get_role(); |
| 665 |
|
| 666 |
auto proc_offset = eb->get_optional_property("_processor_offset", 0); |
| 667 |
auto file_count = eb->get_optional_property("locally_owned_count", num_to_get); |
| 668 |
|
| 669 |
if (role == Ioss::Field::MESH) { |
| 670 |
// Handle the MESH fields required for an ExodusII file model. |
| 671 |
// (The 'genesis' portion) |
| 672 |
if (field.get_name() == "connectivity") { |
| 673 |
// Map element connectivity from global node id to local node id. |
| 674 |
int element_nodes = eb->topology()->number_nodes(); |
| 675 |
|
| 676 |
// Maps global to local |
| 677 |
nodeMap.reverse_map_data(data, field, num_to_get * element_nodes); |
| 678 |
|
| 679 |
// Maps local to "global_implicit" |
| 680 |
if (int_byte_size_api() == 4) { |
| 681 |
map_local_to_global_implicit(reinterpret_cast<int *>(data), num_to_get * element_nodes, |
| 682 |
nodeGlobalImplicitMap); |
| 683 |
} |
| 684 |
else { |
| 685 |
map_local_to_global_implicit(reinterpret_cast<int64_t *>(data), |
| 686 |
num_to_get * element_nodes, nodeGlobalImplicitMap); |
| 687 |
} |
| 688 |
} |
| 689 |
else if (field.get_name() == "connectivity_edge") { |
| 690 |
// Map element connectivity from global edge id to local edge id. |
| 691 |
int element_edges = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 692 |
edgeMap.reverse_map_data(data, field, num_to_get * element_edges); |
| 693 |
} |
| 694 |
else if (field.get_name() == "connectivity_face") { |
| 695 |
// Map element connectivity from global face id to local face id. |
| 696 |
int element_faces = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 697 |
faceMap.reverse_map_data(data, field, num_to_get * element_faces); |
| 698 |
} |
| 699 |
else if (field.get_name() == "connectivity_raw") { |
| 700 |
// Element connectivity is already in local node id, map local to "global_implicit" |
| 701 |
int element_nodes = eb->topology()->number_nodes(); |
| 702 |
if (int_byte_size_api() == 4) { |
| 703 |
map_local_to_global_implicit(reinterpret_cast<int *>(data), num_to_get * element_nodes, |
| 704 |
nodeGlobalImplicitMap); |
| 705 |
} |
| 706 |
else { |
| 707 |
map_local_to_global_implicit(reinterpret_cast<int64_t *>(data), |
| 708 |
num_to_get * element_nodes, nodeGlobalImplicitMap); |
| 709 |
} |
| 710 |
} |
| 711 |
else if (field.get_name() == "ids") { |
| 712 |
size_t glob_map_offset = eb->get_property("global_map_offset").get_int(); |
| 713 |
handle_element_ids(eb, data, num_to_get, glob_map_offset + proc_offset, file_count); |
| 714 |
} |
| 715 |
else if (field.get_name() == "implicit_ids") { |
| 716 |
// Do nothing, input only field. |
| 717 |
} |
| 718 |
} |
| 719 |
else if (role == Ioss::Field::MAP) { |
| 720 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 721 |
for (int comp = 0; comp < comp_count; comp++) { |
| 722 |
std::vector<char> component(my_element_count * int_byte_size_api()); |
| 723 |
|
| 724 |
if (int_byte_size_api() == 4) { |
| 725 |
int *data32 = reinterpret_cast<int *>(data); |
| 726 |
int *comp32 = reinterpret_cast<int *>(Data(component)); |
| 727 |
|
| 728 |
int index = comp; |
| 729 |
for (int64_t i = 0; i < my_element_count; i++) { |
| 730 |
comp32[i] = data32[index]; |
| 731 |
index += comp_count; |
| 732 |
} |
| 733 |
} |
| 734 |
else { |
| 735 |
int64_t *data64 = reinterpret_cast<int64_t *>(data); |
| 736 |
int64_t *comp64 = reinterpret_cast<int64_t *>(Data(component)); |
| 737 |
|
| 738 |
int index = comp; |
| 739 |
for (int64_t i = 0; i < my_element_count; i++) { |
| 740 |
comp64[i] = data64[index]; |
| 741 |
index += comp_count; |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 747 |
num_to_get = write_attribute_field(field, eb, data); |
| 748 |
} |
| 749 |
else if (role == Ioss::Field::TRANSIENT) { |
| 750 |
// Check if the specified field exists on this element block. |
| 751 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 752 |
// exist on the database as scalars with the appropriate |
| 753 |
// extensions. |
| 754 |
|
| 755 |
// Transfer each component of the variable into 'data' and then |
| 756 |
// output. Need temporary storage area of size 'number of |
| 757 |
// elements in this block. |
| 758 |
auto global_entity_count = eb->get_property("global_entity_count").get_int(); |
| 759 |
if (global_entity_count > 0) { |
| 760 |
write_entity_transient_field(field, eb, my_element_count, data); |
| 761 |
} |
| 762 |
} |
| 763 |
else if (role == Ioss::Field::REDUCTION) { |
| 764 |
store_reduction_field(field, eb, data); |
| 765 |
} |
| 766 |
return num_to_get; |
| 767 |
} |
| 768 |
|
| 769 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::FaceBlock *eb, |
| 770 |
const Ioss::Field &field, void *data, |
| 771 |
size_t data_size) const |
| 772 |
{ |
| 773 |
size_t num_to_get = field.verify(data_size); |
| 774 |
|
| 775 |
// Get the face block id and face count |
| 776 |
int64_t my_face_count = eb->entity_count(); |
| 777 |
Ioss::Field::RoleType role = field.get_role(); |
| 778 |
|
| 779 |
if (role == Ioss::Field::MESH) { |
| 780 |
// Handle the MESH fields required for an ExodusII file model. |
| 781 |
// (The 'genesis' portion) |
| 782 |
if (field.get_name() == "connectivity") { |
| 783 |
if (my_face_count > 0) { |
| 784 |
// Map face connectivity from global node id to local node id. |
| 785 |
int face_nodes = eb->topology()->number_nodes(); |
| 786 |
nodeMap.reverse_map_data(data, field, num_to_get * face_nodes); |
| 787 |
} |
| 788 |
} |
| 789 |
else if (field.get_name() == "connectivity_edge") { |
| 790 |
if (my_face_count > 0) { |
| 791 |
// Map face connectivity from global edge id to local edge id. |
| 792 |
// Do it in 'data' ... |
| 793 |
int face_edges = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 794 |
edgeMap.reverse_map_data(data, field, num_to_get * face_edges); |
| 795 |
} |
| 796 |
} |
| 797 |
else if (field.get_name() == "connectivity_raw") { |
| 798 |
// Do nothing, input only field. |
| 799 |
} |
| 800 |
else if (field.get_name() == "ids") { |
| 801 |
handle_face_ids(eb, data, num_to_get); |
| 802 |
} |
| 803 |
else { |
| 804 |
num_to_get = Ioss::Utils::field_warning(eb, field, "mesh output"); |
| 805 |
} |
| 806 |
} |
| 807 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 808 |
num_to_get = write_attribute_field(field, eb, data); |
| 809 |
} |
| 810 |
else if (role == Ioss::Field::TRANSIENT) { |
| 811 |
// Check if the specified field exists on this face block. |
| 812 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 813 |
// exist on the database as scalars with the appropriate |
| 814 |
// extensions. |
| 815 |
|
| 816 |
// Transfer each component of the variable into 'data' and then |
| 817 |
// output. Need temporary storage area of size 'number of |
| 818 |
// faces in this block. |
| 819 |
write_entity_transient_field(field, eb, my_face_count, data); |
| 820 |
} |
| 821 |
else if (role == Ioss::Field::REDUCTION) { |
| 822 |
store_reduction_field(field, eb, data); |
| 823 |
} |
| 824 |
return num_to_get; |
| 825 |
} |
| 826 |
|
| 827 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::EdgeBlock *eb, |
| 828 |
const Ioss::Field &field, void *data, |
| 829 |
size_t data_size) const |
| 830 |
{ |
| 831 |
size_t num_to_get = field.verify(data_size); |
| 832 |
|
| 833 |
// Get the edge block id and edge count |
| 834 |
int64_t my_edge_count = eb->entity_count(); |
| 835 |
Ioss::Field::RoleType role = field.get_role(); |
| 836 |
|
| 837 |
if (role == Ioss::Field::MESH) { |
| 838 |
// Handle the MESH fields required for an ExodusII file model. (The 'genesis' portion) |
| 839 |
if (field.get_name() == "connectivity") { |
| 840 |
if (my_edge_count > 0) { |
| 841 |
// Map edge connectivity from global node id to local node id. |
| 842 |
int edge_nodes = eb->topology()->number_nodes(); |
| 843 |
nodeMap.reverse_map_data(data, field, num_to_get * edge_nodes); |
| 844 |
} |
| 845 |
} |
| 846 |
else if (field.get_name() == "connectivity_raw") { |
| 847 |
// Do nothing, input only field. |
| 848 |
} |
| 849 |
else if (field.get_name() == "ids") { |
| 850 |
handle_edge_ids(eb, data, num_to_get); |
| 851 |
} |
| 852 |
else { |
| 853 |
num_to_get = Ioss::Utils::field_warning(eb, field, "mesh output"); |
| 854 |
} |
| 855 |
} |
| 856 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 857 |
num_to_get = write_attribute_field(field, eb, data); |
| 858 |
} |
| 859 |
else if (role == Ioss::Field::TRANSIENT) { |
| 860 |
// Check if the specified field exists on this edge block. |
| 861 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 862 |
// exist on the database as scalars with the appropriate |
| 863 |
// extensions. |
| 864 |
|
| 865 |
// Transfer each component of the variable into 'data' and then |
| 866 |
// output. Need temporary storage area of size 'number of |
| 867 |
// edges in this block. |
| 868 |
write_entity_transient_field(field, eb, my_edge_count, data); |
| 869 |
} |
| 870 |
else if (role == Ioss::Field::REDUCTION) { |
| 871 |
store_reduction_field(field, eb, data); |
| 872 |
} |
| 873 |
return num_to_get; |
| 874 |
} |
| 875 |
|
| 876 |
int64_t ParallelDatabaseIO::handle_node_ids(void *ids, int64_t num_to_get, size_t /* offset */, |
| 877 |
size_t /*count*/) const |
| 878 |
{ |
| 879 |
/*! |
| 880 |
* There are two modes we need to support in this routine: |
| 881 |
* 1. Initial definition of node map (local->global) and |
| 882 |
* nodeMap.reverse (global->local). |
| 883 |
* 2. Redefinition of node map via 'reordering' of the original |
| 884 |
* map when the nodes on this processor are the same, but their |
| 885 |
* order is changed (or count because of ghosting) |
| 886 |
* |
| 887 |
* So, there will be two maps the 'nodeMap.map' map is a 'direct lookup' |
| 888 |
* map which maps current local position to global id and the |
| 889 |
* 'nodeMap.reverse' is an associative lookup which maps the |
| 890 |
* global id to 'original local'. There is also a |
| 891 |
* 'nodeMap.reorder' which is direct lookup and maps current local |
| 892 |
* position to original local. |
| 893 |
|
| 894 |
* The ids coming in are the global ids; their position is the |
| 895 |
* "local id-1" (That is, data[0] contains the global id of local |
| 896 |
* node 1 in this node block). |
| 897 |
* |
| 898 |
* int local_position = nodeMap.reverse[NodeMap[i+1]] |
| 899 |
* (the nodeMap.map and nodeMap.reverse are 1-based) |
| 900 |
* |
| 901 |
* To determine which map to update on a call to this function, we |
| 902 |
* use the following heuristics: |
| 903 |
* -- If the database state is 'STATE_MODEL:', then update the |
| 904 |
* 'nodeMap.reverse' and 'nodeMap.map' |
| 905 |
* |
| 906 |
* -- If the database state is not STATE_MODEL, then leave the |
| 907 |
* 'nodeMap.reverse' and 'nodeMap.map' alone since they correspond to the |
| 908 |
* information already written to the database. [May want to add a |
| 909 |
* STATE_REDEFINE_MODEL] |
| 910 |
* |
| 911 |
* -- In both cases, update the nodeMap.reorder |
| 912 |
* |
| 913 |
* NOTE: The mapping is done on TRANSIENT fields only; MODEL fields |
| 914 |
* should be in the original order... |
| 915 |
*/ |
| 916 |
nodeMap.set_size(num_to_get); |
| 917 |
|
| 918 |
bool in_define = (dbState == Ioss::STATE_MODEL) || (dbState == Ioss::STATE_DEFINE_MODEL); |
| 919 |
if (int_byte_size_api() == 4) { |
| 920 |
nodeMap.set_map(static_cast<int *>(ids), num_to_get, 0, in_define); |
| 921 |
} |
| 922 |
else { |
| 923 |
nodeMap.set_map(static_cast<int64_t *>(ids), num_to_get, 0, in_define); |
| 924 |
} |
| 925 |
|
| 926 |
nodeMap.set_defined(true); |
| 927 |
return num_to_get; |
| 928 |
} |
| 929 |
|
| 930 |
int64_t ParallelDatabaseIO::handle_element_ids(const Ioss::ElementBlock *eb, void *ids, |
| 931 |
size_t num_to_get, size_t offset, |
| 932 |
size_t count) const |
| 933 |
{ |
| 934 |
if (dbState == Ioss::STATE_MODEL) { |
| 935 |
if (elemGlobalImplicitMap.empty()) { |
| 936 |
elemGlobalImplicitMap.resize(elementCount); |
| 937 |
} |
| 938 |
// Build the implicit_global map used to map an elements |
| 939 |
// local-implicit position to the global-implicit |
| 940 |
// position. Primarily used for sideset elements. 'count' |
| 941 |
// Elements starting at 'eb_offset' map to the global implicit |
| 942 |
// position of 'offset' |
| 943 |
int64_t eb_offset = eb->get_offset(); |
| 944 |
for (size_t i = 0; i < count; i++) { |
| 945 |
elemGlobalImplicitMap[eb_offset + i] = offset + i + 1; |
| 946 |
} |
| 947 |
elemGlobalImplicitMapDefined = true; |
| 948 |
} |
| 949 |
|
| 950 |
elemMap.set_size(elementCount); |
| 951 |
return handle_block_ids(eb, EX_ELEM_MAP, elemMap, ids, num_to_get, offset); |
| 952 |
} |
| 953 |
|
| 954 |
int64_t ParallelDatabaseIO::handle_face_ids(const Ioss::FaceBlock *eb, void *ids, |
| 955 |
size_t num_to_get) const |
| 956 |
{ |
| 957 |
faceMap.set_size(faceCount); |
| 958 |
return handle_block_ids(eb, EX_FACE_MAP, faceMap, ids, num_to_get, 0); |
| 959 |
} |
| 960 |
|
| 961 |
int64_t ParallelDatabaseIO::handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, |
| 962 |
size_t num_to_get) const |
| 963 |
{ |
| 964 |
edgeMap.set_size(edgeCount); |
| 965 |
return handle_block_ids(eb, EX_EDGE_MAP, edgeMap, ids, num_to_get, 0); |
| 966 |
} |
| 967 |
|
| 968 |
void ParallelDatabaseIO::write_nodal_transient_field(const Ioss::Field &field, |
| 969 |
const Ioss::NodeBlock *nb, int64_t count, |
| 970 |
void *variables) const |
| 971 |
{ |
| 972 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 973 |
assert(ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::INTEGER || |
| 974 |
ioss_type == Ioss::Field::INT64 || ioss_type == Ioss::Field::COMPLEX); |
| 975 |
|
| 976 |
if (ioss_type == Ioss::Field::INT64) { |
| 977 |
Ioss::Utils::check_int_to_real_overflow(field, (int64_t *)variables, count); |
| 978 |
} |
| 979 |
|
| 980 |
// Note that if the field's basic type is COMPLEX, then each component of |
| 981 |
// the VariableType is a complex variable consisting of a real and |
| 982 |
// imaginary part. Since exodus cannot handle complex variables, |
| 983 |
// we have to output a (real and imaginary) X (number of |
| 984 |
// components) fields. For example, if V is a 3d vector of complex |
| 985 |
// data, the data in the 'variables' array are v_x, v.im_x, v_y, |
| 986 |
// v.im_y, v_z, v.im_z which need to be output in six separate |
| 987 |
// exodus fields. These fields were already defined in |
| 988 |
// "write_results_metadata". |
| 989 |
|
| 990 |
std::vector<double> temp(count); |
| 991 |
|
| 992 |
int step = get_current_state(); |
| 993 |
step = get_database_step(step); |
| 994 |
|
| 995 |
// get number of components, cycle through each component |
| 996 |
// and add suffix to base 'field_name'. Look up index |
| 997 |
// of this name in 'm_variables[EX_NODE_BLOCK]' map |
| 998 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 999 |
|
| 1000 |
int re_im = 1; |
| 1001 |
if (ioss_type == Ioss::Field::COMPLEX) { |
| 1002 |
re_im = 2; |
| 1003 |
} |
| 1004 |
for (int complex_comp = 0; complex_comp < re_im; complex_comp++) { |
| 1005 |
for (int i = 0; i < comp_count; i++) { |
| 1006 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::OUTPUT, i + 1); |
| 1007 |
|
| 1008 |
auto var_iter = m_variables[EX_NODE_BLOCK].find(var_name); |
| 1009 |
if (var_iter == m_variables[EX_NODE_BLOCK].end()) { |
| 1010 |
std::ostringstream errmsg; |
| 1011 |
fmt::print(errmsg, "ERROR: Could not find nodal variable '{}'\n", var_name); |
| 1012 |
IOSS_ERROR(errmsg); |
| 1013 |
} |
| 1014 |
|
| 1015 |
int var_index = var_iter->second; |
| 1016 |
|
| 1017 |
size_t begin_offset = (re_im * i) + complex_comp; |
| 1018 |
size_t stride = re_im * comp_count; |
| 1019 |
size_t num_out = 0; |
| 1020 |
|
| 1021 |
if (ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::COMPLEX) { |
| 1022 |
num_out = nodeMap.map_field_to_db_scalar_order(static_cast<double *>(variables), temp, |
| 1023 |
begin_offset, count, stride, 0); |
| 1024 |
} |
| 1025 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 1026 |
num_out = nodeMap.map_field_to_db_scalar_order(static_cast<int *>(variables), temp, |
| 1027 |
begin_offset, count, stride, 0); |
| 1028 |
} |
| 1029 |
else if (ioss_type == Ioss::Field::INT64) { |
| 1030 |
num_out = nodeMap.map_field_to_db_scalar_order(static_cast<int64_t *>(variables), temp, |
| 1031 |
begin_offset, count, stride, 0); |
| 1032 |
} |
| 1033 |
|
| 1034 |
if (num_out != static_cast<size_t>(nodeCount)) { |
| 1035 |
std::ostringstream errmsg; |
| 1036 |
fmt::print( |
| 1037 |
errmsg, |
| 1038 |
"ERROR: Problem outputting nodal variable '{}' with index = {} to file '{}' on " |
| 1039 |
"processor {}\n" |
| 1040 |
"\tShould have output {} values, but instead only output {} values.\n", |
| 1041 |
var_name, var_index, get_filename(), myProcessor, fmt::group_digits(nodeCount), |
| 1042 |
fmt::group_digits(num_out)); |
| 1043 |
IOSS_ERROR(errmsg); |
| 1044 |
} |
| 1045 |
|
| 1046 |
// Write the variable... |
| 1047 |
size_t file_count = nb->get_optional_property("locally_owned_count", num_out); |
| 1048 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 1049 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, Data(temp)); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
} |
| 1053 |
|
| 1054 |
void ParallelDatabaseIO::write_entity_transient_field(const Ioss::Field &field, |
| 1055 |
const Ioss::GroupingEntity *ge, |
| 1056 |
int64_t count, void *variables) const |
| 1057 |
{ |
| 1058 |
static Ioss::Map non_element_map; // Used as an empty map for ge->type() != element block. |
| 1059 |
std::vector<double> temp(count); |
| 1060 |
|
| 1061 |
int step = get_current_state(); |
| 1062 |
step = get_database_step(step); |
| 1063 |
|
| 1064 |
Ioss::Map *map = nullptr; |
| 1065 |
int64_t eb_offset = 0; |
| 1066 |
if (ge->type() == Ioss::ELEMENTBLOCK) { |
| 1067 |
const Ioss::ElementBlock *elb = dynamic_cast<const Ioss::ElementBlock *>(ge); |
| 1068 |
Ioss::Utils::check_dynamic_cast(elb); |
| 1069 |
eb_offset = elb->get_offset(); |
| 1070 |
map = &elemMap; |
| 1071 |
} |
| 1072 |
else { |
| 1073 |
map = &non_element_map; |
| 1074 |
} |
| 1075 |
|
| 1076 |
Ioss::Field::BasicType ioss_type = field.get_type(); |
| 1077 |
assert(ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::INTEGER || |
| 1078 |
ioss_type == Ioss::Field::INT64 || ioss_type == Ioss::Field::COMPLEX); |
| 1079 |
|
| 1080 |
if (ioss_type == Ioss::Field::INT64) { |
| 1081 |
Ioss::Utils::check_int_to_real_overflow(field, (int64_t *)variables, count); |
| 1082 |
} |
| 1083 |
|
| 1084 |
// Note that if the field's basic type is COMPLEX, then each component of |
| 1085 |
// the VariableType is a complex variable consisting of a real and |
| 1086 |
// imaginary part. Since exodus cannot handle complex variables, |
| 1087 |
// we have to output a (real and imaginary) X (number of |
| 1088 |
// components) fields. For example, if V is a 3d vector of complex |
| 1089 |
// data, the data in the 'variables' array are v_x, v.im_x, v_y, |
| 1090 |
// v.im_y, v_z, v.im_z which need to be output in six separate |
| 1091 |
// exodus fields. These fields were already defined in |
| 1092 |
// "write_results_metadata". |
| 1093 |
|
| 1094 |
// get number of components, cycle through each component |
| 1095 |
// and add suffix to base 'field_name'. Look up index |
| 1096 |
// of this name in 'm_variables[type]' map |
| 1097 |
int comp_count = field.get_component_count(Ioss::Field::InOut::OUTPUT); |
| 1098 |
ex_entity_type type = Ioexnl::map_exodus_type(ge->type()); |
| 1099 |
|
| 1100 |
int re_im = 1; |
| 1101 |
if (ioss_type == Ioss::Field::COMPLEX) { |
| 1102 |
re_im = 2; |
| 1103 |
} |
| 1104 |
for (int complex_comp = 0; complex_comp < re_im; complex_comp++) { |
| 1105 |
for (int i = 0; i < comp_count; i++) { |
| 1106 |
std::string var_name = get_component_name(field, Ioss::Field::InOut::OUTPUT, i + 1); |
| 1107 |
|
| 1108 |
auto var_iter = m_variables[type].find(var_name); |
| 1109 |
if (var_iter == m_variables[type].end()) { |
| 1110 |
std::ostringstream errmsg; |
| 1111 |
fmt::print(errmsg, "ERROR: Could not find field '{}'\n", var_name); |
| 1112 |
IOSS_ERROR(errmsg); |
| 1113 |
} |
| 1114 |
|
| 1115 |
// var is a [count,comp,re_im] array; re_im = 1(real) or 2(complex) |
| 1116 |
// beg_offset = (re_im*i)+complex_comp |
| 1117 |
// number_values = count |
| 1118 |
// stride = re_im*comp_count |
| 1119 |
int64_t begin_offset = (re_im * i) + complex_comp; |
| 1120 |
int64_t stride = re_im * comp_count; |
| 1121 |
|
| 1122 |
if (ioss_type == Ioss::Field::REAL || ioss_type == Ioss::Field::COMPLEX) { |
| 1123 |
map->map_field_to_db_scalar_order(static_cast<double *>(variables), temp, begin_offset, |
| 1124 |
count, stride, eb_offset); |
| 1125 |
} |
| 1126 |
else if (ioss_type == Ioss::Field::INTEGER) { |
| 1127 |
map->map_field_to_db_scalar_order(static_cast<int *>(variables), temp, begin_offset, |
| 1128 |
count, stride, eb_offset); |
| 1129 |
} |
| 1130 |
else if (ioss_type == Ioss::Field::INT64) { |
| 1131 |
map->map_field_to_db_scalar_order(static_cast<int64_t *>(variables), temp, begin_offset, |
| 1132 |
count, stride, eb_offset); |
| 1133 |
} |
| 1134 |
|
| 1135 |
// Write the variable... |
| 1136 |
size_t file_count = ge->get_optional_property("locally_owned_count", count); |
| 1137 |
if (type == EX_NODE_SET) { |
| 1138 |
std::vector<double> file_data; |
| 1139 |
file_data.reserve(file_count); |
| 1140 |
map_nodeset_data(nodesetOwnedNodes[ge], Data(temp), file_data); |
| 1141 |
} |
| 1142 |
} |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
int64_t ParallelDatabaseIO::put_Xset_field_internal(const Ioss::EntitySet *ns, |
| 1147 |
const Ioss::Field &field, void *data, |
| 1148 |
size_t data_size) const |
| 1149 |
{ |
| 1150 |
size_t entity_count = ns->entity_count(); |
| 1151 |
size_t num_to_get = field.verify(data_size); |
| 1152 |
|
| 1153 |
Ioss::Field::RoleType role = field.get_role(); |
| 1154 |
if (role == Ioss::Field::MESH) { |
| 1155 |
size_t file_count = ns->get_optional_property("locally_owned_count", num_to_get); |
| 1156 |
|
| 1157 |
ex_entity_type type = Ioexnl::map_exodus_type(ns->type()); |
| 1158 |
if (field.get_name() == "ids" || field.get_name() == "ids_raw") { |
| 1159 |
// Map node id from global node id to local node id. |
| 1160 |
// Do it in 'data' ... |
| 1161 |
|
| 1162 |
if (field.get_name() == "ids") { |
| 1163 |
nodeMap.reverse_map_data(data, field, num_to_get); |
| 1164 |
} |
| 1165 |
|
| 1166 |
if (type == EX_NODE_SET) { |
| 1167 |
nodesetOwnedNodes[ns].reserve(file_count); |
| 1168 |
if (int_byte_size_api() == 4) { |
| 1169 |
std::vector<int> i32data; |
| 1170 |
i32data.reserve(file_count); |
| 1171 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 1172 |
map_nodeset_id_data(nodeOwningProcessor, nodesetOwnedNodes[ns], myProcessor, |
| 1173 |
reinterpret_cast<int *>(data), num_to_get, i32data); |
| 1174 |
assert(i32data.size() == file_count); |
| 1175 |
// Maps local to "global_implicit" |
| 1176 |
map_local_to_global_implicit(Data(i32data), file_count, nodeGlobalImplicitMap); |
| 1177 |
} |
| 1178 |
else { |
| 1179 |
std::vector<int64_t> i64data; |
| 1180 |
i64data.reserve(file_count); |
| 1181 |
check_node_owning_processor_data(nodeOwningProcessor, file_count); |
| 1182 |
map_nodeset_id_data(nodeOwningProcessor, nodesetOwnedNodes[ns], myProcessor, |
| 1183 |
reinterpret_cast<int64_t *>(data), num_to_get, i64data); |
| 1184 |
assert(i64data.size() == file_count); |
| 1185 |
map_local_to_global_implicit(Data(i64data), file_count, nodeGlobalImplicitMap); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
} |
| 1189 |
else if (field.get_name() == "orientation") { |
| 1190 |
} |
| 1191 |
else if (field.get_name() == "distribution_factors") { |
| 1192 |
if (type == EX_NODE_SET) { |
| 1193 |
std::vector<double> dbldata; |
| 1194 |
map_nodeset_data(nodesetOwnedNodes[ns], reinterpret_cast<double *>(data), dbldata); |
| 1195 |
} |
| 1196 |
} |
| 1197 |
else { |
| 1198 |
num_to_get = Ioss::Utils::field_warning(ns, field, "output"); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
else if (role == Ioss::Field::TRANSIENT) { |
| 1202 |
// Check if the specified field exists on this element block. |
| 1203 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 1204 |
// exist on the database as scalars with the appropriate |
| 1205 |
// extensions. |
| 1206 |
|
| 1207 |
// Transfer each component of the variable into 'data' and then |
| 1208 |
// output. Need temporary storage area of size 'number of |
| 1209 |
// elements in this block. |
| 1210 |
write_entity_transient_field(field, ns, entity_count, data); |
| 1211 |
} |
| 1212 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 1213 |
num_to_get = write_attribute_field(field, ns, data); |
| 1214 |
} |
| 1215 |
else if (role == Ioss::Field::REDUCTION) { |
| 1216 |
store_reduction_field(field, ns, data); |
| 1217 |
} |
| 1218 |
return num_to_get; |
| 1219 |
} |
| 1220 |
|
| 1221 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, |
| 1222 |
void *data, size_t data_size) const |
| 1223 |
{ |
| 1224 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 1225 |
} |
| 1226 |
|
| 1227 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, |
| 1228 |
void *data, size_t data_size) const |
| 1229 |
{ |
| 1230 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 1231 |
} |
| 1232 |
|
| 1233 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, |
| 1234 |
void *data, size_t data_size) const |
| 1235 |
{ |
| 1236 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 1237 |
} |
| 1238 |
|
| 1239 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::ElementSet *ns, |
| 1240 |
const Ioss::Field &field, void *data, |
| 1241 |
size_t data_size) const |
| 1242 |
{ |
| 1243 |
return put_Xset_field_internal(ns, field, data, data_size); |
| 1244 |
} |
| 1245 |
|
| 1246 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, |
| 1247 |
void * /* data */, size_t data_size) const |
| 1248 |
{ |
| 1249 |
size_t num_to_get = field.verify(data_size); |
| 1250 |
if (field.get_name() == "ids") { |
| 1251 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 1252 |
} |
| 1253 |
else { |
| 1254 |
num_to_get = Ioss::Utils::field_warning(ss, field, "output"); |
| 1255 |
} |
| 1256 |
return num_to_get; |
| 1257 |
} |
| 1258 |
|
| 1259 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::CommSet * /*cs*/, |
| 1260 |
const Ioss::Field &field, void * /*data*/, |
| 1261 |
size_t data_size) const |
| 1262 |
{ |
| 1263 |
size_t num_to_get = field.verify(data_size); |
| 1264 |
return num_to_get; |
| 1265 |
} |
| 1266 |
|
| 1267 |
int64_t ParallelDatabaseIO::put_field_internal(const Ioss::SideBlock *sb, |
| 1268 |
const Ioss::Field &field, void *data, |
| 1269 |
size_t data_size) const |
| 1270 |
{ |
| 1271 |
size_t num_to_get = field.verify(data_size); |
| 1272 |
size_t entity_count = sb->entity_count(); |
| 1273 |
|
| 1274 |
Ioss::Field::RoleType role = field.get_role(); |
| 1275 |
|
| 1276 |
if (role == Ioss::Field::MESH) { |
| 1277 |
if (field.get_name() == "side_ids" && sb->name() == "universal_sideset") {} |
| 1278 |
|
| 1279 |
else if (field.get_name() == "side_ids") { |
| 1280 |
} |
| 1281 |
|
| 1282 |
else if (field.get_name() == "ids") { |
| 1283 |
// ============================================================= |
| 1284 |
// NOTE: Code is currently commented out since we have |
| 1285 |
// redundant ways of getting the data (element/side) out to |
| 1286 |
// the database. The 'ids' field method relies on a numbering |
| 1287 |
// kluge, so for now trying the 'element_side' field... |
| 1288 |
// ============================================================= |
| 1289 |
} |
| 1290 |
|
| 1291 |
else if (field.get_name() == "distribution_factors") { |
| 1292 |
} |
| 1293 |
else if (field.get_name() == "element_side") { |
| 1294 |
// In exodusII, the 'side block' is stored as a sideset. A |
| 1295 |
// sideset has a list of elements and a corresponding local |
| 1296 |
// element side (1-based) |
| 1297 |
|
| 1298 |
// The 'data' passed into the function is stored as a |
| 1299 |
// 2D vector e0,f0,e1,f1,... (e=element, f=side) |
| 1300 |
|
| 1301 |
// To avoid overwriting the passed in data, we allocate |
| 1302 |
// two arrays to store the data for this sideset. |
| 1303 |
|
| 1304 |
// The element_id passed in is the global id; we need to |
| 1305 |
// output the local id. |
| 1306 |
|
| 1307 |
// Allocate space for local side number and element numbers |
| 1308 |
// numbers. |
| 1309 |
// See if edges or faces... |
| 1310 |
size_t side_offset = Ioss::Utils::get_side_offset(sb); |
| 1311 |
|
| 1312 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 1313 |
Ioss::IntVector element(num_to_get); |
| 1314 |
Ioss::IntVector side(num_to_get); |
| 1315 |
int *el_side = reinterpret_cast<int *>(data); |
| 1316 |
|
| 1317 |
size_t index = 0; |
| 1318 |
for (size_t i = 0; i < num_to_get; i++) { |
| 1319 |
element[i] = elemMap.global_to_local(el_side[index++]); |
| 1320 |
side[i] = el_side[index++] + side_offset; |
| 1321 |
} |
| 1322 |
|
| 1323 |
map_local_to_global_implicit(Data(element), num_to_get, elemGlobalImplicitMap); |
| 1324 |
} |
| 1325 |
else { |
| 1326 |
Ioss::Int64Vector element(num_to_get); |
| 1327 |
Ioss::Int64Vector side(num_to_get); |
| 1328 |
int64_t *el_side = reinterpret_cast<int64_t *>(data); |
| 1329 |
|
| 1330 |
size_t index = 0; |
| 1331 |
for (size_t i = 0; i < num_to_get; i++) { |
| 1332 |
element[i] = elemMap.global_to_local(el_side[index++]); |
| 1333 |
side[i] = el_side[index++] + side_offset; |
| 1334 |
} |
| 1335 |
|
| 1336 |
map_local_to_global_implicit(Data(element), num_to_get, elemGlobalImplicitMap); |
| 1337 |
} |
| 1338 |
} |
| 1339 |
else if (field.get_name() == "element_side_raw") { |
| 1340 |
// In exodusII, the 'side block' is stored as a sideset. A |
| 1341 |
// sideset has a list of elements and a corresponding local |
| 1342 |
// element side (1-based) |
| 1343 |
|
| 1344 |
// The 'data' passed into the function is stored as a |
| 1345 |
// 2D vector e0,f0,e1,f1,... (e=element, f=side) |
| 1346 |
|
| 1347 |
// To avoid overwriting the passed in data, we allocate |
| 1348 |
// two arrays to store the data for this sideset. |
| 1349 |
|
| 1350 |
// The element_id passed in is the local id. |
| 1351 |
|
| 1352 |
// See if edges or faces... |
| 1353 |
size_t side_offset = Ioss::Utils::get_side_offset(sb); |
| 1354 |
|
| 1355 |
size_t index = 0; |
| 1356 |
if (field.get_type() == Ioss::Field::INTEGER) { |
| 1357 |
Ioss::IntVector element(num_to_get); |
| 1358 |
Ioss::IntVector side(num_to_get); |
| 1359 |
int *el_side = reinterpret_cast<int *>(data); |
| 1360 |
|
| 1361 |
for (size_t i = 0; i < num_to_get; i++) { |
| 1362 |
element[i] = el_side[index++]; |
| 1363 |
side[i] = el_side[index++] + side_offset; |
| 1364 |
} |
| 1365 |
} |
| 1366 |
else { |
| 1367 |
Ioss::Int64Vector element(num_to_get); |
| 1368 |
Ioss::Int64Vector side(num_to_get); |
| 1369 |
int64_t *el_side = reinterpret_cast<int64_t *>(data); |
| 1370 |
|
| 1371 |
for (size_t i = 0; i < num_to_get; i++) { |
| 1372 |
element[i] = el_side[index++]; |
| 1373 |
side[i] = el_side[index++] + side_offset; |
| 1374 |
} |
| 1375 |
} |
| 1376 |
} |
| 1377 |
else if (field.get_name() == "connectivity") { |
| 1378 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 1379 |
} |
| 1380 |
else if (field.get_name() == "connectivity_raw") { |
| 1381 |
// Do nothing, just handles an idiosyncrasy of the GroupingEntity |
| 1382 |
} |
| 1383 |
else { |
| 1384 |
num_to_get = Ioss::Utils::field_warning(sb, field, "output"); |
| 1385 |
} |
| 1386 |
} |
| 1387 |
else if (role == Ioss::Field::TRANSIENT) { |
| 1388 |
// Check if the specified field exists on this block. |
| 1389 |
// Note that 'higher-order' storage types (e.g. SYM_TENSOR) |
| 1390 |
// exist on the database as scalars with the appropriate |
| 1391 |
// extensions. |
| 1392 |
|
| 1393 |
// Transfer each component of the variable into 'data' and then |
| 1394 |
// output. Need temporary storage area of size 'number of |
| 1395 |
// entities in this block. |
| 1396 |
write_entity_transient_field(field, sb, entity_count, data); |
| 1397 |
} |
| 1398 |
else if (role == Ioss::Field::ATTRIBUTE) { |
| 1399 |
num_to_get = write_attribute_field(field, sb, data); |
| 1400 |
} |
| 1401 |
else if (role == Ioss::Field::REDUCTION) { |
| 1402 |
store_reduction_field(field, sb, data); |
| 1403 |
} |
| 1404 |
return num_to_get; |
| 1405 |
} |
| 1406 |
|
| 1407 |
void ParallelDatabaseIO::write_meta_data(Ioss::IfDatabaseExistsBehavior behavior) |
| 1408 |
{ |
| 1409 |
Ioss::Region *region = get_region(); |
| 1410 |
common_write_metadata(behavior); |
| 1411 |
|
| 1412 |
char the_title[max_line_length + 1]; |
| 1413 |
|
| 1414 |
// Title... |
| 1415 |
if (region->property_exists("title")) { |
| 1416 |
std::string title_str = region->get_property("title").get_string(); |
| 1417 |
Ioss::Utils::copy_string(the_title, title_str); |
| 1418 |
} |
| 1419 |
else { |
| 1420 |
Ioss::Utils::copy_string(the_title, "IOSS Default Output Title"); |
| 1421 |
} |
| 1422 |
|
| 1423 |
bool file_per_processor = false; |
| 1424 |
Ioexnl::Mesh mesh(spatialDimension, the_title, util(), file_per_processor); |
| 1425 |
mesh.populate(region); |
| 1426 |
|
| 1427 |
if (behavior != Ioss::DB_APPEND && behavior != Ioss::DB_MODIFY) { |
| 1428 |
bool omit_qa = false; |
| 1429 |
Ioss::Utils::check_set_bool_property(properties, "OMIT_QA_RECORDS", omit_qa); |
| 1430 |
if (!omit_qa) { |
| 1431 |
put_qa(); |
| 1432 |
} |
| 1433 |
|
| 1434 |
bool omit_info = false; |
| 1435 |
Ioss::Utils::check_set_bool_property(properties, "OMIT_INFO_RECORDS", omit_info); |
| 1436 |
if (!omit_info) { |
| 1437 |
put_info(); |
| 1438 |
} |
| 1439 |
mesh.comm.outputNemesis = false; |
| 1440 |
} |
| 1441 |
|
| 1442 |
metaDataWritten = true; |
| 1443 |
|
| 1444 |
// Set the processor offset property. Specifies where in the global list, the data from this |
| 1445 |
// processor begins... |
| 1446 |
update_processor_offset_property(region, mesh); |
| 1447 |
|
| 1448 |
if (behavior != Ioss::DB_APPEND && behavior != Ioss::DB_MODIFY) { |
| 1449 |
output_node_map(); |
| 1450 |
output_other_metadata(); |
| 1451 |
} |
| 1452 |
} |
| 1453 |
|
| 1454 |
void ParallelDatabaseIO::create_implicit_global_map() const |
| 1455 |
{ |
| 1456 |
// If the node is locally owned, then its position is basically |
| 1457 |
// determined by removing all shared nodes from the list and |
| 1458 |
// then compressing the list. This location plus the proc_offset |
| 1459 |
// gives its location in the global-implicit file. |
| 1460 |
// |
| 1461 |
// Do this over in the DecompositionData class since it has |
| 1462 |
// several utilities in place for MPI communication. |
| 1463 |
|
| 1464 |
DecompositionData<int64_t> compose(Ioss::PropertyManager(), util().communicator()); |
| 1465 |
int64_t locally_owned_count = 0; |
| 1466 |
int64_t processor_offset = 0; |
| 1467 |
compose.create_implicit_global_map(nodeOwningProcessor, nodeGlobalImplicitMap, nodeMap, |
| 1468 |
&locally_owned_count, &processor_offset); |
| 1469 |
|
| 1470 |
nodeGlobalImplicitMapDefined = true; |
| 1471 |
const Ioss::NodeBlockContainer &node_blocks = get_region()->get_node_blocks(); |
| 1472 |
if (!node_blocks[0]->property_exists("locally_owned_count")) { |
| 1473 |
node_blocks[0]->property_add(Ioss::Property("locally_owned_count", locally_owned_count)); |
| 1474 |
} |
| 1475 |
if (!node_blocks[0]->property_exists("_processor_offset")) { |
| 1476 |
node_blocks[0]->property_add(Ioss::Property("_processor_offset", processor_offset)); |
| 1477 |
} |
| 1478 |
|
| 1479 |
output_node_map(); |
| 1480 |
} |
| 1481 |
|
| 1482 |
void ParallelDatabaseIO::output_node_map() const |
| 1483 |
{ |
| 1484 |
// Write the partial nodemap to the database... This is called |
| 1485 |
// two times -- once from create_implicit_global_map() and once |
| 1486 |
// from write_meta_data(). It will only output the map if |
| 1487 |
// the metadata has been written to the output database AND if |
| 1488 |
// the nodeMap.map and nodeGlobalImplicitMap are defined. |
| 1489 |
|
| 1490 |
if (metaDataWritten) { |
| 1491 |
const Ioss::NodeBlockContainer &node_blocks = get_region()->get_node_blocks(); |
| 1492 |
if (node_blocks.empty()) { |
| 1493 |
return; |
| 1494 |
} |
| 1495 |
assert(node_blocks[0]->property_exists("locally_owned_count")); |
| 1496 |
size_t locally_owned_count = node_blocks[0]->get_property("locally_owned_count").get_int(); |
| 1497 |
|
| 1498 |
if (nodeMap.defined() && nodeGlobalImplicitMapDefined) { |
| 1499 |
|
| 1500 |
if (int_byte_size_api() == 4) { |
| 1501 |
std::vector<int> file_ids; |
| 1502 |
file_ids.reserve(locally_owned_count); |
| 1503 |
check_node_owning_processor_data(nodeOwningProcessor, locally_owned_count); |
| 1504 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, &nodeMap.map()[1], file_ids); |
| 1505 |
} |
| 1506 |
else { |
| 1507 |
std::vector<int64_t> file_ids; |
| 1508 |
file_ids.reserve(locally_owned_count); |
| 1509 |
check_node_owning_processor_data(nodeOwningProcessor, locally_owned_count); |
| 1510 |
filter_owned_nodes(nodeOwningProcessor, myProcessor, &nodeMap.map()[1], file_ids); |
| 1511 |
} |
| 1512 |
} |
| 1513 |
} |
| 1514 |
} |
| 1515 |
|
| 1516 |
void ParallelDatabaseIO::check_valid_values() const |
| 1517 |
{ |
| 1518 |
std::vector<int64_t> counts{nodeCount, elementCount, m_groupCount[EX_ELEM_BLOCK]}; |
| 1519 |
std::vector<int64_t> all_counts; |
| 1520 |
util().all_gather(counts, all_counts); |
| 1521 |
// Get minimum value in `all_counts`. If >0, then don't need to check further... |
| 1522 |
auto min_val = *std::min_element(all_counts.begin(), all_counts.end()); |
| 1523 |
|
| 1524 |
if (myProcessor == 0) { |
| 1525 |
size_t proc_count = all_counts.size() / 3; |
| 1526 |
|
| 1527 |
if (min_val < 0) { |
| 1528 |
static std::array<std::string, 3> label{"node", "element", "element block"}; |
| 1529 |
// Error on one or more of the counts... |
| 1530 |
for (size_t j = 0; j < 3; j++) { |
| 1531 |
std::vector<size_t> bad_proc; |
| 1532 |
for (size_t i = 0; i < proc_count; i++) { |
| 1533 |
if (all_counts[3 * i + j] < 0) { |
| 1534 |
bad_proc.push_back(i); |
| 1535 |
} |
| 1536 |
} |
| 1537 |
|
| 1538 |
if (!bad_proc.empty()) { |
| 1539 |
std::ostringstream errmsg; |
| 1540 |
fmt::print(errmsg, "ERROR: Negative {} count on {} processor{}:\n\t{}\n\n", label[j], |
| 1541 |
bad_proc.size(), bad_proc.size() > 1 ? "s" : "", |
| 1542 |
Ioss::Utils::format_id_list(bad_proc, ":")); |
| 1543 |
IOSS_ERROR(errmsg); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
} |
| 1547 |
|
| 1548 |
// Now check for warning (count == 0) |
| 1549 |
if (min_val <= 0) { |
| 1550 |
static std::array<std::string, 3> label{"nodes or elements", "elements", "element blocks"}; |
| 1551 |
// Possible warning on one or more of the counts... |
| 1552 |
// Note that it is possible to have nodes on a processor with no elements, |
| 1553 |
// but not possible to have elements if no nodes... |
| 1554 |
for (size_t j = 0; j < 3; j++) { |
| 1555 |
std::vector<size_t> bad_proc; |
| 1556 |
for (size_t i = 0; i < proc_count; i++) { |
| 1557 |
if (all_counts[3 * i + j] == 0) { |
| 1558 |
bad_proc.push_back(i); |
| 1559 |
} |
| 1560 |
} |
| 1561 |
|
| 1562 |
if (!bad_proc.empty()) { |
| 1563 |
fmt::print(Ioss::WarnOut(), "No {} on processor{}:\n\t{}\n\n", label[j], |
| 1564 |
bad_proc.size() > 1 ? "s" : "", Ioss::Utils::format_id_list(bad_proc, ":")); |
| 1565 |
if (j == 0) { |
| 1566 |
break; |
| 1567 |
} |
| 1568 |
} |
| 1569 |
} |
| 1570 |
} |
| 1571 |
} |
| 1572 |
else { // All other processors; need to abort if negative count |
| 1573 |
if (min_val < 0) { |
| 1574 |
std::ostringstream errmsg; |
| 1575 |
IOSS_ERROR(errmsg); |
| 1576 |
} |
| 1577 |
} |
| 1578 |
} |
| 1579 |
} // namespace Ioexnl |
| 1580 |
#else |
| 1581 |
IOSS_MAYBE_UNUSED const char ioss_exodus_parallel_database_unused_symbol_dummy = '\0'; |
| 1582 |
#endif |