MOAB: Mesh Oriented datABase  (version 5.4.1)
TargetMetricUtil.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2007 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     (2007) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /** \file TargetMetricUtil.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "TargetMetricUtil.hpp"
00034 #include "MsqMatrix.hpp"
00035 #include "PatchData.hpp"
00036 #include "ElementQM.hpp"
00037 #include "ElemSampleQM.hpp"
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 void surface_to_2d( const MsqMatrix< 3, 2 >& A,
00043                     const MsqMatrix< 3, 2 >& W,
00044                     MsqMatrix< 2, 2 >& W_22,
00045                     MsqMatrix< 3, 2 >& RZ )
00046 {
00047     MsqMatrix< 3, 1 > W1 = W.column( 0 );
00048     MsqMatrix< 3, 1 > W2 = W.column( 1 );
00049     MsqMatrix< 3, 1 > nw = W1 * W2;
00050     nw *= 1.0 / length( nw );
00051 
00052     MsqMatrix< 3, 1 > z[2];
00053     z[0] = W1 * ( 1.0 / length( W1 ) );
00054     z[1] = nw * z[0];
00055     MsqMatrix< 3, 2 > Z( z );
00056 
00057     MsqMatrix< 3, 1 > np = A.column( 0 ) * A.column( 1 );
00058     np *= 1.0 / length( np );
00059     double dot           = np % nw;
00060     MsqMatrix< 3, 1 > nr = ( dot >= 0.0 ) ? nw : -nw;
00061     MsqMatrix< 3, 1 > v  = nr * np;
00062     double vlen          = length( v );
00063     if( vlen < DBL_EPSILON )
00064     {
00065         RZ = Z;  // R = I
00066     }
00067     else
00068     {
00069         v *= 1.0 / vlen;
00070         MsqMatrix< 3, 1 > r1[3] = { v, np, v * np };
00071         MsqMatrix< 3, 1 > r2[3] = { v, nr, v * nr };
00072         MsqMatrix< 3, 3 > R1( r1 ), R2( r2 );
00073         RZ = R1 * transpose( R2 ) * Z;
00074     }
00075 
00076     W_22 = transpose( Z ) * W;
00077 }
00078 /*
00079 void surface_to_2d( const MsqMatrix<3,2>& App,
00080                     const MsqMatrix<3,2>& Wp,
00081                     MsqMatrix<2,2>& A,
00082                     MsqMatrix<2,2>& W )
00083 {
00084   MsqMatrix<3,1> Wp1 = Wp.column(0);
00085   MsqMatrix<3,1> Wp2 = Wp.column(1);
00086   MsqMatrix<3,1> nwp = Wp1 * Wp2;
00087   nwp *= 1.0/length(nwp);
00088 
00089   MsqMatrix<3,1> z[2];
00090   z[0] = Wp1 * (1.0 / length( Wp1 ));
00091   z[1] = nwp * z[0];
00092   MsqMatrix<3,2> Z(z);
00093   W = transpose(Z) * Wp;
00094 
00095   MsqMatrix<3,1> npp = App.column(0) * App.column(1);
00096   npp *= 1.0 / length(npp);
00097   double dot = npp % nwp;
00098   MsqMatrix<3,1> nr = (dot >= 0.0) ? nwp : -nwp;
00099   MsqMatrix<3,1> v = nr * npp;
00100   double vlen = length(v);
00101   if (vlen > DBL_EPSILON) {
00102     v *= 1.0 / vlen;
00103     MsqMatrix<3,1> r1[3] = { v, npp, v * npp }, r2[3] = { v, nr, v * nr };
00104     MsqMatrix<3,3> R1( r1 ), R2( r2 );
00105     MsqMatrix<3,3> RT = R2 * transpose(R1);
00106     MsqMatrix<3,2> Ap = RT * App;
00107     A = transpose(Z) * Ap;
00108   }
00109   else {
00110     A = transpose(Z) * App;
00111   }
00112 }
00113 */
00114 
00115 static inline void append_elem_samples( PatchData& pd, size_t e, std::vector< size_t >& handles )
00116 {
00117     NodeSet samples     = pd.get_samples( e );
00118     EntityTopology type = pd.element_by_index( e ).get_element_type();
00119     size_t curr_size    = handles.size();
00120     handles.resize( curr_size + samples.num_nodes() );
00121     std::vector< size_t >::iterator i = handles.begin() + curr_size;
00122     for( unsigned j = 0; j < TopologyInfo::corners( type ); ++j )
00123         if( samples.corner_node( j ) ) *( i++ ) = ElemSampleQM::handle( Sample( 0, j ), e );
00124     for( unsigned j = 0; j < TopologyInfo::edges( type ); ++j )
00125         if( samples.mid_edge_node( j ) ) *( i++ ) = ElemSampleQM::handle( Sample( 1, j ), e );
00126     for( unsigned j = 0; j < TopologyInfo::faces( type ); ++j )
00127         if( samples.mid_face_node( j ) ) *( i++ ) = ElemSampleQM::handle( Sample( 2, j ), e );
00128     if( TopologyInfo::dimension( type ) == 3 && samples.mid_region_node() )
00129         *( i++ ) = ElemSampleQM::handle( Sample( 3, 0 ), e );
00130 }
00131 
00132 void get_sample_pt_evaluations( PatchData& pd, std::vector< size_t >& handles, bool free, MsqError& err )
00133 {
00134     handles.clear();
00135     std::vector< size_t > elems;
00136     ElementQM::get_element_evaluations( pd, elems, free, err );MSQ_ERRRTN( err );
00137     for( std::vector< size_t >::iterator i = elems.begin(); i != elems.end(); ++i )
00138         append_elem_samples( pd, *i, handles );
00139 }
00140 
00141 void get_elem_sample_points( PatchData& pd, size_t elem, std::vector< size_t >& handles, MsqError& /*err*/ )
00142 {
00143     handles.clear();
00144     append_elem_samples( pd, elem, handles );
00145 }
00146 
00147 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines