-
Notifications
You must be signed in to change notification settings - Fork 473
/
Copy pathFAST_Funcs.f90
878 lines (708 loc) · 40.3 KB
/
FAST_Funcs.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
!*******************************************************************************
! FAST_Funcs provides the glue code a uniform interface to module functions.
!...............................................................................
! 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.
!*******************************************************************************
!> This module contains functions for calling module subroutines
module FAST_Funcs
use FAST_Types
use FAST_ModTypes
use NWTC_LAPACK
use AeroDyn
use BeamDyn
use ElastoDyn
use HydroDyn
use InflowWind
use MAP
use MoorDyn
use SeaState
use ServoDyn
use SubDyn
implicit none
#define SOLVER_DEBUG
contains
subroutine FAST_ExtrapInterp(ModData, t_global_next, T, ErrStat, ErrMsg)
type(ModDataType), intent(in) :: ModData !< Module data
real(DbKi), intent(in) :: t_global_next !< next global time step (t + dt), at which we're extrapolating inputs (and ED outputs)
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
character(*), parameter :: RoutineName = 'FAST_ExtrapInterp'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
integer(IntKi) :: i, j
type(VarsIdxType), pointer :: VarIdx
ErrStat = ErrID_None
ErrMsg = ''
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
call AD_Input_ExtrapInterp(T%AD%Input, T%AD%InputTimes, T%AD%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call AD_CopyInput(T%AD%Input(j), T%AD%Input(j + 1), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%AD%InputTimes(j + 1) = T%AD%InputTimes(j)
end do
call AD_CopyInput(T%AD%u, T%AD%Input(1), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%AD%InputTimes(1) = t_global_next
case (Module_BD)
call BD_Input_ExtrapInterp(T%BD%Input(:, ModData%Ins), T%BD%InputTimes(:, ModData%Ins), T%BD%u(ModData%Ins), t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call BD_CopyInput(T%BD%Input(j, ModData%Ins), T%BD%Input(j + 1, ModData%Ins), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%BD%InputTimes(j + 1, ModData%Ins) = T%BD%InputTimes(j, ModData%Ins)
end do
call BD_CopyInput(T%BD%u(ModData%Ins), T%BD%Input(1, ModData%Ins), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%BD%InputTimes(1, ModData%Ins) = t_global_next
case (Module_ED)
call ED_Input_ExtrapInterp(T%ED%Input, T%ED%InputTimes, T%ED%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call ED_CopyInput(T%ED%Input(j), T%ED%Input(j + 1), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%ED%InputTimes(j + 1) = T%ED%InputTimes(j)
end do
call ED_CopyInput(T%ED%u, T%ED%Input(1), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%ED%InputTimes(1) = t_global_next
! case (Module_ExtPtfm)
! case (Module_FEAM)
case (Module_HD)
! TODO: Fix inconsistent function name (HydroDyn_CopyInput)
call HydroDyn_Input_ExtrapInterp(T%HD%Input, T%HD%InputTimes, T%HD%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call HydroDyn_CopyInput(T%HD%Input(j), T%HD%Input(j + 1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
T%HD%InputTimes(j + 1) = T%HD%InputTimes(j)
end do
call HydroDyn_CopyInput(T%HD%u, T%HD%Input(1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
T%HD%InputTimes(1) = t_global_next
! case (Module_IceD)
! case (Module_IceF)
case (Module_IfW)
call InflowWind_Input_ExtrapInterp(T%IfW%Input, T%IfW%InputTimes, T%IfW%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call InflowWind_CopyInput(T%IfW%Input(j), T%IfW%Input(j + 1), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%IfW%InputTimes(j + 1) = T%IfW%InputTimes(j)
end do
call InflowWind_CopyInput(T%IfW%u, T%IfW%Input(1), MESH_UPDATECOPY, Errstat2, ErrMsg2); if (Failed()) return
T%IfW%InputTimes(1) = t_global_next
! case (Module_MAP)
! case (Module_MD)
! case (Module_OpFM)
! case (Module_Orca)
case (Module_SD)
call SD_Input_ExtrapInterp(T%SD%Input, T%SD%InputTimes, T%SD%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call SD_CopyInput(T%SD%Input(j), T%SD%Input(j + 1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
T%SD%InputTimes(j + 1) = T%SD%InputTimes(j)
end do
call SD_CopyInput(T%SD%u, T%SD%Input(1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
T%SD%InputTimes(1) = t_global_next
case (Module_SeaSt)
! call SeaSt_Input_ExtrapInterp(T%SeaSt%Input, T%SeaSt%InputTimes, T%SeaSt%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
! do j = T%p_FAST%InterpOrder, 1, -1
! call SeaSt_CopyInput(T%SeaSt%Input(j), T%SeaSt%Input(j + 1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
! T%SeaSt%InputTimes(j + 1) = T%SeaSt%InputTimes(j)
! end do
! call SeaSt_CopyInput(T%SeaSt%u, T%SeaSt%Input(1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
! T%SeaSt%InputTimes(1) = t_global_next
case (Module_SrvD)
call SrvD_Input_ExtrapInterp(T%SrvD%Input, T%SrvD%InputTimes, T%SrvD%u, t_global_next, ErrStat2, ErrMsg2); if (Failed()) return
do j = T%p_FAST%InterpOrder, 1, -1
call SrvD_CopyInput(T%SrvD%Input(j), T%SrvD%Input(j + 1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
T%SrvD%InputTimes(j + 1) = T%SrvD%InputTimes(j)
end do
call SrvD_CopyInput(T%SrvD%u, T%SrvD%Input(1), MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
T%SrvD%InputTimes(1) = t_global_next
case default
call SetErrStat(ErrID_Fatal, "Unknown module ID "//trim(Num2LStr(ModData%ID)), ErrStat, ErrMsg, RoutineName)
return
end select
contains
logical function Failed()
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
Failed = ErrStat >= AbortErrLev
end function
end subroutine
subroutine FAST_InitIO(Mods, ThisTime, DT, T, ErrStat, ErrMsg)
type(ModDataType), intent(in) :: Mods(:) !< Module data
real(DbKi), intent(in) :: ThisTime !< Initial simulation time (almost always 0)
real(DbKi), intent(in) :: DT !< Glue code time step size
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
character(*), parameter :: RoutineName = 'FAST_InitIO'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
real(DbKi) :: t_global_next ! Simulation time for computing outputs
integer(IntKi) :: i, j, k
ErrStat = ErrID_None
ErrMsg = ''
! Loop through modules
do i = 1, size(Mods)
! Copy state from current to predicted and initialze meshes
call FAST_CopyStates(Mods(i), T, STATE_CURR, STATE_PRED, MESH_NEWCOPY, ErrStat2, ErrMsg2); if (Failed()) return
! Select based on module ID
select case (Mods(i)%ID)
case (Module_AD)
T%AD%InputTimes = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call AD_CopyInput(T%AD%Input(1), T%AD%Input(k), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call AD_CopyInput(T%AD%Input(1), T%AD%u, MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
case (Module_BD)
T%BD%InputTimes(:, Mods(i)%Ins) = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call BD_CopyInput(T%BD%Input(1, Mods(i)%Ins), T%BD%Input(k, Mods(i)%Ins), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call BD_CopyInput(T%BD%Input(1, Mods(i)%Ins), T%BD%u(Mods(i)%Ins), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
case (Module_ED)
T%ED%InputTimes = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call ED_CopyInput(T%ED%Input(1), T%ED%Input(k), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call ED_CopyInput(T%ED%Input(1), T%ED%u, MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_ExtPtfm)
! case (Module_FEAM)
case (Module_HD)
T%HD%InputTimes(:) = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call HydroDyn_CopyInput(T%HD%Input(1), T%HD%Input(k), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call HydroDyn_CopyInput(T%HD%Input(1), T%HD%u, MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_IceD)
! case (Module_IceF)
case (Module_IfW)
! TODO: Fix inconsistent function name
T%IfW%InputTimes = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call InflowWind_CopyInput(T%IfW%Input(1), T%IfW%Input(k), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call InflowWind_CopyInput(T%IfW%Input(1), T%IfW%u, MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_MAP)
! case (Module_MD)
! case (Module_OpFM)
! case (Module_Orca)
case (Module_SD)
T%SD%InputTimes = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call SD_CopyInput(T%SD%Input(1), T%SD%Input(k), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call SD_CopyInput(T%SD%Input(1), T%SD%u, MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_SeaSt)
case (Module_SrvD)
T%SrvD%InputTimes = ThisTime - DT*[(k, k=0, T%p_FAST%InterpOrder)]
do k = 2, T%p_FAST%InterpOrder + 1
call SrvD_CopyInput(T%SrvD%Input(1), T%SrvD%Input(k), MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
end do
call SrvD_CopyInput(T%SrvD%Input(1), T%SrvD%u, MESH_NEWCOPY, Errstat2, ErrMsg2); if (Failed()) return
case default
call SetErrStat(ErrID_Fatal, "Unknown module ID "//trim(Num2LStr(Mods(i)%ID)), ErrStat, ErrMsg, RoutineName)
return
end select
end do
contains
logical function Failed()
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
Failed = ErrStat >= AbortErrLev
end function
end subroutine
subroutine FAST_UpdateStates(ModData, t_initial, n_t_global, x_TC, q_TC, T, ErrStat, ErrMsg)
type(ModDataType), intent(in) :: ModData !< Module data
real(DbKi), intent(in) :: t_initial !< Initial simulation time (almost always 0)
integer(IntKi), intent(in) :: n_t_global !< Integer time step
real(R8Ki), intent(inout) :: x_TC(:) !< Tight coupling state array
real(R8Ki), intent(inout) :: q_TC(:, :) !< Tight coupling state matrix
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
character(*), parameter :: RoutineName = 'FAST_UpdateStates'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
integer(IntKi) :: i, j
integer(IntKi) :: j_ss ! substep loop counter
integer(IntKi) :: n_t_module ! simulation time step, loop counter for individual modules
real(DbKi) :: t_module ! Current simulation time for module
ErrStat = ErrID_None
ErrMsg = ''
! Copy from current to predicted state (MESH_UPDATECOPY)
call FAST_CopyStates(ModData, T, STATE_CURR, STATE_PRED, MESH_UPDATECOPY, ErrStat2, ErrMsg2); if (Failed()) return
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
do j_ss = 1, ModData%SubSteps
n_t_module = n_t_global*ModData%SubSteps + j_ss - 1
t_module = n_t_module*ModData%DT + t_initial
call AD_UpdateStates(t_module, n_t_module, T%AD%Input, T%AD%InputTimes, &
T%AD%p, T%AD%x(STATE_PRED), T%AD%xd(STATE_PRED), &
T%AD%z(STATE_PRED), T%AD%OtherSt(STATE_PRED), &
T%AD%m, ErrStat2, ErrMsg2)
if (Failed()) return
end do
case (Module_BD)
associate (p_BD => T%BD%p(ModData%Ins), &
m_BD => T%BD%m(ModData%Ins), &
u_BD => T%BD%Input(1, ModData%Ins), &
x_BD => T%BD%x(ModData%Ins, STATE_PRED), &
os_BD => T%BD%OtherSt(ModData%Ins, STATE_PRED))
! Transfer tight coupling states to module
call BD_PackStateValues(p_BD, x_BD, m_BD%Jac%x)
! call XferGblToLoc1D(ModData%ixs, x_TC, m_BD%Jac%x)
call BD_UnpackStateValues(p_BD, m_BD%Jac%x, x_BD)
! TODO: Fix state reset
! Set BD accelerations and algorithmic accelerations from q matrix
! do j = 1, size(p_BD%Vars%x)
! select case (p_BD%Vars%x(j)%Field)
! case (VF_TransDisp)
! os_BD%acc(1:3, p_BD%Vars%x(j)%iUsr(1)) = q_TC(p_BD%Vars%x(j)%iq, 3)
! os_BD%xcc(1:3, p_BD%Vars%x(j)%iUsr(1)) = q_TC(p_BD%Vars%x(j)%iq, 4)
! case (VF_Orientation)
! os_BD%acc(4:6, p_BD%Vars%x(j)%iUsr(1)) = q_TC(p_BD%Vars%x(j)%iq, 3)
! os_BD%xcc(4:6, p_BD%Vars%x(j)%iUsr(1)) = q_TC(p_BD%Vars%x(j)%iq, 4)
! end select
! end do
! Update the global reference
call BD_UpdateGlobalRef(u_BD, p_BD, x_BD, os_BD, ErrStat, ErrMsg)
if (Failed()) return
! Update q matrix accelerations and algorithmic accelerations from BD
! do j = 1, size(p_BD%Vars%x)
! select case (p_BD%Vars%x(j)%Field)
! case (VF_TransDisp)
! q_TC(p_BD%Vars%x(j)%iq, 3) = os_BD%acc(1:3, p_BD%Vars%x(j)%iUsr(1))
! q_TC(p_BD%Vars%x(j)%iq, 4) = os_BD%xcc(1:3, p_BD%Vars%x(j)%iUsr(1))
! case (VF_Orientation)
! q_TC(p_BD%Vars%x(j)%iq, 3) = os_BD%acc(4:6, p_BD%Vars%x(j)%iUsr(1))
! q_TC(p_BD%Vars%x(j)%iq, 4) = os_BD%xcc(4:6, p_BD%Vars%x(j)%iUsr(1))
! end select
! end do
! Transfer updated states to solver
call BD_PackStateValues(p_BD, x_BD, m_BD%Jac%x)
! call XferLocToGbl1D(ModData%ixs, m_BD%Jac%x, x_TC)
end associate
case (Module_ED)
associate (p_ED => T%ED%p, m_ED => T%ED%m, &
u_ED => T%ED%Input(1), x_ED => T%ED%x(STATE_PRED))
! Transfer tight coupling states to module
call ED_PackStateValues(p_ED, x_ED, m_ED%Jac%x)
! call XferGblToLoc1D(ModData%ixs, x_TC, m_ED%Jac%x)
call ED_UnpackStateValues(p_ED, m_ED%Jac%x, x_ED)
! Update the azimuth angle
call ED_UpdateAzimuth(p_ED, x_ED, T%p_FAST%DT)
! Transfer updated states to solver
call ED_PackStateValues(p_ED, x_ED, m_ED%Jac%x)
! call XferLocToGbl1D(ModData%ixs, m_ED%Jac%x, x_TC)
end associate
! case (Module_ExtPtfm)
! case (Module_FEAM)
case (Module_HD)
do j_ss = 1, ModData%SubSteps
n_t_module = n_t_global*ModData%SubSteps + j_ss - 1
t_module = n_t_module*ModData%DT + t_initial
call HydroDyn_UpdateStates(t_module, n_t_module, T%HD%Input, T%HD%InputTimes, T%HD%p, &
T%HD%x(STATE_PRED), T%HD%xd(STATE_PRED), &
T%HD%z(STATE_PRED), T%HD%OtherSt(STATE_PRED), &
T%HD%m, ErrStat2, ErrMsg2)
if (Failed()) return
end do
! case (Module_IceD)
! case (Module_IceF)
case (Module_IfW)
! do j_ss = 1, ModData%SubSteps
! n_t_module = n_t_global*ModData%SubSteps + j_ss - 1
! t_module = n_t_module*ModData%DT + t_initial
! call InflowWind_UpdateStates(t_module, n_t_module, T%IfW%Input, T%IfW%InputTimes, T%IfW%p, &
! T%IfW%x(STATE_PRED), T%IfW%xd(STATE_PRED), &
! T%IfW%z(STATE_PRED), T%IfW%OtherSt(STATE_PRED), &
! T%IfW%m, ErrStat2, ErrMsg2)
! if (Failed()) return
! end do
! case (Module_MAP)
! case (Module_MD)
! case (Module_OpFM)
! case (Module_Orca)
case (Module_SD)
associate (p_SD => T%SD%p, m_SD => T%SD%m, &
u_SD => T%SD%Input(1), x_SD => T%SD%x(STATE_PRED))
! TODO: Add Lin struct to SubDyn
! Transfer tight coupling states to module
! call SD_PackStateValues(p_SD, x_SD, m_SD%Lin%x)
! call XferGblToLoc1D(ModData%ixs, x_TC, m_SD%Lin%x)
! call SD_UnpackStateValues(p_SD, m_SD%Lin%x, x_SD)
end associate
! case (Module_SeaSt)
case (Module_SrvD)
do j_ss = 1, ModData%SubSteps
n_t_module = n_t_global*ModData%SubSteps + j_ss - 1
t_module = n_t_module*ModData%DT + t_initial
call SrvD_UpdateStates(t_module, n_t_module, T%SrvD%Input, T%SrvD%InputTimes, T%SrvD%p, &
T%SrvD%x(STATE_PRED), T%SrvD%xd(STATE_PRED), &
T%SrvD%z(STATE_PRED), T%SrvD%OtherSt(STATE_PRED), &
T%SrvD%m, ErrStat2, ErrMsg2)
if (Failed()) return
end do
case default
call SetErrStat(ErrID_Fatal, "Unknown module ID "//trim(Num2LStr(ModData%ID)), ErrStat, ErrMsg, RoutineName)
return
end select
contains
logical function Failed()
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
Failed = ErrStat >= AbortErrLev
end function
end subroutine
subroutine FAST_CalcOutput(ModData, Maps, ThisTime, ThisState, T, ErrStat, ErrMsg)
type(ModDataType), intent(in) :: ModData !< Module data
type(TC_MappingType), intent(inout) :: Maps(:) !< Output->Input mappings
real(DbKi), intent(in) :: ThisTime !< Time
integer(IntKi), intent(in) :: ThisState !< State index
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
character(*), parameter :: RoutineName = 'FAST_CalcOutput'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
integer(IntKi) :: i
ErrStat = ErrID_None
ErrMsg = ''
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
call AD_CalcOutput(ThisTime, T%AD%Input(1), T%AD%p, T%AD%x(ThisState), T%AD%xd(ThisState), T%AD%z(ThisState), &
T%AD%OtherSt(ThisState), T%AD%y, T%AD%m, ErrStat2, ErrMsg2, T%y_FAST%WriteThisStep)
case (Module_BD)
call BD_CalcOutput(ThisTime, T%BD%Input(1, ModData%Ins), T%BD%p(ModData%Ins), T%BD%x(ModData%Ins, ThisState), &
T%BD%xd(ModData%Ins, ThisState), T%BD%z(ModData%Ins, ThisState), T%BD%OtherSt(ModData%Ins, ThisState), &
T%BD%y(ModData%Ins), T%BD%m(ModData%Ins), ErrStat2, ErrMsg2)
case (Module_ED)
call ED_CalcOutput(ThisTime, T%ED%Input(1), T%ED%p, T%ED%x(ThisState), T%ED%xd(ThisState), &
T%ED%z(ThisState), T%ED%OtherSt(ThisState), T%ED%y, T%ED%m, ErrStat2, ErrMsg2)
! case (Module_ExtPtfm)
! case (Module_FEAM)
case (Module_HD)
call HydroDyn_CalcOutput(ThisTime, T%HD%Input(1), T%HD%p, T%HD%x(ThisState), T%HD%xd(ThisState), &
T%HD%z(ThisState), T%HD%OtherSt(ThisState), T%HD%y, T%HD%m, ErrStat2, ErrMsg2)
! case (Module_IceD)
! case (Module_IceF)
case (Module_IfW)
call InflowWind_CalcOutput(ThisTime, T%IfW%Input(1), T%IfW%p, T%IfW%x(ThisState), T%IfW%xd(ThisState), T%IfW%z(ThisState), &
T%IfW%OtherSt(ThisState), T%IfW%y, T%IfW%m, ErrStat2, ErrMsg2)
! case (Module_MAP)
! case (Module_MD)
! case (Module_OpFM)
! case (Module_Orca)
case (Module_SD)
call SD_CalcOutput(ThisTime, T%SD%Input(1), T%SD%p, T%SD%x(ThisState), T%SD%xd(ThisState), T%SD%z(ThisState), &
T%SD%OtherSt(ThisState), T%SD%y, T%SD%m, ErrStat2, ErrMsg2)
! case (Module_SeaSt)
case (Module_SrvD)
call SrvD_CalcOutput(ThisTime, T%SrvD%Input(1), T%SrvD%p, T%SrvD%x(ThisState), T%SrvD%xd(ThisState), T%SrvD%z(ThisState), &
T%SrvD%OtherSt(ThisState), T%SrvD%y, T%SrvD%m, ErrStat2, ErrMsg2)
case default
call SetErrStat(ErrID_Fatal, "Unknown module ID "//trim(Num2LStr(ModData%ID)), ErrStat, ErrMsg, RoutineName)
return
end select
! Check for errors during calc output call
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
if (ErrStat >= AbortErrLev) return
! Set updated flag in mappings where this module is the source
Maps(ModData%SrcMaps)%Ready = .true.
end subroutine
subroutine FAST_GetOP(ModData, ThisTime, ThisState, T, ErrStat, ErrMsg, FlagFilter, &
u_op, y_op, x_op, dx_op, xd_op, z_op)
type(ModDataType), intent(in) :: ModData !< Module data
real(DbKi), intent(in) :: ThisTime !< Time
integer(IntKi), intent(in) :: ThisState !< State index
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
integer(IntKi), optional, intent(in) :: FlagFilter !< Flag to filter variable calculations
real(R8Ki), allocatable, optional, intent(inout) :: u_op(:) !< values of linearized inputs
real(R8Ki), allocatable, optional, intent(inout) :: y_op(:) !< values of linearized outputs
real(R8Ki), allocatable, optional, intent(inout) :: x_op(:) !< values of linearized continuous states
real(R8Ki), allocatable, optional, intent(inout) :: dx_op(:) !< values of first time derivatives of linearized continuous states
real(R8Ki), allocatable, optional, intent(inout) :: xd_op(:) !< values of linearized discrete states
real(R8Ki), allocatable, optional, intent(inout) :: z_op(:) !< values of linearized constraint states
character(*), parameter :: RoutineName = 'FAST_GetOP'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
integer(IntKi) :: i
ErrStat = ErrID_None
ErrMsg = ''
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
call AD_GetOP(ModData%Ins, ThisTime, T%AD%Input(1), T%AD%p, T%AD%x(ThisState), T%AD%xd(ThisState), T%AD%z(ThisState), &
T%AD%OtherSt(ThisState), T%AD%y, T%AD%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
case (Module_BD)
call BD_GetOP(ThisTime, T%BD%Input(1, ModData%Ins), T%BD%p(ModData%Ins), T%BD%x(ModData%Ins, ThisState), &
T%BD%xd(ModData%Ins, ThisState), T%BD%z(ModData%Ins, ThisState), T%BD%OtherSt(ModData%Ins, ThisState), &
T%BD%y(ModData%Ins), T%BD%m(ModData%Ins), ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
case (Module_ED)
call ED_GetOP(ThisTime, T%ED%Input(1), T%ED%p, T%ED%x(ThisState), T%ED%xd(ThisState), &
T%ED%z(ThisState), T%ED%OtherSt(ThisState), T%ED%y, T%ED%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
! case (Module_ExtPtfm)
! case (Module_FEAM)
case (Module_HD)
call HD_GetOP(ThisTime, T%HD%Input(1), T%HD%p, T%HD%x(ThisState), T%HD%xd(ThisState), &
T%HD%z(ThisState), T%HD%OtherSt(ThisState), T%HD%y, T%HD%m, ErrStat2, ErrMsg2, &
u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
! case (Module_IceD)
! case (Module_IceF)
case (Module_IfW)
call InflowWind_GetOP(ThisTime, T%IfW%Input(1), T%IfW%p, T%IfW%x(ThisState), T%IfW%xd(ThisState), T%IfW%z(ThisState), &
T%IfW%OtherSt(ThisState), T%IfW%y, T%IfW%m, ErrStat2, ErrMsg2, &
u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
case (Module_MAP)
call MAP_GetOP(ThisTime, T%MAP%Input(1), T%MAP%p, T%MAP%x(ThisState), T%MAP%xd(ThisState), T%MAP%z(ThisState), &
T%MAP%OtherSt, T%MAP%y, ErrStat2, ErrMsg2, &
u_op=u_op, y_op=y_op) !, x_op=x_op, dx_op=dx_op) MAP doesn't have states
! case (Module_MD)
! case (Module_OpFM)
! case (Module_Orca)
case (Module_SD)
call SD_GetOP(ThisTime, T%SD%Input(1), T%SD%p, T%SD%x(ThisState), T%SD%xd(ThisState), T%SD%z(ThisState), &
T%SD%OtherSt(ThisState), T%SD%y, T%SD%m, ErrStat2, ErrMsg2, &
u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
! case (Module_SeaSt)
case (Module_SrvD)
call SrvD_GetOP(ThisTime, T%SrvD%Input(1), T%SrvD%p, T%SrvD%x(ThisState), T%SrvD%xd(ThisState), T%SrvD%z(ThisState), &
T%SrvD%OtherSt(ThisState), T%SrvD%y, T%SrvD%m, ErrStat2, ErrMsg2, &
u_op=u_op, y_op=y_op, x_op=x_op, dx_op=dx_op)
case default
! Unknown module
ErrStat2 = ErrID_Fatal
ErrMsg2 = "Unsupported module: "//trim(ModData%Abbr)
end select
! Check for errors during calc output call
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
end subroutine
subroutine FAST_JacobianPInput(ModData, ThisTime, ThisState, T, ErrStat, ErrMsg, FlagFilter, dYdu, dXdu)
type(ModDataType), intent(in) :: ModData !< Module data
real(DbKi), intent(in) :: ThisTime !< Time
integer(IntKi), intent(in) :: ThisState !< State
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
integer(IntKi), optional, intent(in) :: FlagFilter !< Variable index number
real(R8Ki), allocatable, optional, intent(inout) :: dYdu(:, :), dXdu(:, :)
character(*), parameter :: RoutineName = 'FAST_JacobianPInput'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
ErrStat = ErrID_None
ErrMsg = ''
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
call AD_JacobianPInput(ThisTime, T%AD%Input(1), T%AD%p, T%AD%x(ThisState), T%AD%xd(ThisState), &
T%AD%z(ThisState), T%AD%OtherSt(ThisState), T%AD%y, T%AD%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdu=dYdu, dXdu=dXdu)
case (Module_BD)
call BD_JacobianPInput(ThisTime, T%BD%Input(1, ModData%Ins), T%BD%p(ModData%Ins), T%BD%x(ModData%Ins, ThisState), T%BD%xd(ModData%Ins, ThisState), &
T%BD%z(ModData%Ins, ThisState), T%BD%OtherSt(ModData%Ins, ThisState), T%BD%y(ModData%Ins), T%BD%m(ModData%Ins), ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdu=dYdu, dXdu=dXdu)
case (Module_ED)
call ED_JacobianPInput(ThisTime, T%ED%Input(1), T%ED%p, T%ED%x(ThisState), T%ED%xd(ThisState), &
T%ED%z(ThisState), T%ED%OtherSt(ThisState), T%ED%y, T%ED%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdu=dYdu, dXdu=dXdu)
! case (Module_ExtPtfm)
case (Module_HD)
call HD_JacobianPInput(ThisTime, T%HD%Input(1), T%HD%p, T%HD%x(ThisState), T%HD%xd(ThisState), &
T%HD%z(ThisState), T%HD%OtherSt(ThisState), T%HD%y, T%HD%m, ErrStat2, ErrMsg2, &
dYdu=dYdu, dXdu=dXdu)
case (Module_IfW)
call InflowWind_JacobianPInput(ThisTime, T%IfW%Input(1), T%IfW%p, T%IfW%x(ThisState), T%IfW%xd(ThisState), &
T%IfW%z(ThisState), T%IfW%OtherSt(ThisState), T%IfW%y, T%IfW%m, ErrStat2, ErrMsg2, &
dYdu=dYdu, dXdu=dXdu)
case (Module_MAP)
call MAP_JacobianPInput(ThisTime, T%MAP%Input(1), T%MAP%p, T%MAP%x(ThisState), T%MAP%xd(ThisState), &
T%MAP%z(ThisState), T%MAP%OtherSt, T%MAP%y, T%MAP%m, ErrStat2, ErrMsg2, &
dYdu=dYdu, dXdu=dXdu)
case (Module_MD)
call MD_JacobianPInput(ThisTime, T%MD%Input(1), T%MD%p, T%MD%x(ThisState), T%MD%xd(ThisState), &
T%MD%z(ThisState), T%MD%OtherSt(ThisState), T%MD%y, T%MD%m, ErrStat2, ErrMsg2, &
dYdu=dYdu, dXdu=dXdu)
! case (Module_SD)
! call SD_JacobianPInput(ThisTime, T%SD%Input(1), T%SD%p, T%SD%x(ThisState), T%SD%xd(ThisState), &
! T%SD%z(ThisState), T%SD%OtherSt(ThisState), T%SD%y, T%SD%m, &
! ErrStat2, ErrMsg2, FlagFilter=FlagFilter, dYdu=dYdu, dXdu=dXdu)
case (Module_SrvD)
call SrvD_JacobianPInput(ThisTime, T%SrvD%Input(1), T%SrvD%p, T%SrvD%x(ThisState), T%SrvD%xd(ThisState), &
T%SrvD%z(ThisState), T%SrvD%OtherSt(ThisState), T%SrvD%y, T%SrvD%m, &
ErrStat2, ErrMsg2, dYdu=dYdu, dXdu=dXdu)
case default
ErrStat2 = ErrID_Fatal
ErrMsg2 = "Unsupported module: "//ModData%Abbr
end select
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
end subroutine
subroutine FAST_JacobianPContState(ModData, ThisTime, ThisState, T, ErrStat, ErrMsg, FlagFilter, dYdx, dXdx, StateRotation)
type(ModDataType), intent(in) :: ModData !< Module data
real(DbKi), intent(in) :: ThisTime !< Time
integer(IntKi), intent(in) :: ThisState !< State
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
integer(IntKi), optional :: FlagFilter
real(R8Ki), allocatable, optional, intent(inout) :: dYdx(:, :), dXdx(:, :)
real(R8Ki), allocatable, optional, intent(inout) :: StateRotation(:, :)
character(*), parameter :: RoutineName = 'FAST_JacobianPContState'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
ErrStat = ErrID_None
ErrMsg = ''
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
call AD_JacobianPContState(ThisTime, T%AD%Input(1), T%AD%p, &
T%AD%x(ThisState), T%AD%xd(ThisState), &
T%AD%z(ThisState), T%AD%OtherSt(ThisState), &
T%AD%y, T%AD%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdx=dYdx, dXdx=dXdx)
case (Module_BD)
call BD_JacobianPContState(ThisTime, T%BD%Input(1, ModData%Ins), T%BD%p(ModData%Ins), &
T%BD%x(ModData%Ins, ThisState), T%BD%xd(ModData%Ins, ThisState), &
T%BD%z(ModData%Ins, ThisState), T%BD%OtherSt(ModData%Ins, ThisState), &
T%BD%y(ModData%Ins), T%BD%m(ModData%Ins), ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdx=dYdx, dXdx=dXdx, StateRotation=StateRotation)
case (Module_ED)
call ED_JacobianPContState(ThisTime, T%ED%Input(1), T%ED%p, &
T%ED%x(ThisState), T%ED%xd(ThisState), &
T%ED%z(ThisState), T%ED%OtherSt(ThisState), &
T%ED%y, T%ED%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdx=dYdx, dXdx=dXdx)
! case (Module_ExtPtfm)
case (Module_HD)
call HD_JacobianPContState(ThisTime, T%HD%Input(1), T%HD%p, &
T%HD%x(ThisState), T%HD%xd(ThisState), &
T%HD%z(ThisState), T%HD%OtherSt(ThisState), &
T%HD%y, T%HD%m, ErrStat2, ErrMsg2, &
FlagFilter=FlagFilter, dYdx=dYdx, dXdx=dXdx)
case (Module_IfW)
call InflowWind_JacobianPContState(ThisTime, T%IfW%Input(1), T%IfW%p, &
T%IfW%x(ThisState), T%IfW%xd(ThisState), &
T%IfW%z(ThisState), T%IfW%OtherSt(ThisState), &
T%IfW%y, T%IfW%m, ErrStat2, ErrMsg2, &
dYdx=dYdx, dXdx=dXdx)
case (Module_MAP)
! MAP doesn't have a JacobianPContState subroutine
ErrStat2 = ErrID_None
ErrMsg2 = ''
case (Module_MD)
call MD_JacobianPContState(ThisTime, T%MD%Input(1), T%MD%p, &
T%MD%x(ThisState), T%MD%xd(ThisState), &
T%MD%z(ThisState), T%MD%OtherSt(ThisState), &
T%MD%y, T%MD%m, ErrStat2, ErrMsg2, &
dYdx=dYdx, dXdx=dXdx)
! case (Module_SD)
! call SD_JacobianPContState(ThisTime, T%SD%Input(1), T%SD%p, &
! T%SD%x(ThisState), T%SD%xd(ThisState), &
! T%SD%z(ThisState), T%SD%OtherSt(ThisState), &
! T%SD%y, T%SD%m, ErrStat2, ErrMsg2, &
! FlagFilter=FlagFilter, dYdx=dYdx, dXdx=dXdx)
case (Module_SrvD)
call SrvD_JacobianPContState(ThisTime, T%SrvD%Input(1), T%SrvD%p, &
T%SrvD%x(ThisState), T%SrvD%xd(ThisState), &
T%SrvD%z(ThisState), T%SrvD%OtherSt(ThisState), &
T%SrvD%y, T%SrvD%m, ErrStat2, ErrMsg2, &
dYdx=dYdx, dXdx=dXdx)
case default
ErrStat2 = ErrID_Fatal
ErrMsg2 = "Unsupported module: "//ModData%Abbr
end select
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
end subroutine
subroutine FAST_SaveStates(ModData, T, ErrStat, ErrMsg)
type(ModDataType), intent(in) :: ModData !< Module data
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
! Copy state from predicted to current with MESH_UPDATECOPY
call FAST_CopyStates(ModData, T, STATE_PRED, STATE_CURR, MESH_UPDATECOPY, ErrStat, ErrMsg)
end subroutine
subroutine FAST_CopyStates(ModData, T, Src, Dst, CtrlCode, ErrStat, ErrMsg)
type(ModDataType), intent(in) :: ModData !< Module data
type(FAST_TurbineType), intent(inout) :: T !< Turbine type
integer(IntKi), intent(in) :: Src, Dst !< State indices
integer(IntKi), intent(in) :: CtrlCode !< Mesh copy code
integer(IntKi), intent(out) :: ErrStat
character(*), intent(out) :: ErrMsg
character(*), parameter :: RoutineName = 'FAST_CopyStates'
integer(IntKi) :: ErrStat2
character(ErrMsgLen) :: ErrMsg2
integer(IntKi) :: i, j
integer(IntKi) :: j_ss ! substep loop counter
integer(IntKi) :: n_t_module ! simulation time step, loop counter for individual modules
real(DbKi) :: t_module ! Current simulation time for module
ErrStat = ErrID_None
ErrMsg = ''
! Select based on module ID
select case (ModData%ID)
case (Module_AD)
call AD_CopyContState(T%AD%x(Src), T%AD%x(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call AD_CopyDiscState(T%AD%xd(Src), T%AD%xd(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call AD_CopyConstrState(T%AD%z(Src), T%AD%z(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call AD_CopyOtherState(T%AD%OtherSt(Src), T%AD%OtherSt(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
case (Module_BD)
call BD_CopyContState(T%BD%x(ModData%Ins, Src), T%BD%x(ModData%Ins, Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call BD_CopyDiscState(T%BD%xd(ModData%Ins, Src), T%BD%xd(ModData%Ins, Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call BD_CopyConstrState(T%BD%z(ModData%Ins, Src), T%BD%z(ModData%Ins, Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call BD_CopyOtherState(T%BD%OtherSt(ModData%Ins, Src), T%BD%OtherSt(ModData%Ins, Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
case (Module_ED)
call ED_CopyContState(T%ED%x(Src), T%ED%x(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call ED_CopyDiscState(T%ED%xd(Src), T%ED%xd(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call ED_CopyConstrState(T%ED%z(Src), T%ED%z(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call ED_CopyOtherState(T%ED%OtherSt(Src), T%ED%OtherSt(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_ExtPtfm)
! case (Module_FEAM)
case (Module_HD)
! TODO: Fix inconsistent function name
call HydroDyn_CopyContState(T%HD%x(Src), T%HD%x(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! call HydroDyn_CopyDiscState(T%HD%xd(Src), T%HD%xd(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! call HydroDyn_CopyConstrState(T%HD%z(Src), T%HD%z(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! call HydroDyn_CopyOtherState(T%HD%OtherSt(Src), T%HD%OtherSt(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_IceD)
! case (Module_IceF)
case (Module_IfW)
! call IfW_CopyContState(T%IfW%x(Src), T%IfW%x(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! call IfW_CopyDiscState(T%IfW%xd(Src), T%IfW%xd(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! call IfW_CopyConstrState(T%IfW%z(Src), T%IfW%z(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! call IfW_CopyOtherState(T%IfW%OtherSt(Src), T%IfW%OtherSt(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_MAP)
! case (Module_MD)
! case (Module_OpFM)
! case (Module_Orca)
case (Module_SD)
call SD_CopyContState(T%SD%x(Src), T%SD%x(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call SD_CopyDiscState(T%SD%xd(Src), T%SD%xd(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call SD_CopyConstrState(T%SD%z(Src), T%SD%z(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call SD_CopyOtherState(T%SD%OtherSt(Src), T%SD%OtherSt(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
! case (Module_SeaSt)
case (Module_SrvD)
call SrvD_CopyContState(T%SrvD%x(Src), T%SrvD%x(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call SrvD_CopyDiscState(T%SrvD%xd(Src), T%SrvD%xd(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call SrvD_CopyConstrState(T%SrvD%z(Src), T%SrvD%z(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
call SrvD_CopyOtherState(T%SrvD%OtherSt(Src), T%SrvD%OtherSt(Dst), CtrlCode, Errstat2, ErrMsg2); if (Failed()) return
case default
call SetErrStat(ErrID_Fatal, "Unknown module ID "//trim(Num2LStr(ModData%ID)), ErrStat, ErrMsg, RoutineName)
return
end select
contains
logical function Failed()
call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName)
Failed = ErrStat >= AbortErrLev
end function
end subroutine
end module