Skip to content

Commit

Permalink
Fixing no saving on exit (#2342)
Browse files Browse the repository at this point in the history
Fixing no saving on exit on MAPDL v24.2
  • Loading branch information
germa89 authored Sep 19, 2023
1 parent a184dd9 commit 7eaa2b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def __init__(
self._stdout = None
self._file_type_for_plots = file_type_for_plots
self._default_file_type_for_plots = file_type_for_plots
self._version = None # cached version

if _HAS_PYVISTA:
if use_vtk is not None: # pragma: no cover
Expand All @@ -251,7 +252,6 @@ def __init__(
self._use_vtk = False

self._log_filehandler = None
self._version = None # cached version
self._local: bool = local
self._cleanup: bool = True
self._vget_arr_counter = 0
Expand Down Expand Up @@ -3581,7 +3581,9 @@ def version(self) -> float:
>>> mapdl.version
20.2
"""
return self.parameters.revision
if not self._version:
self._version = self.parameters.revision
return self._version

@property
@supress_logging
Expand Down
8 changes: 7 additions & 1 deletion src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ def _run_at_connect(self):
self.numvar(200, mute=True)

self.show(self._file_type_for_plots)
self.version # Caching version

def _reset_cache(self):
"""Reset cached items."""
Expand Down Expand Up @@ -1115,7 +1116,12 @@ def _kill_server(self):
"""
self._log.debug("Killing MAPDL server")
self._ctrl("EXIT")
if (
self._version >= 24.2
): # We can't use the non-cached version because of recursion error.
self.run("/EXIT,NOSAVE,,,,,SERVER")
else:
self._ctrl("EXIT")

def _kill_process(self):
"""Kill process stored in self._mapdl_process"""
Expand Down
16 changes: 11 additions & 5 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,24 +1949,30 @@ def test_save_on_exit(mapdl, cleared):
mapdl2 = launch_mapdl(
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
)
mapdl2.parameters["my_par"] = "asdf"
mapdl2.parameters["my_par"] = "initial_value"

db_name = mapdl2.jobname + ".db"
db_dir = mapdl2.directory
db_path = os.path.join(db_dir, db_name)

mapdl2.save(db_name)
assert os.path.exists(db_path)

mapdl2.parameters["my_par"] = "qwerty"
mapdl2.parameters["my_par"] = "final_value"
mapdl2.exit()

mapdl2 = launch_mapdl(
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
)
mapdl2.resume(db_path)
assert mapdl2.parameters["my_par"] == "qwerty"
if mapdl.version >= 24.1:
assert mapdl2.parameters["my_par"] == "initial_value"
else:
# This fails in earlier versions of MAPDL
assert mapdl2.parameters["my_par"] != "initial_value"
assert mapdl2.parameters["my_par"] == "final_value"

mapdl2.parameters["my_par"] = "zxcv"
mapdl2.parameters["my_par"] = "new_initial_value"
db_name = mapdl2.jobname + ".db" # reupdating db path
db_dir = mapdl2.directory
db_path = os.path.join(db_dir, db_name)
Expand All @@ -1976,7 +1982,7 @@ def test_save_on_exit(mapdl, cleared):
license_server_check=False, additional_switches=QUICK_LAUNCH_SWITCHES
)
mapdl2.resume(db_path)
assert mapdl2.parameters["my_par"] == "zxcv"
assert mapdl2.parameters["my_par"] == "new_initial_value"
mapdl2.exit()


Expand Down

0 comments on commit 7eaa2b2

Please sign in to comment.