MOAB: Mesh Oriented datABase  (version 5.4.1)
MsqIRel.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 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     [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /*!
00028   \file   MsqIRel.cpp
00029   \brief
00030 
00031 
00032   \author Jason Kraftcheck
00033   \date   2007-08-14
00034 */
00035 
00036 #include "MsqIRel.hpp"
00037 #include "MsqDebug.hpp"
00038 #include "MsqVertex.hpp"
00039 #include "MsqError.hpp"
00040 #include "MsqIBase.hpp"
00041 
00042 namespace MBMesquite
00043 {
00044 
00045 /***************** DomainTSTT class methods *********************/
00046 
00047 MsqIRel::MsqIRel( iGeom_Instance geom, iRel_Instance relate_iface, iRel_PairHandle relate_instance )
00048     : MsqCommonIGeom( geom ), relateIface( relate_iface ), relateInstance( relate_instance )
00049 {
00050 }
00051 
00052 MsqIRel::~MsqIRel() {}
00053 
00054 void MsqIRel::snap_to( Mesh::VertexHandle handle, Vector3D& coordinate ) const
00055 {
00056     int ierr, dim;
00057     iBase_EntityHandle geom;
00058 
00059     ierr = geom_from_mesh( handle, geom, dim );
00060     if( iBase_SUCCESS != ierr )
00061     {
00062         process_itaps_error( ierr );
00063         return;
00064     }
00065 
00066     if( dim < 3 )
00067     {
00068         ierr = move_to( geom, coordinate );
00069         if( iBase_SUCCESS != ierr )
00070         {
00071             process_itaps_error( ierr );
00072             return;
00073         }
00074     }
00075 }
00076 
00077 void MsqIRel::vertex_normal_at( Mesh::VertexHandle handle, Vector3D& coordinate ) const
00078 {
00079     int ierr, dim;
00080     iBase_EntityHandle geom;
00081 
00082     ierr = geom_from_mesh( handle, geom, dim );
00083     if( iBase_SUCCESS != ierr )
00084     {
00085         process_itaps_error( ierr );
00086         return;
00087     }
00088 
00089     if( dim == 2 )
00090     {
00091         ierr = normal( geom, coordinate );
00092         if( iBase_SUCCESS != ierr )
00093         {
00094             process_itaps_error( ierr );
00095             return;
00096         }
00097     }
00098     else
00099     {
00100         assert( 0 );
00101     }
00102 }
00103 
00104 void MsqIRel::element_normal_at( Mesh::ElementHandle handle, Vector3D& coordinate ) const
00105 {
00106     MsqIRel::vertex_normal_at( handle, coordinate );
00107 }
00108 
00109 void MsqIRel::vertex_normal_at( const Mesh::VertexHandle* handle,
00110                                 Vector3D coordinates[],
00111                                 unsigned count,
00112                                 MsqError& err ) const
00113 {
00114     int ierr, dim;
00115     iBase_EntityHandle geom;
00116     for( unsigned i = 0; i < count; ++i )
00117     {
00118         ierr = geom_from_mesh( handle[i], geom, dim );
00119         if( iBase_SUCCESS != ierr )
00120         {
00121             process_itaps_error( ierr );
00122             return;
00123         }
00124 
00125         if( dim != 2 )
00126         {
00127             MSQ_SETERR( err )
00128             ( "Cannot get normal for non-surface geometry", MsqError::INVALID_ARG );
00129             return;
00130         }
00131 
00132         ierr = normal( geom, coordinates[i] );
00133         if( iBase_SUCCESS != ierr )
00134         {
00135             process_itaps_error( ierr );
00136             return;
00137         }
00138     }
00139 }
00140 
00141 void MsqIRel::domain_DoF( const Mesh::VertexHandle* handle_array,
00142                           unsigned short* dof_array,
00143                           size_t count,
00144                           MsqError& err ) const
00145 {
00146     int ierr;
00147 
00148     geomHandles.resize( count );
00149     ierr = geom_from_mesh( handle_array, arrptr( geomHandles ), dof_array, count );
00150     if( iBase_SUCCESS != ierr )
00151     {
00152         MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR );
00153         return;
00154     }
00155 }
00156 
00157 void MsqIRel::closest_point( Mesh::VertexHandle handle,
00158                              const Vector3D& position,
00159                              Vector3D& closest,
00160                              Vector3D& p_normal,
00161                              MsqError& err ) const
00162 {
00163     int ierr, dim;
00164     iBase_EntityHandle geom;
00165 
00166     ierr = geom_from_mesh( handle, geom, dim );
00167     if( iBase_SUCCESS != ierr )
00168     {
00169         MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR );
00170         return;
00171     }
00172 
00173     if( dim != 2 )
00174     {
00175         MSQ_SETERR( err )( "Cannot get normal for non-surface geometry", MsqError::INVALID_ARG );
00176         return;
00177     }
00178 
00179     ierr = closest_and_normal( geom, position, closest, p_normal );
00180     if( iBase_SUCCESS != ierr )
00181     {
00182         MSQ_SETERR( err )( process_itaps_error( ierr ), MsqError::INTERNAL_ERROR );
00183         return;
00184     }
00185 }
00186 
00187 int MsqIRel::geom_from_mesh( Mesh::EntityHandle mesh_ent_handle, iBase_EntityHandle& geom_handle, int& geom_dim ) const
00188 {
00189     // get geometric entity
00190     int ierr;
00191     iRel_getEntEntRelation( relateIface, relateInstance, (iBase_EntityHandle)mesh_ent_handle, true, &geom_handle,
00192                             &ierr );
00193     if( iBase_SUCCESS != ierr ) return ierr;
00194 
00195     // get dimension of geometric entities
00196     int one = 1, one_too = 1, *type_ptr = &geom_dim;
00197     iGeom_getArrType( geomIFace, &geom_handle, 1, &type_ptr, &one, &one_too, &ierr );
00198     if( iBase_SUCCESS != ierr ) return ierr;
00199 
00200     return iBase_SUCCESS;
00201 }
00202 
00203 int MsqIRel::geom_from_mesh( const Mesh::EntityHandle* handles,
00204                              iBase_EntityHandle* geom_handles,
00205                              unsigned short* dims,
00206                              size_t count ) const
00207 {
00208     int ierr, dim;
00209     for( size_t i = 0; i < count; ++i )
00210     {
00211         ierr = geom_from_mesh( handles[i], geom_handles[i], dim );
00212         if( iBase_SUCCESS != ierr ) return ierr;
00213         dims[i] = dim;
00214     }
00215 
00216     return iBase_SUCCESS;
00217 }
00218 
00219 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines