MOAB: Mesh Oriented datABase
(version 5.4.1)
|
#include "moab/Core.hpp"
#include "moab/ScdInterface.hpp"
#include "moab/ProgOptions.hpp"
#include "moab/CN.hpp"
#include <iostream>
#include <vector>
Go to the source code of this file.
Defines | |
#define | MYSTREAM(a) if( !rank ) cout << ( a ) << endl |
Functions | |
int | main (int argc, char **argv) |
Referenced by main().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 39 of file StructuredMeshSimple.cpp.
References ProgOptions::addOpt(), moab::Range::begin(), box(), moab::ScdInterface::construct_box(), dim, moab::CN::EntityTypeName(), ErrorCode, moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::ScdBox::get_element(), moab::Interface::get_entities_by_dimension(), mb, MB_CHK_ERR, MPI_COMM_WORLD, MYSTREAM, ProgOptions::parseCommandLine(), moab::Interface::query_interface(), rank, moab::Interface::release_interface(), moab::Range::size(), and moab::Interface::type_from_handle().
{ int N = 10, dim = 3; #ifdef MOAB_HAVE_MPI MPI_Init( &argc, &argv ); #endif ProgOptions opts; opts.addOpt< int >( string( "dim,d" ), string( "Dimension of mesh (default=3)" ), &dim ); opts.addOpt< int >( string( ",n" ), string( "Number of elements on a side (default=10)" ), &N ); opts.parseCommandLine( argc, argv ); // 0. Instantiate MOAB and get the structured mesh interface Interface* mb = new( std::nothrow ) Core; if( NULL == mb ) return 1; ScdInterface* scdiface; ErrorCode rval = mb->query_interface( scdiface );MB_CHK_ERR( rval ); // Get a ScdInterface object through moab instance // 1. Decide what the local parameters of the mesh will be, based on parallel/serial and rank. #ifdef MOAB_HAVE_MPI int rank = 0, nprocs = 1; MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); int ilow = rank * N, ihigh = ilow + N; #else int rank = 0; int ilow = 0, ihigh = N; #endif // 2. Create a N^d structured mesh, which includes (N+1)^d vertices and N^d elements. ScdBox* box; rval = scdiface->construct_box( HomCoord( ilow, ( dim > 1 ? 0 : -1 ), ( dim > 2 ? 0 : -1 ) ), // Use in-line logical tests to handle dimensionality HomCoord( ihigh, ( dim > 1 ? N : -1 ), ( dim > 2 ? N : -1 ) ), NULL, 0, // NULL coords vector and 0 coords (don't specify coords for now) box );MB_CHK_ERR( rval ); // box is the structured box object providing the parametric // structured mesh interface for this rectangle of elements // 3. Get the vertices and elements from moab and check their numbers against (N+1)^d and N^d, // resp. Range verts, elems; rval = mb->get_entities_by_dimension( 0, 0, verts );MB_CHK_ERR( rval ); // First '0' specifies "root set", or entire MOAB instance, second the // entity dimension being requested rval = mb->get_entities_by_dimension( 0, dim, elems );MB_CHK_ERR( rval ); #define MYSTREAM( a ) \ if( !rank ) cout << ( a ) << endl if( pow( N, dim ) == (int)elems.size() && pow( N + 1, dim ) == (int)verts.size() ) { // Expected #e and #v are N^d and (N+1)^d, resp. #ifdef MOAB_HAVE_MPI MYSTREAM( "Proc 0: " ); #endif MYSTREAM( "Created " << elems.size() << " " << CN::EntityTypeName( mb->type_from_handle( *elems.begin() ) ) << " elements and " << verts.size() << " vertices." << endl ); } else cout << "Created the wrong number of vertices or hexes!" << endl; // 4. Loop over elements in 3 nested loops over i, j, k; for each (i,j,k): vector< double > coords( 3 * pow( N + 1, dim ) ); vector< EntityHandle > connect; for( int k = 0; k < ( dim > 2 ? N : 1 ); k++ ) { for( int j = 0; j < ( dim > 1 ? N : 1 ); j++ ) { for( int i = 0; i < N - 1; i++ ) { // 4a. Get the element corresponding to (i,j,k) EntityHandle ehandle = box->get_element( i, j, k ); if( 0 == ehandle ) return MB_FAILURE; // 4b. Get the connectivity of the element rval = mb->get_connectivity( &ehandle, 1, connect );MB_CHK_ERR( rval ); // Get the connectivity, in canonical order // 4c. Get the coordinates of the vertices comprising that element rval = mb->get_coords( &connect[0], connect.size(), &coords[0] );MB_CHK_ERR( rval ); // Get the coordinates of those vertices } } } // 5. Release the structured mesh interface and destroy the MOAB instance mb->release_interface( scdiface ); // Tell MOAB we're done with the ScdInterface #ifdef MOAB_HAVE_MPI MPI_Finalize(); #endif return 0; }