Debian Codegraph @

packages/seacas/libraries/ioss/src/main/io_shell_ts.C

raw
1 // Copyright(C) 1999-2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include <algorithm>
8 #include <cassert>
9 #include <cstddef>
10 #include <cstdlib>
11 #include <cstring>
12 #include <fmt/format.h>
13 #include <iomanip>
14 #include <iostream>
15 #include <pthread.h>
16 #include <string>
17 #include <unistd.h>
18 #include <vector>
19
20 #include "Ionit_Initializer.h"
21 #include "Ioss_CodeTypes.h"
22 #include "Ioss_DataPool.h"
23 #include "Ioss_FileInfo.h"
24 #include "Ioss_MemoryUtils.h"
25 #include "Ioss_MeshType.h"
26 #include "Ioss_ParallelUtils.h"
27 #include "Ioss_ScopeGuard.h"
28 #include "Ioss_SerializeIO.h"
29 #include "Ioss_SubSystem.h"
30 #include "Ioss_SurfaceSplit.h"
31 #include "Ioss_Transform.h"
32 #include "Ioss_Utils.h"
33
34 #include "shell_interface.h"
35
36 #define DO_OUTPUT \
37 if (rank == 0) \
38 std::cerr
39
40 // ========================================================================
41
42 namespace {
43 int rank = 0;
44 bool mem_stats = false;
45
46 void show_step(int istep, double time);
47
48 void transfer_nodeblock(Ioss::Region &region, Ioss::Region &output_region, bool debug);
49 void transfer_elementblocks(Ioss::Region &region, Ioss::Region &output_region, bool debug);
50 void transfer_edgeblocks(Ioss::Region &region, Ioss::Region &output_region, bool debug);
51 void transfer_faceblocks(Ioss::Region &region, Ioss::Region &output_region, bool debug);
52 void transfer_nodesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
53 void transfer_edgesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
54 void transfer_facesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
55 void transfer_elemsets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
56 void transfer_sidesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
57 void transfer_commsets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
58 void transfer_coordinate_frames(Ioss::Region &region, Ioss::Region &output_region, bool debug);
59
60 template <typename T>
61 void transfer_fields(const std::vector<T *> &entities, Ioss::Region &output_region,
62 Ioss::Field::RoleType role, const IOShell::Interface &interFace);
63
64 void transfer_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
65 Ioss::Field::RoleType role, const std::string &prefix = "");
66
67 template <typename T>
68 void transfer_field_data(const std::vector<T *> &entities, Ioss::Region &output_region,
69 Ioss::Field::RoleType role, const IOShell::Interface &interFace);
70
71 void transfer_field_data(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
72 Ioss::Field::RoleType role, const IOShell::Interface &interFace,
73 const std::string &prefix = "");
74
75 void transfer_properties(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge);
76
77 void transfer_qa_info(Ioss::Region &in, Ioss::Region &out);
78
79 void transform_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
80 Ioss::Field::RoleType role);
81
82 void transform_field_data(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
83 Ioss::Field::RoleType role, const IOShell::Interface &interFace);
84 void transfer_field_data_internal(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
85 const std::string &field_name,
86 const IOShell::Interface &interFace);
87
88 void file_copy(IOShell::Interface &interFace, int rank);
89
90 Ioss::PropertyManager set_properties(IOShell::Interface &interFace);
91
92 template <typename INT>
93 void set_owned_node_count(Ioss::Region &region, int my_processor, INT dummy);
94
95 bool open_change_set(const std::string &cs_name, Ioss::Region &region, int my_rank)
96 {
97 bool success = true;
98 if (!cs_name.empty()) {
99 success = region.load_internal_change_set_mesh(cs_name);
100 if (!success) {
101 if (my_rank == 0) {
102 fmt::print(stderr, "ERROR: Unable to open change_set '{}' in file '{}'\n", cs_name,
103 region.get_database()->get_filename());
104 }
105 }
106 }
107 return success;
108 }
109
110 } // namespace
111 // ========================================================================
112
113 namespace {
114 std::string codename;
115 std::string version = "4.7";
116 } // namespace
117
118 int main(int argc, char *argv[])
119 {
120 #ifdef SEACAS_HAVE_MPI
121 MPI_Init(&argc, &argv);
122 ON_BLOCK_EXIT(MPI_Finalize);
123 #endif
124 Ioss::ParallelUtils pu{};
125 rank = pu.parallel_rank();
126 int num_proc = pu.parallel_size();
127
128 #ifdef SEACAS_HAVE_KOKKOS
129 Kokkos::ScopeGuard kokkos(argc, argv);
130 #endif
131
132 IOShell::Interface interFace(version);
133 bool success = interFace.parse_options(argc, argv, rank);
134 if (!success) {
135 exit(EXIT_FAILURE);
136 }
137
138 Ioss::SerializeIO::setGroupFactor(interFace.serialize_io_size);
139 mem_stats = interFace.memory_statistics;
140
141 Ioss::Init::Initializer io;
142
143 std::string in_file = interFace.inputFile[0];
144 std::string out_file = interFace.outputFile;
145
146 if (rank == 0 && !interFace.quiet) {
147 fmt::print(stderr,
148 "Input: '{}', Type: {}\n"
149 "Output: '{}', Type: {}\n\n",
150 in_file, interFace.inFiletype, out_file, interFace.outFiletype);
151 }
152
153 #ifdef SEACAS_HAVE_KOKKOS
154 if (rank == 0)
155 fmt::print(stderr, "Kokkos default execution space configuration:\n");
156 Kokkos::DefaultExecutionSpace().print_configuration(std::cerr, false);
157 if (rank == 0)
158 fmt::print(stderr, "\n");
159 #endif
160
161 double begin = Ioss::Utils::timer();
162 file_copy(interFace, rank);
163 double end = Ioss::Utils::timer();
164
165 if (rank == 0 && !interFace.quiet) {
166 if (num_proc > 1) {
167 fmt::print(stderr, "\n\n\tTotal Execution Time = {:.5} seconds on {} processors.\n",
168 end - begin, num_proc);
169 }
170 else {
171 fmt::print(stderr, "\n\n\tTotal Execution Time = {:.5} seconds.\n", end - begin);
172 }
173 }
174
175 if (mem_stats) {
176 int64_t MiB = 1024 * 1024;
177 #ifdef SEACAS_HAVE_MPI
178 int64_t min, max, avg;
179 int64_t hwmin, hwmax, hwavg;
180 pu.memory_stats(min, max, avg);
181 pu.hwm_memory_stats(hwmin, hwmax, hwavg);
182 if (rank == 0) {
183 fmt::print(stderr, "\n\tCurrent Memory: {}M {}M {}M\n", fmt::group_digits(min / MiB),
184 fmt::group_digits(max / MiB), fmt::group_digits(avg / MiB));
185 fmt::print(stderr, "\tHigh Water Memory: {}M {}M {}M\n", fmt::group_digits(hwmin / MiB),
186 fmt::group_digits(hwmax / MiB), fmt::group_digits(hwavg / MiB));
187 }
188 #else
189 int64_t mem = Ioss::MemoryUtils::get_memory_info();
190 int64_t hwm = Ioss::MemoryUtils::get_hwm_memory_info();
191 if (rank == 0) {
192 fmt::print(stderr,
193 "\n\tCurrent Memory: {}M\n"
194 "\tHigh Water Memory: {}M\n",
195 fmt::group_digits(mem / MiB), fmt::group_digits(hwm / MiB));
196 }
197 #endif
198 }
199 if (rank == 0) {
200 fmt::print(stderr, "\n{} execution successful.\n", codename);
201 }
202
203 return EXIT_SUCCESS;
204 }
205
206 namespace {
207 void file_copy(IOShell::Interface &interFace, int my_rank)
208 {
209 Ioss::PropertyManager properties = set_properties(interFace);
210
211 for (const auto &inpfile : interFace.inputFile) {
212 Ioss::DatabaseIO *dbi =
213 Ioss::IOFactory::create(interFace.inFiletype, inpfile, Ioss::READ_MODEL,
214 Ioss::ParallelUtils::comm_world(), properties);
215 if (dbi == nullptr || !dbi->ok(true)) {
216 std::exit(EXIT_FAILURE);
217 }
218 dbi->set_parallel_consistency(false);
219
220 if (mem_stats) {
221 dbi->progress("Database Creation");
222 }
223 if (!interFace.lower_case_variable_names) {
224 dbi->set_lower_case_variable_names(false);
225 }
226 dbi->set_surface_split_type(Ioss::int_to_surface_split(interFace.surface_split_type));
227 dbi->set_field_separator(interFace.fieldSuffixSeparator);
228 if (interFace.ints_64_bit) {
229 dbi->set_int_byte_size_api(Ioss::USE_INT64_API);
230 }
231
232 // NOTE: 'region' owns 'db' pointer at this time...
233 Ioss::Region region(dbi, "region_1");
234
235 if (!interFace.changeSetName.empty()) {
236 bool success = open_change_set(interFace.changeSetName, region, my_rank);
237 if (!success) {
238 if (my_rank == 0) {
239 fmt::print(stderr, "ERROR: Unable to open group '{}' in file '{}'\n",
240 interFace.changeSetName, inpfile);
241 }
242 return;
243 }
244 }
245
246 if (region.mesh_type() != Ioss::MeshType::UNSTRUCTURED) {
247 if (my_rank == 0) {
248 fmt::print(stderr,
249 "\nERROR: io_shell does not support '{}' meshes. Only 'Unstructured' mesh is "
250 "supported at this time.\n",
251 region.mesh_type_string());
252 }
253 return;
254 }
255
256 // Get length of longest name on input file...
257 int max_name_length = dbi->maximum_symbol_length();
258 if (max_name_length > 0) {
259 properties.add(Ioss::Property("MAXIMUM_NAME_LENGTH", max_name_length));
260 }
261
262 // Get integer size being used on the input file and propagate
263 // to output file...
264 int int_byte_size_api = dbi->int_byte_size_api();
265 if (!properties.exists("INTEGER_SIZE_API")) {
266 if (interFace.ints_32_bit) {
267 properties.add(Ioss::Property("INTEGER_SIZE_DB", 4));
268 }
269 else {
270 properties.add(Ioss::Property("INTEGER_SIZE_DB", int_byte_size_api));
271 }
272 properties.add(Ioss::Property("INTEGER_SIZE_API", int_byte_size_api));
273 }
274 if (int_byte_size_api == 8) {
275 interFace.ints_64_bit = true;
276 }
277 //========================================================================
278 // OUTPUT ...
279 //========================================================================
280 Ioss::DatabaseIO *dbo =
281 Ioss::IOFactory::create(interFace.outFiletype, interFace.outputFile, Ioss::WRITE_RESTART,
282 Ioss::ParallelUtils::comm_world(), properties);
283 if (dbo == nullptr || !dbo->ok(true)) {
284 std::exit(EXIT_FAILURE);
285 }
286 dbo->set_parallel_consistency(false);
287
288 // NOTE: 'output_region' owns 'dbo' pointer at this time
289 Ioss::Region output_region(dbo, "region_2");
290 // Set the qa information...
291 output_region.property_add(Ioss::Property(std::string("code_name"), codename));
292 output_region.property_add(Ioss::Property(std::string("code_version"), version));
293
294 if (interFace.inputFile.size() > 1) {
295 properties.add(Ioss::Property("APPEND_OUTPUT", Ioss::DB_APPEND_GROUP));
296
297 // Putting each file into its own output group...
298 // The name of the group will be the basename portion of the filename...
299 Ioss::FileInfo file(inpfile);
300 dbo->create_internal_change_set(file.tailname());
301 }
302
303 if (interFace.debug) {
304 DO_OUTPUT << "DEFINING MODEL ... \n";
305 }
306 if (mem_stats) {
307 dbi->progress("DEFINING MODEL");
308 }
309 if (!output_region.begin_mode(Ioss::STATE_DEFINE_MODEL)) {
310 DO_OUTPUT << "ERROR: Could not put output region into define model state\n";
311 std::exit(EXIT_FAILURE);
312 }
313
314 // Get all properties of input database...
315 transfer_properties(&region, &output_region);
316 transfer_qa_info(region, output_region);
317
318 transfer_nodeblock(region, output_region, interFace.debug);
319
320 // This also assumes that the node order and count is the same for input
321 // and output regions... (This is checked during nodeset output)
322 if (output_region.get_database()->needs_shared_node_information()) {
323 if (interFace.ints_64_bit)
324 set_owned_node_count(region, my_rank, (int64_t)0);
325 else
326 set_owned_node_count(region, my_rank, (int)0);
327 }
328
329 transfer_edgeblocks(region, output_region, interFace.debug);
330 transfer_faceblocks(region, output_region, interFace.debug);
331 transfer_elementblocks(region, output_region, interFace.debug);
332
333 transfer_nodesets(region, output_region, interFace.debug);
334 transfer_edgesets(region, output_region, interFace.debug);
335 transfer_facesets(region, output_region, interFace.debug);
336 transfer_elemsets(region, output_region, interFace.debug);
337
338 transfer_sidesets(region, output_region, interFace.debug);
339 transfer_commsets(region, output_region, interFace.debug);
340
341 transfer_coordinate_frames(region, output_region, interFace.debug);
342
343 if (interFace.debug) {
344 DO_OUTPUT << "END STATE_DEFINE_MODEL... " << '\n';
345 }
346 if (mem_stats) {
347 dbi->progress("END STATE_DEFINE_MODEL");
348 }
349
350 output_region.end_mode(Ioss::STATE_DEFINE_MODEL);
351
352 if (interFace.debug) {
353 DO_OUTPUT << "TRANSFERRING MESH FIELD DATA ... " << '\n';
354 }
355 if (mem_stats) {
356 dbi->progress("TRANSFERRING MESH FIELD DATA ... ");
357 }
358
359 // Model defined, now fill in the model data...
360 output_region.begin_mode(Ioss::STATE_MODEL);
361
362 // Transfer MESH field_data from input to output...
363 transfer_field_data(region.get_node_blocks(), output_region, Ioss::Field::MESH, interFace);
364 transfer_field_data(region.get_node_blocks(), output_region, Ioss::Field::ATTRIBUTE,
365 interFace);
366
367 transfer_field_data(region.get_edge_blocks(), output_region, Ioss::Field::MESH, interFace);
368 transfer_field_data(region.get_edge_blocks(), output_region, Ioss::Field::ATTRIBUTE,
369 interFace);
370
371 transfer_field_data(region.get_face_blocks(), output_region, Ioss::Field::MESH, interFace);
372 transfer_field_data(region.get_face_blocks(), output_region, Ioss::Field::ATTRIBUTE,
373 interFace);
374
375 transfer_field_data(region.get_element_blocks(), output_region, Ioss::Field::MESH, interFace);
376 transfer_field_data(region.get_element_blocks(), output_region, Ioss::Field::ATTRIBUTE,
377 interFace);
378
379 transfer_field_data(region.get_nodesets(), output_region, Ioss::Field::MESH, interFace);
380 transfer_field_data(region.get_nodesets(), output_region, Ioss::Field::ATTRIBUTE, interFace);
381
382 transfer_field_data(region.get_edgesets(), output_region, Ioss::Field::MESH, interFace);
383 transfer_field_data(region.get_edgesets(), output_region, Ioss::Field::ATTRIBUTE, interFace);
384
385 transfer_field_data(region.get_facesets(), output_region, Ioss::Field::MESH, interFace);
386 transfer_field_data(region.get_facesets(), output_region, Ioss::Field::ATTRIBUTE, interFace);
387
388 transfer_field_data(region.get_elementsets(), output_region, Ioss::Field::MESH, interFace);
389 transfer_field_data(region.get_elementsets(), output_region, Ioss::Field::ATTRIBUTE,
390 interFace);
391
392 transfer_field_data(region.get_commsets(), output_region, Ioss::Field::MESH, interFace);
393 transfer_field_data(region.get_commsets(), output_region, Ioss::Field::ATTRIBUTE, interFace);
394 transfer_field_data(region.get_commsets(), output_region, Ioss::Field::COMMUNICATION,
395 interFace);
396
397 // Side Sets
398 {
399 const auto &fss = region.get_sidesets();
400 for (const auto &ifs : fss) {
401 const std::string &name = ifs->name();
402 if (interFace.debug) {
403 DO_OUTPUT << name << ", ";
404 }
405 // Find matching output sideset
406 Ioss::SideSet *ofs = output_region.get_sideset(name);
407
408 if (ofs != nullptr) {
409 transfer_field_data(ifs, ofs, Ioss::Field::MESH, interFace);
410 transfer_field_data(ifs, ofs, Ioss::Field::ATTRIBUTE, interFace);
411
412 const auto &fbs = ifs->get_side_blocks();
413 for (const auto &ifb : fbs) {
414
415 // Find matching output sideblock
416 const std::string &fbname = ifb->name();
417 if (interFace.debug) {
418 DO_OUTPUT << fbname << ", ";
419 }
420 Ioss::SideBlock *ofb = ofs->get_side_block(fbname);
421
422 if (ofb != nullptr) {
423 transfer_field_data(ifb, ofb, Ioss::Field::MESH, interFace);
424 transfer_field_data(ifb, ofb, Ioss::Field::ATTRIBUTE, interFace);
425 }
426 }
427 }
428 }
429 if (interFace.debug) {
430 DO_OUTPUT << '\n';
431 }
432 }
433 if (interFace.debug) {
434 DO_OUTPUT << "END STATE_MODEL... " << '\n';
435 }
436 if (mem_stats) {
437 dbi->progress("END STATE_MODEL... ");
438 }
439 output_region.end_mode(Ioss::STATE_MODEL);
440
441 if (interFace.delete_timesteps) {
442 if (mem_stats) {
443 dbi->progress("Prior to Memory Released... ");
444 dbi->release_memory();
445 dbo->release_memory();
446 dbi->progress("Memory Released... ");
447 }
448 return;
449 }
450
451 if (interFace.debug) {
452 DO_OUTPUT << "DEFINING TRANSIENT FIELDS ... " << '\n';
453 }
454 if (mem_stats) {
455 dbi->progress("DEFINING TRANSIENT FIELDS ... ");
456 }
457
458 int step_count = region.get_optional_property("state_count", 0);
459 if (step_count > 0) {
460 if (!interFace.debug) {
461 DO_OUTPUT << "\n Number of time steps on database =" << std::setw(12)
462 << region.get_property("state_count").get_int() << "\n\n";
463 }
464
465 output_region.begin_mode(Ioss::STATE_DEFINE_TRANSIENT);
466
467 // For each 'TRANSIENT' field in the node blocks and element
468 // blocks, transfer to the output node and element blocks.
469 transfer_fields(&region, &output_region, Ioss::Field::TRANSIENT);
470
471 transfer_fields(region.get_node_blocks(), output_region, Ioss::Field::TRANSIENT, interFace);
472 transfer_fields(region.get_edge_blocks(), output_region, Ioss::Field::TRANSIENT, interFace);
473 transfer_fields(region.get_face_blocks(), output_region, Ioss::Field::TRANSIENT, interFace);
474 transfer_fields(region.get_element_blocks(), output_region, Ioss::Field::TRANSIENT,
475 interFace);
476
477 transfer_fields(region.get_nodesets(), output_region, Ioss::Field::TRANSIENT, interFace);
478 transfer_fields(region.get_edgesets(), output_region, Ioss::Field::TRANSIENT, interFace);
479 transfer_fields(region.get_facesets(), output_region, Ioss::Field::TRANSIENT, interFace);
480 transfer_fields(region.get_elementsets(), output_region, Ioss::Field::TRANSIENT, interFace);
481
482 // Side Sets
483 {
484 const auto &fss = region.get_sidesets();
485 for (const auto &ifs : fss) {
486 const std::string &name = ifs->name();
487 if (interFace.debug) {
488 DO_OUTPUT << name << ", ";
489 }
490
491 // Find matching output sideset
492 Ioss::SideSet *ofs = output_region.get_sideset(name);
493 if (ofs != nullptr) {
494 transfer_fields(ifs, ofs, Ioss::Field::TRANSIENT);
495
496 const auto &fbs = ifs->get_side_blocks();
497 for (const auto &ifb : fbs) {
498
499 // Find matching output sideblock
500 const std::string &fbname = ifb->name();
501 if (interFace.debug) {
502 DO_OUTPUT << fbname << ", ";
503 }
504
505 Ioss::SideBlock *ofb = ofs->get_side_block(fbname);
506 if (ofb != nullptr) {
507 transfer_fields(ifb, ofb, Ioss::Field::TRANSIENT);
508 }
509 }
510 }
511 }
512 if (interFace.debug) {
513 DO_OUTPUT << '\n';
514 }
515 }
516 if (interFace.debug) {
517 DO_OUTPUT << "END STATE_DEFINE_TRANSIENT... " << '\n';
518 }
519 if (mem_stats) {
520 dbi->progress("END STATE_DEFINE_TRANSIENT... ");
521 }
522 output_region.end_mode(Ioss::STATE_DEFINE_TRANSIENT);
523 }
524
525 if (interFace.debug) {
526 DO_OUTPUT << "TRANSFERRING TRANSIENT FIELDS ... " << '\n';
527 }
528 if (mem_stats) {
529 dbi->progress("TRANSFERRING TRANSIENT FIELDS... ");
530 }
531
532 output_region.begin_mode(Ioss::STATE_TRANSIENT);
533 // Get the timesteps from the input database. Step through them
534 // and transfer fields to output database...
535
536 for (int istep = 1; istep <= step_count; istep++) {
537 double time = region.get_state_time(istep);
538 if (time < interFace.minimum_time) {
539 continue;
540 }
541 if (interFace.maximum_time != 0.0 && time > interFace.maximum_time) {
542 break;
543 }
544
545 int ostep = output_region.add_state(time);
546 show_step(istep, time);
547
548 output_region.begin_state(ostep);
549 region.begin_state(istep);
550
551 transfer_field_data(&region, &output_region, Ioss::Field::TRANSIENT, interFace);
552
553 transfer_field_data(region.get_node_blocks(), output_region, Ioss::Field::TRANSIENT,
554 interFace);
555 transfer_field_data(region.get_edge_blocks(), output_region, Ioss::Field::TRANSIENT,
556 interFace);
557 transfer_field_data(region.get_face_blocks(), output_region, Ioss::Field::TRANSIENT,
558 interFace);
559 transfer_field_data(region.get_element_blocks(), output_region, Ioss::Field::TRANSIENT,
560 interFace);
561
562 transfer_field_data(region.get_nodesets(), output_region, Ioss::Field::TRANSIENT,
563 interFace);
564 transfer_field_data(region.get_edgesets(), output_region, Ioss::Field::TRANSIENT,
565 interFace);
566 transfer_field_data(region.get_facesets(), output_region, Ioss::Field::TRANSIENT,
567 interFace);
568 transfer_field_data(region.get_elementsets(), output_region, Ioss::Field::TRANSIENT,
569 interFace);
570
571 // Side Sets
572 {
573 const auto &fss = region.get_sidesets();
574 for (const auto &ifs : fss) {
575 const std::string &name = ifs->name();
576 if (interFace.debug) {
577 DO_OUTPUT << name << ", ";
578 }
579
580 // Find matching output sideset
581 Ioss::SideSet *ofs = output_region.get_sideset(name);
582 if (ofs != nullptr) {
583 transfer_field_data(ifs, ofs, Ioss::Field::TRANSIENT, interFace);
584
585 const auto &fbs = ifs->get_side_blocks();
586 for (const auto &ifb : fbs) {
587
588 // Find matching output sideblock
589 const std::string &fbname = ifb->name();
590 if (interFace.debug) {
591 DO_OUTPUT << fbname << ", ";
592 }
593
594 Ioss::SideBlock *ofb = ofs->get_side_block(fbname);
595 if (ofb != nullptr) {
596 transfer_field_data(ifb, ofb, Ioss::Field::TRANSIENT, interFace);
597 }
598 }
599 }
600 }
601 }
602 region.end_state(istep);
603 output_region.end_state(ostep);
604 }
605 if (interFace.debug) {
606 DO_OUTPUT << "END STATE_TRANSIENT... " << '\n';
607 }
608 if (mem_stats) {
609 dbi->progress("END STATE_TRANSIENT ... ");
610 }
611 output_region.end_mode(Ioss::STATE_TRANSIENT);
612
613 if (mem_stats) {
614 dbi->progress("Prior to Memory Released... ");
615 dbi->release_memory();
616 dbo->release_memory();
617 dbi->progress("Memory Released... ");
618 }
619 }
620 }
621
622 void transfer_nodeblock(Ioss::Region &region, Ioss::Region &output_region, bool debug)
623 {
624 const auto &nbs = region.get_node_blocks();
625 for (const auto &inb : nbs) {
626 const std::string &name = inb->name();
627 if (debug) {
628 DO_OUTPUT << name << ", ";
629 }
630 size_t num_nodes = inb->entity_count();
631 size_t degree = inb->get_property("component_degree").get_int();
632 if (!debug) {
633 DO_OUTPUT << " Number of coordinates per node =" << std::setw(12) << degree << "\n";
634 DO_OUTPUT << " Number of nodes =" << std::setw(12) << num_nodes
635 << "\n";
636 }
637
638 auto *nb = new Ioss::NodeBlock(*inb);
639 output_region.add(nb);
640
641 if (output_region.get_database()->needs_shared_node_information()) {
642 // If the "owning_processor" field exists on the input
643 // nodeblock, transfer it and the "ids" field to the output
644 // nodeblock at this time since it is used to determine
645 // per-processor sizes of nodeblocks and nodesets.
646 if (inb->field_exists("owning_processor")) {
647 size_t isize = inb->get_field("ids").get_size();
648 std::vector<char> data(isize);
649 inb->get_field_data("ids", Data(data), isize);
650 nb->put_field_data("ids", Data(data), isize);
651 isize = inb->get_field("owning_processor").get_size();
652 data.resize(isize);
653 inb->get_field_data("owning_processor", Data(data), isize);
654 nb->put_field_data("owning_processor", Data(data), isize);
655 }
656 }
657 }
658 if (debug) {
659 DO_OUTPUT << '\n';
660 }
661 }
662
663 struct param
664 {
665 Ioss::GroupingEntity *entity;
666 Ioss::Region *output_region;
667 Ioss::Field::RoleType role;
668 const IOShell::Interface *interFace;
669 };
670
671 void *transfer_fields_ts(void *varg)
672 {
673 auto *arg = static_cast<param *>(varg);
674 auto entity = arg->entity;
675 auto output_region = arg->output_region;
676 auto interFace = arg->interFace;
677 auto role = arg->role;
678
679 const std::string &name = entity->name();
680 if (interFace->debug) {
681 DO_OUTPUT << name << ", ";
682 }
683
684 // Find the corresponding output entity...
685 Ioss::GroupingEntity *oeb = output_region->get_entity(name, entity->type());
686 if (oeb != nullptr) {
687 transfer_fields(entity, oeb, role);
688 if (interFace->do_transform_fields) {
689 transform_fields(entity, oeb, role);
690 }
691 }
692 if (interFace->debug) {
693 DO_OUTPUT << '\n';
694 }
695 return varg;
696 }
697
698 template <typename T>
699 void transfer_fields(const std::vector<T *> &entities, Ioss::Region &output_region,
700 Ioss::Field::RoleType role, const IOShell::Interface &interFace)
701 {
702 std::vector<pthread_t> threads(entities.size());
703 std::vector<param> params(entities.size());
704
705 int t = 0;
706 for (const auto &entity : entities) {
707 params[t].entity = entity;
708 params[t].output_region = &output_region;
709 params[t].interFace = &interFace;
710 params[t].role = role;
711 pthread_create(&threads[t], nullptr, transfer_fields_ts, (void *)(Data(params) + t));
712 t++;
713 }
714
715 for (t = 0; t < (int)threads.size(); t++) {
716 pthread_join(threads[t], nullptr);
717 }
718 }
719
720 void *transfer_field_data_ts(void *varg)
721 {
722 auto *arg = static_cast<param *>(varg);
723 auto entity = arg->entity;
724 auto output_region = arg->output_region;
725 auto interFace = arg->interFace;
726 auto role = arg->role;
727
728 const std::string &name = entity->name();
729
730 // Find the corresponding output block...
731 Ioss::GroupingEntity *output = output_region->get_entity(name, entity->type());
732 if (output != nullptr) {
733 transfer_field_data(entity, output, role, *interFace);
734 if (interFace->do_transform_fields) {
735 transform_field_data(entity, output, role, *interFace);
736 }
737 }
738 return arg;
739 }
740
741 template <typename T>
742 void transfer_field_data(const std::vector<T *> &entities, Ioss::Region &output_region,
743 Ioss::Field::RoleType role, const IOShell::Interface &interFace)
744 {
745 std::vector<pthread_t> threads(entities.size());
746 std::vector<param> params(entities.size());
747
748 int t = 0;
749 for (const auto &entity : entities) {
750 params[t].entity = entity;
751 params[t].output_region = &output_region;
752 params[t].interFace = &interFace;
753 params[t].role = role;
754 pthread_create(&threads[t], nullptr, transfer_field_data_ts, (void *)(Data(params) + t));
755 t++;
756 }
757
758 for (t = 0; t < (int)threads.size(); t++) {
759 pthread_join(threads[t], nullptr);
760 }
761 }
762
763 template <typename T>
764 void transfer_blocks(const std::vector<T *> &blocks, Ioss::Region &output_region, bool debug)
765 {
766 if (!blocks.empty()) {
767 size_t total_entities = 0;
768 for (const auto &iblock : blocks) {
769 const std::string &name = iblock->name();
770 if (debug) {
771 DO_OUTPUT << name << ", ";
772 }
773 size_t count = iblock->entity_count();
774 total_entities += count;
775
776 auto *block = new T(*iblock);
777 output_region.add(block);
778 }
779 if (!debug) {
780 DO_OUTPUT << " Number of " << std::setw(14) << (*blocks.begin())->type_string()
781 << "s =" << std::setw(12) << blocks.size() << "\t"
782 << "Length of entity list =" << std::setw(12) << total_entities << "\n";
783 }
784 else {
785 DO_OUTPUT << '\n';
786 }
787 }
788 }
789
790 void transfer_elementblocks(Ioss::Region &region, Ioss::Region &output_region, bool debug)
791 {
792 const auto &ebs = region.get_element_blocks();
793 transfer_blocks(ebs, output_region, debug);
794 }
795
796 void transfer_edgeblocks(Ioss::Region &region, Ioss::Region &output_region, bool debug)
797 {
798 const auto &ebs = region.get_edge_blocks();
799 transfer_blocks(ebs, output_region, debug);
800 }
801
802 void transfer_faceblocks(Ioss::Region &region, Ioss::Region &output_region, bool debug)
803 {
804 const auto &ebs = region.get_face_blocks();
805 transfer_blocks(ebs, output_region, debug);
806 }
807
808 void transfer_sidesets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
809 {
810 const auto &fss = region.get_sidesets();
811 for (const auto &ss : fss) {
812 const std::string &name = ss->name();
813 if (debug) {
814 DO_OUTPUT << name << ", ";
815 }
816
817 auto *surf = new Ioss::SideSet(*ss);
818 output_region.add(surf);
819
820 // Fix up the optional 'owner_block' in copied SideBlocks...
821 const auto &fbs = ss->get_side_blocks();
822 for (const auto &ifb : fbs) {
823 if (ifb->parent_block() != nullptr) {
824 const auto &fb_name = ifb->parent_block()->name();
825 auto *parent = dynamic_cast<Ioss::EntityBlock *>(
826 output_region.get_entity(fb_name, Ioss::ELEMENTBLOCK));
827 if (parent == nullptr) {
828 parent = dynamic_cast<Ioss::EntityBlock *>(
829 output_region.get_entity(fb_name, Ioss::STRUCTUREDBLOCK));
830 }
831
832 auto *ofb = surf->get_side_block(ifb->name());
833 ofb->set_parent_block(parent);
834 }
835 }
836 }
837 if (!debug) {
838 DO_OUTPUT << " Number of SideSets =" << std::setw(12) << fss.size() << "\n";
839 }
840 else {
841 DO_OUTPUT << '\n';
842 }
843 }
844
845 template <typename T>
846 void transfer_sets(const std::vector<T *> &sets, Ioss::Region &output_region, bool debug)
847 {
848 if (!sets.empty()) {
849 size_t total_entities = 0;
850 for (const auto &set : sets) {
851 const std::string &name = set->name();
852 if (debug) {
853 DO_OUTPUT << name << ", ";
854 }
855 size_t count = set->entity_count();
856 total_entities += count;
857 auto *o_set = new T(*set);
858 output_region.add(o_set);
859 }
860
861 if (!debug) {
862 DO_OUTPUT << " Number of " << std::setw(14) << (*sets.begin())->type_string()
863 << "s =" << std::setw(12) << sets.size() << "\t"
864 << "Length of entity list =" << std::setw(12) << total_entities << "\n";
865 }
866 else {
867 DO_OUTPUT << '\n';
868 }
869 }
870 }
871
872 void transfer_nodesets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
873 {
874 const auto &nss = region.get_nodesets();
875 transfer_sets(nss, output_region, debug);
876 }
877
878 void transfer_edgesets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
879 {
880 const auto &nss = region.get_edgesets();
881 transfer_sets(nss, output_region, debug);
882 }
883
884 void transfer_facesets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
885 {
886 const auto &nss = region.get_facesets();
887 transfer_sets(nss, output_region, debug);
888 }
889
890 void transfer_elemsets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
891 {
892 const auto &nss = region.get_elementsets();
893 transfer_sets(nss, output_region, debug);
894 }
895
896 void transfer_commsets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
897 {
898 const auto &css = region.get_commsets();
899 for (const auto &ics : css) {
900 if (debug) {
901 const std::string &name = ics->name();
902 DO_OUTPUT << name << ", ";
903 }
904 auto *cs = new Ioss::CommSet(*ics);
905 output_region.add(cs);
906 }
907 if (debug) {
908 DO_OUTPUT << '\n';
909 }
910 }
911
912 void transfer_coordinate_frames(Ioss::Region &region, Ioss::Region &output_region, bool debug)
913 {
914 const Ioss::CoordinateFrameContainer &cf = region.get_coordinate_frames();
915 for (const auto &frame : cf) {
916 output_region.add(frame);
917 }
918 if (debug) {
919 DO_OUTPUT << '\n';
920 }
921 }
922
923 void transfer_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
924 Ioss::Field::RoleType role, const std::string &prefix)
925 {
926 // Check for transient fields...
927 Ioss::NameList fields = ige->field_describe(role);
928
929 // Iterate through results fields and transfer to output
930 // database... If a prefix is specified, only transfer fields
931 // whose names begin with the prefix
932 for (const auto &field_name : fields) {
933 Ioss::Field field = ige->get_field(field_name);
934 if (field_name != "ids" && !oge->field_exists(field_name) &&
935 Ioss::Utils::substr_equal(prefix, field_name)) {
936 // If the field does not already exist, add it to the output node block
937 oge->field_add(field);
938 }
939 }
940 }
941
942 void transform_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
943 Ioss::Field::RoleType role)
944 {
945 // Check for transient fields...
946 Ioss::NameList fields = ige->field_describe(role);
947
948 // Iterate through results fields and transfer to output database...
949 for (const auto &field_name : fields) {
950 std::string out_field_name = field_name + "_mag";
951 if (!oge->field_exists(out_field_name)) {
952 // If the field does not already exist, add it to the output node block
953 Ioss::Field field = ige->get_field(field_name);
954 Ioss::Field tr_field(out_field_name, field.get_type(), field.raw_storage(),
955 field.get_role(), field.raw_count());
956
957 auto *transform = Ioss::Transform::create("vector magnitude");
958 assert(transform != nullptr);
959 tr_field.add_transform(transform);
960
961 auto *max_transform = Ioss::Transform::create("absolute_maximum");
962 assert(max_transform != nullptr);
963 tr_field.add_transform(max_transform);
964
965 oge->field_add(tr_field);
966 }
967 }
968 }
969
970 void transform_field_data(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
971 Ioss::Field::RoleType role, const IOShell::Interface &interFace)
972 {
973 // Iterate through the TRANSIENT-role fields of the input
974 // database and transfer to output database.
975 Ioss::NameList state_fields = ige->field_describe(role);
976 // Iterate through mesh description fields and transfer to
977 // output database...
978 for (const auto &field_name : state_fields) {
979 std::string out_field_name = field_name + "_mag";
980
981 assert(oge->field_exists(out_field_name));
982
983 #ifdef SEACAS_HAVE_KOKKOS
984 int basic_type = ige->get_field(field_name).get_type();
985 #endif
986
987 size_t isize = ige->get_field(field_name).get_size();
988 size_t osize = oge->get_field(out_field_name).get_size();
989 assert(isize == osize);
990
991 Ioss::DataPool pool;
992 pool.data.resize(isize);
993 switch (interFace.data_storage_type) {
994 case 1: ige->get_field_data(field_name, Data(pool.data), isize); break;
995 #ifdef SEACAS_HAVE_KOKKOS
996 case 3:
997 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
998 ige->get_field_data<char>(field_name, pool.data_view_char);
999 }
1000 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1001 ige->get_field_data<int>(field_name, pool.data_view_int);
1002 }
1003 else if (basic_type == Ioss::Field::INT64) {
1004 ige->get_field_data<int64_t>(field_name, pool.data_view_int64);
1005 }
1006 else if (basic_type == Ioss::Field::REAL) {
1007 ige->get_field_data<double>(field_name, pool.data_view_double);
1008 }
1009 else if (basic_type == Ioss::Field::COMPLEX) {
1010 // Since data_view_complex cannot be a global variable.
1011 ige->get_field_data(field_name, Data(pool.data), isize);
1012 }
1013 else {
1014 }
1015 break;
1016 case 4:
1017 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1018 ige->get_field_data<char>(field_name, pool.data_view_2D_char);
1019 }
1020 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1021 ige->get_field_data<int>(field_name, pool.data_view_2D_int);
1022 }
1023 else if (basic_type == Ioss::Field::INT64) {
1024 ige->get_field_data<int64_t>(field_name, pool.data_view_2D_int64);
1025 }
1026 else if (basic_type == Ioss::Field::REAL) {
1027 ige->get_field_data<double>(field_name, pool.data_view_2D_double);
1028 }
1029 else if (basic_type == Ioss::Field::COMPLEX) {
1030 // Since data_view_complex cannot be a global variable.
1031 ige->get_field_data(field_name, Data(pool.data), isize);
1032 }
1033 else {
1034 }
1035 break;
1036 case 5:
1037 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1038 ige->get_field_data<char, Kokkos::LayoutRight, Kokkos::HostSpace>(
1039 field_name, pool.data_view_2D_char_layout_space);
1040 }
1041 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1042 ige->get_field_data<int, Kokkos::LayoutRight, Kokkos::HostSpace>(
1043 field_name, pool.data_view_2D_int_layout_space);
1044 }
1045 else if (basic_type == Ioss::Field::INT64) {
1046 ige->get_field_data<int64_t, Kokkos::LayoutRight, Kokkos::HostSpace>(
1047 field_name, pool.data_view_2D_int64_layout_space);
1048 }
1049 else if (basic_type == Ioss::Field::REAL) {
1050 ige->get_field_data<double, Kokkos::LayoutRight, Kokkos::HostSpace>(
1051 field_name, pool.data_view_2D_double_layout_space);
1052 }
1053 else if (basic_type == Ioss::Field::COMPLEX) {
1054 // Since data_view_complex cannot be a global variable.
1055 ige->get_field_data(field_name, Data(pool.data), isize);
1056 }
1057 else {
1058 }
1059 break;
1060 #endif
1061 default:
1062 if (field_name == "mesh_model_coordinates") {
1063 std::cerr << "data_storage option not recognized.";
1064 }
1065 return;
1066 }
1067
1068 switch (interFace.data_storage_type) {
1069 case 1: oge->put_field_data(out_field_name, Data(pool.data), osize); break;
1070 #ifdef SEACAS_HAVE_KOKKOS
1071 case 3:
1072 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1073 oge->put_field_data<char>(field_name, pool.data_view_char);
1074 }
1075 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1076 oge->put_field_data<int>(field_name, pool.data_view_int);
1077 }
1078 else if (basic_type == Ioss::Field::INT64) {
1079 oge->put_field_data<int64_t>(field_name, pool.data_view_int64);
1080 }
1081 else if (basic_type == Ioss::Field::REAL) {
1082 oge->put_field_data<double>(field_name, pool.data_view_double);
1083 }
1084 else if (basic_type == Ioss::Field::COMPLEX) {
1085 // Since data_view_complex cannot be a global variable.
1086 oge->put_field_data(out_field_name, Data(pool.data), osize);
1087 }
1088 else {
1089 }
1090 break;
1091 case 4:
1092 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1093 oge->put_field_data<char>(field_name, pool.data_view_2D_char);
1094 }
1095 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1096 oge->put_field_data<int>(field_name, pool.data_view_2D_int);
1097 }
1098 else if (basic_type == Ioss::Field::INT64) {
1099 oge->put_field_data<int64_t>(field_name, pool.data_view_2D_int64);
1100 }
1101 else if (basic_type == Ioss::Field::REAL) {
1102 oge->put_field_data<double>(field_name, pool.data_view_2D_double);
1103 }
1104 else if (basic_type == Ioss::Field::COMPLEX) {
1105 // Since data_view_complex cannot be a global variable.
1106 oge->put_field_data(out_field_name, Data(pool.data), osize);
1107 }
1108 else {
1109 }
1110 break;
1111 case 5:
1112 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1113 oge->put_field_data<char, Kokkos::LayoutRight, Kokkos::HostSpace>(
1114 field_name, pool.data_view_2D_char_layout_space);
1115 }
1116 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1117 oge->put_field_data<int, Kokkos::LayoutRight, Kokkos::HostSpace>(
1118 field_name, pool.data_view_2D_int_layout_space);
1119 }
1120 else if (basic_type == Ioss::Field::INT64) {
1121 oge->put_field_data<int64_t, Kokkos::LayoutRight, Kokkos::HostSpace>(
1122 field_name, pool.data_view_2D_int64_layout_space);
1123 }
1124 else if (basic_type == Ioss::Field::REAL) {
1125 oge->put_field_data<double, Kokkos::LayoutRight, Kokkos::HostSpace>(
1126 field_name, pool.data_view_2D_double_layout_space);
1127 }
1128 else if (basic_type == Ioss::Field::COMPLEX) {
1129 // Since data_view_complex cannot be a global variable.
1130 oge->put_field_data(out_field_name, Data(pool.data), osize);
1131 }
1132 else {
1133 }
1134 break;
1135 #endif
1136 default:
1137 if (field_name == "mesh_model_coordinates") {
1138 std::cerr << "data_storage option not recognized.";
1139 }
1140 return;
1141 }
1142 }
1143 return;
1144 }
1145
1146 void transfer_field_data(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
1147 Ioss::Field::RoleType role, const IOShell::Interface &interFace,
1148 const std::string &prefix)
1149 {
1150 // Iterate through the TRANSIENT-role fields of the input
1151 // database and transfer to output database.
1152 Ioss::NameList state_fields = ige->field_describe(role);
1153
1154 // Complication here is that if the 'role' is 'Ioss::Field::MESH',
1155 // then the 'ids' field must be transferred first...
1156 if (role == Ioss::Field::MESH) {
1157 for (const auto &field_name : state_fields) {
1158 assert(oge->field_exists(field_name));
1159 if (field_name == "ids") {
1160 transfer_field_data_internal(ige, oge, field_name, interFace);
1161 break;
1162 }
1163 }
1164 }
1165
1166 for (const auto &field_name : state_fields) {
1167 // All of the 'Ioss::EntityBlock' derived classes have a
1168 // 'connectivity' field, but it is only interesting on the
1169 // Ioss::ElementBlock class. On the other classes, it just
1170 // generates overhead...
1171 if (field_name == "connectivity" && ige->type() != Ioss::ELEMENTBLOCK) {
1172 continue;
1173 }
1174
1175 if (field_name != "ids" && Ioss::Utils::substr_equal(prefix, field_name)) {
1176 assert(oge->field_exists(field_name));
1177 transfer_field_data_internal(ige, oge, field_name, interFace);
1178 }
1179 }
1180 }
1181
1182 void transfer_field_data_internal(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
1183 const std::string &field_name,
1184 const IOShell::Interface &interFace)
1185 {
1186
1187 size_t isize = ige->get_field(field_name).get_size();
1188 if (isize != oge->get_field(field_name).get_size()) {
1189 assert(isize == oge->get_field(field_name).get_size());
1190 }
1191
1192 if (field_name == "mesh_model_coordinates_x") {
1193 return;
1194 }
1195 if (field_name == "mesh_model_coordinates_y") {
1196 return;
1197 }
1198 if (field_name == "mesh_model_coordinates_z") {
1199 return;
1200 }
1201 if (field_name == "connectivity_raw") {
1202 return;
1203 }
1204 if (field_name == "element_side_raw") {
1205 return;
1206 }
1207 if (field_name == "ids_raw") {
1208 return;
1209 }
1210 if (field_name == "implicit_ids") {
1211 return;
1212 }
1213 if (field_name == "node_connectivity_status") {
1214 return;
1215 }
1216 if (field_name == "owning_processor") {
1217 return;
1218 }
1219 if (field_name == "entity_processor_raw") {
1220 return;
1221 }
1222 if (field_name == "ids" && ige->type() == Ioss::SIDEBLOCK) {
1223 return;
1224 }
1225
1226 #ifdef SEACAS_HAVE_KOKKOS
1227 int basic_type = ige->get_field(field_name).get_type();
1228 #endif
1229
1230 Ioss::DataPool pool;
1231 pool.data.resize(isize);
1232 switch (interFace.data_storage_type) {
1233 case 1: ige->get_field_data(field_name, Data(pool.data), isize); break;
1234 #ifdef SEACAS_HAVE_KOKKOS
1235 case 3:
1236 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1237 ige->get_field_data<char>(field_name, pool.data_view_char);
1238 }
1239 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1240 ige->get_field_data<int>(field_name, pool.data_view_int);
1241 }
1242 else if (basic_type == Ioss::Field::INT64) {
1243 ige->get_field_data<int64_t>(field_name, pool.data_view_int64);
1244 }
1245 else if (basic_type == Ioss::Field::REAL) {
1246 ige->get_field_data<double>(field_name, pool.data_view_double);
1247 }
1248 else if (basic_type == Ioss::Field::COMPLEX) {
1249 // Since data_view_complex cannot be a global variable.
1250 ige->get_field_data(field_name, Data(pool.data), isize);
1251 }
1252 else {
1253 }
1254 break;
1255 case 4:
1256 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1257 ige->get_field_data<char>(field_name, pool.data_view_2D_char);
1258 }
1259 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1260 ige->get_field_data<int>(field_name, pool.data_view_2D_int);
1261 }
1262 else if (basic_type == Ioss::Field::INT64) {
1263 ige->get_field_data<int64_t>(field_name, pool.data_view_2D_int64);
1264 }
1265 else if (basic_type == Ioss::Field::REAL) {
1266 ige->get_field_data<double>(field_name, pool.data_view_2D_double);
1267 }
1268 else if (basic_type == Ioss::Field::COMPLEX) {
1269 // Since data_view_complex cannot be a global variable.
1270 ige->get_field_data(field_name, Data(pool.data), isize);
1271 }
1272 else {
1273 }
1274 break;
1275 case 5:
1276 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1277 ige->get_field_data<char, Kokkos::LayoutRight, Kokkos::HostSpace>(
1278 field_name, pool.data_view_2D_char_layout_space);
1279 }
1280 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1281 ige->get_field_data<int, Kokkos::LayoutRight, Kokkos::HostSpace>(
1282 field_name, pool.data_view_2D_int_layout_space);
1283 }
1284 else if (basic_type == Ioss::Field::INT64) {
1285 ige->get_field_data<int64_t, Kokkos::LayoutRight, Kokkos::HostSpace>(
1286 field_name, pool.data_view_2D_int64_layout_space);
1287 }
1288 else if (basic_type == Ioss::Field::REAL) {
1289 ige->get_field_data<double, Kokkos::LayoutRight, Kokkos::HostSpace>(
1290 field_name, pool.data_view_2D_double_layout_space);
1291 }
1292 else if (basic_type == Ioss::Field::COMPLEX) {
1293 // Since data_view_complex cannot be a global variable.
1294 ige->get_field_data(field_name, Data(pool.data), isize);
1295 }
1296 else {
1297 }
1298 break;
1299 #endif
1300 default:
1301 if (field_name == "mesh_model_coordinates") {
1302 std::cerr << "data_storage option not recognized.";
1303 }
1304 return;
1305 }
1306
1307 switch (interFace.data_storage_type) {
1308 case 1: oge->put_field_data(field_name, Data(pool.data), isize); break;
1309 #ifdef SEACAS_HAVE_KOKKOS
1310 case 3:
1311 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1312 oge->put_field_data<char>(field_name, pool.data_view_char);
1313 }
1314 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1315 oge->put_field_data<int>(field_name, pool.data_view_int);
1316 }
1317 else if (basic_type == Ioss::Field::INT64) {
1318 oge->put_field_data<int64_t>(field_name, pool.data_view_int64);
1319 }
1320 else if (basic_type == Ioss::Field::REAL) {
1321 oge->put_field_data<double>(field_name, pool.data_view_double);
1322 }
1323 else if (basic_type == Ioss::Field::COMPLEX) {
1324 // Since data_view_complex cannot be a global variable.
1325 oge->put_field_data(field_name, Data(pool.data), isize);
1326 }
1327 else {
1328 }
1329 break;
1330 case 4:
1331 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1332 oge->put_field_data<char>(field_name, pool.data_view_2D_char);
1333 }
1334 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1335 oge->put_field_data<int>(field_name, pool.data_view_2D_int);
1336 }
1337 else if (basic_type == Ioss::Field::INT64) {
1338 oge->put_field_data<int64_t>(field_name, pool.data_view_2D_int64);
1339 }
1340 else if (basic_type == Ioss::Field::REAL) {
1341 oge->put_field_data<double>(field_name, pool.data_view_2D_double);
1342 }
1343 else if (basic_type == Ioss::Field::COMPLEX) {
1344 // Since data_view_complex cannot be a global variable.
1345 oge->put_field_data(field_name, Data(pool.data), isize);
1346 }
1347 else {
1348 }
1349 break;
1350 case 5:
1351 if ((basic_type == Ioss::Field::CHARACTER) || (basic_type == Ioss::Field::STRING)) {
1352 oge->put_field_data<char, Kokkos::LayoutRight, Kokkos::HostSpace>(
1353 field_name, pool.data_view_2D_char_layout_space);
1354 }
1355 else if ((basic_type == Ioss::Field::INTEGER) || (basic_type == Ioss::Field::INT32)) {
1356 oge->put_field_data<int, Kokkos::LayoutRight, Kokkos::HostSpace>(
1357 field_name, pool.data_view_2D_int_layout_space);
1358 }
1359 else if (basic_type == Ioss::Field::INT64) {
1360 oge->put_field_data<int64_t, Kokkos::LayoutRight, Kokkos::HostSpace>(
1361 field_name, pool.data_view_2D_int64_layout_space);
1362 }
1363 else if (basic_type == Ioss::Field::REAL) {
1364 oge->put_field_data<double, Kokkos::LayoutRight, Kokkos::HostSpace>(
1365 field_name, pool.data_view_2D_double_layout_space);
1366 }
1367 else if (basic_type == Ioss::Field::COMPLEX) {
1368 // Since data_view_complex cannot be a global variable.
1369 oge->put_field_data(field_name, Data(pool.data), isize);
1370 }
1371 else {
1372 }
1373 break;
1374 #endif
1375 default: return;
1376 }
1377 return;
1378 }
1379
1380 void transfer_qa_info(Ioss::Region &in, Ioss::Region &out)
1381 {
1382 out.add_information_records(in.get_information_records());
1383
1384 const Ioss::NameList &qa = in.get_qa_records();
1385 for (size_t i = 0; i < qa.size(); i += 4) {
1386 out.add_qa_record(qa[i + 0], qa[i + 1], qa[i + 2], qa[i + 3]);
1387 }
1388 }
1389
1390 void transfer_properties(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge)
1391 {
1392 Ioss::NameList properties = ige->property_describe();
1393
1394 // Iterate through properties and transfer to output database...
1395 for (const auto &property : properties) {
1396 if (!oge->property_exists(property)) {
1397 oge->property_add(ige->get_property(property));
1398 }
1399 }
1400 }
1401
1402 void show_step(int istep, double time)
1403 {
1404 DO_OUTPUT.setf(std::ios::scientific);
1405 DO_OUTPUT.setf(std::ios::showpoint);
1406 DO_OUTPUT << " Time step " << std::setw(5) << istep << " at time " << std::setprecision(5)
1407 << time << '\n';
1408 }
1409
1410 template <typename INT>
1411 void set_owned_node_count(Ioss::Region &region, int my_processor, INT /*dummy*/)
1412 {
1413 Ioss::NodeBlock *nb = region.get_node_block("nodeblock_1");
1414 if (nb->field_exists("owning_processor")) {
1415 std::vector<int> my_data;
1416 nb->get_field_data("owning_processor", my_data);
1417
1418 INT owned = std::count(my_data.begin(), my_data.end(), my_processor);
1419 nb->property_add(Ioss::Property("locally_owned_count", owned));
1420
1421 // Set locally_owned_count property on all nodesets...
1422 const Ioss::NodeSetContainer &nss = region.get_nodesets();
1423 for (auto ns : nss) {
1424
1425 std::vector<INT> ids;
1426 ns->get_field_data("ids_raw", ids);
1427 owned = 0;
1428 for (size_t n = 0; n < ids.size(); n++) {
1429 INT id = ids[n];
1430 if (my_data[id - 1] == my_processor) {
1431 owned++;
1432 }
1433 }
1434 ns->property_add(Ioss::Property("locally_owned_count", owned));
1435 }
1436 }
1437 }
1438
1439 Ioss::PropertyManager set_properties(IOShell::Interface &interFace)
1440 {
1441 Ioss::PropertyManager properties;
1442
1443 if (interFace.ints_64_bit) {
1444 properties.add(Ioss::Property("INTEGER_SIZE_DB", 8));
1445 properties.add(Ioss::Property("INTEGER_SIZE_API", 8));
1446 }
1447
1448 if (interFace.ints_32_bit) {
1449 properties.add(Ioss::Property("INTEGER_SIZE_DB", 4));
1450 }
1451
1452 if (interFace.reals_32_bit) {
1453 properties.add(Ioss::Property("REAL_SIZE_DB", 4));
1454 }
1455
1456 if (interFace.in_memory_read) {
1457 properties.add(Ioss::Property("MEMORY_READ", 1));
1458 }
1459
1460 if (interFace.in_memory_write) {
1461 properties.add(Ioss::Property("MEMORY_WRITE", 1));
1462 }
1463
1464 if (interFace.compression_level > 0 || interFace.shuffle || interFace.szip) {
1465 properties.add(Ioss::Property("FILE_TYPE", "netcdf4"));
1466 properties.add(Ioss::Property("COMPRESSION_LEVEL", interFace.compression_level));
1467 properties.add(Ioss::Property("COMPRESSION_SHUFFLE", static_cast<int>(interFace.shuffle)));
1468
1469 if (interFace.szip) {
1470 properties.add(Ioss::Property("COMPRESSION_METHOD", "szip"));
1471 }
1472 else if (interFace.zlib) {
1473 properties.add(Ioss::Property("COMPRESSION_METHOD", "zlib"));
1474 }
1475 }
1476
1477 if (interFace.compose_output == "default") {
1478 if (interFace.outFiletype == "cgns") {
1479 properties.add(Ioss::Property("COMPOSE_RESULTS", "YES"));
1480 properties.add(Ioss::Property("COMPOSE_RESTART", "YES"));
1481 }
1482 else {
1483 properties.add(Ioss::Property("COMPOSE_RESULTS", "NO"));
1484 properties.add(Ioss::Property("COMPOSE_RESTART", "NO"));
1485 }
1486 }
1487 else if (interFace.compose_output == "external") {
1488 properties.add(Ioss::Property("COMPOSE_RESULTS", "NO"));
1489 properties.add(Ioss::Property("COMPOSE_RESTART", "NO"));
1490 }
1491 else if (interFace.compose_output != "none") {
1492 properties.add(Ioss::Property("COMPOSE_RESULTS", "YES"));
1493 properties.add(Ioss::Property("COMPOSE_RESTART", "YES"));
1494 }
1495
1496 if (interFace.file_per_state) {
1497 properties.add(Ioss::Property("FILE_PER_STATE", "YES"));
1498 }
1499
1500 if (interFace.netcdf4) {
1501 properties.add(Ioss::Property("FILE_TYPE", "netcdf4"));
1502 }
1503
1504 if (interFace.netcdf5) {
1505 properties.add(Ioss::Property("FILE_TYPE", "netcdf5"));
1506 }
1507
1508 if (interFace.inputFile.size() > 1) {
1509 properties.add(Ioss::Property("ENABLE_FILE_GROUPS", 1));
1510 }
1511
1512 if (interFace.debug) {
1513 properties.add(Ioss::Property("LOGGING", 1));
1514 }
1515
1516 if (interFace.memory_statistics) {
1517 properties.add(Ioss::Property("ENABLE_TRACING", 1));
1518 }
1519
1520 if (!interFace.decomp_method.empty()) {
1521 properties.add(Ioss::Property("DECOMPOSITION_METHOD", interFace.decomp_method));
1522 }
1523
1524 if (interFace.retain_empty_blocks) {
1525 properties.add(Ioss::Property("RETAIN_EMPTY_BLOCKS", "YES"));
1526 }
1527 return properties;
1528 }
1529 } // namespace