MOAB: Mesh Oriented datABase  (version 5.4.1)
ScdMesh

Functions

void iMesh_createStructuredMesh (iMesh_Instance instance, int *local_dims, int *global_dims, double *i_vals, double *j_vals, double *k_vals, int resolve_shared, int ghost_dim, int bridge_dim, int num_layers, int addl_ents, int vert_gids, int elem_gids, iBase_EntitySetHandle *set_handle, int *err)
 Create a structured mesh.

Detailed Description

Structured Mesh

iMeshExtensions


Function Documentation

void iMesh_createStructuredMesh ( iMesh_Instance  instance,
int *  local_dims,
int *  global_dims,
double *  i_vals,
double *  j_vals,
double *  k_vals,
int  resolve_shared,
int  ghost_dim,
int  bridge_dim,
int  num_layers,
int  addl_ents,
int  vert_gids,
int  elem_gids,
iBase_EntitySetHandle set_handle,
int *  err 
)

Create a structured mesh.

Create a structured mesh, with local and (optionally) global ijk parameters and optional physical positions. If running in parallel, can request shared vertex resolution and optional number and type of ghost layers of elements. Global parameters are used to compute global ids, which are used in shared vertex resolution.

Parameters:
[in]instanceiMesh instance handle
[in]local_dimsMin/max corners of local ijk parameters, -1 for unused dimensions; specified as ilo, jlo, klo, ihi, jhi, khi.
[in]global_dimsMin/max corners of global ijk parameters, -1 for unused dimensions; NULL if running in serial. Order similar to local_dims.
[in]i_valsPhysical positions of i values, NULL if not placed in physical space.
[in]j_valsPhysical positions of j values, NULL if not placed in physical space.
[in]k_valsPhysical positions of k values, NULL if not placed in physical space.
[in]resolve_sharedNon-zero if running in parallel and resolution of shared vertices is desired, zero otherwise.
[in]ghost_dimDimension of entities to ghost, -1 if none desired.
[in]bridge_dimDimension of bridge entities used to compute ghosts, -1 if no ghosts desired.
[in]num_layersNumber of layers of ghosts desired, -1 if no ghosts desired.
[in]addl_entsDimension of addition entities adjacent to ghosts to exchange.
[in]vert_gidsIf non-zero, assigns global ids to vertices, according to global parameterization.
[in]elem_gidsIf non-zero, assigns global ids to elements, according to global parameterization.
[in,out]set_handleA set to which the underlying ScdBox set will be added. NULL if not desired. If *NULL, will be set directly to the underlying ScdBox's set.
[out]errError flag.

Definition at line 3235 of file iMesh_MOAB.cpp.

References moab::Range::begin(), moab::ScdBox::box_set(), CHKERR, moab::ScdInterface::construct_box(), moab::Range::end(), ENTITY_HANDLE, ErrorCode, moab::ParallelComm::exchange_ghost_cells(), moab::ScdParData::gDims, moab::ScdBox::get_coordinate_arrays(), iBase_SUCCESS, moab::Range::insert(), moab::Range::lower_bound(), MOABI, moab::ScdBox::num_elements(), moab::ScdBox::num_vertices(), moab::ScdBox::par_data(), moab::ParallelComm::resolve_shared_ents(), RETURN, moab::ScdBox::start_element(), moab::ScdBox::start_vertex(), and moab::Range::upper_bound().

{
    ScdInterface* scdi = NULL;
    ErrorCode rval     = MOABI->query_interface( scdi );CHKERR( rval, "Couldn't get structured mesh interface." );

    Range tmp_range;
    ScdBox* scd_box;
    rval =
        scdi->construct_box( HomCoord( local_dims[0], local_dims[1], ( -1 != local_dims[2] ? local_dims[2] : 0 ), 1 ),
                             HomCoord( local_dims[3], local_dims[4], ( -1 != local_dims[5] ? local_dims[5] : 0 ), 1 ),
                             NULL, 0, scd_box, NULL, NULL, ( vert_gids ? true : false ) );CHKERR( rval, "Trouble creating scd vertex sequence." );

    // set the global box parameters
    if( global_dims )
    {
        for( int i = 0; i < 6; i++ )
            scd_box->par_data().gDims[i] = global_dims[i];
    }

    tmp_range.insert( scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1 );
    tmp_range.insert( scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1 );
    tmp_range.insert( scd_box->box_set() );

    if( set_handle )
    {
        if( !( *set_handle ) )
        {
            // return the new ScdBox's set
            *set_handle = reinterpret_cast< iBase_EntitySetHandle >( scd_box->box_set() );
        }
        else
        {
            // add the new ScdBox's set to the given file set
            EntityHandle s = scd_box->box_set();
            rval           = MOABI->add_entities( ENTITY_HANDLE( *set_handle ), &s, 1 );CHKERR( rval, "Couldn't add box set to file set." );
        }
    }

    // get a ptr to global id memory
    void* data;
    int count;
    Range::const_iterator topv, bote, tope;

    Tag gid_tag     = 0;
    int *v_gid_data = NULL, *e_gid_data = NULL;
    if( vert_gids || elem_gids )
    {
        gid_tag = MOABI->globalId_tag();
    }

    if( vert_gids )
    {
        topv = tmp_range.upper_bound( tmp_range.begin(), tmp_range.end(),
                                      scd_box->start_vertex() + scd_box->num_vertices() );

        rval = MOABI->tag_iterate( gid_tag, tmp_range.begin(), topv, count, data );CHKERR( rval, "Failed to get tag iterator." );
        assert( count == scd_box->num_vertices() );
        v_gid_data = (int*)data;
    }

    if( elem_gids )
    {
        bote = tmp_range.lower_bound( tmp_range.begin(), tmp_range.end(), scd_box->start_element() );
        tope = tmp_range.upper_bound( tmp_range.begin(), tmp_range.end(), *bote + scd_box->num_elements() );

        rval = MOABI->tag_iterate( gid_tag, bote, tope, count, data );CHKERR( rval, "Failed to get tag iterator." );
        assert( count == scd_box->num_elements() );
        e_gid_data = (int*)data;
    }

    if( i_vals || j_vals || k_vals || v_gid_data || e_gid_data )
    {

        // set the vertex coordinates
        double *xc, *yc, *zc;
        rval = scd_box->get_coordinate_arrays( xc, yc, zc );CHKERR( rval, "Couldn't get vertex coordinate arrays." );

        int i, j, k, il, jl, kl;
        int dil = local_dims[3] - local_dims[0] + 1;
        int djl = local_dims[4] - local_dims[1] + 1;
        int di  = ( global_dims ? global_dims[3] - global_dims[0] + 1 : dil );
        int dj  = ( global_dims ? global_dims[4] - global_dims[1] + 1 : djl );
        for( kl = local_dims[2]; kl <= local_dims[5]; kl++ )
        {
            k = kl - local_dims[2];
            for( jl = local_dims[1]; jl <= local_dims[4]; jl++ )
            {
                j = jl - local_dims[1];
                for( il = local_dims[0]; il <= local_dims[3]; il++ )
                {
                    i                = il - local_dims[0];
                    unsigned int pos = i + j * dil + k * dil * djl;
                    xc[pos]          = ( i_vals ? i_vals[i] : -1.0 );
                    yc[pos]          = ( j_vals ? j_vals[j] : -1.0 );
                    zc[pos]          = ( -1 == local_dims[2] ? 0.0 : ( k_vals ? k_vals[k] : -1.0 ) );
                    if( v_gid_data )
                    {
                        *v_gid_data = ( -1 != kl ? kl * di * dj : 0 ) + jl * di + il + 1;
                        v_gid_data++;
                    }
                    if( e_gid_data && kl < local_dims[5] && jl < local_dims[4] && il < local_dims[3] )
                    {
                        *e_gid_data = ( -1 != kl ? kl * ( di - 1 ) * ( dj - 1 ) : 0 ) + jl * ( di - 1 ) + il + 1;
                        e_gid_data++;
                    }
                }
            }
        }
    }

#ifdef MOAB_HAVE_MPI
    // do parallel stuff, if requested
    if( resolve_shared )
    {
        ParallelComm* pcomm = ParallelComm::get_pcomm( MOABI, 0 );
        if( pcomm )
        {

            rval =
                pcomm->resolve_shared_ents( 0, MOABI->dimension_from_handle( scd_box->start_element() ), 0, &gid_tag );CHKERR( rval, "Trouble resolving shared vertices." );

            if( -1 != ghost_dim )
            {
                rval = pcomm->exchange_ghost_cells( ghost_dim, bridge_dim, num_layers, addl_ents, true );CHKERR( rval, "Trouble exchanging ghosts." );
            }
        }
    }
#else
    // empty statement to remove compiler warning
    if( resolve_shared || ghost_dim || bridge_dim || num_layers || addl_ents )
    {
    }
#endif

    RETURN( iBase_SUCCESS );
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines