MOAB: Mesh Oriented datABase  (version 5.2.1)
VertexConditionNumberQualityMetric.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government 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     diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
00024     pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
00025 
00026   ***************************************************************** */
00027 /*!
00028   \file   VertexConditionNumberQualityMetric.cpp
00029   \brief
00030 
00031   \author Michael Brewer
00032   \date   2002-06-9
00033 */
00034 #include "VertexConditionNumberQualityMetric.hpp"
00035 #include "Vector3D.hpp"
00036 #include "ConditionNumberFunctions.hpp"
00037 
00038 #include <cmath>
00039 #include <vector>
00040 using std::vector;
00041 
00042 using namespace MBMesquite;
00043 
00044 VertexConditionNumberQualityMetric::VertexConditionNumberQualityMetric() : AveragingQM( QualityMetric::LINEAR ) {}
00045 
00046 std::string VertexConditionNumberQualityMetric::get_name() const
00047 {
00048     return "Vertex Condition Number";
00049 }
00050 
00051 int VertexConditionNumberQualityMetric::get_negate_flag() const
00052 {
00053     return 1;
00054 }
00055 
00056 bool VertexConditionNumberQualityMetric::evaluate( PatchData& pd, size_t this_vert, double& fval, MsqError& err )
00057 {
00058     // pd.generate_vertex_to_element_data();
00059     bool return_flag;
00060     fval = MSQ_MAX_CAP;
00061     // get the element array
00062     MsqMeshEntity* elems = pd.get_element_array( err );
00063     // get the vertex to element array and the offset array
00064     // const size_t* elem_offset = pd.get_vertex_to_elem_offset(err);  MSQ_ERRZERO(err);
00065     // const size_t* v_to_e_array = pd.get_vertex_to_elem_array(err);  MSQ_ERRZERO(err);
00066     // find the offset for this vertex
00067     // size_t this_offset = elem_offset[this_vert];
00068     // get the number of elements attached to this vertex (given by the
00069     // first entry in the vertex to element array)
00070     // size_t num_elems = v_to_e_array[this_offset];
00071     // PRINT_INFO("\nIN LOCAL SIZE CPP, num_elements = %i",num_elems);
00072     // if no elements, then return true
00073     size_t num_elems;
00074     const size_t* v_to_e_array = pd.get_vertex_element_adjacencies( this_vert, num_elems, err );
00075     MSQ_ERRZERO( err );
00076 
00077     if( num_elems <= 0 ) { return true; }
00078 
00079     // create an array to store the local metric values before averaging
00080     // Can we remove this dynamic allocatio?
00081     std::vector< double > met_vals( num_elems );
00082     // vector to hold the other verts which form a corner.
00083     vector< size_t > other_vertices;
00084     other_vertices.reserve( 4 );
00085     size_t i = 0;
00086     // only 3 temp_vec will be sent to cond-num calculator, but the
00087     // additional vector3Ds may be needed during the calculations
00088     size_t elem_index;
00089     Vector3D temp_vec[6];
00090     const MsqVertex* vertices = pd.get_vertex_array( err );
00091     // loop over the elements attached to this vertex
00092     for( i = 0; i < num_elems; ++i )
00093     {
00094         // get the vertices connected to this vertex for this element
00095         elem_index = v_to_e_array[i];
00096         elems[elem_index].get_connected_vertices( this_vert, other_vertices, err );
00097         MSQ_ERRZERO( err );
00098         // switch over the element type of this element
00099         switch( elems[v_to_e_array[i]].get_element_type() )
00100         {
00101 
00102             case TRIANGLE:
00103                 temp_vec[0] = vertices[other_vertices[0]] - vertices[this_vert];
00104                 temp_vec[2] = vertices[other_vertices[1]] - vertices[this_vert];
00105                 // make relative to equilateral
00106                 temp_vec[1] = ( ( 2 * temp_vec[2] ) - temp_vec[0] ) * MSQ_SQRT_THREE_INV;
00107                 return_flag = condition_number_2d( temp_vec, elem_index, pd, met_vals[i], err );
00108                 MSQ_ERRZERO( err );
00109                 if( !return_flag ) return return_flag;
00110                 break;
00111             case QUADRILATERAL:
00112                 temp_vec[0] = vertices[other_vertices[0]] - vertices[this_vert];
00113                 temp_vec[1] = vertices[other_vertices[1]] - vertices[this_vert];
00114                 return_flag = condition_number_2d( temp_vec, elem_index, pd, met_vals[i], err );
00115                 MSQ_ERRZERO( err );
00116                 if( !return_flag ) return return_flag;
00117                 break;
00118             case TETRAHEDRON:
00119                 temp_vec[0] = vertices[other_vertices[0]] - vertices[this_vert];
00120                 temp_vec[3] = vertices[other_vertices[1]] - vertices[this_vert];
00121                 temp_vec[4] = vertices[other_vertices[2]] - vertices[this_vert];
00122                 // transform to equilateral tet
00123                 temp_vec[1] = ( ( 2 * temp_vec[3] ) - temp_vec[0] ) / MSQ_SQRT_THREE;
00124                 temp_vec[2] = ( ( 3 * temp_vec[4] ) - temp_vec[0] - temp_vec[3] ) / ( MSQ_SQRT_THREE * MSQ_SQRT_TWO );
00125                 return_flag = condition_number_3d( temp_vec, pd, met_vals[i], err );
00126                 MSQ_ERRZERO( err );
00127                 if( !return_flag ) return return_flag;
00128                 break;
00129             case HEXAHEDRON:
00130                 temp_vec[0] = vertices[other_vertices[0]] - vertices[this_vert];
00131                 temp_vec[1] = vertices[other_vertices[1]] - vertices[this_vert];
00132                 temp_vec[2] = vertices[other_vertices[2]] - vertices[this_vert];
00133                 return_flag = condition_number_3d( temp_vec, pd, met_vals[i], err );
00134                 MSQ_ERRZERO( err );
00135                 if( !return_flag ) return return_flag;
00136                 break;
00137             default:
00138                 MSQ_SETERR( err )
00139                 ( MsqError::UNSUPPORTED_ELEMENT, "Element type (%d) not uspported in VertexConditionNumberQM.\n",
00140                   (int)( elems[v_to_e_array[i]].get_element_type() ) );
00141                 fval = MSQ_MAX_CAP;
00142                 return false;
00143 
00144         }  // end switch over element type
00145         other_vertices.clear();
00146     }  // end loop over elements
00147     fval = average_metrics( arrptr( met_vals ), num_elems, err );
00148     MSQ_ERRZERO( err );
00149     return true;
00150 }
00151 
00152 bool VertexConditionNumberQualityMetric::evaluate_with_indices( PatchData& pd, size_t this_vert, double& value,
00153                                                                 std::vector< size_t >& indices, MsqError& err )
00154 {
00155     bool rval = evaluate( pd, this_vert, value, err );
00156     MSQ_ERRFALSE( err );
00157 
00158     indices.clear();
00159 
00160     MsqMeshEntity* elems = pd.get_element_array( err );
00161     size_t num_elems;
00162     const size_t* v_to_e_array = pd.get_vertex_element_adjacencies( this_vert, num_elems, err );
00163     MSQ_ERRZERO( err );
00164 
00165     // vector to hold the other verts which form a corner.
00166     vector< size_t > other_vertices;
00167     other_vertices.reserve( 4 );
00168     size_t i = 0;
00169 
00170     // loop over the elements attached to this vertex
00171     for( i = 0; i < num_elems; ++i )
00172     {
00173         // get the vertices connected to this vertex for this element
00174         elems[v_to_e_array[i]].get_connected_vertices( this_vert, other_vertices, err );
00175         MSQ_ERRZERO( err );
00176         for( unsigned j = 0; j < other_vertices.size(); ++j )
00177         {
00178             if( other_vertices[j] < pd.num_free_vertices() ) indices.push_back( other_vertices[j] );
00179         }
00180     }
00181 
00182     std::sort( indices.begin(), indices.end() );
00183     indices.erase( std::unique( indices.begin(), indices.end() ), indices.end() );
00184     if( this_vert < pd.num_free_vertices() ) indices.push_back( this_vert );
00185     return rval;
00186 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines