Pvlib for Julia?

Hi,

I have been happily using Julia for a year or so now after being a python user for many more years.

The only thing I am really missing is a substitute for pvlib. pvlib is a popular toolbox for photovoltaic systems modelling. Given all the other modelling tools available in Julia it seems like the perfect activity to do in Julia, yet nothing exists (as far as I have found).

Ofcourse I could use PyCall.jl or some other kind of glue layer but to the honest, the python package began development in 2013 by Sandia National Laboratories and even though it is still in active development its API feels quite dated.

So that brings me to my question. Is there any interest from the Julia community to build a new library for modelling solar systems in native Julia? I imagine (or hope) this is something many scientists and engineers working in energy would be interested in.

4 Likes

I wonder if NREL might have developed something similar in Julia? Havenā€™t seen anything on their GitHub org though

I checked out their repositories but I donā€™t see anything specific to photovoltaics modelling. However, given NRELā€™s involvement with pvlib Iā€™m sure they have thought about it.

1 Like

I am more into wind energy, but writing something like pvlib in Julia should be straightforward. If you find a student who wants to do it I could supervise him or her (I am electrical engineer by training with a focus on renewable energies, now postdoc).

5 Likes

If youā€™re going to write a new library in this space, I would definitely try to make it differentiable by AD. (A colleague of mine supervised a student who did a differentiable PV simulator of this sort, albeit in Python; itā€™s not that hard to set up if you plan for it from the beginning.)

5 Likes

Happy to assist with any AD or ImplicitDifferentiation.jl needs, since there seems to be a mention of the implicit function theorem

2 Likes

Thatā€™s a great idea. Itā€™s really impressive to see differentiable solar cell simulations. Do you know of any such work at the module level?

Now that I finally have some time I have started the project here: PVSim.jl

At this point I am still laying out a plan for the package, I need to think about how Iā€™m going to structure it.

More specifically I need to think about what the shortcomings and strengths of pvlib are, since thatā€™s what it will be benchmarked against. I also want to fix all my annoyances with pvlib, like inconsistent data formats and API calls and lack of proper data handling tools. Data handling is a big thing and automating that part will be a huge time saver. Inspired by:
https://github.com/pvlib/pvanalytics

And this really cool signal decomposition framework by PhD students of Boyd:
https://github.com/slacgismo/solar-data-tools

I expect to make quite some mistakes, and I may even have to rewrite the whole thing once I have learned enough but thatā€™s fine, it wouldnā€™t be the first time that has happened to me :smiley:

6 Likes

I also take interest in PV modelling/simulation, even though my background is not in EE.

Not sure if thatā€™s an issue, as I would have to cover some basic materials to get up to speed in PV sim., but I would like to join the quest in developing this package

Apart from PV itself, the data handling and AD aspects are also very interesting to me as they provide an opportunity to develop some Julia skills Iā€™ve been wanting to tackle for a while.

1 Like

Thanks for showing interest, I was beginning to think I was the only one haha.

Data handling will be done in a second package: PVData.jl

Right now there is not much to program yet. PV simulators are built on something called the model chain, which is a collection of modelling components required to go from irradiance to finally DC or AC power output. In between there are a million choices you can make, depending on the application.

This image (M.J. Mayer, 2021) shows all the steps really well I think:

I want to make as much use of the Julia ecosystem as possible. For example we can build the cell model using MTK.

https://www.pveducation.org/ is a good place to start.

3 Likes

Having built an energy efficient house, I used ESP-r as an open source building thermal modeling tool (written in Fortran). In that field they have done a lot of thinking about climate files, ie what kind of shading can you expect in your locale. These are based on the statistics of weather data for many years. ESP-r has one of a couple of standardized data files for this function.

And since I had the author of WATSUN as a professor in university, I canā€™t help but point you to it.

Both of these are primarily thermal simulation tools, which I as an ME am more excited about, but the solar insolation part is the same for both thermal and PV.

1 Like

Interesting, thanks. My MSc thesis was about thermal modelling of buildings to enable energy flexibility of heat pumps, so I studied these kinds of models quite a bit.

This image (M.J. Mayer, 2021) shows all the steps really well I think:

Awesome! Not sure what else would have been more effective than a diagram like this for a newcomer to the field. Lots of room for modularization right up front btw.

A couple of questions (some for future discussion):

  • Do we expect to have many more components than the ones in the diagram?
  • If I understand correctly, these components would live in PVSim.jl while all other data-related operations would be implemented in PVData.jl. Should the actual simulation (components + data) be implemented inside PVSim.jl too or somewhere else?
  • Any suggestions on how/where can we start sketching some roadmap/feature list to get started with a basic prototype?

I want to make as much use of the Julia ecosystem as possible. For example we can build the cell model using MTK.

100% agreed!

https://www.pveducation.org/ is a good place to start.

Iā€™ve skimmed through the sections, thatā€™s great resource! Thank you, @langestefan!

1 Like

Yup! Thatā€™s what I am thinking about right now. I like what DifferentialEquations.jl has done with how they packaged things, only import the solvers you need saves a lot of overhead. But such package level optimizations are probably best to do later down the line when there actually are choices.

No, this is it. All the model components should fit in one of these light blue boxes. The green box is what PVData.jl is responsible for. I will try to make a better image to explain what I mean.

One thing I especially want to prioritize is system modularity. This is one of the main problems with PVLib, there is no good separation between DC and AC domains. For example I tried making a setup in PVLib which had DC optimizers, like solaredge systems have. That was not possible. I want to be able to drop in an inverter wherever I see fit. I want parellel setups, series setups, DC optimizers, AC optimizers, string optimizers, I have seen all these combinations in the field.

All data related operations should remain in PVData.jl. The simulation in PVSim.jl should just take a dataframe with the right columns, it will not care where that dataframe came from. I think thatā€™s the best way to completely decouple the data operations and simulation domains.

Let me get some basic stuff working first. I am trying to merge the thermal diode component into MTK so I can build the solar panel model. The PV panel model will be based on the single diode model, which is ubiquitous in PV literature and industry (see image below, from Cordeiro 2023). It is important to use this model because solar PV manufacturers provide parameter values for them.

This is super easy to build in ModelingToolkit.jl but we are still missing the diode. Once we have a solar panel model, we can start adding all the other modelling components and it will really start to take shape. The amazing thing about using MTK is now that I can just put an electric port and a thermal port on my solar panel model and I have full modularity in how I connect those to the rest of the system.

2 Likes

Hi @langestefan, Iā€™m one of the maintainers of pvlib-python (kandersolar (Kevin Anderson) Ā· GitHub). Iā€™m only a beginner julia programmer, but have quite some experience in PV modeling and writing PV simulation software, and have daydreamed about making a ā€œpvlib.jlā€ for years. I made some small steps in that direction (solar position calculation, e.g.) some years ago, and perhaps that code could be reused here.

Anyway, I may be interested in collaborating. Would you be interested in having a call sometime to share ideas?

7 Likes

Thatā€™s really amazing to hear! I have interacted a few times with you on pvlib before :slight_smile:

Yeah, letā€™s make it happen. Sounds like a great idea.

Iā€™ll send you a DM

Great. I just added the diode with temperature dependent behaviour to the PR. Hopefully somebody at SciML can look at the PR soon but no rush. I added a few unit tests but this part will need some more thorough testing as everything else is derived from it. In the meantime I will implement the solar module/panel model.

I think itā€™s too much to cover all of it. The parts about semiconductors are tough if you dont have an EE/physics background. Itā€™s also not really necessary because weā€™re not simulation at the silicon level. I would focus on chapters 2, 4, 7 and 8.

ps. this is also a really good resource which covers a lot of the basics: Modeling Guide ā€“ PV Performance Modeling Collaborative (PVPMC)

(the page is not great at explaining the formulas, they can feel a bit like ā€˜magicā€™)

1 Like