1 /*
2 XLiFE++ is an extended library of finite elements written in C++
3     Copyright (C) 2014  Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13     You should have received a copy of the GNU General Public License
14     along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 /*!
18   \file LagrangeTriangle.hpp
19   \authors D. Martin, N. Kielbasiewicz
20   \since 11 jan 2003
21   \date 06 aug 2012
22 
23   \brief Definition of the xlifepp::LagrangeTriangle class
24 
25   LagrangeTriangle defines Lagrange Reference Element interpolation data on triangular elements
26 
27   child classes
28     - LagrangeStdTriangle  : Lagrange standard Reference Element (interpolation at "equidistant" nodes), templated by order up to 6
29     - LagrangeStdTrianglePk: Lagrange standard Reference Element (interpolation at "equidistant" nodes), any order
30 
31   Member functions
32     - interpolationData interpolation data
33     - outputAsP1
34     - pointCoordinates  point coordinates
35     - computeShapeFunctions :  compute polynomials representation of shape functions if required
36     - fig4TeX  TeX format output of local numbering & coordinates
37 
38   External class related functions
39     - tensorNumberingTriangle builds correspondence between segment and triangle local numbering
40 
41   Local numbering of Lagrange Pk triangles, k=1, 2,.., 5
42   \verbatim
43 
44     2     2         2              2                  2
45     | \   | \       | \            | \                | \
46     3---1 5   4     5   7          5  10              5  13
47      k=1  |     \   |     \        |     \            |     \
48           3---6---1 8  10   4      8  14   7          8  17  10
49             k=2     |         \    |         \        |         \
50                     3---6---9---1 11  15  13   4     11  20  19   7
51                          k=3       |             \    |             \
52                                    3---6---9--12---1 14  18  21  16   4
53                                            k=4        |                 \
54                                                       3---6---9--12--15---1
55                                                                 k=5
56   \endverbatim
57 */
58 
59 #ifndef LAGRANGE_TRIANGLE_HPP
60 #define LAGRANGE_TRIANGLE_HPP
61 
62 #include "config.h"
63 #include "RefTriangle.hpp"
64 
65 namespace xlifepp
66 {
67 
68 /*!
69   \class LagrangeTriangle
70   defines Lagrange Reference Element interpolation data on triangular elements
71 
72   Grand-Parent class: RefElement
73   Parent class  : RefTriangle
74   Child classes : LagrangeStdTriangle
75  */
76 class LagrangeTriangle : public RefTriangle
77 {
78   public:
79     LagrangeTriangle(const Interpolation* interp_p); //!< constructor by interpolation
80     virtual ~LagrangeTriangle();  //!< destructor
81 
82   protected:
83     void interpolationData();     //!< builds interpolation data on reference element
84     void sideNumbering();         //!< numbering of side D.O.F's in standard Lagrange elements
85     void sideOfSideNumbering();   //!< numbering of side of side D.O.F's in standard Lagrange elements
86     void pointCoordinates();      //!< builds point coordinates on reference element
87     void computeShapeFunctions(); //!< compute polynomials representation of shape functions
88     std::vector<RefDof*>::iterator vertexCoordinates(); //!< returns vector of vertices dofs
89     std::vector<std::vector<number_t> > splitP1() const; //!< return nodes numbers of first order triangle elements when splitting current element
90     splitvec_t splitO1() const; //!< return nodes numbers of first order triangle elements when splitting current element
91     std::vector<std::pair<number_t,number_t> > splitP1Side(number_t s) const;   //!< return side numbers of first order elements (P1) when splitting current element
92 
93     void outputAsP1(std::ofstream& os, const int , const std::vector<number_t>& ranks) const; //!< output of Lagrange D.o.f's numbers on underlyin P1 D.o.f's
94 
95     //internal side dofs mapping when vertices of side are permuted (k not used in 2d)
96     //   standard i=1, j=2 :  [----1----2---- ... ----p-1----p----]     (p=nbDofsInSides_)
97     //   permuted i=2, j=1 :  [----p----p-1---- ... ----2----1----]
sideDofsMap(const number_t & n,const number_t & i,const number_t & j,const number_t & k=0) const98     number_t sideDofsMap(const number_t& n, const number_t& i, const number_t& j, const number_t& k=0) const
99     {
100         if(i>j) return nbDofsInSides()/3-n+1;
101         return n;
102     }
103 
104     // FOR TEST // FOR TEST // FOR TEST // FOR TEST // FOR TEST // FOR TEST //
105     //#ifdef FIG4TEX_OUTPUT
106     //    void fig4TeX();
107     //#endif /* FIG4TEX_OUTPUT */
108     // FOR TEST // FOR TEST // FOR TEST // FOR TEST // FOR TEST // FOR TEST //
109 
110 }; // end of class LagrangeTriangle
111 
112 /*!
113   \class LagrangeStdTriangle
114   template class child to class LagrangeTriangle (up to P6)
115  */
116 template<number_t Pk>
117 class LagrangeStdTriangle: public LagrangeTriangle
118 {
119   public:
120     LagrangeStdTriangle(const Interpolation* interp_p); //!< constructor by interpolation
121     ~LagrangeStdTriangle(); //!< destructor
122     using RefElement::computeShapeValues;     //to unmask computeShapeValues(vector<real_t>::const_iterator, const bool)
123     void computeShapeValues(std::vector<real_t>::const_iterator it_pt, ShapeValues& shv, const bool withDeriv = true) const; //!< shape functions
getO1splitting() const124     const splitvec_t& getO1splitting() const // override
125      { return splitO1Scheme; }
126   private:
127     // storage of order 1 splitting scheme (intended to graphical softwares usage)
128     splitvec_t splitO1Scheme;
129 }; // end of class LagrangeStdTriangle
130 
131 /*!
132   \class LagrangeStdTrianglePk
133   any order LagrangeTriangle with general formulae
134  */
135 class LagrangeStdTrianglePk: public LagrangeTriangle
136 {
137   public:
138     LagrangeStdTrianglePk(const Interpolation* interp_p); //!< constructor by interpolation
139     ~LagrangeStdTrianglePk();    //!< destructor
140     using RefElement::computeShapeValues;     //to unmask computeShapeValues(vector<real_t>::const_iterator, const bool)
computeShapeValues(std::vector<real_t>::const_iterator it_pt,ShapeValues & shv,const bool withDeriv=true) const141     void computeShapeValues(std::vector<real_t>::const_iterator it_pt, ShapeValues& shv, const bool withDeriv = true) const //! shape functions values
142       {computeShapeValuesFromShapeFunctions(it_pt, shv, withDeriv);}
getO1splitting() const143     const splitvec_t& getO1splitting() const // override
144      { return splitO1Scheme; }
145   private:
146     // storage of order 1 splitting scheme (intended to graphical softwares usage)
147     splitvec_t splitO1Scheme;
148 }; // end of class LagrangeStdTrianglePk
149 
150 //================================================================================
151 // Extern class related functions
152 //================================================================================
153 void tensorNumberingTriangle(const int, std::vector<number_t>&); //!< correspondence between segment and triangle local numbering
154 
155 } // end of namespace xlifepp
156 
157 #endif /* LAGRANGE_TRIANGLE_HPP */
158