1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
/*=========================================================================

  Module:    $RCSfile: V_PyramidMetric.cpp,v $

  Copyright (c) 2006 Sandia Corporation.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

/*
 *
 * PyramidMetrics.cpp contains quality calculations for Pyramids
 *
 * This file is part of VERDICT
 *
 */

#define VERDICT_EXPORTS

#include "moab/verdict.h"
#include "VerdictVector.hpp"
#include <memory.h>

/*
  the pyramid element

       5
       ^
       |\
      /| \\_
     |  \   \
     |  | \_ \_
     /   \/4\  \
    |   /|    \ \_
    | /  \      \ \
    /     |       \
  1 \_    |      _/3
      \_   \   _/
        \_ | _/
          \_/
          2

    a quadrilateral base and a pointy peak like a pyramid

*/

/*!
  the volume of a pyramid

  the volume is calculated by dividing the pyramid into
  2 tets and summing the volumes of the 2 tets.
*/

C_FUNC_DEF double v_pyramid_volume( int num_nodes, double coordinates[][3] )
{

    double volume = 0;
    VerdictVector side1, side2, side3;

    if( num_nodes == 5 )
    {
        // divide the pyramid into 2 tets and calculate each

        side1.set( coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
                   coordinates[1][2] - coordinates[0][2] );

        side2.set( coordinates[3][0] - coordinates[0][0], coordinates[3][1] - coordinates[0][1],
                   coordinates[3][2] - coordinates[0][2] );

        side3.set( coordinates[4][0] - coordinates[0][0], coordinates[4][1] - coordinates[0][1],
                   coordinates[4][2] - coordinates[0][2] );

        // volume of the first tet
        volume = ( side3 % ( side1 * side2 ) ) / 6.0;

        side1.set( coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
                   coordinates[3][2] - coordinates[2][2] );

        side2.set( coordinates[1][0] - coordinates[2][0], coordinates[1][1] - coordinates[2][1],
                   coordinates[1][2] - coordinates[2][2] );

        side3.set( coordinates[4][0] - coordinates[2][0], coordinates[4][1] - coordinates[2][1],
                   coordinates[4][2] - coordinates[2][2] );

        // volume of the second tet
        volume += ( side3 % ( side1 * side2 ) ) / 6.0;
    }
    return (double)volume;
}

C_FUNC_DEF void v_pyramid_quality( int num_nodes,<--- The function 'v_pyramid_quality' is never used.
                                   double coordinates[][3],
                                   unsigned int metrics_request_flag,
                                   PyramidMetricVals* metric_vals )
{
    memset( metric_vals, 0, sizeof( PyramidMetricVals ) );

    if( metrics_request_flag & V_PYRAMID_VOLUME ) metric_vals->volume = v_pyramid_volume( num_nodes, coordinates );
}