| 1 |
// Copyright(C) 2021, 2022, 2023, 2024 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "Ioss_CopyDatabase.h" |
| 8 |
#include "Ioss_DataPool.h" |
| 9 |
#include "Ioss_FaceGenerator.h" |
| 10 |
#include "Ioss_MeshCopyOptions.h" |
| 11 |
#include <array> |
| 12 |
#include <assert.h> |
| 13 |
#include <cmath> |
| 14 |
#include <cstdlib> |
| 15 |
#include <fmt/format.h> |
| 16 |
#include <fmt/ostream.h> |
| 17 |
#include <iostream> |
| 18 |
#include <limits> |
| 19 |
#include <stdint.h> |
| 20 |
#include <string> |
| 21 |
#include <thread> |
| 22 |
#include <vector> |
| 23 |
|
| 24 |
#include "Ioss_Assembly.h" |
| 25 |
#include "Ioss_Blob.h" |
| 26 |
#include "Ioss_CommSet.h" |
| 27 |
#include "Ioss_DBUsage.h" |
| 28 |
#include "Ioss_DatabaseIO.h" |
| 29 |
#include "Ioss_EdgeBlock.h" |
| 30 |
#include "Ioss_EdgeSet.h" |
| 31 |
#include "Ioss_ElementBlock.h" |
| 32 |
#include "Ioss_ElementSet.h" |
| 33 |
#include "Ioss_ElementTopology.h" |
| 34 |
#include "Ioss_EntityBlock.h" |
| 35 |
#include "Ioss_EntityType.h" |
| 36 |
#include "Ioss_FaceBlock.h" |
| 37 |
#include "Ioss_FaceSet.h" |
| 38 |
#include "Ioss_Field.h" |
| 39 |
#include "Ioss_GroupingEntity.h" |
| 40 |
#include "Ioss_IOFactory.h" |
| 41 |
#include "Ioss_MeshType.h" |
| 42 |
#include "Ioss_NodeBlock.h" |
| 43 |
#include "Ioss_NodeSet.h" |
| 44 |
#include "Ioss_ParallelUtils.h" |
| 45 |
#include "Ioss_Property.h" |
| 46 |
#include "Ioss_Region.h" |
| 47 |
#include "Ioss_SideBlock.h" |
| 48 |
#include "Ioss_SideSet.h" |
| 49 |
#include "Ioss_State.h" |
| 50 |
#include "Ioss_StructuredBlock.h" |
| 51 |
#include "Ioss_Utils.h" |
| 52 |
#include "robin_hash.h" |
| 53 |
|
| 54 |
// For copy_database... |
| 55 |
namespace { |
| 56 |
std::vector<int> get_selected_steps(Ioss::Region ®ion, const Ioss::MeshCopyOptions &options); |
| 57 |
void show_step(int istep, double time, const Ioss::MeshCopyOptions &options, int rank); |
| 58 |
std::vector<Ioss::Face> generate_boundary_faces(Ioss::Region ®ion, |
| 59 |
const Ioss::MeshCopyOptions &options); |
| 60 |
void define_model(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &data_pool, |
| 61 |
const std::vector<Ioss::Face> &boundary, const Ioss::MeshCopyOptions &options, |
| 62 |
int rank); |
| 63 |
void transfer_model(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &pool, |
| 64 |
const std::vector<Ioss::Face> &boundary, const Ioss::MeshCopyOptions &options, |
| 65 |
int rank); |
| 66 |
void define_transient_fields(Ioss::Region ®ion, Ioss::Region &output_region, |
| 67 |
const Ioss::MeshCopyOptions &options, int rank); |
| 68 |
void transfer_step(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &pool, |
| 69 |
int istep, const Ioss::MeshCopyOptions &options, int rank); |
| 70 |
|
| 71 |
void transfer_nodeblock(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &pool, |
| 72 |
const Ioss::MeshCopyOptions &options, int rank); |
| 73 |
void transfer_structuredblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 74 |
const Ioss::MeshCopyOptions &options, int rank); |
| 75 |
void transfer_elementblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 76 |
const Ioss::MeshCopyOptions &options, int rank); |
| 77 |
void transfer_edgeblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 78 |
const Ioss::MeshCopyOptions &options, int rank); |
| 79 |
void transfer_faceblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 80 |
const Ioss::MeshCopyOptions &options, int rank); |
| 81 |
void transfer_nodesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 82 |
const Ioss::MeshCopyOptions &options, int rank); |
| 83 |
void transfer_edgesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 84 |
const Ioss::MeshCopyOptions &options, int rank); |
| 85 |
void transfer_facesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 86 |
const Ioss::MeshCopyOptions &options, int rank); |
| 87 |
void transfer_elemsets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 88 |
const Ioss::MeshCopyOptions &options, int rank); |
| 89 |
void transfer_sidesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 90 |
const Ioss::MeshCopyOptions &options, int rank); |
| 91 |
void transfer_commsets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 92 |
const Ioss::MeshCopyOptions &options, int rank); |
| 93 |
|
| 94 |
void transfer_fields(const Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 95 |
Ioss::Field::RoleType role, const std::string &prefix = ""); |
| 96 |
|
| 97 |
void add_proc_id(Ioss::Region ®ion, int rank); |
| 98 |
|
| 99 |
template <typename T> |
| 100 |
void transfer_field_data(const std::vector<T *> &entities, Ioss::Region &output_region, |
| 101 |
Ioss::DataPool &pool, Ioss::Field::RoleType role, |
| 102 |
const Ioss::MeshCopyOptions &options); |
| 103 |
|
| 104 |
void transfer_field_data(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 105 |
Ioss::DataPool &pool, Ioss::Field::RoleType role, |
| 106 |
const Ioss::MeshCopyOptions &options, const std::string &prefix = ""); |
| 107 |
|
| 108 |
void transfer_properties(const Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge); |
| 109 |
|
| 110 |
void transfer_qa_info(Ioss::Region &in, Ioss::Region &out); |
| 111 |
|
| 112 |
void transfer_field_data_internal(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 113 |
Ioss::DataPool &pool, const std::string &field_name, |
| 114 |
const Ioss::MeshCopyOptions &options); |
| 115 |
|
| 116 |
#ifdef SEACAS_HAVE_MPI |
| 117 |
template <typename INT> |
| 118 |
void set_owned_node_count(Ioss::Region ®ion, int my_processor, INT dummy); |
| 119 |
#endif |
| 120 |
|
| 121 |
template <typename T> |
| 122 |
std::pair<size_t, std::string> |
| 123 |
calculate_maximum_field_size(const std::vector<T> &entities, |
| 124 |
std::pair<size_t, std::string> &max_field) |
| 125 |
{ |
| 126 |
size_t max_size = max_field.first; |
| 127 |
std::string max_name = max_field.second; |
| 128 |
for (const auto &entity : entities) { |
| 129 |
Ioss::NameList fields = entity->field_describe(); |
| 130 |
for (const auto &field_name : fields) { |
| 131 |
Ioss::Field field = entity->get_field(field_name); |
| 132 |
if (field.get_size() > max_size) { |
| 133 |
max_size = field.get_size(); |
| 134 |
max_name = field_name; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
return std::make_pair(max_size, max_name); |
| 139 |
} |
| 140 |
|
| 141 |
std::pair<size_t, std::string> calculate_maximum_field_size(const Ioss::Region ®ion) |
| 142 |
{ |
| 143 |
std::pair<size_t, std::string> max_field{}; |
| 144 |
max_field = calculate_maximum_field_size(region.get_node_blocks(), max_field); |
| 145 |
max_field = calculate_maximum_field_size(region.get_edge_blocks(), max_field); |
| 146 |
max_field = calculate_maximum_field_size(region.get_face_blocks(), max_field); |
| 147 |
max_field = calculate_maximum_field_size(region.get_element_blocks(), max_field); |
| 148 |
max_field = calculate_maximum_field_size(region.get_sidesets(), max_field); |
| 149 |
max_field = calculate_maximum_field_size(region.get_nodesets(), max_field); |
| 150 |
max_field = calculate_maximum_field_size(region.get_edgesets(), max_field); |
| 151 |
max_field = calculate_maximum_field_size(region.get_facesets(), max_field); |
| 152 |
max_field = calculate_maximum_field_size(region.get_elementsets(), max_field); |
| 153 |
max_field = calculate_maximum_field_size(region.get_commsets(), max_field); |
| 154 |
max_field = calculate_maximum_field_size(region.get_structured_blocks(), max_field); |
| 155 |
max_field = calculate_maximum_field_size(region.get_assemblies(), max_field); |
| 156 |
max_field = calculate_maximum_field_size(region.get_blobs(), max_field); |
| 157 |
return max_field; |
| 158 |
} |
| 159 |
|
| 160 |
template <typename INT> |
| 161 |
void output_boundary_sideset(Ioss::SideBlock *sb, const std::vector<Ioss::Face> &boundary, |
| 162 |
INT /* dummy */) |
| 163 |
{ |
| 164 |
std::vector<INT> el_side; |
| 165 |
el_side.reserve(boundary.size() * 2); |
| 166 |
for (const auto &face : boundary) { |
| 167 |
el_side.push_back(face.element[0] / 10); |
| 168 |
el_side.push_back(face.element[0] % 10 + 1); |
| 169 |
} |
| 170 |
sb->put_field_data("element_side", el_side); |
| 171 |
} |
| 172 |
} // namespace |
| 173 |
|
| 174 |
void Ioss::transfer_coordinate_frames(Ioss::Region ®ion, Ioss::Region &output_region) |
| 175 |
{ |
| 176 |
const Ioss::CoordinateFrameContainer &cf = region.get_coordinate_frames(); |
| 177 |
for (const auto &frame : cf) { |
| 178 |
output_region.add(frame); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
void Ioss::transfer_assemblies(Ioss::Region ®ion, Ioss::Region &output_region, |
| 183 |
const Ioss::MeshCopyOptions &options, int rank) |
| 184 |
{ |
| 185 |
const auto &assem = region.get_assemblies(); |
| 186 |
if (!assem.empty()) { |
| 187 |
for (const auto &assm : assem) { |
| 188 |
const std::string &name = assm->name(); |
| 189 |
if (options.debug && rank == 0) { |
| 190 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 191 |
} |
| 192 |
|
| 193 |
// NOTE: Can't totally use the copy constructor as it will |
| 194 |
// create a members list containing entities from input |
| 195 |
// database. We need corresponding entities from output |
| 196 |
// database... |
| 197 |
auto *o_assem = new Ioss::Assembly(*assm); |
| 198 |
o_assem->remove_members(); |
| 199 |
|
| 200 |
// Now, repopulate member list with corresponding entities from output database... |
| 201 |
const auto &members = assm->get_members(); |
| 202 |
for (const auto &member : members) { |
| 203 |
const auto *entity = output_region.get_entity(member->name(), member->type()); |
| 204 |
if (entity != nullptr) { |
| 205 |
o_assem->add(entity); |
| 206 |
} |
| 207 |
} |
| 208 |
output_region.add(o_assem); |
| 209 |
} |
| 210 |
|
| 211 |
if (options.output_summary && rank == 0) { |
| 212 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}\n", "Assemblies", |
| 213 |
fmt::group_digits(assem.size())); |
| 214 |
} |
| 215 |
if (options.debug && rank == 0) { |
| 216 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
void Ioss::transfer_blobs(Ioss::Region ®ion, Ioss::Region &output_region, |
| 222 |
const Ioss::MeshCopyOptions &options, int rank) |
| 223 |
{ |
| 224 |
const auto &blobs = region.get_blobs(); |
| 225 |
if (!blobs.empty()) { |
| 226 |
size_t total_entities = 0; |
| 227 |
for (const auto &blob : blobs) { |
| 228 |
const std::string &name = blob->name(); |
| 229 |
if (options.debug && rank == 0) { |
| 230 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 231 |
} |
| 232 |
size_t count = blob->entity_count(); |
| 233 |
total_entities += count; |
| 234 |
auto *o_blob = new Ioss::Blob(*blob); |
| 235 |
output_region.add(o_blob); |
| 236 |
} |
| 237 |
|
| 238 |
if (options.output_summary && rank == 0) { |
| 239 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}", |
| 240 |
(*blobs.begin())->type_string() + "s", fmt::group_digits(blobs.size())); |
| 241 |
fmt::print(Ioss::DebugOut(), "\tLength of entity list = {:14}\n", |
| 242 |
fmt::group_digits(total_entities)); |
| 243 |
} |
| 244 |
if (options.debug && rank == 0) { |
| 245 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 246 |
} |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
void Ioss::copy_database(Ioss::Region ®ion, Ioss::Region &output_region, |
| 251 |
Ioss::MeshCopyOptions &options) |
| 252 |
{ |
| 253 |
|
| 254 |
Ioss::DatabaseIO *dbi = region.get_database(); |
| 255 |
int rank = dbi->util().parallel_rank(); |
| 256 |
|
| 257 |
// Minimize number of times that we grow the memory buffer used for transferring field data. |
| 258 |
auto max_field = calculate_maximum_field_size(region); |
| 259 |
if (options.verbose && rank == 0) { |
| 260 |
std::string label = "MiB"; |
| 261 |
double size = (double)max_field.first / 1024 / 1024; |
| 262 |
if (size > 1024.0) { |
| 263 |
label = "GiB"; |
| 264 |
size /= 1024.0; |
| 265 |
} |
| 266 |
fmt::print(Ioss::DebugOut(), "\n Maximum Field size = {} bytes ({:.3} {}) for field '{}'.\n", |
| 267 |
fmt::group_digits(max_field.first), size, label, max_field.second); |
| 268 |
} |
| 269 |
|
| 270 |
DataPool data_pool; |
| 271 |
data_pool.data.resize(max_field.first); |
| 272 |
if (options.verbose && rank == 0) { |
| 273 |
fmt::print(Ioss::DebugOut(), " Resize finished...\n"); |
| 274 |
} |
| 275 |
|
| 276 |
std::vector<Ioss::Face> boundary = generate_boundary_faces(region, options); |
| 277 |
if (options.define_geometry) { |
| 278 |
define_model(region, output_region, data_pool, boundary, options, rank); |
| 279 |
} |
| 280 |
bool appending = output_region.get_database()->open_create_behavior() == Ioss::DB_APPEND; |
| 281 |
if (!appending) { |
| 282 |
transfer_model(region, output_region, data_pool, boundary, options, rank); |
| 283 |
|
| 284 |
if (options.add_proc_id) { |
| 285 |
Ioss::Utils::clear(data_pool.data); |
| 286 |
add_proc_id(output_region, rank); |
| 287 |
return; |
| 288 |
} |
| 289 |
|
| 290 |
if (options.delete_timesteps) { |
| 291 |
Ioss::Utils::clear(data_pool.data); |
| 292 |
return; |
| 293 |
} |
| 294 |
} // !appending |
| 295 |
|
| 296 |
if (options.define_geometry) { |
| 297 |
define_transient_fields(region, output_region, options, rank); |
| 298 |
} |
| 299 |
|
| 300 |
output_region.begin_mode(Ioss::STATE_TRANSIENT); |
| 301 |
if (options.debug && rank == 0) { |
| 302 |
fmt::print(Ioss::DebugOut(), "TRANSFERRING TRANSIENT FIELDS ... \n"); |
| 303 |
} |
| 304 |
dbi->progress("TRANSFERRING TRANSIENT FIELDS... "); |
| 305 |
|
| 306 |
// Get the timesteps from the input database. Step through them |
| 307 |
// and transfer fields to output database... |
| 308 |
// `selected_steps` specifies whether an input step should be transferred |
| 309 |
// to the output region based on values in `options` |
| 310 |
std::vector<int> selected_steps = get_selected_steps(region, options); |
| 311 |
|
| 312 |
int step_count = (int)region.get_property("state_count").get_int(); |
| 313 |
#ifdef SEACAS_HAVE_MPI |
| 314 |
int min_step_count = dbi->util().global_minmax(step_count, Ioss::ParallelUtils::DO_MIN); |
| 315 |
int max_step_count = dbi->util().global_minmax(step_count, Ioss::ParallelUtils::DO_MAX); |
| 316 |
if (min_step_count != max_step_count) { |
| 317 |
std::ostringstream errmsg; |
| 318 |
fmt::print(errmsg, |
| 319 |
"ERROR: Number of timesteps does not match on all ranks. Range from {} to {}.\n", |
| 320 |
min_step_count, max_step_count); |
| 321 |
IOSS_ERROR(errmsg); |
| 322 |
} |
| 323 |
#endif |
| 324 |
for (int istep = 1; istep <= step_count; istep++) { |
| 325 |
if (selected_steps[istep] == 1) { |
| 326 |
transfer_step(region, output_region, data_pool, istep, options, rank); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
if (options.debug && rank == 0) { |
| 331 |
fmt::print(Ioss::DebugOut(), "END STATE_TRANSIENT... \n"); |
| 332 |
} |
| 333 |
dbi->progress("END STATE_TRANSIENT (begin) ... "); |
| 334 |
|
| 335 |
output_region.end_mode(Ioss::STATE_TRANSIENT); |
| 336 |
dbi->progress("END STATE_TRANSIENT (end) ... "); |
| 337 |
Ioss::Utils::clear(data_pool.data); |
| 338 |
|
| 339 |
if (rank == 0 && options.output_summary) { |
| 340 |
fmt::print(std::cout, "\n\n Output Region summary for rank 0:"); |
| 341 |
output_region.output_summary(std::cout); |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
namespace { |
| 346 |
std::vector<int> get_selected_steps(Ioss::Region ®ion, const Ioss::MeshCopyOptions &options) |
| 347 |
{ |
| 348 |
// This routine checks all steps of the input database and selects those which |
| 349 |
// meet the requirements specified in `options`. The returned (1-based) vector will have a |
| 350 |
// value of `1` if the step is to be output and `0` if skipped. |
| 351 |
int step_count = (int)region.get_property("state_count").get_int(); |
| 352 |
std::vector<int> selected_steps(step_count + 1); |
| 353 |
|
| 354 |
// If user specified a list of times to transfer to output database, |
| 355 |
// process the list and find the times on the input database that are |
| 356 |
// closest to the times in the list. |
| 357 |
if (!options.selected_times.empty()) { |
| 358 |
int selected_step = 0; |
| 359 |
for (auto time : options.selected_times) { |
| 360 |
double diff = std::numeric_limits<double>::max(); |
| 361 |
for (int step = 1; step <= step_count; step++) { |
| 362 |
double db_time = region.get_state_time(step); |
| 363 |
double cur_diff = std::abs(db_time - time); |
| 364 |
if (cur_diff < diff) { |
| 365 |
diff = std::abs(db_time - time); |
| 366 |
selected_step = step; |
| 367 |
} |
| 368 |
} |
| 369 |
if (selected_step > 0) { |
| 370 |
selected_steps[selected_step] = 1; |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
else { |
| 375 |
// User did not select specific times to be output... |
| 376 |
// Just select them all |
| 377 |
for (int i = 1; i <= step_count; i++) { |
| 378 |
selected_steps[i] = 1; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
// Now, filter by min and max time... |
| 383 |
for (int istep = 1; istep <= step_count; istep++) { |
| 384 |
double time = region.get_state_time(istep); |
| 385 |
if (time < options.minimum_time) { |
| 386 |
selected_steps[istep] = 0; |
| 387 |
} |
| 388 |
if (time > options.maximum_time) { |
| 389 |
selected_steps[istep] = 0; |
| 390 |
} |
| 391 |
} |
| 392 |
return selected_steps; |
| 393 |
} |
| 394 |
|
| 395 |
template <typename T> void transfer_mesh_info(const T *input, T *output) |
| 396 |
{ |
| 397 |
transfer_properties(input, output); |
| 398 |
transfer_fields(input, output, Ioss::Field::MESH); |
| 399 |
transfer_fields(input, output, Ioss::Field::MAP); |
| 400 |
transfer_fields(input, output, Ioss::Field::ATTRIBUTE); |
| 401 |
transfer_fields(input, output, Ioss::Field::MESH_REDUCTION); |
| 402 |
} |
| 403 |
|
| 404 |
std::vector<Ioss::Face> generate_boundary_faces(Ioss::Region ®ion, |
| 405 |
const Ioss::MeshCopyOptions &options) |
| 406 |
{ |
| 407 |
std::vector<Ioss::Face> boundary; |
| 408 |
if (options.define_geometry && options.boundary_sideset) { |
| 409 |
Ioss::FaceGenerator face_generator(region); |
| 410 |
if (region.get_database()->int_byte_size_api() == 4) { |
| 411 |
face_generator.generate_faces((int)0, false); |
| 412 |
} |
| 413 |
else { |
| 414 |
face_generator.generate_faces((int64_t)0, false); |
| 415 |
} |
| 416 |
|
| 417 |
// Get vector of all boundary faces which will be output as the skin... |
| 418 |
const auto &faces = face_generator.faces("ALL"); |
| 419 |
for (const auto &face : faces) { |
| 420 |
if (face.element_count() == 1) { |
| 421 |
boundary.push_back(face); |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
return boundary; |
| 426 |
} |
| 427 |
|
| 428 |
void define_model(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &data_pool, |
| 429 |
const std::vector<Ioss::Face> &boundary, const Ioss::MeshCopyOptions &options, |
| 430 |
int rank) |
| 431 |
{ |
| 432 |
if (options.debug && rank == 0) { |
| 433 |
fmt::print(Ioss::DebugOut(), "DEFINING MODEL ... \n"); |
| 434 |
} |
| 435 |
Ioss::DatabaseIO *dbi = region.get_database(); |
| 436 |
dbi->progress("DEFINING MODEL"); |
| 437 |
if (!output_region.begin_mode(Ioss::STATE_DEFINE_MODEL)) { |
| 438 |
if (options.verbose) { |
| 439 |
std::ostringstream errmsg; |
| 440 |
fmt::print(errmsg, "ERROR: Could not put output region into define model state\n"); |
| 441 |
IOSS_ERROR(errmsg); |
| 442 |
} |
| 443 |
else { |
| 444 |
std::exit(EXIT_FAILURE); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
// Get all properties of input database... |
| 449 |
transfer_properties(®ion, &output_region); |
| 450 |
if (!options.ignore_qa_info) { |
| 451 |
transfer_qa_info(region, output_region); |
| 452 |
} |
| 453 |
|
| 454 |
if (rank == 0 && options.output_summary) { |
| 455 |
fmt::print(std::cout, "\n\n Input Region summary for rank 0:\n"); |
| 456 |
} |
| 457 |
transfer_nodeblock(region, output_region, data_pool, options, rank); |
| 458 |
|
| 459 |
#ifdef SEACAS_HAVE_MPI |
| 460 |
// This also assumes that the node order and count is the same for input |
| 461 |
// and output regions... (This is checked during nodeset output) |
| 462 |
if (output_region.get_database()->needs_shared_node_information()) { |
| 463 |
if (options.ints_64_bit) |
| 464 |
set_owned_node_count(region, rank, (int64_t)0); |
| 465 |
else |
| 466 |
set_owned_node_count(region, rank, (int)0); |
| 467 |
} |
| 468 |
#endif |
| 469 |
|
| 470 |
transfer_edgeblocks(region, output_region, options, rank); |
| 471 |
transfer_faceblocks(region, output_region, options, rank); |
| 472 |
transfer_elementblocks(region, output_region, options, rank); |
| 473 |
transfer_structuredblocks(region, output_region, options, rank); |
| 474 |
|
| 475 |
transfer_nodesets(region, output_region, options, rank); |
| 476 |
transfer_edgesets(region, output_region, options, rank); |
| 477 |
transfer_facesets(region, output_region, options, rank); |
| 478 |
transfer_elemsets(region, output_region, options, rank); |
| 479 |
|
| 480 |
transfer_sidesets(region, output_region, options, rank); |
| 481 |
|
| 482 |
if (options.define_geometry && options.boundary_sideset) { |
| 483 |
// Get topology of the sideset faces. Using just block[0] since for what we are doing, doesn't |
| 484 |
// really matter. |
| 485 |
const auto &blocks = region.get_element_blocks(); |
| 486 |
const auto *topo = blocks[0]->topology(); |
| 487 |
const auto &elem_topo = topo->name(); |
| 488 |
const auto &face_topo = topo->boundary_type(0)->name(); |
| 489 |
|
| 490 |
auto *ss = new Ioss::SideSet(output_region.get_database(), "boundary"); |
| 491 |
output_region.add(ss); |
| 492 |
auto *sb = new Ioss::SideBlock(output_region.get_database(), "boundary", face_topo, elem_topo, |
| 493 |
boundary.size()); |
| 494 |
ss->add(sb); |
| 495 |
} |
| 496 |
|
| 497 |
transfer_commsets(region, output_region, options, rank); |
| 498 |
|
| 499 |
transfer_coordinate_frames(region, output_region); |
| 500 |
transfer_blobs(region, output_region, options, rank); |
| 501 |
|
| 502 |
// This must be last... |
| 503 |
transfer_assemblies(region, output_region, options, rank); |
| 504 |
|
| 505 |
if (options.debug && rank == 0) { |
| 506 |
fmt::print(Ioss::DebugOut(), "END STATE_DEFINE_MODEL...\n"); |
| 507 |
} |
| 508 |
dbi->progress("END STATE_DEFINE_MODEL"); |
| 509 |
|
| 510 |
output_region.end_mode(Ioss::STATE_DEFINE_MODEL); |
| 511 |
dbi->progress("output_region.end_mode(Ioss::STATE_DEFINE_MODEL) finished"); |
| 512 |
} |
| 513 |
|
| 514 |
void transfer_model(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &data_pool, |
| 515 |
const std::vector<Ioss::Face> &boundary, const Ioss::MeshCopyOptions &options, |
| 516 |
int rank) |
| 517 |
{ |
| 518 |
if (options.debug && rank == 0) { |
| 519 |
fmt::print(Ioss::DebugOut(), "TRANSFERRING MESH FIELD DATA ...\n"); |
| 520 |
} |
| 521 |
Ioss::DatabaseIO *dbi = region.get_database(); |
| 522 |
dbi->progress("TRANSFERRING MESH FIELD DATA ... "); |
| 523 |
|
| 524 |
// Model defined, now fill in the model data... |
| 525 |
output_region.begin_mode(Ioss::STATE_MODEL); |
| 526 |
|
| 527 |
// Transfer MESH field_data from input to output... |
| 528 |
// Transfer MESH field_data from input to output... |
| 529 |
bool node_major = output_region.node_major(); |
| 530 |
|
| 531 |
if (!node_major) { |
| 532 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, Ioss::Field::MESH, |
| 533 |
options); |
| 534 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, |
| 535 |
Ioss::Field::ATTRIBUTE, options); |
| 536 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, Ioss::Field::MAP, |
| 537 |
options); |
| 538 |
} |
| 539 |
|
| 540 |
if (region.mesh_type() != Ioss::MeshType::STRUCTURED) { |
| 541 |
transfer_field_data(region.get_node_blocks(), output_region, data_pool, Ioss::Field::MESH, |
| 542 |
options); |
| 543 |
transfer_field_data(region.get_node_blocks(), output_region, data_pool, |
| 544 |
Ioss::Field::ATTRIBUTE, options); |
| 545 |
transfer_field_data(region.get_node_blocks(), output_region, data_pool, Ioss::Field::MAP, |
| 546 |
options); |
| 547 |
} |
| 548 |
|
| 549 |
if (node_major) { |
| 550 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, Ioss::Field::MESH, |
| 551 |
options); |
| 552 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, |
| 553 |
Ioss::Field::ATTRIBUTE, options); |
| 554 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, Ioss::Field::MAP, |
| 555 |
options); |
| 556 |
} |
| 557 |
|
| 558 |
// Structured Blocks -- Contain a NodeBlock that also needs its field data transferred... |
| 559 |
const auto &sbs = region.get_structured_blocks(); |
| 560 |
for (const auto &isb : sbs) { |
| 561 |
const std::string &name = isb->name(); |
| 562 |
if (options.debug && rank == 0) { |
| 563 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 564 |
} |
| 565 |
// Find matching output structured block |
| 566 |
Ioss::StructuredBlock *osb = output_region.get_structured_block(name); |
| 567 |
if (osb != nullptr) { |
| 568 |
transfer_field_data(isb, osb, data_pool, Ioss::Field::MESH, options); |
| 569 |
transfer_field_data(isb, osb, data_pool, Ioss::Field::ATTRIBUTE, options); |
| 570 |
|
| 571 |
auto &inb = isb->get_node_block(); |
| 572 |
auto &onb = osb->get_node_block(); |
| 573 |
if (options.debug && rank == 0) { |
| 574 |
fmt::print(Ioss::DebugOut(), "NB: {}, ", inb.name()); |
| 575 |
} |
| 576 |
|
| 577 |
transfer_field_data(&inb, &onb, data_pool, Ioss::Field::MESH, options); |
| 578 |
transfer_field_data(&inb, &onb, data_pool, Ioss::Field::ATTRIBUTE, options); |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
transfer_field_data(region.get_assemblies(), output_region, data_pool, Ioss::Field::MESH, |
| 583 |
options); |
| 584 |
transfer_field_data(region.get_assemblies(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 585 |
options); |
| 586 |
|
| 587 |
transfer_field_data(region.get_blobs(), output_region, data_pool, Ioss::Field::MESH, options); |
| 588 |
transfer_field_data(region.get_blobs(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 589 |
options); |
| 590 |
|
| 591 |
transfer_field_data(region.get_edge_blocks(), output_region, data_pool, Ioss::Field::MESH, |
| 592 |
options); |
| 593 |
transfer_field_data(region.get_edge_blocks(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 594 |
options); |
| 595 |
transfer_field_data(region.get_edge_blocks(), output_region, data_pool, Ioss::Field::MAP, |
| 596 |
options); |
| 597 |
|
| 598 |
transfer_field_data(region.get_face_blocks(), output_region, data_pool, Ioss::Field::MESH, |
| 599 |
options); |
| 600 |
transfer_field_data(region.get_face_blocks(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 601 |
options); |
| 602 |
transfer_field_data(region.get_face_blocks(), output_region, data_pool, Ioss::Field::MAP, |
| 603 |
options); |
| 604 |
|
| 605 |
transfer_field_data(region.get_nodesets(), output_region, data_pool, Ioss::Field::MESH, |
| 606 |
options); |
| 607 |
transfer_field_data(region.get_nodesets(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 608 |
options); |
| 609 |
|
| 610 |
transfer_field_data(region.get_edgesets(), output_region, data_pool, Ioss::Field::MESH, |
| 611 |
options); |
| 612 |
transfer_field_data(region.get_edgesets(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 613 |
options); |
| 614 |
|
| 615 |
transfer_field_data(region.get_facesets(), output_region, data_pool, Ioss::Field::MESH, |
| 616 |
options); |
| 617 |
transfer_field_data(region.get_facesets(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 618 |
options); |
| 619 |
|
| 620 |
transfer_field_data(region.get_elementsets(), output_region, data_pool, Ioss::Field::MESH, |
| 621 |
options); |
| 622 |
transfer_field_data(region.get_elementsets(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 623 |
options); |
| 624 |
|
| 625 |
transfer_field_data(region.get_commsets(), output_region, data_pool, Ioss::Field::MESH, |
| 626 |
options); |
| 627 |
transfer_field_data(region.get_commsets(), output_region, data_pool, Ioss::Field::ATTRIBUTE, |
| 628 |
options); |
| 629 |
transfer_field_data(region.get_commsets(), output_region, data_pool, Ioss::Field::COMMUNICATION, |
| 630 |
options); |
| 631 |
|
| 632 |
// Side Sets |
| 633 |
if (region.mesh_type() == Ioss::MeshType::UNSTRUCTURED) { |
| 634 |
const auto &fss = region.get_sidesets(); |
| 635 |
for (const auto &ifs : fss) { |
| 636 |
const std::string &name = ifs->name(); |
| 637 |
if (options.debug && rank == 0) { |
| 638 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 639 |
} |
| 640 |
// Find matching output sideset |
| 641 |
Ioss::SideSet *ofs = output_region.get_sideset(name); |
| 642 |
|
| 643 |
if (ofs != nullptr) { |
| 644 |
transfer_field_data(ifs, ofs, data_pool, Ioss::Field::MESH, options); |
| 645 |
transfer_field_data(ifs, ofs, data_pool, Ioss::Field::ATTRIBUTE, options); |
| 646 |
|
| 647 |
const auto &fbs = ifs->get_side_blocks(); |
| 648 |
for (const auto &ifb : fbs) { |
| 649 |
|
| 650 |
// Find matching output sideblock |
| 651 |
const std::string &fbname = ifb->name(); |
| 652 |
if (options.debug && rank == 0) { |
| 653 |
fmt::print(Ioss::DebugOut(), "{}, ", fbname); |
| 654 |
} |
| 655 |
Ioss::SideBlock *ofb = ofs->get_side_block(fbname); |
| 656 |
|
| 657 |
if (ofb != nullptr) { |
| 658 |
transfer_field_data(ifb, ofb, data_pool, Ioss::Field::MESH, options); |
| 659 |
transfer_field_data(ifb, ofb, data_pool, Ioss::Field::ATTRIBUTE, options); |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
} |
| 664 |
if (options.debug && rank == 0) { |
| 665 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 666 |
} |
| 667 |
|
| 668 |
if (options.define_geometry && options.boundary_sideset) { |
| 669 |
auto *ss = output_region.get_sideset("boundary"); |
| 670 |
if (ss != nullptr) { |
| 671 |
auto *sb = ss->get_side_block("boundary"); |
| 672 |
if (output_region.get_database()->int_byte_size_api() == 4) { |
| 673 |
output_boundary_sideset(sb, boundary, (int)0); |
| 674 |
} |
| 675 |
else { |
| 676 |
output_boundary_sideset(sb, boundary, (int64_t)0); |
| 677 |
} |
| 678 |
} |
| 679 |
} |
| 680 |
} |
| 681 |
if (options.debug && rank == 0) { |
| 682 |
fmt::print(Ioss::DebugOut(), "END STATE_MODEL... \n"); |
| 683 |
} |
| 684 |
dbi->progress("END STATE_MODEL... "); |
| 685 |
output_region.end_mode(Ioss::STATE_MODEL); |
| 686 |
} |
| 687 |
|
| 688 |
void define_transient_fields(Ioss::Region ®ion, Ioss::Region &output_region, |
| 689 |
const Ioss::MeshCopyOptions &options, int rank) |
| 690 |
{ |
| 691 |
if (options.debug && rank == 0) { |
| 692 |
fmt::print(Ioss::DebugOut(), "DEFINING TRANSIENT FIELDS ... \n"); |
| 693 |
} |
| 694 |
|
| 695 |
Ioss::DatabaseIO *dbi = region.get_database(); |
| 696 |
dbi->progress("DEFINING TRANSIENT FIELDS ... "); |
| 697 |
|
| 698 |
if (region.property_exists("state_count") && region.get_property("state_count").get_int() > 0) { |
| 699 |
if (options.output_summary && rank == 0) { |
| 700 |
fmt::print(Ioss::DebugOut(), "\n Number of time steps on database = {}\n", |
| 701 |
region.get_property("state_count").get_int()); |
| 702 |
} |
| 703 |
|
| 704 |
output_region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 705 |
|
| 706 |
// NOTE: For most types, the fields are transferred from input to output |
| 707 |
// via the copy constructor. The "special" ones are handled here. |
| 708 |
// The below lines handle both methods of handling global variables... |
| 709 |
transfer_fields(®ion, &output_region, Ioss::Field::REDUCTION); |
| 710 |
transfer_fields(®ion, &output_region, Ioss::Field::TRANSIENT); |
| 711 |
|
| 712 |
// Structured Blocks -- Contain a NodeBlock that also needs its fields transferred... |
| 713 |
const auto &sbs = region.get_structured_blocks(); |
| 714 |
for (const auto &isb : sbs) { |
| 715 |
|
| 716 |
// Find matching output structured block |
| 717 |
const std::string &name = isb->name(); |
| 718 |
Ioss::StructuredBlock *osb = output_region.get_structured_block(name); |
| 719 |
if (osb != nullptr) { |
| 720 |
transfer_fields(isb, osb, Ioss::Field::TRANSIENT); |
| 721 |
transfer_fields(isb, osb, Ioss::Field::REDUCTION); |
| 722 |
|
| 723 |
auto &inb = isb->get_node_block(); |
| 724 |
auto &onb = osb->get_node_block(); |
| 725 |
transfer_fields(&inb, &onb, Ioss::Field::TRANSIENT); |
| 726 |
transfer_fields(&inb, &onb, Ioss::Field::REDUCTION); |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
if (options.debug && rank == 0) { |
| 731 |
fmt::print(Ioss::DebugOut(), "END STATE_DEFINE_TRANSIENT... \n"); |
| 732 |
} |
| 733 |
dbi->progress("END STATE_DEFINE_TRANSIENT... "); |
| 734 |
output_region.end_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 735 |
} |
| 736 |
} |
| 737 |
void transfer_step(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &data_pool, |
| 738 |
int istep, const Ioss::MeshCopyOptions &options, int rank) |
| 739 |
{ |
| 740 |
double time = region.get_state_time(istep); |
| 741 |
double otime = time * options.time_scale + options.time_offset; |
| 742 |
int ostep = output_region.add_state(otime); |
| 743 |
|
| 744 |
show_step(istep, time, options, rank); |
| 745 |
|
| 746 |
output_region.begin_state(ostep); |
| 747 |
region.begin_state(istep); |
| 748 |
|
| 749 |
for (int i = 0; i < 2; i++) { |
| 750 |
auto field_type = Ioss::Field::TRANSIENT; |
| 751 |
if (i > 0) { |
| 752 |
field_type = Ioss::Field::REDUCTION; |
| 753 |
} |
| 754 |
|
| 755 |
transfer_field_data(®ion, &output_region, data_pool, field_type, options); |
| 756 |
|
| 757 |
transfer_field_data(region.get_assemblies(), output_region, data_pool, field_type, options); |
| 758 |
transfer_field_data(region.get_blobs(), output_region, data_pool, field_type, options); |
| 759 |
|
| 760 |
if (region.mesh_type() != Ioss::MeshType::STRUCTURED) { |
| 761 |
transfer_field_data(region.get_node_blocks(), output_region, data_pool, field_type, |
| 762 |
options); |
| 763 |
} |
| 764 |
transfer_field_data(region.get_edge_blocks(), output_region, data_pool, field_type, options); |
| 765 |
transfer_field_data(region.get_face_blocks(), output_region, data_pool, field_type, options); |
| 766 |
transfer_field_data(region.get_element_blocks(), output_region, data_pool, field_type, |
| 767 |
options); |
| 768 |
|
| 769 |
{ |
| 770 |
// Structured Blocks -- handle embedded NodeBlock also. |
| 771 |
const auto &sbs = region.get_structured_blocks(); |
| 772 |
for (const auto &isb : sbs) { |
| 773 |
const std::string &name = isb->name(); |
| 774 |
if (options.debug && rank == 0) { |
| 775 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 776 |
} |
| 777 |
// Find matching output structured block |
| 778 |
Ioss::StructuredBlock *osb = output_region.get_structured_block(name); |
| 779 |
if (osb != nullptr) { |
| 780 |
transfer_field_data(isb, osb, data_pool, field_type, options); |
| 781 |
|
| 782 |
auto &inb = isb->get_node_block(); |
| 783 |
auto &onb = osb->get_node_block(); |
| 784 |
transfer_field_data(&inb, &onb, data_pool, field_type, options); |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
transfer_field_data(region.get_nodesets(), output_region, data_pool, field_type, options); |
| 790 |
transfer_field_data(region.get_edgesets(), output_region, data_pool, field_type, options); |
| 791 |
transfer_field_data(region.get_facesets(), output_region, data_pool, field_type, options); |
| 792 |
transfer_field_data(region.get_elementsets(), output_region, data_pool, field_type, options); |
| 793 |
|
| 794 |
// Side Sets |
| 795 |
{ |
| 796 |
const auto &fss = region.get_sidesets(); |
| 797 |
for (const auto &ifs : fss) { |
| 798 |
const std::string &name = ifs->name(); |
| 799 |
if (options.debug && rank == 0) { |
| 800 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 801 |
} |
| 802 |
|
| 803 |
// Find matching output sideset |
| 804 |
Ioss::SideSet *ofs = output_region.get_sideset(name); |
| 805 |
if (ofs != nullptr) { |
| 806 |
transfer_field_data(ifs, ofs, data_pool, field_type, options); |
| 807 |
|
| 808 |
const auto &fbs = ifs->get_side_blocks(); |
| 809 |
for (const auto &ifb : fbs) { |
| 810 |
|
| 811 |
// Find matching output sideblock |
| 812 |
const std::string &fbname = ifb->name(); |
| 813 |
if (options.debug && rank == 0) { |
| 814 |
fmt::print(Ioss::DebugOut(), "{}, ", fbname); |
| 815 |
} |
| 816 |
|
| 817 |
Ioss::SideBlock *ofb = ofs->get_side_block(fbname); |
| 818 |
if (ofb != nullptr) { |
| 819 |
transfer_field_data(ifb, ofb, data_pool, field_type, options); |
| 820 |
} |
| 821 |
} |
| 822 |
} |
| 823 |
} |
| 824 |
} |
| 825 |
} |
| 826 |
region.end_state(istep); |
| 827 |
output_region.end_state(ostep); |
| 828 |
|
| 829 |
if (options.delay > 0.0) { |
| 830 |
std::this_thread::sleep_for( |
| 831 |
std::chrono::milliseconds(static_cast<int>(options.delay * 1'000))); |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
void transfer_nodeblock(Ioss::Region ®ion, Ioss::Region &output_region, Ioss::DataPool &pool, |
| 836 |
const Ioss::MeshCopyOptions &options, int rank) |
| 837 |
{ |
| 838 |
const auto &nbs = region.get_node_blocks(); |
| 839 |
for (const auto &inb : nbs) { |
| 840 |
const std::string &name = inb->name(); |
| 841 |
if (options.debug && rank == 0) { |
| 842 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 843 |
} |
| 844 |
if (options.output_summary && rank == 0) { |
| 845 |
size_t degree = inb->get_property("component_degree").get_int(); |
| 846 |
fmt::print(Ioss::DebugOut(), " Number of Coordinates per Node = {:14}\n", |
| 847 |
fmt::group_digits(degree)); |
| 848 |
size_t num_nodes = inb->entity_count(); |
| 849 |
fmt::print(Ioss::DebugOut(), " Number of Nodes = {:14}\n", |
| 850 |
fmt::group_digits(num_nodes)); |
| 851 |
} |
| 852 |
|
| 853 |
if (options.omitted_blocks) { |
| 854 |
size_t isize = inb->get_field("node_connectivity_status").get_size(); |
| 855 |
pool.data.resize(isize); |
| 856 |
inb->get_field_data("node_connectivity_status", pool.data.data(), isize); |
| 857 |
|
| 858 |
// Count number of "active" nodes |
| 859 |
size_t active = |
| 860 |
std::count_if(pool.data.begin(), pool.data.end(), [](auto &val) { return val >= 2; }); |
| 861 |
fmt::print(Ioss::DebugOut(), " Number of Active Nodes = {:14}\n", |
| 862 |
fmt::group_digits(active)); |
| 863 |
} |
| 864 |
|
| 865 |
auto *nb = new Ioss::NodeBlock(*inb); |
| 866 |
output_region.add(nb); |
| 867 |
|
| 868 |
if (output_region.get_database()->needs_shared_node_information()) { |
| 869 |
// If the "owning_processor" field exists on the input |
| 870 |
// nodeblock, transfer it and the "ids" field to the output |
| 871 |
// nodeblock at this time since it is used to determine |
| 872 |
// per-processor sizes of nodeblocks and nodesets. |
| 873 |
if (inb->field_exists("owning_processor")) { |
| 874 |
size_t isize = inb->get_field("ids").get_size(); |
| 875 |
pool.data.resize(isize); |
| 876 |
inb->get_field_data("ids", pool.data.data(), isize); |
| 877 |
nb->put_field_data("ids", pool.data.data(), isize); |
| 878 |
|
| 879 |
isize = inb->get_field("owning_processor").get_size(); |
| 880 |
pool.data.resize(isize); |
| 881 |
inb->get_field_data("owning_processor", pool.data.data(), isize); |
| 882 |
nb->put_field_data("owning_processor", pool.data.data(), isize); |
| 883 |
} |
| 884 |
} |
| 885 |
} |
| 886 |
if (options.debug && rank == 0) { |
| 887 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
template <typename T> |
| 892 |
void transfer_field_data(const std::vector<T *> &entities, Ioss::Region &output_region, |
| 893 |
Ioss::DataPool &pool, Ioss::Field::RoleType role, |
| 894 |
const Ioss::MeshCopyOptions &options) |
| 895 |
{ |
| 896 |
for (const auto &entity : entities) { |
| 897 |
const std::string &name = entity->name(); |
| 898 |
|
| 899 |
// Find the corresponding output entity (may not exist if omitted) |
| 900 |
Ioss::GroupingEntity *output = output_region.get_entity(name, entity->type()); |
| 901 |
if (output != nullptr) { |
| 902 |
transfer_field_data(entity, output, pool, role, options); |
| 903 |
} |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
template <typename T> |
| 908 |
void transfer_blocks(const std::vector<T *> &blocks, Ioss::Region &output_region, |
| 909 |
const Ioss::MeshCopyOptions &options, int rank) |
| 910 |
{ |
| 911 |
if (!blocks.empty()) { |
| 912 |
size_t total_entities = 0; |
| 913 |
for (const auto &iblock : blocks) { |
| 914 |
if (Ioss::Utils::block_is_omitted(iblock)) { |
| 915 |
continue; |
| 916 |
} |
| 917 |
const std::string &name = iblock->name(); |
| 918 |
if (options.debug && rank == 0) { |
| 919 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 920 |
} |
| 921 |
size_t count = iblock->entity_count(); |
| 922 |
total_entities += count; |
| 923 |
|
| 924 |
auto *block = new T(*iblock); |
| 925 |
output_region.add(block); |
| 926 |
} |
| 927 |
if (options.output_summary && rank == 0) { |
| 928 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}\n", |
| 929 |
(*blocks.begin())->type_string() + "s", fmt::group_digits(blocks.size())); |
| 930 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}\n", |
| 931 |
(*blocks.begin())->contains_string() + "s", fmt::group_digits(total_entities)); |
| 932 |
} |
| 933 |
if (options.debug && rank == 0) { |
| 934 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 935 |
} |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
void transfer_structuredblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 940 |
const Ioss::MeshCopyOptions &options, int rank) |
| 941 |
{ |
| 942 |
const auto &blocks = region.get_structured_blocks(); |
| 943 |
if (!blocks.empty()) { |
| 944 |
size_t total_entities = 0; |
| 945 |
if (options.reverse) { |
| 946 |
// Defines the CGNS zones in the reverse order they |
| 947 |
// were read from the input mesh. This is used in |
| 948 |
// testing to verify that we handle zone reordering |
| 949 |
// correctly. |
| 950 |
for (int i = static_cast<int>(blocks.size()) - 1; i >= 0; i--) { |
| 951 |
const auto &iblock = blocks[i]; |
| 952 |
if (Ioss::Utils::block_is_omitted(iblock)) { |
| 953 |
continue; |
| 954 |
} |
| 955 |
const std::string &name = iblock->name(); |
| 956 |
if (options.debug && rank == 0) { |
| 957 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 958 |
} |
| 959 |
size_t count = iblock->entity_count(); |
| 960 |
total_entities += count; |
| 961 |
|
| 962 |
auto *block = iblock->clone(output_region.get_database()); |
| 963 |
output_region.add(block); |
| 964 |
transfer_mesh_info(iblock, block); |
| 965 |
|
| 966 |
// Now do the transfer on the NodeBlock contained in the StructuredBlock |
| 967 |
auto &inb = iblock->get_node_block(); |
| 968 |
auto &onb = block->get_node_block(); |
| 969 |
if (options.debug && rank == 0) { |
| 970 |
fmt::print(Ioss::DebugOut(), "(NB: {}), ", inb.name()); |
| 971 |
} |
| 972 |
transfer_mesh_info(&inb, &onb); |
| 973 |
} |
| 974 |
} |
| 975 |
else { |
| 976 |
for (const auto &iblock : blocks) { |
| 977 |
if (Ioss::Utils::block_is_omitted(iblock)) { |
| 978 |
continue; |
| 979 |
} |
| 980 |
const std::string &name = iblock->name(); |
| 981 |
if (options.debug && rank == 0) { |
| 982 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 983 |
} |
| 984 |
size_t count = iblock->entity_count(); |
| 985 |
total_entities += count; |
| 986 |
|
| 987 |
auto *block = iblock->clone(output_region.get_database()); |
| 988 |
output_region.add(block); |
| 989 |
transfer_mesh_info(iblock, block); |
| 990 |
|
| 991 |
// Now do the transfer on the NodeBlock contained in the StructuredBlock |
| 992 |
auto &inb = iblock->get_node_block(); |
| 993 |
auto &onb = block->get_node_block(); |
| 994 |
if (options.debug && rank == 0) { |
| 995 |
fmt::print(Ioss::DebugOut(), "(NB: {}), ", inb.name()); |
| 996 |
} |
| 997 |
transfer_mesh_info(&inb, &onb); |
| 998 |
} |
| 999 |
} |
| 1000 |
|
| 1001 |
if (options.output_summary && rank == 0) { |
| 1002 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}\n", |
| 1003 |
(*blocks.begin())->type_string() + "s", fmt::group_digits(blocks.size())); |
| 1004 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}\n", |
| 1005 |
(*blocks.begin())->contains_string() + "s", fmt::group_digits(total_entities)); |
| 1006 |
} |
| 1007 |
if (options.debug && rank == 0) { |
| 1008 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 1009 |
} |
| 1010 |
} |
| 1011 |
} |
| 1012 |
|
| 1013 |
void transfer_elementblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1014 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1015 |
{ |
| 1016 |
const auto &ebs = region.get_element_blocks(); |
| 1017 |
transfer_blocks(ebs, output_region, options, rank); |
| 1018 |
} |
| 1019 |
|
| 1020 |
void transfer_edgeblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1021 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1022 |
{ |
| 1023 |
const auto &ebs = region.get_edge_blocks(); |
| 1024 |
transfer_blocks(ebs, output_region, options, rank); |
| 1025 |
} |
| 1026 |
|
| 1027 |
void transfer_faceblocks(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1028 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1029 |
{ |
| 1030 |
const auto &ebs = region.get_face_blocks(); |
| 1031 |
transfer_blocks(ebs, output_region, options, rank); |
| 1032 |
} |
| 1033 |
|
| 1034 |
void transfer_sidesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1035 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1036 |
{ |
| 1037 |
const auto &fss = region.get_sidesets(); |
| 1038 |
for (const auto &ss : fss) { |
| 1039 |
const std::string &name = ss->name(); |
| 1040 |
auto lc_name = Ioss::Utils::lowercase(name); |
| 1041 |
if (std::find(options.omitted_sets.begin(), options.omitted_sets.end(), lc_name) == |
| 1042 |
options.omitted_sets.end()) { |
| 1043 |
if (options.debug && rank == 0) { |
| 1044 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 1045 |
} |
| 1046 |
auto *surf = new Ioss::SideSet(*ss); |
| 1047 |
output_region.add(surf); |
| 1048 |
|
| 1049 |
// Fix up the optional 'owner_block' in copied SideBlocks... |
| 1050 |
const auto &fbs = ss->get_side_blocks(); |
| 1051 |
for (const auto &ifb : fbs) { |
| 1052 |
if (ifb->parent_block() != nullptr) { |
| 1053 |
const auto &fb_name = ifb->parent_block()->name(); |
| 1054 |
auto *parent = dynamic_cast<Ioss::EntityBlock *>( |
| 1055 |
output_region.get_entity(fb_name, Ioss::ELEMENTBLOCK)); |
| 1056 |
if (parent == nullptr) { |
| 1057 |
parent = dynamic_cast<Ioss::EntityBlock *>( |
| 1058 |
output_region.get_entity(fb_name, Ioss::STRUCTUREDBLOCK)); |
| 1059 |
} |
| 1060 |
|
| 1061 |
auto *ofb = surf->get_side_block(ifb->name()); |
| 1062 |
ofb->set_parent_block(parent); |
| 1063 |
} |
| 1064 |
} |
| 1065 |
} |
| 1066 |
else { |
| 1067 |
if (options.debug && rank == 0) { |
| 1068 |
fmt::print(Ioss::DebugOut(), "{}(omitted), ", name); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
|
| 1073 |
if (options.output_summary && rank == 0 && !fss.empty()) { |
| 1074 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}\n", |
| 1075 |
(*fss.begin())->type_string() + "s", fmt::group_digits(fss.size())); |
| 1076 |
} |
| 1077 |
if (options.debug && rank == 0) { |
| 1078 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 1079 |
} |
| 1080 |
} |
| 1081 |
|
| 1082 |
template <typename T> |
| 1083 |
void transfer_sets(const std::vector<T *> &sets, Ioss::Region &output_region, |
| 1084 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1085 |
{ |
| 1086 |
if (!sets.empty()) { |
| 1087 |
size_t total_entities = 0; |
| 1088 |
for (const auto &set : sets) { |
| 1089 |
const std::string &name = set->name(); |
| 1090 |
auto lc_name = Ioss::Utils::lowercase(name); |
| 1091 |
if (std::find(options.omitted_sets.begin(), options.omitted_sets.end(), lc_name) == |
| 1092 |
options.omitted_sets.end()) { |
| 1093 |
if (options.debug && rank == 0) { |
| 1094 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 1095 |
} |
| 1096 |
size_t count = set->entity_count(); |
| 1097 |
total_entities += count; |
| 1098 |
auto *o_set = new T(*set); |
| 1099 |
output_region.add(o_set); |
| 1100 |
} |
| 1101 |
else { |
| 1102 |
if (options.debug && rank == 0) { |
| 1103 |
fmt::print(Ioss::DebugOut(), "{}(omitted), ", name); |
| 1104 |
} |
| 1105 |
} |
| 1106 |
} |
| 1107 |
if (options.output_summary && rank == 0) { |
| 1108 |
fmt::print(Ioss::DebugOut(), " Number of {:20s} = {:14}", |
| 1109 |
(*sets.begin())->type_string() + "s", fmt::group_digits(sets.size())); |
| 1110 |
fmt::print(Ioss::DebugOut(), "\tLength of entity list = {:14}\n", |
| 1111 |
fmt::group_digits(total_entities)); |
| 1112 |
} |
| 1113 |
if (options.debug && rank == 0) { |
| 1114 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 1115 |
} |
| 1116 |
} |
| 1117 |
} |
| 1118 |
|
| 1119 |
void transfer_nodesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1120 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1121 |
{ |
| 1122 |
const auto &nss = region.get_nodesets(); |
| 1123 |
transfer_sets(nss, output_region, options, rank); |
| 1124 |
} |
| 1125 |
|
| 1126 |
void transfer_edgesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1127 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1128 |
{ |
| 1129 |
const auto &nss = region.get_edgesets(); |
| 1130 |
transfer_sets(nss, output_region, options, rank); |
| 1131 |
} |
| 1132 |
|
| 1133 |
void transfer_facesets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1134 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1135 |
{ |
| 1136 |
const auto &nss = region.get_facesets(); |
| 1137 |
transfer_sets(nss, output_region, options, rank); |
| 1138 |
} |
| 1139 |
|
| 1140 |
void transfer_elemsets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1141 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1142 |
{ |
| 1143 |
const auto &nss = region.get_elementsets(); |
| 1144 |
transfer_sets(nss, output_region, options, rank); |
| 1145 |
} |
| 1146 |
|
| 1147 |
void transfer_commsets(Ioss::Region ®ion, Ioss::Region &output_region, |
| 1148 |
const Ioss::MeshCopyOptions &options, int rank) |
| 1149 |
{ |
| 1150 |
const auto &css = region.get_commsets(); |
| 1151 |
for (const auto &ics : css) { |
| 1152 |
if (options.debug && rank == 0) { |
| 1153 |
const std::string &name = ics->name(); |
| 1154 |
fmt::print(Ioss::DebugOut(), "{}, ", name); |
| 1155 |
} |
| 1156 |
auto *cs = new Ioss::CommSet(*ics); |
| 1157 |
output_region.add(cs); |
| 1158 |
} |
| 1159 |
if (options.debug && rank == 0) { |
| 1160 |
fmt::print(Ioss::DebugOut(), "\n"); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
void transfer_fields(const Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 1165 |
Ioss::Field::RoleType role, const std::string &prefix) |
| 1166 |
{ |
| 1167 |
// Check for transient fields... |
| 1168 |
Ioss::NameList fields = ige->field_describe(role); |
| 1169 |
|
| 1170 |
// Iterate through results fields and transfer to output |
| 1171 |
// database... If a prefix is specified, only transfer fields |
| 1172 |
// whose names begin with the prefix |
| 1173 |
for (const auto &field_name : fields) { |
| 1174 |
Ioss::Field field = ige->get_field(field_name); |
| 1175 |
if (field_name != "ids" && !oge->field_exists(field_name) && |
| 1176 |
Ioss::Utils::substr_equal(prefix, field_name)) { |
| 1177 |
// If the field does not already exist, add it to the output node block |
| 1178 |
oge->field_add(std::move(field)); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
void transfer_field_data(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 1184 |
Ioss::DataPool &pool, Ioss::Field::RoleType role, |
| 1185 |
const Ioss::MeshCopyOptions &options, const std::string &prefix) |
| 1186 |
{ |
| 1187 |
// Iterate through the TRANSIENT-role fields of the input |
| 1188 |
// database and transfer to output database. |
| 1189 |
Ioss::NameList state_fields = ige->field_describe(role); |
| 1190 |
|
| 1191 |
// Complication here is that if the 'role' is 'Ioss::Field::MESH', |
| 1192 |
// then the 'ids' field must be transferred first... |
| 1193 |
if (role == Ioss::Field::MESH && ige->field_exists("ids")) { |
| 1194 |
assert(oge->field_exists("ids")); |
| 1195 |
transfer_field_data_internal(ige, oge, pool, "ids", options); |
| 1196 |
} |
| 1197 |
|
| 1198 |
for (const auto &field_name : state_fields) { |
| 1199 |
// All of the 'Ioss::EntityBlock' derived classes have a |
| 1200 |
// 'connectivity' field, but it is only interesting on the |
| 1201 |
// Ioss::ElementBlock class. On the other classes, it just |
| 1202 |
// generates overhead... |
| 1203 |
|
| 1204 |
if (field_name == "connectivity" && ige->type() != Ioss::ELEMENTBLOCK) { |
| 1205 |
continue; |
| 1206 |
} |
| 1207 |
if (field_name == "ids") { |
| 1208 |
continue; |
| 1209 |
} |
| 1210 |
|
| 1211 |
if (Ioss::Utils::substr_equal(prefix, field_name)) { |
| 1212 |
assert(oge->field_exists(field_name)); |
| 1213 |
transfer_field_data_internal(ige, oge, pool, field_name, options); |
| 1214 |
} |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
void transfer_field_data_internal(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 1219 |
Ioss::DataPool &pool, const std::string &field_name, |
| 1220 |
const Ioss::MeshCopyOptions &options) |
| 1221 |
{ |
| 1222 |
|
| 1223 |
size_t isize = ige->get_field(field_name).get_size(); |
| 1224 |
assert(isize == oge->get_field(field_name).get_size()); |
| 1225 |
|
| 1226 |
if (field_name == "mesh_model_coordinates_x") { |
| 1227 |
return; |
| 1228 |
} |
| 1229 |
if (field_name == "mesh_model_coordinates_y") { |
| 1230 |
return; |
| 1231 |
} |
| 1232 |
if (field_name == "mesh_model_coordinates_z") { |
| 1233 |
return; |
| 1234 |
} |
| 1235 |
if (field_name == "connectivity_raw") { |
| 1236 |
return; |
| 1237 |
} |
| 1238 |
if (field_name == "element_side_raw") { |
| 1239 |
return; |
| 1240 |
} |
| 1241 |
if (field_name == "ids_raw") { |
| 1242 |
return; |
| 1243 |
} |
| 1244 |
if (field_name == "implicit_ids") { |
| 1245 |
return; |
| 1246 |
} |
| 1247 |
if (field_name == "node_connectivity_status") { |
| 1248 |
return; |
| 1249 |
} |
| 1250 |
if (field_name == "owning_processor") { |
| 1251 |
return; |
| 1252 |
} |
| 1253 |
if (field_name == "entity_processor_raw") { |
| 1254 |
return; |
| 1255 |
} |
| 1256 |
if (field_name == "ids" && ige->type() == Ioss::SIDEBLOCK) { |
| 1257 |
return; |
| 1258 |
} |
| 1259 |
if (field_name == "ids" && ige->type() == Ioss::STRUCTUREDBLOCK) { |
| 1260 |
return; |
| 1261 |
} |
| 1262 |
if (field_name == "cell_ids" && ige->type() == Ioss::STRUCTUREDBLOCK) { |
| 1263 |
return; |
| 1264 |
} |
| 1265 |
if (field_name == "cell_node_ids" && ige->type() == Ioss::STRUCTUREDBLOCK) { |
| 1266 |
return; |
| 1267 |
} |
| 1268 |
|
| 1269 |
if (options.data_storage_type == 1 || options.data_storage_type == 2) { |
| 1270 |
if (pool.data.size() < isize) { |
| 1271 |
pool.data.resize(isize); |
| 1272 |
} |
| 1273 |
} |
| 1274 |
else { |
| 1275 |
} |
| 1276 |
|
| 1277 |
#ifdef SEACAS_HAVE_KOKKOS |
| 1278 |
int basic_type = ige->get_field(field_name).get_type(); |
| 1279 |
#endif |
| 1280 |
|
| 1281 |
assert(pool.data.size() >= isize); |
| 1282 |
|
| 1283 |
switch (options.data_storage_type) { |
| 1284 |
case 1: ige->get_field_data(field_name, pool.data.data(), isize); break; |
| 1285 |
#ifdef SEACAS_HAVE_KOKKOS |
| 1286 |
case 3: |
| 1287 |
if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) { |
| 1288 |
ige->get_field_data<char>(field_name, pool.data_view_char); |
| 1289 |
} |
| 1290 |
else if (basic_type == Ioss::Field::INT32) { |
| 1291 |
ige->get_field_data<int>(field_name, pool.data_view_int); |
| 1292 |
} |
| 1293 |
else if (basic_type == Ioss::Field::INT64) { |
| 1294 |
ige->get_field_data<int64_t>(field_name, pool.data_view_int64); |
| 1295 |
} |
| 1296 |
else if (basic_type == Ioss::Field::REAL) { |
| 1297 |
ige->get_field_data<double>(field_name, pool.data_view_double); |
| 1298 |
} |
| 1299 |
else if (basic_type == Ioss::Field::COMPLEX) { |
| 1300 |
// Since data_view_complex cannot be a global variable. |
| 1301 |
ige->get_field_data(field_name, pool.data.data(), isize); |
| 1302 |
} |
| 1303 |
else { |
| 1304 |
} |
| 1305 |
break; |
| 1306 |
case 4: |
| 1307 |
if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) { |
| 1308 |
ige->get_field_data<char>(field_name, pool.data_view_2D_char); |
| 1309 |
} |
| 1310 |
else if (basic_type == Ioss::Field::INT32) { |
| 1311 |
ige->get_field_data<int>(field_name, pool.data_view_2D_int); |
| 1312 |
} |
| 1313 |
else if (basic_type == Ioss::Field::INT64) { |
| 1314 |
ige->get_field_data<int64_t>(field_name, pool.data_view_2D_int64); |
| 1315 |
} |
| 1316 |
else if (basic_type == Ioss::Field::REAL) { |
| 1317 |
ige->get_field_data<double>(field_name, pool.data_view_2D_double); |
| 1318 |
} |
| 1319 |
else if (basic_type == Ioss::Field::COMPLEX) { |
| 1320 |
// Since data_view_complex cannot be a global variable. |
| 1321 |
ige->get_field_data(field_name, pool.data.data(), isize); |
| 1322 |
} |
| 1323 |
else { |
| 1324 |
} |
| 1325 |
break; |
| 1326 |
case 5: |
| 1327 |
if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) { |
| 1328 |
ige->get_field_data<char, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1329 |
field_name, pool.data_view_2D_char_layout_space); |
| 1330 |
} |
| 1331 |
else if (basic_type == Ioss::Field::INT32) { |
| 1332 |
ige->get_field_data<int, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1333 |
field_name, pool.data_view_2D_int_layout_space); |
| 1334 |
} |
| 1335 |
else if (basic_type == Ioss::Field::INT64) { |
| 1336 |
ige->get_field_data<int64_t, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1337 |
field_name, pool.data_view_2D_int64_layout_space); |
| 1338 |
} |
| 1339 |
else if (basic_type == Ioss::Field::REAL) { |
| 1340 |
ige->get_field_data<double, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1341 |
field_name, pool.data_view_2D_double_layout_space); |
| 1342 |
} |
| 1343 |
else if (basic_type == Ioss::Field::COMPLEX) { |
| 1344 |
// Since data_view_complex cannot be a global variable. |
| 1345 |
ige->get_field_data(field_name, pool.data.data(), isize); |
| 1346 |
} |
| 1347 |
else { |
| 1348 |
} |
| 1349 |
break; |
| 1350 |
#endif |
| 1351 |
default: |
| 1352 |
if (field_name == "mesh_model_coordinates") { |
| 1353 |
fmt::print(Ioss::DebugOut(), "data_storage option not recognized."); |
| 1354 |
} |
| 1355 |
return; |
| 1356 |
} |
| 1357 |
|
| 1358 |
switch (options.data_storage_type) { |
| 1359 |
case 1: oge->put_field_data(field_name, pool.data.data(), isize); break; |
| 1360 |
#ifdef SEACAS_HAVE_KOKKOS |
| 1361 |
case 3: |
| 1362 |
if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) { |
| 1363 |
oge->put_field_data<char>(field_name, pool.data_view_char); |
| 1364 |
} |
| 1365 |
else if (basic_type == Ioss::Field::INT32) { |
| 1366 |
oge->put_field_data<int>(field_name, pool.data_view_int); |
| 1367 |
} |
| 1368 |
else if (basic_type == Ioss::Field::INT64) { |
| 1369 |
oge->put_field_data<int64_t>(field_name, pool.data_view_int64); |
| 1370 |
} |
| 1371 |
else if (basic_type == Ioss::Field::REAL) { |
| 1372 |
oge->put_field_data<double>(field_name, pool.data_view_double); |
| 1373 |
} |
| 1374 |
else if (basic_type == Ioss::Field::COMPLEX) { |
| 1375 |
// Since data_view_complex cannot be a global variable. |
| 1376 |
oge->put_field_data(field_name, pool.data.data(), isize); |
| 1377 |
} |
| 1378 |
else { |
| 1379 |
} |
| 1380 |
break; |
| 1381 |
case 4: |
| 1382 |
if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) { |
| 1383 |
oge->put_field_data<char>(field_name, pool.data_view_2D_char); |
| 1384 |
} |
| 1385 |
else if (basic_type == Ioss::Field::INT32) { |
| 1386 |
oge->put_field_data<int>(field_name, pool.data_view_2D_int); |
| 1387 |
} |
| 1388 |
else if (basic_type == Ioss::Field::INT64) { |
| 1389 |
oge->put_field_data<int64_t>(field_name, pool.data_view_2D_int64); |
| 1390 |
} |
| 1391 |
else if (basic_type == Ioss::Field::REAL) { |
| 1392 |
oge->put_field_data<double>(field_name, pool.data_view_2D_double); |
| 1393 |
} |
| 1394 |
else if (basic_type == Ioss::Field::COMPLEX) { |
| 1395 |
// Since data_view_complex cannot be a global variable. |
| 1396 |
oge->put_field_data(field_name, pool.data.data(), isize); |
| 1397 |
} |
| 1398 |
else { |
| 1399 |
} |
| 1400 |
break; |
| 1401 |
case 5: |
| 1402 |
if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) { |
| 1403 |
oge->put_field_data<char, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1404 |
field_name, pool.data_view_2D_char_layout_space); |
| 1405 |
} |
| 1406 |
else if (basic_type == Ioss::Field::INT32) { |
| 1407 |
oge->put_field_data<int, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1408 |
field_name, pool.data_view_2D_int_layout_space); |
| 1409 |
} |
| 1410 |
else if (basic_type == Ioss::Field::INT64) { |
| 1411 |
oge->put_field_data<int64_t, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1412 |
field_name, pool.data_view_2D_int64_layout_space); |
| 1413 |
} |
| 1414 |
else if (basic_type == Ioss::Field::REAL) { |
| 1415 |
oge->put_field_data<double, Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 1416 |
field_name, pool.data_view_2D_double_layout_space); |
| 1417 |
} |
| 1418 |
else if (basic_type == Ioss::Field::COMPLEX) { |
| 1419 |
// Since data_view_complex cannot be a global variable. |
| 1420 |
oge->put_field_data(field_name, pool.data.data(), isize); |
| 1421 |
} |
| 1422 |
else { |
| 1423 |
} |
| 1424 |
break; |
| 1425 |
#endif |
| 1426 |
default: return; |
| 1427 |
} |
| 1428 |
} |
| 1429 |
|
| 1430 |
void transfer_qa_info(Ioss::Region &in, Ioss::Region &out) |
| 1431 |
{ |
| 1432 |
out.add_information_records(in.get_information_records()); |
| 1433 |
|
| 1434 |
const Ioss::NameList &qa = in.get_qa_records(); |
| 1435 |
for (size_t i = 0; i < qa.size(); i += 4) { |
| 1436 |
out.add_qa_record(qa[i + 0], qa[i + 1], qa[i + 2], qa[i + 3]); |
| 1437 |
} |
| 1438 |
} |
| 1439 |
|
| 1440 |
void transfer_properties(const Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge) |
| 1441 |
{ |
| 1442 |
Ioss::NameList properties = ige->property_describe(); |
| 1443 |
|
| 1444 |
// Iterate through properties and transfer to output database... |
| 1445 |
for (const auto &property : properties) { |
| 1446 |
if (!oge->property_exists(property)) { |
| 1447 |
oge->property_add(ige->get_property(property)); |
| 1448 |
} |
| 1449 |
} |
| 1450 |
} |
| 1451 |
|
| 1452 |
void show_step(int istep, double time, const Ioss::MeshCopyOptions &options, int rank) |
| 1453 |
{ |
| 1454 |
if (options.output_summary && rank == 0) { |
| 1455 |
fmt::print(Ioss::DebugOut(), "\r\tTime step {:5d} at time {:10.5e}", istep, time); |
| 1456 |
} |
| 1457 |
} |
| 1458 |
|
| 1459 |
#ifdef SEACAS_HAVE_MPI |
| 1460 |
template <typename INT> |
| 1461 |
void set_owned_node_count(Ioss::Region ®ion, int my_processor, INT /*dummy*/) |
| 1462 |
{ |
| 1463 |
Ioss::NodeBlock *nb = region.get_node_block("nodeblock_1"); |
| 1464 |
if (nb->field_exists("owning_processor")) { |
| 1465 |
std::vector<int> my_data; |
| 1466 |
nb->get_field_data("owning_processor", my_data); |
| 1467 |
|
| 1468 |
INT owned = std::count(my_data.begin(), my_data.end(), my_processor); |
| 1469 |
nb->property_add(Ioss::Property("locally_owned_count", owned)); |
| 1470 |
|
| 1471 |
// Set locally_owned_count property on all nodesets... |
| 1472 |
const Ioss::NodeSetContainer &nss = region.get_nodesets(); |
| 1473 |
for (const auto &ns : nss) { |
| 1474 |
|
| 1475 |
std::vector<INT> ids; |
| 1476 |
ns->get_field_data("ids_raw", ids); |
| 1477 |
owned = 0; |
| 1478 |
for (auto id : ids) { |
| 1479 |
if (my_data[id - 1] == my_processor) { |
| 1480 |
++owned; |
| 1481 |
} |
| 1482 |
} |
| 1483 |
ns->property_add(Ioss::Property("locally_owned_count", owned)); |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} |
| 1487 |
#endif |
| 1488 |
|
| 1489 |
void add_proc_id(Ioss::Region ®ion, int rank) |
| 1490 |
{ |
| 1491 |
region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 1492 |
const auto &sblocks = region.get_structured_blocks(); |
| 1493 |
for (const auto &sb : sblocks) { |
| 1494 |
sb->field_add( |
| 1495 |
Ioss::Field("processor_id", Ioss::Field::REAL, "scalar", Ioss::Field::TRANSIENT)); |
| 1496 |
} |
| 1497 |
|
| 1498 |
const auto &eblocks = region.get_element_blocks(); |
| 1499 |
for (const auto &eb : eblocks) { |
| 1500 |
eb->field_add( |
| 1501 |
Ioss::Field("processor_id", Ioss::Field::REAL, "scalar", Ioss::Field::TRANSIENT)); |
| 1502 |
} |
| 1503 |
region.end_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 1504 |
|
| 1505 |
region.begin_mode(Ioss::STATE_TRANSIENT); |
| 1506 |
|
| 1507 |
auto step = region.add_state(0.0); |
| 1508 |
region.begin_state(step); |
| 1509 |
|
| 1510 |
for (const auto &sb : sblocks) { |
| 1511 |
std::vector<double> proc_id(sb->entity_count(), rank); |
| 1512 |
sb->put_field_data("processor_id", proc_id); |
| 1513 |
} |
| 1514 |
|
| 1515 |
for (const auto &eb : eblocks) { |
| 1516 |
std::vector<double> proc_id(eb->entity_count(), rank); |
| 1517 |
eb->put_field_data("processor_id", proc_id); |
| 1518 |
} |
| 1519 |
|
| 1520 |
region.end_state(step); |
| 1521 |
region.end_mode(Ioss::STATE_TRANSIENT); |
| 1522 |
} |
| 1523 |
} // namespace |