MOAB: Mesh Oriented datABase  (version 5.4.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) [email protected]
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,
00054                                    NodeSet nodeset,
00055                                    double* coeff_out,
00056                                    size_t* indices_out,
00057                                    size_t& num_coeff,
00058                                    MsqError& err ) const
00059 {
00060     if( nodeset.have_any_mid_node() )
00061     {
00062         MSQ_SETERR( err )( nonlinear_error, MsqError::UNSUPPORTED_ELEMENT );
00063         return;
00064     }
00065 
00066     switch( loc.dimension )
00067     {
00068         case 0:
00069             num_coeff      = 1;
00070             indices_out[0] = loc.number;
00071             coeff_out[0]   = 1.0;
00072             break;
00073         case 1:
00074             num_coeff      = 2;
00075             indices_out[0] = loc.number;
00076             indices_out[1] = ( loc.number + 1 ) % 3;
00077             coeff_out[0]   = 0.5;
00078             coeff_out[1]   = 0.5;
00079             break;
00080         case 2:
00081             num_coeff      = 3;
00082             indices_out[0] = 0;
00083             indices_out[1] = 1;
00084             indices_out[2] = 2;
00085             coeff_out[0] = coeff_out[1] = coeff_out[2] = MSQ_ONE_THIRD;
00086             break;
00087         default:
00088             MSQ_SETERR( err )( "Invalid/unsupported logical dimension", MsqError::INVALID_ARG );
00089     }
00090 }
00091 
00092 void LinearTriangle::derivatives( Sample,
00093                                   NodeSet nodeset,
00094                                   size_t* vertices,
00095                                   MsqVector< 2 >* coeff_derivs,
00096                                   size_t& num_vtx,
00097                                   MsqError& err ) const
00098 {
00099     if( nodeset.have_any_mid_node() )
00100     {
00101         MSQ_SETERR( err )( nonlinear_error, MsqError::UNSUPPORTED_ELEMENT );
00102     }
00103     else
00104     {
00105         num_vtx     = 3;
00106         vertices[0] = 0;
00107         vertices[1] = 1;
00108         vertices[2] = 2;
00109 
00110         coeff_derivs[0][0] = -1.0;
00111         coeff_derivs[0][1] = -1.0;
00112         coeff_derivs[1][0] = 1.0;
00113         coeff_derivs[1][1] = 0.0;
00114         coeff_derivs[2][0] = 0.0;
00115         coeff_derivs[2][1] = 1.0;
00116     }
00117 }
00118 
00119 void LinearTriangle::ideal( Sample, MsqMatrix< 3, 2 >& J, MsqError& ) const
00120 {
00121     //  const double g = 1.074569931823542; // sqrt(2/sqrt(3));
00122     //  J(0,0) = g;    J(0,1) = 0.5*g;
00123     //  J(1,0) = 0.0;  J(1,1) = 1.0/g;
00124     //  J(2,0) = 0.0;  J(2,1) = 0.0;
00125     const double a = 0.70710678118654746;  // 1/sqrt(2)
00126     const double b = 1.3160740129524924;   // 4th root of 3
00127     J( 0, 0 )      = -a / b;
00128     J( 0, 1 )      = a / b;
00129     J( 1, 0 )      = -a * b;
00130     J( 1, 1 )      = -a * b;
00131     J( 2, 0 )      = 0.0;
00132     J( 2, 1 )      = 0.0;
00133 }
00134 
00135 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines