| 1 |
// Copyright(C) 1999-2023 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 "Ionit_Initializer.h" |
| 8 |
#include "Ioss_CodeTypes.h" |
| 9 |
#include "Ioss_FileInfo.h" |
| 10 |
#include "Ioss_Hex8.h" |
| 11 |
#include "Ioss_ParallelUtils.h" |
| 12 |
#include "Ioss_Utils.h" |
| 13 |
#include "cgns/Iocgns_Utils.h" |
| 14 |
#include <cassert> |
| 15 |
#include <cstdlib> |
| 16 |
#include <fmt/core.h> |
| 17 |
#include <fmt/format.h> |
| 18 |
#include <stdio.h> |
| 19 |
#include <string> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
#include "Ioss_DBUsage.h" |
| 23 |
#include "Ioss_DatabaseIO.h" |
| 24 |
#include "Ioss_ElementBlock.h" |
| 25 |
#include "Ioss_ElementTopology.h" |
| 26 |
#include "Ioss_EntityBlock.h" |
| 27 |
#include "Ioss_EntityType.h" |
| 28 |
#include "Ioss_Field.h" |
| 29 |
#include "Ioss_GroupingEntity.h" |
| 30 |
#include "Ioss_IOFactory.h" |
| 31 |
#include "Ioss_MeshType.h" |
| 32 |
#include "Ioss_NodeBlock.h" |
| 33 |
#include "Ioss_Property.h" |
| 34 |
#include "Ioss_PropertyManager.h" |
| 35 |
#include "Ioss_Region.h" |
| 36 |
#include "Ioss_ScopeGuard.h" |
| 37 |
#include "Ioss_SideBlock.h" |
| 38 |
#include "Ioss_SideSet.h" |
| 39 |
#include "Ioss_State.h" |
| 40 |
#include "Ioss_StructuredBlock.h" |
| 41 |
#include "Ioss_VariableType.h" |
| 42 |
|
| 43 |
namespace { |
| 44 |
|
| 45 |
int rank = 0; |
| 46 |
|
| 47 |
void show_step(int istep, double time); |
| 48 |
|
| 49 |
void transfer_nodal(const Ioss::Region ®ion, Ioss::Region &output_region); |
| 50 |
void transfer_connectivity(Ioss::Region ®ion, Ioss::Region &output_region); |
| 51 |
void output_sidesets(Ioss::Region ®ion, Ioss::Region &output_region); |
| 52 |
|
| 53 |
void transfer_nodeblock(Ioss::Region ®ion, Ioss::Region &output_region); |
| 54 |
void transfer_elementblocks(Ioss::Region ®ion, Ioss::Region &output_region); |
| 55 |
void transfer_sidesets(Ioss::Region ®ion, Ioss::Region &output_region); |
| 56 |
void create_unstructured(const std::string &inpfile, const std::string &outfile); |
| 57 |
|
| 58 |
void transfer_sb_fields(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 59 |
Ioss::Field::RoleType role); |
| 60 |
void transfer_nb_fields(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 61 |
Ioss::Field::RoleType role); |
| 62 |
|
| 63 |
template <typename T> |
| 64 |
void transfer_fields(const std::vector<T *> &entities, Ioss::Region &output_region, |
| 65 |
Ioss::Field::RoleType role); |
| 66 |
|
| 67 |
void transfer_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 68 |
Ioss::Field::RoleType role); |
| 69 |
|
| 70 |
void transfer_sb_field_data(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 71 |
Ioss::Field::RoleType role); |
| 72 |
void transfer_nb_field_data(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 73 |
Ioss::Field::RoleType role); |
| 74 |
|
| 75 |
void transfer_coord(std::vector<double> &to, std::vector<double> &from, |
| 76 |
std::vector<size_t> &node_id_list) |
| 77 |
{ |
| 78 |
assert(from.empty() || !node_id_list.empty()); |
| 79 |
assert(from.size() == node_id_list.size()); |
| 80 |
for (size_t i = 0; i < from.size(); i++) { |
| 81 |
size_t idx = node_id_list[i]; |
| 82 |
to[idx] = from[i]; |
| 83 |
} |
| 84 |
} |
| 85 |
} // namespace |
| 86 |
// ======================================================================== |
| 87 |
|
| 88 |
namespace { |
| 89 |
std::string codename; |
| 90 |
std::string version = "5.01"; |
| 91 |
} // namespace |
| 92 |
|
| 93 |
int main(int argc, char *argv[]) |
| 94 |
{ |
| 95 |
#ifdef SEACAS_HAVE_MPI |
| 96 |
MPI_Init(&argc, &argv); |
| 97 |
ON_BLOCK_EXIT(MPI_Finalize); |
| 98 |
#endif |
| 99 |
Ioss::ParallelUtils pu{}; |
| 100 |
rank = pu.parallel_rank(); |
| 101 |
|
| 102 |
if (argc <= 2) { |
| 103 |
if (rank == 0) { |
| 104 |
fmt::print(stderr, "ERROR: Syntax is {} {{structured_input}} {{unstructured_output}}\n", |
| 105 |
argv[0]); |
| 106 |
} |
| 107 |
return EXIT_FAILURE; |
| 108 |
} |
| 109 |
|
| 110 |
Ioss::Init::Initializer io; |
| 111 |
std::string in_file = argv[1]; |
| 112 |
std::string out_file = argv[2]; |
| 113 |
|
| 114 |
if (rank == 0) { |
| 115 |
fmt::print(stderr, |
| 116 |
"Structured Input: '{}'\n" |
| 117 |
"Unstructured Output: '{}'\n\n", |
| 118 |
in_file, out_file); |
| 119 |
} |
| 120 |
double begin = Ioss::Utils::timer(); |
| 121 |
create_unstructured(in_file, out_file); |
| 122 |
double end = Ioss::Utils::timer(); |
| 123 |
|
| 124 |
codename = Ioss::FileInfo(argv[0]).basename(); |
| 125 |
if (rank == 0) { |
| 126 |
fmt::print(stderr, "\n\tElapsed time = {:.2f} seconds.\n", end - begin); |
| 127 |
fmt::print(stderr, "\n{} execution successful.\n", codename); |
| 128 |
} |
| 129 |
return EXIT_SUCCESS; |
| 130 |
} |
| 131 |
|
| 132 |
namespace { |
| 133 |
void create_unstructured(const std::string &inpfile, const std::string &outfile) |
| 134 |
{ |
| 135 |
Ioss::PropertyManager properties{}; |
| 136 |
Ioss::DatabaseIO *dbi = Ioss::IOFactory::create("cgns", inpfile, Ioss::READ_MODEL, |
| 137 |
Ioss::ParallelUtils::comm_world(), properties); |
| 138 |
if (dbi == nullptr || !dbi->ok(true)) { |
| 139 |
std::exit(EXIT_FAILURE); |
| 140 |
} |
| 141 |
|
| 142 |
// NOTE: 'region' owns 'db' pointer at this time... |
| 143 |
Ioss::Region region(dbi, "region_1"); |
| 144 |
|
| 145 |
if (region.mesh_type() != Ioss::MeshType::STRUCTURED) { |
| 146 |
int myProcessor = region.get_database()->util().parallel_rank(); |
| 147 |
if (myProcessor == 0) { |
| 148 |
fmt::print(stderr, "\nERROR: The input mesh is not of type STRUCTURED.\n"); |
| 149 |
} |
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
//======================================================================== |
| 154 |
// OUTPUT ... |
| 155 |
//======================================================================== |
| 156 |
#if 0 |
| 157 |
if (dbi->util().parallel_size() > 1) { |
| 158 |
properties.add(Ioss::Property("COMPOSE_RESTART", "YES")); |
| 159 |
} |
| 160 |
#endif |
| 161 |
|
| 162 |
Ioss::DatabaseIO *dbo = Ioss::IOFactory::create("exodus", outfile, Ioss::WRITE_RESTART, |
| 163 |
Ioss::ParallelUtils::comm_world(), properties); |
| 164 |
if (dbo == nullptr || !dbo->ok(true)) { |
| 165 |
std::exit(EXIT_FAILURE); |
| 166 |
} |
| 167 |
|
| 168 |
// NOTE: 'output_region' owns 'dbo' pointer at this time |
| 169 |
Ioss::Region output_region(dbo, "region_2"); |
| 170 |
// Set the qa information... |
| 171 |
output_region.property_add(Ioss::Property(std::string("code_name"), codename)); |
| 172 |
output_region.property_add(Ioss::Property(std::string("code_version"), version)); |
| 173 |
|
| 174 |
if (!output_region.begin_mode(Ioss::STATE_DEFINE_MODEL)) { |
| 175 |
if (rank == 0) { |
| 176 |
fmt::print(stderr, "ERROR: Could not put output region into define model state\n"); |
| 177 |
} |
| 178 |
std::exit(EXIT_FAILURE); |
| 179 |
} |
| 180 |
|
| 181 |
transfer_nodeblock(region, output_region); |
| 182 |
transfer_elementblocks(region, output_region); |
| 183 |
transfer_sidesets(region, output_region); |
| 184 |
|
| 185 |
output_region.end_mode(Ioss::STATE_DEFINE_MODEL); |
| 186 |
|
| 187 |
// Model defined, now fill in the model data... |
| 188 |
output_region.begin_mode(Ioss::STATE_MODEL); |
| 189 |
|
| 190 |
transfer_connectivity(region, output_region); |
| 191 |
transfer_nodal(region, output_region); |
| 192 |
output_sidesets(region, output_region); |
| 193 |
output_region.end_mode(Ioss::STATE_MODEL); |
| 194 |
|
| 195 |
int step_count = region.get_optional_property("state_count", 0); |
| 196 |
if (step_count > 0) { |
| 197 |
if (rank == 0) { |
| 198 |
fmt::print(stderr, "\n Number of time steps on database = {:12}\n\n", |
| 199 |
fmt::group_digits(step_count)); |
| 200 |
} |
| 201 |
|
| 202 |
output_region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 203 |
|
| 204 |
// For each 'TRANSIENT' field in the node blocks and element |
| 205 |
// blocks, transfer to the output node and element blocks. |
| 206 |
transfer_fields(®ion, &output_region, Ioss::Field::TRANSIENT); |
| 207 |
transfer_sb_fields(region, output_region, Ioss::Field::TRANSIENT); |
| 208 |
transfer_nb_fields(region, output_region, Ioss::Field::TRANSIENT); |
| 209 |
|
| 210 |
output_region.end_mode(Ioss::STATE_DEFINE_TRANSIENT); |
| 211 |
|
| 212 |
output_region.begin_mode(Ioss::STATE_TRANSIENT); |
| 213 |
// Get the timesteps from the input database. Step through them |
| 214 |
// and transfer fields to output database... |
| 215 |
|
| 216 |
for (int istep = 1; istep <= step_count; istep++) { |
| 217 |
double time = region.get_state_time(istep); |
| 218 |
|
| 219 |
int ostep = output_region.add_state(time); |
| 220 |
show_step(istep, time); |
| 221 |
|
| 222 |
output_region.begin_state(ostep); |
| 223 |
region.begin_state(istep); |
| 224 |
|
| 225 |
transfer_nb_field_data(region, output_region, Ioss::Field::TRANSIENT); |
| 226 |
transfer_sb_field_data(region, output_region, Ioss::Field::TRANSIENT); |
| 227 |
|
| 228 |
region.end_state(istep); |
| 229 |
output_region.end_state(ostep); |
| 230 |
} |
| 231 |
output_region.end_mode(Ioss::STATE_TRANSIENT); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
void transfer_nodal(const Ioss::Region ®ion, Ioss::Region &output_region) |
| 236 |
{ |
| 237 |
size_t num_nodes = region.get_node_blocks()[0]->entity_count(); |
| 238 |
const auto &nb = output_region.get_node_blocks()[0]; |
| 239 |
assert(nb != nullptr); |
| 240 |
|
| 241 |
if (!output_region.get_database()->needs_shared_node_information()) { |
| 242 |
std::vector<int> ids(num_nodes); // To hold the global node id map. |
| 243 |
const auto &blocks = region.get_structured_blocks(); |
| 244 |
for (const auto &block : blocks) { |
| 245 |
std::vector<int> cell_id; |
| 246 |
block->get_field_data("cell_node_ids", cell_id); |
| 247 |
|
| 248 |
for (size_t i = 0; i < cell_id.size(); i++) { |
| 249 |
size_t idx = block->m_blockLocalNodeIndex[i]; |
| 250 |
assert(idx < num_nodes); |
| 251 |
if (ids[idx] == 0) { |
| 252 |
ids[idx] = cell_id[i]; |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
nb->put_field_data("ids", ids); |
| 257 |
} |
| 258 |
|
| 259 |
std::vector<double> coordinate_x(num_nodes); |
| 260 |
std::vector<double> coordinate_y(num_nodes); |
| 261 |
std::vector<double> coordinate_z(num_nodes); |
| 262 |
|
| 263 |
const auto &blocks = region.get_structured_blocks(); |
| 264 |
for (const auto &block : blocks) { |
| 265 |
std::vector<double> coord_tmp; |
| 266 |
block->get_field_data("mesh_model_coordinates_x", coord_tmp); |
| 267 |
transfer_coord(coordinate_x, coord_tmp, block->m_blockLocalNodeIndex); |
| 268 |
|
| 269 |
block->get_field_data("mesh_model_coordinates_y", coord_tmp); |
| 270 |
transfer_coord(coordinate_y, coord_tmp, block->m_blockLocalNodeIndex); |
| 271 |
|
| 272 |
block->get_field_data("mesh_model_coordinates_z", coord_tmp); |
| 273 |
transfer_coord(coordinate_z, coord_tmp, block->m_blockLocalNodeIndex); |
| 274 |
} |
| 275 |
|
| 276 |
nb->put_field_data("mesh_model_coordinates_x", coordinate_x); |
| 277 |
nb->put_field_data("mesh_model_coordinates_y", coordinate_y); |
| 278 |
nb->put_field_data("mesh_model_coordinates_z", coordinate_z); |
| 279 |
} |
| 280 |
|
| 281 |
void transfer_connectivity(Ioss::Region ®ion, Ioss::Region &output_region) |
| 282 |
{ |
| 283 |
const auto &blocks = region.get_structured_blocks(); |
| 284 |
for (const auto &block : blocks) { |
| 285 |
// We have a structured block of size ni x nj x nk. |
| 286 |
// Need to convert that to element connectivity |
| 287 |
// Node numbers are zero-based offset into this structured block |
| 288 |
// After generated, then map zero-based block-local into one-based global. |
| 289 |
// Since we are outputting "connectivity_raw", there is no difference |
| 290 |
// in parallel or serial. |
| 291 |
|
| 292 |
size_t ni = block->get_property("ni").get_int(); |
| 293 |
size_t nj = block->get_property("nj").get_int(); |
| 294 |
size_t nk = block->get_property("nk").get_int(); |
| 295 |
|
| 296 |
size_t xp1yp1 = (ni + 1) * (nj + 1); |
| 297 |
|
| 298 |
// Find matching element block in output region... |
| 299 |
const auto &name = block->name(); |
| 300 |
auto *output = output_region.get_element_block(name); |
| 301 |
assert(output != nullptr); |
| 302 |
|
| 303 |
{ |
| 304 |
std::vector<int> connect; |
| 305 |
connect.reserve(ni * nj * nk * 8); |
| 306 |
for (size_t k = 0; k < nk; k++) { |
| 307 |
for (size_t j = 0, m = 0; j < nj; j++) { |
| 308 |
for (size_t i = 0; i < ni; i++, m++) { |
| 309 |
size_t base = (k * xp1yp1) + m + j; |
| 310 |
|
| 311 |
connect.push_back(base); |
| 312 |
connect.push_back(base + 1); |
| 313 |
connect.push_back(base + ni + 2); |
| 314 |
connect.push_back(base + ni + 1); |
| 315 |
|
| 316 |
connect.push_back(xp1yp1 + base); |
| 317 |
connect.push_back(xp1yp1 + base + 1); |
| 318 |
connect.push_back(xp1yp1 + base + ni + 2); |
| 319 |
connect.push_back(xp1yp1 + base + ni + 1); |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
// 'connect' contains 0-based block-local node ids at this point |
| 324 |
// Now, map them to processor-global values... |
| 325 |
// NOTE: "processor-global" is 1..num_node_on_processor |
| 326 |
if (!connect.empty()) { |
| 327 |
const auto &gnil = block->m_blockLocalNodeIndex; |
| 328 |
assert(!gnil.empty()); |
| 329 |
for (int &i : connect) { |
| 330 |
i = gnil[i] + 1; |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
output->put_field_data("connectivity_raw", connect); |
| 335 |
} |
| 336 |
|
| 337 |
{ |
| 338 |
std::vector<int> ids; |
| 339 |
block->get_field_data("cell_ids", ids); |
| 340 |
output->put_field_data("ids", ids); |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
void output_sidesets(Ioss::Region ®ion, Ioss::Region &output_region) |
| 346 |
{ |
| 347 |
// Maps the 'parent_face'+1 returned from which_face() |
| 348 |
// to the local 1-based face of the hex elements in that block. |
| 349 |
static const int face_map[] = {4, 1, 5, 2, 3, 6}; |
| 350 |
|
| 351 |
const auto &ssets = region.get_sidesets(); |
| 352 |
for (const auto &ss : ssets) { |
| 353 |
// Get corresponding sidset on output region... |
| 354 |
const auto *ofs = output_region.get_sideset(ss->name()); |
| 355 |
assert(ofs != nullptr); |
| 356 |
|
| 357 |
const auto &fbs = ss->get_side_blocks(); |
| 358 |
size_t fb_index = 0; |
| 359 |
for (const auto &fb : fbs) { |
| 360 |
// Get corresponding sideblock on output sideset 'ofs' |
| 361 |
// Assumes sideblocks are ordered the same on input and output. |
| 362 |
auto ofb = ofs->get_block(fb_index++); |
| 363 |
assert(ofb != nullptr); |
| 364 |
|
| 365 |
// Get parent structured block for this side block... |
| 366 |
auto parent = fb->parent_block(); |
| 367 |
assert(parent != nullptr); |
| 368 |
assert(parent->type() == Ioss::STRUCTUREDBLOCK); |
| 369 |
auto sb_parent = dynamic_cast<const Ioss::StructuredBlock *>(parent); |
| 370 |
Ioss::Utils::check_dynamic_cast(sb_parent); |
| 371 |
|
| 372 |
// Find this sideblock on the parent block... |
| 373 |
const auto &bc_name = fb->name(); |
| 374 |
for (const auto &bc : sb_parent->m_boundaryConditions) { |
| 375 |
auto bc_compose = bc.m_bcName + "/" + sb_parent->name(); |
| 376 |
if (bc_name == bc_compose) { |
| 377 |
std::vector<int> elem_side; |
| 378 |
if (bc.get_face_count() > 0) { |
| 379 |
Ioss::IJK_t range_beg = bc.m_rangeBeg; |
| 380 |
Ioss::IJK_t cell_range_end = bc.m_rangeEnd; |
| 381 |
|
| 382 |
// The range_beg/end are current points and not cells. |
| 383 |
// Need to convert cell_range_end to cells which is typically just point-1 |
| 384 |
// except if the ordinal is the plane of this surface. In this case, |
| 385 |
// range_beg[ord] == cell_range_end[ord]. If this is the case, |
| 386 |
// and we are at the top end of the range, then the beg and end must |
| 387 |
// both be reduced by 1. If at the bottom end of the range, then both |
| 388 |
// are equal to 1. |
| 389 |
// |
| 390 |
for (int i = 0; i < 3; i++) { |
| 391 |
if (cell_range_end[i] == range_beg[i]) { |
| 392 |
if (cell_range_end[i] != 1) { |
| 393 |
cell_range_end[i]--; |
| 394 |
range_beg[i]--; |
| 395 |
} |
| 396 |
} |
| 397 |
else { |
| 398 |
cell_range_end[i]--; |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
#if IOSS_DEBUG_OUTPUT |
| 403 |
fmt::print(stderr, "{}\n", bc); |
| 404 |
#endif |
| 405 |
auto parent_face = face_map[bc.which_face()]; |
| 406 |
elem_side.reserve(bc.get_face_count() * 2); |
| 407 |
for (auto k = range_beg[2]; k <= cell_range_end[2]; k++) { |
| 408 |
for (auto j = range_beg[1]; j <= cell_range_end[1]; j++) { |
| 409 |
for (auto i = range_beg[0]; i <= cell_range_end[0]; i++) { |
| 410 |
auto cell_id = sb_parent->get_global_cell_id(i, j, k); |
| 411 |
assert(cell_id > 0); |
| 412 |
elem_side.push_back(cell_id); |
| 413 |
elem_side.push_back(parent_face); |
| 414 |
} |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
ofb->put_field_data("element_side", elem_side); |
| 419 |
break; |
| 420 |
} |
| 421 |
} |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
void transfer_nodeblock(Ioss::Region ®ion, Ioss::Region &output_region) |
| 427 |
{ |
| 428 |
const auto &nbs = region.get_node_blocks(); |
| 429 |
assert(nbs.size() == 1); |
| 430 |
size_t degree = nbs[0]->get_property("component_degree").get_int(); |
| 431 |
size_t num_nodes = nbs[0]->entity_count(); |
| 432 |
auto nb = new Ioss::NodeBlock(output_region.get_database(), nbs[0]->name(), num_nodes, degree); |
| 433 |
output_region.add(nb); |
| 434 |
|
| 435 |
if (output_region.get_database()->needs_shared_node_information()) { |
| 436 |
std::vector<int> ids(num_nodes); // To hold the global node id map. |
| 437 |
const auto &blocks = region.get_structured_blocks(); |
| 438 |
for (const auto &block : blocks) { |
| 439 |
std::vector<int> cell_id; |
| 440 |
block->get_field_data("cell_node_ids", cell_id); |
| 441 |
|
| 442 |
for (size_t i = 0; i < cell_id.size(); i++) { |
| 443 |
size_t idx = block->m_blockLocalNodeIndex[i]; |
| 444 |
assert(idx < num_nodes); |
| 445 |
if (ids[idx] == 0) { |
| 446 |
ids[idx] = cell_id[i]; |
| 447 |
} |
| 448 |
} |
| 449 |
} |
| 450 |
assert(nb != nullptr); |
| 451 |
nb->put_field_data("ids", ids); |
| 452 |
|
| 453 |
// Each structured block on the incoming mesh has a list of the nodes it shares with |
| 454 |
// other blocks. Use this to construct the "node owning |
| 455 |
// processor" information. Assume that if a node is shared with |
| 456 |
// a lower-numbered processor, then that processor owns the |
| 457 |
// node... |
| 458 |
|
| 459 |
auto shared_nodes = Iocgns::Utils::resolve_processor_shared_nodes( |
| 460 |
region, region.get_database()->util().parallel_rank()); |
| 461 |
|
| 462 |
int myProcessor = output_region.get_database()->util().parallel_rank(); |
| 463 |
std::vector<int> owning_processor(num_nodes, myProcessor); |
| 464 |
for (const auto &block : blocks) { |
| 465 |
int zone = block->get_property("zone").get_int(); |
| 466 |
for (const auto &shared : shared_nodes[zone]) { |
| 467 |
size_t idx = block->m_blockLocalNodeIndex[shared.first]; |
| 468 |
if (owning_processor[idx] > (int)shared.second) { |
| 469 |
owning_processor[idx] = shared.second; |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
nb->put_field_data("owning_processor", owning_processor); |
| 474 |
} |
| 475 |
|
| 476 |
fmt::print("P[{}] Number of coordinates per node = {:12}\n", rank, fmt::group_digits(degree)); |
| 477 |
fmt::print("P[{}] Number of nodes = {:12}\n", rank, |
| 478 |
fmt::group_digits(num_nodes)); |
| 479 |
} |
| 480 |
|
| 481 |
void transfer_elementblocks(Ioss::Region ®ion, Ioss::Region &output_region) |
| 482 |
{ |
| 483 |
const auto &blocks = region.get_structured_blocks(); |
| 484 |
size_t total_entities = 0; |
| 485 |
for (const auto &iblock : blocks) { |
| 486 |
const std::string &name = iblock->name(); |
| 487 |
std::string type = Ioss::Hex8::name; |
| 488 |
size_t count = iblock->get_property("cell_count").get_int(); |
| 489 |
auto block = new Ioss::ElementBlock(output_region.get_database(), name, type, count); |
| 490 |
output_region.add(block); |
| 491 |
#if IOSS_DEBUG_OUTPUT |
| 492 |
fmt::print(stderr, "P[{}] Created Element Block '{}' with {} elements.\n", rank, name, count); |
| 493 |
#endif |
| 494 |
total_entities += count; |
| 495 |
} |
| 496 |
fmt::print("P[{}] Number of Element Blocks = {:12}, Number of elements (cells) = {:12}\n", |
| 497 |
rank, fmt::group_digits(blocks.size()), fmt::group_digits(total_entities)); |
| 498 |
} |
| 499 |
|
| 500 |
void transfer_sidesets(Ioss::Region ®ion, Ioss::Region &output_region) |
| 501 |
{ |
| 502 |
size_t total_sides = 0; |
| 503 |
const auto &ssets = region.get_sidesets(); |
| 504 |
for (const auto &ss : ssets) { |
| 505 |
const std::string &name = ss->name(); |
| 506 |
|
| 507 |
int ss_sides = 0; |
| 508 |
auto surf = new Ioss::SideSet(output_region.get_database(), name); |
| 509 |
const Ioss::SideBlockContainer &fbs = ss->get_side_blocks(); |
| 510 |
for (const auto &fb : fbs) { |
| 511 |
const std::string &fbname = fb->name(); |
| 512 |
std::string fbtype = fb->topology()->name(); |
| 513 |
std::string partype = fb->parent_element_topology()->name(); |
| 514 |
size_t num_side = fb->entity_count(); |
| 515 |
total_sides += num_side; |
| 516 |
|
| 517 |
auto block = |
| 518 |
new Ioss::SideBlock(output_region.get_database(), fbname, fbtype, partype, num_side); |
| 519 |
surf->add(block); |
| 520 |
block->property_add(Ioss::Property("set_offset", ss_sides)); |
| 521 |
|
| 522 |
ss_sides += num_side; |
| 523 |
} |
| 524 |
output_region.add(surf); |
| 525 |
} |
| 526 |
fmt::print("P[{}] Number of SideSets = {:12}, Number of cell faces = {:12}\n", |
| 527 |
rank, fmt::group_digits(ssets.size()), fmt::group_digits(total_sides)); |
| 528 |
} |
| 529 |
|
| 530 |
void show_step(int istep, double time) |
| 531 |
{ |
| 532 |
if (rank == 0) { |
| 533 |
fmt::print(stderr, " Time step {:5d} at time {:.5e}\n", istep, time); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
void transfer_nb_fields(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 538 |
Ioss::Field::RoleType role) |
| 539 |
{ |
| 540 |
size_t num_nodes = region.get_node_blocks()[0]->entity_count(); |
| 541 |
const auto &onb = output_region.get_node_blocks()[0]; |
| 542 |
|
| 543 |
const auto &blocks = region.get_structured_blocks(); |
| 544 |
for (const auto &block : blocks) { |
| 545 |
const auto &nb = block->get_node_block(); |
| 546 |
Ioss::NameList fields = nb.field_describe(role); |
| 547 |
for (const auto &field_name : fields) { |
| 548 |
Ioss::Field field = nb.get_field(field_name); |
| 549 |
if (!onb->field_exists(field_name)) { |
| 550 |
field.reset_count(num_nodes); |
| 551 |
onb->field_add(field); |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
void transfer_sb_fields(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 558 |
Ioss::Field::RoleType role) |
| 559 |
{ |
| 560 |
const auto &nb = output_region.get_node_blocks()[0]; |
| 561 |
size_t num_nodes = region.get_node_blocks()[0]->entity_count(); |
| 562 |
const auto &blocks = region.get_structured_blocks(); |
| 563 |
for (const auto &block : blocks) { |
| 564 |
Ioss::NameList fields = block->field_describe(role); |
| 565 |
|
| 566 |
const auto &name = block->name(); |
| 567 |
auto *eblock = output_region.get_element_block(name); |
| 568 |
assert(eblock != nullptr); |
| 569 |
|
| 570 |
for (const auto &field_name : fields) { |
| 571 |
Ioss::Field field = block->get_field(field_name); |
| 572 |
bool cell_field = Iocgns::Utils::is_cell_field(field); |
| 573 |
if (cell_field) { |
| 574 |
eblock->field_add(field); |
| 575 |
} |
| 576 |
else { |
| 577 |
if (!nb->field_exists(field_name)) { |
| 578 |
field.reset_count(num_nodes); |
| 579 |
nb->field_add(field); |
| 580 |
} |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
void transfer_nb_field_data(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 587 |
Ioss::Field::RoleType role) |
| 588 |
{ |
| 589 |
const auto &onb = output_region.get_node_blocks()[0]; |
| 590 |
Ioss::NameList fields = onb->field_describe(role); |
| 591 |
|
| 592 |
for (const auto &field_name : fields) { |
| 593 |
assert(onb->field_exists(field_name)); |
| 594 |
const Ioss::Field &field = onb->get_field(field_name); |
| 595 |
const Ioss::VariableType *var_type = field.raw_storage(); |
| 596 |
size_t comp_count = var_type->component_count(); |
| 597 |
|
| 598 |
size_t num_nodes = region.get_node_blocks()[0]->entity_count(); |
| 599 |
std::vector<double> node_data(num_nodes * comp_count); |
| 600 |
|
| 601 |
const auto &blocks = region.get_structured_blocks(); |
| 602 |
for (const auto &block : blocks) { |
| 603 |
auto &nb = block->get_node_block(); |
| 604 |
if (nb.field_exists(field_name)) { |
| 605 |
std::vector<double> data; |
| 606 |
nb.get_field_data(field_name, data); |
| 607 |
const auto &node_id_list = block->m_blockLocalNodeIndex; |
| 608 |
assert(!node_id_list.empty()); |
| 609 |
|
| 610 |
for (size_t i = 0; i < node_id_list.size(); i++) { |
| 611 |
size_t node = node_id_list[i]; |
| 612 |
assert(node < num_nodes); |
| 613 |
for (size_t j = 0; j < comp_count; j++) { |
| 614 |
node_data[comp_count * node + j] = data[comp_count * i + j]; |
| 615 |
} |
| 616 |
} |
| 617 |
} |
| 618 |
} |
| 619 |
onb->put_field_data(field_name, node_data); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
void transfer_sb_field_data(const Ioss::Region ®ion, Ioss::Region &output_region, |
| 624 |
Ioss::Field::RoleType role) |
| 625 |
{ |
| 626 |
const auto &blocks = region.get_structured_blocks(); |
| 627 |
for (const auto &block : blocks) { |
| 628 |
Ioss::NameList fields = block->field_describe(role); |
| 629 |
|
| 630 |
for (const auto &field_name : fields) { |
| 631 |
const Ioss::Field &field = block->get_field(field_name); |
| 632 |
if (Iocgns::Utils::is_cell_field(field)) { |
| 633 |
std::vector<double> data; |
| 634 |
block->get_field_data(field_name, data); |
| 635 |
|
| 636 |
const auto &name = block->name(); |
| 637 |
auto *eblock = output_region.get_element_block(name); |
| 638 |
assert(eblock != nullptr); |
| 639 |
eblock->put_field_data(field_name, data); |
| 640 |
} |
| 641 |
} |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
void transfer_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge, |
| 646 |
Ioss::Field::RoleType role) |
| 647 |
{ |
| 648 |
// Check for transient fields... |
| 649 |
Ioss::NameList fields = ige->field_describe(role); |
| 650 |
|
| 651 |
// Iterate through results fields and transfer to output |
| 652 |
// database... |
| 653 |
for (const auto &field_name : fields) { |
| 654 |
const Ioss::Field &field = ige->get_field(field_name); |
| 655 |
if (field_name != "ids" && !oge->field_exists(field_name)) { |
| 656 |
oge->field_add(field); |
| 657 |
} |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
} // namespace |