Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Microgrid Energy Management MPC #2: Battery Model: State of Charge, Efficiency, and Constraints”.
Other ways we can help with Python.
Learn with a mentor
Scheduled Simulation & Engineering courses with live guidance and a certificate.

Course/Training Ansys ~ Heat Transfer and Heat Flux Analysis
★ 5.0 (10)

Course/Training MATLAB — MATLAB App Design: The Ultimate Guide to MATLAB Apps
★ 5.0 (10)

Course/Training Ansys — Airflow Simulation of a Car Radiator with ANSYS
★ 5.0 (9)
Have it built for you
No time to learn Python? Our team can do the project for you.

Matlab Development Service — Complete Neural Signal Processing and Analysis Zero to Hero
★ 5.0 (59)

Ansys Maxwell Development Service
★ 5.0 (50)

Petrel Development Service
★ 5.0 (14)
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Here is the final result, the 300 kWh battery model we tested by fully charging and then discharging. From the 237 kWh that came in, only 214 kWh came back out. Where did the rest go? Let's get started. Hello, welcome to episode two of the MPC-based microgrid energy management series. Batteries are the heart of energy management, storing surplus from the day and releasing it when electricity is expensive. But batteries have real limitations: capacity, maximum power, efficiency, and SOC limits to prevent them from wearing out quickly. Today, we model it as a Python class that will later be used by all strategies.
Create a file named baterai.py The battery class stores a capacity of 300 kWh, a maximum power of 75 kWh, charging and discharging efficiency of 95% each, as well as SOC limits of 20-95%. SOC or state of charge is the percentage of energy stored. Lithium batteries are not used until 0 or 100% to ensure a long lifespan.
The step method receives a power request for 1 hour. Positive means discharging, negative means charging. Power is limited to 75 kWh. When discharging, the available energy is calculated from the SOC above the lower limit multiplied by efficiency, and the SOC decreases more than the energy that comes out. When charging, only 95% of the energy is actually stored. This method returns the actual power that occurs, so that any strategy cannot violate physical limits.
Create a test underscore baterai dot py file. Starting from a SOC of 20%, we request a charge of 75 kWh for 12 hours, then a discharge of 12 hours. Run. Energy in 236.8 kWh, out 213.8, so round-trip efficiency is 90.3%, which is 0.95 x 0.95. Battery is full at the fourth hour, and after that, automatic charging stops even though it is requested continuously.
Let's look at the graph. Top graph is battery power, full charging of 75 kWh only a few hours ago stopped, then discharging. Bottom graph SOC rising up to the upper limit of 95%, then dropping down to the lower limit of 20%, never crossing the red line. This model ensures all following simulations are realistic.
Done. We have modeled the battery with state of charge, charging and discharging efficiency, power limits, and SOC limits, then tested it. In the next episode, we create the simplest energy management strategy, rule-based. Currently working on a thesis, dissertation, or research in the field of microgrid, battery, What about renewable energy? Cerdas Inovasi Digital helps implement energy optimization, from solar panel modeling, wind turbines, and batteries, rule-based strategies, up to model predictive control with CVXPY, as well as opening Python programming courses for electrical engineering. Want to master the entire series, from weather data to cost comparison? All 6 episodes, complete with step-by-step PDF guides and source code, are available to premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or one-time payment of Rp999.000 for lifetime access. Want a single class? Buy a single class with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com. Contact us via WhatsApp, or visit cerdasinovasidigital.com. Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →