Skip to content

Commit

Permalink
feat: support for rotated meshes. Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pgierz committed Jul 22, 2024
1 parent 062fc4a commit f61ea52
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions metis_wizard/metis_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def __init__(self, bin: str = None) -> None:
except AssertionError:
raise MetisPartitionerError(f"{self.bin} not found on PATH.")

def partition_mesh(self, mesh: FesomMesh, n_part: int = 288) -> None:
def partition_mesh(
self, mesh: FesomMesh, n_part: int = 288, alpha=None, beta=None, gamma=None
) -> None:
"""
Partitions the mesh using METIS.
Expand All @@ -111,7 +113,7 @@ def partition_mesh(self, mesh: FesomMesh, n_part: int = 288) -> None:
n_part (int, optional): The number of partitions. Defaults to 288.
"""
# Create the namelist:
nml = prepare_namelist(mesh, n_part)
nml = prepare_namelist(mesh, n_part, alpha, beta, gamma)
# Write the namelist:
nml.write("namelist.config", force=True)
logger.info(f"Namelist written for {self.bin}.")
Expand All @@ -127,7 +129,9 @@ def read_namelist_config():
return data


def prepare_namelist(mesh: FesomMesh, n_part: int = 288):
def prepare_namelist(
mesh: FesomMesh, n_part: int = 288, alpha=None, beta=None, gamma=None
):
"""
This function prepares the METIS namelist file for partitioning.
Expand All @@ -143,6 +147,12 @@ def prepare_namelist(mesh: FesomMesh, n_part: int = 288):
nml = MetisNamelist(f90nml.reads(f))
nml.set_mesh(mesh.path)
nml.set_partitioning(n_part)
if alpha is not None:
nml["geometry"]["alphaeuler"] = alpha
if beta is not None:
nml["geometry"]["betaeuler"] = beta
if gamma is not None:
nml["geometry"]["gammaeuler"] = gamma
return nml


Expand All @@ -153,7 +163,25 @@ def prepare_namelist(mesh: FesomMesh, n_part: int = 288):
@click.argument("mesh_path", type=click.Path(exists=True))
@click.argument("n_part", nargs=-1)
@click.option("--interactive", is_flag=True, help="Interactive mode.")
def main(verbose, quiet, logfile, profile_mem, mesh_path, n_part, interactive=False):
@click.option(
"--rotated", nargs=3, type=float, help="Rotated mesh. Give alpha, beta, gamma."
)
def main(
verbose,
quiet,
logfile,
profile_mem,
mesh_path,
n_part,
interactive=False,
rotated=None,
):
if rotated is not None:
logger.info("Rotated mesh dected. Rotating mesh...")
alpha, beta, gamma = rotated
logger.info(f"Rotating mesh by alpha={alpha}, beta={beta}, gamma={gamma}")
else:
alpha, beta, gamma = None, None, None
if not n_part and interactive:
logger.info("Interactive mode enabled for selecting partitions:")
logger.info("Highlighted (filled in) partitions will be generated...")
Expand Down

0 comments on commit f61ea52

Please sign in to comment.