MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/fem/elems/quad4.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raul Durand                   *
00004  * Copyright (C) 2009 Sergio Galindo                                    *
00005  *                                                                      *
00006  * This program is free software: you can redistribute it and/or modify *
00007  * it under the terms of the GNU General Public License as published by *
00008  * the Free Software Foundation, either version 3 of the License, or    *
00009  * any later version.                                                   *
00010  *                                                                      *
00011  * This program is distributed in the hope that it will be useful,      *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00014  * GNU General Public License for more details.                         *
00015  *                                                                      *
00016  * You should have received a copy of the GNU General Public License    *
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00018  ************************************************************************/
00019 
00020 #ifndef MECHSYS_FEM_QUAD4_H
00021 #define MECHSYS_FEM_QUAD4_H
00022 
00023 // MechSys
00024 #include <mechsys/fem/node.h>
00025 #include <mechsys/fem/geomelem.h>
00026 
00027 namespace FEM
00028 {
00029 
00030 class Quad4: public GeomElem
00031 {
00032 public:
00033     // Auxiliar structure to map local face IDs to local node IDs
00034     static const int Face2Node[4][2]; // 4 edges, 2 nodes/edge
00035 
00036     // Constructor
00037     Quad4 (int NDim);
00038 
00039     // Derived methods
00040     void   SetIPs     (int TotNIP);
00041     size_t FNode      (size_t IdxFace, size_t IdxFNode) const { return Face2Node[IdxFace][IdxFNode]; }
00042     void   Shape      (double r, double s, double t)    const;
00043     void   Derivs     (double r, double s, double t)    const;
00044     void   FaceShape  (double r, double s)              const;
00045     void   FaceDerivs (double r, double s)              const;
00046     void   NatCoords  (Mat_t & C)                       const;
00047 };
00048 
00049 
00050 /* Local IDs
00051                  Nodes                  Faces(edges)
00052    y
00053    |        3             2                  2
00054    +--x      @-----------@             +-----------+
00055              |           |             |           |
00056              |           |             |           |
00057              |           |            3|           |1
00058              |           |             |           |
00059              |           |             |           |
00060              @-----------@             +-----------+
00061             0             1                  0
00062 */
00063 const int Quad4::Face2Node[4][2] = {{ 0, 1 },
00064                                     { 1, 2 },
00065                                     { 2, 3 },
00066                                     { 3, 0 }}; // order of nodes is important
00067 
00068 
00070 
00071 
00072 inline Quad4::Quad4 (int NDim)
00073     : GeomElem(NDim, /*NN*/4, /*NFN*/2, "Quad4")
00074 {
00075     SetIPs (4);
00076 }
00077 
00078 inline void Quad4::SetIPs (int TotNIP)
00079 {
00080          if (TotNIP== 4) IPs = QUAD_IP2;
00081     else if (TotNIP== 9) IPs = QUAD_IP3;
00082     else if (TotNIP==16) IPs = QUAD_IP4;
00083     else if (TotNIP==25) IPs = QUAD_IP5;
00084     else throw new Fatal("Quad4::SetIPs: Total number of integration points = %d is invalid",TotNIP);
00085 
00086     NIP  = TotNIP;
00087     FIPs = LIN_IP2;
00088     NFIP = 2;
00089 }
00090 
00091 inline void Quad4::Shape (double r, double s, double t) const
00092 {
00093     /*      3                        2
00094      *        @--------------------@
00095      *        |               (1,1)|
00096      *        |       s ^          |
00097      *        |         |          |
00098      *        |         |          |
00099      *        |         +----> r   |
00100      *        |       (0,0)        |
00101      *        |                    |
00102      *        |                    |
00103      *        |(-1,-1)             |
00104      *        @--------------------@
00105      *      0                        1
00106      */
00107     N(0) = 0.25*(1.0-r-s+r*s);
00108     N(1) = 0.25*(1.0+r-s-r*s);
00109     N(2) = 0.25*(1.0+r+s+r*s);
00110     N(3) = 0.25*(1.0-r+s-r*s);
00111 }
00112 
00113 inline void Quad4::Derivs (double r, double s, double t) const
00114 {
00115     /*           _     _ T
00116      *          |  dNi  |
00117      *   dNdR = |  ---  |   , where Rj = r, s
00118      *          |_ dRj _|
00119      *  
00120      *   dNdR(j,i), j=>local coordinate and i=>shape function
00121      */
00122     dNdR(0,0) = 0.25*(-1.0+s);   dNdR(1,0) = 0.25*(-1.0+r);
00123     dNdR(0,1) = 0.25*(+1.0-s);   dNdR(1,1) = 0.25*(-1.0-r);
00124     dNdR(0,2) = 0.25*(+1.0+s);   dNdR(1,2) = 0.25*(+1.0+r);
00125     dNdR(0,3) = 0.25*(-1.0-s);   dNdR(1,3) = 0.25*(+1.0-r);
00126 }
00127 
00128 inline void Quad4::FaceShape (double r, double s) const
00129 {
00130     /*  
00131      *       0           |           1
00132      *       @-----------+-----------@-> r
00133      *      -1           |          +1
00134      */
00135     FN(0) = 0.5*(1.0-r);
00136     FN(1) = 0.5*(1.0+r);
00137 }
00138 
00139 inline void Quad4::FaceDerivs (double r, double s) const
00140 {
00141     /*            _     _ T
00142      *           |  dNi  |
00143      *   FdNdR = |  ---  |   , where Rj = r, s
00144      *           |_ dRj _|
00145      *
00146      *   FdNdR(j,i), j=>local coordinate and i=>shape function
00147      */
00148     FdNdR(0,0) = -0.5;
00149     FdNdR(0,1) =  0.5;
00150 }
00151 
00152 inline void Quad4::NatCoords (Mat_t & C) const
00153 {
00154     C.change_dim(4,3);
00155     C = -1.0, -1.0, 1.0,
00156          1.0, -1.0, 1.0,
00157          1.0,  1.0, 1.0,
00158         -1.0,  1.0, 1.0;
00159 }
00160 
00161 
00163 
00164 
00165 // Allocate a new element
00166 GeomElem * Quad4Maker (int NDim) { return new Quad4(NDim); }
00167 
00168 // Register element
00169 int Quad4Register ()
00170 {
00171     GeomElemFactory["Quad4"] = Quad4Maker;
00172     GEOM.Set ("Quad4", (double)GEOM.Keys.Size());
00173     return 0;
00174 }
00175 
00176 // Call register
00177 int __Quad4_dummy_int  = Quad4Register();
00178 
00179 }; // namespace FEM
00180 
00181 #endif // MECHSYS_FEM_QUAD4_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines