Salome HOME
91c18b5e77dfc1b3788e410e7f2784a9072c8669
[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     void printHexaVtk (pfile vtk);           // Impression de la cellule 
84     virtual void majReferences();            // M.A.J relation "utilise par"
85
86     bool hasFreeEdges  ();
87     void propager (Propagation* prop, int nro);
88     void setScalar (double valeur);
89     void setColor  (double valeur)          { setScalar (valeur) ; }
90
91     virtual void saveXml (XmlWriter* xml);
92
93     Elements*  disconnectQuad   (Quad*   face);
94     Elements*  disconnectEdge   (Edge*   arete);
95     Elements*  disconnectVertex (Vertex* noeud);
96
97     int getBase (Vertex* orig, Edge* normale);
98
99     void replaceQuad   (Quad*   old, Quad* nouveau);
100     void replaceEdge   (Edge*   old, Edge* nouveau);
101     void replaceVertex (Vertex* old, Vertex* nouveau);
102     void removeConnected ();
103     void markElements (int marque);
104     double* getCenter    (double centre[]);
105
106     virtual void   duplicate ();
107     Hexa* getClone ()               {  return h_clone ; }
108     Quad*   getOpposedQuad   (Quad* face);
109     Vertex* getOpposedVertex (Quad* face, Vertex* vertex);
110     Edge* getPerpendicularEdge (Quad* face, Vertex* vertex);
111     Edge* getParallelEdge      (Quad* face, Edge*   edge);
112     Quad* findQuad             (Edge* e1, Edge* e2);
113     Edge* findEdge             (Vertex* v1, Vertex* v2);
114
115     int   findQuad   (Quad*   element);
116     int   findEdge   (Edge*   element);
117     int   findVertex (Vertex* element);
118
119
120 private:
121     friend class Cloner;
122     void  OrdonnerAretes ();    // obsolete ?
123     void  OrdonnerSommets ();   // obsolete ?
124
125     void  controlerFaces   ();  // Controle primaire des donnees utilisateur   
126     void  controlerSommets ();  // Idem;  
127
128     void  verifierSommets ();   // Controle de coherence des quads
129     void  verifierAretes ();    // Idem
130
131     void  controlerArete (int arete, int face1, int face2);
132     void  controlerSommet (int node, int arete1, int arete2, int arete3);
133
134     int   findOpposedQuad (Quad* face, Edge* arete);
135
136 private:
137     Quad*   h_quad   [HQ_MAXI];
138     Edge*   h_edge   [HE_MAXI];
139     Vertex* h_vertex [HV_MAXI];
140     Hexa*   h_clone;
141 };
142 // ------------------------------------------------------------  inlining
143 // ============================================================  getQuad
144 inline Quad* Hexa::getQuad (int nro) 
145 {
146    Quad* elt = NULL;
147    if (nro >=0 && nro < HQ_MAXI && el_status == HOK && h_quad [nro]->isValid())
148       elt = h_quad [nro]; 
149
150    return elt;
151 }
152 // ============================================================  getEdge
153 inline Edge* Hexa::getEdge (int nro)
154 {
155    Edge* elt = NULL;
156    if (nro >=0 && nro < HE_MAXI && el_status == HOK && h_edge [nro]->isValid())
157       elt = h_edge [nro]; 
158
159    return elt;
160 }
161 // ============================================================  getVertex
162 inline Vertex* Hexa::getVertex (int nro)
163 {
164    Vertex* elt = NULL;
165    if (nro >=0 && nro <  HV_MAXI && el_status == HOK && h_vertex [nro]->isValid())
166       elt = h_vertex [nro]; 
167
168    return elt;
169 }
170 // ============================================================  getCenter
171 inline double* Hexa::getCenter (double centre[])
172 {
173    centre [dir_x] = centre [dir_y] = centre [dir_z] = 0;
174
175    for (int nv=0 ; nv<HV_MAXI ; nv++)
176        {
177        centre [dir_x] += h_vertex[nv]->getX ();
178        centre [dir_y] += h_vertex[nv]->getY ();
179        centre [dir_z] += h_vertex[nv]->getZ ();
180        }
181
182    centre [dir_x] /= HV_MAXI;
183    centre [dir_y] /= HV_MAXI;
184    centre [dir_z] /= HV_MAXI;
185    return centre;
186 }
187 // =============================================================== definedBy
188 inline bool Hexa::definedBy  (Vertex* v1, Vertex* v2)
189 {
190    for (int n1=0 ; n1< HV_MAXI ; n1++)
191        {
192 //              (   Diagonale        )  Dessus
193        int n2 = (n1 + 2) MODULO HV_MAXI + HV_MAXI;
194        if (   (v1 == h_vertex[n1] && v2 == h_vertex[n2])
195            || (v1 == h_vertex[n2] && v2 == h_vertex[n1])) return true;
196        }
197    return false;
198 }
199 // =============================================================== definedBy
200 inline bool Hexa::definedBy  (Quad* qa, Quad* qb)
201 {
202    for (int nc=0 ; nc< 3 ; nc++)
203        {
204        if (   (qa == h_quad[2*nc]   && qb == h_quad[2*nc+1])
205            || (qa == h_quad[2*nc+1] && qb == h_quad[2*nc])) return true;
206        }
207    return false;
208 }
209 // =============================================================== setScalar
210 inline void Hexa::setScalar  (double val)
211 {
212    for (int nc=0 ; nc< HV_MAXI ; nc++)
213        h_vertex[nc] -> setScalar (val);
214 }
215 // ============================================================== markElements
216 inline void Hexa::markElements  (int marque)
217 {
218    for (int nc=0 ; nc< HQ_MAXI ; nc++) h_quad  [nc] -> setMark (marque);
219    for (int nc=0 ; nc< HE_MAXI ; nc++) h_edge  [nc] -> setMark (marque);
220    for (int nc=0 ; nc< HV_MAXI ; nc++) h_vertex[nc] -> setMark (marque);
221 }
222 // =============================================================== duplicate
223 inline void Hexa::duplicate  ()
224 {
225    h_clone = new Hexa (GetClone (h_quad [Q_A]), 
226                        GetClone (h_quad [Q_B]), 
227                        GetClone (h_quad [Q_C]), 
228                        GetClone (h_quad [Q_D]), 
229                        GetClone (h_quad [Q_E]), 
230                        GetClone (h_quad [Q_F]));
231 }
232 END_NAMESPACE_HEXA
233 #endif
234