{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Notebook : Copie d'une simulation dans un nouvel objet" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'d:\\\\ProgrammationGitLab\\\\HECEPython\\\\docs\\\\source\\\\_static\\\\2d'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from wolfhece.mesh2d.wolf2dprev import prev_sim2D\n", "from wolfhece.PyVertexvectors import zone, Zones, vector, wolfvertex\n", "\n", "from tempfile import TemporaryDirectory\n", "from pathlib import Path\n", "import numpy as np\n", "\n", "from os import getcwd\n", "getcwd()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Répertoire de la simulation à copier" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "indir = Path(r'../../../../tests\\data\\2d\\simke')\n", "indir = (getcwd() / indir).absolute()\n", "\n", "print(indir.exists())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initialisation de la simulation à copier" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "oldsim = prev_sim2D(fname=str(indir / 'simul'))\n", "oldsim.check_wolfcli()\n", "oldsim.search_magnetic_grid()\n", "\n", "old_header = oldsim.get_header()\n", "m_grid = oldsim.magnetic_grid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Copie dans une nouvelle instance" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:root:No infiltration file found\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Copy test: False\n", "Return: General parameters are different\n", "Number of weak BC along X are different\n", "\n" ] } ], "source": [ "with TemporaryDirectory() as outdir:\n", "\n", " # Instanciation of the new simulation\n", " # Set the filepath and file name\n", " # Clear the directory if it already exists\n", " newsim = prev_sim2D(fname=str(Path(outdir) / 'test'), clear=True)\n", "\n", " # We want to keep the origin of the new simulation at the same place as the old one\n", " # We don't want to translate the contour lower-left corner to zero\n", " newsim.bloc_description.translate_origin2zero = False\n", "\n", " # Get the extrenal contour\n", " extern = oldsim.external_border\n", "\n", " # Set the magnetic grid\n", " newsim.set_magnetic_grid(dx=m_grid.dx, dy=m_grid.dy, origx=m_grid.origx, origy=m_grid.origy)\n", "\n", " # Set the external border\n", " newsim.set_external_border_vector(extern)\n", "\n", " # Set the mesh size\n", " newsim.set_mesh_fine_size(dx=old_header.dx, dy=old_header.dy)\n", "\n", " # Copy the blocks\n", " # - contour\n", " # - dx, dy\n", " for curblock in oldsim.bloc_description.my_blocks:\n", " newsim.add_block(curblock.contour, dx=curblock.dx, dy=curblock.dy)\n", "\n", " # Mesh the new simulation\n", " # Useful to check if the mesh is correct\n", " if newsim.mesh():\n", "\n", " # Create the fine arrays -- You can skip this step or just copy the old files\n", " newsim.create_fine_arrays()\n", "\n", " # Create the borders\n", " newsim.create_sux_suy()\n", "\n", " # Transfer the parameters\n", " newsim.copy_parameters(oldsim)\n", "\n", " # Check if the new simulation is the same as the old one\n", " # Remark : the boundary conditions are not copied here\n", " log, ret = newsim.is_like(oldsim)\n", "\n", " print('Copy test:', log)\n", " print('Return:', ret)\n", "\n", " else:\n", " print('Error during mesh creation.')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conditions aux limites" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Lecture des fichiers sux_suy\n", "oldsim.sux_suy.read_file()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Récupération des listes d'indices sous forme de np.array\n", "\n", "Ainsi il est possible de trier rapidement" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609\n", " 610 611 612 613 614 615 616 617 618 619 620 621 934 935 936 937 938 939\n", " 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957\n", " 958 959 960 961 962 963]\n", "[644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644\n", " 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644\n", " 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644 644\n", " 644 644 644 644 644 644]\n" ] } ], "source": [ "bc_i, bc_j = np.asarray(oldsim.list_pot_bc_y())\n", "\n", "# On ne garde que les bords dont j > 640\n", "test = bc_j > 640\n", "print(bc_i[test])\n", "print(bc_j[test])\n" ] } ], "metadata": { "kernelspec": { "display_name": "python3.10", "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.10.11" } }, "nbformat": 4, "nbformat_minor": 2 }