Skip to content
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
5 changes: 5 additions & 0 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,11 @@ def build_rand_tmp():
self._response = out[out.find("LINE= 0") + 13 :]
self._log.info(self._response)

if "*** ERROR ***" in self._response:
raise RuntimeError(
self._response.split("*** ERROR ***")[1].splitlines()[1].strip()
)

# try/except here because MAPDL might have not closed the temp file
try:
os.remove(tmp_filename)
Expand Down
24 changes: 19 additions & 5 deletions src/ansys/mapdl/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,26 @@ def _get_parameter_array(self, parm_name, shape):
array : np.ndarray
Numpy array.
"""
format_str = "(1F64.12)"
with self._mapdl.non_interactive:
self._mapdl.mwrite(parm_name.upper(), label="kji") # use C ordering
self._mapdl.run(format_str)
escaped = False
for each_format_number in [20, 30, 40, 64, 100]:
format_str = f"(1F{each_format_number}.12)"
with self._mapdl.non_interactive:
# use C ordering
self._mapdl.mwrite(parm_name.upper(), label="kji")
self._mapdl.run(format_str)

st = self._mapdl.last_response.rfind(format_str) + len(format_str) + 1

if "**" not in self._mapdl.last_response[st:]:
escaped = True
break

if not escaped: # pragma: no cover
raise RuntimeError(
f"The array '{parm_name}' has a number format "
"that could not be read using '{format_str}'."
)

st = self._mapdl.last_response.rfind(format_str) + len(format_str) + 1
arr_flat = np.fromstring(self._mapdl.last_response[st:], sep="\n").reshape(
shape
)
Expand Down
36 changes: 36 additions & 0 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import pytest


@pytest.mark.parametrize(
"number",
[
1e11,
1e21,
1e31,
1e41,
1e51,
pytest.param(1e61, marks=pytest.mark.xfail),
],
)
def test__get_parameter_array(mapdl, number):
name = "param_array"

# Testing 1D arrays
shape = (100,)
array = np.ones(shape) * number
mapdl.load_array(name=name, array=array)
assert np.allclose(array, mapdl.parameters._get_parameter_array(name, shape))

# Testing 2D arrays
shape = (100, 5)
array = np.ones(shape) * number
mapdl.load_array(name=name, array=array)
assert np.allclose(array, mapdl.parameters._get_parameter_array(name, shape))

# High number
with pytest.raises(RuntimeError):
shape = (100, 100)
array = np.ones(shape) * number
mapdl.load_array(name=name, array=array)
mapdl.parameters._get_parameter_array(name, shape)