-
Notifications
You must be signed in to change notification settings - Fork 0
/
FAST_Subs.f90
7927 lines (6367 loc) · 425 KB
/
FAST_Subs.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
!**********************************************************************************************************************************
! FAST_Solver.f90, FAST_Subs.f90, FAST_Lin.f90, and FAST_Mods.f90 make up the FAST glue code in the FAST Modularization Framework.
! FAST_Prog.f90, FAST_Library.f90, FAST_Prog.c are different drivers for this code.
!..................................................................................................................................
! LICENSING
! Copyright (C) 2013-2016 National Renewable Energy Laboratory
!
! This file is part of FAST.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!**********************************************************************************************************************************
MODULE FAST_Subs
USE FAST_Solver
USE FAST_Linear
USE Waves, ONLY : WaveGrid_n
USE SC_DataEx
USE VersionInfo
USE ZeroMQInterface
IMPLICIT NONE
CONTAINS
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! INITIALIZATION ROUTINES
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!> a wrapper routine to call FAST_Initialize at the full-turbine simulation level (makes easier to write top-level driver)
SUBROUTINE FAST_InitializeAll_T( t_initial, TurbID, Turbine, ErrStat, ErrMsg, InFile, ExternInitData )
REAL(DbKi), INTENT(IN ) :: t_initial !< initial time
INTEGER(IntKi), INTENT(IN ) :: TurbID !< turbine Identifier (1-NumTurbines)
TYPE(FAST_TurbineType), INTENT(INOUT) :: Turbine !< all data for one instance of a turbine
INTEGER(IntKi), INTENT( OUT) :: ErrStat !< Error status of the operation
CHARACTER(*), INTENT( OUT) :: ErrMsg !< Error message if ErrStat /= ErrID_None
CHARACTER(*), OPTIONAL,INTENT(IN ) :: InFile !< A CHARACTER string containing the name of the primary FAST input file (if not present, we'll get it from the command line)
TYPE(FAST_ExternInitType),OPTIONAL,INTENT(IN ) :: ExternInitData !< Initialization input data from an external source (Simulink)
Turbine%TurbID = TurbID
IF (PRESENT(InFile)) THEN
IF (PRESENT(ExternInitData)) THEN
CALL FAST_InitializeAll( t_initial, Turbine%p_FAST, Turbine%y_FAST, Turbine%m_FAST, &
Turbine%ED, Turbine%BD, Turbine%SrvD, Turbine%AD14, Turbine%AD, Turbine%IfW, Turbine%OpFM, Turbine%SC_DX,&
Turbine%HD, Turbine%SD, Turbine%ExtPtfm, Turbine%MAP, Turbine%FEAM, Turbine%MD, Turbine%Orca, &
Turbine%IceF, Turbine%IceD, Turbine%MeshMapData, ErrStat, ErrMsg, InFile, ExternInitData )
ELSE
CALL FAST_InitializeAll( t_initial, Turbine%p_FAST, Turbine%y_FAST, Turbine%m_FAST, &
Turbine%ED, Turbine%BD, Turbine%SrvD, Turbine%AD14, Turbine%AD, Turbine%IfW, Turbine%OpFM, Turbine%SC_DX, &
Turbine%HD, Turbine%SD, Turbine%ExtPtfm, Turbine%MAP, Turbine%FEAM, Turbine%MD, Turbine%Orca, &
Turbine%IceF, Turbine%IceD, Turbine%MeshMapData, ErrStat, ErrMsg, InFile )
END IF
ELSE
CALL FAST_InitializeAll( t_initial, Turbine%p_FAST, Turbine%y_FAST, Turbine%m_FAST, &
Turbine%ED, Turbine%BD, Turbine%SrvD, Turbine%AD14, Turbine%AD, Turbine%IfW, Turbine%OpFM, Turbine%SC_DX, &
Turbine%HD, Turbine%SD, Turbine%ExtPtfm, Turbine%MAP, Turbine%FEAM, Turbine%MD, Turbine%Orca, &
Turbine%IceF, Turbine%IceD, Turbine%MeshMapData, ErrStat, ErrMsg )
END IF
END SUBROUTINE FAST_InitializeAll_T
!----------------------------------------------------------------------------------------------------------------------------------
!> Routine to call Init routine for each module. This routine sets all of the init input data for each module.
SUBROUTINE FAST_InitializeAll( t_initial, p_FAST, y_FAST, m_FAST, ED, BD, SrvD, AD14, AD, IfW, OpFM, SC_DX, HD, SD, ExtPtfm, &
MAPp, FEAM, MD, Orca, IceF, IceD, MeshMapData, ErrStat, ErrMsg, InFile, ExternInitData )
use ElastoDyn_Parameters, only: Method_RK4
REAL(DbKi), INTENT(IN ) :: t_initial !< initial time
TYPE(FAST_ParameterType), INTENT(INOUT) :: p_FAST !< Parameters for the glue code
TYPE(FAST_OutputFileType),INTENT(INOUT) :: y_FAST !< Output variables for the glue code
TYPE(FAST_MiscVarType), INTENT(INOUT) :: m_FAST !< Miscellaneous variables
TYPE(ElastoDyn_Data), INTENT(INOUT) :: ED !< ElastoDyn data
TYPE(BeamDyn_Data), INTENT(INOUT) :: BD !< BeamDyn data
TYPE(ServoDyn_Data), INTENT(INOUT) :: SrvD !< ServoDyn data
TYPE(AeroDyn14_Data), INTENT(INOUT) :: AD14 !< AeroDyn14 data
TYPE(AeroDyn_Data), INTENT(INOUT) :: AD !< AeroDyn data
TYPE(InflowWind_Data), INTENT(INOUT) :: IfW !< InflowWind data
TYPE(OpenFOAM_Data), INTENT(INOUT) :: OpFM !< OpenFOAM data
TYPE(SCDataEx_Data), INTENT(INOUT) :: SC_DX !< SuperController exchange data
TYPE(HydroDyn_Data), INTENT(INOUT) :: HD !< HydroDyn data
TYPE(SubDyn_Data), INTENT(INOUT) :: SD !< SubDyn data
TYPE(ExtPtfm_Data), INTENT(INOUT) :: ExtPtfm !< ExtPtfm_MCKF data
TYPE(MAP_Data), INTENT(INOUT) :: MAPp !< MAP data
TYPE(FEAMooring_Data), INTENT(INOUT) :: FEAM !< FEAMooring data
TYPE(MoorDyn_Data), INTENT(INOUT) :: MD !< Data for the MoorDyn module
TYPE(OrcaFlex_Data), INTENT(INOUT) :: Orca !< OrcaFlex interface data
TYPE(IceFloe_Data), INTENT(INOUT) :: IceF !< IceFloe data
TYPE(IceDyn_Data), INTENT(INOUT) :: IceD !< All the IceDyn data used in time-step loop
TYPE(FAST_ModuleMapType), INTENT(INOUT) :: MeshMapData !< Data for mapping between modules
INTEGER(IntKi), INTENT( OUT) :: ErrStat !< Error status of the operation
CHARACTER(*), INTENT( OUT) :: ErrMsg !< Error message if ErrStat /= ErrID_None
CHARACTER(*), OPTIONAL, INTENT(IN ) :: InFile !< A CHARACTER string containing the name of the primary FAST input file (if not present, we'll get it from the command line)
TYPE(FAST_ExternInitType), OPTIONAL, INTENT(IN) :: ExternInitData !< Initialization input data from an external source (Simulink)
! local variables
CHARACTER(1024) :: InputFile !< A CHARACTER string containing the name of the primary FAST input file
TYPE(FAST_InitData) :: Init !< Initialization data for all modules
REAL(ReKi) :: AirDens ! air density for initialization/normalization of OpenFOAM data
REAL(DbKi) :: dt_IceD ! tmp dt variable to ensure IceDyn doesn't specify different dt values for different legs (IceDyn instances)
REAL(DbKi) :: dt_BD ! tmp dt variable to ensure BeamDyn doesn't specify different dt values for different instances
INTEGER(IntKi) :: ErrStat2
INTEGER(IntKi) :: IceDim ! dimension we're pre-allocating for number of IceDyn legs/instances
INTEGER(IntKi) :: I ! generic loop counter
INTEGER(IntKi) :: k ! blade loop counter
INTEGER(IntKi) :: nNodes ! temp var for OpFM coupling
logical :: CallStart
INTEGER(IntKi) :: NumBl
CHARACTER(ErrMsgLen) :: ErrMsg2
CHARACTER(*), PARAMETER :: RoutineName = 'FAST_InitializeAll'
!..........
ErrStat = ErrID_None
ErrMsg = ""
y_FAST%UnSum = -1 ! set the summary file unit to -1 to indicate it's not open
y_FAST%UnOu = -1 ! set the text output file unit to -1 to indicate it's not open
y_FAST%UnGra = -1 ! set the binary graphics output file unit to -1 to indicate it's not open
p_FAST%WrVTK = VTK_Unknown ! set this so that we can potentially output VTK information on initialization error
p_FAST%VTK_tWidth = 1 ! initialize in case of error before reading the full file
p_FAST%n_VTKTime = 1 ! initialize in case of error before reading the full file
y_FAST%VTK_LastWaveIndx = 1 ! Start looking for wave data at the first index
y_FAST%VTK_count = 0 ! first VTK file has 0 as output
y_FAST%n_Out = 0 ! set the number of ouptut channels to 0 to indicate there's nothing to write to the binary file
p_FAST%ModuleInitialized = .FALSE. ! (array initialization) no modules are initialized
! Get the current time
CALL DATE_AND_TIME ( Values=m_FAST%StrtTime ) ! Let's time the whole simulation
CALL CPU_TIME ( m_FAST%UsrTime1 ) ! Initial time (this zeros the start time when used as a MATLAB function)
m_FAST%UsrTime1 = MAX( 0.0_ReKi, m_FAST%UsrTime1 ) ! CPU_TIME: If a meaningful time cannot be returned, a processor-dependent negative value is returned
m_FAST%t_global = t_initial - 20. ! initialize this to a number < t_initial for error message in ProgAbort
m_FAST%calcJacobian = .TRUE. ! we need to calculate the Jacobian
m_FAST%NextJacCalcTime = m_FAST%t_global ! We want to calculate the Jacobian on the first step
p_FAST%TDesc = ''
! p_FAST%CheckHSSBrTrqC = .false.
y_FAST%Lin%WindSpeed = 0.0_ReKi
if (present(ExternInitData)) then
CallStart = .not. ExternInitData%FarmIntegration ! .and. ExternInitData%TurbineID == 1
if (ExternInitData%TurbineID > 0) p_FAST%TDesc = 'T'//trim(num2lstr(ExternInitData%TurbineID))
else
CallStart = .true.
end if
! Init NWTC_Library, display copyright and version information:
if (CallStart) then
AbortErrLev = ErrID_Fatal ! Until we read otherwise from the FAST input file, we abort only on FATAL errors
CALL FAST_ProgStart( FAST_Ver )
p_FAST%WrSttsTime = .TRUE.
else
! if we don't call the start data (e.g., from FAST.Farm), we won't override AbortErrLev either
CALL DispNVD( FAST_Ver )
p_FAST%WrSttsTime = .FALSE.
end if
IF (PRESENT(InFile)) THEN
p_FAST%UseDWM = .FALSE.
InputFile = InFile
ELSE
CALL GetInputFileName(InputFile,p_FAST%UseDWM,ErrStat2,ErrMsg2)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
END IF
! ... Open and read input files ...
! also, set applicable farm paramters and turbine reference position also for graphics output
p_FAST%UseSC = .FALSE.
if (PRESENT(ExternInitData)) then
p_FAST%FarmIntegration = ExternInitData%FarmIntegration
p_FAST%TurbinePos = ExternInitData%TurbinePos
p_FAST%WaveFieldMod = ExternInitData%WaveFieldMod
if( (ExternInitData%NumSC2CtrlGlob .gt. 0) .or. (ExternInitData%NumSC2Ctrl .gt. 0) .or. (ExternInitData%NumCtrl2SC .gt. 0)) then
p_FAST%UseSC = .TRUE.
end if
if (ExternInitData%FarmIntegration) then ! we're integrating with FAST.Farm
CALL FAST_Init( p_FAST, m_FAST, y_FAST, t_initial, InputFile, ErrStat2, ErrMsg2, ExternInitData%TMax, OverrideAbortLev=.false., RootName=ExternInitData%RootName )
else
CALL FAST_Init( p_FAST, m_FAST, y_FAST, t_initial, InputFile, ErrStat2, ErrMsg2, ExternInitData%TMax, ExternInitData%TurbineID ) ! We have the name of the input file and the simulation length from somewhere else (e.g. Simulink)
end if
else
p_FAST%TurbinePos = 0.0_ReKi
p_FAST%WaveFieldMod = 0
CALL FAST_Init( p_FAST, m_FAST, y_FAST, t_initial, InputFile, ErrStat2, ErrMsg2 ) ! We have the name of the input file from somewhere else (e.g. Simulink)
end if
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
!...............................................................................................................................
p_FAST%dt_module = p_FAST%dt ! initialize time steps for each module
! ........................
! initialize ElastoDyn (must be done first)
! ........................
ALLOCATE( ED%Input( p_FAST%InterpOrder+1 ), ED%InputTimes( p_FAST%InterpOrder+1 ),STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating ED%Input and ED%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
Init%InData_ED%Linearize = p_FAST%Linearize
Init%InData_ED%InputFile = p_FAST%EDFile
IF ( p_FAST%CompAero == Module_AD14 ) THEN
Init%InData_ED%ADInputFile = p_FAST%AeroFile
ELSE
Init%InData_ED%ADInputFile = ""
END IF
Init%InData_ED%RootName = TRIM(p_FAST%OutFileRoot)//'.'//TRIM(y_FAST%Module_Abrev(Module_ED))
Init%InData_ED%CompElast = p_FAST%CompElast == Module_ED
Init%InData_ED%Gravity = p_FAST%Gravity
Init%InData_ED%MHK = p_FAST%MHK
Init%InData_ED%WtrDpth = p_FAST%WtrDpth
CALL ED_Init( Init%InData_ED, ED%Input(1), ED%p, ED%x(STATE_CURR), ED%xd(STATE_CURR), ED%z(STATE_CURR), ED%OtherSt(STATE_CURR), &
ED%y, ED%m, p_FAST%dt_module( MODULE_ED ), Init%OutData_ED, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_ED) = .TRUE.
CALL SetModuleSubstepTime(Module_ED, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
! bjj: added this check per jmj; perhaps it would be better in ElastoDyn, but I'll leave it here for now:
IF ( p_FAST%TurbineType == Type_Offshore_Floating ) THEN
IF ( ED%p%TowerBsHt < 0.0_ReKi .AND. .NOT. EqualRealNos( ED%p%TowerBsHt, 0.0_ReKi ) ) THEN
CALL SetErrStat(ErrID_Fatal,"ElastoDyn TowerBsHt must not be negative for floating offshore systems.",ErrStat,ErrMsg,RoutineName)
END IF
END IF
allocate( y_FAST%Lin%Modules(MODULE_ED)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(ED).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_ED%LinNames_y)) call move_alloc(Init%OutData_ED%LinNames_y,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%Names_y)
if (allocated(Init%OutData_ED%LinNames_x)) call move_alloc(Init%OutData_ED%LinNames_x,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%Names_x)
if (allocated(Init%OutData_ED%LinNames_u)) call move_alloc(Init%OutData_ED%LinNames_u,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%Names_u)
if (allocated(Init%OutData_ED%RotFrame_y)) call move_alloc(Init%OutData_ED%RotFrame_y,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%RotFrame_y)
if (allocated(Init%OutData_ED%RotFrame_x)) call move_alloc(Init%OutData_ED%RotFrame_x,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%RotFrame_x)
if (allocated(Init%OutData_ED%DerivOrder_x)) call move_alloc(Init%OutData_ED%DerivOrder_x,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%DerivOrder_x)
if (allocated(Init%OutData_ED%RotFrame_u)) call move_alloc(Init%OutData_ED%RotFrame_u,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%RotFrame_u)
if (allocated(Init%OutData_ED%IsLoad_u )) call move_alloc(Init%OutData_ED%IsLoad_u ,y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_ED%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_ED)%Instance(1)%NumOutputs = size(Init%OutData_ED%WriteOutputHdr)
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
NumBl = Init%OutData_ED%NumBl
if (p_FAST%CalcSteady) then
if ( EqualRealNos(Init%OutData_ED%RotSpeed, 0.0_ReKi) ) then
p_FAST%TrimCase = TrimCase_none
p_FAST%NLinTimes = 1
p_FAST%LinInterpOrder = 0 ! constant values
elseif ( Init%OutData_ED%isFixed_GenDOF ) then
p_FAST%TrimCase = TrimCase_none
end if
end if
! ........................
! initialize BeamDyn
! ........................
IF ( p_FAST%CompElast == Module_BD ) THEN
p_FAST%nBeams = Init%OutData_ED%NumBl ! initialize number of BeamDyn instances = number of blades
ELSE
p_FAST%nBeams = 0
END IF
ALLOCATE( BD%Input( p_FAST%InterpOrder+1, p_FAST%nBeams ), BD%InputTimes( p_FAST%InterpOrder+1, p_FAST%nBeams ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating BD%Input and BD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
ALLOCATE( BD%x( p_FAST%nBeams,2), &
BD%xd( p_FAST%nBeams,2), &
BD%z( p_FAST%nBeams,2), &
BD%OtherSt( p_FAST%nBeams,2), &
BD%p( p_FAST%nBeams ), &
BD%u( p_FAST%nBeams ), &
BD%y( p_FAST%nBeams ), &
BD%m( p_FAST%nBeams ), &
Init%OutData_BD(p_FAST%nBeams ), &
STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating BeamDyn state, input, and output data.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
IF (p_FAST%CompElast == Module_BD) THEN
Init%InData_BD%DynamicSolve = .TRUE. ! FAST can only couple to BeamDyn when dynamic solve is used.
Init%InData_BD%Linearize = p_FAST%Linearize
Init%InData_BD%gravity = (/ 0.0_ReKi, 0.0_ReKi, -p_FAST%Gravity /) ! "Gravitational acceleration" m/s^2
! now initialize BeamDyn for all beams
dt_BD = p_FAST%dt_module( MODULE_BD )
Init%InData_BD%HubPos = ED%y%HubPtMotion%Position(:,1)
Init%InData_BD%HubRot = ED%y%HubPtMotion%RefOrientation(:,:,1)
p_FAST%BD_OutputSibling = .true.
allocate( y_FAST%Lin%Modules(MODULE_BD)%Instance(p_FAST%nBeams), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(BD).", ErrStat, ErrMsg, RoutineName )
CALL Cleanup()
RETURN
end if
DO k=1,p_FAST%nBeams
Init%InData_BD%RootName = TRIM(p_FAST%OutFileRoot)//'.'//TRIM(y_FAST%Module_Abrev(Module_BD))//TRIM( Num2LStr(k) )
Init%InData_BD%InputFile = p_FAST%BDBldFile(k)
Init%InData_BD%GlbPos = ED%y%BladeRootMotion(k)%Position(:,1) ! {:} - - "Initial Position Vector of the local blade coordinate system"
Init%InData_BD%GlbRot = ED%y%BladeRootMotion(k)%RefOrientation(:,:,1) ! {:}{:} - - "Initial direction cosine matrix of the local blade coordinate system"
Init%InData_BD%RootDisp = ED%y%BladeRootMotion(k)%TranslationDisp(:,1) ! {:} - - "Initial root displacement"
Init%InData_BD%RootOri = ED%y%BladeRootMotion(k)%Orientation(:,:,1) ! {:}{:} - - "Initial root orientation"
Init%InData_BD%RootVel(1:3) = ED%y%BladeRootMotion(k)%TranslationVel(:,1) ! {:} - - "Initial root velocities and angular veolcities"
Init%InData_BD%RootVel(4:6) = ED%y%BladeRootMotion(k)%RotationVel(:,1) ! {:} - - "Initial root velocities and angular veolcities"
CALL BD_Init( Init%InData_BD, BD%Input(1,k), BD%p(k), BD%x(k,STATE_CURR), BD%xd(k,STATE_CURR), BD%z(k,STATE_CURR), &
BD%OtherSt(k,STATE_CURR), BD%y(k), BD%m(k), dt_BD, Init%OutData_BD(k), ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
!bjj: we're going to force this to have the same timestep because I don't want to have to deal with n BD modules with n timesteps.
IF ( k == 1 ) THEN
p_FAST%dt_module( MODULE_BD ) = dt_BD
p_FAST%ModuleInitialized(Module_BD) = .TRUE. ! this really should be once per BD instance, but BD doesn't care so I won't go through the effort to track this
CALL SetModuleSubstepTime(Module_BD, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
ELSEIF ( .NOT. EqualRealNos( p_FAST%dt_module( MODULE_BD ),dt_BD )) THEN
CALL SetErrStat(ErrID_Fatal,"All instances of BeamDyn (one per blade) must have the same time step.",ErrStat,ErrMsg,RoutineName)
END IF
! We're going to do fewer computations if the BD input and output meshes that couple to AD are siblings:
if (BD%p(k)%BldMotionNodeLoc /= BD_MESH_QP) p_FAST%BD_OutputSibling = .false.
if (ErrStat>=AbortErrLev) exit !exit this loop so we don't get p_FAST%nBeams of the same errors
if (size(y_FAST%Lin%Modules(MODULE_BD)%Instance) >= k) then ! for aero maps, we only use the first instance:
if (allocated(Init%OutData_BD(k)%LinNames_y)) call move_alloc(Init%OutData_BD(k)%LinNames_y, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%Names_y )
if (allocated(Init%OutData_BD(k)%LinNames_x)) call move_alloc(Init%OutData_BD(k)%LinNames_x, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%Names_x )
if (allocated(Init%OutData_BD(k)%LinNames_u)) call move_alloc(Init%OutData_BD(k)%LinNames_u, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%Names_u )
if (allocated(Init%OutData_BD(k)%RotFrame_y)) call move_alloc(Init%OutData_BD(k)%RotFrame_y, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%RotFrame_y )
if (allocated(Init%OutData_BD(k)%RotFrame_x)) call move_alloc(Init%OutData_BD(k)%RotFrame_x, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%RotFrame_x )
if (allocated(Init%OutData_BD(k)%RotFrame_u)) call move_alloc(Init%OutData_BD(k)%RotFrame_u, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%RotFrame_u )
if (allocated(Init%OutData_BD(k)%IsLoad_u )) call move_alloc(Init%OutData_BD(k)%IsLoad_u , y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%IsLoad_u )
if (allocated(Init%OutData_BD(k)%DerivOrder_x)) call move_alloc(Init%OutData_BD(k)%DerivOrder_x, y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%DerivOrder_x )
if (allocated(Init%OutData_BD(k)%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_BD)%Instance(k)%NumOutputs = size(Init%OutData_BD(k)%WriteOutputHdr)
end if
END DO
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
END IF
! ........................
! initialize AeroDyn
! ........................
ALLOCATE( AD14%Input( p_FAST%InterpOrder+1 ), AD14%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating AD14%Input and AD14%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
ALLOCATE( AD%Input( p_FAST%InterpOrder+1 ), AD%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating AD%Input and AD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
IF ( p_FAST%CompAero == Module_AD14 ) THEN
CALL AD_SetInitInput(Init%InData_AD14, Init%OutData_ED, ED%y, p_FAST, ErrStat2, ErrMsg2) ! set the values in Init%InData_AD14
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
CALL AD14_Init( Init%InData_AD14, AD14%Input(1), AD14%p, AD14%x(STATE_CURR), AD14%xd(STATE_CURR), AD14%z(STATE_CURR), &
AD14%OtherSt(STATE_CURR), AD14%y, AD14%m, p_FAST%dt_module( MODULE_AD14 ), Init%OutData_AD14, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_AD14) = .TRUE.
CALL SetModuleSubstepTime(Module_AD14, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
! bjj: this really shouldn't be in the FAST glue code, but I'm going to put this check here so people don't use an invalid model
! and send me emails to debug numerical issues in their results.
IF ( AD14%p%TwrProps%PJM_Version .AND. p_FAST%TurbineType == Type_Offshore_Floating ) THEN
CALL SetErrStat(ErrID_Fatal,'AeroDyn v14 tower influence model "NEWTOWER" is invalid for models of floating offshore turbines.',ErrStat,ErrMsg,RoutineName)
END IF
AirDens = Init%OutData_AD14%AirDens
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
ELSEIF ( p_FAST%CompAero == Module_AD ) THEN
allocate(Init%InData_AD%rotors(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat( ErrID_Fatal, 'Allocating rotors', errStat, errMsg, RoutineName )
call Cleanup()
return
end if
Init%InData_AD%rotors(1)%NumBlades = NumBl
! set initialization data for AD
CALL AllocAry( Init%InData_AD%rotors(1)%BladeRootPosition, 3, Init%InData_AD%rotors(1)%NumBlades, 'Init%InData_AD%BladeRootPosition', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
CALL AllocAry( Init%InData_AD%rotors(1)%BladeRootOrientation,3, 3, Init%InData_AD%rotors(1)%NumBlades, 'Init%InData_AD%BladeRootOrientation', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
Init%InData_AD%Gravity = p_FAST%Gravity
Init%InData_AD%Linearize = p_FAST%Linearize
Init%InData_AD%InputFile = p_FAST%AeroFile
Init%InData_AD%RootName = p_FAST%OutFileRoot
Init%InData_AD%MHK = p_FAST%MHK
if ( p_FAST%MHK == 0 ) then
Init%InData_AD%defFldDens = p_FAST%AirDens
elseif ( p_FAST%MHK == 1 .or. p_FAST%MHK == 2 ) then
Init%InData_AD%defFldDens = p_FAST%WtrDens
end if
Init%InData_AD%defKinVisc = p_FAST%KinVisc
Init%InData_AD%defSpdSound = p_FAST%SpdSound
Init%InData_AD%defPatm = p_FAST%Patm
Init%InData_AD%defPvap = p_FAST%Pvap
Init%InData_AD%WtrDpth = p_FAST%WtrDpth
Init%InData_AD%MSL2SWL = p_FAST%MSL2SWL
Init%InData_AD%rotors(1)%HubPosition = ED%y%HubPtMotion%Position(:,1)
Init%InData_AD%rotors(1)%HubOrientation = ED%y%HubPtMotion%RefOrientation(:,:,1)
Init%InData_AD%rotors(1)%NacellePosition = ED%y%NacelleMotion%Position(:,1)
Init%InData_AD%rotors(1)%NacelleOrientation = ED%y%NacelleMotion%RefOrientation(:,:,1)
! Note: not passing tailfin position and orientation at init
Init%InData_AD%rotors(1)%AeroProjMod = APM_BEM_NoSweepPitchTwist
do k=1,NumBl
Init%InData_AD%rotors(1)%BladeRootPosition(:,k) = ED%y%BladeRootMotion(k)%Position(:,1)
Init%InData_AD%rotors(1)%BladeRootOrientation(:,:,k) = ED%y%BladeRootMotion(k)%RefOrientation(:,:,1)
end do
CALL AD_Init( Init%InData_AD, AD%Input(1), AD%p, AD%x(STATE_CURR), AD%xd(STATE_CURR), AD%z(STATE_CURR), &
AD%OtherSt(STATE_CURR), AD%y, AD%m, p_FAST%dt_module( MODULE_AD ), Init%OutData_AD, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_AD) = .TRUE.
CALL SetModuleSubstepTime(Module_AD, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
allocate( y_FAST%Lin%Modules(MODULE_AD)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(AD).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_AD%rotors(1)%LinNames_u )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_u )
if (allocated(Init%OutData_AD%rotors(1)%LinNames_y )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_y ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_y )
if (allocated(Init%OutData_AD%rotors(1)%LinNames_x )) call move_alloc(Init%OutData_AD%rotors(1)%LinNames_x ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%Names_x )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_u )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_u )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_y )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_y ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_y )
if (allocated(Init%OutData_AD%rotors(1)%RotFrame_x )) call move_alloc(Init%OutData_AD%rotors(1)%RotFrame_x ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%RotFrame_x )
if (allocated(Init%OutData_AD%rotors(1)%IsLoad_u )) call move_alloc(Init%OutData_AD%rotors(1)%IsLoad_u ,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_AD%rotors(1)%DerivOrder_x)) call move_alloc(Init%OutData_AD%rotors(1)%DerivOrder_x,y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%DerivOrder_x )
if (allocated(Init%OutData_AD%rotors(1)%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_AD)%Instance(1)%NumOutputs = size(Init%OutData_AD%rotors(1)%WriteOutputHdr)
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
AirDens = Init%OutData_AD%rotors(1)%AirDens
ELSE
AirDens = 0.0_ReKi
END IF ! CompAero
! ........................
! initialize InflowWind
! ........................
ALLOCATE( IfW%Input( p_FAST%InterpOrder+1 ), IfW%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating IfW%Input and IfW%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
IF ( p_FAST%CompInflow == Module_IfW ) THEN
Init%InData_IfW%Linearize = p_FAST%Linearize
Init%InData_IfW%InputFileName = p_FAST%InflowFile
Init%InData_IfW%RootName = TRIM(p_FAST%OutFileRoot)//'.'//TRIM(y_FAST%Module_Abrev(Module_IfW))
Init%InData_IfW%UseInputFile = .TRUE.
Init%InData_IfW%FixedWindFileRootName = .FALSE.
Init%InData_IfW%OutputAccel = p_FAST%MHK > 0
Init%InData_IfW%MHK = p_FAST%MHK
Init%InData_IfW%WtrDpth = p_FAST%WtrDpth
Init%InData_IfW%NumWindPoints = 0
IF ( p_FAST%CompServo == Module_SrvD ) Init%InData_IfW%NumWindPoints = Init%InData_IfW%NumWindPoints + 1
IF ( p_FAST%CompAero == Module_AD14 ) THEN
Init%InData_IfW%NumWindPoints = Init%InData_IfW%NumWindPoints + NumBl * AD14%Input(1)%InputMarkers(1)%NNodes + AD14%Input(1)%Twr_InputMarkers%NNodes
ELSEIF ( p_FAST%CompAero == Module_AD ) THEN
! Number of Wind points from AeroDyn, see AeroDyn.f90
Init%InData_IfW%NumWindPoints = Init%InData_IfW%NumWindPoints + AD_NumWindPoints(AD%Input(1), AD%OtherSt(STATE_CURR))
! Wake -- we allow the wake positions to exceed the wind box
if (allocated(AD%OtherSt(STATE_CURR)%WakeLocationPoints)) then
Init%InData_IfW%BoxExceedAllowF = .true.
Init%InData_IfW%BoxExceedAllowIdx = min(Init%InData_IfW%BoxExceedAllowIdx, AD_BoxExceedPointsIdx(AD%Input(1), AD%OtherSt(STATE_CURR)))
endif
END IF
! lidar
Init%InData_IfW%lidar%Tmax = p_FAST%TMax
Init%InData_IfW%lidar%HubPosition = ED%y%HubPtMotion%Position(:,1)
Init%InData_IfW%lidar%HubPosition = ED%y%HubPtMotion%Position(:,1)
if ( p_FAST%CompElast == Module_BD ) then
Init%InData_IfW%RadAvg = TwoNorm(BD%y(1)%BldMotion%Position(:,1) - BD%y(1)%BldMotion%Position(:,BD%y(1)%BldMotion%Nnodes))
else
Init%InData_IfW%RadAvg = Init%OutData_ED%BladeLength
end if
IF ( PRESENT(ExternInitData) ) THEN
Init%InData_IfW%Use4Dext = ExternInitData%FarmIntegration
if (Init%InData_IfW%Use4Dext) then
Init%InData_IfW%FDext%n = ExternInitData%windGrid_n
Init%InData_IfW%FDext%delta = ExternInitData%windGrid_delta
Init%InData_IfW%FDext%pZero = ExternInitData%windGrid_pZero
end if
ELSE
Init%InData_IfW%Use4Dext = .false.
END IF
CALL InflowWind_Init( Init%InData_IfW, IfW%Input(1), IfW%p, IfW%x(STATE_CURR), IfW%xd(STATE_CURR), IfW%z(STATE_CURR), &
IfW%OtherSt(STATE_CURR), IfW%y, IfW%m, p_FAST%dt_module( MODULE_IfW ), Init%OutData_IfW, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_IfW) = .TRUE.
CALL SetModuleSubstepTime(Module_IfW, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
allocate( y_FAST%Lin%Modules(MODULE_IfW)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(IfW).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_IfW%LinNames_y)) call move_alloc(Init%OutData_IfW%LinNames_y,y_FAST%Lin%Modules(MODULE_IfW)%Instance(1)%Names_y )
if (allocated(Init%OutData_IfW%LinNames_u)) call move_alloc(Init%OutData_IfW%LinNames_u,y_FAST%Lin%Modules(MODULE_IfW)%Instance(1)%Names_u )
if (allocated(Init%OutData_IfW%RotFrame_y)) call move_alloc(Init%OutData_IfW%RotFrame_y,y_FAST%Lin%Modules(MODULE_IfW)%Instance(1)%RotFrame_y )
if (allocated(Init%OutData_IfW%RotFrame_u)) call move_alloc(Init%OutData_IfW%RotFrame_u,y_FAST%Lin%Modules(MODULE_IfW)%Instance(1)%RotFrame_u )
if (allocated(Init%OutData_IfW%IsLoad_u )) call move_alloc(Init%OutData_IfW%IsLoad_u ,y_FAST%Lin%Modules(MODULE_IfW)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_IfW%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_IfW)%Instance(1)%NumOutputs = size(Init%OutData_IfW%WriteOutputHdr)
y_FAST%Lin%WindSpeed = Init%OutData_IfW%WindFileInfo%MWS
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
IF ( p_FAST%CompServo == Module_SrvD ) THEN !assign the number of gates to ServD
if (allocated(IfW%y%lidar%LidSpeed)) then ! make sure we have the array allocated before setting it
CALL AllocAry(Init%InData_SrvD%LidSpeed, size(IfW%y%lidar%LidSpeed), 'Init%InData_SrvD%LidSpeed', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
Init%InData_SrvD%LidSpeed = IfW%y%lidar%LidSpeed
endif
if (allocated(IfW%y%lidar%MsrPositionsX)) then ! make sure we have the array allocated before setting it
CALL AllocAry(Init%InData_SrvD%MsrPositionsX, size(IfW%y%lidar%MsrPositionsX), 'Init%InData_SrvD%MsrPositionsX', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
Init%InData_SrvD%MsrPositionsX = IfW%y%lidar%MsrPositionsX
endif
if (allocated(IfW%y%lidar%MsrPositionsY)) then ! make sure we have the array allocated before setting it
CALL AllocAry(Init%InData_SrvD%MsrPositionsY, size(IfW%y%lidar%MsrPositionsY), 'Init%InData_SrvD%MsrPositionsY', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
Init%InData_SrvD%MsrPositionsY = IfW%y%lidar%MsrPositionsY
endif
if (allocated(IfW%y%lidar%MsrPositionsZ)) then ! make sure we have the array allocated before setting it
CALL AllocAry(Init%InData_SrvD%MsrPositionsZ, size(IfW%y%lidar%MsrPositionsZ), 'Init%InData_SrvD%MsrPositionsZ', errStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
Init%InData_SrvD%MsrPositionsZ = IfW%y%lidar%MsrPositionsZ
endif
Init%InData_SrvD%SensorType = IfW%p%lidar%SensorType
Init%InData_SrvD%NumBeam = IfW%p%lidar%NumBeam
Init%InData_SrvD%NumPulseGate = IfW%p%lidar%NumPulseGate
Init%InData_SrvD%PulseSpacing = IfW%p%lidar%PulseSpacing
END IF
ELSEIF ( p_FAST%CompInflow == Module_OpFM ) THEN
IF ( PRESENT(ExternInitData) ) THEN
Init%InData_OpFM%NumActForcePtsBlade = ExternInitData%NumActForcePtsBlade
Init%InData_OpFM%NumActForcePtsTower = ExternInitData%NumActForcePtsTower
ELSE
CALL SetErrStat( ErrID_Fatal, 'OpenFOAM integration can be used only with external input data (not the stand-alone executable).', ErrStat, ErrMsg, RoutineName )
CALL Cleanup()
RETURN
END IF
! get blade and tower info from AD. Assumption made that all blades have same spanwise characteristics
Init%InData_OpFM%BladeLength = Init%OutData_AD%rotors(1)%BladeProps(1)%BlSpn(Init%OutData_AD%rotors(1)%BladeProps(1)%NumBlNds)
if (allocated(Init%OutData_AD%rotors(1)%TwrElev)) then
Init%InData_OpFM%TowerHeight = Init%OutData_AD%rotors(1)%TwrElev(SIZE(Init%OutData_AD%rotors(1)%TwrElev)) - Init%OutData_AD%rotors(1)%TwrElev(1) ! TwrElev is based on ground or MSL. Need flexible tower length and first node
Init%InData_OpFM%TowerBaseHeight = Init%OutData_AD%rotors(1)%TwrElev(1)
ALLOCATE(Init%InData_OpFM%StructTwrHNodes( SIZE(Init%OutData_AD%rotors(1)%TwrElev)), STAT=ErrStat2)
Init%InData_OpFM%StructTwrHNodes(:) = Init%OutData_AD%rotors(1)%TwrElev(:)
else
Init%InData_OpFM%TowerHeight = 0.0_ReKi
Init%InData_OpFM%TowerBaseHeight = 0.0_ReKi
endif
ALLOCATE(Init%InData_OpFM%StructBldRNodes(Init%OutData_AD%rotors(1)%BladeProps(1)%NumBlNds), STAT=ErrStat2)
Init%InData_OpFM%StructBldRNodes(:) = Init%OutData_AD%rotors(1)%BladeProps(1)%BlSpn(:)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating OpFM%InitInput.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
!Set node clustering type
Init%InData_OpFM%NodeClusterType = ExternInitData%NodeClusterType
! set up the data structures for integration with OpenFOAM
CALL Init_OpFM( Init%InData_OpFM, p_FAST, AirDens, AD%Input(1), Init%OutData_AD, AD%y, OpFM, Init%OutData_OpFM, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
!bjj: fix me!!! to do
Init%OutData_IfW%WindFileInfo%MWS = 0.0_ReKi
ELSE
Init%OutData_IfW%WindFileInfo%MWS = 0.0_ReKi
END IF ! CompInflow
! ........................
! initialize SuperController
! ........................
IF ( PRESENT(ExternInitData) ) THEN
! set up the data structures for integration with supercontroller
IF ( p_FAST%UseSC ) THEN
CALL SC_DX_Init( ExternInitData%NumSC2CtrlGlob, ExternInitData%NumSC2Ctrl, ExternInitData%NumCtrl2SC, SC_DX, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
ELSE
SC_DX%u%c_obj%toSC_Len = 0
SC_DX%u%c_obj%toSC = C_NULL_PTR
SC_DX%y%c_obj%fromSC_Len = 0
SC_DX%y%c_obj%fromSC = C_NULL_PTR
SC_DX%y%c_obj%fromSCglob_Len = 0
SC_DX%y%c_obj%fromSCglob = C_NULL_PTR
END IF
END IF
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
! ........................
! some checks for AeroDyn14's Dynamic Inflow with Mean Wind Speed from InflowWind:
! (DO NOT COPY THIS CODE!)
! bjj: AeroDyn14 should not need this rule of thumb; it should check the instantaneous values when the code runs
! ........................
IF ( p_FAST%CompAero == Module_AD14 ) THEN
IF (AD14%p%DynInfl) THEN
IF ( Init%OutData_IfW%WindFileInfo%MWS < 8.0 ) THEN
CALL SetErrStat(ErrID_Fatal,'AeroDyn v14 "DYNINFL" InfModel is invalid for models with wind speeds less than 8 m/s.',ErrStat,ErrMsg,RoutineName)
!CALL SetErrStat(ErrID_Info,'Estimated average inflow wind speed is less than 8 m/s. Dynamic Inflow will be turned off.',ErrStat,ErrMess,RoutineName )
END IF
END IF
END IF
! ........................
! set some VTK parameters required before HydroDyn init (so we can get wave elevations for visualization)
! ........................
! get wave elevation data for visualization
if ( p_FAST%WrVTK > VTK_None ) then
call SetVTKParameters_B4HD(p_FAST, Init%OutData_ED, Init%InData_HD, BD, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
end if
! ........................
! initialize HydroDyn
! ........................
ALLOCATE( HD%Input( p_FAST%InterpOrder+1 ), HD%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating HD%Input and HD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
IF ( p_FAST%CompHydro == Module_HD ) THEN
Init%InData_HD%Gravity = p_FAST%Gravity
Init%InData_HD%defWtrDens = p_FAST%WtrDens
Init%InData_HD%defWtrDpth = p_FAST%WtrDpth
Init%InData_HD%defMSL2SWL = p_FAST%MSL2SWL
Init%InData_HD%UseInputFile = .TRUE.
Init%InData_HD%InputFile = p_FAST%HydroFile
Init%InData_HD%OutRootName = p_FAST%OutFileRoot
Init%InData_HD%TMax = p_FAST%TMax
Init%InData_HD%hasIce = p_FAST%CompIce /= Module_None
Init%InData_HD%Linearize = p_FAST%Linearize
if (p_FAST%WrVTK /= VTK_None) Init%InData_HD%VisMeshes=.true.
! these values support wave field handling
Init%InData_HD%WaveFieldMod = p_FAST%WaveFieldMod
Init%InData_HD%PtfmLocationX = p_FAST%TurbinePos(1)
Init%InData_HD%PtfmLocationY = p_FAST%TurbinePos(2)
CALL HydroDyn_Init( Init%InData_HD, HD%Input(1), HD%p, HD%x(STATE_CURR), HD%xd(STATE_CURR), HD%z(STATE_CURR), &
HD%OtherSt(STATE_CURR), HD%y, HD%m, p_FAST%dt_module( MODULE_HD ), Init%OutData_HD, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_HD) = .TRUE.
CALL SetModuleSubstepTime(Module_HD, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
allocate( y_FAST%Lin%Modules(MODULE_HD)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(HD).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_HD%LinNames_y)) call move_alloc(Init%OutData_HD%LinNames_y,y_FAST%Lin%Modules(MODULE_HD)%Instance(1)%Names_y )
if (allocated(Init%OutData_HD%LinNames_u)) call move_alloc(Init%OutData_HD%LinNames_u,y_FAST%Lin%Modules(MODULE_HD)%Instance(1)%Names_u )
if (allocated(Init%OutData_HD%LinNames_x)) call move_alloc(Init%OutData_HD%LinNames_x, y_FAST%Lin%Modules(MODULE_HD)%Instance(1)%Names_x )
if (allocated(Init%OutData_HD%DerivOrder_x)) call move_alloc(Init%OutData_HD%DerivOrder_x,y_FAST%Lin%Modules(MODULE_HD)%Instance(1)%DerivOrder_x)
if (allocated(Init%OutData_HD%IsLoad_u )) call move_alloc(Init%OutData_HD%IsLoad_u ,y_FAST%Lin%Modules(MODULE_HD)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_HD%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_HD)%Instance(1)%NumOutputs = size(Init%OutData_HD%WriteOutputHdr)
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
END IF ! CompHydro
! ........................
! initialize SubDyn or ExtPtfm_MCKF
! ........................
ALLOCATE( SD%Input( p_FAST%InterpOrder+1 ), SD%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating SD%Input and SD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
ALLOCATE( ExtPtfm%Input( p_FAST%InterpOrder+1 ), ExtPtfm%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating ExtPtfm%Input and ExtPtfm%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
IF ( p_FAST%CompSub == Module_SD ) THEN
IF ( p_FAST%CompHydro == Module_HD ) THEN
Init%InData_SD%WtrDpth = Init%OutData_HD%WtrDpth
ELSE
Init%InData_SD%WtrDpth = 0.0_ReKi
END IF
Init%InData_SD%Linearize = p_FAST%Linearize
Init%InData_SD%g = p_FAST%Gravity
!Ini%tInData_SD%UseInputFile = .TRUE.
Init%InData_SD%SDInputFile = p_FAST%SubFile
Init%InData_SD%RootName = p_FAST%OutFileRoot
Init%InData_SD%TP_RefPoint = ED%y%PlatformPtMesh%Position(:,1) ! "Interface point" where loads will be transferred to
Init%InData_SD%SubRotateZ = 0.0 ! Used by driver to rotate structure around z
CALL SD_Init( Init%InData_SD, SD%Input(1), SD%p, SD%x(STATE_CURR), SD%xd(STATE_CURR), SD%z(STATE_CURR), &
SD%OtherSt(STATE_CURR), SD%y, SD%m, p_FAST%dt_module( MODULE_SD ), Init%OutData_SD, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_SD) = .TRUE.
CALL SetModuleSubstepTime(Module_SD, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
allocate( y_FAST%Lin%Modules(MODULE_SD)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(SD).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_SD%LinNames_y)) call move_alloc(Init%OutData_SD%LinNames_y,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%Names_y)
if (allocated(Init%OutData_SD%LinNames_x)) call move_alloc(Init%OutData_SD%LinNames_x,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%Names_x)
if (allocated(Init%OutData_SD%LinNames_u)) call move_alloc(Init%OutData_SD%LinNames_u,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%Names_u)
if (allocated(Init%OutData_SD%RotFrame_y)) call move_alloc(Init%OutData_SD%RotFrame_y,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%RotFrame_y)
if (allocated(Init%OutData_SD%RotFrame_x)) call move_alloc(Init%OutData_SD%RotFrame_x,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%RotFrame_x)
if (allocated(Init%OutData_SD%RotFrame_u)) call move_alloc(Init%OutData_SD%RotFrame_u,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%RotFrame_u)
if (allocated(Init%OutData_SD%IsLoad_u )) call move_alloc(Init%OutData_SD%IsLoad_u ,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_SD%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%NumOutputs = size(Init%OutData_SD%WriteOutputHdr)
if (allocated(Init%OutData_SD%DerivOrder_x)) call move_alloc(Init%OutData_SD%DerivOrder_x,y_FAST%Lin%Modules(MODULE_SD)%Instance(1)%DerivOrder_x)
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
ELSE IF ( p_FAST%CompSub == Module_ExtPtfm ) THEN
Init%InData_ExtPtfm%InputFile = p_FAST%SubFile
Init%InData_ExtPtfm%RootName = trim(p_FAST%OutFileRoot)//'.'//TRIM(y_FAST%Module_Abrev(Module_ExtPtfm))
Init%InData_ExtPtfm%Linearize = p_FAST%Linearize
Init%InData_ExtPtfm%PtfmRefzt = ED%p%PtfmRefzt ! Required
CALL ExtPtfm_Init( Init%InData_ExtPtfm, ExtPtfm%Input(1), ExtPtfm%p, &
ExtPtfm%x(STATE_CURR), ExtPtfm%xd(STATE_CURR), ExtPtfm%z(STATE_CURR), ExtPtfm%OtherSt(STATE_CURR), &
ExtPtfm%y, ExtPtfm%m, p_FAST%dt_module( MODULE_ExtPtfm ), Init%OutData_ExtPtfm, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(MODULE_ExtPtfm) = .TRUE.
CALL SetModuleSubstepTime(MODULE_ExtPtfm, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
allocate( y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(ExtPtfm).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_ExtPtfm%LinNames_y)) call move_alloc(Init%OutData_ExtPtfm%LinNames_y,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%Names_y)
if (allocated(Init%OutData_ExtPtfm%LinNames_x)) call move_alloc(Init%OutData_ExtPtfm%LinNames_x,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%Names_x)
if (allocated(Init%OutData_ExtPtfm%LinNames_u)) call move_alloc(Init%OutData_ExtPtfm%LinNames_u,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%Names_u)
if (allocated(Init%OutData_ExtPtfm%RotFrame_y)) call move_alloc(Init%OutData_ExtPtfm%RotFrame_y,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%RotFrame_y)
if (allocated(Init%OutData_ExtPtfm%RotFrame_x)) call move_alloc(Init%OutData_ExtPtfm%RotFrame_x,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%RotFrame_x)
if (allocated(Init%OutData_ExtPtfm%RotFrame_u)) call move_alloc(Init%OutData_ExtPtfm%RotFrame_u,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%RotFrame_u)
if (allocated(Init%OutData_ExtPtfm%IsLoad_u )) call move_alloc(Init%OutData_ExtPtfm%IsLoad_u ,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_ExtPtfm%WriteOutputHdr)) y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%NumOutputs = size(Init%OutData_ExtPtfm%WriteOutputHdr)
if (allocated(Init%OutData_ExtPtfm%DerivOrder_x)) call move_alloc(Init%OutData_ExtPtfm%DerivOrder_x,y_FAST%Lin%Modules(MODULE_ExtPtfm)%Instance(1)%DerivOrder_x)
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
END IF
! ------------------------------
! initialize CompMooring modules
! ------------------------------
ALLOCATE( MAPp%Input( p_FAST%InterpOrder+1 ), MAPp%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating MAPp%Input and MAPp%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
ALLOCATE( MD%Input( p_FAST%InterpOrder+1 ), MD%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating MD%Input and MD%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
ALLOCATE( FEAM%Input( p_FAST%InterpOrder+1 ), FEAM%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating FEAM%Input and FEAM%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
ALLOCATE( Orca%Input( p_FAST%InterpOrder+1 ), Orca%InputTimes( p_FAST%InterpOrder+1 ), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating Orca%Input and Orca%InputTimes.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN
END IF
! ........................
! initialize MAP
! ........................
IF (p_FAST%CompMooring == Module_MAP) THEN
!bjj: until we modify this, MAP requires HydroDyn to be used. (perhaps we could send air density from AeroDyn or something...)
CALL WrScr(NewLine) !bjj: I'm printing two blank lines here because MAP seems to be writing over the last line on the screen.
! Init%InData_MAP%rootname = p_FAST%OutFileRoot ! Output file name
Init%InData_MAP%gravity = p_FAST%Gravity ! This need to be according to g from driver
Init%InData_MAP%sea_density = Init%OutData_HD%WtrDens ! This needs to be set according to seawater density in HydroDyn
Init%InData_MAP%depth = Init%OutData_HD%WtrDpth ! This need to be set according to the water depth in HydroDyn
! differences for MAP++
Init%InData_MAP%file_name = p_FAST%MooringFile ! This needs to be set according to what is in the FAST input file.
Init%InData_MAP%summary_file_name = TRIM(p_FAST%OutFileRoot)//'.MAP.sum' ! Output file name
Init%InData_MAP%depth = -Init%OutData_HD%WtrDpth ! This need to be set according to the water depth in HydroDyn
Init%InData_MAP%LinInitInp%Linearize = p_FAST%Linearize
CALL MAP_Init( Init%InData_MAP, MAPp%Input(1), MAPp%p, MAPp%x(STATE_CURR), MAPp%xd(STATE_CURR), MAPp%z(STATE_CURR), MAPp%OtherSt, &
MAPp%y, p_FAST%dt_module( MODULE_MAP ), Init%OutData_MAP, ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
p_FAST%ModuleInitialized(Module_MAP) = .TRUE.
CALL SetModuleSubstepTime(Module_MAP, p_FAST, y_FAST, ErrStat2, ErrMsg2)
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
allocate( y_FAST%Lin%Modules(Module_MAP)%Instance(1), stat=ErrStat2)
if (ErrStat2 /= 0 ) then
call SetErrStat(ErrID_Fatal, "Error allocating Lin%Modules(MAP).", ErrStat, ErrMsg, RoutineName )
else
if (allocated(Init%OutData_MAP%LinInitOut%LinNames_y)) call move_alloc(Init%OutData_MAP%LinInitOut%LinNames_y,y_FAST%Lin%Modules(Module_MAP)%Instance(1)%Names_y )
if (allocated(Init%OutData_MAP%LinInitOut%LinNames_u)) call move_alloc(Init%OutData_MAP%LinInitOut%LinNames_u,y_FAST%Lin%Modules(Module_MAP)%Instance(1)%Names_u )
if (allocated(Init%OutData_MAP%LinInitOut%IsLoad_u )) call move_alloc(Init%OutData_MAP%LinInitOut%IsLoad_u ,y_FAST%Lin%Modules(Module_MAP)%Instance(1)%IsLoad_u )
if (allocated(Init%OutData_MAP%WriteOutputHdr)) y_FAST%Lin%Modules(Module_MAP)%Instance(1)%NumOutputs = size(Init%OutData_MAP%WriteOutputHdr)
end if
IF (ErrStat >= AbortErrLev) THEN
CALL Cleanup()
RETURN
END IF
! ........................
! initialize MoorDyn
! ........................
ELSEIF (p_FAST%CompMooring == Module_MD) THEN
! some new allocations needed with version that's compatible with farm-level use
ALLOCATE( Init%InData_MD%PtfmInit(6,1), Init%InData_MD%TurbineRefPos(3,1), STAT = ErrStat2 )
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating MoorDyn PtfmInit and TurbineRefPos initialization inputs.",ErrStat,ErrMsg,RoutineName)
CALL Cleanup()
RETURN