MOAB: Mesh Oriented datABase  (version 5.2.1)
LinearTetrahedron.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 "LinearTetrahedron.hpp"
00030 
00031 namespace MBMesquite
00032 {
00033 
00034 static const char* nonlinear_error = "Attempt to use LinearTetrahedron mapping function for a nonlinear element\n";
00035 
00036 EntityTopology LinearTetrahedron::element_topology() const
00037 {
00038     return TETRAHEDRON;
00039 }
00040 
00041 int LinearTetrahedron::num_nodes() const
00042 {
00043     return 4;
00044 }
00045 
00046 NodeSet LinearTetrahedron::sample_points( NodeSet ) const
00047 {
00048     NodeSet result;
00049     result.set_mid_region_node();
00050     return result;
00051 }
00052 
00053 static const unsigned faces[][3] = { { 1, 0, 3 }, { 3, 2, 1 }, { 0, 2, 3 }, { 0, 1, 2 } };
00054 
00055 void LinearTetrahedron::coefficients( Sample location, NodeSet nodeset, double* coeff_out, size_t* indices_out,
00056                                       size_t& num_coeff, MsqError& err ) const
00057 {
00058     if( nodeset.have_any_mid_node() )
00059     {
00060         MSQ_SETERR( err )( nonlinear_error, MsqError::UNSUPPORTED_ELEMENT );
00061         return;
00062     }
00063 
00064     switch( location.dimension )
00065     {
00066         case 0:
00067             num_coeff      = 1;
00068             indices_out[0] = location.number;
00069             coeff_out[0]   = 1.0;
00070             break;
00071         case 1:
00072             num_coeff    = 2;
00073             coeff_out[0] = 0.5;
00074             coeff_out[1] = 0.5;
00075             if( location.number < 3 )
00076             {
00077                 indices_out[0] = location.number;
00078                 indices_out[1] = ( location.number + 1 ) % 3;
00079             }
00080             else
00081             {
00082                 indices_out[0] = location.number - 3;
00083                 indices_out[1] = 3;
00084             }
00085             break;
00086         case 2:
00087             num_coeff      = 3;
00088             indices_out[0] = faces[location.number][0];
00089             indices_out[1] = faces[location.number][1];
00090             indices_out[2] = faces[location.number][2];
00091             coeff_out[0] = coeff_out[1] = coeff_out[2] = coeff_out[3] = MSQ_ONE_THIRD;
00092             break;
00093         case 3:
00094             num_coeff      = 4;
00095             indices_out[0] = 0;
00096             indices_out[1] = 1;
00097             indices_out[2] = 2;
00098             indices_out[3] = 3;
00099             coeff_out[0] = coeff_out[1] = coeff_out[2] = coeff_out[3] = 0.25;
00100             break;
00101         default:
00102             MSQ_SETERR( err )( "Invalid/unsupported logical dimension", MsqError::INVALID_ARG );
00103     }
00104 }
00105 
00106 void LinearTetrahedron::derivatives( Sample, NodeSet nodeset, size_t* vertices, MsqVector< 3 >* coeff_derivs,
00107                                      size_t& num_vtx, MsqError& err ) const
00108 {
00109     if( nodeset.have_any_mid_node() )
00110     {
00111         MSQ_SETERR( err )( nonlinear_error, MsqError::UNSUPPORTED_ELEMENT );
00112         return;
00113     }
00114     else
00115     {
00116         num_vtx     = 4;
00117         vertices[0] = 0;
00118         vertices[1] = 1;
00119         vertices[2] = 2;
00120         vertices[3] = 3;
00121 
00122         coeff_derivs[0][0] = -1.0;
00123         coeff_derivs[0][1] = -1.0;
00124         coeff_derivs[0][2] = -1.0;
00125 
00126         coeff_derivs[1][0] = 1.0;
00127         coeff_derivs[1][1] = 0.0;
00128         coeff_derivs[1][2] = 0.0;
00129 
00130         coeff_derivs[2][0] = 0.0;
00131         coeff_derivs[2][1] = 1.0;
00132         coeff_derivs[2][2] = 0.0;
00133 
00134         coeff_derivs[3][0] = 0.0;
00135         coeff_derivs[3][1] = 0.0;
00136         coeff_derivs[3][2] = 1.0;
00137     }
00138 }
00139 
00140 void LinearTetrahedron::ideal( Sample, MsqMatrix< 3, 3 >& J, MsqError& ) const
00141 {
00142     const double a = 1.122462048309373;   // 6th root of 2
00143     const double b = 1.7320508075688772;  // sqrt(3)
00144     const double c = 1.5874010519681994;  // 2 to the 2/3
00145     J( 0, 0 )      = a;
00146     J( 0, 1 )      = 0.5 * a;
00147     J( 0, 2 )      = 0.5 * a;
00148     J( 1, 0 )      = 0.0;
00149     J( 1, 1 )      = 0.5 * a * b;
00150     J( 1, 2 )      = 0.5 * a / b;
00151     J( 2, 0 )      = 0.0;
00152     J( 2, 1 )      = 0.0;
00153     J( 2, 2 )      = c / b;
00154 }
00155 
00156 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines