Skip to content

Commit

Permalink
more efficient types
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jun 5, 2024
1 parent eeb6f68 commit 606eb7a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ exclude = '''
files = ["src", "scripts"]

ignore_missing_imports = true
allow_redefinition = true
show_error_context = false
show_column_numbers = true

[tool.pytest.ini_options]
log_cli = true
Expand Down
11 changes: 5 additions & 6 deletions src/gemini3d/grid/uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def non_uniform1d(xmax: float, parms: list[float]):
ell = parms[3] # transition length of degradation
x2 = xmax - degdist

x = [dx0 / 2.0]
x = np.array([dx0 / 2.0])
# start offset from zero so we can have an even number (better for mpi)

while x[-1] < xmax:
dx = dx0 + dxincr * (1 / 2 + 1 / 2 * math.tanh((x[-1] - x2) / ell))
x.append(x[-1] + dx)
x = np.append(x, x[-1] + dx)

x = np.append(-np.array(x[::-1]), x)
x = np.append(-x[::-1], x)

return x

Expand All @@ -78,14 +78,13 @@ def altitude_grid(
if alt_max <= alt_min:
raise ValueError("grid_max must be greater than grid_min")

alt = [alt_min]
alt = np.array([alt_min])

while alt[-1] < alt_max:
# dalt=10+9.5*tanh((alt(i-1)-500)/150)
dalt = d[0] + d[1] * math.tanh((alt[-1] - d[2]) / d[3])
alt.append(alt[-1] + dalt)
alt = np.append(alt, alt[-1] + dalt)

alt = np.asarray(alt)
if alt.size < 10:
raise ValueError("grid too small")

Expand Down
10 changes: 5 additions & 5 deletions src/gemini3d/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ def check_compiler():
raise EnvironmentError("Cannot find Fortran compiler e.g. Gfortran")


def check_mpiexec(mpiexec: str, gemexe: Path) -> str:
def check_mpiexec(mpiexec_name: str, gemexe: Path) -> str:
"""
check if specified mpiexec exists on this system.
If not, error as most runs are exceedingly slow with one CPU core.
"""

if not mpiexec:
mpiexec = "mpiexec"
if not mpiexec_name:
mpiexec_name = "mpiexec"

mpi_root = os.environ.get("MPI_ROOT", None)
if mpi_root:
mpi_root += "/bin"

mpiexec = shutil.which(mpiexec, path=mpi_root)
mpiexec = shutil.which(mpiexec_name, path=mpi_root)
if not mpiexec:
raise FileNotFoundError(f"Cannot find mpiexec {mpiexec}")
raise FileNotFoundError(f"Cannot find mpiexec {mpiexec_name}")

ret = subprocess.run([mpiexec, "-help"], capture_output=True, text=True, timeout=5)
if ret.returncode != 0:
Expand Down
4 changes: 2 additions & 2 deletions src/gemini3d/magcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ def magcalc(
nargs="?",
default=1.5,
)
P = P.parse_args()
args = P.parse_args()

magcalc(P.direc, P.dang)
magcalc(args.direc, args.dang)
4 changes: 2 additions & 2 deletions src/gemini3d/magtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def makegrid(
direc: str,
direc: Path,
dang: float = 1.5,
ltheta: int = 16,
lphi: int = 16,
Expand Down Expand Up @@ -89,7 +89,7 @@ def makegrid(


def makegrid_full(
direc: str,
direc: Path,
ltheta: int = 16,
lphi: int = 16,
write_grid: bool = False,
Expand Down
9 changes: 7 additions & 2 deletions src/gemini3d/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import typing as T

import numpy as np
import xarray

from .config import read_nml
from . import find
Expand Down Expand Up @@ -76,7 +75,7 @@ def frame(
*,
cfg: dict[str, T.Any] | None = None,
xg: dict[str, T.Any] | None = None,
) -> xarray.Dataset:
):
"""
load a frame of simulation data, automatically selecting the correct
functions based on simulation parameters
Expand All @@ -93,6 +92,12 @@ def frame(
to avoid reading config.nml
xg: dict
to avoid reading simgrid.*, useful to save time when reading data files in a loop
Returns
-------
dat: xarray.Dataset
simulation data from this time
"""

# %% default variables
Expand Down

0 comments on commit 606eb7a

Please sign in to comment.