Skip to content
Snippets Groups Projects
Commit e04db3f9 authored by Patrick Shriwise's avatar Patrick Shriwise
Browse files

Adding a function to perform mesh generation only. Adding ability to combine...

Adding a function to perform mesh generation only. Adding ability to combine input filles in the PyGriffin.run method.
parent 2ee02968
No related branches found
No related tags found
No related merge requests found
from numbers import Integral
from pathlib import Path
import subprocess
from tkinter import E
from typing import Iterable
import warnings
......@@ -22,9 +23,10 @@ class PyGriffin:
def __init__(self, input, mesh=None, n_procs=1):
self.config = PyGriffinConfig()
self.input = input
self.mesh = mesh
self.n_procs = n_procs
def run(self, cwd=None, other_args=None):
def run(self, input=None, mesh=None, cwd=None, other_args=None):
"""
Execute Griffin
......@@ -41,6 +43,10 @@ class PyGriffin:
cmd = []
# set custom values if requested in method call
input_file = self.input if input is None else input
mesh_file = self.mesh if mesh is None else mesh
if self.n_procs > 1:
if self.config.mpi_enabled:
cmd += ['mpirun', '-n', str(self.n_procs)]
......@@ -52,7 +58,11 @@ class PyGriffin:
# add griffin executable to command line
cmd.append(str(self.config.griffin_exec))
cmd += ['-i', str(self.input)]
cmd += ['-i', str(input_file)]
# append the mesh file to the command if needed
if str(mesh_file).endswith('.i'):
cmd.append(str(mesh_file))
if cwd is not None:
cwd = Path(cwd)
......@@ -72,6 +82,31 @@ class PyGriffin:
return p.wait()
def generate_mesh(self, overwrite=False):
"""
Generates the mesh for the griffin-problem if needed
Parameters
----------
overwrite : bool
Overwrie the current mesh if needed (default False)
Returns
-------
Path to the mesh file
"""
# if a mesh file was passed, no need to generate a new one
if str(self.mesh).endswith('.e'):
return self.mesh
# if a mesh input is set, generate the mesh file
if str(self.mesh).endswith('.i'):
name_parts = str(self.mesh).split('.')
name_parts[-1] = 'e'
mesh_name = '.'.join(name_parts)
self.run(input=self.mesh, other_args=['--mesh-only', mesh_name])
return Path(mesh_name).resolve().absolute()
def __call__(self, cwd=None):
return self.run(cwd)
......@@ -91,6 +126,7 @@ class PyGriffin:
@mesh.setter
def mesh(self, mesh):
cv.check_type('Griffin mesh', mesh, (str, Path))
self._mesh = mesh
@property
def xs(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment