Debian Codegraph @

packages/seacas/libraries/ioss/src/Ioss_SideSet.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 "Ioss_DatabaseIO.h"
8 #include "Ioss_ElementTopology.h"
9 #include "Ioss_Property.h"
10 #include "Ioss_Region.h"
11 #include "Ioss_SideBlock.h"
12 #include "Ioss_SideSet.h"
13 #include <cstddef>
14 #include <fmt/ostream.h>
15 #include <iosfwd>
16 #include <string>
17 #include <vector>
18
19 #include "Ioss_CodeTypes.h"
20 #include "Ioss_GroupingEntity.h"
21 #include "Ioss_PropertyManager.h"
22 #include "Ioss_Utils.h"
23
24 namespace {
25 std::string id_str() { return {"id"}; }
26 void check_for_duplicate_names(const Ioss::SideSet *sset, const Ioss::SideBlock *side_block)
27 {
28 const std::string &name = side_block->name();
29
30 // See if there is a side_block with this name...
31 const Ioss::SideBlock *old_ge = sset->get_side_block(name);
32
33 if (old_ge != nullptr) {
34 std::string filename = sset->get_database()->get_filename();
35 std::ostringstream errmsg;
36 int64_t id1 = side_block->get_optional_property(id_str(), 0);
37 int64_t id2 = old_ge->get_optional_property(id_str(), 0);
38 fmt::print(errmsg,
39 "\nERROR: There are multiple side blocks with the same name "
40 "defined in side set '{}' in the database file '{}'.\n"
41 "\tBoth {} {} and {} {} are named '{}'. All names must be unique.",
42 sset->name(), filename, side_block->type_string(), id1, old_ge->type_string(), id2,
43 name);
44 IOSS_ERROR(errmsg);
45 }
46 }
47 } // namespace
48
49 namespace Ioss {
50 class Field;
51 } // namespace Ioss
52
53 /** \brief Create a side set with no members initially.
54 *
55 * \param[in] io_database The database associated with the region containing the side set.
56 * \param[in] my_name The side set's name.
57 */
58 Ioss::SideSet::SideSet(Ioss::DatabaseIO *io_database, const std::string &my_name)
59 : Ioss::GroupingEntity(io_database, my_name, 0)
60 {
61 properties.add(Ioss::Property(this, "side_block_count", Ioss::Property::INTEGER));
62 properties.add(Ioss::Property(this, "block_count", Ioss::Property::INTEGER));
63 }
64
65 Ioss::SideSet::SideSet(const Ioss::SideSet &other) : Ioss::GroupingEntity(other)
66 {
67 for (const auto &block : other.sideBlocks) {
68 auto *sb = new Ioss::SideBlock(*block);
69 add(sb);
70 }
71 }
72
73 Ioss::SideSet::~SideSet()
74 {
75 try {
76 for (const auto &sb : sideBlocks) {
77 delete sb;
78 }
79 }
80 catch (...) {
81 }
82 }
83
84 const Ioss::SideBlockContainer &Ioss::SideSet::get_side_blocks() const { return sideBlocks; }
85
86 Ioss::SideBlock *Ioss::SideSet::get_block(size_t which) const
87 {
88 IOSS_FUNC_ENTER(m_);
89 if (which < sideBlocks.size()) {
90 return sideBlocks[which];
91 }
92
93 return nullptr;
94 }
95
96 Ioss::SideBlock *Ioss::SideSet::get_side_block(const std::string &my_name) const
97 {
98 IOSS_FUNC_ENTER(m_);
99 Ioss::SideBlock *ge = nullptr;
100 for (const auto &sb : sideBlocks) {
101 if (sb->name() == my_name) {
102 ge = sb;
103 break;
104 }
105 }
106 return ge;
107 }
108
109 bool Ioss::SideSet::add(Ioss::SideBlock *side_block)
110 {
111 check_for_duplicate_names(this, side_block);
112 IOSS_FUNC_ENTER(m_);
113 sideBlocks.push_back(side_block);
114 side_block->owner_ = this;
115 return true;
116 }
117
118 int64_t Ioss::SideSet::internal_get_field_data(const Ioss::Field &field, void *data,
119 size_t data_size) const
120 {
121 return get_database()->get_field(this, field, data, data_size);
122 }
123
124 int64_t Ioss::SideSet::internal_put_field_data(const Ioss::Field &field, void *data,
125 size_t data_size) const
126 {
127 return get_database()->put_field(this, field, data, data_size);
128 }
129
130 int64_t Ioss::SideSet::internal_get_zc_field_data(const Field &field, void **data,
131 size_t *data_size) const
132 {
133 return get_database()->get_zc_field(this, field, data, data_size);
134 }
135
136 Ioss::Property Ioss::SideSet::get_implicit_property(const std::string &my_name) const
137 {
138 if (my_name == "side_block_count") {
139 return {my_name, static_cast<int>(sideBlocks.size())};
140 }
141 if (my_name == "block_count") {
142 return {my_name, static_cast<int>(sideBlocks.size())};
143 }
144
145 return Ioss::GroupingEntity::get_implicit_property(my_name);
146 }
147
148 int Ioss::SideSet::max_parametric_dimension() const
149 {
150 IOSS_FUNC_ENTER(m_);
151 int max_par_dim = 0;
152 for (const auto &sideblock : sideBlocks) {
153 int parametric_dim = sideblock->topology()->parametric_dimension();
154 if (parametric_dim > max_par_dim) {
155 max_par_dim = parametric_dim;
156 }
157 }
158 if (max_par_dim == 0) {
159 // If the sideset is empty, return the maximum that the parametric dimension
160 // could be...
161 // Faces for 3D model; Edges for 2D model
162 const Ioss::Region *reg = get_database()->get_region();
163 max_par_dim = reg->get_property("spatial_dimension").get_int() - 1;
164 }
165 return max_par_dim;
166 }
167
168 void Ioss::SideSet::block_membership(Ioss::NameList &block_members)
169 {
170 IOSS_FUNC_ENTER(m_);
171 if (blockMembership.empty()) {
172 for (auto &sb : sideBlocks) {
173 Ioss::NameList blocks;
174 sb->block_membership(blocks);
175 blockMembership.insert(blockMembership.end(), blocks.begin(), blocks.end());
176 }
177 Ioss::Utils::uniquify(blockMembership);
178 }
179 block_members = blockMembership;
180 }
181
182 bool Ioss::SideSet::equal_(const SideSet &rhs, const bool /* quiet */) const
183 {
184 std::vector<SideBlock *> lhs_side_blocks = this->sideBlocks;
185 std::vector<SideBlock *> rhs_side_blocks = rhs.sideBlocks;
186
187 // COMPARE SideBlocks
188 for (const auto &lhs_side_block : lhs_side_blocks) {
189 std::vector<SideBlock *>::iterator it;
190 for (it = rhs_side_blocks.begin(); it != rhs_side_blocks.end(); ++it) {
191 if ((*(*it)).operator==(*lhs_side_block)) {
192 break;
193 }
194 }
195
196 if (it == rhs_side_blocks.end()) {
197 // NO match for this side block
198 return false;
199 }
200
201 rhs_side_blocks.erase(it);
202 }
203
204 // COMPARE block membership
205 Ioss::NameList lhs_block_membership = this->blockMembership;
206 Ioss::NameList rhs_block_membership = rhs.blockMembership;
207
208 for (const auto &lhs_block_member : lhs_block_membership) {
209 Ioss::NameList::iterator it;
210 for (it = rhs_block_membership.begin(); it != rhs_block_membership.end(); ++it) {
211 if ((*it) == lhs_block_member) {
212 break;
213 }
214 }
215
216 if (it == rhs_block_membership.end()) {
217 // NO match for this side block
218 return false;
219 }
220
221 rhs_block_membership.erase(it);
222 }
223
224 return true;
225 }
226
227 bool Ioss::SideSet::operator==(const SideSet &rhs) const { return equal_(rhs, false); }
228
229 bool Ioss::SideSet::operator!=(const SideSet &rhs) const { return !(*this == rhs); }
230
231 bool Ioss::SideSet::equal(const SideSet &rhs) const { return equal_(rhs, true); }