moab
measure.cpp File Reference
#include <math.h>
#include "measure.hpp"

Go to the source code of this file.

Classes

class  CartVect

Functions

CartVect operator+ (const CartVect &v1, const CartVect &v2)
CartVect operator- (const CartVect &v1, const CartVect &v2)
double operator% (const CartVect &v1, const CartVect &v2)
CartVect operator* (const CartVect &v1, const CartVect &v2)
static double tet_volume (const CartVect &v0, const CartVect &v1, const CartVect &v2, const CartVect &v3)
double edge_length (const double *start_vtx_coords, const double *end_vtx_coords)
double measure (moab::EntityType type, int num_vertices, const double *vertex_coordinates)

Function Documentation

double edge_length ( const double *  start_vtx_coords,
const double *  end_vtx_coords 
)

Definition at line 145 of file measure.cpp.

{
  const CartVect* start = reinterpret_cast<const CartVect*>(start_vtx_coords);
  const CartVect*   end = reinterpret_cast<const CartVect*>(  end_vtx_coords);
  return (*start - *end).len();
}
double measure ( moab::EntityType  type,
int  num_vertices,
const double *  vertex_coordinates 
)

Definition at line 153 of file measure.cpp.

{
  const CartVect* coords = reinterpret_cast<const CartVect*>(vertex_coordinates);
  switch( type )
  {
    case moab::MBEDGE:
      return (coords[0] - coords[1]).len();
    case moab::MBTRI:
      return 0.5 * ((coords[1] - coords[0]) * (coords[2] - coords[0])).len();
    case moab::MBQUAD:
      num_vertices = 4;
    case moab::MBPOLYGON:
    {
      CartVect mid(0,0,0);
      for (int i = 0; i < num_vertices; ++i)
        mid += coords[i];
      mid /= num_vertices;
      
      double sum = 0.0;
      for (int i = 0; i < num_vertices; ++i)
      {
        int j = (i+1)%num_vertices;
        sum += ((mid - coords[i]) * (mid - coords[j])).len();
      }
      return 0.5 * sum;
    }
    case moab::MBTET:
      return tet_volume( coords[0], coords[1], coords[2], coords[3] ) ;
    case moab::MBPYRAMID:
      return tet_volume( coords[0], coords[1], coords[2], coords[4] ) +
             tet_volume( coords[0], coords[2], coords[3], coords[4] ) ;
    case moab::MBPRISM:
      return tet_volume( coords[0], coords[1], coords[2], coords[5] ) +
             tet_volume( coords[3], coords[5], coords[4], coords[0] ) +
             tet_volume( coords[1], coords[4], coords[5], coords[0] ) ;
    case moab::MBHEX:
      return tet_volume( coords[0], coords[1], coords[3], coords[4] ) +
             tet_volume( coords[7], coords[3], coords[6], coords[4] ) +
             tet_volume( coords[4], coords[5], coords[1], coords[6] ) +
             tet_volume( coords[1], coords[6], coords[3], coords[4] ) +
             tet_volume( coords[2], coords[6], coords[3], coords[1] ) ;
    default:
      return 0.0;
  }
}
double operator% ( const CartVect v1,
const CartVect v2 
) [inline]

Definition at line 110 of file measure.cpp.

{
  return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
}
CartVect operator* ( const CartVect v1,
const CartVect v2 
) [inline]

Definition at line 115 of file measure.cpp.

{
  return CartVect( v1.y() * v2.z() - v1.z() * v2.y(),
                   v1.z() * v2.x() - v1.x() * v2.z(),
                   v1.x() * v2.y() - v1.y() * v2.x() );
}
CartVect operator+ ( const CartVect v1,
const CartVect v2 
) [inline]

Definition at line 96 of file measure.cpp.

{
  CartVect rval(v1);
  rval += v2;
  return rval;
}
CartVect operator- ( const CartVect v1,
const CartVect v2 
) [inline]

Definition at line 103 of file measure.cpp.

{
  CartVect rval(v1);
  rval -= v2;
  return rval;
}
static double tet_volume ( const CartVect v0,
const CartVect v1,
const CartVect v2,
const CartVect v3 
) [inline, static]

Definition at line 137 of file measure.cpp.

{
  return 1./6. * ( ((v1 - v0) * (v2 - v0)) % (v3 - v0) );
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines