#include <ReadUtil.hpp>
Public Member Functions | |
ReadUtil (Core *mdb, Error *error_handler) | |
Constructor takes Core pointer. More... | |
~ReadUtil () | |
Destructor. More... | |
ErrorCode | get_node_coords (const int num_arrays, const int num_nodes, const int preferred_start_id, EntityHandle &actual_start_handle, std::vector< double * > &arrays, int sequence_size=-1) |
Get arrays for coordinate data from the MB. More... | |
ErrorCode | get_element_connect (const int num_elements, const int verts_per_element, const EntityType mdb_type, const int preferred_start_id, EntityHandle &actual_start_handle, EntityHandle *&array, int sequence_size=-1) |
Get array for connectivity data from the MB. More... | |
ErrorCode | gather_related_ents (Range &partition, Range &related_ents, EntityHandle *file_set=NULL) |
Gather entities related to those in the partition Gather entities related to those in the input partition. Related means down-adjacent to, contained in, etc. More... | |
ErrorCode | create_entity_sets (EntityID num_sets, const unsigned *set_flags, EntityID preffered_start_id, EntityHandle &actual_start_handle) |
ErrorCode | update_adjacencies (const EntityHandle start_handle, const int number_elements, const int number_vertices_per_element, const EntityHandle *conn_array) |
Tell MB which elements have been added to the database. More... | |
ErrorCode | get_ordered_vertices (EntityHandle *bound_ents, int *sense, int num_bound, int dim, EntityHandle *bound_verts, EntityType &etype) |
Given an ordered list of bounding entities and the sense of those entities, return an ordered list of vertices. More... | |
ErrorCode | assign_ids (Tag id_tag, const Range &ents, int start=0) |
Assign sequential IDS to entities in range and store IDs in tag. More... | |
ErrorCode | assign_ids (Tag id_tag, const EntityHandle *ents, size_t num_ents, int start=0) |
Assign to each entity in an array the ID that is its position in the array plus the value of 'start'. For any non-zero handles in the array, store the ID value in the passed tag. More... | |
ErrorCode | create_gather_set (EntityHandle &gather_set) |
Create a new gather set with tag GATHER_SET. More... | |
ErrorCode | get_gather_set (EntityHandle &gather_set) |
Get entity handle of an existing gather set. More... | |
![]() | |
ReadUtilIface () | |
Constructor. More... | |
virtual | ~ReadUtilIface () |
Destructor. More... | |
Private Attributes | |
Core * | mMB |
Pointer to the Core. More... | |
Additional Inherited Members | |
![]() | |
static void | reorder (const int *order, EntityHandle *conn, int num_elem, int node_per_elem) |
Re-order incoming element connectivity. More... | |
Definition at line 31 of file ReadUtil.hpp.
Constructor takes Core pointer.
Definition at line 38 of file ReadUtil.cpp.
38 : ReadUtilIface(), mMB( mdb ) {}
|
inline |
|
virtual |
Assign to each entity in an array the ID that is its position in the array plus the value of 'start'. For any non-zero handles in the array, store the ID value in the passed tag.
Implements moab::ReadUtilIface.
Definition at line 335 of file ReadUtil.cpp.
336 {
337 ErrorCode rval = check_int_tag( mMB, id_tag );
338 if( MB_SUCCESS != rval ) return rval;
339
340 std::vector< int > data;
341 const EntityHandle* const end = ents + num_ents;
342 const EntityHandle* i = ents;
343 while( i != end )
344 {
345 const EntityHandle* next = std::find( i, end, 0u );
346 size_t size = next - i;
347 if( !size )
348 {
349 ++i;
350 continue;
351 }
352
353 int id = start + ( i - ents );
354 data.resize( size );
355 for( std::vector< int >::iterator j = data.begin(); j != data.end(); ++j )
356 *j = id++;
357
358 rval = mMB->tag_set_data( id_tag, i, size, &data[0] );
359 if( MB_SUCCESS != rval ) return rval;
360 }
361
362 return MB_SUCCESS;
363 }
References moab::check_int_tag(), ErrorCode, MB_SUCCESS, mMB, size, and moab::Core::tag_set_data().
Assign sequential IDS to entities in range and store IDs in tag.
Implements moab::ReadUtilIface.
Definition at line 314 of file ReadUtil.cpp.
315 {
316 ErrorCode rval = check_int_tag( mMB, id_tag );
317 if( MB_SUCCESS != rval ) return rval;
318
319 Range tmp_range;
320 std::vector< int > data;
321 for( Range::const_pair_iterator i = ents.pair_begin(); i != ents.pair_end(); ++i )
322 {
323 data.resize( i->second + 1 - i->first );
324 for( std::vector< int >::iterator j = data.begin(); j != data.end(); ++j )
325 *j = start++;
326 tmp_range.clear();
327 tmp_range.insert( i->first, i->second );
328 rval = mMB->tag_set_data( id_tag, tmp_range, &data[0] );
329 if( MB_SUCCESS != rval ) return rval;
330 }
331
332 return MB_SUCCESS;
333 }
References moab::check_int_tag(), moab::Range::clear(), ErrorCode, moab::Range::insert(), MB_SUCCESS, mMB, moab::Range::pair_begin(), moab::Range::pair_end(), and moab::Core::tag_set_data().
|
virtual |
Implements moab::ReadUtilIface.
Definition at line 116 of file ReadUtil.cpp.
120 {
121 if( num_sets < 1 )
122 {
123 start_handle = 0;
124 return MB_INDEX_OUT_OF_RANGE;
125 }
126
127 ErrorCode error;
128 EntitySequence* seq;
129 error = mMB->sequence_manager()->create_meshset_sequence( num_sets, start_id, flags, start_handle, seq );
130 if( MB_SUCCESS != error ) return error;
131
132 if( seq->start_handle() > start_handle || seq->end_handle() < start_handle ||
133 seq->end_handle() - start_handle + 1 < (EntityHandle)num_sets )
134 return MB_FAILURE;
135
136 return MB_SUCCESS;
137 }
References moab::SequenceManager::create_meshset_sequence(), moab::EntitySequence::end_handle(), moab::error(), ErrorCode, MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, mMB, moab::Core::sequence_manager(), and moab::EntitySequence::start_handle().
|
virtual |
Create a new gather set with tag GATHER_SET.
Implements moab::ReadUtilIface.
Definition at line 365 of file ReadUtil.cpp.
366 {
367 ErrorCode rval = mMB->create_meshset( MESHSET_SET, gather_set );
368 if( MB_SUCCESS != rval ) return rval;
369
370 Tag gather_set_tag;
371 rval = mMB->tag_get_handle( "GATHER_SET", 1, MB_TYPE_INTEGER, gather_set_tag, MB_TAG_CREAT | MB_TAG_SPARSE );
372 if( MB_SUCCESS != rval ) return rval;
373
374 int gather_val = 1;
375 rval = mMB->tag_set_data( gather_set_tag, &gather_set, 1, &gather_val );
376 if( MB_SUCCESS != rval ) return rval;
377
378 return MB_SUCCESS;
379 }
References moab::Core::create_meshset(), ErrorCode, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_INTEGER, MESHSET_SET, mMB, moab::Core::tag_get_handle(), and moab::Core::tag_set_data().
|
virtual |
Gather entities related to those in the partition Gather entities related to those in the input partition. Related means down-adjacent to, contained in, etc.
partition | Entities for which to gather related entities |
related_ents | Related entities |
all_sets | If non-NULL, all sets in mesh instance are returned in the pointed-to range |
Implements moab::ReadUtilIface.
Definition at line 162 of file ReadUtil.cpp.
163 {
164 // Loop over any sets, getting contained ents
165 std::pair< Range::const_iterator, Range::const_iterator > pair_it = partition.equal_range( MBENTITYSET );
166
167 ErrorCode result = MB_SUCCESS;
168 for( Range::const_iterator rit = pair_it.first; rit != pair_it.second; ++rit )
169 {
170 ErrorCode tmp_result = mMB->get_entities_by_handle( *rit, related_ents, Interface::UNION );
171 if( MB_SUCCESS != tmp_result ) result = tmp_result;
172 }
173 RR;
174
175 // Gather adjacent ents of other dimensions
176 Range tmp_ents;
177 for( int dim = 3; dim >= 0; dim-- )
178 {
179 tmp_ents.clear();
180 ErrorCode tmp_result = mMB->get_adjacencies( related_ents, dim, false, tmp_ents, Interface::UNION );
181 if( MB_SUCCESS != tmp_result )
182 result = tmp_result;
183 else
184 related_ents.merge( tmp_ents );
185 }
186 RR;
187
188 // Related ents includes the partition itself
189 related_ents.merge( partition );
190
191 // Get contains-related sets
192 Range tmp_ents3, last_related;
193 if( file_set )
194 result = mMB->get_entities_by_type( *file_set, MBENTITYSET, tmp_ents3 );
195 else
196 result = mMB->get_entities_by_type( 0, MBENTITYSET, tmp_ents3 );RR;
197
198 while( related_ents.size() != last_related.size() )
199 {
200 last_related = related_ents;
201 for( Range::iterator rit = tmp_ents3.begin(); rit != tmp_ents3.end(); ++rit )
202 {
203 if( related_ents.find( *rit ) != related_ents.end() ) continue;
204
205 tmp_ents.clear();
206 result = mMB->get_entities_by_handle( *rit, tmp_ents, true );RR;
207 Range tmp_ents2 = intersect( tmp_ents, related_ents );
208
209 // If the intersection is not empty, set is related
210 if( !tmp_ents2.empty() ) related_ents.insert( *rit );
211 }
212 }
213
214 // Get child-related sets
215 last_related.clear();
216 while( related_ents.size() != last_related.size() )
217 {
218 last_related = related_ents;
219 std::pair< Range::const_iterator, Range::const_iterator > it_pair = last_related.equal_range( MBENTITYSET );
220
221 for( Range::const_iterator rit = it_pair.first; rit != it_pair.second; ++rit )
222 {
223 // Get all children and add to related ents
224 tmp_ents.clear();
225 result = mMB->get_child_meshsets( *rit, tmp_ents, 0 );RR;
226 related_ents.merge( tmp_ents );
227 }
228 }
229
230 // Get parent-related sets
231 last_related.clear();
232 while( related_ents.size() != last_related.size() )
233 {
234 last_related = related_ents;
235 std::pair< Range::const_iterator, Range::const_iterator > it_pair = last_related.equal_range( MBENTITYSET );
236
237 for( Range::const_iterator rit = it_pair.first; rit != it_pair.second; ++rit )
238 {
239 // Get all parents and add to related ents
240 tmp_ents.clear();
241 result = mMB->get_parent_meshsets( *rit, tmp_ents, 0 );RR;
242 related_ents.merge( tmp_ents );
243 }
244 }
245
246 return MB_SUCCESS;
247 }
References moab::Range::begin(), moab::Range::clear(), dim, moab::Range::empty(), moab::Range::end(), moab::Range::equal_range(), ErrorCode, moab::Range::find(), moab::Core::get_adjacencies(), moab::Core::get_child_meshsets(), moab::Core::get_entities_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_parent_meshsets(), moab::Range::insert(), moab::intersect(), MB_SUCCESS, MBENTITYSET, moab::Range::merge(), mMB, RR, moab::Range::size(), and moab::Interface::UNION.
|
virtual |
Get array for connectivity data from the MB.
Implements moab::ReadUtilIface.
Definition at line 76 of file ReadUtil.cpp.
83 {
84 ErrorCode error;
85 EntitySequence* seq;
86
87 if( num_elements < 1 )
88 {
89 actual_start_handle = 0;
90 array = 0;
91 return MB_INDEX_OUT_OF_RANGE;
92 }
93
94 // if (mdb_type <= MBVERTEX || mdb_type >= MBPOLYHEDRON || mdb_type == MBPOLYGON)
95 // return MB_TYPE_OUT_OF_RANGE;
96
97 // Make an entity sequence to hold these elements
98 error =
99 mMB->sequence_manager()->create_entity_sequence( mdb_type, num_elements, verts_per_element, preferred_start_id,
100 actual_start_handle, seq, sequence_size );
101 if( MB_SUCCESS != error ) return error;
102
103 if( seq->start_handle() > actual_start_handle || seq->end_handle() < actual_start_handle ||
104 seq->end_handle() - actual_start_handle + 1 < (unsigned)num_elements )
105 return MB_FAILURE;
106
107 // Get an array for the connectivity
108 array = static_cast< ElementSequence* >( seq )->get_connectivity_array();
109 if( !array ) return MB_FAILURE;
110 array +=
111 ( actual_start_handle - seq->start_handle() ) * static_cast< ElementSequence* >( seq )->nodes_per_element();
112
113 return error;
114 }
References moab::SequenceManager::create_entity_sequence(), moab::EntitySequence::end_handle(), moab::error(), ErrorCode, MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, mMB, moab::ElementSequence::nodes_per_element(), moab::Core::sequence_manager(), and moab::EntitySequence::start_handle().
|
virtual |
Get entity handle of an existing gather set.
Implements moab::ReadUtilIface.
Definition at line 381 of file ReadUtil.cpp.
382 {
383 Tag gather_set_tag;
384 ErrorCode rval = mMB->tag_get_handle( "GATHER_SET", 1, MB_TYPE_INTEGER, gather_set_tag, MB_TAG_SPARSE );
385 if( MB_SUCCESS != rval ) return rval;
386
387 int gather_val = 1;
388 void* vals[] = { &gather_val };
389 Range gather_sets;
390 rval = mMB->get_entities_by_type_and_tag( 0, MBENTITYSET, &gather_set_tag, vals, 1, gather_sets );
391 if( MB_SUCCESS != rval ) return rval;
392
393 if( gather_sets.empty() ) return MB_ENTITY_NOT_FOUND;
394
395 gather_set = gather_sets[0];
396
397 return MB_SUCCESS;
398 }
References moab::Range::empty(), ErrorCode, moab::Core::get_entities_by_type_and_tag(), MB_ENTITY_NOT_FOUND, MB_SUCCESS, MB_TAG_SPARSE, MB_TYPE_INTEGER, MBENTITYSET, mMB, and moab::Core::tag_get_handle().
|
virtual |
Get arrays for coordinate data from the MB.
Implements moab::ReadUtilIface.
Definition at line 40 of file ReadUtil.cpp.
46 {
47 ErrorCode error;
48 EntitySequence* seq = 0;
49
50 if( num_nodes < 1 )
51 {
52 actual_start_handle = 0;
53 arrays.clear();
54 return MB_INDEX_OUT_OF_RANGE;
55 }
56
57 // Create an entity sequence for these nodes
58 error = mMB->sequence_manager()->create_entity_sequence( MBVERTEX, num_nodes, 0, preferred_start_id,
59 actual_start_handle, seq, sequence_size );
60
61 if( error != MB_SUCCESS ) return error;
62
63 if( seq->start_handle() > actual_start_handle || seq->end_handle() < actual_start_handle ||
64 seq->end_handle() - actual_start_handle + 1 < (unsigned)num_nodes )
65 return MB_FAILURE;
66
67 arrays.resize( 3 );
68
69 error = static_cast< VertexSequence* >( seq )->get_coordinate_arrays( arrays[0], arrays[1], arrays[2] );
70 for( unsigned i = 0; i < arrays.size(); ++i )
71 if( arrays[i] ) arrays[i] += ( actual_start_handle - seq->start_handle() );
72
73 return error;
74 }
References moab::SequenceManager::create_entity_sequence(), moab::EntitySequence::end_handle(), moab::error(), ErrorCode, MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, MBVERTEX, mMB, moab::Core::sequence_manager(), and moab::EntitySequence::start_handle().
|
virtual |
Given an ordered list of bounding entities and the sense of those entities, return an ordered list of vertices.
Implements moab::ReadUtilIface.
Definition at line 249 of file ReadUtil.cpp.
255 {
256 // Get dimension of bounding entities
257 int bound_dim = CN::Dimension( TYPE_FROM_HANDLE( bound_ents[0] ) );
258 int indices[MAX_SUB_ENTITY_VERTICES];
259 const EntityHandle* connect = NULL;
260 std::vector< EntityHandle > tmp_connect;
261
262 // Find the right entity type based on # bounding ents
263 int numv = 0, num_connect = 0;
264 ErrorCode result;
265 for( EntityType t = MBEDGE; t < MBENTITYSET; t++ )
266 {
267 int nindex = CN::NumSubEntities( t, bound_dim );
268 if( CN::Dimension( t ) != dim || nindex != bound_size ) continue;
269
270 // Fill in vertices from bounding entity vertices
271 int nverts = CN::VerticesPerEntity( t );
272 std::fill( bound_verts, bound_verts + nverts, 0 );
273 for( int index = 0; index < nindex; index++ )
274 {
275 result = mMB->get_connectivity( bound_ents[index], connect, num_connect, false, &tmp_connect );
276 if( MB_SUCCESS != result ) return result;
277
278 CN::SubEntityVertexIndices( t, bound_dim, index, indices );
279
280 for( int c = 0; c < num_connect; c++ )
281 {
282 if( !bound_verts[indices[c]] )
283 {
284 bound_verts[indices[c]] = ( sense[index] > 0 ) ? connect[c] : connect[num_connect - c - 1];
285 numv++;
286 }
287 }
288 if( numv == nverts )
289 {
290 etype = t;
291 return MB_SUCCESS;
292 }
293 }
294 }
295
296 // If we get here, we didn't get full connectivity
297 etype = MBMAXTYPE;
298 return MB_FAILURE;
299 }
References dim, moab::CN::Dimension(), ErrorCode, moab::Core::get_connectivity(), moab::MAX_SUB_ENTITY_VERTICES, MB_SUCCESS, MBEDGE, MBENTITYSET, MBMAXTYPE, mMB, moab::CN::NumSubEntities(), moab::CN::SubEntityVertexIndices(), moab::TYPE_FROM_HANDLE(), and moab::CN::VerticesPerEntity().
|
virtual |
Tell MB which elements have been added to the database.
Implements moab::ReadUtilIface.
Definition at line 139 of file ReadUtil.cpp.
143 {
144 EntityHandle tmp_hndl = start_handle;
145 AEntityFactory* adj_fact = mMB->a_entity_factory();
146
147 // Iterate over the elements and update adjacency information
148 if( adj_fact != NULL && adj_fact->vert_elem_adjacencies() )
149 {
150 int j = 0;
151 for( int i = 0; i < number_elements; i++ )
152 {
153 adj_fact->notify_create_entity( tmp_hndl, ( conn_array + j ), number_vertices_per_element );
154 tmp_hndl++;
155 j += number_vertices_per_element;
156 }
157 }
158
159 return MB_SUCCESS;
160 }
References moab::Core::a_entity_factory(), MB_SUCCESS, mMB, moab::AEntityFactory::notify_create_entity(), and moab::AEntityFactory::vert_elem_adjacencies().
|
private |
Pointer to the Core.
Definition at line 35 of file ReadUtil.hpp.
Referenced by assign_ids(), create_entity_sets(), create_gather_set(), gather_related_ents(), get_element_connect(), get_gather_set(), get_node_coords(), get_ordered_vertices(), and update_adjacencies().