ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
419 stars 116 forks source link

launch_mapdl.save(fname) and launch_mapdl.resume(fname) strips white spaces from the path string #3192

Closed kp3393 closed 1 week ago

kp3393 commented 1 week ago

🤓 Before submitting the issue

🔍 Description of the bug

Saving (launch_mapdl.save(fname)) the database information as a .db file to a path with white spaces does not save the file in the directory. Similarly, resuming (launch_mapdl.resume(fname)) a .db file from a path with white spaces gives an error "Data file does not exist for RESUME".

🕵️ Steps To Reproduce

# import relevant libraries
from ansys.mapdl.core import launch_mapdl
import os

mapdl = launch_mapdl()
mapdl.clear()
mapdl.prep7()

'Part 1: To replicate the issue with save() method'
# create a dummy geometry to save as db file
mapdl.et(1, 70)
mapdl.block(0, 1, 0, 1, 0, 10)
mapdl.esize(1)
mapdl.vsweep('all')

# assign a path with space in it
dir = r'C:\Users\test folder with space'
db_fname = os.path.join(dir, 'test')

mapdl.save(db_fname, ext='db')

'Part 2: To replicate the issue with resume() method. Assume a previously saved .db file in the dir folder'
mapdl.resume(db_fname, ext='db')
mapdl.exit()

💻 Which Operating System are you using?

Windows

🐍 Which Python version are you using?

3.11

💾 Which MAPDL version are you using?

2023R2

📝 PyMAPDL Report

Show the Report! ```text PyMAPDL Software and Environment Report Packages Requirements ********************* Core packages ------------- ansys.mapdl.core : 0.68.2 numpy : 1.26.4 platformdirs : 4.2.2 scipy : 1.13.1 grpc : Package not found ansys.api.mapdl.v0 : Package not found ansys.mapdl.reader : 0.53.0 google.protobuf : Package not found Optional packages ----------------- matplotlib : 3.9.0 pyvista : 0.43.10 pyiges : 0.3.1 tqdm : 4.66.4 Ansys Installation ****************** Version Location ------------------ 232 C:\Program Files\ANSYS Inc\ANSYS Student\v232 Ansys Environment Variables *************************** ANSYS232_DIR C:\Program Files\ANSYS Inc\ANSYS Student\v232\ANSYS AWP_LOCALE232 en-us AWP_ROOT232 C:\Program Files\ANSYS Inc\ANSYS Student\v232 CADOE_LIBDIR232 C:\Program Files\ANSYS Inc\ANSYS Student\v232\CommonFiles\Language\en-us ```

📝 Installed packages

Show the installed packages! ```text ansys-api-mapdl==0.5.1 ansys-api-platform-instancemanagement==1.1.0 ansys-mapdl-core==0.68.2 ansys-mapdl-reader==0.53.0 ansys-math-core==0.1.5 ansys-platform-instancemanagement==1.1.2 ansys-tools-path==0.6.0 appdirs==1.4.4 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 contourpy==1.2.1 cycler==0.12.1 fonttools==4.53.0 geomdl==5.3.1 grpcio==1.64.1 idna==3.7 importlib_metadata==7.1.0 kiwisolver==1.4.5 matplotlib==3.9.0 mpmath==1.3.0 numpy==1.26.4 packaging==24.1 pillow==10.3.0 platformdirs==4.2.2 pooch==1.8.2 protobuf==3.20.3 psutil==6.0.0 pyansys-tools-versioning==0.5.0 pyiges==0.3.1 pyparsing==3.1.2 python-dateutil==2.9.0.post0 pyvista==0.43.10 requests==2.32.3 SciencePlots==2.1.1 scipy==1.13.1 scooby==0.10.0 six==1.16.0 sympy==1.12 tabulate==0.9.0 tqdm==4.66.4 urllib3==2.2.2 vtk==9.3.0 zipp==3.19.2 ```

📝 Logger output file

Show the logger output file. ```text # PASTE HERE THE CONTENT OF THE LOGGER OUTPUT FILE. ```
kp3393 commented 1 week ago

The issue is similar to #1601, and the workaround discussed solves the problem. However, fixing this bug would be very helpful :).

mikerife commented 1 week ago

Hi @kp3393 This is not a bug - it is expected MAPDL behavior. In MAPDL file and path names can have blank spaces; but if they do then the name needs to be enclosed in single quotes.

You can just add the quotes manually:

# assign a path with space in it
dir = r'C:\Users\test folder with space'
db_fname = os.path.join(dir, 'test')
db_fname = "'" + db_fname + "'"

Mike

kp3393 commented 1 week ago

Hi @mikerife, Thank you for the reply. The solution that was suggested works.