Salome HOME
b1d2d052b103edf25042d36e3a07cb7904772c6c
[modules/hexablock.git] / src / HEXABLOCK / HexHexa.hxx
1
2 // class : Les hexaedres
3
4 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 /* -----------------------------------------------------
24
25                 // ---- Numerotation des faces (%x) 
26                    
27        6=bed  +----bd-----+ bdf=7
28              /|          /|
29            be |   B    bf |
30            /  |        /  |
31     4=bce +----bc-----+...|...bcf=5
32           |  de     D |   df
33           | E |       | F |             z
34          ce   | C     cf  |             ^
35   2=ade...|...+----ad-|---+ adf=3       |   y
36           |  /        |  /              |  /
37           | ae    A   | af              | /
38           |/          |/                |/
39     0=ace +----ac-----+ acf=1           +----->  x
40   
41  * ----------------------------------------------------- */
42 #ifndef __HEX_HEXA_H_
43 #define __HEX_HEXA_H_
44
45 #include "HexEltBase.hxx"
46
47 #include "HexQuad.hxx"
48 #include "HexEdge.hxx"
49 #include "HexVertex.hxx"
50
51 BEGIN_NAMESPACE_HEXA
52
53 class Hexa : public EltBase 
54 {
55 public:
56     virtual Quad*   getQuad   (int  nro);
57     virtual Edge*   getEdge   (int  nro);
58     virtual Vertex* getVertex (int  nro);
59
60     virtual int     countQuad   () { return HQ_MAXI; } 
61     virtual int     countEdge   () { return HE_MAXI; } 
62     virtual int     countVertex () { return HV_MAXI; } 
63
64 public:
65     Hexa (Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4, 
66           Vertex* v5, Vertex* v6, Vertex* v7, Vertex* v8);
67     Hexa (Quad* qa, Quad* qb, Quad* qc, Quad* qd, Quad* qe, Quad* qf);
68     Hexa (Hexa* other);
69     Quad* Inter   (Hexa* other);
70     bool  definedBy  (Vertex* v1, Vertex* v2);
71     bool  definedBy  (Quad*   va, Quad*   v2);
72     virtual void dump ();
73     virtual void dumpPlus ();
74     virtual void dumpFull ();
75   
76     void razNodes ();
77     int  countNodes ();                      // Compte et numerote les noeuds
78     void printNodes (pfile vtk, int& count); // Impression format vtk
79     void colorNodes (pfile vtk);             // Impression scalaires vtk
80     void moveNodes  (Matrix* matrice);       // transfo controlee ds un ensemble
81     void transform  (Matrix* matrice);       // transfo indivituelle
82     void printHexa  (pfile vtk);             // Impression de la cellule 
83     virtual void majReferences();            // M.A.J relation "utilise par"
84
85     bool hasFreeEdges  ();
86     void propager (Propagation* prop, int nro);
87     void setScalar (double valeur);
88     void setColor  (double valeur)          { setScalar (valeur) ; }
89
90     virtual void saveXml (XmlWriter* xml);
91
92     Elements*  disconnectQuad   (Quad*   face);
93     Elements*  disconnectEdge   (Edge*   arete);
94     Elements*  disconnectVertex (Vertex* noeud);
95
96     int getBase (Vertex* orig, Edge* normale);
97
98     void replaceQuad   (Quad*   old, Quad* nouveau);
99     void replaceEdge   (Edge*   old, Edge* nouveau);
100     void replaceVertex (Vertex* old, Vertex* nouveau);
101     void removeConnected ();
102     void markElements (int marque);
103     double* getCenter    (double centre[]);
104
105     virtual void   duplicate ();
106     Hexa* getClone ()               {  return h_clone ; }
107     Quad*   getOpposedQuad   (Quad* face);
108     Vertex* getOpposedVertex (Quad* face, Vertex* vertex);
109     Edge* getPerpendicularEdge (Quad* face, Vertex* vertex);
110     Edge* getParallelEdge      (Quad* face, Edge*   edge);
111     Quad* findQuad             (Edge* e1, Edge* e2);
112     Edge* findEdge             (Vertex* v1, Vertex* v2);
113
114     int   findQuad   (Quad*   element);
115     int   findEdge   (Edge*   element);
116     int   findVertex (Vertex* element);
117
118
119 private:
120     friend class Cloner;
121     void  OrdonnerAretes ();    // obsolete ?
122     void  OrdonnerSommets ();   // obsolete ?
123
124     void  controlerFaces   ();  // Controle primaire des donnees utilisateur   
125     void  controlerSommets ();  // Idem;  
126
127     void  verifierSommets ();   // Controle de coherence des quads
128     void  verifierAretes ();    // Idem
129
130     void  controlerArete (int arete, int face1, int face2);
131     void  controlerSommet (int node, int arete1, int arete2, int arete3);
132
133     int   findOpposedQuad (Quad* face, Edge* arete);
134
135 private:
136     Quad*   h_quad   [HQ_MAXI];
137     Edge*   h_edge   [HE_MAXI];
138     Vertex* h_vertex [HV_MAXI];
139     Hexa*   h_clone;
140 };
141 // ------------------------------------------------------------  inlining
142 // ============================================================  getQuad
143 inline Quad* Hexa::getQuad (int nro) 
144 {
145    Quad* elt = NULL;
146    if (nro >=0 && nro < HQ_MAXI && el_status == HOK && h_quad [nro]->isValid())
147       elt = h_quad [nro]; 
148
149    return elt;
150 }
151 // ============================================================  getEdge
152 inline Edge* Hexa::getEdge (int nro)
153 {
154    Edge* elt = NULL;
155    if (nro >=0 && nro < HE_MAXI && el_status == HOK && h_edge [nro]->isValid())
156       elt = h_edge [nro]; 
157
158    return elt;
159 }
160 // ============================================================  getVertex
161 inline Vertex* Hexa::getVertex (int nro)
162 {
163    Vertex* elt = NULL;
164    if (nro >=0 && nro <  HV_MAXI && el_status == HOK && h_vertex [nro]->isValid())
165       elt = h_vertex [nro]; 
166
167    return elt;
168 }
169 // ============================================================  getCenter
170 inline double* Hexa::getCenter (double centre[])
171 {
172    centre [dir_x] = centre [dir_y] = centre [dir_z] = 0;
173
174    for (int nv=0 ; nv<HV_MAXI ; nv++)
175        {
176        centre [dir_x] += h_vertex[nv]->getX ();
177        centre [dir_y] += h_vertex[nv]->getY ();
178        centre [dir_z] += h_vertex[nv]->getZ ();
179        }
180
181    centre [dir_x] /= HV_MAXI;
182    centre [dir_y] /= HV_MAXI;
183    centre [dir_z] /= HV_MAXI;
184    return centre;
185 }
186 // =============================================================== definedBy
187 inline bool Hexa::definedBy  (Vertex* v1, Vertex* v2)
188 {
189    for (int n1=0 ; n1< HV_MAXI ; n1++)
190        {
191 //              (   Diagonale        )  Dessus
192        int n2 = (n1 + 2) MODULO HV_MAXI + HV_MAXI;
193        if (   (v1 == h_vertex[n1] && v2 == h_vertex[n2])
194            || (v1 == h_vertex[n2] && v2 == h_vertex[n1])) return true;
195        }
196    return false;
197 }
198 // =============================================================== definedBy
199 inline bool Hexa::definedBy  (Quad* qa, Quad* qb)
200 {
201    for (int nc=0 ; nc< 3 ; nc++)
202        {
203        if (   (qa == h_quad[2*nc]   && qb == h_quad[2*nc+1])
204            || (qa == h_quad[2*nc+1] && qb == h_quad[2*nc])) return true;
205        }
206    return false;
207 }
208 // =============================================================== setScalar
209 inline void Hexa::setScalar  (double val)
210 {
211    for (int nc=0 ; nc< HV_MAXI ; nc++)
212        h_vertex[nc] -> setScalar (val);
213 }
214 // ============================================================== markElements
215 inline void Hexa::markElements  (int marque)
216 {
217    for (int nc=0 ; nc< HQ_MAXI ; nc++) h_quad  [nc] -> setMark (marque);
218    for (int nc=0 ; nc< HE_MAXI ; nc++) h_edge  [nc] -> setMark (marque);
219    for (int nc=0 ; nc< HV_MAXI ; nc++) h_vertex[nc] -> setMark (marque);
220 }
221 // =============================================================== duplicate
222 inline void Hexa::duplicate  ()
223 {
224    h_clone = new Hexa (GetClone (h_quad [Q_A]), 
225                        GetClone (h_quad [Q_B]), 
226                        GetClone (h_quad [Q_C]), 
227                        GetClone (h_quad [Q_D]), 
228                        GetClone (h_quad [Q_E]), 
229                        GetClone (h_quad [Q_F]));
230 }
231 END_NAMESPACE_HEXA
232 #endif
233