Skip to content

Commit

Permalink
packages namelist
Browse files Browse the repository at this point in the history
  • Loading branch information
pgierz committed Jul 18, 2024
1 parent 8a987b7 commit c3e01bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Empty file added metis_wizard/__init__.py
Empty file.
17 changes: 11 additions & 6 deletions metis_wizard.py → metis_wizard/metis_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
scales to approximately 300 cores. See the notes in the ``fesom`` documentation <https://readthedocs.org/fesom/> for more information.
"""

import importlib.resources as pkg_resources
import pathlib
import shutil
import subprocess
Expand Down Expand Up @@ -85,7 +86,6 @@ class MetisPartitioner:
"""

_BIN = "fesom_ini"
_NML = "namelist.config"

def __init__(self, bin: str = None) -> None:
"""
Expand All @@ -111,7 +111,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(self._NML, mesh, n_part)
nml = prepare_namelist(mesh, n_part)
# Write the namelist:
nml.write("namelist.config", force=True)
logger.info(f"Namelist written for {self.bin}.")
Expand All @@ -121,21 +121,26 @@ def partition_mesh(self, mesh: FesomMesh, n_part: int = 288) -> None:
logger.success(f"Mesh partitioned with {self.bin} for {n_part}.")


def prepare_namelist(nml_path: str or pathlib.Path, mesh: FesomMesh, n_part: int = 288):
def read_namelist_config():
with pkg_resources.open_text("metis_wizard", "namelist.config") as file:
data = file.read()
return data


def prepare_namelist(mesh: FesomMesh, n_part: int = 288):
"""
This function prepares the METIS namelist file for partitioning.
Parameters:
-----------
nml_path (str): The path to the namelist file.
n_part (int, optional): The number of partitions. Defaults to 288.
Returns:
--------
MetisNamelist object: The METIS namelist object.
"""
with open(nml_path, "r") as f:
nml = MetisNamelist(f90nml.read(f))
f = read_namelist_config()
nml = MetisNamelist(f90nml.reads(f))
nml.set_mesh(mesh.path)
nml.set_partitioning(n_part)
return nml
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ version = "1.0.0"
description = ""
authors = ["Paul Gierz <pgierz@awi.de>"]
readme = "README.md"
include = ["metis_wizard/namelist.config"]
packages = [
{ include = "metis_wizard", from = "." }
]


[tool.poetry.dependencies]
f90nml = "^1.4.4"
rich-click = "^1.8.3"
click-loguru = "^1.3.8"
questionary = "^2.0.1"

click = "^8.1.7"

[tool.poetry.scripts]
metis-wizard = "metis_wizard:main"

metis-wizard = "metis_wizard.metis_wizard:main"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
Expand Down

0 comments on commit c3e01bd

Please sign in to comment.