ansys-mechanical-core 0.10.11__py3-none-any.whl → 0.11.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ansys/mechanical/core/__init__.py +11 -4
- ansys/mechanical/core/_version.py +48 -47
- ansys/mechanical/core/embedding/__init__.py +1 -1
- ansys/mechanical/core/embedding/addins.py +1 -7
- ansys/mechanical/core/embedding/app.py +610 -281
- ansys/mechanical/core/embedding/app_libraries.py +2 -2
- ansys/mechanical/core/embedding/appdata.py +11 -4
- ansys/mechanical/core/embedding/background.py +106 -0
- ansys/mechanical/core/embedding/cleanup_gui.py +61 -0
- ansys/mechanical/core/embedding/enum_importer.py +2 -2
- ansys/mechanical/core/embedding/imports.py +27 -7
- ansys/mechanical/core/embedding/initializer.py +104 -51
- ansys/mechanical/core/embedding/loader.py +1 -1
- ansys/mechanical/core/embedding/logger/__init__.py +219 -216
- ansys/mechanical/core/embedding/logger/environ.py +1 -1
- ansys/mechanical/core/embedding/logger/linux_api.py +1 -1
- ansys/mechanical/core/embedding/logger/sinks.py +1 -1
- ansys/mechanical/core/embedding/logger/windows_api.py +2 -2
- ansys/mechanical/core/embedding/poster.py +34 -2
- ansys/mechanical/core/embedding/resolver.py +41 -44
- ansys/mechanical/core/embedding/runtime.py +1 -1
- ansys/mechanical/core/embedding/shims.py +9 -8
- ansys/mechanical/core/embedding/ui.py +228 -0
- ansys/mechanical/core/embedding/utils.py +1 -1
- ansys/mechanical/core/embedding/viz/__init__.py +1 -1
- ansys/mechanical/core/embedding/viz/{pyvista_plotter.py → embedding_plotter.py} +24 -12
- ansys/mechanical/core/embedding/viz/usd_converter.py +59 -25
- ansys/mechanical/core/embedding/viz/utils.py +32 -2
- ansys/mechanical/core/embedding/warnings.py +1 -1
- ansys/mechanical/core/errors.py +2 -1
- ansys/mechanical/core/examples/__init__.py +1 -1
- ansys/mechanical/core/examples/downloads.py +10 -5
- ansys/mechanical/core/feature_flags.py +1 -1
- ansys/mechanical/core/ide_config.py +212 -0
- ansys/mechanical/core/launcher.py +9 -9
- ansys/mechanical/core/logging.py +14 -2
- ansys/mechanical/core/mechanical.py +2324 -2237
- ansys/mechanical/core/misc.py +176 -176
- ansys/mechanical/core/pool.py +712 -712
- ansys/mechanical/core/run.py +321 -291
- {ansys_mechanical_core-0.10.11.dist-info → ansys_mechanical_core-0.11.12.dist-info}/LICENSE +1 -1
- {ansys_mechanical_core-0.10.11.dist-info → ansys_mechanical_core-0.11.12.dist-info}/METADATA +55 -54
- ansys_mechanical_core-0.11.12.dist-info/RECORD +45 -0
- {ansys_mechanical_core-0.10.11.dist-info → ansys_mechanical_core-0.11.12.dist-info}/WHEEL +1 -1
- {ansys_mechanical_core-0.10.11.dist-info → ansys_mechanical_core-0.11.12.dist-info}/entry_points.txt +1 -0
- ansys_mechanical_core-0.10.11.dist-info/RECORD +0 -41
ansys/mechanical/core/misc.py
CHANGED
@@ -1,176 +1,176 @@
|
|
1
|
-
# Copyright (C) 2022 -
|
2
|
-
# SPDX-License-Identifier: MIT
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
22
|
-
|
23
|
-
"""Contain miscellaneous functions and methods at the module level."""
|
24
|
-
|
25
|
-
from functools import wraps
|
26
|
-
import os
|
27
|
-
import socket
|
28
|
-
from threading import Thread
|
29
|
-
|
30
|
-
|
31
|
-
def is_windows():
|
32
|
-
"""Check if the host machine is on Windows.
|
33
|
-
|
34
|
-
Returns
|
35
|
-
-------
|
36
|
-
``True`` if the host machine is on Windows, ``False`` otherwise.
|
37
|
-
"""
|
38
|
-
if os.name == "nt": # pragma: no cover
|
39
|
-
return True
|
40
|
-
|
41
|
-
return False
|
42
|
-
|
43
|
-
|
44
|
-
def get_mechanical_bin(release_version):
|
45
|
-
"""Get the path for the Mechanical executable file based on the release version.
|
46
|
-
|
47
|
-
Parameters
|
48
|
-
----------
|
49
|
-
release_version: str
|
50
|
-
Mechanical version using the three-digit format. For example, ``"
|
51
|
-
|
52
|
-
"""
|
53
|
-
if is_windows(): # pragma: no cover
|
54
|
-
program_files = os.getenv("PROGRAMFILES", os.path.join("c:\\", "Program Files"))
|
55
|
-
ans_root = os.getenv(
|
56
|
-
f"AWP_ROOT{release_version}",
|
57
|
-
os.path.join(program_files, "ANSYS Inc", f"v{release_version}"),
|
58
|
-
)
|
59
|
-
mechanical_bin = os.path.join(ans_root, "aisol", "bin", "winx64", f"AnsysWBU.exe")
|
60
|
-
else:
|
61
|
-
ans_root = os.getenv(f"AWP_ROOT{release_version}", os.path.join("/", "usr", "ansys_inc"))
|
62
|
-
mechanical_bin = os.path.join(*ans_root, f"v{release_version}", "aisol", f".workbench")
|
63
|
-
|
64
|
-
return mechanical_bin
|
65
|
-
|
66
|
-
|
67
|
-
def threaded(func):
|
68
|
-
"""Decorate a function with this decorator to call it using a thread."""
|
69
|
-
|
70
|
-
@wraps(func)
|
71
|
-
def wrapper(*args, **kwargs):
|
72
|
-
name = kwargs.get("name", f"Threaded `{func.__name__}` function")
|
73
|
-
thread = Thread(target=func, name=name, args=args, kwargs=kwargs)
|
74
|
-
thread.start()
|
75
|
-
return thread
|
76
|
-
|
77
|
-
return wrapper
|
78
|
-
|
79
|
-
|
80
|
-
def threaded_daemon(func):
|
81
|
-
"""Decorate a function with this decorator to call it using a daemon thread."""
|
82
|
-
|
83
|
-
@wraps(func)
|
84
|
-
def wrapper(*args, **kwargs):
|
85
|
-
name = kwargs.get("name", f"Threaded (with Daemon) `{func.__name__}` function")
|
86
|
-
thread = Thread(target=func, name=name, args=args, kwargs=kwargs)
|
87
|
-
thread.daemon = True
|
88
|
-
thread.start()
|
89
|
-
return thread
|
90
|
-
|
91
|
-
return wrapper
|
92
|
-
|
93
|
-
|
94
|
-
def check_valid_ip(ip):
|
95
|
-
"""Check if the IP address is valid.
|
96
|
-
|
97
|
-
Parameters
|
98
|
-
----------
|
99
|
-
ip : str
|
100
|
-
IP address to check.
|
101
|
-
|
102
|
-
"""
|
103
|
-
if ip.lower() != "localhost":
|
104
|
-
ip = ip.replace('"', "").replace("'", "")
|
105
|
-
socket.inet_aton(ip)
|
106
|
-
|
107
|
-
|
108
|
-
def check_valid_port(port, lower_bound=1000, high_bound=60000):
|
109
|
-
"""Check if the port is valid.
|
110
|
-
|
111
|
-
Parameters
|
112
|
-
|
113
|
-
port : int
|
114
|
-
Port to check.
|
115
|
-
lower_bound : int, optional
|
116
|
-
Lowest possible value for the port. The default is ``1000``.
|
117
|
-
high_bound : int, optional
|
118
|
-
Highest possible value for the port. The default is ``60000``.
|
119
|
-
"""
|
120
|
-
if not isinstance(port, int):
|
121
|
-
raise ValueError("The 'port' parameter must be an integer.")
|
122
|
-
|
123
|
-
if lower_bound < port < high_bound:
|
124
|
-
return
|
125
|
-
else:
|
126
|
-
raise ValueError(f"'port' values must be between {lower_bound} and {high_bound}.")
|
127
|
-
|
128
|
-
|
129
|
-
def check_valid_start_instance(start_instance):
|
130
|
-
"""
|
131
|
-
Check if the value obtained from the environmental variable is valid.
|
132
|
-
|
133
|
-
Parameters
|
134
|
-
----------
|
135
|
-
start_instance : str, bool
|
136
|
-
Value obtained from the corresponding environment variable.
|
137
|
-
|
138
|
-
Returns
|
139
|
-
-------
|
140
|
-
bool
|
141
|
-
``True`` if ``start_instance`` is ``True`` or ``"True"``,
|
142
|
-
``False`` otherwise.
|
143
|
-
|
144
|
-
"""
|
145
|
-
if not isinstance(start_instance, (str, bool)):
|
146
|
-
raise ValueError("The value for 'start_instance' should be a string or a boolean.")
|
147
|
-
|
148
|
-
if isinstance(start_instance, bool):
|
149
|
-
return start_instance
|
150
|
-
|
151
|
-
if start_instance.lower() not in ["true", "false"]:
|
152
|
-
raise ValueError(
|
153
|
-
|
154
|
-
)
|
155
|
-
|
156
|
-
return start_instance.lower() == "true"
|
157
|
-
|
158
|
-
|
159
|
-
def is_float(input_string):
|
160
|
-
"""Check if a string can be converted to a float.
|
161
|
-
|
162
|
-
Parameters
|
163
|
-
----------
|
164
|
-
input_string : str
|
165
|
-
String to check.
|
166
|
-
|
167
|
-
Returns
|
168
|
-
-------
|
169
|
-
bool
|
170
|
-
``True`` when conversion is possible, ``False`` otherwise.
|
171
|
-
"""
|
172
|
-
try:
|
173
|
-
float(input_string)
|
174
|
-
return True
|
175
|
-
except ValueError:
|
176
|
-
return False
|
1
|
+
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
"""Contain miscellaneous functions and methods at the module level."""
|
24
|
+
|
25
|
+
from functools import wraps
|
26
|
+
import os
|
27
|
+
import socket
|
28
|
+
from threading import Thread
|
29
|
+
|
30
|
+
|
31
|
+
def is_windows():
|
32
|
+
"""Check if the host machine is on Windows.
|
33
|
+
|
34
|
+
Returns
|
35
|
+
-------
|
36
|
+
``True`` if the host machine is on Windows, ``False`` otherwise.
|
37
|
+
"""
|
38
|
+
if os.name == "nt": # pragma: no cover
|
39
|
+
return True
|
40
|
+
|
41
|
+
return False
|
42
|
+
|
43
|
+
|
44
|
+
def get_mechanical_bin(release_version):
|
45
|
+
"""Get the path for the Mechanical executable file based on the release version.
|
46
|
+
|
47
|
+
Parameters
|
48
|
+
----------
|
49
|
+
release_version: str
|
50
|
+
Mechanical version using the three-digit format. For example, ``"251"`` for
|
51
|
+
2025 R1.
|
52
|
+
"""
|
53
|
+
if is_windows(): # pragma: no cover
|
54
|
+
program_files = os.getenv("PROGRAMFILES", os.path.join("c:\\", "Program Files"))
|
55
|
+
ans_root = os.getenv(
|
56
|
+
f"AWP_ROOT{release_version}",
|
57
|
+
os.path.join(program_files, "ANSYS Inc", f"v{release_version}"),
|
58
|
+
)
|
59
|
+
mechanical_bin = os.path.join(ans_root, "aisol", "bin", "winx64", f"AnsysWBU.exe")
|
60
|
+
else:
|
61
|
+
ans_root = os.getenv(f"AWP_ROOT{release_version}", os.path.join("/", "usr", "ansys_inc"))
|
62
|
+
mechanical_bin = os.path.join(*ans_root, f"v{release_version}", "aisol", f".workbench")
|
63
|
+
|
64
|
+
return mechanical_bin
|
65
|
+
|
66
|
+
|
67
|
+
def threaded(func):
|
68
|
+
"""Decorate a function with this decorator to call it using a thread."""
|
69
|
+
|
70
|
+
@wraps(func)
|
71
|
+
def wrapper(*args, **kwargs):
|
72
|
+
name = kwargs.get("name", f"Threaded `{func.__name__}` function")
|
73
|
+
thread = Thread(target=func, name=name, args=args, kwargs=kwargs)
|
74
|
+
thread.start()
|
75
|
+
return thread
|
76
|
+
|
77
|
+
return wrapper
|
78
|
+
|
79
|
+
|
80
|
+
def threaded_daemon(func):
|
81
|
+
"""Decorate a function with this decorator to call it using a daemon thread."""
|
82
|
+
|
83
|
+
@wraps(func)
|
84
|
+
def wrapper(*args, **kwargs):
|
85
|
+
name = kwargs.get("name", f"Threaded (with Daemon) `{func.__name__}` function")
|
86
|
+
thread = Thread(target=func, name=name, args=args, kwargs=kwargs)
|
87
|
+
thread.daemon = True
|
88
|
+
thread.start()
|
89
|
+
return thread
|
90
|
+
|
91
|
+
return wrapper
|
92
|
+
|
93
|
+
|
94
|
+
def check_valid_ip(ip):
|
95
|
+
"""Check if the IP address is valid.
|
96
|
+
|
97
|
+
Parameters
|
98
|
+
----------
|
99
|
+
ip : str
|
100
|
+
IP address to check.
|
101
|
+
|
102
|
+
"""
|
103
|
+
if ip.lower() != "localhost":
|
104
|
+
ip = ip.replace('"', "").replace("'", "")
|
105
|
+
socket.inet_aton(ip)
|
106
|
+
|
107
|
+
|
108
|
+
def check_valid_port(port, lower_bound=1000, high_bound=60000):
|
109
|
+
"""Check if the port is valid.
|
110
|
+
|
111
|
+
Parameters
|
112
|
+
----------
|
113
|
+
port : int
|
114
|
+
Port to check.
|
115
|
+
lower_bound : int, optional
|
116
|
+
Lowest possible value for the port. The default is ``1000``.
|
117
|
+
high_bound : int, optional
|
118
|
+
Highest possible value for the port. The default is ``60000``.
|
119
|
+
"""
|
120
|
+
if not isinstance(port, int):
|
121
|
+
raise ValueError("The 'port' parameter must be an integer.")
|
122
|
+
|
123
|
+
if lower_bound < port < high_bound:
|
124
|
+
return
|
125
|
+
else:
|
126
|
+
raise ValueError(f"'port' values must be between {lower_bound} and {high_bound}.")
|
127
|
+
|
128
|
+
|
129
|
+
def check_valid_start_instance(start_instance):
|
130
|
+
"""
|
131
|
+
Check if the value obtained from the environmental variable is valid.
|
132
|
+
|
133
|
+
Parameters
|
134
|
+
----------
|
135
|
+
start_instance : str, bool
|
136
|
+
Value obtained from the corresponding environment variable.
|
137
|
+
|
138
|
+
Returns
|
139
|
+
-------
|
140
|
+
bool
|
141
|
+
``True`` if ``start_instance`` is ``True`` or ``"True"``,
|
142
|
+
``False`` otherwise.
|
143
|
+
|
144
|
+
"""
|
145
|
+
if not isinstance(start_instance, (str, bool)):
|
146
|
+
raise ValueError("The value for 'start_instance' should be a string or a boolean.")
|
147
|
+
|
148
|
+
if isinstance(start_instance, bool):
|
149
|
+
return start_instance
|
150
|
+
|
151
|
+
if start_instance.lower() not in ["true", "false"]:
|
152
|
+
raise ValueError(
|
153
|
+
"The value for 'start_instance' should be 'True' or 'False' (case insensitive)."
|
154
|
+
)
|
155
|
+
|
156
|
+
return start_instance.lower() == "true"
|
157
|
+
|
158
|
+
|
159
|
+
def is_float(input_string):
|
160
|
+
"""Check if a string can be converted to a float.
|
161
|
+
|
162
|
+
Parameters
|
163
|
+
----------
|
164
|
+
input_string : str
|
165
|
+
String to check.
|
166
|
+
|
167
|
+
Returns
|
168
|
+
-------
|
169
|
+
bool
|
170
|
+
``True`` when conversion is possible, ``False`` otherwise.
|
171
|
+
"""
|
172
|
+
try:
|
173
|
+
float(input_string)
|
174
|
+
return True
|
175
|
+
except ValueError:
|
176
|
+
return False
|