{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9636506c",
   "metadata": {},
   "source": [
    "# Ejercicio parte 2 : Propiedades de la malla modflow"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3ce4aef",
   "metadata": {},
   "source": [
    "En este ejemplo la malla no estructurada generada en el notebook p1 será convertida al formato <b>Modflow 6</b>. Este formato requiere numerar las celdas que conforman la malla y los vértices de cada celda. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2fc8dad8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.insert(0, '../src')\n",
    "from meshProperties import mesh_shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07fa1523",
   "metadata": {},
   "source": [
    "### primero cargamos el archivo shp que generamos en la parte 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "abc03620",
   "metadata": {},
   "outputs": [],
   "source": [
    "mesh=mesh_shape('../examples/out/angascancha/voronoiRegions.shp')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f9e68de",
   "metadata": {},
   "source": [
    "### extraemos la informacion requerida por el paquete disV de modflow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6a25825c",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████████████████████████████████████████████████████████████████████| 14193/14193 [00:00<00:00, 59828.18it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Creating a unique list of vertices [[x1,y1],[x2,y2],...]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "  3%|█▉                                                                          | 370/14193 [00:00<00:03, 3630.16it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Extracting cell2d data and grid index\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████| 14193/14193 [00:03<00:00, 3843.60it/s]\n"
     ]
    }
   ],
   "source": [
    "gridprops=mesh.get_gridprops_disv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "66658e5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "cell2d = gridprops['cell2d']\n",
    "vertices = gridprops['vertices']\n",
    "ncpl = gridprops['ncpl']\n",
    "nvert = gridprops['nvert']\n",
    "centroids=gridprops['centroids']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a04ee04f",
   "metadata": {},
   "source": [
    "\n",
    "•\tCell2d contiene el ID del polígono sus centroides y la numeración de los vértices que lo conforman.\n",
    "\n",
    "•\tVértices contiene el ID del vértice y sus coordenadas x-y\n",
    "\n",
    "•\tCentroids contiene los centroides de todos los polígonos de la malla en orden de ID.\n",
    "\n",
    "Informacion de los Primeros 5 polígonos de la malla voronoi:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d95e056c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0, 614988.167427446, 8360418.465543622, 6, 134, 62, 45, 40, 102, 134],\n",
       " [1, 614037.6933506567, 8357538.338195067, 7, 5, 4, 2, 0, 1, 3, 5],\n",
       " [2, 614338.9498379508, 8357412.267883617, 6, 13, 14, 9, 4, 5, 13],\n",
       " [3, 614682.1015351404, 8357504.382107228, 7, 14, 13, 15, 19, 30, 22, 14],\n",
       " [4, 614655.3612131404, 8357097.716998593, 6, 32, 17, 10, 20, 33, 32]]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cell2d[0:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "eefc0e79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0, 613882.5067587458, 8357372.451446082],\n",
       " [1, 613903.5641560691, 8357922.451700522],\n",
       " [2, 614060.9157943149, 8357098.475813044],\n",
       " [3, 614120.3865920458, 8357904.17848735],\n",
       " [4, 614182.5067587458, 8357220.066777475]]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vertices[0:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f940c16f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(614988.167427446, 8360418.465543622),\n",
       " (614037.6933506567, 8357538.338195067),\n",
       " (614338.9498379508, 8357412.267883617),\n",
       " (614682.1015351404, 8357504.382107228),\n",
       " (614655.3612131404, 8357097.716998593)]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "centroids[0:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38e01500",
   "metadata": {},
   "source": [
    "### Los resultados son guardados en formato json para su posterior uso en una simulación modflow 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "cb9bc57d",
   "metadata": {},
   "outputs": [],
   "source": [
    "mesh.save_properties('../examples/out/angascancha/json/disvDict.json')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
