31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
"""Rebuild networks from the Python baseline captured before its retirement."""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from app.simulation.core.medium import IdealGasMedium
|
|
from app.simulation.components.amesim.media.mediums import AmesimHeliumPengRobinsonMedium, AmesimIdealAirMedium
|
|
from app.simulation.native_codegen.extended import catalog_contracts
|
|
from app.simulation.systems.network import SimulationNetwork
|
|
|
|
|
|
def reference_data():
|
|
return json.loads((Path(__file__).parent / 'baselines/native/native-python-reference.json').read_text(encoding='utf-8'))
|
|
|
|
|
|
def reference_network(case):
|
|
net = SimulationNetwork('frozen_reference')
|
|
media = {}
|
|
medium_types = {cls.__name__: cls for cls in (IdealGasMedium, AmesimHeliumPengRobinsonMedium, AmesimIdealAirMedium)}
|
|
for item in case['components']:
|
|
spec = item['medium']
|
|
key = json.dumps(spec, sort_keys=True)
|
|
if key not in media:
|
|
media[key] = medium_types[spec['type']](**spec['parameters']) if spec else IdealGasMedium()
|
|
component = catalog_contracts()[item['type']].create(name=item['name'], medium=media[key], parameters=item['parameters'])
|
|
for name, value in item['overrides'].items():
|
|
setattr(component, name, value)
|
|
net.add_component(component)
|
|
for left, right in case['connections']:
|
|
net.connect(*left, *right)
|
|
return net
|