From e25ef92d93a527ceda4b48afb0baa54b5abdd31a Mon Sep 17 00:00:00 2001
From: karamoko <karamoko.samassa@inria.fr>
Date: Mon, 26 Dec 2022 14:28:44 +0100
Subject: [PATCH] now can discretize GEO model

---
 src/bvpy/domains/abstract.py            |   8 +-
 src/bvpy/domains/primitives.py          |  16 +-
 tutorials/bvpy_tutorial_2_domains.ipynb | 250 +++++-------------------
 3 files changed, 60 insertions(+), 214 deletions(-)

diff --git a/src/bvpy/domains/abstract.py b/src/bvpy/domains/abstract.py
index 2aa00ac..023ee5b 100644
--- a/src/bvpy/domains/abstract.py
+++ b/src/bvpy/domains/abstract.py
@@ -21,6 +21,7 @@
 # -----------------------------------------------------------------------
 
 import sys
+import logging
 import tempfile
 from abc import ABC, abstractmethod
 
@@ -392,7 +393,12 @@ class AbstractDomain(ABC):
             self.model.mesh.clear()
 
         if not self.volumes:
-            self.model.addPhysicalGroup(dim, [self.surfaces[0]])
+            try:
+                self.model.addPhysicalGroup(dim, [self.surfaces[0]])
+            except KeyError:
+                logging.warning("Adding physical group of Hemisphere...")
+                for _ , val in self.surfaces.items():
+                    self.model.addPhysicalGroup(2, [val], val+1000)
         else:
             self.model.addPhysicalGroup(dim, [self.volumes[0]])
             
diff --git a/src/bvpy/domains/primitives.py b/src/bvpy/domains/primitives.py
index b8c7390..f903096 100644
--- a/src/bvpy/domains/primitives.py
+++ b/src/bvpy/domains/primitives.py
@@ -395,7 +395,6 @@ class HemiSphere(AbstractDomain, BuiltInModel):
         center = np.array(center)
 
         points = dict()
-        surfaces = dict()
         lines = dict()
 
         points['center'] = self.factory.addPoint(*center)
@@ -450,30 +449,25 @@ class HemiSphere(AbstractDomain, BuiltInModel):
         lineloops = self.factory.addCurveLoop([lines['circle_1'],
                                                lines['circle_7'],
                                                lines['circle_5']])
-        surfaces['quarter_1'] = self.factory.addSurfaceFilling([lineloops])
+        self.surfaces['quarter_1'] = self.factory.addSurfaceFilling([lineloops])
 
         lineloops = self.factory.addCurveLoop([lines['circle_7'],
                                                lines['circle_6'],
                                                lines['circle_2']])
-        surfaces['quarter_2'] = self.factory.addSurfaceFilling([lineloops])
+        self.surfaces['quarter_2'] = self.factory.addSurfaceFilling([lineloops])
 
         lineloops = self.factory.addCurveLoop([lines['circle_6'],
                                                lines['circle_3'],
                                                lines['circle_8']])
-        surfaces['quarter_3'] = self.factory.addSurfaceFilling([lineloops])
+        self.surfaces['quarter_3'] = self.factory.addSurfaceFilling([lineloops])
 
         lineloops = self.factory.addCurveLoop([lines['circle_8'],
                                                lines['circle_5'],
                                                lines['circle_4']])
-        surfaces['quarter_4'] = self.factory.addSurfaceFilling([lineloops])
+        self.surfaces['quarter_4'] = self.factory.addSurfaceFilling([lineloops])
 
-        self.synchronize()
-
-        for key, val in surfaces.items():
-            self.model.addPhysicalGroup(2, [val], val+1000)
-            self.model.setPhysicalName(2, val+1000, key)
+        self.factory.synchronize()
 
-        self.synchronize()
 
 
 class Cube(AbstractDomain, OccModel):
diff --git a/tutorials/bvpy_tutorial_2_domains.ipynb b/tutorials/bvpy_tutorial_2_domains.ipynb
index 21223f2..86f493b 100644
--- a/tutorials/bvpy_tutorial_2_domains.ipynb
+++ b/tutorials/bvpy_tutorial_2_domains.ipynb
@@ -44,7 +44,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -62,17 +62,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Number of triangles within the domain AFTER discretization: 4\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "try:\n",
     "    # domain.mesh.num_cells()\n",
@@ -97,33 +89,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Domain\n",
-      "\n",
-      "------\n",
-      "    * Shape: Rectangle\n",
-      "    * Dimension: 3\n",
-      "    * Length: 1.00e+00\n",
-      "    * Width: 1.00e+00\n",
-      "\n",
-      "Meshing\n",
-      "-------\n",
-      "        * Algorithm: Delaunay\n",
-      "        * Cell type: triangle\n",
-      "        * Number: 3\n",
-      "        * Resolution (i.e. prescribed element size): 1.00e+00\n",
-      "        * Actual size (min, max): (1.00e+00,        1.00e+00)\n",
-      "        * Cells quality: 4.50e+00 +/- 2.87e+00 \n",
-      "\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "domain.info()"
    ]
@@ -138,24 +106,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "962f1bb475cb45eca0a1228b7b6c41ae",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.utils.visu import plot, set_renderer\n",
     "set_renderer('notebook')\n",
@@ -182,24 +135,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "e561ccff5399482eb3d4928de75f32ee",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.utils.visu import plot, set_renderer\n",
     "from bvpy.domains import Rectangle\n",
@@ -231,24 +169,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "b5db0aa22c1945e0b82b57bafae8c249",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "rec = Rectangle(length=2, width=3, cell_size=0.1, clear=True)\n",
     "plot(rec)"
@@ -263,24 +186,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "3d3f14eed8fa4bf4b371dd7395cd9005",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.domains import Disk\n",
     "dsk = Disk(cell_size=0.1, clear=True)\n",
@@ -300,20 +208,33 @@
    "metadata": {},
    "outputs": [
     {
-     "ename": "",
-     "evalue": "",
-     "output_type": "error",
-     "traceback": [
-      "\u001b[1;31mCanceled future for execute_request message before replies were done"
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "WARNING:root:Adding physical group of Hemisphere...\n"
      ]
     },
     {
-     "ename": "",
-     "evalue": "",
-     "output_type": "error",
-     "traceback": [
-      "\u001b[1;31mLe Kernel s’est bloqué lors de l’exécution du code dans la cellule active ou une cellule précédente. Veuillez vérifier le code dans la ou les cellules pour identifier une cause possible de l’échec. Cliquez <a href='https://aka.ms/vscodeJupyterKernelCrash'>ici</a> pour plus d’informations. Pour plus d’informations, consultez Jupyter <a href='command:jupyter.viewOutput'>log</a>."
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Info    : Clearing all models and views...\n",
+      "Info    : Done clearing all models and views\n"
      ]
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "182274771cf6437a972b15e14101d466",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
     }
    ],
    "source": [
@@ -333,13 +254,13 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "f4c9b9021ef04184b2a14e75c4f45d32",
+       "model_id": "a48bb4936ab043d08915c43f1a661985",
        "version_major": 2,
        "version_minor": 0
       },
@@ -367,24 +288,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "f282dc8ea0864d71b137db207b31f06f",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.domains import Ellipsoid\n",
     "elp = Ellipsoid(cell_size=0.1, clear=True)\n",
@@ -400,24 +306,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "47d8a09373f244449677019fb66eafd7",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.domains import Torus\n",
     "tor = Torus(cell_size=0.2, clear=True)\n",
@@ -447,24 +338,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "890f8e1bdad14aae8149deda32465d1d",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.utils.visu import plot, set_renderer\n",
     "from bvpy.domains import Rectangle\n",
@@ -499,24 +375,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "9acdb0a75a5441a79109755fdb731a71",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "from bvpy.domains import Sphere\n",
     "from bvpy.utils.visu import plot, set_renderer\n",
@@ -539,24 +400,9 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 14,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "132ea445eae74e7f836119b4b35da5b6",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "ViewInteractiveWidget(height=768, layout=Layout(height='auto', width='100%'), width=1024)"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "big = Sphere(radius=10, cell_type='tetra', clear=True)\n",
     "sml = Sphere(radius=9, cell_type='tetra')\n",
-- 
GitLab