diff --git a/doc/changelog.d/3590.miscellaneous.md b/doc/changelog.d/3590.miscellaneous.md new file mode 100644 index 0000000000..913c469727 --- /dev/null +++ b/doc/changelog.d/3590.miscellaneous.md @@ -0,0 +1 @@ +feat: improving load_array to reduce format line length \ No newline at end of file diff --git a/src/ansys/mapdl/core/mapdl_extended.py b/src/ansys/mapdl/core/mapdl_extended.py index 94f2808fd4..a12ba23392 100644 --- a/src/ansys/mapdl/core/mapdl_extended.py +++ b/src/ansys/mapdl/core/mapdl_extended.py @@ -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", ) @@ -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) diff --git a/tests/test_parameters.py b/tests/test_parameters.py index fa6cda4de6..417c6389cd 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -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):