// This file is part of the Herezh++ application.
//
// The finite element software Herezh++ is dedicated to the field
// of mechanics for large transformations of solid structures.
// It is developed by Gérard Rio (APP: IDDN.FR.010.0106078.000.R.P.2006.035.20600)
// INSTITUT DE RECHERCHE DUPUY DE LÔME (IRDL) <https://www.irdl.fr/>.
//
// Herezh++ is distributed under GPL 3 license ou ultérieure.
//
// Copyright (C) 1997-2022 Université Bretagne Sud (France)
// AUTHOR : Gérard Rio
// E-MAIL  : gerardrio56@free.fr
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// For more information, please consult: <https://herezh.irdl.fr/>.

/************************************************************************
 *     DATE:        23/01/97                                            *
 *                                                                $     *
 *     AUTEUR:      G RIO   (mailto:gerardrio56@free.fr)                *
 *                                                                $     *
 *     PROJET:      Herezh++                                            *
 *                                                                $     *
 ************************************************************************
 *     BUT:  Definir  La geometrie des tétraèdres quadratiques.         *
 *           Fonction d'interpolation, points d'integration etc         *
 *                                                                $     *
 *     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''     *                                                                      *
 *     VERIFICATION:                                                    *
 *                                                                      *
 *     !  date  !   auteur   !       but                          !     *
 *     ------------------------------------------------------------     *
 *     !        !            !                                    !     *
 *                                                                $     *
 *     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''     *
 *     MODIFICATIONS:                                                   *
 *     !  date  !   auteur   !       but                          !     *
 *     ------------------------------------------------------------     *
 *                                                                $     *
 ************************************************************************/
#ifndef GEOMTETRAQ_H
#define GEOMTETRAQ_H

#include"GeomTetraCom.h"

/*
// ***********************************************************************
//                                                                       *
//     ELEMENT DE REFERENCE , POINTS D'INTEGRATION:                      *
//                                                                       *
//     Source : Dhatt et Touzot p 130, 131, 132 pour les fonctions       *
//              d'interpolation. Pour la numérotation : Modulef          *
// ----------------------------------------------------------------------*
//
//               ^                                
//               |zeta
//               |
//               4
//              /|\
//             / | \
//            /  8  10
//           9   |   \
//          /    |    \
//         /     1- 7- 3 - - - > eta
//        /  5 '   6 '    
//       / '  .    
//      2 
//     /
//    xi      tetraèdre quadratique                   
//
//------------------------------
// Points d'integration 
//------------------------------
// 1 point : (ordre 1)
//            Pt1 (1/4,1/4,1/4)
// 4 points : (ordre 2)  a = (5. - sqrt(5))/20., b = (5+3.*sqrt(5))/20.
//         Pt1 (a,a,a)  ; Pt2 (a,a,b)  ; Pt3 (a,b,a)  ; Pt4 (b,a,a)
//  
// 5 points : (ordre 3)  a = 1/4, b=1/6, c=1/2,
//         Pt1 (a,a,a)  ; Pt2 (b,b,b)  ; Pt3 (b,b,c)  ; Pt4 ( ; Pt4 (c,b,b))
//  
// 15 points : (ordre 5)  a = 1/4, b1=(7+sqrt(15))/34,   b2=(7-sqrt(15))/34, 
//                                 c1=(13+3sqrt(15))/34, c2=(13-3sqrt(15))/34,
//                        d=(5-sqrt(15))/20,  e=(5+sqrt(15))/20,
//         Pt1 (a,a,a)  ; Pt2 (b1,b1,b1)  ; Pt3 (b2,b2,b2)  ; Pt4 (b1,b1,c1)
//         Pt5 (b2,b2,c2)  ; Pt6 (b1,c1,b1)  ; Pt7 (b2,c2,b2)  ; Pt8 (c1,b1,b1)
//         Pt9 (c2,b2,b2)  ; Pt10 (d,d,e)  ; Pt11 (d,e,d)  ; Pt12 (e,d,d)
//         Pt13 (d,e,e)  ; Pt14 (e,d,e)  ; Pt15 (e,e,d)  ;
//    
//
//------------------------------
// pour le tetraèdre quadratique : 
//------------------------------
// face 1 : noeud 7  3  6  2  5  1 , face 2 : noeud 5  2  9  4  8  1,
// face 3 : noeud 7  1  8  4 10  3 , face 4 : noeud 6  3 10  4  9  2, 
//  les normales sortent des faces des elements
//  on attribue 3 points d'integration par face
//
// pour les aretes on suit le fichier Elmail, 6 aretes
// A1-> 1 5 2  A2-> 2 6 3   A3-> 3 7 1   
// A4-> 1 8 4  A5-> 2 9 4   A6-> 3 10 4
//
//   on attribue 2 point d'integration par arete
//
//  concernant la triangulation de chaque face elle est réalisée à l'aide
//  de la triangulation implantée sur l'élément de référence de la face
//  
//  
//
// ************************************************************************
*/
         
/// @addtogroup Les_Elements_de_geometrie
///  @{
///


class GeomTetraQ : public GeomTetraCom
{
  public :
    // CONSTRUCTEURS :
    // il y a 4 points d'integration et 10 noeuds     
    GeomTetraQ(int nbi = 4);
    // de copie
    GeomTetraQ(const GeomTetraQ& a);    
    // DESTRUCTEUR :
    ~GeomTetraQ();
    
    // création d'élément identiques : cette fonction est analogue à la fonction new
    // elle y fait d'ailleurs appel. l'implantation est spécifique dans chaque classe
    // dérivée
    // pt est le pointeur qui est affecté par la fonction 
    ElemGeomC0 * newElemGeomC0(ElemGeomC0 * pt) ;

    //--------- cas de coordonnees locales quelconques ---------------- 
    // retourne les fonctions d'interpolation au point M (en coordonnees locales)
    const Vecteur& Phi_point(const Coordonnee& M);
    // retourne les derivees des fonctions d'interpolation au point M (en coordonnees locales)
    const Mat_pleine& Dphi_point(const Coordonnee& M);
    // en fonction de coordonnees locales, retourne true si le point est a l'interieur
    // de l'element, false sinon
    bool Interieur(const Coordonnee& M);
        
  protected :  
 
    // variables de stockage transitoire, locales pour éviter de les reconstruire à chaque appel
    Vecteur phi_M; // le tableau phi au point M(en coordonnees locales)
    Mat_pleine dphi_M; //les derivees des fonctions d'interpolation au point M(en coordonnees locales)

    // METHODES PROTEGEES :
    inline double& DPHI(int i,int j,int k) { return tabDPhi(k)(i,j);};
    inline double& PHI(int i,int j) {return tabPhi(j)(i); }; 
    // because les routine de calcul de phi et dphi aux pt d'integ sont trop grandes
    // on en fait des routines 
    void Phiphi();
    void DphiDphi();
    // constitution du tableau Extrapol
    void Calcul_extrapol(int nbi);
        
 };
 /// @}  // end of group

#endif