refactor: implement energy chain with consumer, provider and energy system abstractions#1492
Draft
refactor: implement energy chain with consumer, provider and energy system abstractions#1492
Conversation
…ystem abstractions
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the energy chain domain model — abstractions for modeling how consumer demand (mechanical MW) is transformed through providers (motor, generator, shore) into fuel consumption (Sm³/day).
Supersedes #1486 which took a different approach (separate DriveTrain/PowerSupply hierarchies). This PR uses a unified
Providercontract (supply,get_capacity_margin) implemented by both single-step nodes (ElectricMotor,Generator,Shore) and composite systems (SerialEnergySystem,PowerBus), so they can be nested freely.Design
Three core abstractions:
Consumerget_demand() → EnergyStreamRotatingEquipment,ShaftProvidersupply(demand) → EnergyStream,get_capacity_margin(demand) → floatElectricMotor,Generator,Shore,WindEnergySystemProvider+get_children()PowerBus,SerialEnergySystemSerialEnergySystemchains providers sequentially — each node's output becomes the next node's input (mechanical → electrical → fuel).PowerBusdistributes electrical demand across multiple sources in the order they are listed — earlier sources are used first, remaining demand spills over to the next.EnergyChainconnects aConsumerto anEnergySystemand orchestrates the full calculation viarun() → EnergyChainResult.EnergyStreamcarries a typed value (MECHANICAL,ELECTRICAL,FUEL) and unit (MWorSm³/day). Each node transforms the stream type — when fuel is reached, the chain terminates.Structure
flowchart TD subgraph EnergyChain["EnergyChain"] direction TB subgraph Consumer["Consumer — get_demand() → EnergyStream"] RE1["RotatingEquipment A"] --> SHAFT["Shaft"] RE2["RotatingEquipment B"] --> SHAFT end SHAFT -- "demand EnergyStream\n(MECHANICAL, MW)" --> SYSTEM subgraph SYSTEM["EnergySystem — supply(demand) → EnergyStream"] direction TB EM["ElectricMotor\n(Provider)"] EM -- "ELECTRICAL, MW" --> BUS subgraph BUS["PowerBus (EnergySystem)"] SHORE["Shore\n(Provider)"] GEN["Generator\n(Provider)"] end end BUS -- "supply EnergyStream\n(FUEL, Sm³/day)" --> RES["run() → EnergyChainResult\n• demand\n• fuel\n• capacity_margin"] end style Consumer fill:#e8f5e9,stroke:#2e7d32 style SYSTEM fill:#e3f2fd,stroke:#1565c0 style BUS fill:#e3f2fd,stroke:#1565c0 style RES fill:#ffebee,stroke:#c62828Energy flow example
flowchart LR A["RotatingEquipment\n1.0 MW"] --> B["Shaft\n÷ 0.95 mech. eff"] B -->|"1.053 MW"| C["ElectricMotor\n÷ 0.90 efficiency"] C -->|"1.170 MW"| D["Generator\n× 100 Sm³/day per MW"] D -->|"117 Sm³/day"| E["fuel"] style A fill:#e8f5e9 style E fill:#ffebeeEach node transforms the stream:
1.0 / 0.95 = 1.053 MWmechanical1.053 / 0.90 = 1.170 MWelectrical1.170 × 100 = 117 Sm³/dayType of Work
See here (internal): https://github.com/equinor/ecalc-internal/discussions/1044
Have you remembered and considered?
docs/drafts/next.draft.md)docs/docs/migration_guides/)BREAKING:in footer or!in headerWhat is this PR all about?
What else did you consider?
Between the lines?