1/*
2 * Copyright (c) 2005 Lawrence Livermore National Laboratory under
3 * contract number B545069 with the University of Wisconsin - Madison.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */2526#include"moab/CartVect.hpp"27#include"measure.hpp"28usingnamespace moab;
2930inlinestaticdoubletet_volume( const CartVect& v0, const CartVect& v1, const CartVect& v2, const CartVect& v3 )
31 {
32return1. / 6. * ( ( ( v1 - v0 ) * ( v2 - v0 ) ) % ( v3 - v0 ) );
33 }
3435doubleedge_length( constdouble* start_vtx_coords, constdouble* end_vtx_coords )
36 {
37const CartVect* start = reinterpret_cast< const CartVect* >( start_vtx_coords );
38const CartVect* end = reinterpret_cast< const CartVect* >( end_vtx_coords );
39return ( *start - *end ).length();
40 }
4142doublemeasure( moab::EntityType type, int num_vertices, constdouble* vertex_coordinates )
43 {
44const CartVect* coords = reinterpret_cast< const CartVect* >( vertex_coordinates );
45switch( type )
46 {
47case moab::MBEDGE:
48return ( coords[0] - coords[1] ).length();
49case moab::MBTRI:
50return0.5 * ( ( coords[1] - coords[0] ) * ( coords[2] - coords[0] ) ).length();
51case moab::MBQUAD:
52 num_vertices = 4;
53// fall through54case moab::MBPOLYGON: {
55CartVect mid( 0, 0, 0 );
56for( int i = 0; i < num_vertices; ++i )
57 mid += coords[i];
58 mid /= num_vertices;
5960double sum = 0.0;
61for( int i = 0; i < num_vertices; ++i )
62 {
63int j = ( i + 1 ) % num_vertices;
64 sum += ( ( mid - coords[i] ) * ( mid - coords[j] ) ).length();
65 }
66return0.5 * sum;
67 }
68case moab::MBTET:
69returntet_volume( coords[0], coords[1], coords[2], coords[3] );
70case moab::MBPYRAMID:
71returntet_volume( coords[0], coords[1], coords[2], coords[4] ) +
72tet_volume( coords[0], coords[2], coords[3], coords[4] );
73case moab::MBPRISM:
74returntet_volume( coords[0], coords[1], coords[2], coords[5] ) +
75tet_volume( coords[3], coords[5], coords[4], coords[0] ) +
76tet_volume( coords[1], coords[4], coords[5], coords[0] );
77case moab::MBHEX:
78returntet_volume( coords[0], coords[1], coords[3], coords[4] ) +
79tet_volume( coords[7], coords[3], coords[6], coords[4] ) +
80tet_volume( coords[4], coords[5], coords[1], coords[6] ) +
81tet_volume( coords[1], coords[6], coords[3], coords[4] ) +
82tet_volume( coords[2], coords[6], coords[3], coords[1] );
83default:
84return0.0;
85 }
86 }