119
119
120
120
SESSION_ID_NAME = "__PYMAPDL_SESSION_ID__"
121
121
122
+ DEFAULT_TIME_STEP_STREAM = None
123
+ DEFAULT_TIME_STEP_STREAM_NT = 500
124
+ DEFAULT_TIME_STEP_STREAM_POSIX = 100
125
+
122
126
# Retry policy for gRPC calls.
123
127
SERVICE_DEFAULT_CONFIG = {
124
128
# 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]:
1069
1073
def _send_command_stream (self , cmd , verbose = False ) -> str :
1070
1074
"""Send a command and expect a streaming response"""
1071
1075
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 ))]
1073
1078
stream = self ._stub .SendCommandS (request , metadata = metadata )
1074
1079
response = []
1075
1080
for item in stream :
@@ -1775,13 +1780,14 @@ def input(
1775
1780
execution time.
1776
1781
1777
1782
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:
1779
1784
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 ``
1782
1787
1783
1788
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.
1785
1791
1786
1792
orig_cmd : str, optional
1787
1793
Original command. There are some cases, were input is
@@ -1831,6 +1837,11 @@ def input(
1831
1837
>>> with mapdl.non_interactive:
1832
1838
mapdl.run("/input,inputtrigger,inp") # This inputs 'myinput.inp'
1833
1839
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
+
1834
1845
"""
1835
1846
# Checking compatibility
1836
1847
# Checking the user is not reusing old api:
@@ -1911,18 +1922,14 @@ def input(
1911
1922
# are unclear
1912
1923
filename = self ._get_file_path (fname , progress_bar )
1913
1924
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 )
1917
1926
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
+ ]
1925
1931
1932
+ if verbose :
1926
1933
request = pb_types .InputFileRequest (filename = filename )
1927
1934
strouts = self ._stub .InputFileS (request , metadata = metadata )
1928
1935
responses = []
@@ -1934,13 +1941,8 @@ def input(
1934
1941
response = "\n " .join (responses )
1935
1942
return response .strip ()
1936
1943
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
1944
1946
1945
1947
# since we can't directly run /INPUT, we have to write a
1946
1948
# temporary input file that tells MAPDL to read the input
@@ -2014,6 +2016,31 @@ def input(
2014
2016
2015
2017
return output
2016
2018
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
+
2017
2044
def _get_file_path (self , fname : str , progress_bar : bool = False ) -> str :
2018
2045
"""Find files in the Python and MAPDL working directories.
2019
2046
0 commit comments