7#include "iotm_export.h"
21#include <unordered_map>
36 using ErrorHandler = std::function<void(
const std::ostringstream &)>;
63 set_error_handler([](
const std::ostringstream &errmsg) { default_error_handler(errmsg); });
68 m_partNames.push_back(name);
69 handle_block_part(name);
74 register_part_name(name);
78 unsigned get(
const std::string &name)
const
82 return get_part_id(name);
85 std::string
get(
unsigned id)
const
89 return get_part_name(
id);
104 std::vector<std::string> names;
105 names.reserve(m_parts.size());
107 for (
const auto &iter : m_parts) {
108 names.push_back(iter.second);
114 bool is_registered(
const std::string &name)
const {
return m_ids.count(name) > 0; }
136 assign(name, result.first);
141 unsigned nextPartId = 1;
142 for (
const std::string &name : m_partNames) {
143 if (m_ids.find(name) == m_ids.end()) {
144 while (is_assigned(nextPartId))
147 assign(name, nextPartId);
151 m_idsAssigned =
true;
154 void assign(
const std::string &name,
unsigned id)
const
156 validate_name_and_id(name,
id);
163 if (is_registered(name)) {
164 if (m_ids[name] !=
id) {
165 std::ostringstream errmsg;
166 errmsg <<
"Cannot assign part '" << name <<
"' two different ids: " << m_ids[name]
168 m_errorHandler(errmsg);
172 if (is_assigned(
id)) {
173 std::ostringstream errmsg;
174 errmsg <<
"Part id " <<
id <<
" has already been assigned, cannot assign it to part '"
176 m_errorHandler(errmsg);
181 bool is_assigned(
unsigned id)
const {
return m_parts.count(
id) > 0; }
185 auto it = m_ids.find(name);
186 if (it == m_ids.end()) {
187 std::ostringstream errmsg;
188 errmsg <<
"PartIdMapping has no ID for invalid part name " << name;
189 m_errorHandler(errmsg);
196 auto it = m_parts.find(
id);
197 if (it == m_parts.end()) {
198 std::ostringstream errmsg;
199 errmsg <<
"PartIdMapping has no part name for invalid id " << id;
200 m_errorHandler(errmsg);
205 std::vector<std::string> m_partNames{};
206 mutable std::unordered_map<std::string, unsigned>
m_ids;
207 mutable std::map<unsigned, std::string>
m_parts;
208 mutable bool m_idsAssigned{
false};
226 std::ostringstream errmsg;
227 errmsg <<
"Could not find node id " << nodeId;
235 const std::vector<double> &coordinates)
237 if (!coordinates.empty()) {
250 const std::vector<double> &coordinates)
252 if (coordinates.size() != nodeIds.size() * spatialDim) {
253 std::ostringstream errmsg;
254 errmsg <<
"Number of coordinates: " << coordinates.size()
255 <<
", Number of nodes: " << nodeIds.size()
256 <<
", Spatial dimension: " << spatialDim;
262 const std::vector<double> &coordinates)
264 std::vector<double>::const_iterator coordIter = coordinates.begin();
265 for (
const EntityId &nodeId : nodeIds) {
266 m_nodalCoords[nodeId] = std::vector<double>(coordIter, coordIter + spatialDim);
267 coordIter += spatialDim;
276 template <
typename EntityId,
typename Topology>
struct ElementData
308 template <
typename EntityId,
typename Topology>
class Sidesets;
310 template <
typename EntityId>
class Nodesets;
Definition Iotm_TextMeshTopologyMapping.h:33
Definition Iotm_TextMeshDataTypes.h:312
Definition Iotm_TextMeshDataTypes.h:214
void set_coordinate_data(const unsigned spatialDim, const std::set< EntityId > &nodeIds, const std::vector< double > &coordinates)
Definition Iotm_TextMeshDataTypes.h:234
std::unordered_map< EntityId, std::vector< double > > m_nodalCoords
Definition Iotm_TextMeshDataTypes.h:272
void validate_num_coordinates(const unsigned spatialDim, const std::set< EntityId > &nodeIds, const std::vector< double > &coordinates)
Definition Iotm_TextMeshDataTypes.h:249
ErrorHandler m_errorHandler
Definition Iotm_TextMeshDataTypes.h:273
void fill_coordinate_map(const unsigned spatialDim, const std::set< EntityId > &nodeIds, const std::vector< double > &coordinates)
Definition Iotm_TextMeshDataTypes.h:261
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshDataTypes.h:244
bool m_hasCoordinateData
Definition Iotm_TextMeshDataTypes.h:271
const std::vector< double > & operator[](const EntityId nodeId) const
Definition Iotm_TextMeshDataTypes.h:221
bool has_coordinate_data() const
Definition Iotm_TextMeshDataTypes.h:246
Coordinates()
Definition Iotm_TextMeshDataTypes.h:216
Definition Iotm_TextMeshNodeset.h:46
Definition Iotm_TextMeshDataTypes.h:59
unsigned get_part_id(const std::string &name) const
Definition Iotm_TextMeshDataTypes.h:183
void assign_ids() const
Definition Iotm_TextMeshDataTypes.h:139
ErrorHandler m_errorHandler
Definition Iotm_TextMeshDataTypes.h:210
bool is_registered(const std::string &name) const
Definition Iotm_TextMeshDataTypes.h:114
void assign(const std::string &name, unsigned id) const
Definition Iotm_TextMeshDataTypes.h:154
unsigned get(const std::string &name) const
Definition Iotm_TextMeshDataTypes.h:78
void register_part_name(const std::string &name)
Definition Iotm_TextMeshDataTypes.h:66
void validate_name_and_id(const std::string &name, unsigned id) const
Definition Iotm_TextMeshDataTypes.h:161
const std::string get_group_type() const
Definition Iotm_TextMeshDataTypes.h:120
std::string get(unsigned id) const
Definition Iotm_TextMeshDataTypes.h:85
void handle_block_part(const std::string &name)
Definition Iotm_TextMeshDataTypes.h:129
unsigned size() const
Definition Iotm_TextMeshDataTypes.h:92
std::string get_part_name(unsigned id) const
Definition Iotm_TextMeshDataTypes.h:194
std::map< unsigned, std::string > m_parts
Definition Iotm_TextMeshDataTypes.h:207
std::unordered_map< std::string, unsigned > m_ids
Definition Iotm_TextMeshDataTypes.h:206
PartIdMapping()
Definition Iotm_TextMeshDataTypes.h:61
void finalize_parse()
Definition Iotm_TextMeshDataTypes.h:122
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshDataTypes.h:118
void register_part_name_with_id(const std::string &name, unsigned id)
Definition Iotm_TextMeshDataTypes.h:72
const std::vector< std::string > & get_part_names() const
Definition Iotm_TextMeshDataTypes.h:116
std::vector< std::string > get_part_names_sorted_by_id() const
Definition Iotm_TextMeshDataTypes.h:99
bool is_assigned(unsigned id) const
Definition Iotm_TextMeshDataTypes.h:181
Definition Iotm_TextMeshSideset.h:104
Definition Iotm_TextMeshDataTypes.h:39
T Topology
Definition Iotm_TextMeshDataTypes.h:41
std::unordered_map< std::string, Topology > m_nameToTopology
Definition Iotm_TextMeshDataTypes.h:55
virtual ~TopologyMapping()
Definition Iotm_TextMeshDataTypes.h:43
virtual void initialize_topology_map()=0
virtual Topology invalid_topology() const =0
Topology topology(const std::string &textMeshName) const
Definition Iotm_TextMeshDataTypes.h:45
std::function< void(const std::ostringstream &)> ErrorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:35
void default_error_handler(const std::ostringstream &message)
Definition Iotm_TextMeshFuncs.h:32
std::pair< unsigned, bool > get_id_from_part_name(const std::string &name, const std::string &prefix)
Definition Iotm_TextMeshFuncs.h:118
A namespace for the textmesh database format.
Definition Iotm_DatabaseIO.C:95
int64_t EntityId
Definition Iotm_TextMesh.h:33
Definition Iotm_TextMeshDataTypes.h:288
bool operator()(const EntityId lhs, const EntityId rhs)
Definition Iotm_TextMeshDataTypes.h:305
bool operator()(const ElementData< EntityId, Topology > &lhs, const EntityId rhs)
Definition Iotm_TextMeshDataTypes.h:295
bool operator()(const EntityId lhs, const ElementData< EntityId, Topology > &rhs)
Definition Iotm_TextMeshDataTypes.h:300
bool operator()(const ElementData< EntityId, Topology > &lhs, const ElementData< EntityId, Topology > &rhs)
Definition Iotm_TextMeshDataTypes.h:289
Definition Iotm_TextMeshDataTypes.h:277
Topology topology
Definition Iotm_TextMeshDataTypes.h:280
std::string partName
Definition Iotm_TextMeshDataTypes.h:282
int proc
Definition Iotm_TextMeshDataTypes.h:278
EntityId identifier
Definition Iotm_TextMeshDataTypes.h:279
std::vector< EntityId > nodeIds
Definition Iotm_TextMeshDataTypes.h:281
Definition Iotm_TextMeshDataTypes.h:315
std::set< int > m_emptyProcs
Definition Iotm_TextMeshDataTypes.h:364
std::set< EntityId > nodeIds
Definition Iotm_TextMeshDataTypes.h:319
Assemblies< EntityId > assemblies
Definition Iotm_TextMeshDataTypes.h:323
Nodesets< EntityId > nodesets
Definition Iotm_TextMeshDataTypes.h:322
std::vector< ElementData< EntityId, Topology > > elementDataVec
Definition Iotm_TextMeshDataTypes.h:317
const std::set< int > & procs_for_node(const EntityId nodeId) const
Definition Iotm_TextMeshDataTypes.h:348
std::set< EntityId > m_emptyNodes
Definition Iotm_TextMeshDataTypes.h:365
PartIdMapping partIds
Definition Iotm_TextMeshDataTypes.h:318
void associate_node_with_proc(const EntityId nodeId, int proc)
Definition Iotm_TextMeshDataTypes.h:355
unsigned spatialDim
Definition Iotm_TextMeshDataTypes.h:316
Coordinates< EntityId > coords
Definition Iotm_TextMeshDataTypes.h:320
TextMeshData()
Definition Iotm_TextMeshDataTypes.h:325
void add_element(const ElementData< EntityId, Topology > &elem)
Definition Iotm_TextMeshDataTypes.h:327
std::unordered_map< int, std::set< EntityId > > m_nodesOnProc
Definition Iotm_TextMeshDataTypes.h:362
std::unordered_map< EntityId, std::set< int > > m_procsForNode
Definition Iotm_TextMeshDataTypes.h:361
unsigned num_nodes_on_proc(int proc) const
Definition Iotm_TextMeshDataTypes.h:342
const std::set< EntityId > & nodes_on_proc(int proc) const
Definition Iotm_TextMeshDataTypes.h:336
Sidesets< EntityId, Topology > sidesets
Definition Iotm_TextMeshDataTypes.h:321