| 1 |
// Copyright(C) 1999-2020, 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, etc |
| 8 |
#include "exodusII.h" // for ex_set, etc |
| 9 |
#include "fmt/format.h" |
| 10 |
#include "iqsort.h" // for index_qsort |
| 11 |
#include "node_set.h" |
| 12 |
#include "smart_assert.h" // for SMART_ASSERT |
| 13 |
#include <cstdlib> // for exit |
| 14 |
#include <vector> // for vector |
| 15 |
|
| 16 |
template <typename INT> Node_Set<INT>::Node_Set() : Exo_Entity() {} |
| 17 |
|
| 18 |
template <typename INT> Node_Set<INT>::Node_Set(int file_id, size_t id) : Exo_Entity(file_id, id) {} |
| 19 |
|
| 20 |
template <typename INT> |
| 21 |
Node_Set<INT>::Node_Set(int file_id, size_t id, size_t nnodes, size_t ndfs) |
| 22 |
: Exo_Entity(file_id, id, nnodes), num_dist_factors(ndfs) |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
template <typename INT> Node_Set<INT>::~Node_Set() |
| 27 |
{ |
| 28 |
delete[] nodes; |
| 29 |
delete[] nodeIndex; |
| 30 |
delete[] dist_factors; |
| 31 |
} |
| 32 |
|
| 33 |
template <typename INT> EXOTYPE Node_Set<INT>::exodus_type() const { return EX_NODE_SET; } |
| 34 |
|
| 35 |
template <typename INT> const INT *Node_Set<INT>::Nodes() const |
| 36 |
{ |
| 37 |
// See if already loaded... |
| 38 |
if (!nodes) { |
| 39 |
std::vector<INT> tmp; |
| 40 |
load_nodes(tmp); |
| 41 |
} |
| 42 |
return nodes; |
| 43 |
} |
| 44 |
|
| 45 |
template <typename INT> size_t Node_Set<INT>::Node_Id(size_t position) const |
| 46 |
{ |
| 47 |
if (numEntity == 0) { |
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
// See if already loaded... |
| 52 |
if (!nodes) { |
| 53 |
std::vector<INT> tmp; |
| 54 |
load_nodes(tmp); |
| 55 |
} |
| 56 |
SMART_ASSERT(position < numEntity); |
| 57 |
return nodes[nodeIndex[position]]; |
| 58 |
} |
| 59 |
|
| 60 |
template <typename INT> size_t Node_Set<INT>::Node_Index(size_t position) const |
| 61 |
{ |
| 62 |
if (numEntity == 0) { |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
// See if already loaded... |
| 67 |
if (!nodes) { |
| 68 |
std::vector<INT> tmp; |
| 69 |
load_nodes(tmp); |
| 70 |
} |
| 71 |
SMART_ASSERT(position < numEntity); |
| 72 |
SMART_ASSERT(nodeIndex != nullptr); |
| 73 |
return nodeIndex[position]; |
| 74 |
} |
| 75 |
|
| 76 |
template <typename INT> void Node_Set<INT>::apply_map(const std::vector<INT> &node_map) |
| 77 |
{ |
| 78 |
SMART_ASSERT(!node_map.empty()); |
| 79 |
if (nodes != nullptr) { |
| 80 |
delete[] nodes; |
| 81 |
nodes = nullptr; |
| 82 |
delete[] nodeIndex; |
| 83 |
nodeIndex = nullptr; |
| 84 |
} |
| 85 |
load_nodes(node_map); |
| 86 |
} |
| 87 |
|
| 88 |
template <typename INT> void Node_Set<INT>::load_nodes(const std::vector<INT> &node_map) const |
| 89 |
{ |
| 90 |
if (numEntity > 0) { |
| 91 |
nodes = new INT[numEntity]; |
| 92 |
SMART_ASSERT(nodes != nullptr); |
| 93 |
nodeIndex = new INT[numEntity]; |
| 94 |
SMART_ASSERT(nodeIndex != nullptr); |
| 95 |
ex_get_set(fileId, EX_NODE_SET, id_, nodes, nullptr); |
| 96 |
|
| 97 |
if (!node_map.empty()) { |
| 98 |
for (size_t i = 0; i < numEntity; i++) { |
| 99 |
nodes[i] = 1 + node_map[nodes[i] - 1]; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
for (size_t i = 0; i < numEntity; i++) { |
| 104 |
nodeIndex[i] = i; |
| 105 |
} |
| 106 |
if (interFace.nsmap_flag) { |
| 107 |
index_qsort(nodes, nodeIndex, numEntity); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
template <typename INT> const double *Node_Set<INT>::Distribution_Factors() const |
| 113 |
{ |
| 114 |
if ((dist_factors == nullptr) && num_dist_factors > 0) { |
| 115 |
dist_factors = new double[num_dist_factors]; |
| 116 |
SMART_ASSERT(dist_factors != nullptr); |
| 117 |
ex_get_set_dist_fact(fileId, EX_NODE_SET, id_, dist_factors); |
| 118 |
} |
| 119 |
return dist_factors; |
| 120 |
} |
| 121 |
|
| 122 |
template <typename INT> void Node_Set<INT>::Free_Distribution_Factors() const |
| 123 |
{ |
| 124 |
if (dist_factors) { |
| 125 |
delete[] dist_factors; |
| 126 |
dist_factors = nullptr; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
template <typename INT> int Node_Set<INT>::Check_State() const |
| 131 |
{ |
| 132 |
SMART_ASSERT(id_ >= EX_INVALID_ID); |
| 133 |
SMART_ASSERT(!(id_ == EX_INVALID_ID && numEntity > 0)); |
| 134 |
SMART_ASSERT(!(id_ == EX_INVALID_ID && num_dist_factors > 0)); |
| 135 |
SMART_ASSERT(!(id_ == EX_INVALID_ID && nodes)); |
| 136 |
SMART_ASSERT(!(id_ == EX_INVALID_ID && dist_factors)); |
| 137 |
|
| 138 |
return 1; |
| 139 |
} |
| 140 |
|
| 141 |
template <typename INT> void Node_Set<INT>::entity_load_params() |
| 142 |
{ |
| 143 |
std::vector<ex_set> sets(1); |
| 144 |
sets[0].id = id_; |
| 145 |
sets[0].type = EX_NODE_SET; |
| 146 |
sets[0].entry_list = nullptr; |
| 147 |
sets[0].extra_list = nullptr; |
| 148 |
sets[0].distribution_factor_list = nullptr; |
| 149 |
|
| 150 |
int err = ex_get_sets(fileId, 1, Data(sets)); |
| 151 |
|
| 152 |
if (err < 0) { |
| 153 |
Error(fmt::format("Failed to get nodeset parameters for nodeset {}. ! Aborting...\n", id_)); |
| 154 |
} |
| 155 |
|
| 156 |
numEntity = sets[0].num_entry; |
| 157 |
num_dist_factors = sets[0].num_distribution_factor; |
| 158 |
} |
| 159 |
|
| 160 |
template class Node_Set<int>; |
| 161 |
template class Node_Set<int64_t>; |