MOAB: Mesh Oriented datABase  (version 5.4.1)
V_PyramidMetric.cpp
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Module:    $RCSfile: V_PyramidMetric.cpp,v $
00004 
00005   Copyright (c) 2006 Sandia Corporation.
00006   All rights reserved.
00007   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 
00015 /*
00016  *
00017  * PyramidMetrics.cpp contains quality calculations for Pyramids
00018  *
00019  * This file is part of VERDICT
00020  *
00021  */
00022 
00023 #define VERDICT_EXPORTS
00024 
00025 #include "moab/verdict.h"
00026 #include "VerdictVector.hpp"
00027 #include <memory.h>
00028 
00029 /*
00030   the pyramid element
00031 
00032        5
00033        ^
00034        |\
00035       /| \\_
00036      |  \   \
00037      |  | \_ \_
00038      /   \/4\  \
00039     |   /|    \ \_
00040     | /  \      \ \
00041     /     |       \
00042   1 \_    |      _/3
00043       \_   \   _/
00044         \_ | _/
00045           \_/
00046           2
00047 
00048     a quadrilateral base and a pointy peak like a pyramid
00049 
00050 */
00051 
00052 /*!
00053   the volume of a pyramid
00054 
00055   the volume is calculated by dividing the pyramid into
00056   2 tets and summing the volumes of the 2 tets.
00057 */
00058 
00059 C_FUNC_DEF double v_pyramid_volume( int num_nodes, double coordinates[][3] )
00060 {
00061 
00062     double volume = 0;
00063     VerdictVector side1, side2, side3;
00064 
00065     if( num_nodes == 5 )
00066     {
00067         // divide the pyramid into 2 tets and calculate each
00068 
00069         side1.set( coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
00070                    coordinates[1][2] - coordinates[0][2] );
00071 
00072         side2.set( coordinates[3][0] - coordinates[0][0], coordinates[3][1] - coordinates[0][1],
00073                    coordinates[3][2] - coordinates[0][2] );
00074 
00075         side3.set( coordinates[4][0] - coordinates[0][0], coordinates[4][1] - coordinates[0][1],
00076                    coordinates[4][2] - coordinates[0][2] );
00077 
00078         // volume of the first tet
00079         volume = ( side3 % ( side1 * side2 ) ) / 6.0;
00080 
00081         side1.set( coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
00082                    coordinates[3][2] - coordinates[2][2] );
00083 
00084         side2.set( coordinates[1][0] - coordinates[2][0], coordinates[1][1] - coordinates[2][1],
00085                    coordinates[1][2] - coordinates[2][2] );
00086 
00087         side3.set( coordinates[4][0] - coordinates[2][0], coordinates[4][1] - coordinates[2][1],
00088                    coordinates[4][2] - coordinates[2][2] );
00089 
00090         // volume of the second tet
00091         volume += ( side3 % ( side1 * side2 ) ) / 6.0;
00092     }
00093     return (double)volume;
00094 }
00095 
00096 C_FUNC_DEF void v_pyramid_quality( int num_nodes,
00097                                    double coordinates[][3],
00098                                    unsigned int metrics_request_flag,
00099                                    PyramidMetricVals* metric_vals )
00100 {
00101     memset( metric_vals, 0, sizeof( PyramidMetricVals ) );
00102 
00103     if( metrics_request_flag & V_PYRAMID_VOLUME ) metric_vals->volume = v_pyramid_volume( num_nodes, coordinates );
00104 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines