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 */
25
26 #include "moab/CartVect.hpp"
27 #include "measure.hpp"
28 using namespace moab;
29
tet_volume(const CartVect & v0,const CartVect & v1,const CartVect & v2,const CartVect & v3)30 inline static double tet_volume( const CartVect& v0,
31 const CartVect& v1,
32 const CartVect& v2,
33 const CartVect& v3 )
34 {
35 return 1./6. * ( ((v1 - v0) * (v2 - v0)) % (v3 - v0) );
36 }
37
edge_length(const double * start_vtx_coords,const double * end_vtx_coords)38 double edge_length( const double* start_vtx_coords,
39 const double* end_vtx_coords )
40 {
41 const CartVect* start = reinterpret_cast<const CartVect*>(start_vtx_coords);
42 const CartVect* end = reinterpret_cast<const CartVect*>( end_vtx_coords);
43 return (*start - *end).length();
44 }
45
measure(moab::EntityType type,int num_vertices,const double * vertex_coordinates)46 double measure( moab::EntityType type,
47 int num_vertices,
48 const double* vertex_coordinates )
49 {
50 const CartVect* coords = reinterpret_cast<const CartVect*>(vertex_coordinates);
51 switch( type )
52 {
53 case moab::MBEDGE:
54 return (coords[0] - coords[1]).length();
55 case moab::MBTRI:
56 return 0.5 * ((coords[1] - coords[0]) * (coords[2] - coords[0])).length();
57 case moab::MBQUAD:
58 num_vertices = 4;
59 case moab::MBPOLYGON:
60 {
61 CartVect mid(0,0,0);
62 for (int i = 0; i < num_vertices; ++i)
63 mid += coords[i];
64 mid /= num_vertices;
65
66 double sum = 0.0;
67 for (int i = 0; i < num_vertices; ++i)
68 {
69 int j = (i+1)%num_vertices;
70 sum += ((mid - coords[i]) * (mid - coords[j])).length();
71 }
72 return 0.5 * sum;
73 }
74 case moab::MBTET:
75 return tet_volume( coords[0], coords[1], coords[2], coords[3] ) ;
76 case moab::MBPYRAMID:
77 return tet_volume( coords[0], coords[1], coords[2], coords[4] ) +
78 tet_volume( coords[0], coords[2], coords[3], coords[4] ) ;
79 case moab::MBPRISM:
80 return tet_volume( coords[0], coords[1], coords[2], coords[5] ) +
81 tet_volume( coords[3], coords[5], coords[4], coords[0] ) +
82 tet_volume( coords[1], coords[4], coords[5], coords[0] ) ;
83 case moab::MBHEX:
84 return tet_volume( coords[0], coords[1], coords[3], coords[4] ) +
85 tet_volume( coords[7], coords[3], coords[6], coords[4] ) +
86 tet_volume( coords[4], coords[5], coords[1], coords[6] ) +
87 tet_volume( coords[1], coords[6], coords[3], coords[4] ) +
88 tet_volume( coords[2], coords[6], coords[3], coords[1] ) ;
89 default:
90 return 0.0;
91 }
92 }
93
94