Skip to content

Commit

Permalink
Merge branch 'feat/adding-opened-attribute-to-xpl-and-small-fixes' in…
Browse files Browse the repository at this point in the history
…to ci/testing-improvements
  • Loading branch information
germa89 committed Feb 10, 2025
2 parents 1dd9eee + 9b7ce9f commit b63f8f8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3730.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: ram units
1 change: 1 addition & 0 deletions doc/changelog.d/3731.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: adding opened attribute
6 changes: 3 additions & 3 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def generate_mapdl_launch_command(
cpu_sw = "-np %d" % nproc

if ram:
ram_sw = "-m %d" % int(1024 * ram)
LOG.debug(f"Setting RAM: {ram_sw}")
ram_sw = "-m %d" % int(ram)
LOG.debug(f"Setting RAM: {ram_sw} MB")
else:
ram_sw = ""

Expand Down Expand Up @@ -1990,7 +1990,7 @@ def get_value(
ram = SLURM_MEM_PER_NODE

if not units:
args["ram"] = int(ram)
args["ram"] = int(ram) # Assuming in MB
elif units == "T": # tera
args["ram"] = int(ram) * (2**10) ** 2
elif units == "G": # giga
Expand Down
12 changes: 11 additions & 1 deletion src/ansys/mapdl/core/xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def close(self):
"""
response = self._mapdl.run("*XPL,CLOSE")
self._check_ignored(response)
self._filename = None
self._open = False
return response

Expand Down Expand Up @@ -373,6 +374,8 @@ def save(self):
"""Save the current file, ignoring the marked records."""
response = self._mapdl.run("*XPL,SAVE").strip()
self._check_ignored(response)
self._open = False
self._filename = None
return response

def extract(self, recordname, sets="ALL", asarray=False):
Expand Down Expand Up @@ -550,8 +553,15 @@ def write(self, recordname, vecname):
def __repr__(self):
txt = "MAPDL File Explorer\n"
if self._open:
txt += "\tOpen file:%s" % self._filename
txt += f"\tOpen file : {self._filename}"
txt += "\n".join(self.where().splitlines()[1:])
else:
txt += "\tNo open file"
return txt

@property
def opened(self):
if self._open:
return self._filename
else:
return None
12 changes: 6 additions & 6 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ def test_generate_mapdl_launch_command_windows():
jobname = "myjob"
nproc = 10
port = 1000
ram = 2
ram = 2024
additional_switches = "-my_add=switch"

cmd = generate_mapdl_launch_command(
Expand All @@ -1022,7 +1022,7 @@ def test_generate_mapdl_launch_command_windows():
assert "-port" in cmd
assert f"{port}" in cmd
assert "-m" in cmd
assert f"{ram*1024}" in cmd
assert f"{ram}" in cmd
assert "-np" in cmd
assert f"{nproc}" in cmd
assert "-grpc" in cmd
Expand All @@ -1037,7 +1037,7 @@ def test_generate_mapdl_launch_command_windows():
assert f"{exec_file}" in cmd
assert f" -j {jobname} " in cmd
assert f" -port {port} " in cmd
assert f" -m {ram*1024} " in cmd
assert f" -m {ram} " in cmd
assert f" -np {nproc} " in cmd
assert " -grpc" in cmd
assert f" {additional_switches} " in cmd
Expand All @@ -1053,7 +1053,7 @@ def test_generate_mapdl_launch_command_linux():
jobname = "myjob"
nproc = 10
port = 1000
ram = 2
ram = 2024
additional_switches = "-my_add=switch"

cmd = generate_mapdl_launch_command(
Expand All @@ -1075,7 +1075,7 @@ def test_generate_mapdl_launch_command_linux():
assert "-port" in cmd
assert f"{port}" in cmd
assert "-m" in cmd
assert f"{ram*1024}" in cmd
assert f"{ram}" in cmd
assert "-np" in cmd
assert f"{nproc}" in cmd
assert "-grpc" in cmd
Expand All @@ -1091,7 +1091,7 @@ def test_generate_mapdl_launch_command_linux():
assert f"{exec_file} " in cmd
assert f" -j {jobname} " in cmd
assert f" -port {port} " in cmd
assert f" -m {ram*1024} " in cmd
assert f" -m {ram} " in cmd
assert f" -np {nproc} " in cmd
assert " -grpc" in cmd
assert f" {additional_switches} " in cmd
Expand Down
15 changes: 12 additions & 3 deletions tests/test_xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ def xpl(self, mapdl, cube_solve):
self.create_cube(mapdl)

xpl.open(self.full_file)

yield xpl
xpl.close()

@staticmethod
def test_close(xpl):
if xpl.opened:
xpl.close()

def test_close(self, xpl):
xpl.close()
with pytest.raises(MapdlCommandIgnoredError):
xpl.list()
Expand Down Expand Up @@ -197,3 +199,10 @@ def test_extract(self, xpl):

mat = xpl.extract("NSL")
assert mat.shape == (243, 10)

def test_opened(self, xpl):
assert xpl.opened
xpl.close()
assert not xpl.opened
xpl.open(self.full_file)
assert xpl.opened

0 comments on commit b63f8f8

Please sign in to comment.