IOSS 2.0
Loading...
Searching...
No Matches
Iotm_TextMesh.h
Go to the documentation of this file.
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#pragma once
8
9#include "Ioss_CodeTypes.h"
10#include "Ioss_EntityType.h" // for EntityType
11#include "Ioss_Region.h"
12#include <cstddef> // for size_t
13#include <cstdint> // for int64_t
14#include <map> // for map, etc
15#include <set>
16#include <string> // for string
17#include <unordered_map>
18#include <utility> // for pair
19#include <vector> // for vector
20
29#include "Iotm_TextMeshUtils.h"
30#include "iotm_export.h"
31
32namespace Iotm {
33 using EntityId = int64_t;
48
49 struct IOTM_EXPORT BlockPartition
50 {
51 size_t offset;
52 std::string name;
53 std::set<EntityId> elemIds;
54
55 BlockPartition() : offset(0), name("") {}
56
57 BlockPartition(size_t offset_, const std::string &name_, const std::set<EntityId> &elemIds_)
58 : offset(offset_), name(name_), elemIds(elemIds_)
59 {
60 }
61 };
62
63 class IOTM_EXPORT TextMesh
64 {
65 public:
66 explicit TextMesh(const std::string &parameters, IOSS_MAYBE_UNUSED int proc_count = 1,
67 int my_proc = 0);
68 explicit TextMesh(int proc_count = 1, int my_proc = 0);
69 TextMesh();
70 TextMesh(const TextMesh &) = delete;
71 TextMesh &operator=(const TextMesh &) = delete;
72
73 virtual ~TextMesh() = default;
74
75 /**
76 * Return number of nodes in the entire model.
77 */
78 virtual int64_t node_count() const;
79
80 /**
81 * Return number of nodes on this processor.
82 */
83 virtual int64_t node_count_proc() const;
84
85 /**
86 * Return number of element blocks in the entire model.
87 */
88 virtual int64_t block_count() const;
89
90 /**
91 * Return number of nodesets in the entire model.
92 */
93 virtual int64_t nodeset_count() const;
94
95 /**
96 * Return number of nodeset nodes on nodeset 'id'
97 */
98 int64_t nodeset_node_count(EntityId id) const;
99
100 /**
101 * Return number of nodeset nodes on nodeset 'id' on the current processor
102 */
103 virtual int64_t nodeset_node_count_proc(EntityId id) const;
104
105 /**
106 * Return number of sidesets in the entire model.
107 */
108 virtual int64_t sideset_count() const;
109
110 /**
111 * Return number of sideset 'sides' on sideset 'id'
112 */
113 int64_t sideset_side_count(EntityId id) const;
114
115 /**
116 * Return number of sideset 'sides' on sideset 'id' on the current
117 * processor.
118 */
119 virtual int64_t sideset_side_count_proc(EntityId id) const;
120
121 /**
122 * Return number of sideblock 'sides' on sideset 'id' and sideblock 'sideBlockName'
123 */
124 int64_t sideblock_side_count(EntityId id, const std::string &sideBlockName) const;
125
126 /**
127 * Return number of sideset 'sides' on sideset 'id' and sideblock 'sideBlockName' on the current
128 * processor.
129 */
130 virtual int64_t sideblock_side_count_proc(EntityId id, const std::string &sideBlockName) const;
131
132 /**
133 * Return number of elements in all element blocks in the model.
134 */
135 virtual int64_t element_count() const;
136
137 /**
138 * Return number of elements in all element blocks on this processor.
139 */
140 int64_t element_count_proc() const;
141
142 int64_t timestep_count() const { return m_timestepCount; }
143 /**
144 * Return number of elements in the element block with id
145 * 'block_number'.
146 */
147 virtual int64_t element_count(EntityId block_number) const;
148
149 /**
150 * Return number of elements on this processor in the element
151 * block with id 'block_number'.
152 */
153 int64_t element_count_proc(EntityId block_number) const;
154
155 /**
156 * Return number of assemblies in the entire model.
157 */
158 int64_t assembly_count() const;
159
160 /**
161 * Returns pair containing "topology type string" and "number of
162 * nodes / element". The topology type string will be "hex8" for
163 * the hex element block and "shell4" for the shell element blocks.
164 */
165 virtual std::pair<std::string, int> topology_type(EntityId block_number) const;
166
167 virtual int64_t communication_node_count_proc() const;
168 virtual void node_communication_map(Ioss::Int64Vector &map, std::vector<int> &proc);
169 virtual void owning_processor(int *owner, EntityId num_node);
170 /**
171 * Fill the passed in 'map' argument with the node map
172 * "map[local_position] = global_id" for the nodes on this
173 * processor.
174 */
175 virtual void node_map(Ioss::Int64Vector &map) const;
176 virtual void node_map(Ioss::IntVector &map) const;
177
178 /**
179 * Fill the passed in 'map' argument with the element map
180 * "map[local_position] = global_id" for the elements on this
181 * processor in block "block_number".
182 */
183 virtual void element_map(EntityId block_number, Ioss::Int64Vector &map) const;
184 virtual void element_map(EntityId block_number, Ioss::IntVector &map) const;
185
186 /**
187 * Fill the passed in 'map' argument with the element map
188 * "map[local_position] = global_id" for all elements on this
189 * processor
190 */
191 virtual void element_map(Ioss::Int64Vector &map) const;
192 virtual void element_map(Ioss::IntVector &map) const;
193
194 /**
195 * Return the connectivity for the elements on this processor in
196 * the block with id 'block_number'. If the elements in this block
197 * have 'npe' nodes per element, then the first 'npe' entries in
198 * the 'conn' vector will be the nodal connectivity for the first
199 * element; the next 'npe' entries are the nodal connectivity for
200 * the second element. The 'connect' vector will be resized to the
201 * size required to contain the nodal connectivity for the
202 * specified block; all information in 'connect' will be overwritten.
203 */
204 void connectivity(EntityId block_number, Ioss::Int64Vector &connect) const;
205 void connectivity(EntityId block_number, Ioss::IntVector &connect) const;
206 void connectivity(EntityId block_number, EntityId *connect) const;
207 virtual void connectivity(EntityId block_number, int *connect) const;
208
209 /**
210 * Return the coordinates for all nodes on this processor. The
211 * first 3 entries in the 'coord' vector are the x, y, and z
212 * coordinates of the first node, etc. The 'coord' vector will be
213 * resized to the size required to contain the nodal coordinates;
214 * all information in 'coord' will be overwritten.
215 */
216 virtual void coordinates(std::vector<double> &coord) const;
217 virtual void coordinates(double *coord) const;
218
219 /**
220 * Return the coordinates for all nodes on this processor in
221 * separate vectors. The vectors will be resized to the size
222 * required to contain the nodal coordinates; all information in
223 * the vectors will be overwritten.
224 */
225 virtual void coordinates(std::vector<double> &x, std::vector<double> &y,
226 std::vector<double> &z) const;
227
228 /**
229 * Return the coordinates for component 'comp' (1=x, 2=y, 3=z)
230 * for all nodes on this processor. The
231 * vector will be resized to the size required to contain the
232 * nodal coordinates; all information in the vector will be
233 * overwritten.
234 * It is an error to request the coordinates via this function
235 * if a rotation is defined.
236 */
237 virtual void coordinates(int component, std::vector<double> &xyz) const;
238 virtual void coordinates(int component, double *xyz) const;
239
240 /**
241 * Return the list of nodes in nodeset 'id' on this processor.
242 * The 'nodes' vector will be resized to the size required to
243 * contain the node list. The ids are global ids.
244 */
245 virtual void nodeset_nodes(EntityId id, Ioss::Int64Vector &nodes) const;
246
247 /**
248 * Return the list of the face/ordinal pairs
249 * "elem_sides[local_position] = element global_id" and
250 * "elem_sides[local_position+1] = element local face id (0-based)"
251 * for the faces in sideset 'id' on this
252 * processor. The 'elem_sides' vector will be resized to the size
253 * required to contain the list. The element ids are global ids,
254 * the side ordinal is 0-based.
255 */
256 virtual void sideset_elem_sides(EntityId id, Ioss::Int64Vector &elemSides) const;
257 virtual void sideblock_elem_sides(EntityId sidesetId, const std::string &sideBlockName,
258 Ioss::Int64Vector &elemSides) const;
259
260 virtual std::vector<std::string> sideset_touching_blocks(EntityId set_id) const;
261
263 {
264 return m_variableCount.find(type) != m_variableCount.end()
265 ? m_variableCount.find(type)->second
266 : 0;
267 }
268
269 // Element block query
270 std::vector<std::string> get_part_names() const;
271 EntityId get_part_id(const std::string &name) const;
272
273 // Nodeset query
274 std::vector<std::string> get_nodeset_names() const;
275 std::string get_nodeset_name(EntityId id) const;
276 EntityId get_nodeset_id(const std::string &name) const;
277
278 // Sideset query
279 std::vector<std::string> get_sideset_names() const;
280 std::string get_sideset_name(EntityId id) const;
281 EntityId get_sideset_id(const std::string &name) const;
282
283 // Assembly query
284 std::vector<std::string> get_assembly_names() const;
285 std::string get_assembly_name(EntityId id) const;
286 EntityId get_assembly_id(const std::string &name) const;
287 Ioss::EntityType get_assembly_type(const std::string &name) const;
288 std::vector<std::string> get_assembly_members(const std::string &name) const;
289
290 static Ioss::EntityType assembly_type_to_entity_type(const AssemblyType type);
291
292 void update_block_omissions_from_assemblies(Ioss::Region *region,
293 std::vector<std::string> &assemblyOmissions,
294 std::vector<std::string> &assemblyInclusions,
295 std::vector<std::string> &blockOmissions,
296 std::vector<std::string> &blockInclusions) const;
297
298 unsigned spatial_dimension() const;
299
300 std::vector<SideBlockInfo> get_side_block_info_for_sideset(const std::string &name) const;
301 std::vector<size_t> get_local_side_block_indices(const std::string &name,
302 const SideBlockInfo &info) const;
303 SplitType get_sideset_split_type(const std::string &name) const;
304
305 void compute_block_membership(const std::string &sideSetName, const std::string &sideBlockName,
306 std::vector<std::string> &block_membership) const;
307
308 private:
309 template <typename INT>
310 void raw_element_map(EntityId block_number, std::vector<INT> &map) const;
311 template <typename INT> void raw_element_map(std::vector<INT> &map) const;
312 template <typename INT> void raw_connectivity(EntityId block_number, INT *connect) const;
313 template <typename INT> void raw_node_map(std::vector<INT> &map) const;
314
315 void set_variable_count(const std::string &type, size_t count);
316
317 void initialize();
318
319 void build_part_to_topology_map();
320 void build_block_partition_map();
321 void build_element_connectivity_map();
322
323 std::vector<EntityId> get_part_ids(const std::vector<std::string> &partNames);
324 std::vector<size_t> get_part_offsets(const std::vector<EntityId> &partIds);
325
326 Topology get_topology_for_part(EntityId id) const;
327
328 std::set<EntityId> get_local_element_ids_for_block(EntityId id) const;
329
330 std::set<std::string> get_blocks_touched_by_sideset(const SidesetData *sideset) const;
331
332 void compute_block_membership_impl(const SidesetData &sidesetData,
333 const SideBlockInfo &sideBlock,
334 std::vector<std::string> &sideBlockTouchingBlockParts) const;
335
336 size_t m_myProcessor{0};
337
338 size_t m_timestepCount{0};
339 std::map<Ioss::EntityType, size_t> m_variableCount;
340
342
344
345 std::unordered_map<std::string, Topology> m_partToTopology;
346
347 std::unordered_map<EntityId, BlockPartition> m_blockPartition;
348
349 std::unordered_map<EntityId, std::vector<EntityId>> m_elementConnectivity;
350 };
351} // namespace Iotm
#define IOSS_MAYBE_UNUSED
Definition Ioss_CodeTypes.h:54
A grouping entity that contains other grouping entities.
Definition Ioss_Region.h:93
Definition Iotm_TextMesh.h:64
virtual ~TextMesh()=default
ErrorHandler m_errorHandler
Definition Iotm_TextMesh.h:343
std::unordered_map< EntityId, std::vector< EntityId > > m_elementConnectivity
Definition Iotm_TextMesh.h:349
TextMeshData m_data
Definition Iotm_TextMesh.h:341
std::unordered_map< EntityId, BlockPartition > m_blockPartition
Definition Iotm_TextMesh.h:347
TextMesh(const TextMesh &)=delete
std::unordered_map< std::string, Topology > m_partToTopology
Definition Iotm_TextMesh.h:345
std::map< Ioss::EntityType, size_t > m_variableCount
Definition Iotm_TextMesh.h:339
int64_t timestep_count() const
Definition Iotm_TextMesh.h:142
size_t get_variable_count(Ioss::EntityType type) const
Definition Iotm_TextMesh.h:262
TextMesh & operator=(const TextMesh &)=delete
Definition Iotm_TextMeshTopologyMapping.h:33
Definition Iotm_TextMeshDataTypes.h:312
Definition Iotm_TextMeshDataTypes.h:214
Definition Iotm_TextMeshUtils.h:566
std::vector< int64_t > Int64Vector
Definition Ioss_CodeTypes.h:22
std::vector< int > IntVector
Definition Ioss_CodeTypes.h:21
EntityType
The particular type of GroupingEntity.
Definition Ioss_EntityType.h:12
std::function< void(const std::ostringstream &)> ErrorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:35
AssemblyType
Definition Iotm_TextMeshAssembly.h:39
SplitType
Definition Iotm_TextMeshSidesetSplitter.h:49
A namespace for the textmesh database format.
Definition Iotm_DatabaseIO.C:95
text_mesh::ErrorHandler ErrorHandler
Definition Iotm_TextMesh.h:44
int64_t EntityId
Definition Iotm_TextMesh.h:33
Definition Iotm_TextMesh.h:50
BlockPartition(size_t offset_, const std::string &name_, const std::set< EntityId > &elemIds_)
Definition Iotm_TextMesh.h:57
std::set< EntityId > elemIds
Definition Iotm_TextMesh.h:53
size_t offset
Definition Iotm_TextMesh.h:51
std::string name
Definition Iotm_TextMesh.h:52
BlockPartition()
Definition Iotm_TextMesh.h:55
Definition Iotm_TextMeshAssembly.h:56
Definition Iotm_TextMeshDataTypes.h:288
Definition Iotm_TextMeshDataTypes.h:277
Definition Iotm_TextMeshNodeset.h:41
Definition Iotm_TextMeshSidesetSplitter.h:39
Definition Iotm_TextMeshSidesetSplitter.h:64
Definition Iotm_TextMeshDataTypes.h:315