-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve run_elmer_grid function #23
Labels
Comments
arvedes
added
enhancement
New feature or request
good first issue
Good for newcomers
labels
Jan 4, 2023
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 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
<#23 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI2VVZVIKNEP4GKYVUC3FZLWQ2NKTANCNFSM6AAAAAATQ5WT24>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Sounds good! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are some limitations of the run_elmer_grid function:
It shouldn't be a big deal to implement that.
The text was updated successfully, but these errors were encountered: