Skip to content

Commit a72c9c0

Browse files
committed
Merge branch 'main' into release/0.69
2 parents cbf0ddb + a7d4359 commit a72c9c0

File tree

10 files changed

+148
-22
lines changed

10 files changed

+148
-22
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ jobs:
151151
python-package-name: ${{ env.PACKAGE_NAME }}
152152
dev-mode: ${{ github.ref != 'refs/heads/main' }}
153153
upload-reports: True
154+
hide-log: false
155+
154156

155157
docs-build:
156158
name: "Build documentation"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: node/element selection commands returning selected ids

doc/changelog.d/3641.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chore: update CHANGELOG for v0.69.0

doc/changelog.d/3642.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: timeout for file checking

src/ansys/mapdl/core/commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
"LSEL",
194194
"ASEL",
195195
"VSEL",
196+
"ESLN",
197+
"NSLE",
196198
]
197199

198200

src/ansys/mapdl/core/mapdl_core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,10 @@ def wrap_xsel_function_output(method):
13211321
return self.geometry.anum
13221322
elif name == "VSEL":
13231323
return self.geometry.vnum
1324+
elif name == "ESLN":
1325+
return self.mesh.enum
1326+
elif name == "NSLE":
1327+
return self.mesh.nnum
13241328
else:
13251329
return None
13261330

@@ -2915,6 +2919,7 @@ def _check_mapdl_os(self):
29152919
self._platform = "windows"
29162920
else: # pragma: no cover
29172921
raise MapdlRuntimeError("Unknown platform: {}".format(platform))
2922+
self.logger.debug(f"MAPDL is running on {self._platform} OS.")
29182923

29192924
def _check_on_docker(self):
29202925
"""Check if MAPDL is running on docker."""

src/ansys/mapdl/core/mapdl_grpc.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119

120120
SESSION_ID_NAME = "__PYMAPDL_SESSION_ID__"
121121

122+
DEFAULT_TIME_STEP_STREAM = None
123+
DEFAULT_TIME_STEP_STREAM_NT = 500
124+
DEFAULT_TIME_STEP_STREAM_POSIX = 100
125+
122126
# Retry policy for gRPC calls.
123127
SERVICE_DEFAULT_CONFIG = {
124128
# see https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy-capabilities
@@ -1069,7 +1073,8 @@ def _send_command(self, cmd: str, mute: bool = False) -> Optional[str]:
10691073
def _send_command_stream(self, cmd, verbose=False) -> str:
10701074
"""Send a command and expect a streaming response"""
10711075
request = pb_types.CmdRequest(command=cmd)
1072-
metadata = [("time_step_stream", "100")]
1076+
time_step = self._get_time_step_stream()
1077+
metadata = [("time_step_stream", str(time_step))]
10731078
stream = self._stub.SendCommandS(request, metadata=metadata)
10741079
response = []
10751080
for item in stream:
@@ -1775,13 +1780,14 @@ def input(
17751780
execution time.
17761781
17771782
Due to stability issues, the default time_step_stream is
1778-
dependent on verbosity. The defaults are:
1783+
dependent on the OS MAPDL is running on. The defaults are:
17791784
1780-
- ``verbose=True``: ``time_step_stream=500``
1781-
- ``verbose=False``: ``time_step_stream=50``
1785+
- Windows: ``time_step_stream=500``
1786+
- Linux: ``time_step_stream=100``
17821787
17831788
These defaults will be ignored if ``time_step_stream`` is
1784-
manually set.
1789+
manually set. See the *Examples* section to learn how to change
1790+
the default value globally.
17851791
17861792
orig_cmd : str, optional
17871793
Original command. There are some cases, were input is
@@ -1831,6 +1837,11 @@ def input(
18311837
>>> with mapdl.non_interactive:
18321838
mapdl.run("/input,inputtrigger,inp") # This inputs 'myinput.inp'
18331839
1840+
You can also change them globably using:
1841+
1842+
>>> from ansys.mapdl.core import mapdl_grpc
1843+
>>> mapdl_grpc.DEFAULT_TIME_STEP_STREAM=100 # in milliseconds
1844+
18341845
"""
18351846
# Checking compatibility
18361847
# Checking the user is not reusing old api:
@@ -1911,18 +1922,14 @@ def input(
19111922
# are unclear
19121923
filename = self._get_file_path(fname, progress_bar)
19131924

1914-
if time_step_stream is not None:
1915-
if time_step_stream <= 0:
1916-
raise ValueError("``time_step_stream`` must be greater than 0``")
1925+
time_step_stream = self._get_time_step_stream(time_step_stream)
19171926

1918-
if verbose:
1919-
if time_step_stream is None:
1920-
time_step_stream = 500
1921-
metadata = [
1922-
("time_step_stream", str(time_step_stream)),
1923-
("chunk_size", str(chunk_size)),
1924-
]
1927+
metadata = [
1928+
("time_step_stream", str(time_step_stream)),
1929+
("chunk_size", str(chunk_size)),
1930+
]
19251931

1932+
if verbose:
19261933
request = pb_types.InputFileRequest(filename=filename)
19271934
strouts = self._stub.InputFileS(request, metadata=metadata)
19281935
responses = []
@@ -1934,13 +1941,8 @@ def input(
19341941
response = "\n".join(responses)
19351942
return response.strip()
19361943

1937-
# otherwise, not verbose
1938-
if time_step_stream is None:
1939-
time_step_stream = 50
1940-
metadata = [
1941-
("time_step_stream", str(time_step_stream)),
1942-
("chunk_size", str(chunk_size)),
1943-
]
1944+
##
1945+
# Otherwise, not verbose
19441946

19451947
# since we can't directly run /INPUT, we have to write a
19461948
# temporary input file that tells MAPDL to read the input
@@ -2014,6 +2016,31 @@ def input(
20142016

20152017
return output
20162018

2019+
def _get_time_step_stream(
2020+
self, time_step: Optional[Union[int, float]] = None
2021+
) -> str:
2022+
"""Return the time step for checking if MAPDL is done writing the
2023+
output to the file which later will be returned as response
2024+
"""
2025+
if time_step is None:
2026+
if DEFAULT_TIME_STEP_STREAM is not None:
2027+
time_step = DEFAULT_TIME_STEP_STREAM
2028+
elif self.platform == "windows":
2029+
time_step = DEFAULT_TIME_STEP_STREAM_NT
2030+
elif self.platform == "linux":
2031+
time_step = DEFAULT_TIME_STEP_STREAM_POSIX
2032+
else:
2033+
raise ValueError(
2034+
f"The MAPDL platform ('{self.platform}') is not recognaised."
2035+
)
2036+
2037+
else:
2038+
if time_step <= 0:
2039+
raise ValueError("``time_step`` argument must be greater than 0``")
2040+
2041+
self.logger.debug(f"The time_step argument is set to: {time_step}")
2042+
return time_step
2043+
20172044
def _get_file_path(self, fname: str, progress_bar: bool = False) -> str:
20182045
"""Find files in the Python and MAPDL working directories.
20192046

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,24 @@ def create_geometry(mapdl):
11571157
return areas, keypoints
11581158

11591159

1160+
@pytest.fixture(scope="function")
1161+
def two_dimensional_mesh(mapdl, cleared):
1162+
length = 4
1163+
height = 1
1164+
thickness = 0.2
1165+
mesh_size = 0.1
1166+
1167+
mapdl.prep7()
1168+
1169+
mapdl.r(r1=thickness)
1170+
mapdl.et(1, "PLANE182", kop3=3, kop6=0)
1171+
mapdl.rectng(0, length, 0, height)
1172+
mapdl.mshkey(1)
1173+
mapdl.mshape(0, "2D")
1174+
mapdl.esize(mesh_size)
1175+
mapdl.amesh("ALL")
1176+
1177+
11601178
@pytest.fixture
11611179
def query(mapdl, cleared):
11621180
return mapdl.queries

tests/test_grpc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import re
2626
import shutil
2727
import sys
28+
from unittest.mock import patch
2829

2930
import grpc
3031
import pytest
@@ -682,3 +683,32 @@ def _null_close_process():
682683
mapdl.prep7(mapdl)
683684

684685
mapdl._exited = False # Restoring
686+
687+
688+
@pytest.mark.parametrize("platform", ["linux", "windows", "error"])
689+
def test__get_time_step_stream(mapdl, platform):
690+
with patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.platform", platform):
691+
from ansys.mapdl.core import mapdl_grpc
692+
693+
if platform == "linux":
694+
DEFAULT_TIME_STEP_STREAM = mapdl_grpc.DEFAULT_TIME_STEP_STREAM_POSIX
695+
elif platform == "windows":
696+
DEFAULT_TIME_STEP_STREAM = mapdl_grpc.DEFAULT_TIME_STEP_STREAM_NT
697+
else:
698+
with pytest.raises(ValueError, match="The MAPDL platform"):
699+
mapdl._get_time_step_stream()
700+
701+
return # Early exit
702+
703+
assert DEFAULT_TIME_STEP_STREAM == mapdl._get_time_step_stream()
704+
705+
mapdl_grpc.DEFAULT_TIME_STEP_STREAM = 200
706+
assert mapdl_grpc.DEFAULT_TIME_STEP_STREAM == mapdl._get_time_step_stream()
707+
mapdl_grpc.DEFAULT_TIME_STEP_STREAM = None
708+
709+
assert 700 == mapdl._get_time_step_stream(700)
710+
711+
with pytest.raises(
712+
ValueError, match="``time_step`` argument must be greater than 0``"
713+
):
714+
mapdl._get_time_step_stream(-700)

tests/test_mesh_grpc.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,42 @@ def test_nodal_rotation(mapdl, cleared):
317317
]
318318
)
319319
assert np.allclose(nrotation_ref, nrotations[:7, :])
320+
321+
322+
def test_esln(mapdl, two_dimensional_mesh):
323+
mapdl.nsel("S", "LOC", "X", 0)
324+
selected_ids = mapdl.esln("S", 0)
325+
expected_selected_ids = np.array([1, 41, 81, 121, 161, 201, 241, 281, 321, 361])
326+
assert all(selected_ids == expected_selected_ids)
327+
328+
329+
def test_nsle(mapdl, two_dimensional_mesh):
330+
mapdl.esel("S", "CENT", "X", 0, 0.1)
331+
selected_ids = mapdl.nsle("S")
332+
expected_selected_ids = np.array(
333+
[
334+
1,
335+
3,
336+
52,
337+
91,
338+
92,
339+
93,
340+
94,
341+
95,
342+
96,
343+
97,
344+
98,
345+
99,
346+
100,
347+
101,
348+
102,
349+
103,
350+
104,
351+
105,
352+
106,
353+
107,
354+
108,
355+
109,
356+
]
357+
)
358+
assert all(selected_ids == expected_selected_ids)

0 commit comments

Comments
 (0)