Debian Codegraph @

packages/seacas/applications/exodiff/exo_block.C

raw
1 // Copyright(C) 1999-2023 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "ED_SystemInterface.h" // for SystemInterface, interFace
8 #include "exo_block.h"
9 #include "exodusII.h" // for ex_block, etc
10 #include "fmt/ostream.h"
11 #include "smart_assert.h" // for SMART_ASSERT
12 #include <cstdlib> // for exit, nullptr
13 #include <string> // for string, char_traits
14
15 template <typename INT> Exo_Block<INT>::Exo_Block() : Exo_Entity() {}
16
17 template <typename INT>
18 Exo_Block<INT>::Exo_Block(int file_id, size_t exo_block_id) : Exo_Entity(file_id, exo_block_id)
19 {
20 SMART_ASSERT(file_id >= 0);
21 SMART_ASSERT((int)exo_block_id > EX_INVALID_ID);
22
23 initialize(file_id, exo_block_id);
24 }
25
26 template <typename INT>
27 Exo_Block<INT>::Exo_Block(int file_id, size_t id, const char *type, size_t num_e, size_t num_npe)
28 : Exo_Entity(file_id, id, num_e), elmt_type(type), num_nodes_per_elmt(num_npe)
29 {
30 SMART_ASSERT(id > 0);
31 SMART_ASSERT(!elmt_type.empty());
32 SMART_ASSERT(num_npe > 0);
33 }
34
35 template <typename INT> EXOTYPE Exo_Block<INT>::exodus_type() const { return EX_ELEM_BLOCK; }
36
37 template <typename INT> void Exo_Block<INT>::entity_load_params()
38 {
39 int num_attr;
40 ex_block block{};
41 block.id = id_;
42 block.type = EX_ELEM_BLOCK;
43 int err = ex_get_block_param(fileId, &block);
44
45 if (err < 0) {
46 Error("Exo_Block<INT>::entity_load_params(): Failed to get element"
47 " block parameters! Aborting...\n");
48 }
49
50 numEntity = block.num_entry;
51 num_nodes_per_elmt = block.num_nodes_per_entry;
52 num_attr = block.num_attribute;
53 elmt_type = block.topology;
54
55 if (num_nodes_per_elmt < 0 || num_attr < 0) {
56 Error(fmt::format(
57 fmt::runtime("Exo_Block<INT>::entity_load_params(): Data appears corrupt for block {}!\n"
58 "\tnum elmts = {}\n"
59 "\tnum nodes per elmt = {}\n"
60 "\tnum attributes = {}\n"
61 " ... Aborting...\n"),
62 fmt::group_digits(numEntity), num_nodes_per_elmt, num_attr));
63 }
64 }
65
66 template <typename INT> std::string Exo_Block<INT>::Load_Connectivity()
67 {
68 SMART_ASSERT(Check_State());
69
70 if (fileId < 0) {
71 return "ERROR: Invalid file id!";
72 }
73 if (id_ == EX_INVALID_ID) {
74 return "ERROR: Must initialize block parameters first!";
75 }
76 if (!conn.empty()) {
77 conn.clear();
78 }
79
80 if (numEntity && num_nodes_per_elmt) {
81 conn.resize(numEntity * num_nodes_per_elmt);
82
83 int err = ex_get_conn(fileId, EX_ELEM_BLOCK, id_, Data(conn), nullptr, nullptr);
84 if (err < 0) {
85 Error(fmt::format("Exo_Block<INT>::Load_Connectivity(): Call to ex_get_conn returned error "
86 "value! Block id = {}\n"
87 "Aborting...\n",
88 id_));
89 }
90 else if (err > 0) {
91 return fmt::format("WARNING: Number {} returned from call to ex_get_conn()", err);
92 }
93 }
94
95 return "";
96 }
97
98 template <typename INT> std::string Exo_Block<INT>::Free_Connectivity()
99 {
100 conn.clear();
101 SMART_ASSERT(conn.empty());
102 return "";
103 }
104
105 template <typename INT> const INT *Exo_Block<INT>::Connectivity(size_t elmt_index) const
106 {
107 SMART_ASSERT(Check_State());
108
109 if (conn.empty() || elmt_index >= numEntity) {
110 return nullptr;
111 }
112
113 return &conn[elmt_index * num_nodes_per_elmt];
114 }
115
116 template <typename INT> int Exo_Block<INT>::Check_State() const
117 {
118 SMART_ASSERT(id_ >= EX_INVALID_ID);
119 SMART_ASSERT(!(id_ == EX_INVALID_ID && !elmt_type.empty()));
120 SMART_ASSERT(!(id_ == EX_INVALID_ID && num_nodes_per_elmt >= 0));
121 SMART_ASSERT(!(id_ == EX_INVALID_ID && !conn.empty()));
122
123 SMART_ASSERT(!(!conn.empty() && (numEntity == 0 || num_nodes_per_elmt <= 0)));
124
125 return 1;
126 }
127 template class Exo_Block<int>;
128 template class Exo_Block<int64_t>;