MOAB: Mesh Oriented datABase  (version 5.3.1)
LinearTriangle.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2006 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     (2006) kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 #include "Mesquite.hpp"
00028 #include "MsqError.hpp"
00029 #include "LinearTriangle.hpp"
00030 
00031 namespace MBMesquite
00032 {
00033 
00034 static const char* nonlinear_error = "Attempt to use LinearTriangle mapping function for a nonlinear element\n";
00035 
00036 EntityTopology LinearTriangle::element_topology() const
00037 {
00038     return TRIANGLE;
00039 }
00040 
00041 int LinearTriangle::num_nodes() const
00042 {
00043     return 3;
00044 }
00045 
00046 NodeSet LinearTriangle::sample_points( NodeSet ) const
00047 {
00048     NodeSet result;
00049     result.set_mid_face_node( 0 );
00050     return result;
00051 }
00052 
00053 void LinearTriangle::coefficients( Sample loc, NodeSet nodeset, double* coeff_out, size_t* indices_out,
00054                                    size_t& num_coeff, MsqError& err ) const
00055 {
00056     if( nodeset.have_any_mid_node() )
00057     {
00058         MSQ_SETERR( err )( nonlinear_error, MsqError::UNSUPPORTED_ELEMENT );
00059         return;
00060     }
00061 
00062     switch( loc.dimension )
00063     {
00064         case 0:
00065             num_coeff      = 1;
00066             indices_out[0] = loc.number;
00067             coeff_out[0]   = 1.0;
00068             break;
00069         case 1:
00070             num_coeff      = 2;
00071             indices_out[0] = loc.number;
00072             indices_out[1] = ( loc.number + 1 ) % 3;
00073             coeff_out[0]   = 0.5;
00074             coeff_out[1]   = 0.5;
00075             break;
00076         case 2:
00077             num_coeff      = 3;
00078             indices_out[0] = 0;
00079             indices_out[1] = 1;
00080             indices_out[2] = 2;
00081             coeff_out[0] = coeff_out[1] = coeff_out[2] = MSQ_ONE_THIRD;
00082             break;
00083         default:
00084             MSQ_SETERR( err )( "Invalid/unsupported logical dimension", MsqError::INVALID_ARG );
00085     }
00086 }
00087 
00088 void LinearTriangle::derivatives( Sample, NodeSet nodeset, size_t* vertices, MsqVector< 2 >* coeff_derivs,
00089                                   size_t& num_vtx, MsqError& err ) const
00090 {
00091     if( nodeset.have_any_mid_node() ) { MSQ_SETERR( err )( nonlinear_error, MsqError::UNSUPPORTED_ELEMENT ); }
00092     else
00093     {
00094         num_vtx     = 3;
00095         vertices[0] = 0;
00096         vertices[1] = 1;
00097         vertices[2] = 2;
00098 
00099         coeff_derivs[0][0] = -1.0;
00100         coeff_derivs[0][1] = -1.0;
00101         coeff_derivs[1][0] = 1.0;
00102         coeff_derivs[1][1] = 0.0;
00103         coeff_derivs[2][0] = 0.0;
00104         coeff_derivs[2][1] = 1.0;
00105     }
00106 }
00107 
00108 void LinearTriangle::ideal( Sample, MsqMatrix< 3, 2 >& J, MsqError& ) const
00109 {
00110     //  const double g = 1.074569931823542; // sqrt(2/sqrt(3));
00111     //  J(0,0) = g;    J(0,1) = 0.5*g;
00112     //  J(1,0) = 0.0;  J(1,1) = 1.0/g;
00113     //  J(2,0) = 0.0;  J(2,1) = 0.0;
00114     const double a = 0.70710678118654746;  // 1/sqrt(2)
00115     const double b = 1.3160740129524924;   // 4th root of 3
00116     J( 0, 0 )      = -a / b;
00117     J( 0, 1 )      = a / b;
00118     J( 1, 0 )      = -a * b;
00119     J( 1, 1 )      = -a * b;
00120     J( 2, 0 )      = 0.0;
00121     J( 2, 1 )      = 0.0;
00122 }
00123 
00124 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines