MOAB: Mesh Oriented datABase  (version 5.2.1)
RefSizeTargetCalculator.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2009 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to 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     (2009) kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 /** \file RefSizeTargetCalculator.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "RefSizeTargetCalculator.hpp"
00034 #include "ReferenceMesh.hpp"
00035 #include "PatchData.hpp"
00036 #include "MsqError.hpp"
00037 
00038 namespace MBMesquite
00039 {
00040 
00041 /* We now scale W_ideal such that det(W_ideal) == 1, so don't scale here
00042 static void init_scale_factors( double factors[MIXED] )
00043 {
00044   for (int i = 0; i < MIXED; ++i)
00045     factors[i] = 0.0;
00046 
00047   factors[     TRIANGLE] = 0.21934566882541542;
00048   factors[QUADRILATERAL] = 0.25;
00049   factors[  TETRAHEDRON] = 0.08171340981758000;
00050   factors[      PYRAMID] = 0.06068647146341543;
00051   factors[        PRISM] = 0.07311522294180514;
00052   factors[   HEXAHEDRON] = 0.08333333333333333;
00053 }
00054 */
00055 
00056 RefSizeTargetCalculator::RefSizeTargetCalculator( ReferenceMesh* reference_mesh, TargetCalculator* tc )
00057     : refMesh( reference_mesh ), scaledTargets( tc )
00058 {
00059 }  //   { init_scale_factors( scaleFactor ); }
00060 
00061 RefSizeTargetCalculator::RefSizeTargetCalculator( ReferenceMesh* reference_mesh )
00062     : refMesh( reference_mesh ), scaledTargets( &defaultTargets )
00063 {
00064 }  //   { init_scale_factors( scaleFactor );  }
00065 
00066 double RefSizeTargetCalculator::average_edge_length( PatchData& pd, size_t element, MsqError& err )
00067 {
00068     Vector3D coords[8];
00069     MsqMeshEntity& elem = pd.element_by_index( element );
00070     const size_t* conn  = elem.get_vertex_index_array();
00071     size_t nvtx         = elem.vertex_count();
00072     if( nvtx > ( sizeof( coords ) / sizeof( coords[0] ) ) )
00073     {
00074         MSQ_SETERR( err )( "Invalid element type", MsqError::UNSUPPORTED_ELEMENT );
00075         return false;
00076     }
00077 
00078     Mesh::VertexHandle handles[8];
00079     for( unsigned i = 0; i < nvtx; ++i )
00080         handles[i] = pd.get_vertex_handles_array()[conn[i]];
00081 
00082     refMesh->get_reference_vertex_coordinates( handles, nvtx, coords, err );
00083     MSQ_ERRZERO( err );
00084 
00085     EntityTopology type = elem.get_element_type();
00086     unsigned num_edges  = TopologyInfo::edges( type );
00087     double len_sum      = 0.0;
00088     for( unsigned i = 0; i < num_edges; ++i )
00089     {
00090         const unsigned* edge = TopologyInfo::edge_vertices( type, i );
00091         len_sum += ( coords[edge[0]] - coords[edge[1]] ).length();
00092     }
00093     return len_sum * ( 1.0 / num_edges );  // scaleFactor[type];
00094 }
00095 
00096 bool RefSizeTargetCalculator::get_3D_target( PatchData& pd, size_t element, Sample sample, MsqMatrix< 3, 3 >& W,
00097                                              MsqError& err )
00098 {
00099     scaledTargets->get_3D_target( pd, element, sample, W, err );
00100     MSQ_ERRZERO( err );
00101 
00102     double f = average_edge_length( pd, element, err );
00103     MSQ_ERRZERO( err );
00104     W *= f;
00105 
00106     return true;
00107 }
00108 
00109 bool RefSizeTargetCalculator::get_surface_target( PatchData& pd, size_t element, Sample sample, MsqMatrix< 3, 2 >& W,
00110                                                   MsqError& err )
00111 {
00112     scaledTargets->get_surface_target( pd, element, sample, W, err );
00113     MSQ_ERRZERO( err );
00114 
00115     double f = average_edge_length( pd, element, err );
00116     MSQ_ERRZERO( err );
00117     W *= f;
00118 
00119     return true;
00120 }
00121 
00122 bool RefSizeTargetCalculator::get_2D_target( PatchData& pd, size_t element, Sample sample, MsqMatrix< 2, 2 >& W,
00123                                              MsqError& err )
00124 {
00125     scaledTargets->get_2D_target( pd, element, sample, W, err );
00126     MSQ_ERRZERO( err );
00127 
00128     double f = average_edge_length( pd, element, err );
00129     MSQ_ERRZERO( err );
00130     W *= f;
00131 
00132     return true;
00133 }
00134 
00135 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines