Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding opened attribute #3731

Merged
merged 8 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 18 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,22 @@ 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):
"""
Check if a file is currently open.

Returns:
str or None: The filename if a file is open, otherwise None.
"""

if self._open:
return self._filename
else:
return None
25 changes: 20 additions & 5 deletions tests/test_xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def create_cube(self, mapdl):
from conftest import clear

clear(mapdl)
mapdl.clear()
mapdl.prep7()

# set up the full file
mapdl.block(0, 1, 0, 1, 0, 1)
Expand All @@ -70,9 +72,12 @@ def create_cube(self, mapdl):
if mapdl.result_file in mapdl.list_files():
mapdl.slashdelete(mapdl.result_file)

if "cube_solve_xpl" in mapdl.list_files():
mapdl.slashdelete("cube_solve_xpl.db")

# solve first 10 non-trivial modes
mapdl.modal_analysis(nmode=10, freqb=1)
mapdl.save("cube_solve_xpl")
mapdl.save("cube_solve_xpl", "db")

@pytest.fixture(scope="class")
def cube_solve(self, mapdl):
Expand All @@ -81,17 +86,20 @@ def cube_solve(self, mapdl):
@pytest.fixture(scope="function")
def xpl(self, mapdl, cube_solve):
mapdl.prep7()
mapdl.resume("cube_solve_xpl")
mapdl.resume("cube_solve_xpl", "db")

xpl = mapdl.xpl
if not self.full_file and not self.full_file in mapdl.list_files():
self.create_cube(mapdl)

xpl.open(self.full_file)
return xpl

@staticmethod
def test_close(xpl):
yield xpl

if xpl.opened:
xpl.close()

def test_close(self, xpl):
xpl.close()
with pytest.raises(MapdlCommandIgnoredError):
xpl.list()
Expand Down Expand Up @@ -198,3 +206,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