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