![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /*
00002 * Copyright (c) 2005 Lawrence Livermore National Laboratory under
00003 * contract number B545069 with the University of Wisconsin - Madison.
00004 *
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions
00007 * are met:
00008 * 1. Redistributions of source code must retain the above copyright
00009 * notice, this list of conditions and the following disclaimer.
00010 * 2. Redistributions in binary form must reproduce the above copyright
00011 * notice, this list of conditions and the following disclaimer in the
00012 * documentation and/or other materials provided with the distribution.
00013 *
00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024 */
00025
00026 #include "moab/CartVect.hpp"
00027 #include "measure.hpp"
00028 using namespace moab;
00029
00030 inline static double tet_volume( const CartVect& v0, const CartVect& v1, const CartVect& v2, const CartVect& v3 )
00031 {
00032 return 1. / 6. * ( ( ( v1 - v0 ) * ( v2 - v0 ) ) % ( v3 - v0 ) );
00033 }
00034
00035 double edge_length( const double* start_vtx_coords, const double* end_vtx_coords )
00036 {
00037 const CartVect* start = reinterpret_cast< const CartVect* >( start_vtx_coords );
00038 const CartVect* end = reinterpret_cast< const CartVect* >( end_vtx_coords );
00039 return ( *start - *end ).length();
00040 }
00041
00042 double measure( moab::EntityType type, int num_vertices, const double* vertex_coordinates )
00043 {
00044 const CartVect* coords = reinterpret_cast< const CartVect* >( vertex_coordinates );
00045 switch( type )
00046 {
00047 case moab::MBEDGE:
00048 return ( coords[0] - coords[1] ).length();
00049 case moab::MBTRI:
00050 return 0.5 * ( ( coords[1] - coords[0] ) * ( coords[2] - coords[0] ) ).length();
00051 case moab::MBQUAD:
00052 num_vertices = 4;
00053 // fall through
00054 case moab::MBPOLYGON: {
00055 CartVect mid( 0, 0, 0 );
00056 for( int i = 0; i < num_vertices; ++i )
00057 mid += coords[i];
00058 mid /= num_vertices;
00059
00060 double sum = 0.0;
00061 for( int i = 0; i < num_vertices; ++i )
00062 {
00063 int j = ( i + 1 ) % num_vertices;
00064 sum += ( ( mid - coords[i] ) * ( mid - coords[j] ) ).length();
00065 }
00066 return 0.5 * sum;
00067 }
00068 case moab::MBTET:
00069 return tet_volume( coords[0], coords[1], coords[2], coords[3] );
00070 case moab::MBPYRAMID:
00071 return tet_volume( coords[0], coords[1], coords[2], coords[4] ) +
00072 tet_volume( coords[0], coords[2], coords[3], coords[4] );
00073 case moab::MBPRISM:
00074 return tet_volume( coords[0], coords[1], coords[2], coords[5] ) +
00075 tet_volume( coords[3], coords[5], coords[4], coords[0] ) +
00076 tet_volume( coords[1], coords[4], coords[5], coords[0] );
00077 case moab::MBHEX:
00078 return tet_volume( coords[0], coords[1], coords[3], coords[4] ) +
00079 tet_volume( coords[7], coords[3], coords[6], coords[4] ) +
00080 tet_volume( coords[4], coords[5], coords[1], coords[6] ) +
00081 tet_volume( coords[1], coords[6], coords[3], coords[4] ) +
00082 tet_volume( coords[2], coords[6], coords[3], coords[1] );
00083 default:
00084 return 0.0;
00085 }
00086 }