Skip to content

Commit

Permalink
feat: improving load_array to reduce format line length (#3590)
Browse files Browse the repository at this point in the history
* feat: reducing format lenght in load_array

* tests: improving tests

* chore: adding changelog file 3590.miscellaneous.md [dependabot-skip]

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Nov 29, 2024
1 parent 89bd649 commit 4a2a4f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3590.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: improving load_array to reduce format line length
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ def load_array(self, name, array):
np.savetxt(
filename,
array,
delimiter=",",
delimiter="",
header="File generated by PyMAPDL:load_array",
fmt="%24.18e",
)
Expand All @@ -2329,7 +2329,7 @@ def load_array(self, name, array):
n2 = imax
n3 = kmax
self.vread(name, filename, n1=n1, n2=n2, n3=n3, label=label, nskip=1)
fmt = "(" + ",',',".join(["E24.18" for i in range(jmax)]) + ")"
fmt = f"({jmax}E24.18)"
logger.info("Using *VREAD with format %s in %s", fmt, filename)
self.run(fmt)

Expand Down
19 changes: 14 additions & 5 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,20 @@ def test__get_parameter_array(mapdl, cleared, number):
assert np.allclose(array, mapdl.parameters._get_parameter_array(name, shape))

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

# Random number
array = np.random.rand(*shape)
mapdl.load_array(name=name, array=array)
assert np.allclose(array, mapdl.parameters._get_parameter_array(name, shape))

# Random big number
array = np.random.rand(*shape) * number
mapdl.load_array(name=name, array=array)
assert np.allclose(array, mapdl.parameters._get_parameter_array(name, shape))


def parameters_name(mapdl, func, par_name):
Expand Down

0 comments on commit 4a2a4f2

Please sign in to comment.