-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR3Main03.pas
2837 lines (2600 loc) · 82.6 KB
/
R3Main03.pas
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
unit R3Main03;
(* Programid : RnMod3d *)
(* Versionid : Version 0.8 (Sep. 15, 1997 - July 18, 2000) *)
(* Description : Radon transport model - 3D time-dependent - finite volume *)
(* Programmer1 : Claus E. Andersen, Risoe National Laboratory *)
(* Programmer2 : DK-4000 Roskilde, Denmark. [email protected] *)
(* Copyright : Risoe National Laboratory, Denmark *)
(* Documentation : User's Guide to RnMod3d, Risoe-R-1201(EN) *)
(* Files : R3Defi03.pas = Global definitions *)
(* R3Main03.pas = Main program *)
(* R3Delp03.pas = Special Delphi 3.0 / Borland Pascal 7.0 code *)
(* R3Dirs03.pas = Compiler directives *)
(* R3Writ03.pas = Mainly procedures for writing text *)
{$I R3dirs03}
interface
{$IFDEF Delphi}
uses sysutils,R3Delp03,R3Writ03,R3Defi03; (* Delphi *)
{$ELSE}
uses dos,R3Writ03,R3Defi03; (* Borland Pascal *)
{$ENDIF}
procedure change_con(i:itype;j:jtype;k:ktype;
dir:dirtype;var conOld:nodecontype; conNew:nodecontype);
procedure change_node(i:itype;j:jtype;k:ktype;
nodetypNew:nodetyptype;
wconNew,econNew,
sconNew,nconNew,
bconNew,tconNew:nodecontype);
procedure set_node(i:itype;j:jtype;k:ktype;nodetypNew:nodetyptype);
procedure error_node(idst:string;i:itype;j:jtype;k:ktype;message:string);
procedure update_flxval(flx:flxtype;dir:dirtype;i:itype;j:jtype;k:ktype;sign:signtype);
procedure initialize_vars;
procedure create_GP(var GP:gridtype);
procedure dispose_GP(var GP:gridtype);
procedure initialize_GP(var GP:gridtype);
procedure copy_GP(var GP1,GP2:gridtype);
procedure swap_GP(var GP1,GP2:gridtype);
procedure dispose_Fieldbuffer(cBUFname:use_fieldbuffer_type);
procedure create_Fieldbuffer(var cBUF:fieldtype);
procedure save_Field_in_buffer(var cBUF:fieldtype);
procedure restore_Field_from_buffer(var cBUF:fieldtype);
procedure dispose_qBUF(var qBUF:flowfieldtype);
procedure create_qBUF(var qBUF:flowfieldtype);
procedure save_FlowField_in_qBUF(var qBUF:flowfieldtype);
procedure restore_FlowField_from_qBUF(var qBUF:flowfieldtype);
procedure initialize_nodes_and_connectors;
procedure convert_deadnodes_to_NOPs;
procedure check_node_connections;
procedure set_materials;
procedure set_coefficients;
procedure check_coefficients;
function mat_string(m:mattype):string;
procedure wr_count_nodes(var OM:text);
procedure find_field;
procedure find_better_field_Gauss_Seidel;
procedure find_better_field_Thomas;
procedure reset_fluxes;
procedure wr_residuals(var OM:text);
procedure wr_fluxes(var OM:text);
procedure wr_obses(var OM:text);
procedure wr_all_nodedata(var OM:text);
procedure wr_all_coefficients(var OM:text);
procedure export_field_proc(filename:string);
procedure run_model;
procedure close_model;
procedure update_plotfile(plt:pltfiletype;wdir:dirtype);
procedure solve_iline(j0:jtype;k0:ktype);
procedure solve_jline(i0:itype;k0:ktype);
procedure solve_kline(i0:itype;j0:jtype);
procedure set_cvsize(i:itype;j:jtype;k:ktype;
var ArW,ArE,ArS,ArN,ArB,ArT,dV:datatype);
function FixId(dir:dirtype;h:htype;var wFixfound:FixType):boolean;
function nodetyp_string(x:nodetyptype):string;
function nodecon_string(x:nodecontype):string;
procedure find_residuals;
procedure calc_fluxes(iter_period:longint);
procedure calc_obses(iter_period:longint);
function war_string(w:warningtype):string;
procedure extract_time_and_daystrings(t:timetype; var tst,dayst,dnost:string);
procedure get_t(var t:timetype);
function time_difference(t1,t2:timetype):datatype;
procedure wr_t(var OM:text; t:timetype);
function node_flux(dir:dirtype;i:itype;j:jtype;k:ktype):datatype;
implementation
function converged:boolean; forward;
procedure set_boundary_conditions(bc_proc:aijkproctype); forward;
procedure boundary_conditions_2D(i:itype;j:jtype;k:ktype); forward;
procedure extract_time_and_daystrings(t:timetype; var tst,dayst,dnost:string);
begin
{$IFDEF Delphi}
tst:=TimeToStr(t);
dayst:=FormatDateTime('dd/mm/yyyy',t);
dnost:='';
{$ELSE}
tst:=' ';
dayst:=' ';
dnost:=' ';
{$ENDIF}
end;
{$IFDEF Delphi}
procedure get_t(var t:timetype);
begin
t:=now;
end;
{$ELSE}
procedure get_t(var t:timetype);
begin
t:=0;
end;
{$ENDIF}
function dt(t1,t2:timetype):datatype;
const ID = 'dt';
begin
dt:=(t2-t1)*24*3600; (* seconds *)
end;
function time_difference(t1,t2:timetype):datatype;
(* Time is a renamed version of dt for external use *)
(* dt is too common a name for the purpose *)
(* June 19, 2000 *)
begin
time_difference:=dt(t1,t2);
end;
{$IFDEF Delphi}
procedure wr_t(var OM:text; t:timetype);
var tst,dst,dnost:string;
begin
extract_time_and_daystrings(t,tst,dst,dnost);
writeln(OM,'* Time = ',dnost,' ',dst,' ',tst);
end;
{$ELSE}
function LeadingZero(w :Word): String;
var s:String;
begin
Str(w:0,s);
if Length(s) = 1 then s := '0' + s;
LeadingZero := s;
end;
function get_datetimestring:string;
var Hour, Minute, Second, Sec100: Word;
Year, Month, Day, DayOfWeek: Word;
tst,yearst,monthst,dayst:string;
begin
GetTime(Hour, Minute, Second, Sec100);
GetDate(Year, Month, Day, DayOfWeek);
tst:=LeadingZero(hour)+':'+LeadingZero(minute)+':'+LeadingZero(second);
str(year,yearst);
str(month,monthst);
str(day,dayst);
get_datetimestring:=dayst+'-'+monthst+'-'+yearst+' '+tst;
end;
procedure wr_t(var OM:text; t:timetype);
var tst,dst,dnost:string;
begin
dst:='there';
dnost:='';
writeln(OM,'* Time = ',get_datetimestring);
end;
{$ENDIF}
function nodecon_string(x:nodecontype):string;
var st:string;
begin
case x of
nill: st:='nill ';
std: st:='std ';
noflow: st:='noflow ';
ConX: st:='unchanged ';
else
st:='Unknown !!';
end; (* case *)
nodecon_string:=st;
end;
function nodetyp_string(x:nodetyptype):string;
var st:string;
begin
case x of
NOP: st:='NOP ';
free: st:='free ';
fixed1: st:='fixed1 ';
fixed2: st:='fixed2 ';
fixed3: st:='fixed3 ';
fixed4: st:='fixed4 ';
fixed5: st:='fixed5 ';
NodX: st:='unchanged ';
else
st:='Unknown !!';
end; (* case *)
nodetyp_string:=st;
end;
function mat_string(m:mattype):string;
var st:string;
begin
case m of
mat_undefined : st:='mat? ';
mat1 : st:='mat1 ';
mat2 : st:='mat2 ';
mat3 : st:='mat3 ';
mat4 : st:='mat4 ';
mat5 : st:='mat5 ';
mat6 : st:='mat6 ';
mat7 : st:='mat7 ';
mat8 : st:='mat8 ';
mat9 : st:='mat9 ';
mat10: st:='mat10';
mat11: st:='mat11';
mat12: st:='mat12';
mat13: st:='mat13';
mat14: st:='mat14';
mat15: st:='mat15';
else
st:='Unknown !!';
end; (* case *)
mat_string:=st;
end;
function geometry_string(g:geometrytype):string;
var st:string;
begin
case g of
cartesian3D : st:='cartesian3D ';
cartesian2D : st:='cartesian2D ';
cylindrical2D : st:='cylindrical2D ';
else
st:='Unknown !!';
end; (* case *)
geometry_string:=st;
end;
function war_string(w:warningtype):string;
var st:string;
begin
case w of
war_none: st:='war_none';
war_first: st:='war_first';
war_interpolation: st:='war_interpolation';
war_other: st:='war_other';
war_fileimport: st:='war_fileimport';
war_convergence: st:='war_convergence';
war_residual: st:='war_residual';
else
st:='war_Unknown !!';
end; (* case *)
war_string:=st;
end;
procedure change_con(i:itype;j:jtype;k:ktype;
dir:dirtype;var conOld:nodecontype; conNew:nodecontype);
const ID='change_con';
var err:integer;
conResult:nodecontype;
begin
err:=0;
conresult:=nill; (* Arbitary initialization just to make compiler happy *)
case conOld of
Nill:
begin
case conNew of
Nill: err:=err+10000;
NoFlow,ConX: conResult:=conOld; (* Do nothing *)
Std: err:=err+1;
else
err:=err+10;
end; (* case *)
end; (* nill *)
NoFlow:
begin (* noFlow *)
case conNew of
Nill: err:=err+10000;
NoFlow,ConX: conResult:=conOld; (* Do nothing *)
Std: begin (* reestablish connection to/from the other node *)
conResult:=conNew;
case dir of
west: GP[i-1]^[j]^[k].econ:=std;
east: GP[i+1]^[j]^[k].wcon:=std;
south: GP[i]^[j-1]^[k].ncon:=std;
north: GP[i]^[j+1]^[k].scon:=std;
bottom: GP[i]^[j]^[k-1].tcon:=std;
top: GP[i]^[j]^[k+1].bcon:=std;
else
err:=err+100;
end; (* dir case *)
end; (* std *)
else
err:=err+10;
end; (* case conNew *)
end; (* noflow *)
Std:
begin (* std *)
case conNew of
nill: err:=err+10000;
Std,ConX: conResult:=conOld; (* Do nothing *)
noFlow: begin (* break connection to/from the other node *)
conResult:=conNew;
case dir of
west: GP[i-1]^[j]^[k].econ:=noflow;
east: GP[i+1]^[j]^[k].wcon:=noflow;
south: GP[i]^[j-1]^[k].ncon:=noflow;
north: GP[i]^[j+1]^[k].scon:=noflow;
bottom: GP[i]^[j]^[k-1].tcon:=noflow;
top: GP[i]^[j]^[k+1].bcon:=noflow;
else
err:=err+100;
end; (* dir case *)
end; (* std *)
else
err:=err+1;
end; (* case conNew *)
end; (* std *)
else (* incl. ConX *)
err:=5000;
end; (* main case *)
if err<>0 then
begin
writeln('* Old connection : ',nodecon_string(conOld));
writeln('* Wanted connection : ',nodecon_string(conNew));
writeln('* Direction : ',dirname(dir));
writeln('* Error code : ',err:10);
writeln('* 1 = Cannot change Nill');
writeln('* 10 = Unknown New connection');
writeln('* 100 = Illegal direction (use west, east, south, north, top, bottom)');
writeln('* 1000 = Cannot change Std to Nill');
writeln('* 5000 = Illegal old connection');
writeln('* 10000 = Nill is an Illegal new connection');
error_node(ID,i,j,k,'Some problem--see above.');
end
else
conOld:=conResult;
end;
procedure change_node(i:itype;j:jtype;k:ktype;
nodetypNew:nodetyptype;
wconNew,econNew,
sconNew,nconNew,
bconNew,tconNew:nodecontype);
const ID='change_node';
begin
with(GP[i]^[j]^[k]) do
begin
if (nodetypNew<>NodX) then nodetyp:=nodetypNew;
if (nodetyp=NOP) then GP[i]^[j]^[k].valid_fieldvalue:=false
else GP[i]^[j]^[k].valid_fieldvalue:=true;
if (nodetypNew=NOP) and
( (wconNew<>noFlow) or (econNew<>noFlow) or
(sconNew<>noFlow) or (nconNew<>noFlow) or
(bconNew<>noFlow) or (tconNew<>noFlow) ) then
begin
writeln('* w-con : ',nodecon_string(wconNew));
writeln('* e-con : ',nodecon_string(econNew));
writeln('* s-con : ',nodecon_string(sconNew));
writeln('* n-con : ',nodecon_string(nconNew));
writeln('* b-con : ',nodecon_string(bconNew));
writeln('* t-con : ',nodecon_string(tconNew));
error_node(ID,i,j,k,'When you try to set nodetyp=NOP,'+
' all connections should be set to noFlow');
end;
change_con(i,j,k,west, wcon,wconNew);
change_con(i,j,k,east, econ,econNew);
change_con(i,j,k,south, scon,sconNew);
change_con(i,j,k,north, ncon,nconNew);
change_con(i,j,k,bottom,bcon,bconNew);
change_con(i,j,k,top, tcon,tconNew);
end;
end; (* change_node *)
procedure set_node(i:itype;j:jtype;k:ktype;nodetypNew:nodetyptype);
begin
if (nodetypNew=NOP) then
change_node(i,j,k,NOP,noFlow,noFlow,noFlow,noFlow,noFlow,noFlow)
else
change_node(i,j,k,nodetypNew,ConX,ConX,ConX,ConX,ConX,ConX);
end;
procedure set_nodes_region_ijk(iA,iB:itype;ireg:regsettype;
jA,jB:jtype;jreg:regsettype;
kA,kB:ktype;kreg:regsettype;
nodetyp0:nodetyptype;
wcon0,econ0,
scon0,ncon0,
bcon0,tcon0:nodecontype);
const ID='set_nodes_region_ijk';
var i:itype;
j:jtype;
k:ktype;
begin
if not (iA<=iB) then error_std(ID,'iA>iB');
if not (jA<=jB) then error_std(ID,'jA>jB');
if not (kA<=kB) then error_std(ID,'kA>kB');
for i:=1 to imax do
for j:=1 to jmax do
for k:=1 to kmax do
if in_region_ijk(i,iA,iB,ireg,j,jA,jB,jreg,k,kA,kB,kreg) then
change_node(i,j,k,nodetyp0,wcon0,econ0,scon0,ncon0,bcon0,tcon0);
end; (* set_nodes_region_ijk *)
procedure set_nodes_region(xFixA,xFixB:Fixtype;xreg:regsettype;
yFixA,yFixB:Fixtype;yreg:regsettype;
zFixA,zFixB:Fixtype;zreg:regsettype;
nodetyp0:nodetyptype;
wcon0,econ0,
scon0,ncon0,
bcon0,tcon0:nodecontype);
const ID='set_nodes_region';
var iA,iB:itype;
jA,jB:jtype;
kA,kB:ktype;
begin
check_fix_region_param(ID,xFixA,xFixB,yFixA,yFixB,zFixA,zFixB);
iA:=wFixVal[xFixA].h; iB:=wFixVal[xFixB].h;
jA:=wFixVal[yFixA].h; jB:=wFixVal[yFixB].h;
kA:=wFixVal[zFixA].h; kB:=wFixVal[zFixB].h; (* ERROR: kB was missing april 7, 1998 *)
set_nodes_region_ijk(iA,iB,xreg,jA,jB,yreg,kA,kB,zreg,
nodetyp0,
wcon0,econ0,scon0,ncon0,bcon0,tcon0);
end; (* set_nodes_region_fix *)
procedure error_node(idst:string;i:itype;j:jtype;k:ktype;message:string);
begin
writeln('Error_node message from ',idst);
writeln(message);
writeln;
writeln('Nodedata : ');
wr_nodedata(output,i,j,k,true);
writeln('Press enter');
close(LOG);
if press_enter_wanted then readln;
halt;
end;
procedure check_node_connections;
const id='check_node_connections';
var i:itype;
j:jtype;
k:ktype;
err:integer;
begin
if wr_main_procedure_id then writeln(ID,'...');
if wr_main_procedure_id then writeln(LOG,ID,'...');
for i:=1 to imax do
for j:=1 to jmax do
for k:=1 to kmax do
with GP[i]^[j]^[k] do
begin
if (econ<>std) and (wcon<>std) and
(scon<>std) and (ncon<>std) and
(bcon<>std) and (tcon<>std) and
(nodetyp<>NOP) and (not (nodetyp in FixedBCs)) then
error_node(id,i,j,k,'This node is completely disconnected.'+cr+
'Why has it not been set to NOP ?');
err:=0;
if (wcon=std) and (GP[i-1]^[j]^[k].econ<>std) then err:=err+1;
if (econ=std) and (GP[i+1]^[j]^[k].wcon<>std) then err:=err+1;
if (scon=std) and (GP[i]^[j-1]^[k].ncon<>std) then err:=err+1;
if (ncon=std) and (GP[i]^[j+1]^[k].scon<>std) then err:=err+1;
if (bcon=std) and (GP[i]^[j]^[k-1].tcon<>std) then err:=err+1;
if (tcon=std) and (GP[i]^[j]^[k+1].bcon<>std) then err:=err+1;
if (wcon=noFlow) and (GP[i-1]^[j]^[k].econ<>noFlow) then err:=err+1;
if (econ=noFlow) and (GP[i+1]^[j]^[k].wcon<>noFlow) then err:=err+1;
if (scon=noFlow) and (GP[i]^[j-1]^[k].ncon<>noFlow) then err:=err+1;
if (ncon=noFlow) and (GP[i]^[j+1]^[k].scon<>noFlow) then err:=err+1;
if (bcon=noFlow) and (GP[i]^[j]^[k-1].tcon<>noFlow) then err:=err+1;
if (tcon=noFlow) and (GP[i]^[j]^[k+1].bcon<>noFlow) then err:=err+1;
if err<>0 then error_node(ID,i,j,k,'Problem std--non-std!!')
end;
end;
procedure wr_count_nodes(var OM:text);
const id='wr_count_nodes';
var i:itype;
j,jusemin,jusemax:jtype;
k:ktype;
typ:nodetyptype;
totsum:longint;
sum:array[nodetyptype] of longint;
begin
wr_line(OM);
writeln(OM,ID);
if (geometry=cartesian3D) then
begin
jusemin:=1;
jusemax:=jmax;
end
else
begin
jusemin:=2;
jusemax:=2;
end;
totsum:=0;
for typ:=Nop to Nodx do
sum[typ]:=0;
for i:=1 to imax do
for j:=jusemin to jusemax do
for k:=1 to kmax do
begin
inc(totsum);
inc(sum[GP[i]^[j]^[k].nodetyp]);
end;
writeln(OM,'* Type and number of nodes incl. boundary conditions : ');
for typ:=Nop to Nodx do
if typ in FixedBCs then
writeln(OM,'*',nodetyp_string(typ):15,' ',sum[typ]:6,' value = ',cBC[typ]:20)
else
writeln(OM,'*',nodetyp_string(typ):15,' ',sum[typ]:6);
writeln(OM,'*','Total':15,' ',totsum:6);
end;
function FlxName(Flx:FlxType):string;
const ID='FlxName';
var st:string;
begin
case Flx of
flx1 : st:='Flx1 ';
flx2 : st:='Flx2 ';
flx3 : st:='Flx3 ';
flx4 : st:='Flx4 ';
flx5 : st:='Flx5 ';
(*flx6 : st:='Flx6 ';
flx7 : st:='Flx7 ';
flx8 : st:='Flx8 ';
flx9 : st:='Flx9 ';
flx10: st:='Flx10 ';*)
else
st:='Unknown!';
end;
FlxName:=st;
end; (* FlxName *)
function ObsName(Obs:ObsType):string;
const ID='ObsName';
var st:string;
begin
case Obs of
obs1 : st:='Obs1 ';
obs2 : st:='Obs2 ';
obs3 : st:='Obs3 ';
obs4 : st:='Obs4 ';
obs5 : st:='Obs5 ';
else
st:='Unknown!';
end;
ObsName:=st;
end; (* ObsName *)
function FixId(dir:dirtype;h:htype;var wFixfound:FixType):boolean;
const ID='FixId';
var wFix,FixStart,FixStop:FixType;
found:boolean;
begin
FixStart:=xFix1; (* Arbitary initialization just to keep compiler happy! *)
FixStop :=xFix1; (* Arbitary initialization just to keep compiler happy! *)
wFixfound:=wFixlast;
case dir of
xdir: begin FixStart:=xFix1; FixStop:=pred(yFix1) end;
ydir: begin FixStart:=yFix1; FixStop:=pred(zFix1) end;
zdir: begin FixStart:=zFix1; FixStop:=pred(wFixLast) end;
else
error_std(ID,'Unknown dir');
end;
found:=false;
for wFix:=FixStart to FixStop do
if (wFixVal[wFix].defined) and (wFixVal[wFix].h=h) then
begin
found:=true;
wFixfound:=wFix;
end;
FixID:=found;
end;
procedure set_cvsize(i:itype;j:jtype;k:ktype;
var ArW,ArE,ArS,ArN,ArB,ArT,dV:datatype);
const ID='set_cvsize';
begin
case geometry of
cartesian3D:
begin
ArW:=(y[j+1]-y[j])*(z[k+1]-z[k]);
ArE:=ArW;
ArS:=(x[i+1]-x[i])*(z[k+1]-z[k]);
ArN:=ArS;
ArB:=(x[i+1]-x[i])*(y[j+1]-y[j]);
ArT:=ArB;
dV:=(x[i+1]-x[i])*(y[j+1]-y[j])*(z[k+1]-z[k]);
end;
cartesian2D:
begin
ArW:=Ly*(z[k+1]-z[k]);
ArE:=ArW;
ArS:=(x[i+1]-x[i])*(z[k+1]-z[k]);
ArN:=ArS;
ArB:=(x[i+1]-x[i])*Ly;
ArT:=ArB;
dV:=(x[i+1]-x[i])*Ly*(z[k+1]-z[k]);
end;
cylindrical2D:
begin
ArW:=2*pi*x[i]*(z[k+1]-z[k]);
ArE:=2*pi*x[i+1]*(z[k+1]-z[k]);
ArS:=1;
ArN:=1;
ArB:=pi*(sqr(x[i+1])-sqr(x[i]));
ArT:=ArB;
if j=2 then dV:=pi*(sqr(x[i+1])-sqr(x[i]))*(z[k+1]-z[k])
else dV:=0;
end;
else
error_std(ID,'Unknown geometry');
end;
end; (* set_cvsize *)
procedure convert_deadnodes_to_NOPs;
const ID='convert_deadnodes_to_NOPs';
var sum,ArW,ArE,ArS,ArN,ArB,ArT,dV:datatype;
i:itype;j:jtype;k:ktype;
begin
if wr_main_procedure_id then writeln(ID,'...');
if wr_main_procedure_id then writeln(LOG,ID,'...');
for i:=1 to imax do
for j:=1 to jmax do
for k:=1 to kmax do
with GP[i]^[j]^[k] do
begin
set_cvsize(i,j,k,ArW,ArE,ArS,ArN,ArB,ArT,dV);
if (ArW=0) and (wcon=std) then
change_con(i,j,k,west,wcon,noflow);
if (ArE=0) and (econ=std) then
change_con(i,j,k,east,econ,noflow);
if (ArS=0) and (scon=std) then
change_con(i,j,k,south,scon,noflow);
if (ArN=0) and (ncon=std) then
change_con(i,j,k,north,ncon,noflow);
if (ArB=0) and (bcon=std) then
change_con(i,j,k,bottom,bcon,noflow);
if (ArT=0) and (tcon=std) then
change_con(i,j,k,top,tcon,noflow);
sum:=0;
if (wcon=std) then sum:=sum+1;
if (econ=std) then sum:=sum+1;
if (scon=std) then sum:=sum+1;
if (ncon=std) then sum:=sum+1;
if (bcon=std) then sum:=sum+1;
if (tcon=std) then sum:=sum+1;
if (sum=0) and (nodetyp=free) then (* Fixed nodes may well be disconnected ! *)
begin
change_node(i,j,k,NOP,noFlow,noFlow,noFlow,noFlow,noFlow,noFlow);
if wr_details then writeln(LOG,ID,' Warning. Node at (i j k)=(',i:5,' ',j:5,' ',k:5,') was set to NOP');
end;
end;
end;
function Apower(P:datatype):datatype;
const ID='Apower';
zero=1E-196;
var A:datatype;
begin
case scheme of
powerlaw:
begin
if (1-0.1*abs(P)>zero) then A:=max(0,exp(5*ln(1-0.1*abs(P))))
else A:=0;
end;
central: A:=1-0.5*abs(P);
upwind: A:=1;
hybrid: A:=max(0,1-0.5*abs(P));
exact : begin
if abs(exp(abs(P))-1)>zero then
A:=abs(P)/(exp(abs(P))-1)
else
A:=1/(1+0.5*abs(P));
end;
else
begin
A:=0;
error_std(ID,'Unknown scheme type!');
end;
end;
Apower:=A;
end;
function Deff(D1,D2,f:datatype):datatype;
(* See Patankar p. 45 or Risoe-R-623(EN) p. 15 *)
begin
if (D1=0) or (D2=0) then error_std('Deff','D1=0 or D2=0');
if ((1.0-f)/D1+f/D2)=0 then error_std('Deff','((1-f)/D1+f/D2)=0');
Deff:=1.0/((1.0-f)/D1+f/D2);
end;
function a_coeff(Ar,q:datatype;dir:dirtype;i:itype;j:jtype;k:ktype):datatype;
const ID='a_coeff';
PeMax=100;
var aa,ds,f,D1,D2,Y,QQ,Pe:datatype;
begin
Pe:=0; (* Aribtary initialization just to keep compiler happy ! *)
ds:=0; (* Aribtary initialization just to keep compiler happy ! *)
f:=0; (* Aribtary initialization just to keep compiler happy ! *)
D1:=0; (* Aribtary initialization just to keep compiler happy ! *)
D2:=0; (* Aribtary initialization just to keep compiler happy ! *)
QQ:=0; (* Aribtary initialization just to keep compiler happy ! *)
case dir of
west: begin
ds:=0.5*(dx[i-1]+dx[i]);
if ds=0 then error_node(ID,i,j,k,'ds=0 '+DirName(dir));
f:=dx[i]/ds/2;
D1:=D_def(xdir,i-1,j,k);
D2:=D_def(xdir,i,j,k);
QQ:=q;
end;
east: begin
ds:=0.5*(dx[i]+dx[i+1]);
if ds=0 then error_node(ID,i,j,k,'ds=0 '+DirName(dir));
f:=dx[i+1]/ds/2;
D1:=D_def(xdir,i,j,k);
D2:=D_def(xdir,i+1,j,k);
QQ:=-q;
end;
south: begin
ds:=0.5*(dy[j-1]+dy[j]);
if ds=0 then error_node(ID,i,j,k,'ds=0 '+DirName(dir));
f:=dy[j]/ds/2;
D1:=D_def(ydir,i,j-1,k);
D2:=D_def(ydir,i,j,k);
QQ:=q;
end;
north: begin
ds:=0.5*(dy[j]+dy[j+1]);
if ds=0 then error_node(ID,i,j,k,'ds=0 '+DirName(dir));
f:=dy[j+1]/ds/2;
D1:=D_def(ydir,i,j,k);
D2:=D_def(ydir,i,j+1,k);
QQ:=-q;
end;
bottom: begin
ds:=0.5*(dz[k-1]+dz[k]);
if ds=0 then error_node(ID,i,j,k,'ds=0 '+DirName(dir));
f:=dz[k]/ds/2;
D1:=D_def(zdir,i,j,k-1);
D2:=D_def(zdir,i,j,k);
QQ:=q;
end;
top: begin
ds:=0.5*(dz[k]+dz[k+1]);
if ds=0 then error_node(ID,i,j,k,'ds=0 '+DirName(dir));
f:=dz[k+1]/ds/2;
D1:=D_def(zdir,i,j,k);
D2:=D_def(zdir,i,j,k+1);
QQ:=-q;
end;
else
error_std(ID,'Illegal direction '+DirName(dir));
end;
Y:=Deff(D1,D2,f)*Ar/ds;
if Ar<0 then
error_node(ID,i,j,k,'Ar<0. Direction : '+DirName(dir));
if Y<0 then
error_node(ID,i,j,k,'Y<0. Direction : '+DirName(dir));
if (Y=0) and (q>0) then Pe:=PeMax;
if (Y=0) and (q<0) then Pe:=-PeMax;
if (Y=0) and (q=0) then
error_std(ID,'Y=0 and q=0, Cannot calculate Peclet number !');
if (Y<>0) then Pe:=q/Y;
if Pe>PeMax then Pe:=PeMax;
if Pe<-Pemax then Pe:=-PeMax;
aa:=Y*Apower(Pe)+max(0,QQ);
a_coeff:=aa;
end;
procedure set_coefficients;
const ID='set_coefficients';
var ArW,ArE,ArS,ArN,ArB,ArT,dV:datatype;
i:itype;j:jtype;k:ktype;
ap_new_dt:datatype;
begin
if wr_main_procedure_id then writeln(ID,'...');
if wr_main_procedure_id then writeln(LOG,ID,'...');
for i:=1 to imax do
for j:=1 to jmax do
for k:=1 to kmax do
begin
set_cvsize(i,j,k,ArW,ArE,ArS,ArN,ArB,ArT,dV);
with GP[i]^[j]^[k] do
begin
if nodetyp=NOP then
begin
aW:=0; aE:=0; aSS:=0; aN:=0; aB:=0; aT:=0;
aP_old_dt:=0;
b:=dumReal;
aP:=1;
valid_fieldvalue:=false;
end;
if nodetyp in fixedBCs then
begin
aW:=0; aE:=0; aSS:=0; aN:=0; aB:=0; aT:=0;
aP_old_dt:=0;
b:=cBC[nodetyp];
aP:=1;
valid_fieldvalue:=true;
end;
if nodetyp=free then
begin
case Wcon of
std: aW:=a_coeff(ArW,qw,west,i,j,k);
nill,noflow: aW:=0;
else
error_node(ID,i,j,k,'Unknown node connector (W)');
end; (* Wcon *)
case Econ of
std: aE:=a_coeff(ArE,qE,east,i,j,k);
nill,noflow: aE:=0;
else
error_node(ID,i,j,k,'Unknown node connector (E)');
end; (* Econ *)
case Scon of
std: aSS:=a_coeff(ArS,qS,south,i,j,k);
nill,noflow: aSS:=0;
else
error_node(ID,i,j,k,'Unknown node connector (S)');
end; (* Scon *)
case Ncon of
std: aN:=a_coeff(ArN,qN,north,i,j,k);
nill,noflow: aN:=0;
else
error_node(ID,i,j,k,'Unknown node connector (N)');
end; (* Ncon *)
case Bcon of
std: aB:=a_coeff(ArB,qB,bottom,i,j,k);
nill,noflow: aB:=0;
else
error_node(ID,i,j,k,'Unknown node connector (B)');
end; (* Bcon *)
case Tcon of
std: aT:=a_coeff(ArT,qT,top,i,j,k);
nill,noflow: aT:=0;
else
error_node(ID,i,j,k,'Unknown node connector (T)');
end; (* Tcon *)
(* The "density" beta may now change from one time step to the
next. aP_old should correspond to the time when the last
field was calculated. If we ignore transport, generation
and decay we have: beta(1)*ca(1) = beta(0)*ca(0). In terms
of coefficients this means, that ap_new*ca = ap_old*ca_old) *)
case solution of
unsteady: begin (* Revised June 6, 1999 *)
if dtim<=0 then error_std(ID,'dtim<=0 !!');
aP_new_dt:=beta_def(i,j,k)*dV;
if not unsteady_has_been_started then aP_old_dt:=aP_new_dt;
end;
steady: begin (* Revised November 1, 1999 *)
(* Now a steady-state field can be used as a start of am unstaedy calc. *)
ap_new_dt:=beta_def(i,j,k)*dV;;
aP_old_dt:=0
end;
else
ap_new_dt:=0; (* Just to keep compiler happy *)
error_std(ID,'This solution type is invalid.')
end;
if solution=unsteady then
begin
b:=e_def(i,j,k)*dV*G_def(i,j,k)+aP_old_dt/dtim*GP[i]^[j]^[k].c;
aP:=aW+aE+aSS+aN+aB+aT+aP_new_dt/dtim+beta_def(i,j,k)*dV*lambda_def(i,j,k);
end
else
begin
b:=e_def(i,j,k)*dV*G_def(i,j,k);
aP:=aW+aE+aSS+aN+aB+aT+beta_def(i,j,k)*dV*lambda_def(i,j,k);
end;
aP_old_dt:=aP_new_dt; (* To be used in next timne step *)
valid_fieldvalue:=true;
end; (* nodetyp=free *)
if not (nodetyp in [NOP,free]+fixedBCs) then
error_std(ID,'Illegal or undefined nodetyp.');
end;
end;
if (solution=unsteady) then
unsteady_has_been_started:=true
else
unsteady_has_been_started:=false;
end; (* set_coefficients *)
procedure revise_BC_running_coefficients;
const ID='revise_BC_running_coefficients';
var ArW,ArE,ArS,ArN,ArB,ArT,dV:datatype;
i:itype;j:jtype;k:ktype;
begin
if wr_main_procedure_id then writeln(ID,'...');
if wr_main_procedure_id then writeln(LOG,ID,'...');
for i:=1 to imax do
for j:=1 to jmax do
for k:=1 to kmax do
begin
set_cvsize(i,j,k,ArW,ArE,ArS,ArN,ArB,ArT,dV);
with GP[i]^[j]^[k] do
begin
if nodetyp in fixedBCs then
begin
aW:=0; aE:=0; aSS:=0; aN:=0; aB:=0; aT:=0;
aP_old_dt:=0;
b:=cBC[nodetyp];
aP:=1;
valid_fieldvalue:=true;
end;
end;
end;
end; (* revise_BC_running_coefficients *)
procedure check_coefficients;
const ID='check_coefficients';
var i:itype;j:jtype;k:ktype;
begin
if wr_main_procedure_id then writeln(ID,'...');
if wr_main_procedure_id then writeln(LOG,ID,'...');
for i:=1 to imax do
for j:=1 to jmax do
for k:=1 to kmax do
if GP[i]^[j]^[k].ap=0 then
error_node(ID,i,j,k,'ap=0. Try another scheme (e.g. upwind)!');
end;
procedure initialize_vars;
const ID='initialize_vars';
var nodetyp:nodetyptype;
i:itype;j:jtype;k:ktype;
wFix:FixType;
obs:obstype;
begin
if wr_main_procedure_id then writeln(ID,'...');
if wr_main_procedure_id then writeln(LOG,ID,'...');
for i:=1 to imaxTot do
begin
x[i]:=dumReal;
dx[i]:=dumReal;
dcdxMax[i]:=0;
end;
for j:=1 to jmaxTot do
begin
y[j]:=dumReal;
dy[j]:=dumReal;
dcdyMax[j]:=0;
end;
for k:=1 to kmaxTot do