-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFDWind.f90
executable file
·1263 lines (895 loc) · 63.2 KB
/
FDWind.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MODULE FDWind
! This module reads and processes 4-dimensional wind fields.
! The subroutines were originally created by Marshall Buhl to read LES data provided by researchers
! at NCAR. It was later updated by Bonnie Jonkman to read DNS data provided by researchers at CoRA.
!
! Data are assumed to be in units of meters and seconds.
!
! 7 Oct 2009 B. Jonkman, NREL/NWTC using subroutines from AeroDyn 12.57
!----------------------------------------------------------------------------------------------------
USE NWTC_Library
USE SharedInflowDefns
IMPLICIT NONE
PRIVATE
! FD_Wind
REAL(ReKi) :: DelXgrid ! The nondimensional distance between grid points in the x direction.
REAL(ReKi) :: DelYgrid ! The nondimensional distance between grid points in the y direction.
REAL(ReKi) :: DelZgrid ! The nondimensional distance between grid points in the z direction.
REAL(ReKi) :: FDper ! Total time in dataset.
REAL(ReKi) :: FDTime (2) ! Times for the 4D wind files.
REAL(ReKi), ALLOCATABLE :: FDu (:,:,:,:) ! The u-component array of 4D wind data.
REAL(ReKi), ALLOCATABLE :: FDv (:,:,:,:) ! The v-component array of 4D wind data.
REAL(ReKi), ALLOCATABLE :: FDw (:,:,:,:) ! The w-component array of 4D wind data.
REAL(ReKi), ALLOCATABLE :: FDuData (:,:,:,:) ! The u-component array of all 4D wind data when used with advection.
REAL(ReKi), ALLOCATABLE :: FDvData (:,:,:,:) ! The v-component array of all 4D wind data when used with advection.
REAL(ReKi), ALLOCATABLE :: FDwData (:,:,:,:) ! The w-component array of all 4D wind data when used with advection.
REAL(ReKi) :: Lx ! Fractional location of tower centerline from upwind end to downwind end of the dataset.
REAL(ReKi) :: Ly ! Fractional location of tower centerline from right (looking downwind) to left side of the dataset.
REAL(ReKi) :: Lz ! Fractional location of hub height from bottom to top of dataset.
REAL(ReKi) :: Offsets (3) ! Offsets to convert integer data to actual wind speeds.
REAL(ReKi), SAVE :: PrevTime ! The previous time this was called -- so we can go back in time if necessary
REAL(ReKi) :: RotDiam ! Rotor diameter.
REAL(ReKi) :: ScalFact (3) ! Scaling factors to convert integer data to actual wind speeds.
REAL(ReKi) :: ScaleVel ! Scaling velocity, U0. 2*U0 is the difference in wind speed between the top and bottom of the wave.
REAL(ReKi), ALLOCATABLE :: Times4D (:) ! The list of times for the 4D-wind input files.
REAL(ReKi) :: Tm_max ! The total nondimensional time of the dataset.
REAL(ReKi) :: TSclFact ! Scale factor for time (h/U0).
REAL(ReKi) :: T_4D_En ! Time at which the wave event ends.
REAL(ReKi) :: T_4D_St ! Time at which the wave event starts.
REAL(ReKi) :: Xmax ! The dimensional downwind length of the dataset.
REAL(ReKi) :: Xt ! Distance of the tower from the upwind end of the dataset.
REAL(ReKi) :: Ymax ! The dimensional lateral width of the dataset.
REAL(ReKi) :: Yt ! Distance of the tower from the right side of the dataset (looking downwind).
REAL(ReKi) :: Zmax ! The dimensional vertical height of the dataset.
REAL(ReKi) :: Zt ! Distance of the hub from the bottom of the dataset.
REAL(ReKi) :: Zref ! The reference height (hub height)
INTEGER :: FD_DF_X ! The decimation factor for the 4D wind data in the x direction.
INTEGER :: FD_DF_Y ! The decimation factor for the 4D wind data in the y direction.
INTEGER :: FD_DF_Z ! The decimation factor for the 4D wind data in the z direction.
INTEGER :: FDFileNo ! The 4D wind file number.
INTEGER :: FDRecL ! The length, in bytes, of the LE binary records.
INTEGER :: Ind4DAdv ! Index of the file to be used in advection
INTEGER :: Ind4Dnew ! Index of the newest 4D wind file.
INTEGER :: Ind4Dold ! Index of the older 4D wind file.
INTEGER :: Num4Dt ! The number of 4D wind grids, one grid per time step.
INTEGER, PARAMETER :: Num4DtD = 2 ! The number of 4D wind grids stored in memory, normally 2
INTEGER :: Num4Dx ! The number of 4D wind grid points in the x direction.
INTEGER :: Num4DxD ! The decimated number of 4D wind grid points in the x direction.
INTEGER :: Num4DxD1 ! The decimated number of 4D wind grid points in the x direction minus 1.
INTEGER :: Num4Dy ! The number of 4D wind grid points in the y direction.
INTEGER :: Num4DyD ! The decimated number of 4D wind grid points in the y direction.
INTEGER :: Num4DyD1 ! The decimated number of 4D wind grid points in the y direction minus 1.
INTEGER :: Num4Dz ! The number of 4D wind grid points in the z direction.
INTEGER :: Num4DzD ! The decimated number of 4D wind grid points in the z direction.
INTEGER :: Num4DzD1 ! The decimated number of 4D wind grid points in the z direction minus 1.
INTEGER :: NumAdvect ! Number of frozen timesteps to advect past the turbine
INTEGER :: Shft4Dnew ! Number of times the x-data needs to be shifted for advection
INTEGER, ALLOCATABLE :: Times4DIx (:) ! Index number of the 4D time files (used for advection)
INTEGER :: FDUnit ! Unit number for reading wind files
LOGICAL :: Advect ! Flag to indicate whether or not to advect a given data set or to just use the time step files
LOGICAL :: VertShft ! Flag to indicate whether or not to shift the z values for the w component.
LOGICAL, SAVE :: Initialized = .FALSE.
CHARACTER(5), ALLOCATABLE :: AdvFiles (:)
CHARACTER(1024) :: FDSpath ! The path to the 4D wind files.
PUBLIC :: FD_Init
PUBLIC :: FD_GetWindSpeed
PUBLIC :: FD_Terminate
PUBLIC :: FD_GetValue
CONTAINS
!====================================================================================================
SUBROUTINE FD_Init(UnWind, WindFile, RefHt, ErrStat)
! This subroutine is called at the beginning of a simulation to initialize the module.
!----------------------------------------------------------------------------------------------------
! Passed variables
INTEGER, INTENT(IN) :: UnWind ! unit number for reading wind files
CHARACTER(*), INTENT(IN) :: WindFile ! Name of the 4D wind parameter file (.fdp)
REAL(ReKi), INTENT(IN) :: RefHt ! The reference height for the billow (should be hub height)
INTEGER, INTENT(OUT) :: ErrStat ! return 0 if no errors; non-zero otherwise
! Local variables
CHARACTER(1024) :: FDTSfile ! name of the 4D time step file
REAL(ReKi) :: FDTimStp ! Average time step for 4D wind data.
INTEGER :: IT
!-------------------------------------------------------------------------------------------------
! Check that the module hasn't already been initialized.
!-------------------------------------------------------------------------------------------------
IF ( Initialized ) THEN
CALL WrScr( ' FDWind has already been initialized.' )
ErrStat = 1
RETURN
ELSE
ErrStat = 0
CALL NWTC_Init()
END IF
!-------------------------------------------------------------------------------------------------
! Set the reference height for the wind file (this takes the place of HH that was used earlier)
!-------------------------------------------------------------------------------------------------
ZRef = RefHt
!-------------------------------------------------------------------------------------------------
! Read the main 4D input file
!-------------------------------------------------------------------------------------------------
CALL ReadFDP( UnWind, WindFile, FDTSfile, ErrStat )
IF ( ErrStat /= 0 ) RETURN
!-------------------------------------------------------------------------------------------------
! Get the times array, which must be scaled and shifted later using TSclFact and T_4D_St
!-------------------------------------------------------------------------------------------------
CALL Read4Dtimes ( UnWind, FDTSfile, ErrStat )
IF ( ErrStat /= 0 ) RETURN
!-------------------------------------------------------------------------------------------------
! Calculate some values that don't change during the run.
!-------------------------------------------------------------------------------------------------
FDRecL = 2*Num4Dx*Num4Dy ! The length, in bytes, of the 4D binary records.
Num4DxD = ( Num4Dx + FD_DF_X - 1 )/FD_DF_X ! The decimated number of 4D wind grid points in the x direction.
Num4DyD = ( Num4Dy + FD_DF_Y - 1 )/FD_DF_Y ! The decimated number of 4D wind grid points in the y direction.
Num4DzD = ( Num4Dz + FD_DF_Z - 1 )/FD_DF_Z ! The decimated number of 4D wind grid points in the z direction.
Num4DxD1 = Num4DxD - 1 ! The decimated number of 4D wind grid points in the x direction minus 1.
Num4DyD1 = Num4DyD - 1 ! The decimated number of 4D wind grid points in the y direction minus 1.
Num4DzD1 = Num4DzD - 1 ! The decimated number of 4D wind grid points in the z direction minus 1.
Tm_max = Times4D(Num4Dt) ! Time of end of dataset.
IF ( ADVECT ) THEN
FDTimStp = Xmax / ( ( Num4Dx - 1 )*( ScaleVel )*Num4Dt ) ! The timestep is calculated by the approximation dx/dt ~= U0 (divide by num4dt to get delta for a full timestep).
FDper = FDTimStp * Num4Dt ! Total time in dataset. (We have periodic time, so multiply by number of time steps, without subtracting 1)
TSclFact = FDper / Tm_max ! Equivalent scale factor for time.
ELSE
FDper = TSclFact*Tm_max ! Total time in dataset.
FDTimStp = FDper/( Num4Dt - 1 ) ! Average time step.
ENDIF
T_4D_En = T_4D_St + FDper ! Time for the end of the dataset.
Xt = Xmax*Lx ! Distance of the tower from the upwind end of the dataset.
Yt = Ymax*Ly ! Distance of the tower from the right side of the dataset (looking downwind).
Zt = Zmax*Lz ! Distance of the hub from the bottom of the dataset.
DelXgrid = 1.0/Num4DxD1 ! The nondimensional distance between grid points in the x direction.
DelYgrid = 1.0/Num4DyD1 ! The nondimensional distance between grid points in the y direction.
DelZgrid = 1.0/Num4DzD1 ! The nondimensional distance between grid points in the z direction.
!-------------------------------------------------------------------------------------------------
! Scale and shift the times array using TSclFact and T_4D_St
!-------------------------------------------------------------------------------------------------
DO IT=1,Num4Dt
Times4D(IT) = TSclFact*Times4D(IT) + T_4D_St
ENDDO ! IT
!-------------------------------------------------------------------------------------------------
! Allocate velocity arrays and fill Data arrays for advection (DNS files)
!-------------------------------------------------------------------------------------------------
IF (.NOT. ALLOCATED(FDu) ) THEN
! CALL AllocAry ( FDu, Num4DxD, Num4DyD, Num4DzD, 2, 'U-component velocity array (FDu)', ErrStat)
ALLOCATE ( FDu(Num4DxD,Num4DyD,Num4DzD,2), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the U-component velocity array (FDu) array.' )
RETURN
END IF
END IF
IF (.NOT. ALLOCATED(FDv) ) THEN
! CALL AllocAry ( FDv, Num4DxD, Num4DyD, Num4DzD, 2, 'V-component velocity array (FDv)', ErrStat)
ALLOCATE ( FDv(Num4DxD,Num4DyD,Num4DzD,2), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the V-component velocity array (FDv) array.' )
RETURN
END IF
END IF
IF (.NOT. ALLOCATED(FDw) ) THEN
! CALL AllocAry ( FDw, Num4DxD, Num4DyD, Num4DzD, 2, 'W-component velocity array (FDw)', ErrStat)
ALLOCATE ( FDw(Num4DxD,Num4DyD,Num4DzD,2), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the W-component velocity array (FDw) array.' )
RETURN
END IF
END IF
IF ( ADVECT ) THEN
IF (.NOT. ALLOCATED(FDuData) ) THEN
! CALL AllocAry ( FDuData, Num4DxD, Num4DyD, Num4DzD, Num4Dt, 'U-component velocity array (FDuData)', ErrStat)
ALLOCATE ( FDuData(Num4DxD,Num4DyD,Num4DzD,Num4Dt), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the U-component velocity array (FDuData) array.' )
RETURN
END IF
END IF
IF (.NOT. ALLOCATED(FDvData) ) THEN
! CALL AllocAry ( FDvData, Num4DxD, Num4DyD, Num4DzD, Num4Dt, 'V-component velocity array (FDvData)', ErrStat)
ALLOCATE ( FDvData(Num4DxD,Num4DyD,Num4DzD,Num4Dt), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the V-component velocity array (FDvData) array.' )
RETURN
END IF
END IF
IF (.NOT. ALLOCATED(FDwData) ) THEN
! CALL AllocAry ( FDwData, Num4DxD, Num4DyD, Num4DzD, Num4Dt, 'W-component velocity array (FDwData)', ErrStat)
ALLOCATE ( FDwData(Num4DxD,Num4DyD,Num4DzD,Num4Dt), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the W-component velocity array (FDwData) array.' )
RETURN
END IF
END IF
CALL ReadAll4DData(UnWind, ErrStat) !This needs AdvFiles(:), which was is read in ReadFDP()
IF ( ErrStat /= 0 ) RETURN
ENDIF
!-------------------------------------------------------------------------------------------------
! Determine the first file needed for this simulation.
!-------------------------------------------------------------------------------------------------
Ind4Dold = 1 ! Put the old stuff in the first part of the array.
Ind4Dnew = 2 ! Put the new stuff in the second part of the array.
Shft4Dnew = 0
IF ( T_4D_St >= 0.0 ) THEN
FDFileNo = 1
ELSE
FDFileNo = Num4Dt
DO IT=1,Num4Dt
IF ( Times4D(IT) > 0.0 ) THEN
FDFileNo = IT - 1
EXIT
END IF
END DO ! IT
END IF
!-------------------------------------------------------------------------------------------------
! Open, read, and close the first set of files.
!-------------------------------------------------------------------------------------------------
FDTime(Ind4Dold) = Times4D(FDFileNo) ! Set the time for this file.
IF ( ADVECT ) THEN
CALL Load4DData(Ind4Dold) ! load data stored in FDuData, FDvData, and FDwData arrays
ELSE
CALL LoadLESData( UnWind, FDFileNo, Ind4Dold, ErrStat )
END IF
!-------------------------------------------------------------------------------------------------
! Open, read, and close the second set of files.
!-------------------------------------------------------------------------------------------------
FDFileNo = FDFileNo + 1
IF ( ADVECT ) THEN
FDFileNo = MOD(FDFileNo-1,Num4Dt) + 1
IF (FDFileNo == 1) THEN
Shft4Dnew = Shft4Dnew + 1
IF (Ind4DAdv <= NumAdvect) THEN ! Ind4DAdv was set in ReadFDP
IF ( MOD( Shft4Dnew, Num4Dx ) == 0 ) THEN
CALL ReadAll4DData(UnWind, ErrStat)
IF ( ErrStat /= 0 ) RETURN
END IF
END IF
ENDIF
FDTime(Ind4Dnew) = Times4D(FDFileNo) + Shft4Dnew*FDPer ! Set the time for this file.
CALL Load4DData( Ind4Dnew ) ! shift the data
ELSE
FDTime(Ind4Dnew) = Times4D(FDFileNo) ! Set the time for this file.
CALL LoadLESData( UnWind, FDFileNo, Ind4Dnew, ErrStat )
ENDIF
!-------------------------------------------------------------------------------------------------
! Set the initialization flag
!-------------------------------------------------------------------------------------------------
FDUnit = UnWind
PrevTime = 0.0
Initialized = .TRUE.
RETURN
END SUBROUTINE FD_Init
!====================================================================================================
SUBROUTINE ReadFDP ( UnWind, FileName, FDTSfile, ErrStat )
! This subroutine is used to read the input parameters for the large-eddy simulation.
!----------------------------------------------------------------------------------------------------
! Passed variables
INTEGER, INTENT(IN) :: UnWind ! unit number for reading wind files
CHARACTER(*), INTENT(IN) :: FileName ! Then name of the LE data file.
CHARACTER(*), INTENT(OUT) :: FDTSfile ! The name of the file containing the time-step history of the wind files.
INTEGER, INTENT(OUT) :: ErrStat ! return 0 if no errors encountered; non-zero otherwise
! Local variables
CHARACTER(1024) :: HeaderLine
CHARACTER(1),PARAMETER :: Comp(3) = (/'U', 'V', 'W' /) ! the wind components
REAL(ReKi) :: CoefTE ! Coefficient of thermal expansion.
REAL(ReKi) :: DistScal ! Disturbance scale (ratio of wave height to rotor diameter) from input file.
REAL(ReKi) :: Grav ! Gravitational acceleration.
REAL(ReKi) :: LenScale ! Length scale (h).
REAL(ReKi) :: Ri ! Richardson number.
REAL(ReKi) :: Ubot ! Steady u-component wind speed at the bottom of the wave.
REAL(ReKi) :: Zm_maxo ! The nondimensional vertical height of the untrimmed dataset.
REAL(ReKi) :: Xm_max ! The nondimensional downwind length of the dataset.
REAL(ReKi) :: Ym_max ! The nondimensional lateral width of the dataset.
REAL(ReKi) :: Zm_max ! The nondimensional vertical height of the dataset.
INTEGER :: I
!-------------------------------------------------------------------------------------------------
! Open the 4D parameter file for reading
!-------------------------------------------------------------------------------------------------
CALL OpenFInpFile ( UnWind, TRIM( FileName ), ErrStat)
IF (ErrStat /= 0) RETURN
!-------------------------------------------------------------------------------------------------
! Read the 4D parameter input file
!-------------------------------------------------------------------------------------------------
!..............................................................................................
! Read the 4D wind parameters specific to this turbine simulation.
!..............................................................................................
CALL ReadStr( UnWind, TRIM( FileName ), HeaderLine, 'Header line', 'The header line in the FTP file', ErrStat )
IF (ErrStat /= 0) RETURN
CALL WrScr ( ' Heading of the 4D-wind-parameter file: "'//TRIM(HeaderLine)//'"' )
CALL ReadCom( UnWind, TRIM( FileName ), 'Header line', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), FDSpath, 'FDSpath', 'Location (path) of the binary dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), FDTSfile, 'FDTSfile', &
'Name of the file containing the time-step history of the wind files', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Ubot, 'Ubot', 'Steady u-component wind speed at the bottom of the wave', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), DistScal, 'DistScal', 'Disturbance scale', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Lx, 'Lx', &
'Fractional location of tower centerline from upwind end to downwind end of the dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Ly, 'Ly', &
'Fractional location of tower centerline from right (looking downwind) to left side of the dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Lz, 'Lz', &
'Fractional location of hub height from bottom to top of dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), T_4D_St, 'T_4D_St', 'Time at which the wave event starts', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), ScaleVel, 'ScaleVel', &
'Scaling velocity, U0: half the difference in wind speed between the top and bottom of the billow.', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), RotDiam, 'RotDiam', 'Rotor diameter', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), FD_DF_X, 'FD_DF_X', 'Decimation factor in X direction', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), FD_DF_Y, 'FD_DF_Y', 'Decimation factor in Y direction', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), FD_DF_Z, 'FD_DF_Z', 'Decimation factor in Z direction', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadCom( UnWind, TRIM( FileName ), 'blank line', ErrStat )
IF (ErrStat /= 0) RETURN
!..............................................................................................
! Read the 4D wind parameters specific to the K-H billow simulation being used.
!..............................................................................................
CALL ReadCom( UnWind, TRIM( FileName ), 'LES parameters specific to the K-H billow simulation being used', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), VertShft, 'VertShft', &
'Flag to indicate whether or not to shift the z values for the w component', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Xm_max, 'Xm_max', &
'Maximum nondimensional downwind distance from center of dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Ym_max, 'Ym_max', &
'Maximum nondimensional lateral distance from center of dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Zm_max, 'Zm_max', &
'Maximum nondimensional vertical distance from center of dataset', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Zm_maxo, 'Zm_maxo', &
'Maximum nondimensional vertical distance from center of untrimmed dataset', ErrStat )
IF (ErrStat /= 0) RETURN
DO I = 1,3
CALL ReadVar( UnWind, TRIM( FileName ), ScalFact(I), Comp(I)//'Scl', &
Comp(I)//'-component scale factor for converting from integers to reals', ErrStat )
IF (ErrStat /= 0) RETURN
ScalFact(I) = ScalFact(I) * ScaleVel
CALL ReadVar( UnWind, TRIM( FileName ), Offsets(I), Comp(I)//'Off', &
Comp(I)//'-component offset for converting from integers to reals', ErrStat )
IF (ErrStat /= 0) RETURN
Offsets(I) = Offsets(I) * ScaleVel
END DO
Offsets (1) = Offsets (1) + ScaleVel + Ubot ! u-component offset to convert integer data to actual wind speeds.
CALL ReadVar( UnWind, TRIM( FileName ), Num4Dt, 'Num4Dt', 'The number of LE grids, one grid per time step', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Num4Dx, 'Num4Dx', 'The number of LE grid points in the x direction', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Num4Dy, 'Num4Dy', 'The number of LE grid points in the y direction', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Num4Dz, 'Num4Dz', 'The number of LE grid points in the z direction', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Ri, 'Ri', 'Richardson number', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), CoefTE, 'CoefTE', 'Coefficient of thermal expansion', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Grav, 'Grav', 'Gravitational acceleration', ErrStat )
IF (ErrStat /= 0) RETURN
CALL ReadVar( UnWind, TRIM( FileName ), Advect, 'Advect', 'Advection flag', ErrStat )
IF (ErrStat /= 0) THEN
Advect = .FALSE.
Ind4DAdv = 0
ErrStat = 0
CALL WrScr( ' Advection will not be used.')
ELSE
IF (Advect) THEN
IF ( FD_DF_X /= 1 ) THEN
CALL WrScr( ' FD_DF_X must be 1 when using advection. ' )
FD_DF_X = 1
ENDIF
CALL ReadVar( UnWind, TRIM( FileName ), NumAdvect, 'NumAdvect', 'Number of 4D files for advection', ErrStat )
IF (ErrStat /= 0) RETURN
IF ( NumAdvect < 1 ) THEN
CALL WrScr( ' NumAdvect in 4D-wind-parameter file, "'//TRIM( FileName )//'," must be at least 1.' )
ErrStat = 1
RETURN
ENDIF
IF ( .NOT. ALLOCATED( AdvFiles ) ) THEN
! CALL AllocAry( AdvFiles, NumAdvect, 'AdvFiles array', ErrStat )
ALLOCATE ( AdvFiles(NumAdvect), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the AdvFiles array.' )
RETURN
END IF
ENDIF
CALL ReadAryLines( UnWind, TRIM( FileName ), AdvFiles, NumAdvect, 'AdvFiles', 'Advection file names', ErrStat )
IF (ErrStat /= 0) RETURN
Ind4DAdv = 1
ELSE
Ind4DAdv = 0
ENDIF !Advect == .TRUE.
END IF
!-------------------------------------------------------------------------------------------------
! Close the 4D parameter input file
!-------------------------------------------------------------------------------------------------
CLOSE ( UnWind )
!-------------------------------------------------------------------------------------------------
! Close the 4D parameter input file
!-------------------------------------------------------------------------------------------------
LenScale = RotDiam*DistScal/Zm_max ! Length scale (h).
Xmax = Xm_max*LenScale ! The dimensional length of the dataset.
Ymax = Ym_max*LenScale ! The dimensional width of the dataset
Zmax = Zm_max*LenScale ! The dimensional vertical height of the dataset.
TSclFact = LenScale/ScaleVel ! Scale factor for time (h/U0).
RETURN
END SUBROUTINE ReadFDP
!====================================================================================================
SUBROUTINE Read4Dtimes ( UnWind, FileName, ErrStat )
! This subroutine is used to read the time array for the 4D data. The times in the file are
! non-dimensional and non-uniformly spaced. They are scaled using TSclFact to obtain units of seconds
! and T_4D_St is added to allow the billow to start at non-zero time.
!----------------------------------------------------------------------------------------------------
! Passed variables
INTEGER, INTENT(IN) :: UnWind ! unit number for reading wind files
CHARACTER(*), INTENT(IN) :: FileName ! Then name of the LE data file.
INTEGER, INTENT(OUT) :: ErrStat ! return 0 if no errors encountered; non-zero otherwise
! Local variables
INTEGER :: I ! Loop counter
!-------------------------------------------------------------------------------------------------
! Allocate arrays to store the data in
!-------------------------------------------------------------------------------------------------
IF (.NOT. ALLOCATED( Times4D) ) THEN
! CALL AllocAry( Times4D, Num4Dt, '4D time array', ErrStat)
ALLOCATE ( Times4D(Num4Dt), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the Times4D array.' )
RETURN
END IF
END IF
IF (.NOT. ALLOCATED( Times4DIx) ) THEN
! CALL AllocAry( Times4DIx, Num4Dt, '4D time array', ErrStat)
ALLOCATE ( Times4DIx(Num4Dt), STAT=ErrStat )
IF ( ErrStat /= 0 ) THEN
CALL WrScr ( ' Error allocating memory for the Times4DIx array.' )
RETURN
END IF
END IF
!-------------------------------------------------------------------------------------------------
! Open the 4D times file
!-------------------------------------------------------------------------------------------------
CALL OpenFInpFile ( UnWind, TRIM( FileName ), ErrStat)
IF ( ErrStat /= 0 ) RETURN
!-------------------------------------------------------------------------------------------------
! Read the 4D times file
!-------------------------------------------------------------------------------------------------
CALL ReadCom( UnWind, TRIM( FileName ), 'first line', ErrStat)
IF ( ErrStat /= 0 ) RETURN
DO I=1,Num4Dt
READ (UnWind,*,IOSTAT=ErrStat) Times4DIx(I), Times4D(I)
IF ( ErrStat /= 0 ) THEN
CALL WrScr( ' Error reading line '//TRIM( Int2LStr( I+1 ) )// &
' of the 4D-wind time-steps file, "'//TRIM( FileName )//'."')
RETURN
ENDIF
ENDDO ! I
!-------------------------------------------------------------------------------------------------
! Close the 4D times file
!-------------------------------------------------------------------------------------------------
CLOSE ( UnWind )
RETURN
END SUBROUTINE Read4Dtimes
!====================================================================================================
SUBROUTINE ReadAll4DData(UnWind, ErrStat)
! This subroutine reads the data into one array to be accessed later when ADVECT=.TRUE. Since there
! are just a few time steps, we'll load them into memory to (hopefully) save I/O time.
!----------------------------------------------------------------------------------------------------
INTEGER, INTENT(IN) :: UnWind
INTEGER, INTENT(OUT) :: ErrStat !
INTEGER :: IT
CHARACTER(1) :: FDNum
CHARACTER(20) :: DNSFileName ! String containing part of the current file name.
DO IT = 1,Num4Dt
WRITE(FDNum,'(I1.1)') Times4DIx(IT)
DNSFileName = TRIM(AdvFiles(Ind4DAdv))//'_'//TRIM(FDNum)//'.dns'
CALL Read4DData ( UnWind, TRIM( FDSpath )//'\u\u_16i_'//TRIM(DNSFileName), FDuData, IT, ScalFact(1), Offsets(1), ErrStat )
IF ( ErrStat /= 0 ) RETURN
CALL Read4DData ( UnWind, TRIM( FDSpath )//'\v\v_16i_'//TRIM(DNSFileName), FDvData, IT, ScalFact(2), Offsets(2), ErrStat )
IF ( ErrStat /= 0 ) RETURN
CALL Read4DData ( UnWind, TRIM( FDSpath )//'\w\w_16i_'//TRIM(DNSFileName), FDwData, IT, ScalFact(3), Offsets(3), ErrStat )
IF ( ErrStat /= 0 ) RETURN
ENDDO ! IT
Ind4DAdv = Ind4DAdv + 1
RETURN
END SUBROUTINE ReadAll4DData
!====================================================================================================
SUBROUTINE LoadLESData( UnWind, FileNo, Indx, ErrStat )
! This subroutine reads binary data from the U, V, and W files and stores them in the arrays FDu,
! FDv, and FDw (by calling Read4DData).
!----------------------------------------------------------------------------------------------------
! Passed variables
INTEGER, INTENT(IN) :: UnWind ! unit number for reading wind files
INTEGER, INTENT(IN) :: FileNo ! current file number to read
INTEGER, INTENT(IN) :: Indx ! index into the data arrays
INTEGER, INTENT(OUT) :: ErrStat ! return 0 if no errors encountered; non-zero otherwise
! local variables
CHARACTER(5) :: FDNum
CHARACTER(20) :: LESFileName ! String containing part of the current file name.
! get the file name for the file number
WRITE(FDNum,'(I5.5)', IOStat=ErrStat) FileNo
IF ( ErrStat /= 0 ) RETURN
LESFileName = TRIM(FDNum)//'.les'
! set the paths and read the data for each component
CALL Read4DData ( UnWind, TRIM( FDSpath )//'\u\u_16i_'//TRIM(LESFileName), FDu, Indx, ScalFact(1), Offsets(1), ErrStat )
IF ( ErrStat /= 0 ) RETURN
CALL Read4DData ( UnWind, TRIM( FDSpath )//'\v\v_16i_'//TRIM(LESFileName), FDv, Indx, ScalFact(2), Offsets(2), ErrStat )
IF ( ErrStat /= 0 ) RETURN
CALL Read4DData ( UnWind, TRIM( FDSpath )//'\w\w_16i_'//TRIM(LESFileName), FDw, Indx, ScalFact(3), Offsets(3), ErrStat )
END SUBROUTINE LoadLESData
!====================================================================================================
SUBROUTINE Read4DData ( UnWind, FileName, Comp, Indx4, Scale, Offset, ErrStat)
! This subroutine is used to read one time-step's worth of large-eddy wind data for one component
! from a file.
!----------------------------------------------------------------------------------------------------
! Passed variables
INTEGER, INTENT(IN) :: UnWind ! The I/O unit of the LE file.
CHARACTER(*),INTENT(IN) :: FileName ! Then name of the LE data file.
REAL(ReKi), INTENT(INOUT) :: Comp (:,:,:,:) ! The velocity array [do NOT make this INTENT(OUT): other parts of the array may become undefined]
INTEGER, INTENT(IN) :: Indx4 ! The index of the 4th dimension of Comp, which is to be read.
REAL(ReKi), INTENT(IN) :: Scale ! The scale factor for converting from intergers to non-normalized reals.
REAL(ReKi), INTENT(IN) :: Offset ! The offset for converting from intergers to non-normalized reals.
INTEGER, INTENT(OUT) :: ErrStat ! The returned status of a READ.
! Local variables
INTEGER :: IX ! A DO index for indexing the arrays in the x direction.
INTEGER :: IXK ! An index for the decimated arrays in the x direction.
INTEGER :: IY ! A DO index for indexing the arrays in the y direction.
INTEGER :: IYK ! An index for the decimated arrays in the y direction.
INTEGER :: IZ ! A DO index for indexing the arrays in the z direction.
INTEGER :: IZK ! An index for the decimated arrays in the z direction.
INTEGER(B2Ki) :: Com (Num4Dx,Num4Dy) ! Temporary array to hold component's integer values for a given Z.
!-------------------------------------------------------------------------------------------------
! Open the binary input file
!-------------------------------------------------------------------------------------------------
CALL OpenUInBEFile( UnWind, TRIM( FileName ), FDRecL, ErrStat )
IF ( ErrStat /= 0 ) RETURN
!-------------------------------------------------------------------------------------------------
! Read the input file
!-------------------------------------------------------------------------------------------------
IZK = 0
DO IZ=1,Num4Dz,FD_DF_Z
READ (UnWind,REC=IZ,IOSTAT=ErrStat) Com
IF ( ErrStat /= 0 ) THEN
CALL WrScr( ' Error reading record '//TRIM( Int2LStr( IZ ) )// &
' of the binary 4D wind file, "'//TRIM( FileName )//'".')
RETURN
ENDIF
IZK = IZK + 1 ! IZK = ( IZ - 1 + FD_DF_Z )/FD_DF_Z
IYK = 0
DO IY=1,Num4Dy,FD_DF_Y
IYK = IYK + 1 ! IYK = ( IY - 1 + FD_DF_Y )/FD_DF_Y
DO IX=1,Num4Dx,FD_DF_X
! shift the x-index, if necessary, to perform Advection
!IXK = ( IX + FD_DF_X - 1 )/FD_DF_X
IXK = ( MOD(IX+Shft4Dnew-1,Num4Dx) + FD_DF_X )/FD_DF_X
Comp(IXK,IYK,IZK,Indx4) = Scale*Com(IX,IY) + Offset
ENDDO ! IX
ENDDO ! IY
ENDDO ! IZ
!-------------------------------------------------------------------------------------------------
! Close the file
!-------------------------------------------------------------------------------------------------
CLOSE ( UnWind )
RETURN
END SUBROUTINE Read4DData
!====================================================================================================
SUBROUTINE Load4DData( InpIndx )
! This subroutine takes the data from the storage array (used when ADVECT=.TRUE., shifts it if necessary,
! and loads it into the array for the time slice indexed by InpIndx.
!----------------------------------------------------------------------------------------------------
INTEGER, INTENT(IN) :: InpIndx
INTEGER :: IX
INTEGER :: IXK
DO IX=1,Num4Dx,FD_DF_X
! shift the x-index, if necessary, to perform Advection
IXK = ( MOD(IX+Shft4Dnew-1,Num4Dx) + FD_DF_X )/FD_DF_X
FDu(IXK,:,:,InpIndx) = FDuData(IX,:,:,FDFileNo)
FDv(IXK,:,:,InpIndx) = FDvData(IX,:,:,FDFileNo)
FDw(IXK,:,:,InpIndx) = FDwData(IX,:,:,FDFileNo)
ENDDO ! IX
RETURN
END SUBROUTINE Load4DData
!====================================================================================================
FUNCTION FD_GetValue(RVarName, ErrStat)
! This function returns a real scalar value whose name is listed in the RVarName input argument.
! If the name is not recognized, an error is returned in ErrStat.
!----------------------------------------------------------------------------------------------------
CHARACTER(*), INTENT(IN) :: RVarName
INTEGER, INTENT(OUT) :: ErrStat
REAL(ReKi) :: FD_GetValue
CHARACTER(20) :: VarNameUC
!-------------------------------------------------------------------------------------------------
! Check that the module has been initialized.
!-------------------------------------------------------------------------------------------------
IF ( .NOT. Initialized ) THEN
CALL WrScr( ' Initialialize the FDWind module before calling its subroutines.' )
ErrStat = 1
RETURN
ELSE
ErrStat = 0
END IF
!-------------------------------------------------------------------------------------------------
! Return the requested values.
!-------------------------------------------------------------------------------------------------
VarNameUC = RVarName
CALL Conv2UC( VarNameUC )
SELECT CASE ( TRIM(VarNameUC) )
CASE ('ROTDIAM' )
FD_GetValue = RotDiam
CASE DEFAULT
CALL WrScr( ' Invalid variable name in FD_GetRValue().' )
ErrStat = 1
END SELECT
END FUNCTION FD_GetValue
!====================================================================================================
FUNCTION FD_GetWindSpeed(Time, InputPosition, ErrStat)
! This function is used to interpolate into the 4D wind arrays. It receives X, Y, Z and TIME from the
! calling routine. The time since the start of the 4D data is used to decide which pair of time slices
! to interpolate within and between. After finding the two time slices, it decides which eight grid
! points bound the (X,Y,Z) pair. It does a trilinear interpolation for each time slice. Linear
! interpolation is then used to interpolate between time slices. This routine assumes that X is
! downwind, Y is to the left when looking downwind and Z is up. It also assumes that no
! extrapolation will be needed except in time and the Z direction. In those cases, the appropriate
! steady winds are used.
!----------------------------------------------------------------------------------------------------
! Passed variables:
REAL(ReKi), INTENT(IN) :: Time ! the time
REAL(ReKi), INTENT(IN) :: InputPosition(3) ! structure that contains the position
INTEGER, INTENT(OUT):: ErrStat ! returns 0 if no error; non-zero otherwise
TYPE(InflIntrpOut) :: FD_GetWindSpeed ! the resultant wind speed
! Local Variables:
REAL(ReKi) :: Ixhyz ! Temporary interpolated value.
REAL(ReKi) :: Ixlyz ! Temporary interpolated value.
REAL(ReKi) :: Ixyzo ! Temporary interpolated value.
REAL(ReKi) :: Iyhz ! Temporary interpolated value.
REAL(ReKi) :: Iylz ! Temporary interpolated value.
REAL(ReKi) :: Ixyzn ! Temporary interpolated value.
REAL(ReKi) :: Tgrid ! Fractional distance between time grids.
REAL(ReKi) :: Xgrid ! Fractional distance between grids in the x direction.
REAL(ReKi) :: Xnorm ! Nondimensional downwind distance of the analysis point from upwind end of dataset.
REAL(ReKi) :: Ygrid ! Fractional distance between grids in the y direction.
REAL(ReKi) :: Ynorm ! Nondimensional lateral distance of the analysis point from right side of dataset (looking downwind).
REAL(ReKi) :: Zgrid ! Fractional distance between grids in the z direction.
REAL(ReKi) :: Zgrid_w ! Fractional distance between grids in the z direction for the w component.
REAL(ReKi) :: Znorm ! Nondimensional vertical distance of the analysis point from bottom of dataset.
REAL(ReKi) :: Znorm_w ! Nondimensional vertical distance of the analysis point from bottom of dataset for the w component.
INTEGER :: IT ! Index for do loop
INTEGER :: IXHI ! Index for the more-positive x value.
INTEGER :: IXLO ! Index for the more-negative x value.
INTEGER :: IYHI ! Index for the more-positive y value.
INTEGER :: IYLO ! Index for the more-negative y value.
INTEGER :: IZHI ! Index for the more-positive z value.
INTEGER :: IZHI_w ! Index for the more-positive z value for the w component.
INTEGER :: IZLO ! Index for the more-negative z value.
INTEGER :: IZLO_w ! Index for the more-negative z value for the w component.
!-------------------------------------------------------------------------------------------------
! Check that we've initialized everything first
!-------------------------------------------------------------------------------------------------
IF ( .NOT. Initialized ) THEN
CALL WrScr( ' Initialialize the FDWind module before calling its subroutines.' )
ErrStat = 1
RETURN
ELSE
ErrStat = 0
END IF
!-------------------------------------------------------------------------------------------------
! If the TIME is greater than the time for the last file read, read another set of files until we straddle the current time.
! Stick with the last file if we've exhausted the data.
! We're assuming here that the simulation time step is smaller than the wind-file time step.
!-------------------------------------------------------------------------------------------------
IF ( Time < PrevTime .AND. Time < FDTime(Ind4Dold) ) THEN ! bjj: GET THE CORRECT TIME if we're going backward!
!----------------------------------------------------------------------------------------------
! Determine the first file needed for this simulation.
!----------------------------------------------------------------------------------------------
Ind4Dold = 1 ! Put the old stuff in the first part of the array.
Ind4Dnew = 2 ! Put the new stuff in the second part of the array.
FDFileNo = Num4Dt
DO IT=1,Num4Dt
IF ( Times4D(IT) > Time ) THEN
FDFileNo = IT - 1
EXIT
END IF
END DO ! IT
!----------------------------------------------------------------------------------------------
! Open, read, and close the first set of files.
!----------------------------------------------------------------------------------------------
FDTime(Ind4Dold) = Times4D(FDFileNo) ! Set the time for this file.
IF ( ADVECT ) THEN
CALL Load4DData(Ind4Dold) ! load data stored in FDuData, FDvData, and FDwData arrays
ELSE
CALL LoadLESData( FDUnit, FDFileNo, Ind4Dold, ErrStat )
END IF
!----------------------------------------------------------------------------------------------
! Open, read, and close the second set of files.
!----------------------------------------------------------------------------------------------