Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
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>

+ Collaboration diagram for moab::SpectralMeshTool:

Public Member Functions

 SpectralMeshTool (Interface *impl, int order=0)
 Constructor. More...
 
 ~SpectralMeshTool ()
 Destructor. More...
 
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. More...
 
Tag spectral_order_tag (const bool create_if_missing=false)
 Return tag used to store spectral order. More...
 
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. More...
 
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. More...
 
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. More...
 
void spectral_order (int order)
 Set spectral order for this instance. More...
 
int spectral_order ()
 Get spectral order for this instance. More...
 

Static Public Attributes

static const short int permute_array [] = { 0, 1, 13, 25, 3, 2, 14, 26, 7, 6, 18, 30, 11, 10, 22, 34 }
 
static const short int lin_permute_array [] = { 0, 25, 34, 11 }
 

Private Attributes

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

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 22 of file SpectralMeshTool.hpp.

Constructor & Destructor Documentation

◆ SpectralMeshTool()

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

Constructor.

Parameters
implMOAB Interface instance
orderSpectral order, defaults to 0

Definition at line 131 of file SpectralMeshTool.hpp.

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

References mError, and moab::Interface::query_interface().

◆ ~SpectralMeshTool()

moab::SpectralMeshTool::~SpectralMeshTool ( )
inline

Destructor.

Definition at line 137 of file SpectralMeshTool.hpp.

137 {}

Member Function Documentation

◆ convert_to_coarse()

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 72 of file SpectralMeshTool.cpp.

73 {
74  if( order ) spectralOrder = order;
75  if( !spectralOrder )
76  {
77  MB_SET_ERR( MB_FAILURE, "Spectral order must be set or input before converting to spectral mesh" );
78  }
79 
80  Range tmp_ents, ents;
81  ErrorCode rval = mbImpl->get_entities_by_handle( spectral_set, tmp_ents );
82  if( MB_SUCCESS != rval || ents.empty() ) return rval;
83 
84  // get the max-dimensional elements from it
85  ents = tmp_ents.subset_by_dimension( 3 );
86  if( ents.empty() ) ents = tmp_ents.subset_by_dimension( 2 );
87  if( ents.empty() ) ents = tmp_ents.subset_by_dimension( 1 );
88  if( ents.empty() )
89  {
90  MB_SET_ERR( MB_FAILURE, "Can't find any entities for conversion" );
91  }
92 
93  // get a ptr to connectivity
94  if( ents.psize() != 1 )
95  {
96  MB_SET_ERR( MB_FAILURE, "Entities must be in one chunk for conversion" );
97  }
98  EntityHandle* conn;
99  int count, verts_per_e;
100  rval = mbImpl->connect_iterate( ents.begin(), ents.end(), conn, verts_per_e, count );
101  if( MB_SUCCESS != rval || count != (int)ents.size() ) return rval;
102 
103  Range tmp_range;
104  return create_spectral_elems( conn, ents.size(), CN::Dimension( TYPE_FROM_HANDLE( *ents.begin() ) ), tmp_range );
105 }

References moab::Range::begin(), moab::Interface::connect_iterate(), create_spectral_elems(), moab::CN::Dimension(), moab::Range::empty(), moab::Range::end(), ErrorCode, moab::Interface::get_entities_by_handle(), MB_SET_ERR, MB_SUCCESS, mbImpl, moab::Range::psize(), moab::Range::size(), spectralOrder, moab::Range::subset_by_dimension(), and moab::TYPE_FROM_HANDLE().

◆ convert_to_fine()

ErrorCode moab::SpectralMeshTool::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.

Parameters
spectral_setSet containing spectral elements

Definition at line 59 of file SpectralMeshTool.cpp.

60 {
61  return MB_NOT_IMPLEMENTED;
62 }

References MB_NOT_IMPLEMENTED.

◆ create_spectral_elems()

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 108 of file SpectralMeshTool.cpp.

114 {
115  assert( spectralOrder && num_fine_elems );
116 
117  // now create num_coarse_elems
118  // compute the number of local elems, accounting for coarse or fine representation
119  // spectral_unit is the # fine elems per coarse elem, or spectralOrder^2
120  int spectral_unit = spectralOrder * spectralOrder;
121  int num_coarse_elems = num_fine_elems / spectral_unit;
122 
123  EntityHandle* new_conn;
124  EntityHandle start_elem;
125  ReadUtilIface* rmi;
126  ErrorCode rval = mbImpl->query_interface( rmi );
127  if( MB_SUCCESS != rval ) return rval;
128 
129  int verts_per_felem = spectralOrderp1 * spectralOrderp1, verts_per_celem = std::pow( (double)2.0, dim );
130 
131  rval = rmi->get_element_connect( num_coarse_elems, verts_per_celem, ( 2 == dim ? MBQUAD : MBHEX ), 0, start_elem,
132  new_conn );MB_CHK_SET_ERR( rval, "Failed to create elems" );
133 
134  output_range.insert( start_elem, start_elem + num_coarse_elems - 1 );
135 
136  // read connectivity into that space
137 
138  // permute_array takes a 4*order^2-long vector of integers, representing the connectivity of
139  // order^2 elems (fine elems in a coarse elem), and picks out the ids of the vertices necessary
140  // to get a lexicographically-ordered array of vertices in a spectral element of that order
141  // assert(verts_per_felem == (sizeof(permute_array)/sizeof(unsigned int)));
142 
143  // we're assuming here that elems was empty on input
144  int count;
145  EntityHandle* sv_ptr = NULL;
146  rval = mbImpl->tag_iterate( spectral_vertices_tag( true ), output_range.begin(), output_range.end(), count,
147  (void*&)sv_ptr );MB_CHK_SET_ERR( rval, "Failed to get SPECTRAL_VERTICES ptr" );
148  assert( count == num_coarse_elems );
149  int f = start_idx, fs = 0, fl = 0;
150  for( int c = 0; c < num_coarse_elems; c++ )
151  {
152  for( int i = 0; i < verts_per_celem; i++ )
153  new_conn[fl + i] = conn[f + lin_permute_array[i]];
154  fl += verts_per_celem;
155  for( int i = 0; i < verts_per_felem; i++ )
156  sv_ptr[fs + i] = conn[f + permute_array[i]];
157  f += verts_per_celem * spectral_unit;
158  fs += verts_per_felem;
159  }
160  if( local_gids ) std::copy( sv_ptr, sv_ptr + verts_per_felem * num_coarse_elems, range_inserter( *local_gids ) );
161 
162  return MB_SUCCESS;
163 }

References moab::Range::begin(), dim, moab::Range::end(), ErrorCode, moab::ReadUtilIface::get_element_connect(), moab::Range::insert(), lin_permute_array, MB_CHK_SET_ERR, MB_SUCCESS, MBHEX, mbImpl, MBQUAD, permute_array, moab::Interface::query_interface(), spectral_vertices_tag(), spectralOrder, spectralOrderp1, and moab::Interface::tag_iterate().

Referenced by convert_to_coarse(), and moab::NCHelperHOMME::create_mesh().

◆ spectral_order() [1/2]

int moab::SpectralMeshTool::spectral_order ( )
inline

Get spectral order for this instance.

Returns
order Order set on this instance

Definition at line 97 of file SpectralMeshTool.hpp.

98  {
99  return spectralOrder;
100  }

References spectralOrder.

◆ spectral_order() [2/2]

void moab::SpectralMeshTool::spectral_order ( int  order)
inline

Set spectral order for this instance.

Parameters
orderOrder set on this instance

Definition at line 88 of file SpectralMeshTool.hpp.

89  {
90  spectralOrder = order;
91  spectralOrderp1 = order + 1;
92  }

References spectralOrder, and spectralOrderp1.

◆ spectral_order_tag()

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 40 of file SpectralMeshTool.cpp.

41 {
42  ErrorCode rval = MB_SUCCESS;
43  if( !soTag && create_if_missing )
44  {
45 
46  // create it
47  int dum = 0;
48  rval = mbImpl->tag_get_handle( "SPECTRAL_ORDER", 1, MB_TYPE_INTEGER, soTag, MB_TAG_DENSE | MB_TAG_CREAT, &dum );
49  }
50 
51  return ( rval == MB_SUCCESS ? soTag : 0 );
52 }

References moab::dum, ErrorCode, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, mbImpl, soTag, and moab::Interface::tag_get_handle().

◆ spectral_vertices_tag()

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 17 of file SpectralMeshTool.cpp.

18 {
19  ErrorCode rval = MB_SUCCESS;
20  if( !svTag && create_if_missing )
21  {
22  if( !spectralOrder )
23  {
24  // should already be a spectral order tag...
25  MB_SET_ERR_RET_VAL( "Spectral order must be set before creating spectral vertices tag", 0 );
26  }
27 
28  // create it
29  std::vector< EntityHandle > dum_val( spectralOrderp1 * spectralOrderp1, 0 );
30  rval = mbImpl->tag_get_handle( "SPECTRAL_VERTICES", spectralOrderp1 * spectralOrderp1, MB_TYPE_HANDLE, svTag,
31  MB_TAG_DENSE | MB_TAG_CREAT, &dum_val[0] );
32  }
33 
34  return ( rval == MB_SUCCESS ? svTag : 0 );
35 }

References ErrorCode, MB_SET_ERR_RET_VAL, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_HANDLE, mbImpl, spectralOrder, spectralOrderp1, svTag, and moab::Interface::tag_get_handle().

Referenced by moab::NCHelperHOMME::create_mesh(), and create_spectral_elems().

Member Data Documentation

◆ lin_permute_array

const short int moab::SpectralMeshTool::lin_permute_array = { 0, 25, 34, 11 }
static

Definition at line 109 of file SpectralMeshTool.hpp.

Referenced by create_spectral_elems().

◆ mbImpl

Interface* moab::SpectralMeshTool::mbImpl
private

the MB instance that this works with

Definition at line 113 of file SpectralMeshTool.hpp.

Referenced by convert_to_coarse(), create_spectral_elems(), spectral_order_tag(), and spectral_vertices_tag().

◆ mError

Error* moab::SpectralMeshTool::mError
private

error object for this tool

Definition at line 116 of file SpectralMeshTool.hpp.

Referenced by SpectralMeshTool().

◆ permute_array

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

Definition at line 107 of file SpectralMeshTool.hpp.

Referenced by create_spectral_elems().

◆ soTag

Tag moab::SpectralMeshTool::soTag
private

SPECTRAL_ORDER tag.

Definition at line 122 of file SpectralMeshTool.hpp.

Referenced by spectral_order_tag().

◆ spectralOrder

int moab::SpectralMeshTool::spectralOrder
private

order of the spectral mesh being accessed

Definition at line 125 of file SpectralMeshTool.hpp.

Referenced by convert_to_coarse(), create_spectral_elems(), spectral_order(), and spectral_vertices_tag().

◆ spectralOrderp1

int moab::SpectralMeshTool::spectralOrderp1
private

order of the spectral mesh being accessed plus one

Definition at line 128 of file SpectralMeshTool.hpp.

Referenced by create_spectral_elems(), spectral_order(), and spectral_vertices_tag().

◆ svTag

Tag moab::SpectralMeshTool::svTag
private

SPECTRAL_VERTICES tag.

Definition at line 119 of file SpectralMeshTool.hpp.

Referenced by spectral_vertices_tag().


The documentation for this class was generated from the following files: