-
Notifications
You must be signed in to change notification settings - Fork 0
/
A2_Control_mod.f90
1045 lines (1025 loc) · 39.2 KB
/
A2_Control_mod.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
! ----------------------------------------------------------------------
! Programmer(s): Yutong CHEN @XJTU, MER Dr. Konstantin MIKITYUK @PSI
! ----------------------------------------------------------------------
!
! A module for defining Control module
!
! ----------------------------------------------------------------------
module Control_mod
!======= Inclusions ===========
use Reactor_mod
use omp_lib
!======= Declarations =========
implicit none
!== SHARED variables ==
character(len=20) :: id, mat, cate, pid, sigid
character(len=20) :: mats(maxnlyr) = 'end'
real(c_double) :: ri, ro, tmp0, p0
real(c_double) :: ris(maxnlyr) = -1.d0
integer(c_int) :: nr, pnode, mltpl, nomp = 1, nlyr
integer(c_int) :: nrs(maxnlyr) = -1
!== UNIQUE variables ==
! XTIME variables-----------------------------------------------------
real(c_double) :: tstart= 0.0d0 , tend = 1.d+02, dtout = 1.d+01
real(c_double) :: dtini = 1.0d-08, dtmin = 1.d-08, dtmax = 1.d-1
! XSOLV variables-----------------------------------------------------
character(len=20) :: solver(nsolvr) = 'end'
real(c_double) :: rt = 1.0d-4
real(c_double) :: at(4) = 1.0d-6
integer(c_long):: mxsteps= 1000000
integer(c_int) :: maxnef = 7, maxcor = 3
! XPIPE variables-----------------------------------------------------
real(c_double) :: dhyd, len, dir, areaz, p2d, sb2st
integer(c_int) :: nz
! XJUNC variables-----------------------------------------------------
character(len=20) :: pid_f, pid_t
real(c_double) :: kfac = 0.d0
! XCORE variables-----------------------------------------------------
real(c_double) :: power0, lambda, beta, life
! XFUEL variables-----------------------------------------------------
logical :: isfu(maxnlyr) = .FALSE.
! XCLAD variables-----------------------------------------------------
! XFROD variables-----------------------------------------------------
character(len=20) :: fid, cid
real(c_double) :: hgap, kr, kz
! XTHBC variables-----------------------------------------------------
real(c_double) :: bcval(2)
! XHSTR variables-----------------------------------------------------
character(len=20) :: bcl, bcr
! XSGNL variables-----------------------------------------------------
real(c_double) :: sgnval = endval
real(c_double) :: sgntab(2, maxtab) = endval
! --------------------------------------------------------------------
!== NAMELIST declarations ==
! XTIME namelist 1.--------------------------------------------------
NAMELIST /XTIME/ tstart, tend , dtout , dtini , dtmin , dtmax
! XSOLV namelist 2.--------------------------------------------------
NAMELIST /XSOLV/ solver, nomp , rt , at , maxnef, maxcor, &
mxsteps, solopt
! XPIPE namelist 3.--------------------------------------------------
NAMELIST /XPIPE/ id , mat , cate , dhyd , len , dir , &
areaz , p2d , sb2st , nz , tmp0 , p0 , sigid
! XJUNC namelist 4.--------------------------------------------------
NAMELIST /XJUNC/ cate , pid_f , pid_t , sigid , kfac
! XCORE namelist 5.--------------------------------------------------
NAMELIST /XCORE/ power0, sigid , lambda, beta , life
! XFUEL namelist 6.--------------------------------------------------
NAMELIST /XFUEL/ id , mat , ri , ro , nr , tmp0 , &
mats , ris , nrs , nlyr , isfu
! XCLAD namelist 7.--------------------------------------------------
NAMELIST /XCLAD/ id , mat , ri , ro , nr , tmp0
! XFROD namelist 8.--------------------------------------------------
NAMELIST /XFROD/ id , fid , hgap , cid , pid , pnode , &
mltpl , kr , kz
! XTHBC namelist 9.--------------------------------------------------
NAMELIST /XTHBC/ id , cate , bcval , pid , pnode
! XHSTR namelist 10.--------------------------------------------------
NAMELIST /XHSTR/ id , mat , bcl , bcr , ri , ro , &
nr , tmp0 , mltpl , mats , ris , nrs , &
nlyr
! XSGNL namelist 11.--------------------------------------------------
NAMELIST /XSGNL/ id , cate , sgnval, sgntab
!== NAMELIST information ==
! namelist titles
character(len=6) :: nmlstr(nnmlst)
! array storing namelist counts
integer(c_int) :: nmlnum(nnmlst)
!== Fluid information ==
! array storing fluid show-up counts
integer(c_int) :: numfld(nfluids)
contains
! ----------------------------------------------------------------------
! construct_input: a subroutine that read the input file and store all
! input data into object type(Reactor) :: Reactor_obj
! ----------------------------------------------------------------------
subroutine construct_input()
!======= Declarations =========
implicit none
!== I/O variables ==
!== local variables ==
character(len=6) :: nml_str
real(c_double) :: dz
real(c_double),allocatable :: inp_pipe(:)
integer(c_int) :: i, j, thread_limit
! the objects
type(Pipe), allocatable :: Pipe_arr(:)
type(Junc), allocatable :: Junc_arr(:)
type(Fuel), allocatable :: Fuel_arr(:)
type(Clad), allocatable :: Clad_arr(:)
type(Fuelrod), allocatable :: Frod_arr(:)
type(Thermbc), allocatable :: Thermbc_arr(:)
type(Htstr), allocatable :: Htstr_arr(:)
type(Signal), allocatable :: Signal_arr(:)
type(Fuel) :: fuel_obj
type(Gasgap) :: ggap_obj
type(Clad) :: clad_obj
type(Thermbc) :: bcl_obj, bcr_obj
!======= Internals ============
! assign the namelist titles
nmlstr(idxtime)= '&XTIME'
nmlstr(idxsolv)= '&XSOLV'
nmlstr(idxpipe)= '&XPIPE'
nmlstr(idxjunc)= '&XJUNC'
nmlstr(idxcore)= '&XCORE'
nmlstr(idxfuel)= '&XFUEL'
nmlstr(idxclad)= '&XCLAD'
nmlstr(idxfrod)= '&XFROD'
nmlstr(idxthbc)= '&XTHBC'
nmlstr(idxhstr)= '&XHSTR'
nmlstr(idxsgnl)= '&XSGNL'
! open input file
open(unit=inpfu, status='old', file='input', form='formatted')
! initialize the counters
nmlnum = 0
numfld = 0
! cycle to count the namelists
do while (.TRUE.)
read(inpfu, '(1X,A6)', end=100) nml_str
do i = 1, nnmlst
if(nml_str == nmlstr(i)) then
nmlnum(i) = nmlnum(i) + 1
end if
end do
end do
100 continue
! /XTIME/-----------------------------------------------------------
if(nmlnum(idxtime)>=1) then
rewind(inpfu)
write(0,*) '===/XTIME/==='
! only read the first /XTIME/
read(inpfu, nml=XTIME)
else
print*, 'no namelist /XTIME/ detected'
stop 'program stop at Construct_input'
end if
! /XSOLV/-----------------------------------------------------------
if(nmlnum(idxsolv)>=1) then
rewind(inpfu)
write(0,*) '===/XSOLV/==='
! only read the first /XSOLV/
read(inpfu, nml=XSOLV)
! cycle the solver array
do i = 1, nsolvr
select case (solver(i))
case('htstr')
solve_htstr = .TRUE.
print*, 'solves htstr'
case('fuelrod')
solve_fuelrod= .TRUE.
print*, 'solves fuelrod'
case('fluid')
solve_fluid = .TRUE.
print*, 'solves fluid'
case('pointcore')
solve_pkcore = .TRUE.
print*, 'solves pointcore'
case default
if(solver(i)=='end') then
print*, 'all involved solvers are presented above...'
exit
else
print*, 'no match for solver = ', solver(i)
stop 'program stopped at Construct_input'
end if
end select
end do
! set omp parameters
thread_limit = omp_get_max_threads()
write(0,'(1X,A27,I3)') 'maximum available threads =', thread_limit
num_of_threads = min(max(nomp, 1), thread_limit)
! print SUNLinSol information
select case (solopt)
case(1)
print*, 'Dense direct linear solver (internal) selected'
case(2)
print*, 'PCG iterative solver selected'
case(3)
print*, 'SPBCGS solver selected'
case(4)
print*, 'SPFGMR solver selected'
case(5)
print*, 'SPGMR solver selected'
case(6)
print*, 'SPTFQMR solver selected'
case default
print*, 'no match for solopt = ', solopt
stop 'program stopped at Construct_input'
end select
else
print*, 'no namelist /XSOLV/ detected'
stop 'program stop at Construct_input'
end if
if(solve_fluid) then
! /XPIPE/-----------------------------------------------------------
if(nmlnum(idxpipe)>=1) then
allocate(Pipe_arr(nmlnum(idxpipe)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XPIPE/=== *', nmlnum(idxpipe)
do i = 1, nmlnum(idxpipe)
read(inpfu, nml=xpipe)
! read different categories of pipes seperately
select case (cate)
case('round')
allocate(inp_pipe(6))
inp_pipe(1) = dhyd
inp_pipe(2) = len
inp_pipe(3) = areaz
inp_pipe(4) = dir
inp_pipe(5) = tmp0
inp_pipe(6) = p0
case('brods')
allocate(inp_pipe(8))
inp_pipe(1) = dhyd
inp_pipe(2) = len
inp_pipe(3) = areaz
inp_pipe(4) = dir
inp_pipe(5) = p2d
inp_pipe(6) = sb2st
inp_pipe(7) = tmp0
inp_pipe(8) = p0
case('wrods')
allocate(inp_pipe(8))
inp_pipe(1) = dhyd
inp_pipe(2) = len
inp_pipe(3) = areaz
inp_pipe(4) = dir
inp_pipe(5) = p2d
inp_pipe(6) = sb2st
inp_pipe(7) = tmp0
inp_pipe(8) = p0
case('freelevel')
nz = 1
allocate(inp_pipe(5))
inp_pipe(1) = dhyd
inp_pipe(2) = len
inp_pipe(3) = areaz
inp_pipe(4) = tmp0
inp_pipe(5) = p0
case('fill')
nz = 1
allocate(inp_pipe(2))
inp_pipe(1) = tmp0
inp_pipe(2) = p0
Pipe_arr(i)%sigid = sigid
case('break')
nz = 1
allocate(inp_pipe(2))
inp_pipe(1) = tmp0
inp_pipe(2) = p0
case default
print*, 'no match for pipe category = ', cate
stop 'program stopped at Construct_inputs'
end select
call Pipe_arr(i)%init_pipe(id,mat,cate,nz,inp_pipe)
deallocate(inp_pipe)
! count the fluid show-ups
select case (mat)
case ('LBE')
numfld(idxlbe) = numfld(idxlbe)+ 1
case ('Na1')
numfld(idxna1) = numfld(idxna1)+ 1
case ('H2O')
numfld(idxh2o) = numfld(idxh2o)+ 1
case default
print*, 'no match for fluid = ', mat
stop 'program stopped at Construct_inputs'
end select
end do
! assign the Pipe_arr to Reactor_obj
call Reactor_glo%fluid%init_fld_p(Pipe_arr)
! get the fluid thermophysical data
if(numfld(idxlbe)>0) call get_lbe_dat()
if(numfld(idxna1)>0) call get_na1_dat()
if(numfld(idxh2o)>0) call get_h2o_dat()
else
print*, 'missing /XPIPE/ input for fluid solver'
stop 'program stopped at Construct_input'
end if
deallocate(Pipe_arr)
! /XJUNC/-----------------------------------------------------------
if(nmlnum(idxjunc)>=1) then
allocate(Junc_arr(nmlnum(idxjunc)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XJUNC/=== *', nmlnum(idxjunc)
do i = 1, nmlnum(idxjunc)
read(inpfu, nml=xjunc)
! read different categories of pipes seperately
select case(cate)
case('jun-norm')
! normal junction whose mdot is dependent variable
! mdot is dependent
call Junc_arr(i)%init_junc(cate, pid_f, pid_t)
case('jun-head')
! junciton with pump driving head
! mdot is independently solved by ode
! pump head controlled by signal sigid
call Junc_arr(i)%init_junc(cate, pid_f, pid_t, sigid)
case('jun-flow')
! junction with massflowrate signal
! mdot is independent, but controlled by signal sigid
call Junc_arr(i)%init_junc(cate, pid_f, pid_t, sigid)
case default
print*, 'no match for junction category = ', cate
stop 'program stopped at Construct_inputs'
end select
! local pressure loss coefficient
Junc_arr(i)%kfac = kfac
end do
! assign the Junc_arr to Reactor_obj
call Reactor_glo%fluid%init_fld_j(Junc_arr)
else
print*, 'missing /XJUNC/ input for fluid solver'
stop 'program stopped at Construct_input'
end if
! junction mdot solved by ode
neq_tot = neq_tot + neq_mdot
! freelevel length solved by ode
neq_tot = neq_tot + neq_flen
! fluid enthalpy solved by ode
neq_tot = neq_tot + neq_enth
!
call Reactor_glo%fluid%init_fluid()
end if
if(solve_fuelrod) then
if(.not.solve_fluid) then
print*, 'fuelrod simulation cannot proceed without fluid'
stop 'program stopped at Construct_input'
end if
! /XCORE/-----------------------------------------------------------
if(nmlnum(idxcore)>=1) then
rewind(inpfu)
write(0,*) '===/XCORE/==='
! only read the first /XCORE/
read(inpfu, nml=XCORE)
Reactor_glo%core%power0 = power0
if(solve_pkcore) then
call Reactor_glo%core%init_core_pkcore(lambda, beta, life)
end if
else
print*, 'missing /XCORE/ input for fuelrod solver'
stop 'program stopped at Construct_input'
end if
! /XFUEL/-----------------------------------------------------------
if(nmlnum(idxfuel)>=1) then
allocate(Fuel_arr(nmlnum(idxfuel)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XFUEL/=== *', nmlnum(idxfuel)
do i = 1, nmlnum(idxfuel)
! re-initialize arrays
mats = 'end'
ris = -1.d0
nrs = -1
isfu = .FALSE.
nlyr = 1
read(inpfu, nml=XFUEL)
if(nlyr==1) then
call Fuel_arr(i)%init_fp1(id, mat, ri, ro, nr, isfu(1), tmp0)
else
call Fuel_arr(i)%init_fp2(id, mats(1:nlyr), ris(1:nlyr+1), nrs(1:nlyr), isfu(1:nlyr), nlyr, tmp0)
end if
end do
else
print*, 'missing /XFUEL/ input for fuelrod solver'
stop 'program stopped at Construct_input'
end if
! /XCLAD/-----------------------------------------------------------
if(nmlnum(idxclad)>=1) then
allocate(Clad_arr(nmlnum(idxclad)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XCLAD/=== *', nmlnum(idxclad)
do i = 1, nmlnum(idxclad)
read(inpfu, nml=XCLAD)
call Clad_arr(i)%init_cd(id, mat, ri, ro, nr, tmp0)
end do
else
print*, 'missing /XCLAD/ input for fuelrod solver'
stop 'program stopped at Construct_input'
end if
! /XFROD/-----------------------------------------------------------
if(nmlnum(idxfrod)>=1) then
allocate(Frod_arr(nmlnum(idxfrod)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XFROD/=== *', nmlnum(idxfrod)
do i = 1, nmlnum(idxfrod)
read(inpfu, nml=XFROD)
! loop for the matching fuel pellet object
do j = 1, nmlnum(idxfuel)
if(fid==Fuel_arr(j)%idstr) then
fuel_obj = Fuel_arr(j)
exit
end if
end do
if(j>nmlnum(idxfuel)) then
print*, 'no match for fuel = ', fid
stop 'program stopped at Construct_input'
end if
! initialize gasgap object
call ggap_obj%init_gg(hgap)
! loop for the matching cladding object
do j = 1, nmlnum(idxclad)
if(cid==Clad_arr(j)%idstr) then
clad_obj = Clad_arr(j)
exit
end if
end do
if(j>nmlnum(idxclad)) then
print*, 'no match for clad = ', cid
stop 'program stopped at Construct_input'
end if
! loop for the matching pipe object
do j = 1, nmlnum(idxpipe)
if(pid==Reactor_glo%fluid%pipes(j)%idstr) then
dz = Reactor_glo%fluid%pipes(j)%dz
exit
end if
end do
if(j>nmlnum(idxpipe)) then
print*, 'no match for pipeid = ', pid
stop 'program stopped at Construct_input'
end if
call Frod_arr(i)%init_frd(id, fuel_obj, ggap_obj, clad_obj, &
kr, kz, pid, pnode, mltpl, dz)
end do
else
print*, 'missing /XFROD/ input for fuelrod solver'
stop 'program stopped at Construct_input'
end if
! assign the Frod_arr to Reactor_obj (shallow copy)
call Reactor_glo%Solid%init_sld_f(Frod_arr)
neq_tot = neq_tot + neq_frod
! free the dynamic memory
deallocate(Fuel_arr)
deallocate(Clad_arr)
deallocate(Frod_arr)
end if
if(solve_htstr) then
! /XTHBC/-----------------------------------------------------------
if(nmlnum(idxthbc)>=1) then
allocate(Thermbc_arr(nmlnum(idxthbc)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XTHBC/=== *', nmlnum(idxthbc)
do i = 1, nmlnum(idxthbc)
read(inpfu, nml=XTHBC)
if(cate=='coupling') then
! here the bcval does not have practical meaning
bcval = 0.d0
call Thermbc_arr(i)%init_bc(id, cate, bcval, pid, pnode)
else
call Thermbc_arr(i)%init_bc(id, cate, bcval)
end if
end do
else
print*, 'missing /XTHBC/ input for htstr solver'
stop 'program stopped at Construct_inputs'
end if
! /XHSTR/-----------------------------------------------------------
if(nmlnum(idxhstr)>=1) then
allocate(Htstr_arr(nmlnum(idxhstr)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XHSTR/=== *', nmlnum(idxhstr)
do i = 1, nmlnum(idxhstr)
nlyr = 1 ! re-initialize needed
read(inpfu, nml=XHSTR)
! search for the left thermbc object
do j = 1, nmlnum(idxthbc)
if(Thermbc_arr(j)%bcname==bcl) then
bcl_obj = Thermbc_arr(j)
exit
end if
end do
if(j>nmlnum(idxthbc)) then
print*, 'no match for left thermbc name = ', bcl
stop 'program stopped at Construct_inputs'
end if
! search for the right thermbc object
do j = 1, nmlnum(idxthbc)
if(Thermbc_arr(j)%bcname==bcr) then
bcr_obj = Thermbc_arr(j)
exit
end if
end do
if(j>nmlnum(idxthbc)) then
print*, 'no match for right thermbc name = ', bcr
stop 'program stopped at Construct_inputs'
end if
! initialize the heat structure objects
if(nlyr==1) then
! single-layer htstr model
call Htstr_arr(i)%init_hs1(id, mat, ri, ro, nr, tmp0, bcl_obj, bcr_obj, mltpl)
else
! multi-layer htstr model
! check the inputs
do j = 1, nlyr+1
if(j<nlyr+1) then
if(mats(j)=='end') stop 'check mats input for htstr multi-layer model'
if(nrs(j)==-1) stop 'check nrs input for htstr multi-layer model'
end if
if(ris(j)==-1.d0) stop 'check ris input for htstr multi-layer model'
end do
call Htstr_arr(i)%init_hs2(id,mats(1:nlyr),ris(1:nlyr+1),nrs(1:nlyr),nlyr,tmp0,bcl_obj,bcr_obj,mltpl)
end if
end do
! assign the Htstr_arr to Reactor_obj (shallow copy)
call Reactor_glo%Solid%init_sld_h(Htstr_arr)
! accumulate the htstr node number
neq_tot = neq_tot + neq_hstr
! free the dynamic memory
deallocate(Htstr_arr)
deallocate(Thermbc_arr)
else
print*, 'missing /XHSTR/ input for htstr solver'
stop 'program stopped at Construct_inputs'
end if
end if
! /XSGNL/-----------------------------------------------------------
if(nmlnum(idxsgnl)>=1) then
allocate(Signal_arr(nmlnum(idxsgnl)))
allocate(Reactor_glo%signals(nmlnum(idxsgnl)))
! global arrarys storing signal data
allocate(sgnids_arr(nmlnum(idxsgnl)))
allocate(sgnval_arr(nmlnum(idxsgnl)))
rewind(inpfu)
write(0,'(1X,A15,I3)') '===/XSGNL/=== *', nmlnum(idxsgnl)
do i = 1, nmlnum(idxsgnl)
sgntab = endval
read(inpfu, nml=XSGNL)
sgnids_arr(i) = id
! echo the signals with fixed name and purpose
select case (id)
case('dtprint')
print*, '*** system signal dtprint specified'
set_dtprint = .TRUE.
case('corepow')
print*, '*** system signal corepow specified'
set_corepow = .TRUE.
case default
print*, ADJUSTL(TRIM(id)), ' signal specified'
end select
!
select case (cate)
case('constant')
call Signal_arr(i)%init_sgnl(id, cate)
sgnval_arr(i) = sgnval
case('lookup')
! overwrite the sgnval with the first column value
sgnval = sgntab(2,1)
! j is the counter of actual input number of sgntab
j = 1
do while (.TRUE.)
if(sgntab(1,j)/=endval .and. sgntab(2,j)/=endval) then
j = j+1
else
if(sgntab(1,j)/=endval .or. sgntab(2,j)/=endval) then
print*, 'Warning in signal id = ', id, ', lookup table'
print*, 'the x-array and y-array sizes do not match'
end if
exit
end if
end do
! check the lookup table input
if(j<3) then
print*, 'lookup table needs at leat 2 columns for signal = ', id
stop 'program stopped at Construct_inputs'
else
call Signal_arr(i)%init_sgnl(id, cate, sgntab(1:2,1:j-1))
end if
case default
print*, 'no match for signal category = ', cate
stop 'program stopped at Construct_inputs'
end select
end do
Reactor_glo%signals = Signal_arr
Reactor_glo%nsgnl = size(Signal_arr)
deallocate(Signal_arr)
end if
! check input
if((solve_fuelrod).and.(.not.solve_pkcore).and.(.not.set_corepow)) then
print*, 'need pkcore solver or corepow signal for core calculation'
stop 'program stopped at Construct_inputs'
end if
! close input file
close(inpfu)
end subroutine construct_input
! ----------------------------------------------------------------------
! evaluate_signals: a subroutine that evaluate the siganls, update the
! signal values during transient calculations
! ----------------------------------------------------------------------
subroutine evaluate_signals(time)
!======= Declarations =========
implicit none
!== I/O variables ==
real(c_double) :: time
!== local variables ==
integer(c_int) :: i, j
real(c_double) :: t_arr(1), y_arr(1)
! pointer for sliced array
!======= Internals ============
do i = 1, Reactor_glo%nsgnl
! update signal values array
select case (Reactor_glo%signals(i)%cate)
case ('constant')
! do not need further action
continue
case ('lookup')
t_arr(1) = time
call interp1d(Reactor_glo%signals(i)%sgntab(1,:), &
Reactor_glo%signals(i)%sgntab(2,:),t_arr,y_arr)
sgnval_arr(i) = y_arr(1)
case default
print*, 'no match for signal type = ', Reactor_glo%signals(i)%cate
stop 'program stopped at evaluate_signals'
end select
end do
! assign the signal values relative to fluid
if(solve_fluid) then
do i = 1, Reactor_glo%fluid%npipe
! update fill pipe temperature
if(Reactor_glo%fluid%pipes(i)%cate=='fill') then
do j = 1, Reactor_glo%nsgnl
if(Reactor_glo%fluid%pipes(i)%sigid==sgnids_arr(j)) then
select case (Reactor_glo%fluid%pipes(i)%matid)
case('LBE')
call ht_lbe(sgnval_arr(j:j), Reactor_glo%fluid%pipes(i)%enth)
case('Na1')
call ht_na1(sgnval_arr(j:j), Reactor_glo%fluid%pipes(i)%enth)
case('H2O')
call hpt_h2o(Reactor_glo%fluid%pipes(i)%pval,sgnval_arr(j:j), &
Reactor_glo%fluid%pipes(i)%enth)
case default
print*, 'no match for fluid material name = ', Reactor_glo%fluid%pipes(i)%matid
stop 'program stopped at Fluid%init_fluid'
end select
end if
end do
end if
if(Reactor_glo%fluid%pipes(i)%cate=='break') then
! update break pipe pressure
do j = 1, Reactor_glo%nsgnl
if(Reactor_glo%fluid%pipes(i)%sigid==sgnids_arr(j)) then
Reactor_glo%fluid%pipes(i)%pval = sgnval_arr(j)
end if
end do
end if
end do
! update the mdot of jun-flow junctions
do i = 1, Reactor_glo%fluid%njunc
if(Reactor_glo%fluid%juncs(i)%cate=='jun-flow') then
do j = 1, Reactor_glo%nsgnl
if(Reactor_glo%fluid%juncs(i)%sigid==sgnids_arr(j)) then
Reactor_glo%fluid%mdots(i) = sgnval_arr(j)
exit
end if
end do
end if
end do
! update the phead of jun-head junctions
do i = 1, Reactor_glo%fluid%njunc
if(Reactor_glo%fluid%juncs(i)%cate=='jun-head') then
do j = 1, Reactor_glo%nsgnl
if(Reactor_glo%fluid%juncs(i)%sigid==sgnids_arr(j)) then
Reactor_glo%fluid%juncs(i)%phead = sgnval_arr(j)
exit
end if
end do
end if
end do
end if
! assign the signal values relative to fuelrods
if(solve_fuelrod.and.set_corepow) then
do i = 1, Reactor_glo%nsgnl
if(Reactor_glo%signals(i)%id=='corepow') then
Reactor_glo%core%power = sgnval_arr(i)*Reactor_glo%core%power0
end if
end do
end if
end subroutine evaluate_signals
! ----------------------------------------------------------------------
! open_output_files: a subroutine that open the output files, assigning
! the file units and name strings
! ----------------------------------------------------------------------
subroutine open_output_files()
!======= Declarations =========
implicit none
!== I/O variables ==
!== local variables ==
! output directory name
character(len=20) :: rsltdir
! path for results
character(len=50) :: path4results
! file id string
character(len=250):: fileid
! column id string
character(len=18) :: colid
! system command string
character(len=100):: command
! loop counters
integer(c_int) :: i, j, k
! status variable
integer(c_int) :: status
! integers recording system time
integer(c_int) :: time_arr(8)
integer(c_int) :: year, month, day, hour, minute, second
!======= Internals ============
! the primary output dir
command = 'mkdir -p '//'output'
call SYSTEM(command, status)
! the path for results
call DATE_AND_TIME(VALUES = time_arr)
year = time_arr(1) ! 4
month = time_arr(2) ! 2
day = time_arr(3) ! 2
hour = time_arr(5) ! 2
minute= time_arr(6) ! 2
second= time_arr(7) ! 2
write(rsltdir, 100) year,'-',month,'-',day,'-',hour,'-',minute,'-',second
path4results = 'output'//'/'//ADJUSTL(TRIM(rsltdir))
command = 'mkdir '//path4results
call SYSTEM(command, status)
k = 1 ! k serves as the pointer for output file unit
! open fluid output files
if(solve_fluid) then
command = 'mkdir '//ADJUSTL(TRIM(path4results))//'/'//'fluid'
call SYSTEM(command, status)
if(status /= 0) then
print*, 'Failed to creat output directory for fluid, check your permession.'
else
print*, 'Directory created successfully for fluid.'
end if
! open output .dat files relative to fluid
do i = 1, Reactor_glo%fluid%npipe
! fluid temperature
write(fileid,110) 'pipe-temp-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'temp-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
! fluid pressure
write(fileid,110) 'pipe-p-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'p-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
! fluid re
write(fileid,110) 'pipe-re-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'re-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
! fluid pr
write(fileid,110) 'pipe-pr-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'pr-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
! fluid pe
write(fileid,110) 'pipe-pe-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'pe-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
! fluid xe
write(fileid,110) 'pipe-xe-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'xe-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
! fluid htcmod
write(fileid,110) 'pipe-hmod-',ADJUSTL(TRIM(Reactor_glo%fluid%pipes(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colid,120)'hmod-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
end do
! fluid mdots
write(fileid,110) 'mdots-','juncs','.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fluid'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do i = 1, Reactor_glo%fluid%njunc
write(colid,120)'mdot-',i
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
end if
! open htstr output files
if(solve_htstr) then
command = 'mkdir '//ADJUSTL(TRIM(path4results))//'/'//'htstr'
call SYSTEM(command, status)
if(status /= 0) then
print*, 'Failed to creat output directory for htstr, check your permession.'
else
print*, 'Directory created successfully for htstr.'
end if
! open output .dat files relative to htstrs
do i = 1, Reactor_glo%solid%nhtstr
write(fileid,110) 'htstr-temp-',ADJUSTL(TRIM(Reactor_glo%solid%htstrs(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'htstr'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%solid%htstrs(i)%nr
write(colid,120)'temp-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
end do
end if
! open fuelrod output files
if(solve_fuelrod) then
command = 'mkdir '//ADJUSTL(TRIM(path4results))//'/'//'fuelrod'
call SYSTEM(command, status)
if(status /= 0) then
print*, 'Failed to creat output directory for fuelrod, check your permession.'
else
print*, 'Directory created successfully for fuelrod.'
end if
! open output .dat files relative to fuelrods
do i = 1, Reactor_glo%solid%nfrod
write(fileid,110) 'frod-temp-',ADJUSTL(TRIM(Reactor_glo%solid%frods(i)%idstr)),'.dat'
open(unit=otpfu+k, file=ADJUSTL(TRIM(path4results))//'/'//'fuelrod'//'/'//ADJUSTL(TRIM(fileid)), &
status='new', form='formatted')
colid = 'time'
write(otpfu+k,'(A18)',advance='no')colid
do j = 1, Reactor_glo%solid%frods(i)%nf
write(colid,120)'fuel-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
do j = 1, Reactor_glo%solid%frods(i)%nc
write(colid,120)'clad-',j
write(otpfu+k,'(A18)',advance='no')colid
end do
write(otpfu+k,*)''
k = k + 1
end do
end if
100 format(I4.4, A1, I2.2, A1, I2.2, A1, I2.2, A1, I2.2, A1, I2.2)
110 format(A, A, A)
120 format(A, I2.2)
end subroutine open_output_files
subroutine print_output_files(time)
!======= Declarations =========
implicit none
!== I/O variables ==
real(c_double) :: time
!== local variables ==
character(len=18) :: colstr
integer(c_int) :: i, j, k
!======= Internals ============
k = 1 ! k serves as the pointer for output file unit
! fluid outputs
if(solve_fluid) then
! write to output .dat files relative to fluid
do i = 1, Reactor_glo%fluid%npipe
! fluid temperature
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(ES18.8e2)')Reactor_glo%fluid%pipes(i)%temp(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
! fluid pressure
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(ES18.8e2)')Reactor_glo%fluid%pipes(i)%pval(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
! fluid re
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(ES18.8e2)')Reactor_glo%fluid%pipes(i)%re(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
! fluid pr
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(ES18.8e2)')Reactor_glo%fluid%pipes(i)%pr(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
! fluid pe
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(ES18.8e2)')Reactor_glo%fluid%pipes(i)%pe(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
! fluid xe
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(ES18.8e2)')Reactor_glo%fluid%pipes(i)%xe(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
! fluid htcmod
write(colstr,'(ES18.8e2)')time
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
do j = 1, Reactor_glo%fluid%pipes(i)%nz
write(colstr,'(I18)')Reactor_glo%fluid%pipes(i)%htcmod(j)
write(otpfu+k,'(A18)',advance='no') ADJUSTL(colstr)
end do
write(otpfu+k,*)''
k = k + 1
end do