The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings MMD
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

authoralainbastide <alain.bastide@univ-reunion.fr>
Sun, 19 Jul 2020 06:57:15 +0000 (10:57 +0400)
committeralainbastide <alain.bastide@univ-reunion.fr>
Sun, 19 Jul 2020 06:57:15 +0000 (10:57 +0400)
TODO.md
src/primal.c

diff --git a/TODO.md b/TODO.md
index 8f6f178..9e11310 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -22,6 +22,8 @@ Reduce the execution time of the functions :
 
 ​       
      * Do dualFaceToDualSegments
+     
+     * Memory Allocation see https://github.com/ivmai and GC 
 
 3. Build Matrix
      * primal DIV
index 4aefbf0..9e1782e 100644 (file)
@@ -436,7 +436,7 @@ void setHexahedreCellToCells(struct primalMesh * myPrimalMesh)
                           
                         }
                     }
-           
+                  
                 }                        //                        cellNumbers+=jj;
               
               sortListConnectivity(cellList, cellNumbers);
@@ -466,7 +466,7 @@ void setHexahedreCellToCells(struct primalMesh * myPrimalMesh)
     }
 #endif
   
-
+  
   free(cellList);
   free(vertexList);
   
@@ -719,16 +719,24 @@ void setHexahedreCellToFacesOwnerNeighbour(struct primalMesh * myPrimalMesh)
 
 void setHexahedreFaceToCells(struct primalMesh * myPrimalMesh)
 /*
- * void XXX(struct primalMesh * myPrimalMesh)
+ * void setHexahedreFaceToCells(struct primalMesh * myPrimalMesh)
  * 
  * 
  * Input : myPrimalMesh struct
  * 
- * Use :  
+ * Use :  myPrimalMesh->faceNumber
+ *        myPrimalMesh->cellNumber
+ *        myPrimalMesh->cellToFacesOwnerNumber
+ *        myPrimalMesh->cellToFacesNeighbourNumber
  *        
  * 
  * Allocate : 
+ *            myPrimalMesh->faceToCells
+ *            myPrimalMesh->faceToCellsNumber
  * Produce : 
+ *            myPrimalMesh->faceToCells
+ *            myPrimalMesh->faceToCellsNumber
+ *           
  * 
  */
 {
@@ -754,8 +762,6 @@ void setHexahedreFaceToCells(struct primalMesh * myPrimalMesh)
       
       for(connectivity_int faceAi=0;faceAi<myPrimalMesh->cellToFacesOwnerNumber[celli];faceAi++)
         {
-          //          myPrimalMesh->cellToFacesOwner[celli][faceAi];
-          //          debug_print("O: %ld %ld\n",celli, myPrimalMesh->cellToFacesOwner[celli][faceAi]);
           
           selectedFace = myPrimalMesh->cellToFacesOwner[celli][faceAi];
           
@@ -768,8 +774,6 @@ void setHexahedreFaceToCells(struct primalMesh * myPrimalMesh)
       
       for(connectivity_int faceAi=0;faceAi<myPrimalMesh->cellToFacesNeighbourNumber[celli];faceAi++)
         {
-          //          myPrimalMesh->cellToFacesOwner[celli][faceAi];
-          //          debug_print("O: %ld %ld\n",celli, myPrimalMesh->cellToFacesNeighbour[celli][faceAi]);
           
           selectedFace = myPrimalMesh->cellToFacesNeighbour[celli][faceAi];
           
@@ -799,10 +803,6 @@ void setHexahedreFaceToCells(struct primalMesh * myPrimalMesh)
   
 #endif
   
-  //  free(copyFace);
-  //  free(vertexList);
-  //  free(vertexListInverted);
-  
   
   endFunction(__FUNCTION__, t);
   
@@ -812,23 +812,37 @@ void setHexahedreFaceToCells(struct primalMesh * myPrimalMesh)
 
 void setHexahedreSegments(struct primalMesh * myPrimalMesh)
 /*
- * void XXX(struct primalMesh * myPrimalMesh)
+ * void setHexahedreSegments(struct primalMesh * myPrimalMesh)
  * 
  * 
  * Input : myPrimalMesh struct
  * 
- * Use :  
+ * Use :  myPrimalMesh->cellNumber
+ *        myPrimalMesh->cellToVertex
+ *      
+ * 
+ *        hexaedron_localSegmentList
  *        
  * 
- * Allocate : 
- * Produce : 
+ * Allocate : myPrimalMesh->segments
+ *            myPrimalMesh->segmentNumber
+ *            myPrimalMesh->cellToSegmentOwner
+ *            myPrimalMesh->cellToSegmentOwnerNumber
+ *            myPrimalMesh->cellToSegmentNeighbour
+ *            myPrimalMesh->cellToSegmentNeighbourNumber
+ * 
+ * Produce :  myPrimalMesh->segments
+ *            myPrimalMesh->segmentNumber
+ *            myPrimalMesh->cellToSegmentOwner
+ *            myPrimalMesh->cellToSegmentOwnerNumber
+ *            myPrimalMesh->cellToSegmentNeighbour
+ *            myPrimalMesh->cellToSegmentNeighbourNumber
  * 
  */
 {
   
   clock_t t=startFunction(__FUNCTION__);
   affiche("\n");
-  //  affiche("%s : REFAIRE CETTE FONCTION EN UTILISANT CELLTOFACE PUIS REDUIRE LA RECHERCHE DANS SEGMENTS EN INTRODUISANT PAR EXEMPLE CELLTOSEGMENTS\n",__FUNCTION__);
   
   connectivity_int * vertexList         = (connectivity_int * ) malloc(sizeof (connectivity_int)*SEGMENTVERTEX);
   connectivity_int * vertexListInverted = (connectivity_int * ) malloc(sizeof (connectivity_int)*SEGMENTVERTEX);
@@ -1015,16 +1029,17 @@ void setHexahedreSegments(struct primalMesh * myPrimalMesh)
 
 void setHexahedreSegmentsCentres(struct primalMesh * myPrimalMesh)
 /*
- * void XXX(struct primalMesh * myPrimalMesh)
+ * void setHexahedreSegmentsCentres(struct primalMesh * myPrimalMesh)
  * 
  * 
  * Input : myPrimalMesh struct
  * 
- * Use :  
+ * Use :  myPrimalMesh->segmentNumber
  *        
  * 
- * Allocate : 
- * Produce : 
+ * Allocate : myPrimalMesh->segmentCentres
+ *            
+ * Produce :  myPrimalMesh->segmentCentres
  * 
  */
 {
@@ -1082,128 +1097,11 @@ void setHexahedreSegmentsCentres(struct primalMesh * myPrimalMesh)
 
 
 
-void setHexahedreSegments2(struct primalMesh * myPrimalMesh)
-/*
- * void XXX(struct primalMesh * myPrimalMesh)
- * 
- * 
- * Input : myPrimalMesh struct
- * 
- * Use :  
- *        
- * 
- * Allocate : 
- * Produce : 
- * 
- */
-{
-  
-  clock_t t=startFunction(__FUNCTION__);
-  affiche("\n");
-  affiche("%s : Nouvelle fonction setHexahedreSegments pour réduire le temps de calcul\n",__FUNCTION__);
-  
-  connectivity_int * vertexList         = (connectivity_int * ) malloc(sizeof (connectivity_int)*SEGMENTVERTEX);
-  connectivity_int * vertexListInverted = (connectivity_int * ) malloc(sizeof (connectivity_int)*SEGMENTVERTEX);
-  connectivity_int * copyFace           = (connectivity_int * ) malloc(sizeof (connectivity_int)*(QUAD+1));
-  
-  connectivity_int testSegment = 0;
-  
-  myPrimalMesh->segments  = (connectivity_int ** ) realloc(myPrimalMesh->segments, sizeof (connectivity_int*)*(myPrimalMesh->cellNumber*6));
-  for (connectivity_int segmentAi=0;segmentAi<(myPrimalMesh->cellNumber*6);segmentAi++)
-    myPrimalMesh->segments[segmentAi]  = (connectivity_int * ) malloc(sizeof (connectivity_int)*SEGMENTVERTEX);
-  
-  for (connectivity_int faceAi=0;faceAi<myPrimalMesh->faceNumber;faceAi++)
-    //  for (long faceAi=(long)(myPrimalMesh->faceNumber-1);faceAi>=0;faceAi--)
-    {
-      
-      if(faceAi % (int)floor(myPrimalMesh->cellNumber*10/NBAFFICHE) == 0 && faceAi != 0)
-        release_print( "%-40s :  (%ld)\n","FACE", faceAi);
-      
-      
-      memcpy(copyFace,myPrimalMesh->faces[faceAi],sizeof (connectivity_int)*(QUAD));
-      copyFace[QUAD] = copyFace[0];
-      
-      for (connectivity_int vertexAi=0;vertexAi<QUAD;vertexAi++)
-        {
-          
-          vertexList[0] = copyFace[vertexAi];
-          vertexList[1] = copyFace[(vertexAi+1) % QUAD];
-          
-          vertexListInverted[0] = vertexList[1];
-          vertexListInverted[1] = vertexList[0];
-          
-          testSegment = 0;
-          
-          /*
-           * AMELIORATION du temps de calcul :
-           * Augmenter la vitesse de recherche
-           * en incluant une fonction faceToCells puis cellToSegments pour réduire l'impact de la recherche
-           */
-          for (connectivity_int segmentAi=0;segmentAi<myPrimalMesh->segmentNumber  && testSegment == 0;segmentAi++)
-            {
-              
-              if( vertexList[0] == myPrimalMesh->segments[segmentAi][0])
-                {
-                  if( vertexList[1] == myPrimalMesh->segments[segmentAi][1])
-                    {
-                      testSegment = 1;
-                    }
-                }
-              else
-                if( vertexListInverted[0] == myPrimalMesh->segments[segmentAi][0])
-                  {
-                    if( vertexListInverted[1] == myPrimalMesh->segments[segmentAi][1])
-                      
-                      {
-                        testSegment = 2;
-                      }
-                  }
-            }
-          
-          if(testSegment == 0)
-            {
-              if(myPrimalMesh->cellNumber*HEXAHEDRON_FACES<=myPrimalMesh->segmentNumber)
-                {
-                  myPrimalMesh->segments  = (connectivity_int ** ) realloc(myPrimalMesh->segments, sizeof (connectivity_int*)*(myPrimalMesh->segmentNumber+1));
-                  myPrimalMesh->segments[myPrimalMesh->segmentNumber]  = (connectivity_int * ) malloc(sizeof (connectivity_int)*SEGMENTVERTEX);
-                }
-              memcpy(myPrimalMesh->segments[myPrimalMesh->segmentNumber], vertexList, sizeof(connectivity_int)*SEGMENTVERTEX);
-              
-              myPrimalMesh->segmentNumber++;
-            }
-          
-        }
-    }
-  
-#ifdef DEBUG
-  for(connectivity_int segmentAi=0;segmentAi<myPrimalMesh->segmentNumber;segmentAi++)
-    {
-      debug_print( "%-40s : %ld ( ","myPrimalMesh->segments", segmentAi);
-      
-      for(connectivity_int vertexAi=0;vertexAi<SEGMENTVERTEX;vertexAi++)
-        {
-          debug_print( "%ld " , myPrimalMesh->segments[segmentAi][vertexAi] );
-        }
-      debug_print(")\n");
-    }
-  
-#endif
-  
-  free(copyFace);
-  free(vertexList);
-  free(vertexListInverted);
-  
-  
-  endFunction(__FUNCTION__, t);
-  
-}
-
-
 
 
 void setHexahedreVertexToSegments(struct primalMesh * myPrimalMesh)
 /*
- * void XXX(struct primalMesh * myPrimalMesh)
+ * void setHexahedreVertexToSegments(struct primalMesh * myPrimalMesh)
  * 
  * 
  * Input : myPrimalMesh struct
@@ -1735,7 +1633,7 @@ void setHexahedreSortFaceToVertex(struct primalMesh * myPrimalMesh)
       
     }
   
+  
   endFunction(__FUNCTION__, t);
   
 }
@@ -2165,6 +2063,7 @@ void setHexahedreBoundaryFaces(struct primalMesh * myPrimalMesh)
   clock_t t=startFunction(__FUNCTION__);
   
   
+  // identifys boundary faces an put face numbers in faceBoundary
   for(connectivity_int facei=0;facei<myPrimalMesh->faceNumber;facei++)
     {
       if(myPrimalMesh->faceToCellsNumber[facei] == 1)
@@ -2173,20 +2072,81 @@ void setHexahedreBoundaryFaces(struct primalMesh * myPrimalMesh)
           myPrimalMesh->faceBoundary = (connectivity_int *) realloc( myPrimalMesh->faceBoundary, (myPrimalMesh->faceBoundaryNumber+1) * sizeof(connectivity_int));
           
           myPrimalMesh->faceBoundary[myPrimalMesh->faceBoundaryNumber] = facei;
-
+          
           myPrimalMesh->faceBoundaryNumber++;
         }
-
+      
     }  
-
+  
+  connectivity_short * tmpVertex = (connectivity_short *) malloc(myPrimalMesh->vertexNumber * sizeof(connectivity_short));
+  memset(tmpVertex, (0), myPrimalMesh->vertexNumber * sizeof(connectivity_short));
+  connectivity_int boundaryVertexNumber = 0;
+  
   for(connectivity_int facei=0;facei<myPrimalMesh->faceBoundaryNumber;facei++)
     {
-//      myPrimalMesh->faces[myPrimalMesh->faceBoundary[facei]];
+      connectivity_int faceNumber = myPrimalMesh->faceBoundary[facei]; // numero de la face frontière
+      connectivity_int * facej = myPrimalMesh->faces[ faceNumber ]; // récupere le numero des points de cette face
+      
+      for(connectivity_short vertexi=0;vertexi<QUAD;vertexi++)
+        {      
+          tmpVertex[facej[vertexi]] ++; // compte pour chaque point le nombre de faces frontières
+        }
+    }
+  
+  connectivity_int * boundaryVertexGlobal = (connectivity_int *) malloc(myPrimalMesh->vertexNumber * sizeof(connectivity_int));
+  memset(boundaryVertexGlobal, (connectivity_int)(0), myPrimalMesh->vertexNumber * sizeof(connectivity_int));
+  
+  for(connectivity_int vertexi=0;vertexi<myPrimalMesh->vertexNumber;vertexi++)
+    {
+      if(tmpVertex[vertexi]!=0) boundaryVertexNumber++; // compte le nombre de points frontière
+    }  
+  
+  connectivity_int * boundaryVertex = (connectivity_int *) malloc(boundaryVertexNumber * sizeof(connectivity_int));
+  connectivity_int count = 0;
+  for(connectivity_int vertexi=0;vertexi<myPrimalMesh->vertexNumber;vertexi++)
+    {
+      if(tmpVertex[vertexi]!=0) { // si le point est frontière
+          boundaryVertex[count] = vertexi; // vecteur de taille boundaryVertexNumber qui stocke les numéros de points
+          boundaryVertexGlobal[vertexi] = count; // stocke dans un vecteur global la position locale du point dans boundaryVertex
+          count++;
+        }
+    }
+  
+  
+  // boundaryVertexToBoundaryFaces
+  count=0;
+  connectivity_int * boundaryVertexToBoundaryFacesNumber = (connectivity_int *) malloc(boundaryVertexNumber * sizeof(connectivity_int));
+  for(connectivity_int vertexi=0;vertexi<boundaryVertexNumber;vertexi++)
+    {
+      memset(boundaryVertexToBoundaryFacesNumber, (connectivity_int)(0), sizeof(connectivity_int));
+    }
+  
+  connectivity_int ** boundaryVertexToBoundaryFaces = (connectivity_int **) malloc(boundaryVertexNumber * sizeof(connectivity_int*));
+  for(connectivity_int vertexi=0;vertexi<myPrimalMesh->vertexNumber;vertexi++)
+    {
+      if(tmpVertex[vertexi]!=0) {
+          boundaryVertexToBoundaryFacesNumber[count] = tmpVertex[vertexi];
+          boundaryVertexToBoundaryFaces[count] = (connectivity_int*) malloc( boundaryVertexToBoundaryFacesNumber[count] * sizeof(connectivity_int*));
+          count++;
+        }  
     }
   
-//https://codeforwin.org/2015/07/c-program-to-print-all-unique-element-in-array.html  
-
 
+  //  for(connectivity_int facei=0;facei<myPrimalMesh->faceBoundaryNumber;facei++)
+  //    {
+  //      connectivity_int faceNumber = myPrimalMesh->faceBoundary[facei];
+  //      connectivity_int * facej = myPrimalMesh->faces[ faceNumber ];
+  
+  //      for(connectivity_short vertexi=0;vertexi<QUAD;vertexi++)
+  //        {      //      myPrimalMesh->faces[myPrimalMesh->faceBoundary[facei]];
+  //          connectivity_int vertexGlobal = ;
+  
+  //          boundaryVertexToBoundaryFaces[facej[vertexi]][boundaryVertexToBoundaryFacesNumber[facej[vertexi]] ] = faceNumber;
+  //          boundaryVertexToBoundaryFacesNumber[facej[vertexi]]++;
+  //        }
+  //    }
+  
+  
 #ifdef DEBUG      
   for(connectivity_int facei=0;facei<myPrimalMesh->faceBoundaryNumber;facei++)
     {
@@ -2197,8 +2157,64 @@ void setHexahedreBoundaryFaces(struct primalMesh * myPrimalMesh)
                   
                   );
     }
+  
+  debug_print("%-40s : %ld \n","boundaryVertexNumber",boundaryVertexNumber);
+  
+  for(connectivity_int vertexi=0;vertexi<boundaryVertexNumber;vertexi++)
+    {
+      debug_print("%-40s : %ld (%d)\n",
+                  "tmpVertex",
+                  vertexi,
+                  tmpVertex[vertexi]
+                  
+                  );
+    }
+  
+  
+  for(connectivity_int vertexi=0;vertexi<myPrimalMesh->vertexNumber;vertexi++)
+    {
+      debug_print("%-40s : %ld (%ld)\n",
+                  "boundaryVertexGlobal",
+                  vertexi,
+                  boundaryVertexGlobal[vertexi]
+                  
+                  );
+    }
+  
+  for(connectivity_int vertexi=0;vertexi<boundaryVertexNumber;vertexi++)
+    {
+      debug_print("%-40s : %ld (%ld)\n",
+                  "boundaryVertex",
+                  vertexi,
+                  boundaryVertex[vertexi]
+                  
+                  );
+    }
+  
+  
+  //  for(connectivity_int faceAi=0;faceAi<myDualMesh->internalDualFacesNumber;faceAi++)
+  //    {
+  
+  //      debug_print( "%-40s : %ld","myDualMesh->internalDualFaces", faceAi);
+  
+  
+  //          for(connectivity_int vertexi=0;vertexi<DIM3D;vertexi++)
+  //            {
+  //              debug_print( "%lf " , boundaryVertexToBoundaryFaces[faceAi][pointi] );
+  //            }
+  
+  //      debug_print(" \n");
+  
+  //    }
 #endif   
   
+  free(tmpVertex);
+  free(boundaryVertexToBoundaryFaces);
+  //  boundaryVertexGlobal
+  //  boundaryVertexToBoundaryFacesNumber
+  
+  //      boundaryVertexToBoundaryFaces
+  
   endFunction(__FUNCTION__, t);
   
 }