MOAB: Mesh Oriented datABase  (version 5.4.1)
TriLagrangeShapeTest.cpp File Reference
#include "Mesquite.hpp"
#include "TriLagrangeShape.hpp"
#include "TopologyInfo.hpp"
#include "MsqError.hpp"
#include "IdealElements.hpp"
#include "JacobianCalculator.hpp"
#include "UnitUtil.hpp"
#include <vector>
#include <algorithm>
#include <iostream>
#include <sstream>
+ Include dependency graph for TriLagrangeShapeTest.cpp:

Go to the source code of this file.

Classes

class  TriLagrangeShapeTest

Defines

#define ASSERT_VALUES_EQUAL(v1, v2, location, bits)   ASSERT_MESSAGE( value_message( ( location ), ( bits ), ( v1 ), ( v2 ) ), ( fabs( ( v1 ) - ( v2 ) ) < epsilon ) )

Typedefs

typedef double(* N_t )(double, double)

Functions

static CppUnit::Message value_message (unsigned location, NodeSet bits, double v1, double v2)
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION (TriLagrangeShapeTest,"TriLagrangeShapeTest")
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION (TriLagrangeShapeTest,"Unit")
double N0 (double r, double s)
double N1 (double r, double)
double N2 (double, double s)
double N3 (double r, double s)
double N4 (double r, double s)
double N5 (double r, double s)
double dN0dr (double r, double s)
double dN0ds (double r, double s)
double dN1dr (double r, double)
double dN1ds (double, double)
double dN2dr (double, double)
double dN2ds (double, double s)
double dN3dr (double r, double s)
double dN3ds (double r, double)
double dN4dr (double, double s)
double dN4ds (double r, double)
double dN5dr (double, double s)
double dN5ds (double r, double s)
static void get_coeff (NodeSet nodeset, const double *rs, double *coeffs)
static void get_derivs (NodeSet nodeset, const double *rs, double *derivs)
static void check_valid_indices (const size_t *vtx_in, size_t num_vtx)
static void check_no_zeros (const MsqVector< 2 > *derivs, size_t num_vtx)
static void compare_coefficients (const double *coeffs, const size_t *indices, const double *expected_coeffs, size_t num_coeff, unsigned loc, NodeSet bits)
static void compare_derivatives (const size_t *vertices, size_t num_vtx, const MsqVector< 2 > *derivs, const double *expected_derivs, unsigned loc, NodeSet bits)

Variables

const double epsilon = 1e-6
const N_t N [] = { &N0, &N1, &N2, &N3, &N4, &N5 }
const N_t dNdr [] = { &dN0dr, &dN1dr, &dN2dr, &dN3dr, &dN4dr, &dN5dr }
const N_t dNds [] = { &dN0ds, &dN1ds, &dN2ds, &dN3ds, &dN4ds, &dN5ds }
const double rs_corner [][2] = { { 0, 0 }, { 1, 0 }, { 0, 1 } }
const double rs_edge [][2] = { { 0.5, 0.0 }, { 0.5, 0.5 }, { 0.0, 0.5 } }
const double rs_mid [2] = { 1.0 / 3.0, 1.0 / 3.0 }

Detailed Description

Author:
Jason Kraftcheck

Definition in file TriLagrangeShapeTest.cpp.


Define Documentation

#define ASSERT_VALUES_EQUAL (   v1,
  v2,
  location,
  bits 
)    ASSERT_MESSAGE( value_message( ( location ), ( bits ), ( v1 ), ( v2 ) ), ( fabs( ( v1 ) - ( v2 ) ) < epsilon ) )

Definition at line 49 of file TriLagrangeShapeTest.cpp.

Referenced by compare_coefficients(), and compare_derivatives().


Typedef Documentation

typedef double( * N_t)(double, double)

Definition at line 200 of file TriLagrangeShapeTest.cpp.


Function Documentation

static void check_no_zeros ( const MsqVector< 2 > *  derivs,
size_t  num_vtx 
) [static]

Definition at line 256 of file TriLagrangeShapeTest.cpp.

References CPPUNIT_ASSERT.

Referenced by compare_derivatives().

{
    for( unsigned i = 0; i < num_vtx; ++i )
    {
        double dr = derivs[i][0];
        double ds = derivs[i][1];
        CPPUNIT_ASSERT( ( fabs( dr ) > 1e-6 ) || ( fabs( ds ) > 1e-6 ) );
    }
}
static void check_valid_indices ( const size_t *  vtx_in,
size_t  num_vtx 
) [static]

Definition at line 242 of file TriLagrangeShapeTest.cpp.

References CPPUNIT_ASSERT.

Referenced by compare_derivatives().

{
    CPPUNIT_ASSERT( num_vtx < 7 );
    CPPUNIT_ASSERT( num_vtx > 2 );
    size_t vertices[6];
    std::copy( vtx_in, vtx_in + num_vtx, vertices );
    std::sort( vertices, vertices + num_vtx );
    for( unsigned i = 1; i < num_vtx; ++i )
    {
        CPPUNIT_ASSERT( vertices[i] != vertices[i - 1] );
        CPPUNIT_ASSERT( vertices[i] < 6 );
    }
}
static void compare_coefficients ( const double *  coeffs,
const size_t *  indices,
const double *  expected_coeffs,
size_t  num_coeff,
unsigned  loc,
NodeSet  bits 
) [static]

Definition at line 266 of file TriLagrangeShapeTest.cpp.

References ASSERT_VALUES_EQUAL, CPPUNIT_ASSERT, and MBMesquite::NodeSet::mid_edge_node().

Referenced by TriLagrangeShapeTest::test_corner_coeff(), TriLagrangeShapeTest::test_edge_coeff(), and TriLagrangeShapeTest::test_mid_coeff().

{
    // find the location in the returned list for each node
    size_t revidx[6];
    double test_vals[6];
    for( size_t i = 0; i < 6; ++i )
    {
        revidx[i]    = std::find( indices, indices + num_coeff, i ) - indices;
        test_vals[i] = ( revidx[i] == num_coeff ) ? 0.0 : coeffs[revidx[i]];
    }

    // Check that index list doesn't contain any nodes not actually
    // present in the element.
    CPPUNIT_ASSERT( bits.mid_edge_node( 0 ) || ( revidx[3] == num_coeff ) );
    CPPUNIT_ASSERT( bits.mid_edge_node( 1 ) || ( revidx[4] == num_coeff ) );
    CPPUNIT_ASSERT( bits.mid_edge_node( 2 ) || ( revidx[5] == num_coeff ) );

    // compare expected and actual coefficient values
    ASSERT_VALUES_EQUAL( expected_coeffs[0], test_vals[0], loc, bits );
    ASSERT_VALUES_EQUAL( expected_coeffs[1], test_vals[1], loc, bits );
    ASSERT_VALUES_EQUAL( expected_coeffs[2], test_vals[2], loc, bits );
    ASSERT_VALUES_EQUAL( expected_coeffs[3], test_vals[3], loc, bits );
    ASSERT_VALUES_EQUAL( expected_coeffs[4], test_vals[4], loc, bits );
    ASSERT_VALUES_EQUAL( expected_coeffs[5], test_vals[5], loc, bits );
}
static void compare_derivatives ( const size_t *  vertices,
size_t  num_vtx,
const MsqVector< 2 > *  derivs,
const double *  expected_derivs,
unsigned  loc,
NodeSet  bits 
) [static]

Definition at line 297 of file TriLagrangeShapeTest.cpp.

References ASSERT_VALUES_EQUAL, check_no_zeros(), and check_valid_indices().

Referenced by TriLagrangeShapeTest::test_corner_derivs(), TriLagrangeShapeTest::test_edge_derivs(), and TriLagrangeShapeTest::test_mid_derivs().

{
    check_valid_indices( vertices, num_vtx );
    check_no_zeros( derivs, num_vtx );
    double expanded_derivs[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    for( unsigned i = 0; i < num_vtx; ++i )
    {
        expanded_derivs[2 * vertices[i]]     = derivs[i][0];
        expanded_derivs[2 * vertices[i] + 1] = derivs[i][1];
    }

    ASSERT_VALUES_EQUAL( expected_derivs[0], expanded_derivs[0], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[1], expanded_derivs[1], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[2], expanded_derivs[2], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[3], expanded_derivs[3], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[4], expanded_derivs[4], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[5], expanded_derivs[5], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[6], expanded_derivs[6], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[7], expanded_derivs[7], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[8], expanded_derivs[8], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[9], expanded_derivs[9], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[10], expanded_derivs[10], loc, bits );
    ASSERT_VALUES_EQUAL( expected_derivs[11], expanded_derivs[11], loc, bits );
}
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( TriLagrangeShapeTest  ,
"TriLagrangeShapeTest"   
)
double dN0dr ( double  r,
double  s 
)

Definition at line 151 of file TriLagrangeShapeTest.cpp.

{
    return 4 * r + 4 * s - 3;
}
double dN0ds ( double  r,
double  s 
)

Definition at line 155 of file TriLagrangeShapeTest.cpp.

{
    return 4 * r + 4 * s - 3;
}
double dN1dr ( double  r,
double   
)

Definition at line 159 of file TriLagrangeShapeTest.cpp.

{
    return 4 * r - 1;
}
double dN1ds ( double  ,
double   
)

Definition at line 163 of file TriLagrangeShapeTest.cpp.

{
    return 0;
}
double dN2dr ( double  ,
double   
)

Definition at line 167 of file TriLagrangeShapeTest.cpp.

{
    return 0;
}
double dN2ds ( double  ,
double  s 
)

Definition at line 171 of file TriLagrangeShapeTest.cpp.

{
    return 4 * s - 1;
}
double dN3dr ( double  r,
double  s 
)

Definition at line 175 of file TriLagrangeShapeTest.cpp.

{
    return 4 * ( 1 - s - 2 * r );
}
double dN3ds ( double  r,
double   
)

Definition at line 179 of file TriLagrangeShapeTest.cpp.

{
    return -4 * r;
}
double dN4dr ( double  ,
double  s 
)

Definition at line 183 of file TriLagrangeShapeTest.cpp.

{
    return 4 * s;
}
double dN4ds ( double  r,
double   
)

Definition at line 187 of file TriLagrangeShapeTest.cpp.

{
    return 4 * r;
}
double dN5dr ( double  ,
double  s 
)

Definition at line 191 of file TriLagrangeShapeTest.cpp.

{
    return -4 * s;
}
double dN5ds ( double  r,
double  s 
)

Definition at line 195 of file TriLagrangeShapeTest.cpp.

{
    return 4 * ( 1 - r - 2 * s );
}
static void get_coeff ( NodeSet  nodeset,
const double *  rs,
double *  coeffs 
) [static]

Definition at line 209 of file TriLagrangeShapeTest.cpp.

References MBMesquite::NodeSet::mid_edge_node(), and N.

Referenced by TriLagrangeShapeTest::test_corner_coeff(), TriLagrangeShapeTest::test_edge_coeff(), and TriLagrangeShapeTest::test_mid_coeff().

{
    for( int i = 0; i < 6; ++i )
        coeffs[i] = ( *N[i] )( rs[0], rs[1] );
    for( int i = 0; i < 3; ++i )
        if( !nodeset.mid_edge_node( i ) )
        {
            coeffs[i] += 0.5 * coeffs[i + 3];
            coeffs[( i + 1 ) % 3] += 0.5 * coeffs[i + 3];
            coeffs[i + 3] = 0;
        }
}
static void get_derivs ( NodeSet  nodeset,
const double *  rs,
double *  derivs 
) [static]

Definition at line 222 of file TriLagrangeShapeTest.cpp.

References dNdr, dNds, and MBMesquite::NodeSet::mid_edge_node().

Referenced by TriLagrangeShapeTest::test_corner_derivs(), TriLagrangeShapeTest::test_edge_derivs(), and TriLagrangeShapeTest::test_mid_derivs().

{
    for( int i = 0; i < 6; ++i )
    {
        derivs[2 * i]     = ( *dNdr[i] )( rs[0], rs[1] );
        derivs[2 * i + 1] = ( *dNds[i] )( rs[0], rs[1] );
    }
    for( int i = 0; i < 3; ++i )
        if( !nodeset.mid_edge_node( i ) )
        {
            derivs[2 * i] += 0.5 * derivs[2 * i + 6];
            derivs[2 * i + 1] += 0.5 * derivs[2 * i + 7];
            int j = ( i + 1 ) % 3;
            derivs[2 * j] += 0.5 * derivs[2 * i + 6];
            derivs[2 * j + 1] += 0.5 * derivs[2 * i + 7];
            derivs[2 * i + 6] = 0;
            derivs[2 * i + 7] = 0;
        }
}
double N0 ( double  r,
double  s 
)

Definition at line 124 of file TriLagrangeShapeTest.cpp.

References t.

Referenced by moab::SmoothFace::init_edge_control_points(), and moab::SmoothFace::init_facet_control_points().

{
    double t = 1 - r - s;
    return t * ( 2 * t - 1 );
}
double N1 ( double  r,
double   
)

Definition at line 129 of file TriLagrangeShapeTest.cpp.

Referenced by moab::FBEngine::weave_lateral_face_from_edges().

{
    return r * ( 2 * r - 1 );
}
double N2 ( double  ,
double  s 
)

Definition at line 133 of file TriLagrangeShapeTest.cpp.

Referenced by moab::FBEngine::weave_lateral_face_from_edges().

{
    return s * ( 2 * s - 1 );
}
double N3 ( double  r,
double  s 
)

Definition at line 137 of file TriLagrangeShapeTest.cpp.

References t.

Referenced by moab::SmoothFace::init_edge_control_points(), and moab::SmoothFace::init_facet_control_points().

{
    double t = 1 - r - s;
    return 4 * r * t;
}
double N4 ( double  r,
double  s 
)

Definition at line 142 of file TriLagrangeShapeTest.cpp.

{
    return 4 * r * s;
}
double N5 ( double  r,
double  s 
)

Definition at line 146 of file TriLagrangeShapeTest.cpp.

References t.

{
    double t = 1 - r - s;
    return 4 * s * t;
}
static CppUnit::Message value_message ( unsigned  location,
NodeSet  bits,
double  v1,
double  v2 
) [inline, static]

Definition at line 52 of file TriLagrangeShapeTest.cpp.

{
    CppUnit::Message m( "equality assertion failed" );

    std::ostringstream buffer1;
    buffer1 << "Expected : " << v1;
    m.addDetail( buffer1.str() );

    std::ostringstream buffer2;
    buffer2 << "Actual   : " << v2;
    m.addDetail( buffer2.str() );

    std::ostringstream buffer3;
    buffer3 << "Location : ";
    if( location < 3 )
        buffer3 << "Corner " << location;
    else if( location < 6 )
        buffer3 << "Edge " << location - 3;
    else if( location == 6 )
        buffer3 << "Mid-element";
    else
        buffer3 << "INVALID!!";
    m.addDetail( buffer3.str() );

    std::ostringstream buffer4;
    buffer4 << "Node Bits: " << bits;
    m.addDetail( buffer4.str() );
    return m;
}

Variable Documentation

const N_t dNdr[] = { &dN0dr, &dN1dr, &dN2dr, &dN3dr, &dN4dr, &dN5dr }

Definition at line 202 of file TriLagrangeShapeTest.cpp.

Referenced by get_derivs().

const N_t dNds[] = { &dN0ds, &dN1ds, &dN2ds, &dN3ds, &dN4ds, &dN5ds }

Definition at line 203 of file TriLagrangeShapeTest.cpp.

Referenced by get_derivs().

const double epsilon = 1e-6

Definition at line 48 of file TriLagrangeShapeTest.cpp.

const double rs_corner[][2] = { { 0, 0 }, { 1, 0 }, { 0, 1 } }
const double rs_edge[][2] = { { 0.5, 0.0 }, { 0.5, 0.5 }, { 0.0, 0.5 } }
const double rs_mid[2] = { 1.0 / 3.0, 1.0 / 3.0 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines