MHKiT-Software / MHKiT-Python

MHKiT-Python provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
https://mhkit-software.github.io/MHKiT/
BSD 3-Clause "New" or "Revised" License
47 stars 45 forks source link

wave elevation function is very slow #140

Closed cmichelenstrofer closed 2 years ago

cmichelenstrofer commented 2 years ago
elev = surface_elevation(S, time) 

is about 20 times slower than

elev = np.zeros(time.shape)
for ifreq, iS in S.T.iteritems(): 
    elev += iS[0] * np.cos(ifreq*2*np.pi * time + np.random.rand()*2*np.pi)
cmichelenstrofer commented 2 years ago

The calculation of B can be taken out of the for loop, it is time consuming and does not require mcol.

cmichelenstrofer commented 2 years ago

Speed up by:

B = np.outer(time_index, omega)

instead of

from itertools import product as _product
B = np.array([x*y for x,y in _product(time_index, omega)])

and

C = np.cos(B+phase[eta.columns[0]])

instead of

C = np.real(np.exp(1j*(B+phase[mcol])))