Quick Start¶
Get up and running with flixOpt in 5 minutes! This guide walks you through creating and solving your first energy system optimization.
Installation¶
First, install flixOpt:
Your First Model¶
Let's create a simple energy system with a generator, demand, and battery storage.
1. Import flixOpt¶
2. Define your time horizon¶
2. Set Up the Flow System¶
# Create the flow system
flow_system = fx.FlowSystem(timesteps)
# Define an effect to minimize (costs)
costs = fx.Effect('costs', 'EUR', 'Minimize total system costs', is_objective=True)
flow_system.add_elements(costs)
4. Add Components¶
# Electricity bus
electricity_bus = fx.Bus('electricity')
# Solar generator with time-varying output
solar_profile = np.array([0, 0, 0, 0, 0, 0, 0.2, 0.5, 0.8, 1.0,
1.0, 0.9, 0.8, 0.7, 0.5, 0.3, 0.1, 0,
0, 0, 0, 0, 0, 0])
solar = fx.Source(
'solar',
outputs=[fx.Flow(
'power',
bus='electricity',
size=100, # 100 kW capacity
relative_maximum=solar_profile
)
])
# Demand
demand_profile = np.array([30, 25, 20, 20, 25, 35, 50, 70, 80, 75,
70, 65, 60, 65, 70, 80, 90, 95, 85, 70,
60, 50, 40, 35])
demand = fx.Sink('demand', inputs=[
fx.Flow('consumption',
bus='electricity',
size=1,
fixed_relative_profile=demand_profile)
])
# Battery storage
battery = fx.Storage(
'battery',
charging=fx.Flow('charge', bus='electricity', size=50),
discharging=fx.Flow('discharge', bus='electricity', size=50),
capacity_in_flow_hours=100, # 100 kWh capacity
initial_charge_state=50, # Start at 50%
eta_charge=0.95,
eta_discharge=0.95,
)
# Add all components to system
flow_system.add_elements(solar, demand, battery, electricity_bus)
5. Visualize and Run Optimization¶
# Optional: visualize your system structure
flow_system.topology.plot(path='system.html')
# Run optimization
flow_system.optimize(fx.solvers.HighsSolver())
6. Access and Visualize Results¶
# Access raw solution data
print(flow_system.solution)
# Use statistics for aggregated data
print(flow_system.statistics.flow_hours)
# Access component-specific results
print(flow_system.components['battery'].solution)
# Visualize results
flow_system.statistics.plot.balance('electricity')
flow_system.statistics.plot.storage('battery')
7. Save Results (Optional)¶
# Save the flow system (includes inputs and solution)
flow_system.to_netcdf('results/solar_battery.nc')
# Load it back later
loaded_fs = fx.FlowSystem.from_netcdf('results/solar_battery.nc')
What's Next?¶
Now that you've created your first model, you can:
- Learn the concepts - Read the Core Concepts guide
- Explore examples - Check out more Examples
- Deep dive - Study the Mathematical Formulation
- Build complex models - Use Recipes for common patterns
Common Workflow¶
Most flixOpt projects follow this pattern:
- Define time series - Set up the temporal resolution
- Create flow system - Initialize with time series and effects
- Add buses - Define connection points
- Add components - Create generators, storage, converters, loads
- Verify structure - Use
flow_system.topology.plot()to visualize - Run optimization - Call
flow_system.optimize(solver) - Analyze results - Via
flow_system.statisticsand.solution - Visualize - Use
flow_system.statistics.plot.*methods
Tips¶
- Start simple and add complexity incrementally
- Use meaningful names for components and flows
- Check solver status before analyzing results
- Enable logging during development for debugging
- Visualize results to verify model behavior