API 参考 - 协仿真处理器 (Co-simulation Handlers)¶
协仿真处理器 (Co-simulation Handlers)
协仿真处理器 (Co-simulation Handlers) 提供了用于与外部仿真工具(如 Aspen Plus)进行数据交换和协同仿真的接口。 请在下方的标签页中选择您感兴趣的特定模块。
run_div_simulation(temp_input_csv, temp_output_csv, **kwargs)
¶
Runs a simulation based on fake divertor data.
Reads data from a source CSV, selects specific columns, and writes them to a temporary output CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp_input_csv
|
str
|
Path to the temporary input CSV file (unused). |
required |
temp_output_csv
|
str
|
Path to the temporary output CSV file. |
required |
**kwargs
|
Additional keyword arguments (unused). |
{}
|
Returns:
| Type | Description |
|---|---|
dict
|
A placeholder dictionary with output variable mappings. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the source CSV file cannot be found. |
ValueError
|
If the source CSV is missing required columns. |
Note
The temp_input_csv parameter is kept for interface consistency but not used. Reads from div_handler.csv in the same directory as this module. Returns a placeholder dict with format {"to_CL": "{1,2,3,4,5,6}"}.
Source code in tricys/handlers/div_handler.py
AspenEnhanced
¶
A helper class to encapsulate interactions with an Aspen Plus COM server.
Attributes:
| Name | Type | Description |
|---|---|---|
aspen |
The Aspen Plus COM object instance. |
|
M_T |
Molar mass of Tritium (3.016 g/mol). |
|
M_D |
Molar mass of Deuterium (2.014 g/mol). |
|
M_H |
Molar mass of Hydrogen (1.008 g/mol). |
Note
Requires Aspen Plus COM interface to be available on the system. Sets visibility to 0 and suppresses dialogs for automation.
Source code in tricys/handlers/i_iss_handler.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
__init__(bkp_path)
¶
Initialize Aspen connection and define molar masses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bkp_path
|
str
|
Path to the Aspen backup file (.bkp). |
required |
Note
Converts path to absolute before loading. Suppresses Aspen GUI and dialogs. COM object version "Apwn.Document.40.0" may need adjustment for different Aspen Plus versions.
Source code in tricys/handlers/i_iss_handler.py
close()
¶
Closes the Aspen connection.
Note
Should always be called to properly clean up COM resources. Typically used in finally block to ensure cleanup even on errors.
Source code in tricys/handlers/i_iss_handler.py
get_stream_results()
¶
Get H/D/T mass flow rates (g/h) from key streams.
Returns:
| Name | Type | Description |
|---|---|---|
dict
|
Dictionary mapping stream names to [H, D, T] mass flow lists. |
|
Format |
dict
|
{"WDS": [H, D, T], "SDST2": [H, D, T], "SDSD2": [H, D, T]}. |
Note
Retrieves mole flows in kmol/h, converts to mol/h (*1000), then calculates mass flows using isotope-specific molar masses. Streams mapped are: WDS->S4, SDST2->S17, SDSD2->S16.
Source code in tricys/handlers/i_iss_handler.py
run_step()
¶
Execute single-step simulation and wait for completion.
Note
Uses busy-wait polling with 0.1 second intervals to check if engine is running. Blocks until simulation step completes.
Source code in tricys/handlers/i_iss_handler.py
set_composition(ratios)
¶
Set six-component input composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratios
|
list
|
List of 7 values [EH2, EHD, ED2, EHT, EDT, ET2, total_flow]. |
required |
Note
Updates Aspen stream FROMTEP with H2, HD, D2, HT, DT, T2 flows and total flow. Total flow is divided by 2 when setting TOTFLOW/MIXED node.
Source code in tricys/handlers/i_iss_handler.py
run_aspen_simulation(temp_input_csv, temp_output_csv, bkp_path='example_aspenbkp/T2-Threetowers4.bkp', aspen_results_csv=None, base=20, retime=60, time_step=3, min_stable_steps=100, stable_threshold=1e-06)
¶
Runs an Aspen Plus simulation based on inputs from a Modelica simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp_input_csv
|
str
|
Path to the input CSV file with time-series data. |
required |
temp_output_csv
|
str
|
Path to save the final summarized output CSV. |
required |
bkp_path
|
str
|
Path to the Aspen backup file (.bkp). Defaults to example path. |
'example_aspenbkp/T2-Threetowers4.bkp'
|
aspen_results_csv
|
str
|
Path to save detailed Aspen results. Defaults to None. |
None
|
base
|
float
|
Minimum inventory (heel) to start simulation (mol). Defaults to 20. |
20
|
retime
|
int
|
Lag time in minutes for output results. Defaults to 60. |
60
|
time_step
|
int
|
Time step in minutes. Defaults to 3. |
3
|
min_stable_steps
|
int
|
Consecutive stable steps to confirm stability. Defaults to 100. |
100
|
stable_threshold
|
float
|
Relative difference threshold for stability. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary mapping output variable names to their final values, |
dict
|
formatted as Modelica vector strings. |
dict
|
e.g., {'to_SDS': '{v1,v2,v3}', 'to_WDS': '{v4,v5,v6}'}. |
Note
Implements delayed feedback with retime lag. Skips simulation until inventory reaches base level. Stops early if system stabilizes (T_flow change < threshold for min_stable_steps). Input CSV encoding is 'gbk'. Creates cumulative inventory tracking columns I_H, I_D, I_T. Output columns use 1-indexed array notation [1], [2], [3].
Source code in tricys/handlers/i_iss_handler.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
run_dummy_simulation(temp_input_csv, temp_output_csv, **kwargs)
¶
Runs a simulation based on fake i_ISS data.
Reads data from a source CSV, selects specific columns, and writes them to a temporary output CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp_input_csv
|
str
|
Path to the temporary input CSV file (unused). |
required |
temp_output_csv
|
str
|
Path to the temporary output CSV file. |
required |
**kwargs
|
Additional keyword arguments (unused). |
{}
|
Returns:
| Type | Description |
|---|---|
dict
|
A placeholder dictionary with output variable mappings. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the source CSV file cannot be found. |
ValueError
|
If the source CSV is missing required columns. |
Note
The temp_input_csv parameter is kept for interface consistency but not used. Reads from i_iss_handler.csv in the same directory as this module. Selects columns for to_SDS[1-5] and to_WDS[1-5]. Returns placeholder dict with format {"to_SDS": "{1,2,3,4,5,6}", "to_WDS": "{1,7,8,9,10,11}"}.