Turbsim correlated fuorier coefficients

Good Morning Everybody,

I am trying to generate a code close to TurbSim in Matlab getting a 3-dimensional turbulent wind speed field on a square grid,by making use of the only Kaimal and Von Karman PSD models.
Let’s say that these are the main features for the simulation:

HubHt = 84 [m];
GridWidth = 80 [m];
GridHeight = 80 [m];
RotorDiameter = 80 [m];
NumGrid_Y = 31;
NumGrid_Z = 31;
AnalysisTime = 600;
UsableTime = 40;
TimeStep = 0.5;
UHub = 11.4;

IECTurbC = ‘B’;
IECed = ‘2’;
TurbModel = ‘IECKAI’;

Even within Matlab I handle the Coherence matrix by means of the spptrf lapack function, so that the coherence matrix is an array made up of 961*(961+1)/2 indipendent elements ( an this array should be mono-dimensional), since the coherence matrix is a symmetric positive definite one.

After having got the Veers Matrix (packed into a one-dimensional array??) , I should go to calculate the correlated fourier coefficients by means of this code:


  ! Calculate the correlated fourier coefficients.   
  ! -------------------------------------------------------------

DO IVec = 1,3
IF2 = 0
DO IFREQ = 1,NumFreq

  IF2      = IF2 + 2
  IF1      = IF2 - 1
  
  DO J=1,NTot

        ! Apply a random phase to each of the columns of H to
        ! produce random phases in the wind component.
        ! Then sum each of the rows into the vector V.
        
     IRand = IFreq + (J-1)*NumFreq + (IVec-1)*NTot*NumFreq  ! This sorts the random numbers as they were done previously

     Ph    = TwoPi*RandNum(IRand)
     CPh   = COS( Ph )
     SPh   = SIN( Ph )

     Indx  = NTot*(J-1) - J*(J-1)/2 + J !Index of H(I,J)
     DO I=J,NTot

        V(IF1,I,IVec) = V(IF1,I,IVec) + TRH(Indx)*CPh  !Real part
        V(IF2,I,IVec) = V(IF2,I,IVec) + TRH(Indx)*SPh  !Imaginary part

        Indx = Indx + 1      !H(I,J)

     ENDDO ! I  
  ENDDO ! J

ENDDO !IFreq

ENDDO !IVec

But, then, matlab tells me that there’s a mismatch between the left-side dimensions (3 because of V) and the right-side dimensions; and having a look at the code,this seems right.
So I would like to know how to overcome this issue;maybe I missed some passages or ,even worse, I did not get the right way TurbSim handle these data.

I look forward to getting some hints,whenever possible.
Kind regards,
Francesco Perrone

Hi, Francesco.

In TurbSim, the “Veers H Matrix”, is stored in variable TRH, which is one-dimensional by pair of points on the grid. However, TRH is a function of frequency and wind component, so it gets recalculated at each frequency and component in the loop. (This is done to minimize the amount of storage needed for the variable.)

The V matrix is three-dimensional, by frequency (note that there are real and complex parts for each frequency), grid point, and wind-speed component.

It looks like you have isolated the correct portion of the Fortran code. I am not sure why you are getting an error in Matlab when you try to implement this. Maybe there was an unnoticed error when you converted the Fortran code to Matlab? Perhaps the arrays/matrices were dimensioned improperly?

Regards,
Bonnie

Hi,Bonnie.

I believe that Matlab turns into error since V is a three-dimensional array,whereas TRH(Indx)*CPh and TRH(Indx)*SPh are one-dimensional (at least I guess so).
Hence,Matlab is not able to perform the sum with the V first column.

I have another trivial question. CPh/SPh arrays are NumTotNumFreq3 sized,TRH is NumTot*(NumTot + 1)/2 (is it stored in a columnwise array?? or in a row-wise one??), so I´m wondering which is the final dimension of TRH(Indx)*SPh/CPh.

I apologize for asking real easy stuff and thank you in advance.

Kind regards,

Francesco

Hi, Francesco.

In the Fortran code, all the calculations are done in loops, so, while V is a 3-dimensional array, V(IF1,I,IVec) is just a scalar. TRH is a one-dimensional array, but TRH(Indx), CPh, and SPh are also just scalars. You could implement the Matlab code with the same loops and then you wouldn’t need to worry about row vs column arrays, etc.

If you want to do whole-array calculations, you would probably declare many of the arrays differently… such as RandNum stores a random phase for each point, each frequency, and each component. In Fortran we have declared it as a one-dimensional array (NTotNumFreq3), but in Matlab, you might want to declare it as a three-dimensional array (perhaps using NumFreq x NTot x 3). If you go back to Paul Veers’ Sandia Report, Three-Dimensional Wind Simulation, you can see the matrix multiplications that we are implementing in the Fortran code. That may help you decide how to set up your variables.

Hi,Bonnie.

During the day I worked everything out.

I knew all the arrays/matrices sizes,but the code in Matlab works using functions differing from those TurbSim recalls.

Now everything is running as it should.

I really thank you for the hints provided.

Best regards,
Francesco