Salome HOME
Merge branch 'V7_dev'
[modules/hexablock.git] / src / HEXABLOCK / HexHexa.cxx
index 3290a835a2128c4788d4e3e50f42e17e05e168c7..fd76993f19626797d59f566628517d89fd90df9c 100755 (executable)
@@ -1,12 +1,12 @@
 
 // C++ : Gestion des Hexaedres
 
-// Copyright (C) 2009-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -194,6 +194,38 @@ void Hexa::controlerFaces  ()
               setError (888);
               }
        }
+   for (int dd=0 ; dd<DIM3 ; dd++)
+       {
+       Quad* qa  = h_quad [2*dd];
+       Quad* qb  = h_quad [2*dd+1];
+       Edge* cut = qa->inter (qb);
+       if (cut != NULL)
+          {
+          bool more = true;
+          for (int nc=2*dd+2 ; more && nc<HQ_MAXI ; nc++)
+              {
+              Edge* cut = qa->inter (h_quad[nc]);
+              if (cut==NULL)
+                 {
+                 more = false;
+                 // cout << " ... le quad oppose au quad " << 2*dd
+                      // << " est le " << nc << endl;
+                 qb             = h_quad[nc];
+                 h_quad[nc]     = h_quad [2*dd+1];
+                 h_quad[2*dd+1] = qb;
+                 }
+              }
+          if (more)
+             {
+             char num [10];
+             sprintf (num, "%d", 2*dd+1);
+             el_root->putError ("addHexa : the %sth quad has no opposed quad",
+                                 num);
+             setError (886);
+             return ;
+             }
+          }
+       }
 }
 // ======================================================== controlerSommets
 void Hexa::controlerSommets  ()
@@ -1074,8 +1106,29 @@ Edge* Hexa::findEdge (Vertex* v1, Vertex* v2)
 
    return NULL;
 }
-// ====================================================== getPerpendicularEdge
-Edge* Hexa::getPerpendicularEdge (Quad* quad, Vertex* vertex)
+// ====================================================== opposedVertex
+Vertex* Hexa::opposedVertex (Quad* quad, Vertex* vertex)
+{
+   if (quad==NULL || vertex==NULL)
+      return NULL;
+
+   int nv = quad->indexVertex (vertex);
+   int nq = findQuad (quad);
+   if (nv<0 || nq<0)
+      return NULL;
+
+   for (int nro=0 ; nro<HE_MAXI ; nro++)
+       {
+       Edge* edge = h_edge [nro];
+       int   nv   = edge->index (vertex);
+       if (nv>=0 && quad->indexEdge(edge) <0)
+          return edge->getVertex (1-nv);
+       }
+
+   return NULL;
+}
+// ====================================================== perpendicularEdge
+Edge* Hexa::perpendicularEdge (Quad* quad, Vertex* vertex)
 {
    if (quad==NULL || vertex==NULL)
       return NULL;
@@ -1093,6 +1146,29 @@ Edge* Hexa::getPerpendicularEdge (Quad* quad, Vertex* vertex)
 
    return NULL;
 }
+// ====================================================== perpendicularQuad
+Quad* Hexa::perpendicularQuad (Quad* quad, Edge* edge)
+{
+   if (BadElement (quad) || BadElement (edge))
+      return NULL;
+
+   int qed = quad->indexEdge (edge);
+   int ned = findEdge (edge);
+   int nq  = findQuad (quad);
+   if (qed <0 || ned<0 || nq<0)
+      return NULL;
+
+   for (int nro=0 ; nro<HQ_MAXI ; nro++)
+       {
+       if (nro != nq)
+          {   
+          Quad* face = h_quad[nro];
+          if (EltIsValid(face) && face->indexEdge (edge)>=0)
+             return face;
+          }
+       }
+   return NULL;
+}
 // ============================================================  getQuad
 Quad* Hexa::getQuad (int nro)
 {
@@ -1152,12 +1228,18 @@ bool Hexa::definedBy  (Vertex* v1, Vertex* v2)
 // =============================================================== definedBy
 bool Hexa::definedBy  (Quad* qa, Quad* qb)
 {
-   for (int nc=0 ; nc< 3 ; nc++)
+   if (qa==qb || BadElement (qa) || BadElement (qb))
+       return false;
+
+   bool p1 = false, p2 = false;
+   for (int nq=0 ; nq< HQ_MAXI ; nq++)
        {
-       if (   (qa == h_quad[2*nc]   && qb == h_quad[2*nc+1])
-           || (qa == h_quad[2*nc+1] && qb == h_quad[2*nc])) return true;
+       if (qa == h_quad[nq])
+          p1 = true;
+       else if (qb == h_quad[nq])
+          p2 = true;
        }
-   return false;
+   return p1 && p2;
 }
 // =============================================================== setColor
 void Hexa::setColor  (double val)