ansys-systemcoupling-core 0.5.0__py3-none-any.whl → 0.6__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.
Potentially problematic release.
This version of ansys-systemcoupling-core might be problematic. Click here for more details.
- ansys/systemcoupling/core/__init__.py +11 -5
- ansys/systemcoupling/core/adaptor/api_23_1/show_plot.py +75 -0
- ansys/systemcoupling/core/adaptor/api_23_1/solution_root.py +7 -1
- ansys/systemcoupling/core/adaptor/api_23_2/show_plot.py +75 -0
- ansys/systemcoupling/core/adaptor/api_23_2/solution_root.py +7 -1
- ansys/systemcoupling/core/adaptor/api_24_1/show_plot.py +75 -0
- ansys/systemcoupling/core/adaptor/api_24_1/solution_root.py +7 -1
- ansys/systemcoupling/core/adaptor/api_24_2/add_participant.py +4 -4
- ansys/systemcoupling/core/adaptor/api_24_2/setup_root.py +1 -1
- ansys/systemcoupling/core/adaptor/api_24_2/show_plot.py +75 -0
- ansys/systemcoupling/core/adaptor/api_24_2/solution_root.py +7 -1
- ansys/systemcoupling/core/adaptor/impl/injected_commands.py +215 -32
- ansys/systemcoupling/core/adaptor/impl/static_info.py +17 -0
- ansys/systemcoupling/core/adaptor/impl/syc_proxy.py +3 -0
- ansys/systemcoupling/core/adaptor/impl/syc_proxy_interface.py +4 -0
- ansys/systemcoupling/core/adaptor/impl/types.py +1 -1
- ansys/systemcoupling/core/charts/chart_datatypes.py +169 -0
- ansys/systemcoupling/core/charts/csv_chartdata.py +299 -0
- ansys/systemcoupling/core/charts/live_csv_datasource.py +87 -0
- ansys/systemcoupling/core/charts/message_dispatcher.py +84 -0
- ansys/systemcoupling/core/charts/plot_functions.py +92 -0
- ansys/systemcoupling/core/charts/plotdefinition_manager.py +303 -0
- ansys/systemcoupling/core/charts/plotter.py +343 -0
- ansys/systemcoupling/core/client/grpc_client.py +6 -1
- ansys/systemcoupling/core/participant/manager.py +25 -9
- ansys/systemcoupling/core/participant/protocol.py +1 -0
- ansys/systemcoupling/core/session.py +4 -4
- ansys/systemcoupling/core/syc_version.py +1 -1
- ansys/systemcoupling/core/util/file_transfer.py +4 -0
- {ansys_systemcoupling_core-0.5.0.dist-info → ansys_systemcoupling_core-0.6.dist-info}/METADATA +11 -10
- {ansys_systemcoupling_core-0.5.0.dist-info → ansys_systemcoupling_core-0.6.dist-info}/RECORD +33 -22
- {ansys_systemcoupling_core-0.5.0.dist-info → ansys_systemcoupling_core-0.6.dist-info}/LICENSE +0 -0
- {ansys_systemcoupling_core-0.5.0.dist-info → ansys_systemcoupling_core-0.6.dist-info}/WHEEL +0 -0
|
@@ -21,52 +21,97 @@
|
|
|
21
21
|
# SOFTWARE.
|
|
22
22
|
|
|
23
23
|
from copy import deepcopy
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
import os
|
|
25
|
+
import random
|
|
26
|
+
import time
|
|
27
|
+
from typing import Callable, Dict, Optional, Protocol
|
|
28
|
+
|
|
29
|
+
import ansys.platform.instancemanagement as pypim
|
|
30
|
+
|
|
31
|
+
from ansys.systemcoupling.core.charts.plot_functions import create_and_show_plot
|
|
32
|
+
from ansys.systemcoupling.core.charts.plotdefinition_manager import (
|
|
33
|
+
DataTransferSpec,
|
|
34
|
+
InterfaceSpec,
|
|
35
|
+
PlotSpec,
|
|
36
|
+
)
|
|
37
|
+
from ansys.systemcoupling.core.native_api import NativeApi
|
|
26
38
|
from ansys.systemcoupling.core.participant.manager import ParticipantManager
|
|
27
39
|
from ansys.systemcoupling.core.participant.mapdl import MapdlSystemCouplingInterface
|
|
28
|
-
from ansys.systemcoupling.core.syc_version import compare_versions
|
|
29
40
|
from ansys.systemcoupling.core.util.yaml_helper import yaml_load_from_string
|
|
30
41
|
|
|
31
42
|
from .get_status_messages import get_status_messages
|
|
32
43
|
from .types import Container
|
|
33
44
|
|
|
34
45
|
|
|
46
|
+
# We cannot import Session directly, so define a protocol for typing.
|
|
47
|
+
# We mainly use it as a means of accessing the "API roots".
|
|
48
|
+
class SessionProtocol(Protocol):
|
|
49
|
+
case: Container
|
|
50
|
+
setup: Container
|
|
51
|
+
solution: Container
|
|
52
|
+
_native_api: NativeApi
|
|
53
|
+
|
|
54
|
+
def download_file(
|
|
55
|
+
self, file_name: str, local_file_dir: str = ".", overwrite: bool = False
|
|
56
|
+
) -> None: ...
|
|
57
|
+
|
|
58
|
+
def upload_file(
|
|
59
|
+
self,
|
|
60
|
+
file_name: str,
|
|
61
|
+
remote_file_name: Optional[str] = None,
|
|
62
|
+
overwrite: bool = False,
|
|
63
|
+
) -> None: ...
|
|
64
|
+
|
|
65
|
+
|
|
35
66
|
def get_injected_cmd_map(
|
|
36
|
-
version: str,
|
|
37
67
|
category: str,
|
|
38
|
-
|
|
68
|
+
session: SessionProtocol,
|
|
39
69
|
part_mgr: ParticipantManager,
|
|
40
70
|
rpc,
|
|
41
71
|
) -> Dict[str, Callable]:
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
|
|
72
|
+
"""Get a dictionary mapping names to functions that implement injected commands
|
|
73
|
+
for the specified API category.
|
|
74
|
+
|
|
75
|
+
Whereas the set of commands that exists by default on the API represents a relatively
|
|
76
|
+
mechanical exposure of native System Coupling commands to PySystemCoupling, the
|
|
77
|
+
"injected commands" that are returned from here are either *additional* commands
|
|
78
|
+
that have no counterpart in System Coupling or *overrides* to existing commands
|
|
79
|
+
that provide modified or extended behavior.
|
|
45
80
|
"""
|
|
46
81
|
ret = {}
|
|
47
82
|
|
|
48
83
|
if category == "setup":
|
|
84
|
+
# ``get_injected_cmd_map`` needs to be called during initialisation, where
|
|
85
|
+
# the session API roots are not necessarily available yet. We therefore
|
|
86
|
+
# defer their access via the lambda.
|
|
87
|
+
get_setup_root_object = lambda: session.setup
|
|
49
88
|
ret = {
|
|
50
89
|
"get_setup_summary": lambda **kwargs: rpc.GetSetupSummary(**kwargs),
|
|
51
90
|
"get_status_messages": lambda **kwargs: get_status_messages(
|
|
52
|
-
rpc,
|
|
91
|
+
rpc, get_setup_root_object(), **kwargs
|
|
53
92
|
),
|
|
54
93
|
"add_participant": lambda **kwargs: _wrap_add_participant(
|
|
55
|
-
|
|
94
|
+
session, part_mgr, **kwargs
|
|
56
95
|
),
|
|
57
96
|
}
|
|
58
97
|
|
|
59
98
|
if category == "solution":
|
|
99
|
+
get_solution_root_object = lambda: session.solution
|
|
100
|
+
get_setup_root_object = lambda: session.setup
|
|
60
101
|
ret = {
|
|
61
|
-
"solve": lambda **kwargs: _wrap_solve(
|
|
102
|
+
"solve": lambda **kwargs: _wrap_solve(
|
|
103
|
+
get_solution_root_object(), part_mgr, **kwargs
|
|
104
|
+
),
|
|
62
105
|
"interrupt": lambda **kwargs: rpc.interrupt(**kwargs),
|
|
63
106
|
"abort": lambda **kwargs: rpc.abort(**kwargs),
|
|
107
|
+
"show_plot": lambda **kwargs: _show_plot(session, **kwargs),
|
|
64
108
|
}
|
|
65
109
|
|
|
66
110
|
if category == "case":
|
|
111
|
+
get_case_root_object = lambda: session.case
|
|
67
112
|
ret = {
|
|
68
113
|
"clear_state": lambda **kwargs: _wrap_clear_state(
|
|
69
|
-
|
|
114
|
+
get_case_root_object(), part_mgr, **kwargs
|
|
70
115
|
)
|
|
71
116
|
}
|
|
72
117
|
|
|
@@ -74,9 +119,10 @@ def get_injected_cmd_map(
|
|
|
74
119
|
|
|
75
120
|
|
|
76
121
|
def _wrap_add_participant(
|
|
77
|
-
|
|
122
|
+
session: SessionProtocol, part_mgr: ParticipantManager, **kwargs
|
|
78
123
|
) -> str:
|
|
79
|
-
|
|
124
|
+
setup = session.setup
|
|
125
|
+
if participant_session := kwargs.get("participant_session", None):
|
|
80
126
|
if len(kwargs) != 1:
|
|
81
127
|
raise RuntimeError(
|
|
82
128
|
"If a 'participant_session' argument is passed to "
|
|
@@ -85,46 +131,124 @@ def _wrap_add_participant(
|
|
|
85
131
|
if part_mgr is None:
|
|
86
132
|
raise RuntimeError("Internal error: participant manager is not available.")
|
|
87
133
|
|
|
88
|
-
if compare_versions(server_version, "24.1") < 0:
|
|
89
|
-
raise RuntimeError(
|
|
90
|
-
f"System Coupling server version '{server_version}' is too low to"
|
|
91
|
-
"support this form of 'add_participant'. Minimum version is '24.1'."
|
|
92
|
-
)
|
|
93
|
-
|
|
94
134
|
# special handling for mapdl session
|
|
95
|
-
if "ansys.mapdl.core.mapdl_grpc.MapdlGrpc" in str(type(
|
|
135
|
+
if "ansys.mapdl.core.mapdl_grpc.MapdlGrpc" in str(type(participant_session)):
|
|
96
136
|
return part_mgr.add_participant(
|
|
97
|
-
participant_session=MapdlSystemCouplingInterface(
|
|
137
|
+
participant_session=MapdlSystemCouplingInterface(participant_session)
|
|
98
138
|
)
|
|
99
139
|
|
|
100
|
-
if not hasattr(
|
|
140
|
+
if not hasattr(participant_session, "system_coupling"):
|
|
101
141
|
raise RuntimeError(
|
|
102
142
|
"The 'participant_session' parameter does not provide a "
|
|
103
143
|
"'system_coupling' attribute and therefore cannot support this "
|
|
104
144
|
"form of 'add_participant'."
|
|
105
145
|
)
|
|
146
|
+
return part_mgr.add_participant(
|
|
147
|
+
participant_session=participant_session.system_coupling
|
|
148
|
+
)
|
|
106
149
|
|
|
107
|
-
|
|
150
|
+
if input_file := kwargs.get("input_file", None):
|
|
151
|
+
session.upload_file(input_file)
|
|
108
152
|
|
|
109
|
-
return
|
|
153
|
+
return setup._add_participant(**kwargs)
|
|
110
154
|
|
|
111
155
|
|
|
112
|
-
def _wrap_clear_state(
|
|
113
|
-
root_object: Container, part_mgr: ParticipantManager, **kwargs
|
|
114
|
-
) -> None:
|
|
156
|
+
def _wrap_clear_state(case: Container, part_mgr: ParticipantManager, **kwargs) -> None:
|
|
115
157
|
part_mgr.clear()
|
|
116
|
-
|
|
158
|
+
case._clear_state(**kwargs)
|
|
117
159
|
|
|
118
160
|
|
|
119
|
-
def _wrap_solve(
|
|
161
|
+
def _wrap_solve(solution: Container, part_mgr: ParticipantManager) -> None:
|
|
120
162
|
if part_mgr is None:
|
|
121
|
-
|
|
163
|
+
solution._solve()
|
|
122
164
|
else:
|
|
123
165
|
part_mgr.solve()
|
|
124
166
|
|
|
125
167
|
|
|
168
|
+
def _ensure_file_available(session: SessionProtocol, filepath: str) -> str:
|
|
169
|
+
"""If we are in a "PIM" session, copies the file specified by ``filepath``
|
|
170
|
+
into the working directory, so that it is available for download.
|
|
171
|
+
|
|
172
|
+
A suffix is added to the name of the copy to make the name unique, and
|
|
173
|
+
the new name is returned.
|
|
174
|
+
"""
|
|
175
|
+
# Note: it is a general issue with files in a PIM session that they can
|
|
176
|
+
# only be uploaded to/downloaded from the root working directory. We
|
|
177
|
+
# might want to consider integrating something like this directly into
|
|
178
|
+
# the file_transfer module later so that it is more seamless.
|
|
179
|
+
|
|
180
|
+
if not pypim.is_configured():
|
|
181
|
+
return filepath
|
|
182
|
+
|
|
183
|
+
# Copy file to a unique name in the working directory
|
|
184
|
+
file_name = os.path.basename(filepath)
|
|
185
|
+
root_name, _, ext = file_name.rpartition(".")
|
|
186
|
+
ext = f".{ext}" if ext else ""
|
|
187
|
+
new_name = f"{root_name}_{int(time.time())}_{random.randint(1, 10000000)}{ext}"
|
|
188
|
+
|
|
189
|
+
session._native_api.ExecPythonString(
|
|
190
|
+
PythonString=f"import shutil\nshutil.copy('{filepath}', '{new_name}')"
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
session.download_file(new_name, ".")
|
|
194
|
+
return new_name
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _show_plot(session: SessionProtocol, **kwargs):
|
|
198
|
+
setup = session.setup
|
|
199
|
+
working_dir = kwargs.pop("working_dir", ".")
|
|
200
|
+
interface_name = kwargs.pop("interface_name", None)
|
|
201
|
+
if interface_name is None:
|
|
202
|
+
interfaces = setup.coupling_interface.get_object_names()
|
|
203
|
+
if len(interfaces) == 0:
|
|
204
|
+
return
|
|
205
|
+
if len(interfaces) > 1:
|
|
206
|
+
raise RuntimeError(
|
|
207
|
+
"show_plot() currently only supports a single interface."
|
|
208
|
+
)
|
|
209
|
+
interface_name = interfaces[0]
|
|
210
|
+
interface_object = setup.coupling_interface[interface_name]
|
|
211
|
+
interface_disp_name = interface_object.display_name
|
|
212
|
+
|
|
213
|
+
if (transfer_names := kwargs.pop("transfer_names", None)) is None:
|
|
214
|
+
transfer_names = interface_object.data_transfer.get_object_names()
|
|
215
|
+
|
|
216
|
+
if len(transfer_names) == 0:
|
|
217
|
+
return None
|
|
218
|
+
|
|
219
|
+
transfer_disp_names = [
|
|
220
|
+
interface_object.data_transfer[trans_name].display_name
|
|
221
|
+
for trans_name in transfer_names
|
|
222
|
+
]
|
|
223
|
+
|
|
224
|
+
show_convergence = kwargs.pop("show_convergence", True)
|
|
225
|
+
show_transfer_values = kwargs.pop("show_transfer_values", True)
|
|
226
|
+
|
|
227
|
+
# TODO : better way to do this?
|
|
228
|
+
is_transient = setup.solution_control.time_step_size is not None
|
|
229
|
+
|
|
230
|
+
file_path = _ensure_file_available(
|
|
231
|
+
session, os.path.join(working_dir, "SyC", f"{interface_name}.csv")
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
spec = PlotSpec()
|
|
235
|
+
intf_spec = InterfaceSpec(interface_name, interface_disp_name)
|
|
236
|
+
spec.interfaces.append(intf_spec)
|
|
237
|
+
for transfer in transfer_disp_names:
|
|
238
|
+
intf_spec.transfers.append(
|
|
239
|
+
DataTransferSpec(
|
|
240
|
+
display_name=transfer,
|
|
241
|
+
show_convergence=show_convergence,
|
|
242
|
+
show_transfer_values=show_transfer_values,
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
spec.plot_time = is_transient
|
|
246
|
+
|
|
247
|
+
return create_and_show_plot(spec, [file_path])
|
|
248
|
+
|
|
249
|
+
|
|
126
250
|
def get_injected_cmd_data() -> list:
|
|
127
|
-
"""
|
|
251
|
+
"""Get a list of injected command data in the right form to insert
|
|
128
252
|
at a convenient point in the current processing.
|
|
129
253
|
|
|
130
254
|
Because the data returned data is always a new copy, it can be manipulated at will.
|
|
@@ -327,4 +451,63 @@ _cmd_yaml = """
|
|
|
327
451
|
pyname: clear_state
|
|
328
452
|
isInjected: true
|
|
329
453
|
pysyc_internal_name: _clear_state
|
|
454
|
+
- name: show_plot
|
|
455
|
+
pyname: show_plot
|
|
456
|
+
exposure: solution
|
|
457
|
+
isInjected: true
|
|
458
|
+
isQuery: false
|
|
459
|
+
retType: <class 'NoneType'>
|
|
460
|
+
doc: |-
|
|
461
|
+
Shows plots of transfer values and convergence for data transfers
|
|
462
|
+
of a coupling interface.
|
|
463
|
+
|
|
464
|
+
essentialArgNames:
|
|
465
|
+
- interface_name
|
|
466
|
+
optionalArgNames:
|
|
467
|
+
- transfer_names
|
|
468
|
+
- working_dir
|
|
469
|
+
- show_convergence
|
|
470
|
+
- show_transfer_values
|
|
471
|
+
defaults:
|
|
472
|
+
- None
|
|
473
|
+
- "."
|
|
474
|
+
- True
|
|
475
|
+
- True
|
|
476
|
+
args:
|
|
477
|
+
- #!!python/tuple
|
|
478
|
+
- interface_name
|
|
479
|
+
- pyname: interface_name
|
|
480
|
+
Type: <class 'str'>
|
|
481
|
+
type: String
|
|
482
|
+
doc: |-
|
|
483
|
+
Specification of which interface to plot.
|
|
484
|
+
- #!!python/tuple
|
|
485
|
+
- transfer_names
|
|
486
|
+
- pyname: transfer_names
|
|
487
|
+
Type: <class 'list'>
|
|
488
|
+
type: String List
|
|
489
|
+
doc: |-
|
|
490
|
+
Specification of which data transfers to plot. Defaults
|
|
491
|
+
to ``None``, which means plot all data transfers.
|
|
492
|
+
- #!!python/tuple
|
|
493
|
+
- working_dir
|
|
494
|
+
- pyname: working_dir
|
|
495
|
+
Type: <class 'str'>
|
|
496
|
+
type: String
|
|
497
|
+
doc: |-
|
|
498
|
+
Working directory (defaults = ".").
|
|
499
|
+
- #!!python/tuple
|
|
500
|
+
- show_convergence
|
|
501
|
+
- pyname: show_convergence
|
|
502
|
+
Type: <class 'bool'>
|
|
503
|
+
type: Logical
|
|
504
|
+
doc: |-
|
|
505
|
+
Whether to show convergence plots (defaults to ``True``).
|
|
506
|
+
- #!!python/tuple
|
|
507
|
+
- show_transfer_values
|
|
508
|
+
- pyname: show_transfer_values
|
|
509
|
+
Type: <class 'bool'>
|
|
510
|
+
type: Logical
|
|
511
|
+
doc: |-
|
|
512
|
+
Whether to show transfer value plots (defaults to ``True``).
|
|
330
513
|
"""
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
from copy import deepcopy
|
|
24
24
|
from typing import Dict, List, Tuple
|
|
25
25
|
|
|
26
|
+
from ansys.systemcoupling.core.adaptor.impl.get_syc_version import get_syc_version
|
|
26
27
|
from ansys.systemcoupling.core.adaptor.impl.injected_commands import (
|
|
27
28
|
get_injected_cmd_data,
|
|
28
29
|
)
|
|
@@ -310,6 +311,21 @@ def get_extended_cmd_metadata(api) -> list:
|
|
|
310
311
|
Object providing access to the System Coupling *native API*.
|
|
311
312
|
"""
|
|
312
313
|
|
|
314
|
+
def fix_up_doc(cmd_metadata):
|
|
315
|
+
if get_syc_version(api) != "24.2":
|
|
316
|
+
return cmd_metadata
|
|
317
|
+
|
|
318
|
+
# There is a bug in doc text queried from 24.2 SyC. The "*" need
|
|
319
|
+
# to be escaped to avoid issues in Sphinx. This can be a surgical
|
|
320
|
+
# fix because 24.2 is frozen now.
|
|
321
|
+
for cmd in cmd_metadata:
|
|
322
|
+
if cmd["pyname"] == "add_participant":
|
|
323
|
+
add_part_cmd = cmd
|
|
324
|
+
for arg_name, arg_info in add_part_cmd["args"]:
|
|
325
|
+
if arg_name == "InputFile":
|
|
326
|
+
arg_info["doc"] = arg_info["doc"].replace("*", r"\*")
|
|
327
|
+
return cmd_metadata
|
|
328
|
+
|
|
313
329
|
def find_item_by_name(items: List[Dict], name: str) -> dict:
|
|
314
330
|
for item in items:
|
|
315
331
|
if item["name"] == name:
|
|
@@ -400,4 +416,5 @@ def get_extended_cmd_metadata(api) -> list:
|
|
|
400
416
|
cmd_metadata = get_cmd_metadata(api)
|
|
401
417
|
injected_data = get_injected_cmd_data()
|
|
402
418
|
merge_data(cmd_metadata, injected_data)
|
|
419
|
+
cmd_metadata = fix_up_doc(cmd_metadata)
|
|
403
420
|
return cmd_metadata
|
|
@@ -89,6 +89,9 @@ class SycProxy(SycProxyInterface):
|
|
|
89
89
|
return adapt_native_named_object_keys(state)
|
|
90
90
|
return state
|
|
91
91
|
|
|
92
|
+
def get_property_state(self, path, property):
|
|
93
|
+
return self.__rpc.GetParameter(ObjectPath=path, Name=property)
|
|
94
|
+
|
|
92
95
|
def delete(self, path):
|
|
93
96
|
self.__rpc.DeleteObject(ObjectPath=path)
|
|
94
97
|
|
|
@@ -241,7 +241,7 @@ class SettingsBase(Base, Generic[StateT]):
|
|
|
241
241
|
|
|
242
242
|
def get_property_state(self, prop):
|
|
243
243
|
"""Get the state of the ``prop`` property ."""
|
|
244
|
-
return self.sycproxy.
|
|
244
|
+
return self.sycproxy.get_property_state(self.syc_path, self.to_syc_name(prop))
|
|
245
245
|
|
|
246
246
|
@staticmethod
|
|
247
247
|
def _print_state_helper(state, out, indent=0, indent_factor=2):
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Copyright (C) 2023 - 2024 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
|
+
from dataclasses import dataclass, field
|
|
24
|
+
from enum import Enum
|
|
25
|
+
from typing import Optional
|
|
26
|
+
|
|
27
|
+
"""Common data types for the storage of metadata and data for chart series.
|
|
28
|
+
|
|
29
|
+
All series are assumed to belong to an interface and to a data transfer within the interface
|
|
30
|
+
|
|
31
|
+
Raw data should be processed into this format from whatever source is available (CSV file
|
|
32
|
+
or streamed data, for example) and the actual charts will be built from this.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class SeriesType(Enum):
|
|
37
|
+
CONVERGENCE = 1
|
|
38
|
+
SUM = 2
|
|
39
|
+
WEIGHTED_AVERAGE = 3
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class TransferSeriesInfo:
|
|
44
|
+
"""Information about the chart series data associated with a data transfer.
|
|
45
|
+
|
|
46
|
+
Attributes
|
|
47
|
+
----------
|
|
48
|
+
data_index : int
|
|
49
|
+
This is used by the data source processor to associate this information (likely
|
|
50
|
+
obtained from heading or other metadata) with the correct data series.
|
|
51
|
+
It indexes into the full list of series associated with a given interface.
|
|
52
|
+
series_type : SeriesType
|
|
53
|
+
The type of line series.
|
|
54
|
+
transfer_display_name : str
|
|
55
|
+
The display name of the data transfer. This is a primary identifier for data
|
|
56
|
+
transfers because CSV data sources do not currently include information about
|
|
57
|
+
the underlying data model names of data transfers.
|
|
58
|
+
disambiguation_index: int
|
|
59
|
+
This should be set to 0, unless there is more than one data transfer with the
|
|
60
|
+
same display name. A contiguous range of indexes starting at 0 should be assigned
|
|
61
|
+
to the list of data transfers with the same display name.
|
|
62
|
+
participant_display_name : str, optional
|
|
63
|
+
The display name of the participant. This is required for transfer value series
|
|
64
|
+
but not for convergence series.
|
|
65
|
+
line_suffixes: list[str]
|
|
66
|
+
This should always be empty for convergence series. For transfer value series,
|
|
67
|
+
it should contain the suffixes for any component series that exist. That is,
|
|
68
|
+
suffixes for complex components, "real" or "imag", and suffixes for vector
|
|
69
|
+
components, "x", "y", "z", or a combination of complex and vector component
|
|
70
|
+
types. The data indexes for individual components of the transfer are assumed
|
|
71
|
+
to be contiguous from ``data_index``.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
data_index: int
|
|
75
|
+
series_type: SeriesType
|
|
76
|
+
transfer_display_name: str
|
|
77
|
+
disambiguation_index: int
|
|
78
|
+
# Remainder for non-CONVERGENCE series only
|
|
79
|
+
participant_display_name: Optional[str] = None
|
|
80
|
+
line_suffixes: list[str] = field(default_factory=list)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass
|
|
84
|
+
class InterfaceInfo:
|
|
85
|
+
"""Information about the chart series data associated with a single interface.
|
|
86
|
+
|
|
87
|
+
Attributes
|
|
88
|
+
----------
|
|
89
|
+
name : str
|
|
90
|
+
The name of the coupling interface data model object.
|
|
91
|
+
display_name : str, optional
|
|
92
|
+
The display name of the interface object. This may be unassigned initially.
|
|
93
|
+
is_transient : bool
|
|
94
|
+
Whether the data on this interface is associated with a transient analysis.
|
|
95
|
+
transfer_info : list[TransferSeriesInfo]
|
|
96
|
+
The list of ``TransferSeriesInfo`` associated with this interface.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
name: str
|
|
100
|
+
display_name: str = "" # TODO: check whether this is actually needed.
|
|
101
|
+
is_transient: bool = False
|
|
102
|
+
transfer_info: list[TransferSeriesInfo] = field(default_factory=list)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class SeriesData:
|
|
107
|
+
"""The plot data for a single chart line series and information to allow
|
|
108
|
+
it to be associated with chart metadata.
|
|
109
|
+
|
|
110
|
+
An instance of this type is assumed to be associated externally with a
|
|
111
|
+
single interface.
|
|
112
|
+
|
|
113
|
+
Attributes
|
|
114
|
+
----------
|
|
115
|
+
transfer_index : int
|
|
116
|
+
Index of the ``TransferSeriesInfo`` metadata for this series within the
|
|
117
|
+
``InterfaceInfo`` for the interface this series is associated with.
|
|
118
|
+
component_index : int, optional
|
|
119
|
+
The component index if this series is one of a set of complex and/or
|
|
120
|
+
vector components of the transfer. Otherwise is ``None``.
|
|
121
|
+
start_index : int, optional
|
|
122
|
+
The starting iteration of the ``data`` field. This defaults to 0 and
|
|
123
|
+
only needs to be set to a different value if incremental data, such
|
|
124
|
+
as might arise during "live" update of plots, has become available.
|
|
125
|
+
data : list[float]
|
|
126
|
+
The series data. This is always indexed by iteration. Extract time
|
|
127
|
+
step-based data by using a time step to iteration mapping.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
transfer_index: int # Index into transfer_info of associated InterfaceInfo
|
|
131
|
+
component_index: Optional[int] = None # Component index if applicable
|
|
132
|
+
|
|
133
|
+
start_index: int = 0 # Use when providing incremental data
|
|
134
|
+
|
|
135
|
+
data: list[float] = field(default_factory=list)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@dataclass
|
|
139
|
+
class InterfaceSeriesData:
|
|
140
|
+
"""The series data for given interface.
|
|
141
|
+
|
|
142
|
+
Attributes
|
|
143
|
+
----------
|
|
144
|
+
info : InterfaceInfo
|
|
145
|
+
The metadata for the interface.
|
|
146
|
+
series : list[SeriesData]
|
|
147
|
+
The data for all series associated with the interface.
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
info: InterfaceInfo
|
|
151
|
+
series: list[SeriesData] = field(default_factory=list)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@dataclass
|
|
155
|
+
class TimestepData:
|
|
156
|
+
"""Mappings from iteration to time step and time.
|
|
157
|
+
|
|
158
|
+
Attributes
|
|
159
|
+
----------
|
|
160
|
+
timestep : list[int]
|
|
161
|
+
Timestep indexes, indexed by iteration. Typically, multiple consecutive
|
|
162
|
+
iteration indexes map to the same timestep index.
|
|
163
|
+
time: list[float]
|
|
164
|
+
Time values, indexed by iteration. Typically, multiple consecutive iteration
|
|
165
|
+
indexes map to the same time value.
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
timestep: list[int] = field(default_factory=list) # iter -> step index
|
|
169
|
+
time: list[float] = field(default_factory=list) # iter -> time
|