1
1
2
+ from cmath import sin
2
3
import ctypes
3
4
import numpy
4
5
import addict
@@ -140,18 +141,20 @@ def load_data(self, unit, get_solution, get_solution_str, idx=None, parType=None
140
141
result = get_solution (* tuple (wrappers [var_key ](var_value ) for var_key , var_value in vars .items ()))
141
142
142
143
shape = []
144
+ dims = []
143
145
dimensions = ['nTime' , 'nPort' , 'nParShells' , 'nAxialCells' , 'nRadialCells' , 'nComp' , 'nBound' ]
144
146
for dim in dimensions :
145
147
if dim in vars and vars [dim ].value :
146
148
shape .append (vars [dim ].value )
149
+ dims .append (dim )
147
150
148
151
data = numpy .ctypeslib .as_array (vars ['data' ], shape = shape )
149
152
time = numpy .ctypeslib .as_array (vars ['time' ], shape = (vars ['nTime' ].value , ))
150
153
151
154
if own_data :
152
- return ( time .copy (), data .copy ())
155
+ return time .copy (), data .copy (), dims
153
156
else :
154
- return ( time , data )
157
+ return time , data , dims
155
158
156
159
def inlet (self , unit , own_data = True ):
157
160
return self .load_data (unit , self ._api .getSolutionInlet , 'getSolutionInlet' , own_data = own_data )
@@ -312,7 +315,6 @@ def run(self, filename = None, simulation=None, timeout = None, check=None):
312
315
return self .res
313
316
314
317
def load_solution (self , sim , solution_fun , solution_str ):
315
- # - [ ] Split Components (Should be unified)
316
318
# - [ ] Split Ports (incl `SINGLE_AS_MULTI_PORT`)
317
319
# - [ ] Split Partype (Particle + Solid)
318
320
# - [ ] Coordinates?
@@ -325,7 +327,7 @@ def load_solution(self, sim, solution_fun, solution_str):
325
327
if key .startswith ('unit' ):
326
328
if value [f'write_{ solution_str } ' ]:
327
329
unit = int (key [- 3 :])
328
- t , out = solution_fun (unit )
330
+ t , out , dims = solution_fun (unit )
329
331
330
332
if not len (solution .solution_times ):
331
333
solution .solution_times = t
@@ -340,14 +342,54 @@ def load_solution_io(self, sim, solution_fun, solution_str):
340
342
if key .startswith ('unit' ):
341
343
if value [f'write_{ solution_str } ' ]:
342
344
unit = int (key [- 3 :])
343
- t , out = solution_fun (unit )
345
+ t , out , dims = solution_fun (unit )
344
346
345
347
if not len (solution .solution_times ):
346
348
solution .solution_times = t
347
-
348
- for comp in range (out .shape [2 ]):
349
- comp_out = numpy .squeeze (out [:,:,comp ])
350
- solution [key ][f'{ solution_str } _comp_{ comp :03d} ' ] = comp_out
349
+
350
+ split_components_data = value .get ('split_components_data' , 1 )
351
+ split_ports_data = value .get ('split_ports_data' , 1 )
352
+ single_as_multi_port = value .get ('single_as_multi_port' , 0 )
353
+
354
+ nComp = dims .index ('nComp' )
355
+ try :
356
+ nPorts = dims .index ('nPorts' )
357
+ except ValueError :
358
+ nPorts = None
359
+
360
+ if split_components_data :
361
+ if split_ports_data :
362
+ if nPorts is None :
363
+ if single_as_multi_port :
364
+ for comp in range (out .shape [nComp ]):
365
+ comp_out = numpy .squeeze (out [..., comp ])
366
+ solution [key ][f'{ solution_str } _port_000_comp_{ comp :03d} ' ] = comp_out
367
+ else :
368
+ for comp in range (out .shape [nComp ]):
369
+ comp_out = numpy .squeeze (out [..., comp ])
370
+ solution [key ][f'{ solution_str } _comp_{ comp :03d} ' ] = comp_out
371
+ else :
372
+ for port in range (out .shape [nPorts ]):
373
+ for comp in range (out .shape [nComp ]):
374
+ comp_out = numpy .squeeze (out [..., port , comp ])
375
+ solution [key ][f'{ solution_str } _port_{ port :03d} _comp_{ comp :03d} ' ] = comp_out
376
+ else :
377
+ for comp in range (out .shape [nComp ]):
378
+ comp_out = numpy .squeeze (out [...,comp ])
379
+ solution [key ][f'{ solution_str } _comp_{ comp :03d} ' ] = comp_out
380
+ else :
381
+ if split_ports_data :
382
+ if nPorts is None :
383
+ if single_as_multi_port :
384
+ solution [key ][f'{ solution_str } _port_000' ] = out
385
+ else :
386
+ solution [key ][solution_str ] = out
387
+ else :
388
+ for port in range (out .shape [nPorts ]):
389
+ port_out = numpy .squeeze (out [..., port , :])
390
+ solution [key ][f'{ solution_str } _port_{ port :03d} ' ] = port_out
391
+ else :
392
+ solution [key ][solution_str ] = out
351
393
return solution
352
394
353
395
def load_inlet (self , sim ):
0 commit comments