moab
moab::SpectralMeshTool Class Reference

Class with convenience functions for handling spectral mesh Class with convenience functions for handling spectral meshes. See description of spectral mesh handling in doc/metadata_info.doc and in the MOAB user's guide. More...

#include <SpectralMeshTool.hpp>

List of all members.

Public Member Functions

 SpectralMeshTool (Interface *impl, int order=0)
 Constructor.
 ~SpectralMeshTool ()
 Destructor.
Tag spectral_vertices_tag (const bool create_if_missing=false)
 Return tag used to store lexicographically-ordered vertex array NOTE: If creating this tag with this call, this SpectralMeshTool instance must already have a non-zero spectral order value set on it; the size of the spectral vertices tag depends on this order.
Tag spectral_order_tag (const bool create_if_missing=false)
 Return tag used to store spectral order.
ErrorCode convert_to_fine (EntityHandle spectral_set)
 Convert representation from coarse to fine Each element in set, or in interface if set is not input, is converted to fine elements, using vertices in SPECTRAL_VERTICES tagged array.
ErrorCode convert_to_coarse (int order=0, EntityHandle spectral_set=0)
 Convert representation from fine to coarse Each element in set, or in interface if set is not input, is converted to coarse elements, with fine vertices put into SPECTRAL_VERTICES tagged array. NOTE: This function assumes that each order^d (fine) elements comprise each coarse element, and are in order of fine elements in each coarse element. If order is input as 0, looks for a SPECTRAL_ORDER tag on the mesh.
template<class T >
ErrorCode create_spectral_elems (const T *conn, int num_fine_elems, int dim, Range &output_range, int start_idx=0, Range *local_gids=NULL)
 Create coarse spectral elements from fine elements pointed to by conn This function creates the coarse elements by taking conn (assumed to be in FE ordering) and picking out the corner vertices to make coarse connectivity, and the other vertices (along with corners) to make SPECTRAL_VERTICES array pointed to by each entity.
void spectral_order (int order)
 Set spectral order for this instance.
int spectral_order ()
 Get spectral order for this instance.

Static Public Attributes

static const short int permute_array []
static const short int lin_permute_array []

Private Attributes

InterfacembImpl
 the MB instance that this works with
ErrormError
 error object for this tool
Tag svTag
 SPECTRAL_VERTICES tag.
Tag soTag
 SPECTRAL_ORDER tag.
int spectralOrder
 order of the spectral mesh being accessed
int spectralOrderp1
 order of the spectral mesh being accessed plus one

Detailed Description

Class with convenience functions for handling spectral mesh Class with convenience functions for handling spectral meshes. See description of spectral mesh handling in doc/metadata_info.doc and in the MOAB user's guide.

There are two primary representations of spectral meshes: a) coarse elements: with SPECTRAL_VERTICES lexicographically-ordered array of fine vertices on each element, and tags on vertices or on elements (with _LEX suffix) b) fine elements: as linear elements made from fine vertices, with tags on vertices

Definition at line 21 of file SpectralMeshTool.hpp.


Constructor & Destructor Documentation

moab::SpectralMeshTool::SpectralMeshTool ( Interface impl,
int  order = 0 
) [inline]

Constructor.

Parameters:
implMOAB Interface instance
orderSpectral order, defaults to 0

Definition at line 121 of file SpectralMeshTool.hpp.

        : mbImpl(impl), svTag(0), soTag(0), spectralOrder(order), spectralOrderp1(order+1)
{
  impl->query_interface(mError);
}

Destructor.

Definition at line 127 of file SpectralMeshTool.hpp.

{}

Member Function Documentation

ErrorCode moab::SpectralMeshTool::convert_to_coarse ( int  order = 0,
EntityHandle  spectral_set = 0 
)

Convert representation from fine to coarse Each element in set, or in interface if set is not input, is converted to coarse elements, with fine vertices put into SPECTRAL_VERTICES tagged array. NOTE: This function assumes that each order^d (fine) elements comprise each coarse element, and are in order of fine elements in each coarse element. If order is input as 0, looks for a SPECTRAL_ORDER tag on the mesh.

Parameters:
orderOrder of the spectral mesh
spectral_setSet containing spectral elements

Definition at line 74 of file SpectralMeshTool.cpp.

{
  if (order) spectralOrder = order;
  if (!spectralOrder) {
      mError->set_last_error("Spectral order must be set or input before converting to spectral mesh.");
      return MB_FAILURE;
  }
  
  Range tmp_ents, ents;
  ErrorCode rval = mbImpl->get_entities_by_handle(spectral_set, tmp_ents);
  if (MB_SUCCESS != rval || ents.empty()) return rval;
  
    // get the max-dimensional elements from it
  ents = tmp_ents.subset_by_dimension(3);
  if (ents.empty()) ents = tmp_ents.subset_by_dimension(2);
  if (ents.empty()) ents = tmp_ents.subset_by_dimension(1);
  if (ents.empty()) {
    mError->set_last_error("Can't find any entities for conversion!");
    return MB_FAILURE;
  }
    
    // get a ptr to connectivity
  if (ents.psize() != 1) {
    mError->set_last_error("Entities must be in one chunk for conversion.");
    return MB_FAILURE;
  }
  EntityHandle *conn;
  int count, verts_per_e;
  rval = mbImpl->connect_iterate(ents.begin(), ents.end(), conn, verts_per_e, count);
  if (MB_SUCCESS != rval || count != (int)ents.size()) return rval;

  Range tmp_range;
  return create_spectral_elems(conn, ents.size(), CN::Dimension(TYPE_FROM_HANDLE(*ents.begin())), tmp_range);
}

Convert representation from coarse to fine Each element in set, or in interface if set is not input, is converted to fine elements, using vertices in SPECTRAL_VERTICES tagged array.

Parameters:
spectral_setSet containing spectral elements

Definition at line 60 of file SpectralMeshTool.cpp.

{
  return MB_NOT_IMPLEMENTED;
}
template<class T >
template ErrorCode moab::SpectralMeshTool::create_spectral_elems< EntityHandle > ( const T conn,
int  num_fine_elems,
int  dim,
Range output_range,
int  start_idx = 0,
Range local_gids = NULL 
)

Create coarse spectral elements from fine elements pointed to by conn This function creates the coarse elements by taking conn (assumed to be in FE ordering) and picking out the corner vertices to make coarse connectivity, and the other vertices (along with corners) to make SPECTRAL_VERTICES array pointed to by each entity.

Parameters:
connConnectivity of fine (linear) elements, in FE ordering
verts_per_eVertices per entity
num_fine_elemsNumber of fine elements represented by conn
spectral_setSet to which coarse elements should be added, if any
start_idxStarting index in conn (for parallel support)
local_gidsIf non-null, will insert all fine vertices into this range

Definition at line 110 of file SpectralMeshTool.cpp.

{
  assert(spectralOrder && num_fine_elems);
  
    // now create num_coarse_elems
    // compute the number of local elems, accounting for coarse or fine representation
    // spectral_unit is the # fine elems per coarse elem, or spectralOrder^2
  int spectral_unit = spectralOrder*spectralOrder;
  int num_coarse_elems = num_fine_elems / spectral_unit;

  EntityHandle *new_conn;
  EntityHandle start_elem;
  ReadUtilIface *rmi;
  ErrorCode rval = mbImpl->query_interface(rmi);
  if (MB_SUCCESS != rval) return rval;
  
  int verts_per_felem = spectralOrderp1*spectralOrderp1,
      verts_per_celem = std::pow((double)2.0, dim);

  rval = rmi->get_element_connect(num_coarse_elems, verts_per_celem,
                                  (2 == dim ? MBQUAD : MBHEX), 0, start_elem, new_conn);
  if (MB_SUCCESS != rval) {
    mError->set_last_error("Failed to create elems.");
    return rval;
  }

  output_range.insert(start_elem, start_elem + num_coarse_elems - 1);

    // read connectivity into that space

    // permute_array takes a 4*order^2-long vector of integers, representing the connectivity of order^2
    // elems (fine elems in a coarse elem), and picks out the ids of the vertices necessary
    // to get a lexicographically-ordered array of vertices in a spectral element of that order
    //assert(verts_per_felem == (sizeof(permute_array)/sizeof(unsigned int)));
  
    // we're assuming here that elems was empty on input
  int count;
  EntityHandle *sv_ptr = NULL;
  rval = mbImpl->tag_iterate(spectral_vertices_tag(true), output_range.begin(), output_range.end(), count, (void*&)sv_ptr);
  if (MB_SUCCESS != rval) {
    mError->set_last_error("Failed to get SPECTRAL_VERTICES ptr.");
    return rval;
  }
  assert(count == num_coarse_elems);
  int f = start_idx, fs = 0, fl = 0;
  for (int c = 0; c < num_coarse_elems; c++) {
    for (int i = 0; i < verts_per_celem; i++)
      new_conn[fl+i] = conn[f+lin_permute_array[i]];
    fl += verts_per_celem;
    for (int i = 0; i < verts_per_felem; i++) 
      sv_ptr[fs+i] = conn[f+permute_array[i]];
    f += verts_per_celem*spectral_unit;
    fs += verts_per_felem;
  }
  if (local_gids) 
    std::copy(sv_ptr, sv_ptr+verts_per_felem*num_coarse_elems, range_inserter(*local_gids));

  return MB_SUCCESS;
}
void moab::SpectralMeshTool::spectral_order ( int  order) [inline]

Set spectral order for this instance.

Parameters:
orderOrder set on this instance

Definition at line 84 of file SpectralMeshTool.hpp.

{spectralOrder = order; spectralOrderp1 = order+1;}

Get spectral order for this instance.

Returns:
order Order set on this instance

Definition at line 89 of file SpectralMeshTool.hpp.

{return spectralOrder;}
Tag moab::SpectralMeshTool::spectral_order_tag ( const bool  create_if_missing = false)

Return tag used to store spectral order.

Parameters:
so_tagSpectral order tag
create_if_missingIf true, will create this tag if it doesn't exist already
create_if_missingIf true, will create this tag if it doesn't exist already

Definition at line 41 of file SpectralMeshTool.cpp.

{
  ErrorCode rval = MB_SUCCESS;
  if (!soTag && create_if_missing) {
        
      // create it
    int dum = 0;
    rval = mbImpl->tag_get_handle("SPECTRAL_ORDER", 1, MB_TYPE_INTEGER,
                                  soTag, MB_TAG_DENSE | MB_TAG_CREAT, &dum);
  }
      
  return (rval == MB_SUCCESS ? soTag : 0);
}
Tag moab::SpectralMeshTool::spectral_vertices_tag ( const bool  create_if_missing = false)

Return tag used to store lexicographically-ordered vertex array NOTE: If creating this tag with this call, this SpectralMeshTool instance must already have a non-zero spectral order value set on it; the size of the spectral vertices tag depends on this order.

Parameters:
sv_tagSpectral vertices tag
create_if_missingIf true, will create this tag if it doesn't exist already

Definition at line 19 of file SpectralMeshTool.cpp.

{
  ErrorCode rval = MB_SUCCESS;
  if (!svTag && create_if_missing) {
    if (!spectralOrder) {
        // should already be a spectral order tag...
      mError->set_last_error("Spectral order must be set before creating spectral vertices tag.");
      return 0;
    }
        
      // create it
    std::vector<EntityHandle> dum_val(spectralOrderp1*spectralOrderp1, 0);
    rval = mbImpl->tag_get_handle("SPECTRAL_VERTICES", spectralOrderp1*spectralOrderp1, MB_TYPE_HANDLE,
                                  svTag, MB_TAG_DENSE | MB_TAG_CREAT, &dum_val[0]);
  }
      
  return (rval == MB_SUCCESS ? svTag : 0);
}

Member Data Documentation

Initial value:
{0, 25, 34, 11}

Definition at line 98 of file SpectralMeshTool.hpp.

the MB instance that this works with

Definition at line 103 of file SpectralMeshTool.hpp.

error object for this tool

Definition at line 106 of file SpectralMeshTool.hpp.

const short int moab::SpectralMeshTool::permute_array [static]
Initial value:
 
{0, 1, 13, 25, 3, 2, 14, 26, 7, 6, 18, 30, 11, 10, 22, 34}

Definition at line 96 of file SpectralMeshTool.hpp.

SPECTRAL_ORDER tag.

Definition at line 112 of file SpectralMeshTool.hpp.

order of the spectral mesh being accessed

Definition at line 115 of file SpectralMeshTool.hpp.

order of the spectral mesh being accessed plus one

Definition at line 118 of file SpectralMeshTool.hpp.

SPECTRAL_VERTICES tag.

Definition at line 109 of file SpectralMeshTool.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines