Skip to content
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

Open
1 of 3 tasks
arvedes opened this issue Jan 4, 2023 · 4 comments
Open
1 of 3 tasks

Improve run_elmer_grid function #23

arvedes opened this issue Jan 4, 2023 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@arvedes
Copy link
Member

arvedes commented Jan 4, 2023

There are some limitations of the run_elmer_grid function:

  • It only works with Gmsh msh-files
  • It moves all the output back into the directory where the msh-file is (this should be default but optional)
  • It doesn’t support any additional arguments for ElmerGrid (e.g. for partitioning)

It shouldn't be a big deal to implement that.

@arvedes arvedes added enhancement New feature or request good first issue Good for newcomers labels Jan 4, 2023
@muddi900
Copy link
Contributor

muddi900 commented Jan 5, 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)

@arvedes
Copy link
Member Author

arvedes commented Jan 5, 2023

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?

@muddi900
Copy link
Contributor

muddi900 commented Jan 5, 2023 via email

@arvedes
Copy link
Member Author

arvedes commented Jan 5, 2023

Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants