MOAB: Mesh Oriented datABase  (version 5.4.1)
read_ucd_nc.cpp File Reference
#include "TestUtil.hpp"
#include "moab/Core.hpp"
#include "moab/ReadUtilIface.hpp"
#include "TagInfo.hpp"
#include "MBTagConventions.hpp"
+ Include dependency graph for read_ucd_nc.cpp:

Go to the source code of this file.

Functions

void test_read_all ()
void test_read_onevar ()
void test_read_onetimestep ()
void test_read_nomesh ()
void test_read_novars ()
void test_read_coord_vars ()
void test_gather_onevar ()
void test_read_conn ()
void get_options (std::string &opts)
int main (int argc, char *argv[])

Variables

std::string example = "unittest/io/homme3x3458.t.3.nc"
std::string conn_fname = "unittest/io/HommeMapping.nc"
const int levels = 3

Function Documentation

void get_options ( std::string &  opts)
int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file read_ucd_nc.cpp.

References moab::fail(), RUN_TEST, test_gather_onevar(), test_read_all(), test_read_conn(), test_read_coord_vars(), test_read_nomesh(), test_read_novars(), test_read_onetimestep(), and test_read_onevar().

{
    int result = 0;

#ifdef MOAB_HAVE_MPI
    int fail = MPI_Init( &argc, &argv );
    if( fail ) return 1;
#else
    argv[0]   = argv[argc - argc];  // To remove the warnings in serial mode about unused variables
#endif

    result += RUN_TEST( test_read_all );
    result += RUN_TEST( test_read_onevar );
    result += RUN_TEST( test_read_onetimestep );
    result += RUN_TEST( test_read_nomesh );
    result += RUN_TEST( test_read_novars );
    result += RUN_TEST( test_read_coord_vars );
    result += RUN_TEST( test_gather_onevar );
    result += RUN_TEST( test_read_conn );

#ifdef MOAB_HAVE_MPI
    fail = MPI_Finalize();
    if( fail ) return 1;
#endif

    return result;
}
void test_read_all ( )
void test_read_conn ( )

Definition at line 363 of file read_ucd_nc.cpp.

References CHECK_EQUAL, CHECK_ERR, conn_fname, ErrorCode, moab::Interface::get_entities_by_type(), get_options(), moab::ParallelComm::get_pcomm(), moab::Interface::load_file(), MBQUAD, MBVERTEX, moab::ParallelComm::proc_config(), moab::ProcConfig::proc_size(), and moab::Range::size().

Referenced by main().

{
    Core moab;
    Interface& mb = moab;

    std::string opts;
    get_options( opts );

    ErrorCode rval = mb.load_file( conn_fname.c_str(), NULL, opts.c_str() );CHECK_ERR( rval );

#ifdef MOAB_HAVE_MPI
    ParallelComm* pcomm = ParallelComm::get_pcomm( &mb, 0 );
    int procs           = pcomm->proc_config().proc_size();
#else
    int procs = 1;
#endif

    // Make check runs this test on one processor
    if( 1 == procs )
    {
        // Get vertices
        Range verts;
        rval = mb.get_entities_by_type( 0, MBVERTEX, verts );CHECK_ERR( rval );
        CHECK_EQUAL( (size_t)3458, verts.size() );

        // Get cells
        Range cells;
        rval = mb.get_entities_by_type( 0, MBQUAD, cells );CHECK_ERR( rval );
        CHECK_EQUAL( (size_t)3456, cells.size() );
    }
}

Definition at line 212 of file read_ucd_nc.cpp.

References CHECK_EQUAL, CHECK_ERR, CHECK_REAL_EQUAL, moab::Interface::create_meshset(), eps, ErrorCode, example, get_options(), levels, moab::Interface::load_file(), MB_TAG_SPARSE, MB_TAG_VARLEN, MB_TYPE_DOUBLE, MB_TYPE_INTEGER, MB_TYPE_OPAQUE, MESHSET_SET, moab::Interface::tag_get_by_ptr(), and moab::Interface::tag_get_handle().

Referenced by main().

{
    Core moab;
    Interface& mb = moab;

    EntityHandle file_set;
    ErrorCode rval = mb.create_meshset( MESHSET_SET, file_set );CHECK_ERR( rval );

    std::string orig, opts;
    get_options( orig );

    opts = orig + std::string( ";NOMESH;VARIABLE=" );
    rval = mb.load_file( example.c_str(), &file_set, opts.c_str() );CHECK_ERR( rval );

    std::string tag_name;
    int var_len;
    Tag var_tag;
    const void* var_data;

    // Check tag for regular coordinate variable lev
    tag_name = "lev";
    var_len  = 0;
    rval     = mb.tag_get_handle( tag_name.c_str(), var_len, MB_TYPE_OPAQUE, var_tag, MB_TAG_SPARSE | MB_TAG_VARLEN );CHECK_ERR( rval );
    CHECK_EQUAL( true, var_tag->variable_length() );
    CHECK_EQUAL( MB_TYPE_DOUBLE, var_tag->get_data_type() );

    // Check lev tag size and values on file_set
    rval = mb.tag_get_by_ptr( var_tag, &file_set, 1, &var_data, &var_len );CHECK_ERR( rval );
    CHECK_EQUAL( levels, var_len );
    double* lev_val  = (double*)var_data;
    const double eps = 1e-10;
    CHECK_REAL_EQUAL( 3.54463800000002, lev_val[0], eps );
    CHECK_REAL_EQUAL( 13.9672100000001, lev_val[levels - 1], eps );

    // Check tag for dummy coordinate variable ncol
    tag_name = "ncol";
    var_len  = 0;
    rval     = mb.tag_get_handle( tag_name.c_str(), var_len, MB_TYPE_OPAQUE, var_tag, MB_TAG_SPARSE | MB_TAG_VARLEN );CHECK_ERR( rval );
    CHECK_EQUAL( true, var_tag->variable_length() );
    CHECK_EQUAL( MB_TYPE_INTEGER, var_tag->get_data_type() );

    // Check ncol tag size and values on file_set
    rval = mb.tag_get_by_ptr( var_tag, &file_set, 1, &var_data, &var_len );CHECK_ERR( rval );
    CHECK_EQUAL( 1, var_len );
    int* ncol_val = (int*)var_data;
    CHECK_EQUAL( 3458, ncol_val[0] );

    // Create another file set
    EntityHandle file_set2;
    rval = mb.create_meshset( MESHSET_SET, file_set2 );CHECK_ERR( rval );

    // Read file again with file_set2
    rval = mb.load_file( example.c_str(), &file_set2, opts.c_str() );CHECK_ERR( rval );

    // Check tag for regular coordinate lev
    tag_name = "lev";
    var_len  = 0;
    rval     = mb.tag_get_handle( tag_name.c_str(), var_len, MB_TYPE_OPAQUE, var_tag, MB_TAG_SPARSE | MB_TAG_VARLEN );CHECK_ERR( rval );
    CHECK_EQUAL( true, var_tag->variable_length() );
    CHECK_EQUAL( MB_TYPE_DOUBLE, var_tag->get_data_type() );

    // Check lev tag size and values on file_set2
    rval = mb.tag_get_by_ptr( var_tag, &file_set2, 1, &var_data, &var_len );CHECK_ERR( rval );
    CHECK_EQUAL( levels, var_len );
    lev_val = (double*)var_data;
    CHECK_REAL_EQUAL( 3.54463800000002, lev_val[0], eps );
    CHECK_REAL_EQUAL( 13.9672100000001, lev_val[levels - 1], eps );

    // Check tag for dummy coordinate variable ncol
    tag_name = "ncol";
    var_len  = 0;
    rval     = mb.tag_get_handle( tag_name.c_str(), var_len, MB_TYPE_OPAQUE, var_tag, MB_TAG_SPARSE | MB_TAG_VARLEN );CHECK_ERR( rval );
    CHECK_EQUAL( true, var_tag->variable_length() );
    CHECK_EQUAL( MB_TYPE_INTEGER, var_tag->get_data_type() );

    // Check ncol tag size and values on file_set2
    rval = mb.tag_get_by_ptr( var_tag, &file_set2, 1, &var_data, &var_len );CHECK_ERR( rval );
    CHECK_EQUAL( 1, var_len );
    ncol_val = (int*)var_data;
    CHECK_EQUAL( 3458, ncol_val[0] );
}
void test_read_nomesh ( )
void test_read_novars ( )
void test_read_onevar ( )

Variable Documentation

std::string conn_fname = "unittest/io/HommeMapping.nc"

Definition at line 10 of file read_ucd_nc.cpp.

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

std::string example = "unittest/io/homme3x3458.t.3.nc"

Definition at line 9 of file read_ucd_nc.cpp.

const int levels = 3

Definition at line 28 of file read_ucd_nc.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines