![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /* WriteDamsel.cpp
00002 * The Damsel library provides mesh-aware parallel I/O; see
00003 * http://cucis.ece.northwestern.edu/projects/DAMSEL/ for details, though for now that site is
00004 * restricted to project participants. Damsel uses a data model that's very similar to that used in
00005 * MOAB and ITAPS. It uses the same basic data model concepts of entities, sets, tags, and
00006 * interface. In theory, we should be able to completely save/restore to/from Damsel any data that
00007 * can be saved/restored to/from our native HDF5-based reader/writer.
00008 *
00009 * Mapping between MOAB-Damsel data models
00010 * =======================================
00011 * Basic data model entities, MOAB <--> Damsel:
00012 * Entity <--> Entity
00013 * EntitySet <--> Collection
00014 * Tag <--> Tag
00015 * API/data strutures:
00016 * Range (n1) <--> Sequence container
00017 * std::vector <--> Vector container
00018 * Range (n2) <--> Tree container
00019 *
00020 * n1: single contiguous subrange
00021 * n2: multiple subranges
00022 *
00023 * Conventions
00024 * ===========
00025 * There are parts of MOAB data structures that need to be stored to Damsel that aren't represented
00026 * in the Damsel data model, e.g. dense vs. sparse storage type, set tracking flags.
00027 * - We need to store these as tags in Damsel.
00028 * - Since Damsel tags need to have a MOAB counterpart, we have to create those as tag data in MOAB
00029 * too (duplicating the data in the data structures, bummer).
00030 * - Because we may want to use these tags for multiple Damsel writes/models, we create the
00031 * MOAB-side tags in the WriteDamsel constructor, not in the init_tags function that's called for
00032 * every write
00033 * - Conventional tags have names prefixed with mbdmsl_ to avoid name conflicts with other MOAB
00034 * tags. Here we list the conventional tags used by MOAB's Damsel reader/writer.
00035 *
00036 * Tag name Tag char's (storage type, data type, length, def val) Values,
00037 * used for what
00038 * -------- -----------------------------------------------------
00039 * -------------------- mbdmsl_XCOORDS dense; double[1]; 0.0 MOAB vertex x coordinate
00040 * mbdmsl_YCOORDS dense; double[1]; 0.0 MOAB
00041 * vertex y coordinate mbdmsl_ZCOORDS dense; double[1]; 0.0 MOAB vertex z coordinate
00042 * mbdmsl_COLL_FLAGS sparse; char; 1; 0x0 bit 0:
00043 * 0=set-type, 1=vector-type 1: 1=tracking, 0=not tracking mbdmsl_PARENTS sparse; handle; var;
00044 * (list of parent sets) mbdmsl_CHILDS sparse; handle; var; (list of child sets)
00045 *
00046 *
00047 *
00048 */
00049
00050 #include "WriteDamsel.hpp"
00051
00052 #include "DamselUtil.hpp"
00053 #include "damsel.h"
00054 #include
00055 #include "moab/Interface.hpp"
00056 #include "moab/Core.hpp"
00057 #include "moab/Range.hpp"
00058 #include "moab/Error.hpp"
00059 #include "moab/WriteUtilIface.hpp"
00060 #include "MBTagConventions.hpp"
00061 #include "EntitySequence.hpp"
00062 #include "Internals.hpp"
00063 #include "DenseTag.hpp"
00064 #include "SparseTag.hpp"
00065
00066 namespace moab
00067 {
00068
00069 WriterIface* WriteDamsel::factory( Interface* iface )
00070 {
00071 return new WriteDamsel( iface );
00072 }
00073
00074 WriteDamsel::WriteDamsel( Interface* impl )
00075 : mbImpl( impl ), mWriteIface( NULL ), sequenceManager( NULL ), dU(), DAMSEL_FLAGS( DAMSEL_IS_TRACKING )
00076 {
00077 assert( impl != NULL );
00078
00079 impl->query_interface( mWriteIface );
00080 assert( mWriteIface );
00081
00082 sequenceManager = dynamic_cast< Core* >( impl )->sequence_manager();
00083 assert( sequenceManager );
00084
00085 ErrorCode rval =
00086 mbImpl->tag_get_handle( "mbdmsl_XCOORDS", 1, MB_TYPE_DOUBLE, dU.xcoordsTag.mTagh, MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR_CONT( rval, "Failed to create_tag mbdmsl_XCOORDS" );
00087 dU.xcoordsTag.tagType = MB_TAG_ANY;
00088 dU.tagMap.push_back( dU.xcoordsTag );
00089 rval =
00090 mbImpl->tag_get_handle( "mbdmsl_YCOORDS", 1, MB_TYPE_DOUBLE, dU.ycoordsTag.mTagh, MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR_CONT( rval, "Failed to create_tag mbdmsl_YCOORDS" );
00091 dU.ycoordsTag.tagType = MB_TAG_ANY;
00092 dU.tagMap.push_back( dU.ycoordsTag );
00093
00094 rval =
00095 mbImpl->tag_get_handle( "mbdmsl_ZCOORDS", 1, MB_TYPE_DOUBLE, dU.zcoordsTag.mTagh, MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR_CONT( rval, "Failed to create_tag mbdmsl_ZCOORDS" );
00096 dU.zcoordsTag.tagType = MB_TAG_ANY;
00097 dU.tagMap.push_back( dU.zcoordsTag );
00098
00099 rval = mbImpl->tag_get_handle( "mbdmsl_COLL_FLAGS", 1, MB_TYPE_INTEGER, dU.collFlagsTag.mTagh,
00100 MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_SET_ERR_CONT( rval, "Failed to create_tag mbdmsl_COLL_FLAGS" );
00101 dU.collFlagsTag.tagType = MB_TAG_ANY;
00102 dU.tagMap.push_back( dU.collFlagsTag );
00103
00104 /*
00105 rval = mbImpl->tag_get_handle("mbdmsl_PARENTS", 1, MB_TYPE_HANDLE,
00106 dU.parentsTag.mTagh, MB_TAG_DENSE | MB_TAG_CREAT |
00107 MB_TAG_VARLEN);MB_CHK_SET_ERR_CONT(rval, "Failed to create_tag mbdmsl_PARENTS");
00108 dU.parentsTag.tagType = MB_TAG_DENSE;
00109 dU.tagMap.push_back(dU.parentsTag);
00110
00111 rval = mbImpl->tag_get_handle("mbdmsl_CHILDREN", 1, MB_TYPE_HANDLE,
00112 dU.childrenTag.mTagh, MB_TAG_DENSE | MB_TAG_CREAT |
00113 MB_TAG_VARLEN);MB_CHK_SET_ERR_CONT(rval, "Failed to create_tag mbdmsl_CHILDREN");
00114 dU.childrenTag.tagType = MB_TAG_DENSE;
00115 dU.tagMap.push_back(dU.childrenTag);
00116 */
00117
00118 dU.moabHandleType = ( sizeof( EntityHandle ) == 64 ? DAMSEL_HANDLE_TYPE_HANDLE64 : DAMSEL_HANDLE_TYPE_HANDLE32 );
00119 }
00120
00121 WriteDamsel::~WriteDamsel()
00122 {
00123 if( mWriteIface ) mbImpl->release_interface( mWriteIface );
00124 }
00125
00126 ErrorCode WriteDamsel::write_file( const char* file_name,
00127 const bool /* overwrite */,
00128 const FileOptions& opts,
00129 const EntityHandle* meshset_list,
00130 const int num_sets,
00131 const std::vector< std::string >& /* qa_records */,
00132 const Tag* /* tag_list */,
00133 int /* num_tags */,
00134 int /* requested_output_dimension */ )
00135 {
00136 // Gather all entities into one big range
00137 Range all_ents;
00138 ErrorCode rval;
00139 damsel_err_t err;
00140
00141 dU.dmslLib = DMSLlib_init();
00142
00143 // Create a damsel model
00144 dU.dmslModel =
00145 DMSLmodel_create( sizeof( EntityHandle ) == 8 ? DAMSEL_HANDLE_TYPE_HANDLE64 : DAMSEL_HANDLE_TYPE_HANDLE32 );
00146
00147 // Attach to a file, since we need it for creating containers
00148 MPI_Comm comm = MPI_COMM_WORLD;
00149 unlink( file_name );
00150 err = DMSLmodel_attach( dU.dmslModel, file_name, comm, NULL );
00151 CHK_DMSL_ERR( err, "DMSLmodel_attach failed" );
00152
00153 rval = mWriteIface->gather_entities( all_ents, meshset_list, num_sets );MB_CHK_SET_ERR( rval, "Gather entities failed in WriteDamsel" );
00154
00155 if( all_ents.empty() ) return MB_SUCCESS;
00156
00157 // Create damsel tags for MOAB dense, sparse, and conventional tags
00158 rval = init_tag_info();MB_CHK_ERR( rval );
00159
00160 // Iterate through the groups of contiguous sequences of handles
00161 RangeSeqIntersectIter rsi( sequenceManager );
00162 rval = rsi.init( all_ents.begin(), all_ents.end() );
00163
00164 while( MB_SUCCESS == rval )
00165 {
00166 // Write subrange of things to damsel: map handles, map entity definition data
00167 // (connectivity/coords/set contents), map dense tags
00168 rval = write_subrange( rsi );MB_CHK_SET_ERR( rval, "Failed to write subrange" );
00169
00170 rval = rsi.step();
00171 while( MB_ENTITY_NOT_FOUND == rval )
00172 rval = rsi.step();
00173 }
00174
00175 // Write sparse tags
00176 rval = map_sparse_tags();MB_CHK_SET_ERR( rval, "Failed to write sparse tags" );
00177
00178 // damsel_request_t request;
00179 // err = DMSLmodel_transfer_async(dU.dmslModel, DAMSEL_TRANSFER_TYPE_WRITE, &request);
00180 err = DMSLmodel_transfer_sync( dU.dmslModel, DAMSEL_TRANSFER_TYPE_WRITE );
00181 CHK_DMSL_ERR( err, "DMSLmodel_transfer_asynch failed" );
00182
00183 // damsel_status_t status;
00184 // err = DMSLmodel_wait(request, &status);CHK_DMSL_ERR(err, "DMSLmodel_wait failed");
00185
00186 DMSLmodel_close( dU.dmslModel );
00187
00188 DMSLlib_finalize( dU.dmslLib );
00189
00190 // We should be done
00191 return MB_SUCCESS;
00192 }
00193
00194 ErrorCode WriteDamsel::init_tag_info()
00195 {
00196 // Initialize allTags and tagIndices
00197 std::vector< Tag > tmp_mtags;
00198 ErrorCode rval = mbImpl->tag_get_tags( tmp_mtags );MB_CHK_SET_ERR( rval, "Failed to get all tag handles." );
00199 int dum_size;
00200 damsel_err_t err;
00201
00202 // Define damsel tag handles for all dense/sparse tags
00203 for( std::vector< Tag >::iterator vit = tmp_mtags.begin(); vit != tmp_mtags.end(); ++vit )
00204 {
00205 if( ( ( *vit )->get_storage_type() != MB_TAG_DENSE && ( *vit )->get_storage_type() != MB_TAG_SPARSE ) ||
00206 mbImpl->tag_get_length( *vit, dum_size ) == MB_VARIABLE_DATA_LENGTH || dum_size != 1 )
00207 {
00208 std::cerr << "Warning: tag " << ( *vit )->get_name()
00209 << "is not of type dense or sparse, and is not currently supported by the "
00210 "damsel writer."
00211 << std::endl;
00212 continue;
00213 }
00214
00215 std::vector< DamselUtil::tinfo >::iterator vit2 =
00216 std::find_if( dU.tagMap.begin(), dU.tagMap.end(), DamselUtil::MtagP< DamselUtil::tinfo >( *vit ) );
00217
00218 if( vit2 != dU.tagMap.end() && ( *vit2 ).tagType == MB_TAG_ANY )
00219 // Conventional tag - skip
00220 continue;
00221
00222 else if( vit2 == dU.tagMap.end() )
00223 {
00224 // Create a damsel counterpart for this tag
00225 Tag thandle = *vit;
00226 err = DMSLtag_define( dU.dmslModel, (damsel_handle_ptr)&thandle,
00227 DamselUtil::mtod_data_type[( *vit )->get_data_type()], ( *vit )->get_name().c_str() );
00228 CHK_DMSL_ERR( err, "Failure to get Damsel tag for MOAB tag" );
00229 dU.tagMap.push_back( DamselUtil::tinfo( thandle, 0, ( *vit )->get_storage_type() ) );
00230 }
00231 else
00232 {
00233 // Assert there's a corresponding moab tag handle
00234 assert( ( *vit2 ).mTagh );
00235 }
00236 }
00237
00238 // Do the same for conventional tags:
00239 // XCOORDS
00240 err = DMSLtag_define( dU.dmslModel, ( damsel_handle_ptr ) & ( dU.xcoordsTag.mTagh ),
00241 DamselUtil::mtod_data_type[MB_TYPE_DOUBLE], dU.xcoordsTag.mTagh->get_name().c_str() );
00242 dU.tagMap.push_back( dU.xcoordsTag );
00243 CHK_DMSL_ERR( err, "Failure to get Damsel tag for MOAB tag" );
00244
00245 // YCOORDS
00246 err = DMSLtag_define( dU.dmslModel, ( damsel_handle_ptr ) & ( dU.ycoordsTag.mTagh ),
00247 DamselUtil::mtod_data_type[MB_TYPE_DOUBLE], dU.ycoordsTag.mTagh->get_name().c_str() );
00248 dU.tagMap.push_back( dU.ycoordsTag );
00249 CHK_DMSL_ERR( err, "Failure to get Damsel tag for MOAB tag" );
00250
00251 // ZCOORDS
00252 err = DMSLtag_define( dU.dmslModel, ( damsel_handle_ptr ) & ( dU.zcoordsTag.mTagh ),
00253 DamselUtil::mtod_data_type[MB_TYPE_DOUBLE], dU.zcoordsTag.mTagh->get_name().c_str() );
00254 dU.tagMap.push_back( dU.zcoordsTag );
00255 CHK_DMSL_ERR( err, "Failure to get Damsel tag for MOAB tag" );
00256
00257 // COLL_FLAGS
00258 err = DMSLtag_define( dU.dmslModel, ( damsel_handle_ptr ) & ( dU.collFlagsTag.mTagh ),
00259 DamselUtil::mtod_data_type[MB_TYPE_INTEGER], dU.collFlagsTag.mTagh->get_name().c_str() );
00260 dU.tagMap.push_back( dU.collFlagsTag );
00261 CHK_DMSL_ERR( err, "Failure to get Damsel tag for MOAB tag" );
00262
00263 /*
00264 SKIP PARENTS/CHILDREN FOR NOW, UNTIL WE HAVE VAR LENGTH TAGS IN DAMSEL
00265
00266 // PARENTS
00267 dU.parentsTagPair.second = DMSLtag_define(dU.dmslModel,
00268 (damsel_handle_ptr)&(dU.collFlagsTagPair.first),
00269 DamselUtil::mtod_data_type[(dU.collFlagsTagPair.first)->get_data_type()],
00270 (dU.parentsTagPair.first)->get_name().c_str());
00271 if (DAMSEL_TAG_INVALID == dtag)
00272 MB_SET_ERR(MB_FAILURE, "Failure to get Damsel tag for MOAB tag " <<
00273 (dU.parentsTagPair.first)->get_name());
00274
00275 // CHILDREN
00276 dU.childrenTagPair.second = DMSLtag_define(dU.dmslModel,
00277 (damsel_handle_ptr)&(dU.collFlagsTagPair.first),
00278 DamselUtil::mtod_data_type[(dU.collFlagsTagPair.first)->get_data_type()],
00279 (dU.childrenTagPair.first)->get_name().c_str());
00280 if (DAMSEL_TAG_INVALID == dtag)
00281 MB_SET_ERR(MB_FAILURE, "Failure to get Damsel tag for MOAB tag " <<
00282 (dU.childrenTagPair.first)->get_name());
00283 */
00284
00285 // Map the tag handles in one big call
00286 int num_tags = dU.tagMap.size();
00287 std::vector< Tag > moab_taghs;
00288 moab_taghs.reserve( num_tags );
00289 for( std::vector< DamselUtil::tinfo >::iterator vit = dU.tagMap.begin(); vit != dU.tagMap.end(); ++vit )
00290 {
00291 moab_taghs.push_back( ( *vit ).mTagh );
00292 }
00293
00294 damsel_container mtags =
00295 DMSLcontainer_create_vector( dU.dmslModel, (damsel_handle_ptr)&moab_taghs[0], moab_taghs.size() );
00296 std::cerr << "MOAB: created model container: mtags = " << mtags << std::endl;
00297
00298 err = DMSLmodel_map_handles_inventing_file_handles( mtags );
00299 CHK_DMSL_ERR( err, "Failed to map tag handles" );
00300
00301 err = DMSLcontainer_release( mtags );
00302 CHK_DMSL_ERR( err, "Problem releasing tag handle container" );
00303
00304 return MB_SUCCESS;
00305 }
00306
00307 ErrorCode WriteDamsel::write_vertices( RangeSeqIntersectIter& rsi )
00308 {
00309 // Write the vertices; these vertices will be in the same sequence and will be contiguous,
00310 // guaranteed
00311 EntityHandle start_vert = rsi.get_start_handle(), end_vert = rsi.get_end_handle();
00312
00313 // Create a damsel container for these vertex handles
00314 damsel_container vertex_cont =
00315 DMSLcontainer_create_sequence( dU.dmslModel, start_vert, (int)( end_vert - start_vert + 1 ), 1 );
00316 std::cerr << "MOAB: created model container: vertex_cont = " << vertex_cont << std::endl;
00317 if( DAMSEL_CONTAINER_INVALID == vertex_cont )
00318 MB_SET_ERR( MB_FAILURE,
00319 "Failed to create vertex sequence for vertices starting with handle " << rsi.get_start_handle() );
00320
00321 damsel_err_t err = DMSLmodel_map_handles_inventing_file_handles( vertex_cont );
00322 CHK_DMSL_ERR( err, "Failed to map handles" );
00323
00324 // Define the entities to damsel
00325 err = DMSLentity_define( vertex_cont, DAMSEL_ENTITY_TYPE_VERTEX, 1, vertex_cont );
00326 CHK_DMSL_ERR( err, "Failure in DMSLentity_define for vertices starting with handle " << rsi.get_start_handle() );
00327
00328 // Get the vertex coordinates storage locations and pass to damsel
00329 Range vert_range( start_vert, end_vert );
00330 double *xcoords = NULL, *ycoords = NULL, *zcoords = NULL;
00331 int count;
00332 ErrorCode rval = mbImpl->coords_iterate( vert_range.begin(), vert_range.end(), xcoords, ycoords, zcoords, count );MB_CHK_SET_ERR( rval,
00333 "Failed to get coordinate iterator for vertices starting with handle " << rsi.get_start_handle() );
00334 if( count != (int)vert_range.size() )
00335 {
00336 MB_SET_ERR( MB_FAILURE, "Vertex subrange not in the same sequence for vertices starting with handle "
00337 << rsi.get_start_handle() );
00338 }
00339
00340 if( xcoords && !ycoords && !zcoords )
00341 {
00342 // Interleaved
00343
00344 // Map the data to damsel
00345 err = DMSLmodel_map_tag( xcoords, vertex_cont, (damsel_handle_ptr)&dU.xcoordsTag.mTagh );
00346 CHK_DMSL_ERR( err, "Failed to assign vertex coordinates tag for vertices starting with handle "
00347 << rsi.get_start_handle() );
00348 }
00349 else
00350 {
00351 // Map the data to damsel
00352 err = DMSLmodel_map_tag( xcoords, vertex_cont, (damsel_handle_ptr)&dU.xcoordsTag.mTagh );
00353 CHK_DMSL_ERR( err, "Failed to assign vertex x coordinates tag for vertices starting with handle "
00354 << rsi.get_start_handle() );
00355 err = DMSLmodel_map_tag( ycoords, vertex_cont, (damsel_handle_ptr)&dU.ycoordsTag.mTagh );
00356 CHK_DMSL_ERR( err, "Failed to assign vertex y coordinates tag for vertices starting with handle "
00357 << rsi.get_start_handle() );
00358 err = DMSLmodel_map_tag( zcoords, vertex_cont, (damsel_handle_ptr)&dU.zcoordsTag.mTagh );
00359 CHK_DMSL_ERR( err, "Failed to assign vertex z coordinates tag for vertices starting with handle "
00360 << rsi.get_start_handle() );
00361 }
00362
00363 // Write/map dense tags
00364 rval = map_dense_tags( rsi, vertex_cont );MB_CHK_ERR( rval );
00365
00366 err = DMSLcontainer_release( vertex_cont );
00367 CHK_DMSL_ERR( err, "Problem releasing vertex handle container" );
00368
00369 return MB_SUCCESS;
00370 }
00371
00372 ErrorCode WriteDamsel::write_entities( RangeSeqIntersectIter& rsi )
00373 {
00374 // Write the entities; these entities will be in the same sequence and will be contiguous,
00375 // guaranteed
00376 EntityHandle start_ent = rsi.get_start_handle(), end_ent = rsi.get_end_handle();
00377
00378 // Create a damsel container for these entity handles
00379 damsel_container ent_cont;
00380 ent_cont = DMSLcontainer_create_sequence( dU.dmslModel, start_ent, (int)( end_ent - start_ent + 1 ), 1 );
00381 std::cerr << "MOAB: created model container: ent_cont = " << ent_cont << std::endl;
00382 if( DAMSEL_CONTAINER_INVALID == ent_cont ) MB_SET_ERR( MB_FAILURE, "Bad sequence returned by Damsel" );
00383
00384 damsel_err_t err = DMSLmodel_map_handles_inventing_file_handles( ent_cont );
00385 CHK_DMSL_ERR( err, "Failed to map handles" );
00386
00387 // Get # verts per entity and entity type
00388 EntityType etype = mbImpl->type_from_handle( start_ent );
00389 assert( MBMAXTYPE != etype );
00390 int num_connect = rsi.get_sequence()->values_per_entity();
00391 assert( 0 < num_connect );
00392
00393 // Get the connectivity storage location and pass to damsel
00394 Range ent_range( start_ent, end_ent );
00395 int count;
00396 EntityHandle* connect;
00397 int verts_per_ent;
00398 ErrorCode rval = mbImpl->connect_iterate( ent_range.begin(), ent_range.end(), connect, verts_per_ent, count );MB_CHK_SET_ERR( rval,
00399 "Failed to get connect iterator for entities starting with handle " << rsi.get_start_handle() );
00400 if( count != (int)ent_range.size() )
00401 MB_SET_ERR( MB_FAILURE, "Entity subrange not in the same sequence for entities starting with handle "
00402 << rsi.get_start_handle() );
00403
00404 // Define the entities to damsel
00405 err = DMSLentity_define_fast( ent_cont, DamselUtil::mtod_entity_type[etype], num_connect, (damsel_handle*)connect );
00406 CHK_DMSL_ERR( err, "DMSLentity_define failed for entities starting with handle " << rsi.get_start_handle() );
00407
00408 // Write dense tags
00409 rval = map_dense_tags( rsi, ent_cont );MB_CHK_ERR( rval );
00410
00411 err = DMSLcontainer_release( ent_cont );
00412 CHK_DMSL_ERR( err, "Problem releasing entity handle container" );
00413
00414 return MB_SUCCESS;
00415 }
00416
00417 ErrorCode WriteDamsel::map_dense_tags( RangeSeqIntersectIter& rsi, damsel_container& ent_cont )
00418 {
00419 // All dense_tags have been initialized before this, so here we just go through
00420 // them and map data if there is any
00421 const unsigned char* val_ptr;
00422 ErrorCode rval = MB_SUCCESS;
00423 std::vector< DamselUtil::tinfo >::iterator tagit;
00424 damsel_err_t err;
00425 for( tagit = dU.tagMap.begin(); tagit != dU.tagMap.end(); ++tagit )
00426 {
00427 if( ( *tagit ).tagType != MB_TAG_DENSE ) continue;
00428
00429 // Get a ptr to memory for this tag/sequence
00430 DenseTag* dtag = dynamic_cast< DenseTag* >( ( *tagit ).mTagh );
00431 assert( dtag );
00432 rval = dtag->get_array( rsi.get_sequence(), val_ptr );MB_CHK_SET_ERR( rval, "Failed to get tag coordinates pointer for vertices starting with handle "
00433 << rsi.get_start_handle() );
00434
00435 // If ptr is NULL, no data for this tag in this sequence
00436 if( !val_ptr ) continue;
00437
00438 // Else, register with damsel
00439 err = DMSLmodel_map_tag( (void*)val_ptr, ent_cont, (damsel_handle_ptr)&dtag );
00440 CHK_DMSL_ERR( err,
00441 "Failed to write coordinates tag for vertices starting with handle " << rsi.get_start_handle() );
00442 }
00443
00444 return rval;
00445 }
00446
00447 ErrorCode WriteDamsel::map_sparse_tags()
00448 {
00449 // All sparse_tags have been initialized before this, so here we just go through
00450 // them and map data if there is any
00451 ErrorCode rval = MB_SUCCESS;
00452 damsel_err_t err;
00453 std::vector< DamselUtil::tinfo >::iterator tagit;
00454 std::vector< unsigned char > tag_values;
00455 std::vector< EntityHandle > tagged_ents;
00456 damsel_container ent_cont;
00457 for( tagit = dU.tagMap.begin(); tagit != dU.tagMap.end(); ++tagit )
00458 {
00459 if( ( *tagit ).tagType != MB_TAG_SPARSE ) continue;
00460 // Get a ptr to memory for this tag/sequence
00461 SparseTag* stag = dynamic_cast< SparseTag* >( ( *tagit ).mTagh );
00462 assert( stag );
00463 Range output_ents;
00464 rval = stag->get_tagged_entities( sequenceManager, output_ents );MB_CHK_SET_ERR( rval, "Trouble getting tagged entities for tag " << stag->get_name() );
00465
00466 // If no entities have this tag set, don't map it
00467 if( output_ents.empty() ) continue;
00468
00469 // Else, register with damsel
00470 // Allocate space for and get values
00471 tag_values.resize( stag->get_size() * output_ents.size() );
00472 rval = mbImpl->tag_get_data( stag, output_ents, &tag_values[0] );MB_CHK_SET_ERR( rval, "Trouble getting tag values for tag " << stag->get_name() );
00473
00474 // Build a vector of entity handles from the range, and a container from that
00475 tagged_ents.resize( output_ents.size() );
00476 std::copy( output_ents.begin(), output_ents.end(), tagged_ents.begin() );
00477 ent_cont = DMSLcontainer_create_vector( dU.dmslModel, (damsel_handle_ptr)&tagged_ents[0], tagged_ents.size() );
00478 std::cerr << "MOAB: created model container: sparse_tag_ent_cont = " << ent_cont << std::endl;
00479 if( DAMSEL_CONTAINER_INVALID == ent_cont )
00480 MB_SET_ERR( MB_FAILURE, "Trouble creating entity handle container for tag " << stag->get_name() );
00481
00482 // Now map it
00483 err = DMSLmodel_map_tag( (void*)&tag_values[0], ent_cont, (damsel_handle_ptr)&stag );
00484 CHK_DMSL_ERR( err, "Failed to write tag " << stag->get_name() );
00485
00486 err = DMSLcontainer_release( ent_cont );
00487 CHK_DMSL_ERR( err, "Problem releasing entity handle container" );
00488 }
00489
00490 return rval;
00491 }
00492
00493 ErrorCode WriteDamsel::write_sets( RangeSeqIntersectIter& rsi )
00494 {
00495 // Write the sets
00496 ErrorCode rval = MB_SUCCESS;
00497 std::vector< EntityHandle > ents;
00498 damsel_container mcont;
00499 damsel_err_t err;
00500 unsigned int i, num_sets = rsi.get_end_handle() - rsi.get_start_handle() + 1;
00501 std::vector< unsigned int > set_flags( num_sets, 0 );
00502 EntityHandle seth;
00503 for( seth = rsi.get_start_handle(), i = 0; seth <= rsi.get_end_handle(); seth++, i++ )
00504 {
00505 // Get all the entities in the set
00506 ents.clear();
00507 rval = mbImpl->get_entities_by_handle( seth, ents );MB_CHK_SET_ERR( rval, "get_entities_by_handle failed for set " << seth );
00508 if( !ents.empty() )
00509 {
00510 mcont = DMSLcontainer_create_vector( dU.dmslModel, (damsel_handle*)&ents[0], ents.size() );
00511 }
00512 else
00513 {
00514 mcont = DMSLcontainer_create_vector( dU.dmslModel, (damsel_handle*)NULL, 0 );
00515 }
00516 std::cerr << "MOAB: created model container: sets_cont = " << mcont << std::endl;
00517
00518 // Get the set type (range or set)
00519 unsigned int opts;
00520 rval = mbImpl->get_meshset_options( seth, opts );MB_CHK_SET_ERR( rval, "Failed to get options for meshset " << seth );
00521 damsel_collection_type coll_type =
00522 ( opts & MESHSET_SET ? DAMSEL_HANDLE_COLLECTION_TYPE_SET : DAMSEL_HANDLE_COLLECTION_TYPE_VECTOR );
00523
00524 // Parents/children...
00525
00526 // Set flags
00527 if( opts & MESHSET_TRACK_OWNER )
00528 set_flags[i] |= MESHSET_TRACK_OWNER;
00529 else
00530 set_flags[i] &= !MESHSET_TRACK_OWNER;
00531
00532 // Create the collection
00533 DMSLcoll_create( dU.dmslModel, (damsel_handle_ptr)&seth, mcont, coll_type );
00534
00535 // Release the container
00536 err = DMSLcontainer_release( mcont );
00537 CHK_DMSL_ERR( err, "Problem releasing set entity handle container" );
00538 }
00539
00540 // Set the COLL_FLAGS tag, using assign (direct)
00541 // Make a container of set handles...
00542 mcont = DMSLcontainer_create_sequence( dU.dmslModel, rsi.get_start_handle(), num_sets, 1 );
00543 std::cerr << "MOAB: created model container: sets_cont = " << mcont << std::endl;
00544
00545 // Assign the tags on them
00546 err = DMSLmodel_map_tag( &set_flags[0], mcont, ( damsel_handle_ptr ) & ( dU.collFlagsTag.mTagh ) );
00547 CHK_DMSL_ERR( err, "Failed to assign COLL_FLAGS tag for sets" );
00548
00549 // Map set handles
00550 err = DMSLmodel_map_handles_inventing_file_handles( mcont );
00551 CHK_DMSL_ERR( err, "Failed to map set handles" );
00552
00553 // Map other dense tags
00554 rval = map_dense_tags( rsi, mcont );MB_CHK_SET_ERR( rval, "Failed to map dense tags for sets" );
00555
00556 return rval;
00557 }
00558
00559 } // namespace moab