MOAB: Mesh Oriented datABase  (version 5.2.1)
CylinderDomain.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2005 Lawrence Livermore National Laboratory.  Under
00005     the terms of Contract B545069 with the University of Wisconsin --
00006     Madison, Lawrence Livermore National Laboratory retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 #ifndef MSQ_CYLINDER_DOMAIN_CPP
00028 #define MSQ_CYLINDER_DOMAIN_CPP
00029 
00030 #include "Mesquite.hpp"
00031 #include "CylinderDomain.hpp"
00032 #include <limits>
00033 
00034 namespace MBMesquite
00035 {
00036 
00037 CylinderDomain::~CylinderDomain() {}
00038 
00039 void CylinderDomain::evaluate( Mesh::VertexHandle, const Vector3D& point, Vector3D& closest, Vector3D& normal ) const
00040 {
00041     const double EPSILON      = std::numeric_limits< double >::epsilon();
00042     double t                  = mAxis % ( point - mCenter );
00043     const Vector3D axis_point = mCenter + t * mAxis;
00044 
00045     normal           = point - axis_point;
00046     const double len = normal.length();
00047     if( len < EPSILON )
00048     {
00049         Vector3D v( 1, 0, 0 );
00050         if( ( v * mAxis ).length() < EPSILON ) v.set( 0, 1, 0 );
00051         normal = v * mAxis;
00052         normal.normalize();
00053     }
00054     else
00055     {
00056         normal /= len;
00057     }
00058 
00059     closest = axis_point + mRadius * normal;
00060     normal *= outwardSign;
00061 }
00062 
00063 void CylinderDomain::snap_to( Mesh::VertexHandle h, Vector3D& v ) const
00064 {
00065     Vector3D p( v ), n;
00066     evaluate( h, p, v, n );
00067 }
00068 
00069 void CylinderDomain::vertex_normal_at( Mesh::VertexHandle h, Vector3D& v ) const
00070 {
00071     Vector3D p( v ), l;
00072     evaluate( h, p, l, v );
00073 }
00074 
00075 void CylinderDomain::element_normal_at( Mesh::ElementHandle h, Vector3D& v ) const
00076 {
00077     Vector3D p( v ), l;
00078     // NOTE: Explicitly invoke this class's evaluate method for elements.
00079     //       BoundedCylindarDomain overrides evaluate for vertices only.
00080     CylinderDomain::evaluate( h, p, l, v );
00081 }
00082 
00083 void CylinderDomain::vertex_normal_at( const Mesh::VertexHandle* h, Vector3D coords[], unsigned count, MsqError& ) const
00084 {
00085     for( unsigned i = 0; i < count; ++i )
00086         vertex_normal_at( h[i], coords[i] );
00087 }
00088 
00089 void CylinderDomain::closest_point( Mesh::VertexHandle handle, const Vector3D& position, Vector3D& closest,
00090                                     Vector3D& normal, MsqError& ) const
00091 {
00092     evaluate( handle, position, closest, normal );
00093 }
00094 
00095 void CylinderDomain::domain_DoF( const Mesh::VertexHandle*, unsigned short* dof_array, size_t count, MsqError& ) const
00096 {
00097     std::fill( dof_array, dof_array + count, (unsigned short)2 );
00098 }
00099 
00100 }  // namespace MBMesquite
00101 
00102 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines