-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathAeroDyn.f90
7806 lines (6407 loc) · 422 KB
/
AeroDyn.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
!*********************************************************************************************************************************
! LICENSING
! Copyright (C) 2015-2016 National Renewable Energy Laboratory
! Copyright (C) 2016-2021 Envision Energy USA, LTD
!
! This file is part of AeroDyn.
!
! 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.
!
!**********************************************************************************************************************************
!> AeroDyn is a time-domain aerodynamics module for horizontal-axis wind turbines.
module AeroDyn
use NWTC_Library
use AeroDyn_Types
use AeroDyn_IO
use BEMT
use AirfoilInfo
use NWTC_LAPACK
use AeroAcoustics
use UnsteadyAero
use FVW
use FVW_Subs, only: FVW_AeroOuts
use IfW_FlowField, only: IfW_FlowField_GetVelAcc, IfW_UniformWind_GetOP, IfW_UniformWind_Perturb, IfW_FlowField_CopyFlowFieldType
implicit none
private
! ..... Public Subroutines ...................................................................................................
public :: AD_Init ! Initialization routine
public :: AD_ReInit ! Routine to reinitialize driver (re-initializes the states)
public :: AD_End ! Ending routine (includes clean up)
public :: AD_UpdateStates ! Loose coupling routine for solving for constraint states, integrating
! continuous states, and updating discrete states
public :: AD_CalcOutput ! Routine for computing outputs
public :: AD_CalcConstrStateResidual ! Tight coupling routine for returning the constraint state residual
PUBLIC :: AD_JacobianPInput ! Routine to compute the Jacobians of the output(Y), continuous - (X), discrete -
! (Xd), and constraint - state(Z) functions all with respect to the inputs(u)
PUBLIC :: AD_JacobianPContState ! Routine to compute the Jacobians of the output(Y), continuous - (X), discrete -
! (Xd), and constraint - state(Z) functions all with respect to the continuous
! states(x)
PUBLIC :: AD_JacobianPDiscState ! Routine to compute the Jacobians of the output(Y), continuous - (X), discrete -
! (Xd), and constraint - state(Z) functions all with respect to the discrete
! states(xd)
PUBLIC :: AD_JacobianPConstrState ! Routine to compute the Jacobians of the output(Y), continuous - (X), discrete -
! (Xd), and constraint - state(Z) functions all with respect to the constraint
! states(z)
PUBLIC :: AD_GetOP !< Routine to pack the operating point values (for linearization) into arrays
contains
!----------------------------------------------------------------------------------------------------------------------------------
!> This subroutine sets the initialization output data structure, which contains data to be returned to the calling program (e.g.,
!! FAST or AeroDyn_Driver)
subroutine AD_SetInitOut(MHK, WtrDpth, p, p_AD, InputFileData, InitOut, errStat, errMsg)
integer(IntKi), intent(in ) :: MHK ! MHK flag
real(ReKi), intent(in ) :: WtrDpth ! water depth
type(RotInitOutputType), intent( out) :: InitOut ! output data
type(RotInputFile), intent(in ) :: InputFileData ! input file data (for setting airfoil shape outputs)
type(RotParameterType), intent(in ) :: p ! Parameters
type(AD_ParameterType), intent(in ) :: p_AD ! Parameters
integer(IntKi), intent( out) :: errStat ! Error status of the operation
character(*), intent( out) :: errMsg ! Error message if ErrStat /= ErrID_None
! Local variables
integer(intKi) :: ErrStat2 ! temporary Error status
character(ErrMsgLen) :: ErrMsg2 ! temporary Error message
character(*), parameter :: RoutineName = 'AD_SetInitOut'
integer(IntKi) :: i, j, k, f
integer(IntKi) :: NumCoords
! Initialize variables for this routine
errStat = ErrID_None
errMsg = ""
InitOut%AirDens = p%AirDens
call AllocAry( InitOut%WriteOutputHdr, p%numOuts + p%BldNd_TotNumOuts, 'WriteOutputHdr', errStat2, errMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( InitOut%WriteOutputUnt, p%numOuts + p%BldNd_TotNumOuts, 'WriteOutputUnt', errStat2, errMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
if (ErrStat >= AbortErrLev) return
do i=1,p%NumOuts
InitOut%WriteOutputHdr(i) = p%OutParam(i)%Name
InitOut%WriteOutputUnt(i) = p%OutParam(i)%Units
end do
! Set the info in WriteOutputHdr and WriteOutputUnt
CALL AllBldNdOuts_InitOut( InitOut, p, InputFileData, ErrStat2, ErrMsg2 )
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
! set visualization data:
! this check is overly restrictive, but it would be a lot of work to ensure that only the *used* airfoil
! tables have the same number of coordinates.
if ( allocated(p_AD%AFI) ) then
if ( p_AD%AFI(1)%NumCoords > 0 ) then
NumCoords = p_AD%AFI(1)%NumCoords
do i=2,size(p_AD%AFI)
if (p_AD%AFI(i)%NumCoords /= NumCoords) then
call SetErrStat( ErrID_Info, 'Airfoil files do not contain the same number of x-y coordinates.', ErrStat, ErrMsg, RoutineName )
NumCoords = -1
exit
end if
end do
if (NumCoords > 0) then
if (NumCoords < 3) then
call SetErrStat( ErrID_Info, 'Airfoil files with NumCoords > 0 must contain at least 2 coordinates.', ErrStat, ErrMsg, RoutineName )
return
end if
allocate( InitOut%BladeShape( p%numBlades ), STAT=ErrStat2 )
if (ErrStat2 /= 0) then
call SetErrStat( ErrID_Info, 'Error allocationg InitOut%AD_BladeShape', ErrStat, ErrMsg, RoutineName )
return
end if
do k=1,p%numBlades
call allocAry( InitOut%BladeShape(k)%AirfoilCoords, 2, NumCoords-1, InputFileData%BladeProps(k)%NumBlNds, 'AirfoilCoords', ErrStat2, ErrMsg2)
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
if (ErrStat >= AbortErrLev) return
do j=1,InputFileData%BladeProps(k)%NumBlNds
f = InputFileData%BladeProps(k)%BlAFID(j)
do i=1,NumCoords-1
InitOut%BladeShape(k)%AirfoilCoords(1,i,j) = InputFileData%BladeProps(k)%BlChord(j)*( p_AD%AFI(f)%Y_Coord(i+1) - p_AD%AFI(f)%Y_Coord(1) )
InitOut%BladeShape(k)%AirfoilCoords(2,i,j) = InputFileData%BladeProps(k)%BlChord(j)*( p_AD%AFI(f)%X_Coord(i+1) - p_AD%AFI(f)%X_Coord(1) )
end do
end do
end do
end if
end if
end if
! set blade properties data ! bjj: I would probably do a move_alloc() at the end of the init routine rather than make a copy like this....
ALLOCATE(InitOut%BladeProps(p%numBlades), STAT = ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating memory for BladeProps.", ErrStat, ErrMsg, RoutineName)
RETURN
END IF
do k=1,p%numBlades
! allocate space and copy blade data:
CALL AD_CopyBladePropsType(InputFileData%BladeProps(k), InitOut%BladeProps(k), MESH_NEWCOPY, ErrStat2, ErrMsg2)
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
end do
!Tower data
IF ( p%NumTwrNds > 0 ) THEN
ALLOCATE(InitOut%TwrElev(p%NumTwrNds), STAT = ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating memory for TwrElev.", ErrStat, ErrMsg, RoutineName)
RETURN
END IF
IF ( MHK == MHK_FixedBottom ) THEN
InitOut%TwrElev(:) = InputFileData%TwrElev(:) - WtrDpth
ELSE
InitOut%TwrElev(:) = InputFileData%TwrElev(:)
END IF
ALLOCATE(InitOut%TwrDiam(p%NumTwrNds), STAT = ErrStat2)
IF (ErrStat2 /= 0) THEN
CALL SetErrStat(ErrID_Fatal,"Error allocating memory for TwrDiam.", ErrStat, ErrMsg, RoutineName)
RETURN
END IF
InitOut%TwrDiam(:) = p%TwrDiam(:)
END IF
end subroutine AD_SetInitOut
!----------------------------------------------------------------------------------------------------------------------------------
!> This routine is called at the start of the simulation to perform initialization steps.
!! The parameters are set here and not changed during the simulation.
!! The initial states and initial guess for the input are defined.
subroutine AD_Init( InitInp, u, p, x, xd, z, OtherState, y, m, Interval, InitOut, ErrStat, ErrMsg )
!..................................................................................................................................
type(AD_InitInputType), intent(in ) :: InitInp !< Input data for initialization routine
type(AD_InputType), intent( out) :: u !< An initial guess for the input; input mesh must be defined
type(AD_ParameterType), intent( out) :: p !< Parameters
type(AD_ContinuousStateType), intent( out) :: x !< Initial continuous states
type(AD_DiscreteStateType), intent( out) :: xd !< Initial discrete states
type(AD_ConstraintStateType), intent( out) :: z !< Initial guess of the constraint states
type(AD_OtherStateType), intent( out) :: OtherState !< Initial other states
type(AD_OutputType), intent( out) :: y !< Initial system outputs (outputs are not calculated;
!! only the output mesh is initialized)
type(AD_MiscVarType), intent( out) :: m !< Initial misc/optimization variables
real(DbKi), intent(inout) :: interval !< Coupling interval in seconds: the rate that
!! (1) AD_UpdateStates() is called in loose coupling &
!! (2) AD_UpdateDiscState() is called in tight coupling.
!! Input is the suggested time from the glue code;
!! Output is the actual coupling interval that will be used
!! by the glue code.
type(AD_InitOutputType), intent( out) :: InitOut !< Output for initialization routine
integer(IntKi), intent( out) :: errStat !< Error status of the operation
character(*), intent( out) :: errMsg !< Error message if ErrStat /= ErrID_None
! Local variables
integer(IntKi) :: i,k ! loop counter
integer(IntKi) :: iR ! loop on rotors
integer(IntKi) :: nNodesVelRot ! number of nodes associated with the rotor that need wind velocity (for CFD coupling)
integer(IntKi) :: errStat2 ! temporary error status of the operation
character(ErrMsgLen) :: errMsg2 ! temporary error message
type(FileInfoType) :: FileInfo_In !< The derived type for holding the full input file for parsing -- we may pass this in the future
type(AD_InputFile) :: InputFileData ! Data stored in the module's input file after parsing
character(1024) :: PriPath !< Primary path
integer(IntKi) :: UnEcho ! Unit number for the echo file
integer(IntKi) :: nRotors ! Number of rotors
integer(IntKi), allocatable, dimension(:) :: NumBlades ! Number of blades per rotor
integer(IntKi) , allocatable, dimension(:) :: AeroProjMod ! AeroProjMod per rotor
logical , allocatable, dimension(:) :: calcCrvAngle ! whether the curve angle should be calculated
character(*), parameter :: RoutineName = 'AD_Init'
! Initialize variables for this routine
errStat = ErrID_None
errMsg = ""
UnEcho = -1
! Initialize the NWTC Subroutine Library
call NWTC_Init( EchoLibVer=.FALSE. )
! Display the module information
call DispNVD( AD_Ver )
! Allocate rotors data types
nRotors = size(InitInp%rotors)
allocate(x%rotors(nRotors), xd%rotors(nRotors), z%rotors(nRotors), OtherState%rotors(nRotors), stat=errStat2)
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating rotor states', errStat, errMsg, RoutineName )
allocate(u%rotors(nRotors), y%rotors(nRotors), InitOut%rotors(nRotors), InputFileData%rotors(nRotors), stat=errStat2)
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating rotor input/outputs', errStat, errMsg, RoutineName )
allocate(p%rotors(nRotors), m%rotors(nRotors), stat=errStat2)
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating rotor params/misc', errStat, errMsg, RoutineName )
allocate(NumBlades(nRotors), stat=errStat2 ) ! temp array to pass NumBlades
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating numblades per rotor', errStat, errMsg, RoutineName )
allocate(AeroProjMod(nRotors), stat=errStat2 ) ! temp array to pass AeroProjMod
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating AeroProjMod per rotor', errStat, errMsg, RoutineName )
! Inflow storage
allocate(m%Inflow(3), stat=errStat2)
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating Inflow', errStat, errMsg, RoutineName )
allocate(m%Inflow(1)%RotInflow(nRotors), stat=errStat2)
if (errStat2/=0) call SetErrStat( ErrID_Fatal, 'Allocating rotor inflow', errStat, errMsg, RoutineName )
if (errStat/=ErrID_None) then
call Cleanup()
return
end if
AeroProjMod=-1
! set a few parameters needed while reading the input file
do iR = 1, nRotors
call ValidateNumBlades( InitInp%rotors(iR)%NumBlades, ErrStat2, ErrMsg2 )
if (Failed()) return;
NumBlades(iR) = InitInp%rotors(iR)%NumBlades
p%rotors(iR)%NumBlades = InitInp%rotors(iR)%NumBlades
AeroProjMod(iR) = InitInp%rotors(iR)%AeroProjMod ! NOTE: we allow this to be overwritten
if (nRotors > 1) then
p%rotors(iR)%RootName = TRIM(InitInp%RootName)//'.AD.R'//trim(num2lstr(iR))
else
p%rotors(iR)%RootName = TRIM(InitInp%RootName)//'.AD'
endif
enddo
p%RootName = TRIM(InitInp%RootName)//'.AD'
CALL GetPath( InitInp%InputFile, PriPath ) ! Input files will be relative to the path where the primary input file is located.
! -----------------------------------------------------------------
! Read the primary AeroDyn input file, or copy from passed input
if (InitInp%UsePrimaryInputFile) then
! Read the entire input file, minus any comment lines, into the FileInfo_In
! data structure in memory for further processing.
call ProcessComFile( InitInp%InputFile, FileInfo_In, ErrStat2, ErrMsg2 )
else
call NWTC_Library_CopyFileInfoType( InitInp%PassedPrimaryInputData, FileInfo_In, MESH_NEWCOPY, ErrStat2, ErrMsg2 )
endif
if (Failed()) return;
! For diagnostic purposes, the following can be used to display the contents
! of the FileInfo_In data structure.
! call Print_FileInfo_Struct( CU, FileInfo_In ) ! CU is the screen -- different number on different systems.
! Parse the FileInfo_In structure of data from the inputfile into the InitInp%InputFile structure
CALL ParsePrimaryFileInfo( PriPath, InitInp, InitInp%InputFile, p%RootName, NumBlades, interval, FileInfo_In, InputFileData, UnEcho, ErrStat2, ErrMsg2 )
if (Failed()) return;
! --- "Automatic handling of AeroProjMod
do iR = 1, nRotors
if (AeroProjMod(iR) == -1) then
if (InputFileData%Wake_Mod /= WakeMod_BEMT) then
! For BEMT, we don't throw a warning
call WrScr('[INFO] Using the input file input `BEM_Mod` to match BEM coordinate system outputs')
endif
select case (InputFileData%BEM_Mod)
case (BEMMod_2D); AeroProjMod(ir) = APM_BEM_NoSweepPitchTwist
case (BEMMod_3D); AeroProjMod(ir) = APM_BEM_Polar
case default; call Fatal('Input `BEM_Mod` not supported: '//trim(num2lstr(InputFileData%BEM_Mod))); return
end select
endif
enddo
call AllocAry( calcCrvAngle, sum(NumBlades), 'calcCrvAngle', ErrStat2, ErrMsg2)
if (Failed()) return;
! -----------------------------------------------------------------
! Read the AeroDyn blade files, or copy from passed input
call ReadInputFiles( InitInp%InputFile, InputFileData, interval, p%RootName, NumBlades, AeroProjMod, UnEcho, calcCrvAngle, ErrStat2, ErrMsg2 )
if (Failed()) return;
! override some parameters to simplify for aero maps
! bjj: do we put a warning here if any of these values aren't currently set this way?
if (InitInp%CompAeroMaps) then
InputFileData%DTAero = interval ! we're not using this, so set it to something "safe"
InputFileData%UA_Init%UAMod = UA_None
InputFileData%TwrPotent = TwrPotent_none
InputFileData%TwrShadow = TwrShadow_none
InputFileData%TwrAero = TwrAero_none
!InputFileData%CavitCheck = .false.
!InputFileData%TFinAero = .false. ! not sure if this needs to be set or not
InputFileData%DBEMT_Mod = DBEMT_none
end if
! Validate the inputs
call ValidateInputData( InitInp, InputFileData, NumBlades, calcCrvAngle, ErrStat2, ErrMsg2 )
if (Failed()) return;
! set BlCrvAng (in radians, done after validation of other inputs):
k = 1;
do iR = 1, nRotors
do I=1,NumBlades(iR)
if (calcCrvAngle(k)) CALL setCantAngle( InputFileData%rotors(iR)%BladeProps(I) )
k = k + 1
end do
end do
!............................................................................................
! Define parameters
!............................................................................................
! Initialize AFI module (read Airfoil tables)
call Init_AFIparams( InputFileData, p%AFI, UnEcho, p%RootName, ErrStat2, ErrMsg2 )
if (Failed()) return;
! set the rest of the parameters
p%Skew_Mod = InputFileData%Skew_Mod
do iR = 1, nRotors
p%rotors(iR)%AeroProjMod = AeroProjMod(iR)
call WrScr(' AeroDyn: projMod: '//trim(num2lstr(p%rotors(iR)%AeroProjMod)))
call SetParameters( InitInp, InputFileData, InputFileData%rotors(iR), p%rotors(iR), p, ErrStat2, ErrMsg2 )
if (Failed()) return;
enddo
! TailFin parameters
do iR = 1, nRotors
p%rotors(iR)%TFinAero = InputFileData%rotors(iR)%TFinAero
p%rotors(iR)%TFin%TFinMod = InputFileData%rotors(iR)%TFin%TFinMod
p%rotors(iR)%TFin%TFinArea = InputFileData%rotors(iR)%TFin%TFinArea
p%rotors(iR)%TFin%TFinIndMod = InputFileData%rotors(iR)%TFin%TFinIndMod
p%rotors(iR)%TFin%TFinAFID = InputFileData%rotors(iR)%TFin%TFinAFID
p%rotors(iR)%TFin%TFinChord = InputFileData%rotors(iR)%TFin%TFinChord
p%rotors(iR)%TFin%TFinKp = InputFileData%rotors(iR)%TFin%TFinKp
p%rotors(iR)%TFin%TFinSigma = InputFileData%rotors(iR)%TFin%TFinSigma
p%rotors(iR)%TFin%TFinAStar = InputFileData%rotors(iR)%TFin%TFinAStar
p%rotors(iR)%TFin%TFinKv = InputFileData%rotors(iR)%TFin%TFinKv
p%rotors(iR)%TFin%TFinCDc = InputFileData%rotors(iR)%TFin%TFinCDc
enddo
! Set pointer to FlowField data
if (associated(InitInp%FlowField)) p%FlowField => InitInp%FlowField
!............................................................................................
! Define and initialize inputs here
!............................................................................................
do iR = 1, nRotors
call Init_u( u%rotors(iR), p%rotors(iR), p, InputFileData%rotors(iR), InitInp%MHK, InitInp%WtrDpth, InitInp%rotors(iR), errStat2, errMsg2 )
if (Failed()) return;
enddo
!............................................................................................
! Calculate buoyancy parameters
!............................................................................................
do iR = 1, nRotors
if ( p%rotors(iR)%Buoyancy ) then
call SetBuoyancyParameters( InputFileData%rotors(iR), u%rotors(iR), p%rotors(iR), ErrStat2, ErrMsg2 )
if (Failed()) return;
end if
end do
!............................................................................................
! Initialize the BEMT module (also sets other variables for sub module)
!............................................................................................
! initialize BEMT after setting parameters and inputs because we are going to use the already-
! calculated node positions from the input meshes
if (p%Wake_Mod /= WakeMod_FVW) then
do iR = 1, nRotors
call Init_BEMTmodule( InputFileData, InputFileData%rotors(iR), u%rotors(iR), m%rotors(iR)%BEMT_u(1), p%rotors(iR), p, x%rotors(iR)%BEMT, xd%rotors(iR)%BEMT, z%rotors(iR)%BEMT, &
OtherState%rotors(iR)%BEMT, m%rotors(iR)%BEMT_y, m%rotors(iR)%BEMT, ErrStat2, ErrMsg2 )
if (Failed()) return;
call BEMT_CopyInput( m%rotors(iR)%BEMT_u(1), m%rotors(iR)%BEMT_u(2), MESH_NEWCOPY, ErrStat2, ErrMsg2 )
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
!............................................................................................
! Initialize the AeroAcoustics Module if the CompAA flag is set
!............................................................................................
if (p%rotors(iR)%CompAA) then
call Init_AAmodule( InitInp%rotors(iR), InputFileData, InputFileData%rotors(iR), u%rotors(iR), m%rotors(iR)%AA_u, p%rotors(iR), p, x%rotors(iR)%AA, xd%rotors(iR)%AA, z%rotors(iR)%AA, OtherState%rotors(iR)%AA, m%rotors(iR)%AA_y, m%rotors(iR)%AA, ErrStat2, ErrMsg2 )
if (Failed()) return;
end if
enddo
else ! if (p%Wake_Mod == WakeMod_FVW) then
!-------------------------------------------------------------------------------------------------
! Initialize FVW module if it is used
!-------------------------------------------------------------------------------------------------
! Unfortunately we do not know the interpolation order used by OpenFAST glue code at this point,
! so we can't size things exactly. This means that we either must size too big here, or we must
! resize in the FVW code at the first CalcOutput call. This is a bit problematic for efficiency
! but not a complete deal-breaker.
if (.not. allocated(m%FVW_u)) Allocate(m%FVW_u(3)) !size(u)))
call Init_OLAF( InputFileData, u, m%FVW_u(1), p, x%FVW, xd%FVW, z%FVW, OtherState%FVW, m, ErrStat2, ErrMsg2 )
if (Failed()) return;
! populate the rest of the FVW_u so that extrap-interp will work
do i=2,3 !size(u)
call FVW_CopyInput( m%FVW_u(1), m%FVW_u(i), MESH_NEWCOPY, ErrStat2, ErrMsg2 )
if (Failed()) return;
enddo
endif
!............................................................................................
! Define outputs here
!............................................................................................
do iR = 1, nRotors
call Init_y(y%rotors(iR), u%rotors(iR), p%rotors(iR), errStat2, errMsg2) ! do this after input meshes have been initialized
if (Failed()) return;
enddo
!............................................................................................
! Initialize misc vars
!............................................................................................
! many states are in the BEMT module, which were initialized in BEMT_Init()
do iR = 1, nRotors
call Init_MiscVars(m%rotors(iR), p%rotors(iR), p, u%rotors(iR), y%rotors(iR), errStat2, errMsg2)
if (Failed()) return;
enddo
!............................................................................................
! Initialize m%Inflow%RotInflow for tracking wind inflow
!............................................................................................
do iR = 1, nRotors
call Init_RotInflow( p%rotors(iR), m%Inflow(1)%RotInflow(iR), errStat2, ErrMsg2 )
if (Failed()) return
enddo
! Duplicte Inflow(1) (must be done after Init_OLAF)
call AD_CopyInflowType(m%Inflow(1), m%Inflow(2), MESH_NEWCOPY, ErrStat2, ErrMsg2)
if (Failed()) return
call AD_CopyInflowType(m%Inflow(1), m%Inflow(3), MESH_NEWCOPY, ErrStat2, ErrMsg2)
if (Failed()) return
!............................................................................................
! Initialize states
!............................................................................................
! The wake from FVW is stored in other states. This may not be the best place to put it!
call Init_States(m, p, OtherState, errStat2, errMsg2)
if (Failed()) return;
!............................................................................................
! Define initialization output here
!............................................................................................
InitOut%Ver = AD_Ver
do iR = 1, nRotors
call AD_SetInitOut(InitInp%MHK, InitInp%WtrDpth, p%rotors(iR), p, InputFileData%rotors(iR), InitOut%rotors(iR), errStat2, errMsg2)
if (Failed()) return;
enddo
! after setting InitOut variables, we really don't need the airfoil coordinates taking up
! space in AeroDyn
if ( allocated(p%AFI) ) then
do i=1,size(p%AFI)
if (allocated(p%AFI(i)%X_Coord)) deallocate( p%AFI(i)%X_Coord)
if (allocated(p%AFI(i)%Y_Coord)) deallocate( p%AFI(i)%Y_Coord)
end do
end if
! number of nodes velocity is required at (for coupling to cfd)
InitOut%nNodesVel = 0
do iR = 1, nRotors
if (u%rotors(iR)%HubMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%HubMotion%nNodes
do k = 1,size(u%rotors(iR)%BladeMotion)
if (u%rotors(iR)%BladeMotion(k)%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%BladeMotion(k)%nNodes
enddo
if (u%rotors(iR)%TowerMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%TowerMotion%nNodes
if (u%rotors(iR)%NacelleMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%NacelleMotion%nNodes
if (u%rotors(iR)%TFinMotion%committed) InitOut%nNodesVel = InitOut%nNodesVel + u%rotors(iR)%TFinMotion%nNodes
enddo
!............................................................................................
! Initialize Jacobian:
!............................................................................................
if (InitInp%Linearize .or. InitInp%CompAeroMaps) then
do iR = 1, nRotors
call Init_Jacobian(InputFileData%rotors(iR), p%rotors(iR), p, u%rotors(iR), y%rotors(iR), m%rotors(iR), InitOut%rotors(iR), errStat2, errMsg2)
if (Failed()) return;
enddo
end if
!............................................................................................
! Print the summary file if requested:
!............................................................................................
if (InputFileData%SumPrint) then
do iR = 1, nRotors
call AD_PrintSum( InputFileData, p%rotors(iR), p, u, y, NumBlades(iR), InputFileData%rotors(iR)%BladeProps(:), ErrStat2, ErrMsg2 )
if (Failed()) return;
enddo
end if
!............................................................................................
! If you want to choose your own rate instead of using what the glue code suggests, tell the glue code the rate at which
! this module must be called here:
!............................................................................................
Interval = p%DT
call Cleanup()
contains
subroutine Fatal(errMsg_in)
character(*), intent(in) :: errMsg_in
call SetErrStat(ErrID_Fatal, errMsg_in, ErrStat, ErrMsg, RoutineName )
call Cleanup()
end subroutine Fatal
logical function Failed()
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
Failed = ErrStat >= AbortErrLev
if (Failed) call Cleanup()
end function Failed
subroutine Cleanup()
CALL AD_DestroyInputFile( InputFileData, ErrStat2, ErrMsg2 )
CALL NWTC_Library_Destroyfileinfotype(FileInfo_In, ErrStat2, ErrMsg2)
if (allocated(NumBlades )) deallocate(NumBlades)
if (allocated(AeroProjMod )) deallocate(AeroProjMod)
if (allocated(calcCrvAngle)) deallocate(calcCrvAngle)
IF ( UnEcho > 0 ) CLOSE( UnEcho )
end subroutine Cleanup
end subroutine AD_Init
!----------------------------------------------------------------------------------------------------------------------------------
!> This subroutine reinitializes BEMT and UA, assuming that we will start the simulation over again, with only the inputs being different.
!! This allows us to bypass reading input files and allocating arrays because p is already set.
subroutine AD_ReInit(p, x, xd, z, OtherState, m, Interval, ErrStat, ErrMsg )
type(AD_ParameterType), intent(in ) :: p !< Parameters
type(AD_ContinuousStateType), intent(inout) :: x !< Initial continuous states
type(AD_DiscreteStateType), intent(inout) :: xd !< Initial discrete states
type(AD_ConstraintStateType), intent(inout) :: z !< Initial guess of the constraint states
type(AD_OtherStateType), intent(inout) :: OtherState !< Initial other states
type(AD_MiscVarType), intent(inout) :: m !< Initial misc/optimization variables
real(DbKi), intent(in ) :: interval !< Coupling interval in seconds: the rate that
!! (1) AD_UpdateStates() is called in loose coupling &
!! (2) AD_UpdateDiscState() is called in tight coupling.
!! Input is the suggested time from the glue code;
!! Output is the actual coupling interval that will be used
!! by the glue code.
integer(IntKi), intent( out) :: errStat !< Error status of the operation
character(*), intent( out) :: errMsg !< Error message if ErrStat /= ErrID_None
integer(IntKi) :: iR ! loop on rotors
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
character(*), parameter :: RoutineName = 'AD_ReInit'
ErrStat = ErrID_None
ErrMsg = ''
if ( .not. EqualRealNos(p%DT, interval) ) then
call SetErrStat( ErrID_Fatal, 'When AD is reinitialized, DT must not change.', ErrStat, ErrMsg, RoutineName )
return
! we could get around this by figuring out what needs to change when we modify the dt parameter... probably just some unused-parameters
! and the UA filter
end if
if (p%Wake_Mod /= WakeMod_FVW) then
do IR=1, size(p%rotors)
call BEMT_ReInit(p%rotors(iR)%BEMT,x%rotors(iR)%BEMT,xd%rotors(iR)%BEMT,z%rotors(iR)%BEMT,OtherState%rotors(iR)%BEMT,m%rotors(iR)%BEMT,ErrStat,ErrMsg)
if (p%UA_Flag) then
call UA_ReInit( p%rotors(iR)%BEMT%UA, x%rotors(iR)%BEMT%UA, xd%rotors(iR)%BEMT%UA, OtherState%rotors(iR)%BEMT%UA, m%rotors(iR)%BEMT%UA, ErrStat2, ErrMsg2 )
call SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
end if
enddo
else
ErrStat = ErrID_Fatal
ErrMsg = 'AD_ReInit: Cannot reinitialize AeroDyn with OLAF'
end if
end subroutine AD_ReInit
!----------------------------------------------------------------------------------------------------------------------------------
!> This routine initializes (allocates) the misc variables for use during the simulation.
subroutine Init_MiscVars(m, p, p_AD, u, y, errStat, errMsg)
type(RotMiscVarType), intent(inout) :: m !< misc/optimization data (not defined in submodules)
type(RotParameterType), intent(in ) :: p !< Parameters
type(AD_ParameterType), intent(in ) :: p_AD !< Parameters
type(RotInputType), intent(inout) :: u !< input for HubMotion mesh (create sibling mesh here)
type(RotOutputType), intent(inout) :: y !< output (create mapping between output and otherstate mesh here)
integer(IntKi), intent( out) :: errStat !< Error status of the operation
character(*), intent( out) :: errMsg !< Error message if ErrStat /= ErrID_None
! Local variables
integer(intKi) :: i, j, k
integer(intKi) :: ErrStat2 ! temporary Error status
character(ErrMsgLen) :: ErrMsg2 ! temporary Error message
character(*), parameter :: RoutineName = 'Init_MiscVars'
! Initialize variables for this routine
errStat = ErrID_None
errMsg = ""
call AllocAry( m%DisturbedInflow, 3_IntKi, p%NumBlNds, p%numBlades, 'm%DisturbedInflow', ErrStat2, ErrMsg2 ) ! must be same size as RotInflow%Blade(k)%InflowVel
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
if ((p_AD%SectAvg) .and. ((p_AD%Wake_Mod == WakeMod_BEMT)) ) then
call AllocAry( m%SectAvgInflow, 3_IntKi, p%NumBlNds, p%numBlades, 'm%SectAvgInflow' , ErrStat2, ErrMsg2 ); if(Failed()) return
endif
call AllocAry( m%orientationAnnulus, 3_IntKi, 3_IntKi, p%NumBlNds, p%numBlades, 'm%orientationAnnulus', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%R_li, 3_IntKi, 3_IntKi, p%NumBlNds, p%numBlades, 'm%R_li', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call allocAry( m%SigmaCavit, p%NumBlNds, p%numBlades, 'm%SigmaCavit', errStat2, errMsg2); call setErrStat(errStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
call allocAry( m%SigmaCavitCrit, p%NumBlNds, p%numBlades, 'm%SigmaCavitCrit', errStat2, errMsg2); call setErrStat(errStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
call allocAry( m%CavitWarnSet, p%NumBlNds, p%numBlades, 'm%CavitWarnSet', errStat2, errMsg2); call setErrStat(errStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
m%SigmaCavit = 0.0_ReKi !Init to zero for output files in case a cavit check isnt done but output is requested
m%SigmaCavitCrit = 0.0_ReKi
m%CavitWarnSet = .false.
! arrays for output
allocate( m%AllOuts(0:MaxOutPts), STAT=ErrStat2 ) ! allocate starting at zero to account for invalid output channels
if (ErrStat2 /= 0) then
call SetErrStat( ErrID_Fatal, "Error allocating AllOuts.", errStat, errMsg, RoutineName )
return
end if
m%AllOuts = 0.0_ReKi
! save these tower calculations for output:
call AllocAry( m%W_Twr, p%NumTwrNds, 'm%W_Twr', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%X_Twr, p%NumTwrNds, 'm%X_Twr', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Y_Twr, p%NumTwrNds, 'm%Y_Twr', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
! save blade calculations for output:
if (p%TwrPotent /= TwrPotent_none .or. p%TwrShadow /= TwrShadow_none) then
call AllocAry( m%TwrClrnc, p%NumBlNds, p%NumBlades, 'm%TwrClrnc', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
end if
call AllocAry( m%Cant, p%NumBlNds, p%NumBlades, 'm%Cant', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Toe, p%NumBlNds, p%NumBlades, 'm%Toe', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%X, p%NumBlNds, p%NumBlades, 'm%X', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Y, p%NumBlNds, p%NumBlades, 'm%Y', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Z, p%NumBlNds, p%NumBlades, 'm%Z', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%hub_theta_x_root, p%NumBlades, 'm%hub_theta_x_root', ErrStat2, ErrMsg2 )
call AllocAry( m%M, p%NumBlNds, p%NumBlades, 'm%M', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Mx, p%NumBlNds, p%NumBlades, 'm%Mx', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%My, p%NumBlNds, p%NumBlades, 'm%My', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Mz, p%NumBlNds, p%NumBlades, 'm%Mz', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
call AllocAry( m%Vind_i, 3, p%NumBlNds, p%NumBlades, 'm%Vind_i', ErrStat2, ErrMsg2 )
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
! mesh mapping data for integrating load over entire rotor:
allocate( m%B_L_2_H_P(p%NumBlades), Stat = ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat( ErrID_Fatal, "Error allocating B_L_2_H_P mapping structure.", errStat, errMsg, RoutineName )
return
end if
call MeshCopy( y%HubLoad, m%HubLoad, MESH_NEWCOPY, ErrStat2, ErrMsg2 )
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
if (ErrStat >= AbortErrLev) RETURN
do k=1,p%NumBlades
CALL MeshMapCreate( y%BladeLoad(k), m%HubLoad, m%B_L_2_H_P(k), ErrStat2, ErrMsg2 )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName//':B_L_2_H_P('//TRIM(Num2LStr(K))//')' )
end do
if (ErrStat >= AbortErrLev) RETURN
! Mesh mapping data for integrating load over entire blade:
allocate( m%B_L_2_R_P(p%NumBlades), Stat = ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat( ErrID_Fatal, "Error allocating B_L_2_R_P mapping structure.", errStat, errMsg, RoutineName )
return
end if
allocate( m%BladeRootLoad(p%NumBlades), Stat = ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat( ErrID_Fatal, "Error allocating BladeRootLoad mesh array.", errStat, errMsg, RoutineName )
return
end if
do k=1,p%NumBlades
call MeshCopy ( SrcMesh = u%BladeRootMotion(k) &
, DestMesh = m%BladeRootLoad(k) &
, CtrlCode = MESH_SIBLING &
, IOS = COMPONENT_OUTPUT &
, force = .TRUE. &
, moment = .TRUE. &
, ErrStat = ErrStat2 &
, ErrMess = ErrMsg2 )
call SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
end do !k=blades
if (ErrStat >= AbortErrLev) RETURN
do k=1,p%NumBlades
CALL MeshMapCreate( y%BladeLoad(k), m%BladeRootLoad(k), m%B_L_2_R_P(k), ErrStat2, ErrMsg2 )
CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName//':B_L_2_R_P('//TRIM(Num2LStr(K))//')' )
end do !k=blades
if (ErrStat >= AbortErrLev) RETURN
if (p%Buoyancy) then
! Point mesh for blade buoyant loads
allocate(m%BladeBuoyLoadPoint(p%NumBlades), Stat = ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat(ErrID_Fatal, "Error allocating BladeBuoyLoadPoint mesh array.", errStat, errMsg, RoutineName)
return
end if
! Line mesh for blade buoyant loads
allocate(m%BladeBuoyLoad(p%NumBlades), Stat = ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat(ErrID_Fatal, "Error allocating BladeBuoyLoad mesh array.", errStat, errMsg, RoutineName)
return
end if
! Mesh mapping for blade buoyant loads from point to line
allocate(m%B_P_2_B_L(p%NumBlades), Stat = ErrStat2)
if (ErrStat2 /= 0) then
call SetErrStat(ErrID_Fatal, "Error allocating B_P_2_B_L mapping structure.", errStat, errMsg, RoutineName)
return
end if
do k=1,p%NumBlades
call MeshCreate ( BlankMesh = m%BladeBuoyLoadPoint(k) &
, IOS = COMPONENT_OUTPUT &
, Nnodes = p%NumBlNds &
, force = .TRUE. &
, moment = .TRUE. &
, ErrStat = ErrStat2 &
, ErrMess = ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
do j = 1,p%NumBlNds
call MeshPositionNode(m%BladeBuoyLoadPoint(k), j, u%BladeMotion(k)%Position(:,j), errStat2, errMsg2, u%BladeMotion(k)%RefOrientation(:,:,j))
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
call MeshConstructElement(m%BladeBuoyLoadPoint(k), ELEMENT_POINT, errStat2, errMsg2, p1=j)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
end do !j=nodes
call MeshCommit(m%BladeBuoyLoadPoint(k), errStat2, errMsg2)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName//':BladeBuoyLoadPoint'//trim(num2lstr(k)))
if (errStat >= AbortErrLev) return
m%BladeBuoyLoadPoint(k)%Force = 0.0_ReKi
m%BladeBuoyLoadPoint(k)%Moment = 0.0_ReKi
end do !k=blades
do k=1,p%NumBlades
call MeshCreate ( BlankMesh = m%BladeBuoyLoad(k) &
, IOS = COMPONENT_OUTPUT &
, Nnodes = p%NumBlNds &
, force = .TRUE. &
, moment = .TRUE. &
, ErrStat = ErrStat2 &
, ErrMess = ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
do j = 1,p%NumBlNds
call MeshPositionNode(m%BladeBuoyLoad(k), j, u%BladeMotion(k)%Position(:,j), errStat2, errMsg2, u%BladeMotion(k)%RefOrientation(:,:,j))
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
end do !j=nodes
do j = 1,p%NumBlNds-1
call MeshConstructElement(m%BladeBuoyLoad(k), ELEMENT_LINE2, errStat2, errMsg2, p1=j, p2=j+1)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
end do !j=nodes
call MeshCommit(m%BladeBuoyLoad(k), errStat2, errMsg2)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName//':BladeBuoyLoad'//trim(num2lstr(k)))
if (errStat >= AbortErrLev) return
m%BladeBuoyLoad(k)%Force = 0.0_ReKi
m%BladeBuoyLoad(k)%Moment = 0.0_ReKi
end do !k=blades
do k=1,p%NumBlades
call MeshMapCreate(m%BladeBuoyLoadPoint(k), m%BladeBuoyLoad(k), m%B_P_2_B_L(k), ErrStat2, ErrMsg2)
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName//':B_P_2_B_L('//TRIM(Num2LStr(K))//')')
end do !k=blades
if (ErrStat >= AbortErrLev) RETURN
if ( p%NumTwrNds > 0 ) then
call MeshCreate ( BlankMesh = m%TwrBuoyLoadPoint &
, IOS = COMPONENT_OUTPUT &
, Nnodes = p%NumTwrNds &
, force = .TRUE. &
, moment = .TRUE. &
, ErrStat = ErrStat2 &
, ErrMess = ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
do j = 1,p%NumTwrNds
call MeshPositionNode(m%TwrBuoyLoadPoint, j, u%TowerMotion%Position(:,j), errStat2, errMsg2, u%TowerMotion%RefOrientation(:,:,j))
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
call MeshConstructElement(m%TwrBuoyLoadPoint, ELEMENT_POINT, errStat2, errMsg2, p1=j)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
end do !j=nodes
call MeshCommit(m%TwrBuoyLoadPoint, errStat2, errMsg2)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName//':TwrBuoyLoadPoint')
if (errStat >= AbortErrLev) return
m%TwrBuoyLoadPoint%Force = 0.0_ReKi
m%TwrBuoyLoadPoint%Moment = 0.0_ReKi
call MeshCreate ( BlankMesh = m%TwrBuoyLoad &
, IOS = COMPONENT_OUTPUT &
, Nnodes = p%NumTwrNds &
, force = .TRUE. &
, moment = .TRUE. &
, ErrStat = ErrStat2 &
, ErrMess = ErrMsg2 )
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
do j = 1,p%NumTwrNds
call MeshPositionNode(m%TwrBuoyLoad, j, u%TowerMotion%Position(:,j), errStat2, errMsg2, u%TowerMotion%RefOrientation(:,:,j))
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
end do !j=nodes
do j = 1,p%NumTwrNds-1
call MeshConstructElement(m%TwrBuoyLoad, ELEMENT_LINE2, errStat2, errMsg2, p1=j, p2=j+1)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName)
end do !j=nodes
call MeshCommit(m%TwrBuoyLoad, errStat2, errMsg2)
call SetErrStat(errStat2, errMsg2, errStat, errMsg, RoutineName//':TwrBuoyLoad')
if (errStat >= AbortErrLev) return
m%TwrBuoyLoad%Force = 0.0_ReKi
m%TwrBuoyLoad%Moment = 0.0_ReKi
call MeshMapCreate(m%TwrBuoyLoadPoint, m%TwrBuoyLoad, m%T_P_2_T_L, ErrStat2, ErrMsg2)
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName//':T_P_2_T_L')
if (ErrStat >= AbortErrLev) RETURN
end if
end if
!
if (p%NumTwrNds > 0) then
m%W_Twr = 0.0_ReKi
m%X_Twr = 0.0_ReKi
m%Y_Twr = 0.0_ReKi
end if
m%FirstWarn_TowerStrike = .true.
contains
logical function Failed()
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
Failed = ErrStat >= AbortErrLev
end function Failed
end subroutine Init_MiscVars
!----------------------------------------------------------------------------------------------------------------------------------
!> This routine initializes (allocates) the states for use during the simulation.
subroutine Init_States(m, p, OtherState, errStat, errMsg)
type(AD_MiscVarType), intent(in ) :: m !< misc/optimization data (not defined in submodules)
type(AD_ParameterType), intent(in ) :: p !< Parameters
type(AD_OtherStateType), intent(inout) :: OtherState !< Discrete states
integer(IntKi), intent( out) :: errStat !< Error status of the operation
character(*), intent( out) :: errMsg !< Error message if ErrStat /= ErrID_None
! Local variables
integer(intKi) :: ErrStat2 ! temporary Error status
character(ErrMsgLen) :: ErrMsg2 ! temporary Error message
character(*), parameter :: RoutineName = 'Init_States'
errStat = ErrID_None
errMsg = ""
! store Wake positions in otherstates. This may not be the best location
if (allocated(m%FVW%r_wind)) then
call AllocAry( OtherState%WakeLocationPoints, 3_IntKi, size(m%FVW%r_wind,DIM=2), ' OtherState%WakeLocationPoints', ErrStat2, ErrMsg2 ) ! must be same size as m%r_wind from FVW
call SetErrStat( errStat2, errMsg2, errStat, errMsg, RoutineName )
OtherState%WakeLocationPoints = m%FVW%r_wind
endif
end subroutine Init_States
!----------------------------------------------------------------------------------------------------------------------------------
!> This routine initializes AeroDyn meshes and output array variables for use during the simulation.
subroutine Init_y(y, u, p, errStat, errMsg)
type(RotOutputType), intent( out) :: y !< Module outputs
type(RotInputType), intent(inout) :: u !< Module inputs -- intent(out) because of mesh sibling copy
type(RotParameterType), intent(in ) :: p !< Parameters
integer(IntKi), intent( out) :: errStat !< Error status of the operation
character(*), intent( out) :: errMsg !< Error message if ErrStat /= ErrID_None
! Local variables
integer(intKi) :: k ! loop counter for blades
integer(intKi) :: ErrStat2 ! temporary Error status
character(ErrMsgLen) :: ErrMsg2 ! temporary Error message
character(*), parameter :: RoutineName = 'Init_y'
! Initialize variables for this routine
errStat = ErrID_None
errMsg = ""