pvlib / pvlib-python

A set of documented functions for simulating the performance of photovoltaic energy systems.
https://pvlib-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.18k stars 998 forks source link

Addition of floating module #1937

Open AlbaAlcaniz opened 9 months ago

AlbaAlcaniz commented 9 months ago

As shown at the 2023 European PVPMC, people have interest on modelling the inclination angles of a floating PV system. I have developed and published a Matlab code for that here that I would like to include to pvlib.

In summary, the code consists of the following steps:

  1. Decompose the wind speed in line with the axes of the floater
  2. Calculate the Jonswap spectrum from the windspeed. The Jonswap is specific for the North Sea, but a more general spectrum like the Pierson-Moskowitz could also be included
  3. Compute the surface elevation
  4. Calculate the moments of inertia of the floater
  5. Calculate the inclinations of the two axes of the floater (called roll and pitch)
  6. Transform the inclination angles to tilt and azimuth

Since the code is in matlab, it should be organized differently in python. Below is my first proposal for the organization in its own floating.py module.

def decompose_wind_speed(wind_speed, wind_dir, Floater.orientation):
     return wind_speed_x, wind_speed_y

class Sea
     def __init__(ang_freq, time_res):
     def jonswap_spectrum(self, wind_speed, wind_speed_x, wind_speed_y):
          return spectrum
     def pierson_moskowitz_spectrum(self, wind_speed, wind_speed_x, wind_speed_y):
          return spectrum
     def surface_elevation(self, type_spectrum, wind_speed, wind_speed_x, wind_speed_y):
          # call one of the spectrum functions
          return elevation

class Floater
     def __init__(mass, width, length, thickness, orientation):
     def compute_inertia_moment(self):
          return inertia
     def get_inclination_angles(self, Sea):
          # call compute_inertia_moment()
          return pitch, roll
     def get_tilt_azimuth(self, Sea):
          # call get_inclination_angles()
          return tilt, azimuth

This would ensure that sequential functions are called once while allowing individual functions if needed. What do you think? Do you have any suggestions for improvement?

cwhanse commented 9 months ago

Overall structure looks OK to me. spectrum is a sequence of (frequency, spectral density) pairs - is that right? I'm noodling on the name Sea, is there an equivalent concept of wave spectrum for other-than-ocean water bodies? Lakes, ponds, canals, and the like.

AlbaAlcaniz commented 7 months ago

Yes, the spectrum is a sequence of (frequency, spectral density) pairs that changes according to the wind speed.

I only know of wave spectra for oceans, as the waves in inland-water bodies are generally small. I think that most disturbances in lakes, ponds, canals and the like are generally caused by human actions (e.g. ships) or random actions so they are harder to model.

I have finally had the time to work on this. I have created a fork of pvlib in my github. The files to check are floating.py and example.py in the folder /pvlib/floating/. The classes and functions are in the first file. The second one is an example of usage. The remaining files are the direct translation from the matlab code, therefore irrelevant in the end but useful for now when debugging.

I'd like your opinion on the coding structure before merging it into the main code. I'm aware that the files are not commented and there are no tests, but as the structure may be subjected to changes, I didn't want to get into those details yet. There are also some functions that work with random values, but for now are set to ones to improve the "testing".