Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improving load_array to reduce format line length #3590

Merged
merged 3 commits into from
Nov 29, 2024
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
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
Loading