Open arvedes opened 1 year ago
For number 2, do you mean something like this.
+def run_elmer_grid(sim_dir, meshfile, elmergrid=None, **kwargs):
"""Run ElmerGrid on gmsh meshfile and move everithing into main
directory.
@@ -14,6 +14,8 @@ def run_elmer_grid(sim_dir, meshfile, elmergrid=None):
sim_dir (str): Simulation directory
meshfile (str): Filename of .msh file
elmergrid (str): ElmerGrid executable
+ Kwargs:
+ out_dir (str): Optional directory to save the output.
"""
if elmergrid is None:
# On Windows ElmerGrid.exe is not found once gmsh.initialize() was executed.
@@ -28,11 +30,12 @@ def run_elmer_grid(sim_dir, meshfile, elmergrid=None):
subprocess.run(args, cwd=sim_dir, stdout=f, stderr=f)
mesh_dir = sim_dir + "/" + ".".join(meshfile.split(".")[:-1])
+ out_dir = kwargs.get('out_dir', sim_dir)
files = os.listdir(mesh_dir)
for f in files:
if os.path.exists(sim_dir + "/" + f):
os.remove(sim_dir + "/" + f)
- shutil.move(mesh_dir + "/" + f, sim_dir)
+ shutil.move(mesh_dir + "/" + f, out_dir)
shutil.rmtree(mesh_dir)
Yes, exactly. Alternatively we could do something like
def run_elmer_grid(sim_dir, meshfile, elmergrid=None, move_to_simdir=True):
(...)
if move_to_simdir:
files = os.listdir(mesh_dir)
for f in files:
if os.path.exists(sim_dir + "/" + f):
os.remove(sim_dir + "/" + f)
shutil.move(mesh_dir + "/" + f, sim_dir)
shutil.rmtree(mesh_dir)
In case move_to_simdir==False
everyting would stay in mesh_dir
folder, as it is the usual ElmerGrid behavior.
Which one would you prefer?
We can also add bool kwarg keep_mesh_dir
to the value, which will not run the code block at all.
On Thu, Jan 5, 2023 at 3:15 PM Arved Wintzer @.***> wrote:
Yes, exactly. Alternatively we could do something like
def run_elmer_grid(sim_dir, meshfile, elmergrid=None, move_to_simdir=True): (...)
if move_to_simdir: files = os.listdir(mesh_dir) for f in files: if os.path.exists(sim_dir + "/" + f): os.remove(sim_dir + "/" + f) shutil.move(mesh_dir + "/" + f, sim_dir) shutil.rmtree(mesh_dir)
In case move_to_simdir==False everyting would stay in mesh_dir folder, as it is the usual ElmerGrid behavior.
Which one would you prefer?
— Reply to this email directly, view it on GitHub https://github.com/nemocrys/pyelmer/issues/23#issuecomment-1372024876, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2VVZVIKNEP4GKYVUC3FZLWQ2NKTANCNFSM6AAAAAATQ5WT24 . You are receiving this because you commented.Message ID: @.***>
Sounds good!
There are some limitations of the run_elmer_grid function:
It shouldn't be a big deal to implement that.