Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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/4123.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix: update mpwrite and mpread methods to enforce 'lib' as the only valid lib argument
21 changes: 9 additions & 12 deletions src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
allow_iterables_vmin,
allow_pickable_entities,
check_deprecated_vtk_kwargs,
load_file,
random_string,
requires_graphics,
supress_logging,
Expand Down Expand Up @@ -345,7 +344,7 @@ def mpwrite(
self,
fname="",
ext="",
lib="",
lib="LIB",
mat="",
download_file=False,
progress_bar=False,
Expand All @@ -359,23 +358,21 @@ def mpwrite(
f"The supplied path {fname_} is not allowed."
)

output = super().mpwrite(fname, ext, lib, mat, **kwargs)
output = super().mpwrite(fname, ext, lib=lib, mat=mat, **kwargs)
if download_file:
self.download(os.path.basename(fname_), progress_bar=progress_bar)

return output

@wraps(_MapdlCore.mpread)
def mpread(self, fname="", ext="", lib="", **kwargs):
if lib:
raise NotImplementedError(
"The option 'lib' is not supported by the MAPDL gRPC server."
)
def mpread(self, fname="", ext="", lib="LIB", **kwargs):
if lib != "LIB":
raise MapdlRuntimeError("The 'lib' argument only supports the 'LIB' value.")

fname_ = fname + "." + ext
fname = load_file(self, fname_)
self._log.info("Bypassing 'MPREAD' with 'INPUT'.")
return self.input(fname)
fname = self._get_file_name(fname, ext, "mp")
fname = self._get_file_path(fname, kwargs.get("progress_bar", False))
file_, ext_, path_ = self._decompose_fname(fname)
return self.input(file_, ext_, **kwargs)

@wraps(_MapdlCore.cwd)
def cwd(self, *args, **kwargs):
Expand Down
51 changes: 44 additions & 7 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,14 +1492,17 @@ def test_mpfunctions(mapdl, cube_solve, capsys):
ext = "mp1"

mapdl.prep7()
mapdl.slashdelete(fname, ext) # remove file if it exists

assert f"WRITE OUT MATERIAL PROPERTY LIBRARY TO FILE=" in mapdl.mpwrite(fname, ext)
assert "WRITE OUT MATERIAL PROPERTY" in mapdl.mpwrite(fname, ext, mat=1)
assert f"{fname}.{ext}" in mapdl.list_files()

# asserting downloading
ext = "mp2"
assert f"WRITE OUT MATERIAL PROPERTY LIBRARY TO FILE=" in mapdl.mpwrite(
fname, ext, download_file=True
mapdl.slashdelete(fname, ext) # remove file if it exists

assert "WRITE OUT MATERIAL PROPERTY" in mapdl.mpwrite(
fname, ext, download_file=True, mat=1
)
assert f"{fname}.{ext}" in mapdl.list_files()
assert os.path.exists(f"{fname}.{ext}")
Expand All @@ -1512,6 +1515,8 @@ def test_mpfunctions(mapdl, cube_solve, capsys):
os.remove(f"{fname}.{ext}") # remove temp file

ext = ext + "2"
mapdl.slashdelete(fname, ext) # remove file if it exists

fname_ = f"{fname}.{ext}"
new_nuxy = "MPDATA,NUXY, 1, 1, 0.4000000E+00,"
nuxy = float(new_nuxy.split(",")[4])
Expand Down Expand Up @@ -1561,15 +1566,47 @@ def test_mpfunctions(mapdl, cube_solve, capsys):
with pytest.raises(FileNotFoundError):
mapdl.mpread(fname="dummy", ext="dummy")

# Test not implemented error
with pytest.raises(NotImplementedError):
mapdl.mpread(fname="dummy", ext="dummy", lib="something")

# Test suppliying a dir path when in remote
if not ON_LOCAL:
with pytest.raises(IOError):
mapdl.mpwrite("/test_dir/test", "mp")

mapdl.slashdelete(fname, ext) # remove file if it exists


def test_mpread_lib(mapdl):
mapdl.input_strings(
"""
/prep7
/units,si
TB,BH ,_MATL , 1, 20
TBTEM, 0.00000000 , 1
TBPT,, 59.5238095 , 0.200000000
TBPT,, 119.047619 , 0.400000000
TBPT,, 158.730159 , 0.550000000
TBPT,, 396.825397 , 1.15000000
TBPT,, 555.555556 , 1.30000000
TBPT,, 793.650794 , 1.40000000
TBPT,, 1587.30159 , 1.55000000
TBPT,, 3968.25397 , 1.63500000
TBPT,, 7936.50794 , 1.65500000
TBPT,, 15873.0159 , 1.67500000
TBPT,, 31746.0317 , 1.70138960
TBPT,, 63492.0635 , 1.75000000
TBPT,, 95238.0952 , 1.79000000
TBPT,, 190476.190 , 1.90980000
TBPT,, 285714.286 , 2.02960000
TBPT,, 380952.381 , 2.14950000
"""
)
mapdl.slashdelete("database", "mp")
mapdl.mpwrite("database", "mp", mat=1)
mapdl.clear()
mapdl.prep7()
mapdl.mpread("database", "mp")
mapdl.mplist()
assert mapdl.get_value("MAT", 0, "count") == 1.0


def test_mapdl_str(mapdl, cleared):
out = str(mapdl)
Expand Down
Loading