Debian Codegraph @

packages/seacas/libraries/ioss/src/faodel/Iofaodel_DatabaseIO.C

raw
1 // Copyright(C) 1999-2021, 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 "faodel/Iofaodel_DatabaseIO.h"
8 #include "faodel/Iofaodel_FieldSerialization.h"
9 #include "faodel/Iofaodel_PropertySerialization.h"
10 #include "faodel/Iofaodel_Utils.h"
11
12 #include "Ioss_CodeTypes.h"
13 #include "Ioss_CommSet.h"
14 #include "Ioss_ElementBlock.h"
15 #include "Ioss_NodeBlock.h"
16 #include "Ioss_NodeSet.h"
17 #include "Ioss_SideBlock.h"
18 #include "Ioss_SideSet.h"
19 #include "Ioss_SubSystem.h"
20 #include "Ioss_Utils.h"
21
22 #include <algorithm>
23 #include <cctype>
24 #include <cfloat>
25 #include <climits>
26 #include <cstdlib>
27 #include <cstring>
28 #include <ctime>
29 #include <fmt/ostream.h>
30 #include <fstream>
31 #include <iostream>
32 #include <iterator>
33 #include <list>
34 #include <map>
35 #include <mutex>
36 #include <set>
37 #include <string>
38 #include <vector>
39
40 #include "faodel-services/MPISyncStart.hh"
41
42 #if 1
43 #define PRINT_KEYS
44 #endif
45
46 namespace Iofaodel {
47 // namespace {
48 // Output a message that the operation is unsupported and die...
49 void unsupported(const char *operation)
50 {
51 std::cerr << "ERROR: Unsupported functionality called: " << operation << '\n';
52 std::abort();
53 }
54
55 int get_file_pointer() { return 0; }
56
57 const char *Version() { return "Iofaodel_DatabaseIO.C 2010/09/22"; }
58
59 void faodel_error(int exoid, int lineno, int /* processor */)
60 {
61 std::ostringstream errmsg;
62
63 errmsg << "Faodel error at line " << lineno << " in file '" << Version()
64 << "' Please report to [email protected] if you need help.";
65
66 IOSS_ERROR(errmsg);
67 }
68 //} // namespace
69
70 // ========================================================================
71 const IOFactory *IOFactory::factory()
72 {
73 static IOFactory registerThis;
74 return &registerThis;
75 }
76
77 IOFactory::IOFactory() : Ioss::IOFactory("faodel") {}
78
79 Ioss::DatabaseIO *IOFactory::make_IO(const std::string &filename, Ioss::DatabaseUsage db_usage,
80 Ioss_MPI_Comm communicator,
81 const Ioss::PropertyManager &properties) const
82 {
83 return new DatabaseIO(nullptr, filename, db_usage, communicator, properties);
84 }
85
86 /*
87 * There are three basic cases to address, manifested in whether any bootstrapping is done and
88 * what gets provided to kelpie::Connect()
89 *
90 * - Each process wants a local store, potentially backed by an IOM, but isn't interested
91 * in sharing data with any other nodes. This will be satisfied by a localkv: URI. Dirman
92 * isn't strictly necessary.
93 *
94 * - Some subset (an improper subset; all nodes might join) of the processes in the IOSS job will
95 * participate in keyspace partitioning (and therefore data sharing).
96 * This will be indicated by dht: or rft: URIs (distributed hash
97 * table or rank-folding table, respectively), and the configuration should specify
98 * which processes in the job are participants. URIs may be annotated to configure IOMs on
99 * each kelpie instance and to configure the pools themselves. Dirman must be started among
100 * the pool processes.
101 *
102 * - No Kelpie pool will be hosted by this job. We need the node ID of a remote Dirman so that
103 * this job's calls to Connect() can have their URIs translated appropriately to the node IDs
104 * of the processes comprising the remote Kelpie service. We don't have any input into the
105 * configuration of that service.
106 */
107
108 DatabaseIO::DatabaseIO(Ioss::Region *region, const std::string &filename,
109 Ioss::DatabaseUsage db_usage, Ioss_MPI_Comm communicator,
110 const Ioss::PropertyManager &props)
111 : Ioss::DatabaseIO(region, filename, db_usage, communicator, props), spatialDimension(3),
112 nodeBlockCount(0), elementBlockCount(0), nodesetCount(0), sidesetCount(0),
113 commsetNodeCount(0), commsetElemCount(0)
114 {
115 std::string resource("local:/ioss");
116
117 // Allow an override of the faodel configuration.
118 // Two methods: supply the faodel-config-replace property, or set the FAODEL_CONFIG
119 // environment variable. FAODEL_CONFIG takes precedence.
120 // if FAODEL_CONFIG is set, we will also use (if set) FAODEL_RESOURCE_URI and not attempt
121 // to do anything smart to it
122 char *faodel_config_env = std::getenv("FAODEL_CONFIG");
123 if (faodel_config_env not_eq nullptr) {
124
125 faodel_config.Append(faodel_config_env);
126 char *resource_override = std::getenv("FAODEL_RESOURCE_URI");
127
128 if (resource_override not_eq nullptr)
129 resource = resource_override;
130 }
131 else {
132
133 if (props.exists("faodel-resource-uri"))
134 resource = props.get("faodel-resource-uri").get_string();
135
136 if (props.exists("faodel-config-replace")) {
137
138 faodel_config.Append(props.get("faodel-config-replace").get_string());
139 }
140 else {
141
142 // Do some things in common for all setups
143 faodel_config.Append(R"(
144 lunasa.lazy_memory_manager malloc
145 lunasa.eager_memory_manager malloc
146 kelpie.ioms iom-posix
147 kelpie.iom.iom-posix.type posixindividualobjects
148 x)");
149
150 // if there are other fragments the caller wants to add to the Faodel
151 // config, get it before we potentially stand up dirman
152 faodel_config.AppendFromReferences();
153 if (props.exists("faodel-config-append")) {
154 faodel_config.Append(props.get("faodel-config-append").get_string());
155 }
156
157 // Set up IOM if the caller provided a path
158 faodel_config.Append("kelpie.iom.iom-posix.path " + [props]() -> std::string {
159 if (props.exists("faodel-iom-path")) {
160 return props.get("faodel-iom-path").get_string();
161 }
162 else {
163 return "/tmp";
164 }
165 }());
166 resource.append("&iom=iom-posix&behavior=writetoiom");
167
168 //
169 // Figure out the setup based on the resource URI
170 //
171 if (resource.rfind("local:", 0) == 0) {
172
173 // Asking for local kv, no syncstart, no dirman
174 faodel_config.Append(R"(
175 kelpie.type nonet
176 mpisyncstart.enable false
177 )");
178 }
179 else {
180
181 // We aren't local, so we can call syncstart
182 // If we were supplied a kelpie-dirman-nodeid property, we assume we're
183 // being pointed at a dirman that has already been set up. This should be
184 // the job-to-job case, where the dirman root runs in a separate application,
185 // but it's possible for the app to have set up kelpie/dirman itself and wants
186 // to use that.
187 //
188 // If that property isn't present, we assume that we need to configure a dirman
189 // for our own use. Right now we assume any such dirman will be rooted at rank 0
190 // and set up a pool that spans all ranks.
191
192 faodel_config.Append(R"(
193 kelpie.type standard
194 mpisyncstart.enable true
195 )");
196 if (props.exists("faodel-dirman-nodeid")) {
197 faodel_config.Append("dirman.root_node " +
198 props.get("faodel-dirman-nodeid").get_string());
199 }
200 else {
201 faodel_config.Append("dirman.root_node_mpi 0");
202 faodel_config.Append("dirman.type centralized");
203 faodel_config.Append("dirman.resources_mpi[] " + resource + " all");
204 }
205
206 if (resource.rfind("rft:", 0) == 0) {
207 // any necessary RFTn URI decorations
208 // Use the rank target if given, else use our rank as a target
209 resource.append("&rank=");
210 if (props.exists("faodel-rft-target-rank")) {
211 resource.append(std::to_string(props.get("faodel-rft-target-rank").get_int()));
212 }
213 else {
214 resource.append(std::to_string(parallel_rank()));
215 }
216 }
217 }
218 }
219 }
220
221 std::once_flag faodel_bootstrap_flag;
222 std::call_once(faodel_bootstrap_flag, [this]() {
223 faodel::mpisyncstart::bootstrap();
224 try {
225 faodel::bootstrap::Start(faodel_config, kelpie::bootstrap);
226 }
227 catch (const std::exception &xc) {
228 std::cerr << "bootstrap exception" << xc.what();
229 std::rethrow_exception(std::current_exception());
230 }
231 });
232
233 // Use the filename to create a bucket in the resource URI
234 // This will help to isolate multiple datasets being used at the same URI
235 resource.append("&bucket=") += filename;
236
237 try {
238 pool = kelpie::Connect(resource);
239 }
240 catch (const std::exception &xc) {
241 std::cerr << "kelpie::Connect exception: " << xc.what();
242 std::rethrow_exception(std::current_exception());
243 }
244 dbState = Ioss::STATE_UNKNOWN;
245 std::cerr << "exiting Iofaodel ctor" << std::endl;
246 }
247
248 DatabaseIO::~DatabaseIO()
249 {
250 // Shut down Faodel gracefully
251 faodel::bootstrap::Finish();
252 }
253
254 bool DatabaseIO::put_properties() const
255 {
256 // TODO add check to see what's been published before publishing again
257 map_properties(*(get_region()), [this](const Ioss::Region &r, const Ioss::GroupingEntity &e,
258 const Ioss::Property &p) {
259 this->pool.Publish(make_key(parallel_rank(), r, e, p), pack_property(r, e, p));
260 });
261 return true;
262 }
263
264 void DatabaseIO::finalize_database() const
265 {
266 if (this->usage() == Ioss::DatabaseUsage::WRITE_RESTART ||
267 this->usage() == Ioss::DatabaseUsage::WRITE_RESULTS ||
268 this->usage() == Ioss::DatabaseUsage::WRITE_HISTORY ||
269 this->usage() == Ioss::DatabaseUsage::WRITE_HEARTBEAT) {
270
271 // write states to LDO
272 pool.Publish(make_states_key(parallel_rank(), *get_region()), pack_states(*get_region()));
273
274 auto sidesets = get_region()->get_sidesets();
275 for (auto sideset : sidesets) {
276 auto sideblocks = sideset->get_side_blocks();
277 for (auto sideblock : sideblocks) {
278 auto sideblock_key =
279 make_sideblock_key(parallel_rank(), *(get_region()), *sideset, *sideblock);
280
281 /* PUBLISH the SideBlocks that the SideSet references. */
282 auto ldo = pack_sideblock(*sideblock);
283 pool.Publish(sideblock_key, ldo);
284 }
285 }
286
287 auto structuredblocks = get_region()->get_structured_blocks();
288 for (auto structuredblock : structuredblocks) {
289 auto structuredblock_key =
290 make_structuredblock_key(parallel_rank(), *(get_region()), *structuredblock);
291
292 /* PUBLISH the attributes of StructuredBlock */
293 auto ldo = pack_structuredblock(*structuredblock);
294 pool.Publish(structuredblock_key, ldo);
295 }
296
297 // write properties to LDOs and publish
298 this->put_properties();
299 }
300 }
301
302 std::string DatabaseIO::get_format() const { return "faodel"; }
303
304 bool DatabaseIO::begin_state_nl(int /* state */, double /* time */) { return false; }
305
306 bool DatabaseIO::end_state_nl(int /* state */, double /* time */) { return false; }
307
308 void DatabaseIO::read_meta_data_nl()
309 {
310 this->get_step_times_nl();
311
312 this->read_region();
313
314 this->get_edgeblocks();
315 this->get_elemblocks();
316 this->get_faceblocks();
317 this->get_nodeblocks();
318 this->get_structuredblocks();
319
320 this->get_edgesets();
321 this->get_elemsets();
322 this->get_facesets();
323 this->get_nodesets();
324 this->get_sidesets();
325 this->get_commsets();
326 }
327
328 void DatabaseIO::get_step_times_nl()
329 {
330 auto search_key = make_states_search_key(parallel_rank(), *get_region());
331 kelpie::ObjectCapacities oc;
332 pool.List(search_key, &oc);
333 if (oc.keys.size() == 1) {
334 lunasa::DataObject ldo;
335 pool.Need(oc.keys[0], oc.capacities[0], &ldo);
336
337 auto meta = static_cast<Iofaodel::meta_entry_t *>(ldo.GetMetaPtr());
338
339 auto entry = static_cast<Iofaodel::state_entry_t *>(
340 static_cast<void *>(static_cast<char *>(ldo.GetDataPtr()) + meta->value.offset));
341
342 auto data = static_cast<Iofaodel::state_entry_t::basic_type *>(
343 static_cast<void *>(entry->data + entry->value.offset));
344
345 for (size_t state(1); state <= entry->count; state++)
346 get_region()->add_state(data[state - 1]);
347 }
348 // TODO
349 // else {
350 // Report error of not having 1 set of time steps
351 // }
352 }
353
354 std::vector<double> DatabaseIO::get_db_step_times_nl()
355 {
356 std::vector<double> tsteps;
357 auto search_key = make_states_search_key(parallel_rank(), *get_region());
358 kelpie::ObjectCapacities oc;
359 pool.List(search_key, &oc);
360 if (oc.keys.size() == 1) {
361 lunasa::DataObject ldo;
362 pool.Need(oc.keys[0], oc.capacities[0], &ldo);
363
364 auto meta = static_cast<Iofaodel::meta_entry_t *>(ldo.GetMetaPtr());
365
366 auto entry = static_cast<Iofaodel::state_entry_t *>(
367 static_cast<void *>(static_cast<char *>(ldo.GetDataPtr()) + meta->value.offset));
368
369 auto data = static_cast<Iofaodel::state_entry_t::basic_type *>(
370 static_cast<void *>(entry->data + entry->value.offset));
371
372 for (size_t state(1); state <= entry->count; state++)
373 tsteps.push_back(data[state - 1]);
374 }
375 // TODO
376 // else {
377 // Report error of not having 1 set of time steps
378 // }
379
380 return tsteps;
381 }
382
383 void DatabaseIO::read_region()
384 {
385
386 {
387 // Region Properties
388 kelpie::ObjectCapacities oc;
389 auto search_key = property_search_key(parallel_rank(), *(get_region()), *(get_region()));
390 pool.List(search_key, &oc);
391 this->read_entity_properties(oc, *(this->get_region()));
392 }
393
394 {
395 // Region Fields
396 kelpie::ObjectCapacities oc;
397 auto search_key = field_search_key(parallel_rank(), *(get_region()), *(get_region()));
398 pool.List(search_key, &oc);
399 this->read_entity_fields(oc, *(this->get_region()));
400 }
401
402 {
403 // Region TRANSIENT Fields
404 kelpie::ObjectCapacities oc;
405 auto search_key = field_search_key(parallel_rank(), 1, *(get_region()), *(get_region()));
406 pool.List(search_key, &oc);
407 this->read_entity_fields(oc, *(this->get_region()));
408 }
409 }
410
411 void DatabaseIO::read_entity_properties(kelpie::ObjectCapacities oc, Ioss::GroupingEntity &entity)
412 {
413 // TODO do we need to update default properties upon construction?
414 // Properties
415 for (size_t i = 0; i < oc.keys.size(); i++) {
416 lunasa::DataObject ldo;
417 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
418
419 auto meta(static_cast<meta_entry_t *>(ldo.GetMetaPtr()));
420 auto prop = static_cast<Iofaodel::property_entry_t *>(
421 static_cast<void *>(static_cast<char *>(ldo.GetDataPtr()) + meta->value.offset));
422
423 std::string property_name(prop->data + prop->name.offset, prop->name.size);
424
425 auto value_ptr = static_cast<void *>(prop->data + prop->value.offset);
426 if (prop->basic_type == Ioss::Property::BasicType::STRING) {
427 std::string value(prop->data + prop->value.offset, prop->value.size);
428 entity.property_update(property_name, value);
429 }
430 else if (prop->basic_type == Ioss::Property::BasicType::INTEGER) {
431 entity.property_update(property_name, *(reinterpret_cast<int64_t *>(value_ptr)));
432 }
433 else if (prop->basic_type == Ioss::Property::BasicType::REAL) {
434 entity.property_update(property_name, *(reinterpret_cast<double *>(value_ptr)));
435 }
436 }
437 }
438
439 Ioss::Property DatabaseIO::read_property(lunasa::DataObject &ldo)
440 {
441 // Properties
442 auto meta(static_cast<meta_entry_t *>(ldo.GetMetaPtr()));
443 auto prop = static_cast<Iofaodel::property_entry_t *>(
444 static_cast<void *>(static_cast<char *>(ldo.GetDataPtr()) + meta->value.offset));
445
446 std::string property_name(prop->data + prop->name.offset, prop->name.size);
447 Ioss::Property *property = nullptr;
448
449 auto value_ptr = static_cast<void *>(prop->data + prop->value.offset);
450 if (prop->basic_type == Ioss::Property::BasicType::STRING) {
451 std::string value(prop->data + prop->value.offset, prop->value.size);
452 property = new Ioss::Property(property_name, value);
453 }
454 else if (prop->basic_type == Ioss::Property::BasicType::INTEGER) {
455 property = new Ioss::Property(property_name, *(reinterpret_cast<int64_t *>(value_ptr)));
456 }
457 else if (prop->basic_type == Ioss::Property::BasicType::REAL) {
458 property = new Ioss::Property(property_name, *(reinterpret_cast<double *>(value_ptr)));
459 }
460
461 return *property;
462 }
463
464 void DatabaseIO::read_entity_fields(kelpie::ObjectCapacities oc, Ioss::GroupingEntity &entity)
465 {
466 // Fields
467 for (size_t i = 0; i < oc.keys.size(); i++) {
468 lunasa::DataObject ldo;
469
470 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
471
472 auto meta(static_cast<meta_entry_t *>(ldo.GetMetaPtr()));
473
474 auto field = static_cast<field_entry_t *>(
475 static_cast<void *>(static_cast<char *>(ldo.GetDataPtr()) + meta->value.offset));
476
477 std::string field_name(field->data + field->name.offset, field->name.size);
478 std::string field_storage(field->data + field->storage.offset, field->storage.size);
479
480 if (!entity.field_exists(field_name)) {
481 entity.field_add(Ioss::Field(field_name, field->basic_type, field_storage, field->role_type,
482 field->raw_count));
483 }
484 }
485 }
486
487 void DatabaseIO::get_edgeblocks()
488 {
489 std::string type_string("EdgeBlock");
490 kelpie::ObjectCapacities oc;
491 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
492 pool.List(search_key, &oc);
493
494 auto entity_names = get_entity_names(oc.keys, type_string);
495 for (auto entity_name : entity_names) {
496 bool have_entity_count(false);
497 int64_t entity_count(0);
498 bool have_original_edge_type(false);
499 std::string original_edge_type;
500
501 for (size_t i = 0; i < oc.keys.size(); i++) {
502
503 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
504
505 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
506 lunasa::DataObject ldo;
507 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
508 entity_count = property_get_int(ldo);
509 have_entity_count = true;
510 }
511
512 if (oc.keys[i].K2().find("original_edge_type") != std::string::npos) {
513 lunasa::DataObject ldo;
514 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
515 original_edge_type = property_get_int(ldo);
516 have_original_edge_type = true;
517 }
518 }
519 }
520
521 if (have_entity_count && have_original_edge_type) {
522 auto block = new Ioss::EdgeBlock(this, entity_name, original_edge_type, entity_count);
523
524 // Add Properties that aren't created in the CTor
525 auto property_search = property_search_key(parallel_rank(), *(get_region()), *block);
526 kelpie::ObjectCapacities property_oc;
527 pool.List(property_search, &property_oc);
528 this->read_entity_properties(property_oc, *block);
529
530 // Add fields that aren't created in the CTor
531 auto field_search = field_search_key(parallel_rank(), *(get_region()), *block);
532 kelpie::ObjectCapacities field_oc;
533 pool.List(field_search, &field_oc);
534 this->read_entity_fields(field_oc, *block);
535
536 this->get_region()->add(block);
537 }
538 }
539 }
540
541 void DatabaseIO::get_elemblocks()
542 {
543 std::string type_string("ElementBlock");
544 kelpie::ObjectCapacities oc;
545 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
546 pool.List(search_key, &oc);
547
548 auto entity_names = get_entity_names(oc.keys, type_string);
549 for (auto entity_name : entity_names) {
550 bool have_entity_count(false);
551 int64_t entity_count(0);
552 bool have_original_topology_type(false);
553 std::string original_topology_type;
554
555 for (size_t i = 0; i < oc.keys.size(); i++) {
556
557 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
558
559 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
560 lunasa::DataObject ldo;
561 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
562 entity_count = property_get_int(ldo);
563 have_entity_count = true;
564 }
565
566 if (oc.keys[i].K2().find("original_topology_type") != std::string::npos) {
567 lunasa::DataObject ldo;
568 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
569 original_topology_type = property_get_string(ldo);
570 have_original_topology_type = true;
571 }
572 }
573 }
574
575 if (have_entity_count && have_original_topology_type) {
576 auto block =
577 new Ioss::ElementBlock(this, entity_name, original_topology_type, entity_count);
578
579 // Add Properties that aren't created in the CTor
580 auto property_search = property_search_key(parallel_rank(), *(get_region()), *block);
581 kelpie::ObjectCapacities property_oc;
582 pool.List(property_search, &property_oc);
583 this->read_entity_properties(property_oc, *block);
584
585 // Add fields that aren't created in the CTor
586 auto field_search = field_search_key(parallel_rank(), *(get_region()), *block);
587 kelpie::ObjectCapacities field_oc;
588 pool.List(field_search, &field_oc);
589 this->read_entity_fields(field_oc, *block);
590
591 // Add TRANSIENT fields that aren't created in the CTor
592 auto field_search_debug = field_search_key(parallel_rank(), 1, *(get_region()), *block);
593 kelpie::ObjectCapacities field_oc_debug;
594 pool.List(field_search_debug, &field_oc_debug);
595 this->read_entity_fields(field_oc_debug, *block);
596
597 this->get_region()->add(block);
598 }
599 }
600 }
601
602 void DatabaseIO::get_faceblocks()
603 {
604 std::string type_string("FaceBlock");
605 kelpie::ObjectCapacities oc;
606 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
607 pool.List(search_key, &oc);
608
609 auto entity_names = get_entity_names(oc.keys, type_string);
610 for (auto entity_name : entity_names) {
611 bool have_entity_count(false);
612 int64_t entity_count(0);
613 bool have_original_topology_type(false);
614 std::string original_topology_type;
615
616 for (size_t i = 0; i < oc.keys.size(); i++) {
617
618 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
619
620 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
621 lunasa::DataObject ldo;
622 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
623 entity_count = property_get_int(ldo);
624 have_entity_count = true;
625 }
626
627 if (oc.keys[i].K2().find("original_topology_type") != std::string::npos) {
628 lunasa::DataObject ldo;
629 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
630 original_topology_type = property_get_string(ldo);
631 have_original_topology_type = true;
632 }
633 }
634 }
635
636 if (have_entity_count && have_original_topology_type) {
637 auto block = new Ioss::FaceBlock(this, entity_name, original_topology_type, entity_count);
638
639 // Add Properties that aren't created in the CTor
640 auto property_search = property_search_key(parallel_rank(), *(get_region()), *block);
641 kelpie::ObjectCapacities property_oc;
642 pool.List(property_search, &property_oc);
643 this->read_entity_properties(property_oc, *block);
644
645 // Add fields that aren't created in the CTor
646 auto field_search = field_search_key(parallel_rank(), *(get_region()), *block);
647 kelpie::ObjectCapacities field_oc;
648 pool.List(field_search, &field_oc);
649 this->read_entity_fields(field_oc, *block);
650
651 this->get_region()->add(block);
652 }
653 }
654 }
655
656 void DatabaseIO::get_nodeblocks()
657 {
658 std::string type_string("NodeBlock");
659 kelpie::ObjectCapacities oc;
660 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
661 pool.List(search_key, &oc);
662
663 auto entity_names = get_entity_names(oc.keys, type_string);
664 for (auto entity_name : entity_names) {
665 bool have_entity_count(false);
666 int64_t entity_count(0);
667 bool have_component_degree(false);
668 int64_t component_degree(0);
669
670 for (size_t i = 0; i < oc.keys.size(); i++) {
671 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
672
673 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
674 lunasa::DataObject ldo;
675 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
676 entity_count = property_get_int(ldo);
677 have_entity_count = true;
678 }
679
680 if (oc.keys[i].K2().find("component_degree") != std::string::npos) {
681 lunasa::DataObject ldo;
682 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
683 component_degree = property_get_int(ldo);
684 have_component_degree = true;
685 }
686 }
687 }
688
689 if (have_entity_count && have_component_degree) {
690 // Creates a new NodeBlock with default Properties and Fields
691 auto block = new Ioss::NodeBlock(this, entity_name, entity_count, component_degree);
692
693 // Add Properties that aren't created in the CTor
694 auto property_search = property_search_key(parallel_rank(), *(get_region()), *block);
695 kelpie::ObjectCapacities property_oc;
696 pool.List(property_search, &property_oc);
697 this->read_entity_properties(property_oc, *block);
698
699 // Add fields that aren't created in the CTor
700 auto field_search = field_search_key(parallel_rank(), *(get_region()), *block);
701 kelpie::ObjectCapacities field_oc;
702 pool.List(field_search, &field_oc);
703 this->read_entity_fields(field_oc, *block);
704
705 // Add TRANSIENT fields that aren't created in the CTor
706 auto field_search_debug = field_search_key(parallel_rank(), 1, *(get_region()), *block);
707 kelpie::ObjectCapacities field_oc_debug;
708 pool.List(field_search_debug, &field_oc_debug);
709 this->read_entity_fields(field_oc_debug, *block);
710
711 this->get_region()->add(block);
712 }
713 }
714 }
715
716 void DatabaseIO::get_structuredblocks()
717 {
718 std::string type_string("StructuredBlock");
719 kelpie::ObjectCapacities oc;
720 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
721 pool.List(search_key, &oc);
722
723 auto entity_names = get_entity_names(oc.keys, type_string);
724 for (auto entity_name : entity_names) {
725 std::unordered_map<std::string, int> ctor_properties;
726 std::list<std::string> property_names = {
727 "component_degree", "ni", "nj", "nk", "ni_global",
728 "nj_global", "nk_global", "offset_i", "offset_j", "offset_k"};
729
730 for (size_t i = 0; i < oc.keys.size(); i++) {
731 for (auto property_name : property_names) {
732 // NOTE: ordinary find won't work b/c the names of multiple properties share substrings,
733 // e.g., "ni" and "ni_global" (a string find on "ni" will match both)
734 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
735 size_t position = oc.keys[i].K2().rfind(property_name);
736 if (position != std::string::npos &&
737 (position + property_name.size()) == oc.keys[i].K2().size()) {
738 lunasa::DataObject ldo;
739 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
740 ctor_properties[property_name] = property_get_int(ldo);
741 }
742 }
743 }
744 }
745
746 if (ctor_properties.size() != property_names.size()) {
747 fmt::print(
748 stderr,
749 "[ERROR] Unable to reconstruct StructuredBlock ({}): FOUND {} of {} properties\n",
750 entity_name.c_str(), ctor_properties.size(), property_names.size());
751 return;
752 }
753
754 auto block = new Ioss::StructuredBlock(
755 this, entity_name, ctor_properties["component_degree"], ctor_properties["ni"],
756 ctor_properties["nj"], ctor_properties["nk"], ctor_properties["offset_i"],
757 ctor_properties["offset_j"], ctor_properties["offset_k"], ctor_properties["ni_global"],
758 ctor_properties["nj_global"], ctor_properties["nk_global"]);
759
760 // Add attributes that aren't created in the CTor
761 auto attribute_key = make_structuredblock_key(parallel_rank(), *(get_region()), *block);
762 lunasa::DataObject ldo;
763 pool.Need(attribute_key, &ldo);
764 unpack_structuredblock(ldo, *block);
765
766 // Add Properties that aren't created in the CTor
767 auto property_search = property_search_key(parallel_rank(), *(get_region()), *block);
768 kelpie::ObjectCapacities property_oc;
769 pool.List(property_search, &property_oc);
770 this->read_entity_properties(property_oc, *block);
771
772 // Add fields that aren't created in the CTor
773 auto field_search = field_search_key(parallel_rank(), *(get_region()), *block);
774 kelpie::ObjectCapacities field_oc;
775 pool.List(field_search, &field_oc);
776 this->read_entity_fields(field_oc, *block);
777
778 // Add TRANSIENT fields that aren't created in the CTor
779 auto field_search_debug = field_search_key(parallel_rank(), 1, *(get_region()), *block);
780 kelpie::ObjectCapacities field_oc_debug;
781 pool.List(field_search_debug, &field_oc_debug);
782 this->read_entity_fields(field_oc_debug, *block);
783
784 this->get_region()->add(block);
785 }
786 }
787
788 void DatabaseIO::get_edgesets()
789 {
790 std::string type_string("EdgeSet");
791 kelpie::ObjectCapacities oc;
792 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
793 pool.List(search_key, &oc);
794
795 auto entity_names = get_entity_names(oc.keys, type_string);
796 for (auto entity_name : entity_names) {
797 bool have_entity_count(false);
798 int64_t entity_count(0);
799 bool have_component_degree(false);
800
801 for (size_t i = 0; i < oc.keys.size(); i++) {
802
803 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
804
805 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
806 lunasa::DataObject ldo;
807 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
808 entity_count = property_get_int(ldo);
809 have_entity_count = true;
810 }
811 }
812 }
813
814 if (have_entity_count && have_component_degree) {
815 auto entity = new Ioss::EdgeSet(this, entity_name, entity_count);
816
817 // Add Properties that aren't created in the CTor
818 auto property_search = property_search_key(parallel_rank(), *(get_region()), *entity);
819 kelpie::ObjectCapacities property_oc;
820 pool.List(property_search, &property_oc);
821 this->read_entity_properties(property_oc, *entity);
822
823 // Add fields that aren't created in the CTor
824 auto field_search = field_search_key(parallel_rank(), *(get_region()), *entity);
825 kelpie::ObjectCapacities field_oc;
826 pool.List(field_search, &field_oc);
827 this->read_entity_fields(field_oc, *entity);
828
829 this->get_region()->add(entity);
830 }
831 }
832 }
833
834 void DatabaseIO::get_elemsets()
835 {
836 std::string type_string("ElementSet");
837 kelpie::ObjectCapacities oc;
838 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
839 pool.List(search_key, &oc);
840
841 auto entity_names = get_entity_names(oc.keys, type_string);
842 for (auto entity_name : entity_names) {
843 bool have_entity_count(false);
844 int64_t entity_count(0);
845 bool have_component_degree(false);
846
847 for (size_t i = 0; i < oc.keys.size(); i++) {
848
849 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
850
851 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
852 lunasa::DataObject ldo;
853 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
854 entity_count = property_get_int(ldo);
855 have_entity_count = true;
856 }
857 }
858 }
859
860 if (have_entity_count && have_component_degree) {
861 auto entity = new Ioss::ElementSet(this, entity_name, entity_count);
862
863 // Add Properties that aren't created in the CTor
864 auto property_search = property_search_key(parallel_rank(), *(get_region()), *entity);
865 kelpie::ObjectCapacities property_oc;
866 pool.List(property_search, &property_oc);
867 this->read_entity_properties(property_oc, *entity);
868
869 // Add fields that aren't created in the CTor
870 auto field_search = field_search_key(parallel_rank(), *(get_region()), *entity);
871 kelpie::ObjectCapacities field_oc;
872 pool.List(field_search, &field_oc);
873 this->read_entity_fields(field_oc, *entity);
874
875 this->get_region()->add(entity);
876 }
877 }
878 }
879
880 void DatabaseIO::get_facesets()
881 {
882 std::string type_string("FaceSet");
883 kelpie::ObjectCapacities oc;
884 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
885 pool.List(search_key, &oc);
886
887 auto entity_names = get_entity_names(oc.keys, type_string);
888 for (auto entity_name : entity_names) {
889 bool have_entity_count(false);
890 int64_t entity_count(0);
891 bool have_component_degree(false);
892
893 for (size_t i = 0; i < oc.keys.size(); i++) {
894
895 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
896
897 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
898 lunasa::DataObject ldo;
899 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
900 entity_count = property_get_int(ldo);
901 have_entity_count = true;
902 }
903 }
904 }
905
906 if (have_entity_count && have_component_degree) {
907 auto entity = new Ioss::FaceSet(this, entity_name, entity_count);
908
909 // Add Properties that aren't created in the CTor
910 auto property_search = property_search_key(parallel_rank(), *(get_region()), *entity);
911 kelpie::ObjectCapacities property_oc;
912 pool.List(property_search, &property_oc);
913 this->read_entity_properties(property_oc, *entity);
914
915 // Add fields that aren't created in the CTor
916 auto field_search = field_search_key(parallel_rank(), *(get_region()), *entity);
917 kelpie::ObjectCapacities field_oc;
918 pool.List(field_search, &field_oc);
919 this->read_entity_fields(field_oc, *entity);
920
921 this->get_region()->add(entity);
922 }
923 }
924 }
925
926 void DatabaseIO::get_nodesets()
927 {
928 std::string type_string("NodeSet");
929 kelpie::ObjectCapacities oc;
930 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
931 pool.List(search_key, &oc);
932
933 auto entity_names = get_entity_names(oc.keys, type_string);
934 for (auto entity_name : entity_names) {
935 bool have_entity_count(false);
936 int64_t entity_count(0);
937
938 for (size_t i = 0; i < oc.keys.size(); i++) {
939 std::string entity_name_search = "/" + entity_name + "/";
940 if (oc.keys[i].K2().find(entity_name_search) != std::string::npos) {
941
942 if (oc.keys[i].K2().find("entity_count") != std::string::npos) {
943 lunasa::DataObject ldo;
944 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
945 entity_count = property_get_int(ldo);
946 have_entity_count = true;
947 }
948 }
949 }
950
951 if (have_entity_count) {
952 auto entity = new Ioss::NodeSet(this, entity_name, entity_count);
953
954 // Add Properties that aren't created in the CTor
955 auto property_search = property_search_key(parallel_rank(), *(get_region()), *entity);
956 kelpie::ObjectCapacities property_oc;
957 pool.List(property_search, &property_oc);
958 this->read_entity_properties(property_oc, *entity);
959
960 // Add fields that aren't created in the CTor
961 auto field_search = field_search_key(parallel_rank(), *(get_region()), *entity);
962 kelpie::ObjectCapacities field_oc;
963 pool.List(field_search, &field_oc);
964 this->read_entity_fields(field_oc, *entity);
965
966 this->get_region()->add(entity);
967 }
968 }
969 }
970
971 void DatabaseIO::get_sidesets()
972 {
973 std::string type_string("SideSet");
974 kelpie::ObjectCapacities oc;
975 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
976 pool.List(search_key, &oc);
977
978 auto entity_names = get_entity_names(oc.keys, type_string);
979 for (auto entity_name : entity_names) {
980 auto entity = new Ioss::SideSet(this, entity_name);
981
982 // Add Properties that aren't created in the CTor
983 auto property_search = property_search_key(parallel_rank(), *(get_region()), *entity);
984 kelpie::ObjectCapacities property_oc;
985 pool.List(property_search, &property_oc);
986 this->read_entity_properties(property_oc, *entity);
987
988 // Add fields that aren't created in the CTor
989 auto field_search = field_search_key(parallel_rank(), *(get_region()), *entity);
990 kelpie::ObjectCapacities field_oc;
991 pool.List(field_search, &field_oc);
992 this->read_entity_fields(field_oc, *entity);
993
994 // FIND the SideBlocks that this SideSet references
995 auto sideblocks_key = sideblocks_search_key(parallel_rank(), *(get_region()), *entity);
996 kelpie::ObjectCapacities sideblocks_search_oc;
997 pool.List(sideblocks_key, &sideblocks_search_oc);
998
999 for (size_t i = 0; i < sideblocks_search_oc.Size(); i++) {
1000 lunasa::DataObject ldo;
1001 pool.Need(sideblocks_search_oc.keys[i], sideblocks_search_oc.capacities[i], &ldo);
1002 int64_t entity_count = unpack_sideblocks(ldo);
1003
1004 auto sideblock_name = get_entity_name(sideblocks_search_oc.keys[i], "SideBlock");
1005 auto property_key = make_property_key(parallel_rank(), *(get_region()), "SideBlock",
1006 sideblock_name, "STRING", "topology_type");
1007 lunasa::DataObject property_ldo;
1008 pool.Need(property_key, &property_ldo);
1009 Ioss::Property topo_property = this->read_property(property_ldo);
1010
1011 auto parent_property_key =
1012 make_property_key(parallel_rank(), *(get_region()), "SideBlock", sideblock_name,
1013 "STRING", "parent_topology_type");
1014 lunasa::DataObject parent_property_ldo;
1015 pool.Need(parent_property_key, &parent_property_ldo);
1016 Ioss::Property parent_topo_property = this->read_property(parent_property_ldo);
1017
1018 auto sideblock = new Ioss::SideBlock(this, sideblock_name, topo_property.get_string(),
1019 parent_topo_property.get_string(), entity_count);
1020
1021 // Add Properties that aren't created in the CTor
1022 auto sideblock_property_search =
1023 property_search_key(parallel_rank(), *(get_region()), *sideblock);
1024 kelpie::ObjectCapacities sideblock_property_oc;
1025 pool.List(sideblock_property_search, &sideblock_property_oc);
1026 this->read_entity_properties(sideblock_property_oc, *sideblock);
1027
1028 // Add fields that aren't created in the CTor
1029 auto sideblock_field_search =
1030 field_search_key(parallel_rank(), *(get_region()), *sideblock);
1031 kelpie::ObjectCapacities sideblock_field_oc;
1032 pool.List(sideblock_field_search, &sideblock_field_oc);
1033 this->read_entity_fields(sideblock_field_oc, *sideblock);
1034
1035 entity->add(sideblock);
1036 }
1037
1038 this->get_region()->add(entity);
1039 }
1040 }
1041
1042 void DatabaseIO::get_commsets()
1043 {
1044 std::string type_string("CommSet");
1045 kelpie::ObjectCapacities oc;
1046 auto search_key = entity_search_key(parallel_rank(), *(get_region()), type_string);
1047 pool.List(search_key, &oc);
1048
1049 auto entity_names = get_entity_names(oc.keys, type_string);
1050 for (auto entity_name : entity_names) {
1051 bool have_entity_count(false);
1052 int64_t entity_count(0);
1053 bool have_entity_type(false);
1054 std::string entity_type("");
1055
1056 for (size_t i = 0; i < oc.keys.size(); i++) {
1057 if (oc.keys[i].K2().find(entity_name) != std::string::npos) {
1058 /* Check if we have all of the necessary attributes */
1059 if (have_entity_type && have_entity_count)
1060 break;
1061
1062 if (!have_entity_count) {
1063 size_t position = oc.keys[i].K2().rfind("entity_count");
1064 if (position != std::string::npos) {
1065 lunasa::DataObject ldo;
1066 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
1067 entity_count = property_get_int(ldo);
1068 have_entity_count = true;
1069 }
1070 }
1071
1072 if (!have_entity_type) {
1073 size_t position = oc.keys[i].K2().rfind("entity_type");
1074 if (position != std::string::npos) {
1075 lunasa::DataObject ldo;
1076 pool.Need(oc.keys[i], oc.capacities[i], &ldo);
1077 entity_type = property_get_string(ldo);
1078 have_entity_type = true;
1079 }
1080 }
1081 }
1082 }
1083
1084 if (!have_entity_type) {
1085 fmt::print(stderr, "[ERROR] Unable to reconstruct CommSet (entity_type NOT found)\n");
1086 return;
1087 }
1088
1089 if (!have_entity_count) {
1090 fmt::print(stderr, "[ERROR] Unable to reconstruct CommSet (entity_count NOT found)\n");
1091 return;
1092 }
1093
1094 auto commset = new Ioss::CommSet(this, entity_name, entity_type, entity_count);
1095
1096 // Add Properties that aren't created in the CTor
1097 auto property_search = property_search_key(parallel_rank(), *(get_region()), *commset);
1098 kelpie::ObjectCapacities property_oc;
1099 pool.List(property_search, &property_oc);
1100 this->read_entity_properties(property_oc, *commset);
1101
1102 // Add fields that aren't created in the CTor
1103 auto field_search = field_search_key(parallel_rank(), *(get_region()), *commset);
1104 kelpie::ObjectCapacities field_oc;
1105 pool.List(field_search, &field_oc);
1106 this->read_entity_fields(field_oc, *commset);
1107
1108 // Add TRANSIENT fields that aren't created in the CTor
1109 auto field_search_transient = field_search_key(parallel_rank(), 1, *(get_region()), *commset);
1110 kelpie::ObjectCapacities field_oc_transient;
1111 pool.List(field_search_transient, &field_oc_transient);
1112 this->read_entity_fields(field_oc_transient, *commset);
1113
1114 this->get_region()->add(commset);
1115 }
1116 }
1117
1118 void DatabaseIO::read_communication_metadata() {}
1119
1120 int64_t DatabaseIO::get_field_internal(const Ioss::Region *reg, const Ioss::Field &field,
1121 void *data, size_t data_size) const
1122 {
1123 return get_field_internal(*reg, field, data, data_size);
1124 ;
1125 }
1126 int64_t DatabaseIO::get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field,
1127 void *data, size_t data_size) const
1128 {
1129 return get_field_internal(*nb, field, data, data_size);
1130 ;
1131 }
1132 int64_t DatabaseIO::get_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field,
1133 void *data, size_t data_size) const
1134 {
1135 return get_field_internal(*nb, field, data, data_size);
1136 ;
1137 }
1138 int64_t DatabaseIO::get_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field,
1139 void *data, size_t data_size) const
1140 {
1141 return get_field_internal(*nb, field, data, data_size);
1142 ;
1143 }
1144 int64_t DatabaseIO::get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field,
1145 void *data, size_t data_size) const
1146 {
1147 return get_field_internal(*eb, field, data, data_size);
1148 ;
1149 }
1150 int64_t DatabaseIO::get_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field,
1151 void *data, size_t data_size) const
1152 {
1153 return get_field_internal(*fb, field, data, data_size);
1154 ;
1155 }
1156 int64_t DatabaseIO::get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field,
1157 void *data, size_t data_size) const
1158 {
1159 return get_field_internal(*ns, field, data, data_size);
1160 ;
1161 }
1162 int64_t DatabaseIO::get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field,
1163 void *data, size_t data_size) const
1164 {
1165 return get_field_internal(*ns, field, data, data_size);
1166 ;
1167 }
1168 int64_t DatabaseIO::get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field,
1169 void *data, size_t data_size) const
1170 {
1171 return get_field_internal(*ns, field, data, data_size);
1172 ;
1173 }
1174 int64_t DatabaseIO::get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field,
1175 void *data, size_t data_size) const
1176 {
1177 return get_field_internal(*ns, field, data, data_size);
1178 ;
1179 }
1180 int64_t DatabaseIO::get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field,
1181 void *data, size_t data_size) const
1182 {
1183 return get_field_internal(*fs, field, data, data_size);
1184 ;
1185 }
1186 int64_t DatabaseIO::get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field,
1187 void *data, size_t data_size) const
1188 {
1189 return get_field_internal(*cs, field, data, data_size);
1190 ;
1191 }
1192 int64_t DatabaseIO::get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
1193 void *data, size_t data_size) const
1194 {
1195 // Field::raw_count() should be the same for all mesh_model_coords* fields. It refers to
1196 // the number of types of type SCALAR or VECTOR_3D etc.
1197 // The number of double values is the raw_count() * Field::raw_storage().component_count()
1198 if (field.get_name() == "mesh_model_coordinates" &&
1199 field.get_role() == Ioss::Field::RoleType::MESH) {
1200
1201 size_t num_to_get = field.verify(data_size);
1202 auto component_data_size = field.get_size() / this->spatial_dimension();
1203 double *data_ptr = static_cast<double *>(data);
1204 // The role for all mesh_model_coords should be Ioss::Field::RoleType::MESH
1205 auto role = field.get_role();
1206
1207 auto dim = this->spatial_dimension();
1208 std::vector<double> data_x(num_to_get);
1209 std::vector<double> data_y((dim > 1) ? num_to_get : 0);
1210 std::vector<double> data_z((dim > 2) ? num_to_get : 0);
1211
1212 {
1213 auto field_x =
1214 Ioss::Field("mesh_model_coordinates_x", field.get_type(), "scalar", role, num_to_get);
1215 this->get_field_internal(*sb, field_x, Data(data_x), component_data_size);
1216 }
1217
1218 if (dim > 1) {
1219 auto field_y =
1220 Ioss::Field("mesh_model_coordinates_y", field.get_type(), "scalar", role, num_to_get);
1221 this->get_field_internal(*sb, field_y, Data(data_y), component_data_size);
1222 }
1223
1224 if (dim > 2) {
1225 auto field_z =
1226 Ioss::Field("mesh_model_coordinates_z", field.get_type(), "scalar", role, num_to_get);
1227 this->get_field_internal(*sb, field_z, Data(data_z), component_data_size);
1228 }
1229
1230 size_t index(0);
1231 for (auto id(0); id < field.raw_count(); ++id) {
1232 data_ptr[index++] = data_x[id];
1233 if (dim > 1)
1234 data_ptr[index++] = data_y[id];
1235 if (dim > 2)
1236 data_ptr[index++] = data_z[id];
1237 }
1238 }
1239 else
1240 return get_field_internal(*sb, field, data, data_size);
1241 ;
1242 }
1243 int64_t DatabaseIO::get_field_internal(const Ioss::Assembly *a, const Ioss::Field &field,
1244 void *data, size_t data_size) const
1245 {
1246 return 0;
1247 }
1248 int64_t DatabaseIO::get_field_internal(const Ioss::Blob *b, const Ioss::Field &field, void *data,
1249 size_t data_size) const
1250 {
1251 return 0;
1252 }
1253 int64_t DatabaseIO::put_field_internal(const Ioss::Region *reg, const Ioss::Field &field,
1254 void *data, size_t data_size) const
1255 {
1256 return put_field_internal(*reg, field, data, data_size);
1257 ;
1258 }
1259 int64_t DatabaseIO::put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field,
1260 void *data, size_t data_size) const
1261 {
1262 return put_field_internal(*nb, field, data, data_size);
1263 ;
1264 }
1265 int64_t DatabaseIO::put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field,
1266 void *data, size_t data_size) const
1267 {
1268 return put_field_internal(*eb, field, data, data_size);
1269 ;
1270 }
1271 int64_t DatabaseIO::put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field,
1272 void *data, size_t data_size) const
1273 {
1274 return put_field_internal(*nb, field, data, data_size);
1275 ;
1276 }
1277 int64_t DatabaseIO::put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field,
1278 void *data, size_t data_size) const
1279 {
1280 return put_field_internal(*eb, field, data, data_size);
1281 ;
1282 }
1283 int64_t DatabaseIO::put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field,
1284 void *data, size_t data_size) const
1285 {
1286 return put_field_internal(*fb, field, data, data_size);
1287 ;
1288 }
1289 int64_t DatabaseIO::put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field,
1290 void *data, size_t data_size) const
1291 {
1292 return put_field_internal(*ns, field, data, data_size);
1293 ;
1294 }
1295 int64_t DatabaseIO::put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field,
1296 void *data, size_t data_size) const
1297 {
1298 return put_field_internal(*ns, field, data, data_size);
1299 ;
1300 }
1301 int64_t DatabaseIO::put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field,
1302 void *data, size_t data_size) const
1303 {
1304 return put_field_internal(*ns, field, data, data_size);
1305 ;
1306 }
1307 int64_t DatabaseIO::put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field,
1308 void *data, size_t data_size) const
1309 {
1310 return put_field_internal(*ns, field, data, data_size);
1311 ;
1312 }
1313 int64_t DatabaseIO::put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field,
1314 void *data, size_t data_size) const
1315 {
1316 return put_field_internal(*fs, field, data, data_size);
1317 ;
1318 }
1319 int64_t DatabaseIO::put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field,
1320 void *data, size_t data_size) const
1321 {
1322 return put_field_internal(*cs, field, data, data_size);
1323 ;
1324 }
1325 int64_t DatabaseIO::put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
1326 void *data, size_t data_size) const
1327 {
1328 return put_field_internal(*sb, field, data, data_size);
1329 ;
1330 }
1331 int64_t DatabaseIO::put_field_internal(const Ioss::Assembly *a, const Ioss::Field &field,
1332 void *data, size_t data_size) const
1333 {
1334 return 0;
1335 }
1336 int64_t DatabaseIO::put_field_internal(const Ioss::Blob *b, const Ioss::Field &field, void *data,
1337 size_t data_size) const
1338 {
1339 return 0;
1340 }
1341
1342 int64_t DatabaseIO::get_field_internal(const Ioss::GroupingEntity &e, const Ioss::Field &f,
1343 void *data, size_t data_size) const
1344 {
1345 lunasa::DataObject ldo;
1346 kelpie::Key k = make_key(parallel_rank(), *(get_region()), e, f);
1347 pool.Need(k, &ldo);
1348
1349 /*
1350 unpack the LDO to retrieve the field data (user data) and set the output variables
1351 according to the field type information
1352 */
1353
1354 auto meta_ptr(static_cast<meta_entry_t *>(ldo.GetMetaPtr()));
1355
1356 auto field_ptr(static_cast<field_entry_t *>(
1357 static_cast<void *>(static_cast<char *>(ldo.GetDataPtr()) + meta_ptr->value.offset)));
1358
1359 // TODO what other checks do we need here?
1360 if (data_size != field_ptr->value.size)
1361 return 1;
1362
1363 std::memcpy(data, static_cast<void *>(field_ptr->data + field_ptr->value.offset),
1364 field_ptr->value.size);
1365
1366 return 0;
1367 }
1368
1369 int64_t DatabaseIO::put_field_internal(const Ioss::GroupingEntity &e, const Ioss::Field &f,
1370 void *data, size_t data_size) const
1371 {
1372 auto key = make_key(parallel_rank(), *(get_region()), e, f);
1373 auto ldo = pack_field(*(get_region()), e, f, data, data_size);
1374 pool.Publish(key, ldo);
1375 return 0;
1376 }
1377
1378 } // namespace Iofaodel