-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR3Writ03.pas
1379 lines (1279 loc) · 39.8 KB
/
R3Writ03.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 R3Writ03;
(* 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,R3Defi03; (* Delphi *)
{$ELSE}
uses dos,R3defi03; (* Borland Pascal *)
{$ENDIF}
procedure error_std(idst:string;message:string);
procedure warning_std(idst:string;message:string;war:warningtype);
procedure wr_memory_status(var OM:text;st:string);
procedure wr_material_volumes_etc(var OM:text);
procedure wr_axis(var OM:text;dir:dirtype);
procedure wr_axes_proc(var OM:text);
procedure wr_nodedata(var OM:text; i:itype;j:jtype;k:ktype; header:boolean);
procedure wr_cvsize(var OM:text);
procedure get_fieldvalue(xp,dx,yp,dy,zp,dz:datatype; var c,dc:datatype; var valid:boolean);
procedure get_fieldvalue2D(xp,dx,zp,dz:datatype; var c,dc:datatype; var valid:boolean);
function fieldvalue(xp,yp,zp:datatype; var valid:boolean):datatype;
function fieldvalue2D(xp,zp:datatype; var valid:boolean):datatype;
function xnod(i:itype):datatype;
function ynod(j:jtype):datatype;
function znod(k:ktype):datatype;
procedure find_i_intpol(xp:datatype; var iA1,iB1,iA2,iB2:itype);
procedure find_j_intpol(yp:datatype; var jA1,jB1,jA2,jB2:jtype);
procedure find_k_intpol(zp:datatype; var kA1,kB1,kA2,kB2:ktype);
function find_i_face(xp:datatype):itype;
function find_j_face(yp:datatype):jtype;
function find_k_face(zp:datatype):ktype;
function find_i_cv(xp:datatype):itype;
function find_j_cv(yp:datatype):jtype;
function find_k_cv(zp:datatype):ktype;
procedure get_avgfield(x1,x2,y1,y2,z1,z2,ddd:datatype; var c,dc:datatype);
procedure get_avgfield2D(x1,x2,z1,z2,ddd:datatype; var c,dc:datatype);
procedure get_activity(mset: mattypeset; var act_tot,vol:datatype);
procedure wr_gridfiles;
Implementation
uses R3Main03;
procedure error_std(idst:string;message:string);
begin
writeln('Error_std message from : ',idst);
writeln(message);
writeln('Press enter');
if LOG_file_is_open then close(LOG);
if RES_file_is_open then close(RES);
if press_enter_wanted then readln;
halt;
end;
procedure warning_std(idst:string;
message:string;
war:warningtype);
begin
inc(warning_table[war]);
warnings_were_issued:=true;
if ord(war)>ord(max_issued_warning_priority) then
max_issued_warning_priority:=war;
if ord(war)>=ord(warning_priority_screen) then
begin
wr_line(output);
writeln('Warning_std message from : ',idst,' (warning = ',war_string(war),')');
writeln(message);
wr_line(output);
end;
if (LOG_file_is_open) and (ord(war)>=ord(warning_priority_log)) then
begin
wr_line(LOG);
writeln(LOG,'Warning_std message from : ',idst,' (warning = ',war_string(war),')');
writeln(LOG,message);
wr_line(LOG);
end;
end;
procedure wr_memory_status(var OM:text;st:string);
const ID='wr_memory_status';
begin
wr_line(OM);
writeln(OM,ID);
{$IFNDEF Delphi}
writeln(OM,'* MaxAvail = ',MaxAvail/1000/1000:12:4,' Mb '+st,' Nodes = ',number_of_nodes:12);
{$ENDIF}
writeln(OM,' imax = ',imax:6 ,' jmax = ',jmax:6 ,' kmax = ',kmax:6);
writeln(OM,' imaxTot = ',imaxTot:6,' jmaxTot= ',jmaxTot:6,' kmaxTot = ',kmaxTot:6);
{$IFDEF Delphi}
(* These functions can be used to tell something about the memory status under Delphi *)
(*
writeln(OM,'TotalAddrSpace = ',GetHeapStatus.TotalAddrSpace);
writeln(OM,'TotalUncommitted = ',GetHeapStatus.TotalUncommitted);
writeln(OM,'Totalcommitted = ',GetHeapStatus.Totalcommitted);
writeln(OM,'Total allocated = ',GetHeapStatus.TotalAllocated);
writeln(OM,'Total free = ',GetHeapStatus.TotalFree);
writeln(OM,'Free small = ',GetHeapStatus.FreeSmall);
writeln(OM,'Free big = ',GetHeapStatus.FreeBig);
writeln(OM,'Unused = ',GetHeapStatus.Unused);
writeln(OM,'Overhead = ',GetHeapStatus.overhead);
writeln(OM,'HeapErrorCode = ',GetHeapStatus.HeapErrorCode);
*)
{$ENDIF}
end;
procedure get_activity(mset: mattypeset; var act_tot,vol:datatype);
var conc,dum,dV:datatype;
i:itype;
j,jusemin,jusemax:jtype;
k:ktype;
begin
act_tot:=0;
vol:=0;
if geometry=cartesian3D then
begin
jusemin:=1;
jusemax:=jmax;
end
else
begin
jusemin:=2;
jusemax:=2;
end;
for i:=1 to imax do
for j:=jusemin to jusemax do
for k:=1 to kmax do
if (materials_def(i,j,k) in mset) then
begin
set_cvsize(i,j,k,dum,dum,dum,dum,dum,dum,dV);
vol:=vol+dV;
if (dV<>0) and (GP[i]^[j]^[k].valid_fieldvalue) then
begin
conc:=GP[i]^[j]^[k].c;
act_tot:=act_tot+beta_def(i,j,k)*conc*dV;
(* Observe: *)
(* conc is the radon concentration in the air-filled pores *)
(* whereas act_tot is the total activity regardless of phase. *)
end;
end;
end; (* get_activity *)
procedure wr_material_volumes_etc(var OM:text);
const ID='wr_material_volumes_etc';
var i:itype;
j,jusemin,jusemax:jtype;
k:ktype;
ArW,ArE,ArS,ArN,ArB,ArT,dV,conc:datatype;
m:mattype;
first:array[mattype] of boolean;
num,N_invalid:array[mattype] of longint;
act,avgconc,sumconc,minconc,maxconc,vol:array[mattype] of datatype;
act_tot,avgconc_tot,sumconc_tot,vol_tot:datatype;
i_minconc,i_maxconc:array[mattype] of itype;
j_minconc,j_maxconc:array[mattype] of jtype;
k_minconc,k_maxconc:array[mattype] of ktype;
matset: set of mattype;
begin
wr_line(OM);
writeln(OM,ID,' (volume-averaged field values)');
if geometry=cartesian3D then
begin
jusemin:=1;
jusemax:=jmax;
end
else
begin
jusemin:=2;
jusemax:=2;
end;
vol_tot:=0;
act_tot:=0;
sumconc_tot:=0;
for m:=mat_undefined to mat_last do
begin
first[m]:=true;
num[m]:=0;
avgconc[m]:=0.0;
sumconc[m]:=0.0;
minconc[m]:=0.0;
maxconc[m]:=0.0;
i_minconc[m]:=1;
j_minconc[m]:=1;
k_minconc[m]:=1;
i_maxconc[m]:=1;
j_maxconc[m]:=1;
k_maxconc[m]:=1;
vol[m]:=0;
act[m]:=0;
N_invalid[m]:=0;
end;
for i:=1 to imax do
for j:=jusemin to jusemax do
for k:=1 to kmax do
begin
set_cvsize(i,j,k,ArW,ArE,ArS,ArN,ArB,ArT,dV);
m:=GP[i]^[j]^[k].mat;
vol[m]:=vol[m]+dV;
vol_tot:=vol_tot+dV;
(* if (dV<>0) and (not GP[i]^[j]^[k].valid_fieldvalue) then *)
if (dV=0) or (not GP[i]^[j]^[k].valid_fieldvalue) then (* Changed May 30, 1999 *)
begin
inc(N_invalid[m]); (* Changed June 25, 1998 from: error_node(ID,i,j,k,'dV<>0 and fieldvalue=false !'); *)
end
else
begin
conc:=GP[i]^[j]^[k].c;
sumconc[m]:=sumconc[m]+conc*dV;
sumconc_tot:=sumconc_tot+conc*dV;
act[m]:=act[m]+beta_def(i,j,k)*conc*dV;
act_tot:=act_tot+beta_def(i,j,k)*conc*dV;
if (dV>0) then
begin
inc(num[m]);
if (first[m]) or (conc<minconc[m]) then
begin
minconc[m]:=conc;
i_minconc[m]:=i;
j_minconc[m]:=j;
k_minconc[m]:=k;
end;
if (first[m]) or (conc>maxconc[m]) then
begin
maxconc[m]:=conc;
i_maxconc[m]:=i;
j_maxconc[m]:=j;
k_maxconc[m]:=k;
end;
if first[m] then first[m]:=false;
end;
end; (* valid point *)
end;
if vol[mat_last]<>0 then
error_std(ID,'Some volumes have been assigned to mat_last.');
for m:=mat_undefined to pred(mat_last) do
if (vol[m]<>0) then avgconc[m]:=sumconc[m]/vol[m];
if (vol_tot<>0) then
avgconc_tot:=sumconc_tot/vol_tot;
matset:=[];
for m:=mat_undefined to pred(mat_last) do
if (num[m]+N_invalid[m]<>0) then matset:=matset+[m];
writeln(OM,'mat ':6,' ',
'Avg(conc)':18,' ',
'Activity':18,' ',
'Volume':18,' ',
'N':10,' ',
'N_invalid':10);
for m:=mat_undefined to pred(mat_last) do
if m in matset then
writeln(OM,mat_string(m):6,' ',
avgconc[m]:18,' ',
act[m]:18,' ',
vol[m]:18,' ',
num[m]:10,' ',
N_invalid[m]:10);
if geometry=cartesian3D then
begin
writeln(OM,'mat ':6,' ',
'Min(conc)':18,' ',
'i':3,' ',
'j':3,' ',
'k':3,' ',
'x':12,' ',
'y':12,' ',
'z':12);
for m:=mat_undefined to pred(mat_last) do
if m in matset then
writeln(OM,mat_string(m):6,' ',
minconc[m]:18,' ',
i_minconc[m]:3,' ',
j_minconc[m]:3,' ',
k_minconc[m]:3,' ',
xnod(i_minconc[m]):12,' ',
ynod(j_minconc[m]):12,' ',
znod(k_minconc[m]):12);
writeln(OM,'mat ':6,' ',
'Max(conc)':18,' ',
'i':3,' ',
'j':3,' ',
'k':3,' ',
'x':12,' ',
'y':12,' ',
'z':12);
for m:=mat_undefined to pred(mat_last) do
if m in matset then
writeln(OM,mat_string(m):6,' ',
maxconc[m]:18,' ',
i_maxconc[m]:3,' ',
j_maxconc[m]:3,' ',
k_maxconc[m]:3,' ',
xnod(i_maxconc[m]):12,' ',
ynod(j_maxconc[m]):12,' ',
znod(k_maxconc[m]):12);
end
else
begin (* 2D only *)
writeln(OM,'mat ':6,' ',
'Min(conc)':18,' ',
'i':3,' ',
'k':3,' ',
'x':12,' ',
'z':12);
for m:=mat_undefined to pred(mat_last) do
if m in matset then
writeln(OM,mat_string(m):6,' ',
minconc[m]:18,' ',
i_minconc[m]:3,' ',
k_minconc[m]:3,' ',
xnod(i_minconc[m]):12,' ',
znod(k_minconc[m]):12);
writeln(OM,'mat ':6,' ',
'Max(conc)':18,' ',
'i':3,' ',
'k':3,' ',
'x':12,' ',
'z':12);
for m:=mat_undefined to pred(mat_last) do
if m in matset then
writeln(OM,mat_string(m):6,' ',
maxconc[m]:18,' ',
i_maxconc[m]:3,' ',
k_maxconc[m]:3,' ',
xnod(i_maxconc[m]):12,' ',
znod(k_maxconc[m]):12);
end;
writeln(OM,'Total geometric volume = ',vol_tot:20);
writeln(OM,'Total activity = ',act_tot:20);
writeln(OM,'Overall mean concentration = ',avgconc_tot:20);
end;
procedure wr_axis(var OM:text;dir:dirtype);
const ID='wr_axis';
var h,hmax:htype;
w,dw,dcdwMax:axistype;
fixst,st,sth:string;
wFix:FixType;
begin
hmax:=0; (* Arbitary initialization just to keep compiler happy! *)
case dir of
xdir: begin hmax:=imax; w:=x; dw:=dx; sth:='i'; st:='x'; dcdwMax:=dcdxMax end;
ydir: begin hmax:=jmax; w:=y; dw:=dy; sth:='j'; st:='y'; dcdwMax:=dcdyMax end;
zdir: begin hmax:=kmax; w:=z; dw:=dz; sth:='k'; st:='z'; dcdwMax:=dcdzMax end;
else
error_std(ID,'Illegal dir.');
end;
writeln(OM,'axis',' ',
sth:3,' ',
st+'['+sth+']':11,' ',
st+'['+sth+'+1]':11,' ',
'd'+st+'['+sth+']':12,' ',
'dcd'+st:12,' ',
'dcd'+st+'norm':10,' ',
'Fixpts':7);
for h:=1 to hmax do
begin
if FixID(dir,h,wFix) then
FixSt:=FixName(wFix)
else
FixSt:='-';
write(OM,st:4,' ',
h:3,' ',
w[h]:11:5,' ',
w[h+1]:11:5,' ',
dw[h]:12:7,' ',
dcdwMax[h]:12,' ');
if dcdwMaxAll<>0 then
write(OM,dcdwMax[h]/dcdwMaxAll:10:8,' ')
else
write(OM,0.0:10:8);
writeln(OM,FixSt:7);
end;
end; (* wr_axis *)
procedure wr_axes_proc(var OM:text);
const ID='wr_axes_proc';
begin
wr_line(OM);
writeln(OM,ID);
wr_axis(OM,xdir);
writeln(OM);
wr_axis(OM,ydir);
writeln(OM);
wr_axis(OM,zdir);
writeln(OM);
end;
procedure wr_nodedata(var OM:text; i:itype;j:jtype;k:ktype; header:boolean);
const ID='wr_nodedata';
begin
wr_line(OM);
writeln(OM,ID);
if header then
begin
wr_line(OM);
writeln(OM,'i':3,' ','j':3,' ','k':3,' ','c':12,' ',
'nodetyp',' ',
'west ','east ',
'south ','north ',
'bottom ','top ');
wr_line(OM);
end;
with GP[i]^[j]^[k] do
writeln(OM,i:3,' ',j:3,' ',k:3,' ',c:12:3,' ',
nodetyp_string(nodetyp),' ',
nodecon_string(wcon),nodecon_string(econ),
nodecon_string(scon),nodecon_string(ncon),
nodecon_string(bcon),nodecon_string(tcon));
end;
procedure wr_cvsize(var OM:text);
const ID='wr_cvsize';
var ArW,ArE,ArS,ArN,ArB,ArT,dV:datatype;
i:itype;j:jtype;k:ktype;
begin
wr_line(OM);
writeln(OM,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);
writeln(OM,i:3,' ',j:3,' ',k:3,' ArW=',ArW:12,' ArE=',ArE:12,
' ArS=',ArS:12,' ArN=',ArN:12,
' ArB=',ArB:12,' ArT=',ArT:12,
' dV=',dV:12);
end;
end;
function xnod(i:itype):datatype;
begin
xnod:=x[i]+0.5*dx[i];
end;
function ynod(j:jtype):datatype;
begin
ynod:=y[j]+0.5*dy[j];
end;
function znod(k:ktype):datatype;
begin
znod:=z[k]+0.5*dz[k];
end;
procedure find_i_intpol(xp:datatype; var iA1,iB1,iA2,iB2:itype);
const ID='find_i_intpol';
var found:boolean;
i:itype;
begin
found:=false;
for i:=1 to imax do
if (not found) and (abs(xp-xnod(i))<=0) then (* First check if xp is exactly on top of a node ... *)
begin
found:=true;
if i=1 then
begin (* Unique *)
iA1:=1; iB1:=2;
iA2:=1; iB2:=2;
end;
if (2<=i) and (i<=imax-1) then
begin (* Two solutions *)
iA1:=i-1; iB1:=i;
iA2:=i; iB2:=i+1;
end;
if (i=imax) then
begin (* Unique *)
iA1:=imax-1; iB1:=imax;
iA2:=imax-1; iB2:=imax;
end;
end;
if not found then (* ... then look between nodes *)
for i:=1 to imax-1 do
if (xnod(i)<xp) and (xp<xnod(i+1)) then
begin
found:=true;
iA1:=i; iB1:=i+1;
iA2:=i; iB2:=i+1;
end;
if not found then
begin
writeln('x = ',xp);
error_std(ID,'Could not find x on this axis !!')
end;
end; (* find_i_intpol *)
procedure find_j_intpol(yp:datatype; var jA1,jB1,jA2,jB2:jtype);
const ID='find_j_intpol';
var found:boolean;
j:jtype;
begin
found:=false;
for j:=1 to jmax do
if (not found) and (abs(yp-ynod(j))<=0) then (* First check if yp is exactly on top of a node ... *)
begin
found:=true;
if j=1 then
begin (* Unique *)
jA1:=1; jB1:=2;
jA2:=1; jB2:=2;
end;
if (2<=j) and (j<=jmax-1) then
begin (* Two solutions *)
jA1:=j-1; jB1:=j;
jA2:=j; jB2:=j+1;
end;
if (j=jmax) then
begin (* Unique *)
jA1:=jmax-1; jB1:=jmax;
jA2:=jmax-1; jB2:=jmax;
end;
end;
if not found then (* ... then look between nodes *)
for j:=1 to jmax-1 do
if (ynod(j)<yp) and (yp<ynod(j+1)) then
begin
found:=true;
jA1:=j; jB1:=j+1;
jA2:=j; jB2:=j+1;
end;
if not found then
begin
writeln('y = ',yp);
error_std(ID,'Could not find y on this axis !!')
end;
end; (* find_j_intpol *)
procedure find_k_intpol(zp:datatype; var kA1,kB1,kA2,kB2:ktype);
const ID='find_k_intpol';
var found:boolean;
k:ktype;
begin
found:=false;
for k:=1 to kmax do
if (not found) and (abs(zp-znod(k))<=0) then (* First check if zp is exactly on top of a node ... *)
begin
found:=true;
if k=1 then
begin (* Unique *)
kA1:=1; kB1:=2;
kA2:=1; kB2:=2;
end;
if (2<=k) and (k<=kmax-1) then
begin (* Two solutions *)
kA1:=k-1; kB1:=k;
kA2:=k; kB2:=k+1;
end;
if (k=kmax) then
begin (* Unique *)
kA1:=kmax-1; kB1:=kmax;
kA2:=kmax-1; kB2:=kmax;
end;
end;
if not found then (* ... then look between nodes *)
for k:=1 to kmax-1 do
if (znod(k)<zp) and (zp<znod(k+1)) then
begin
found:=true;
kA1:=k; kB1:=k+1;
kA2:=k; kB2:=k+1;
end;
if not found then
begin
writeln('z = ',zp);
error_std(ID,'Could not find z on this axis !!')
end;
end; (* find_k_intpol *)
function find_i_cv(xp:datatype):itype;
const ID='find_i_cv';
(* Gives the number of the control volume where xp belongs *)
var ip:itype;
begin
if (xp<x[1]) or (xp>x[imax]) then
begin
writeln('xp = ',xp:14,' Valid range : ',x[1]:14,' to ',x[imax]:14);
error_std(ID,'Out of range');
end;
ip:=imax;
repeat
ip:=ip-1
until ((x[ip]<=xp) and (xp<=x[ip+1]));
find_i_cv:=ip;
end;
function find_j_cv(yp:datatype):jtype;
const ID='find_j_cv';
(* Gives the number of the control volume where yp belongs *)
var jp:jtype;
begin
if (yp<y[1]) or (yp>y[jmax]) then
begin
writeln('yp = ',yp:14,' Valid range : ',y[1]:14,' to ',y[jmax]:14);
error_std(ID,'Out of range');
end;
jp:=jmax;
repeat
jp:=jp-1
until ((y[jp]<=yp) and (yp<=y[jp+1]));
find_j_cv:=jp;
end;
function find_k_cv(zp:datatype):ktype;
const ID='find_k_cv';
(* Gives the number of the control volume where xp belongs *)
var kp:ktype;
begin
if (zp<z[1]) or (zp>z[kmax]) then
begin
writeln('zp = ',zp:14,' Valid range : ',z[1]:14,' to ',z[kmax]:14);
error_std(ID,'Out of range');
end;
kp:=kmax;
repeat
kp:=kp-1
until ((z[kp]<=zp) and (zp<=z[kp+1]));
find_k_cv:=kp;
end;
function find_i_face(xp:datatype):itype;
const ID='find_i_face';
(* Observe if xp is between the x-coordinate of node no. i1 and i2
this function returns i=i1 although xp may be within control volume
i2. *)
var ip:itype;
begin
if (xp<xnod(1)) or (xp>xnod(imax)) then
begin
writeln('xp = ',xp:14,' Valid range : ',xnod(1):14,' to ',xnod(imax):14);
error_std(ID,'Out of range');
end;
ip:=imax;
repeat
ip:=ip-1
until ((xnod(ip)<=xp) and (xp<=xnod(ip+1)));
find_i_face:=ip;
end;
function find_j_face(yp:datatype):jtype;
const ID='find_j_face';
(* Observe if yp is between the y-coordinate of node no. j1 and j2
this function returns j=j1 although yp may be within control volume
j2. *)
var jp:jtype;
begin
if (yp<ynod(1)) or (yp>ynod(jmax)) then
begin
writeln('yp = ',yp:14,' Valid range : ',ynod(1):14,' to ',ynod(jmax):14);
error_std(ID,'Out of range');
end;
jp:=jmax;
repeat
jp:=jp-1
until ((ynod(jp)<=yp) and (yp<=ynod(jp+1)));
find_j_face:=jp;
end;
function find_k_face(zp:datatype):ktype;
const ID='find_k_face';
(* Observe if zp is between the z-coordinate of node no. k1 and k2
this function returns k=k1 although zp may be within control volume
k2. *)
var kp:ktype;
begin
if (zp<znod(1)) or (zp>znod(kmax)) then
begin
writeln('zp = ',zp:14,' Valid range : ',znod(1):14,' to ',znod(kmax):14);
error_std(ID,'Out of range');
end;
kp:=kmax;
repeat
kp:=kp-1
until ((znod(kp)<=zp) and (zp<=znod(kp+1)));
find_k_face:=kp;
end;
function fieldvalue_old(xp,yp,zp:datatype):datatype;
const ID='fieldvalue_old';
var xA,xB,yA,yB,zA,zB,
f1,f2,f3,f4,f5,f6,f7,f8,
fp,
t1,t2,t3:datatype;
ip:itype; jp:jtype; kp:ktype;
begin
ip:=find_i_face(xp);
jp:=find_j_face(yp);
kp:=find_k_face(zp);
xA:=xnod(ip);
xB:=xnod(ip+1);
yA:=ynod(jp);
yB:=ynod(jp+1);
zA:=znod(kp);
zB:=znod(kp+1);
if (xB-xA)<>0 then t1:=(xp-xA)/(xB-xA) else t1:=0;
if (yB-yA)<>0 then t2:=(yp-yA)/(yB-yA) else t2:=0;
if (zB-zA)<>0 then t3:=(zp-zA)/(zB-zA) else t3:=0;
if ((GP[ip]^ [jp]^ [kp] .nodetyp in [NOP,NodX]) or
(GP[ip+1]^[jp]^ [kp] .nodetyp in [NOP,NodX]) or
(GP[ip]^ [jp+1]^[kp] .nodetyp in [NOP,NodX]) or
(GP[ip+1]^[jp+1]^[kp] .nodetyp in [NOP,NodX]) or
(GP[ip]^ [jp]^ [kp+1].nodetyp in [NOP,NodX]) or
(GP[ip+1]^[jp]^ [kp+1].nodetyp in [NOP,NodX]) or
(GP[ip]^ [jp+1]^[kp+1].nodetyp in [NOP,NodX]) or
(GP[ip+1]^[jp+1]^[kp+1].nodetyp in [NOP,NodX])) then
begin
wr_nodedata(output,ip, jp, kp,true);
wr_nodedata(output,ip+1,jp, kp,false);
wr_nodedata(output,ip, jp+1,kp,false);
wr_nodedata(output,ip+1,jp+1,kp,false);
wr_nodedata(output,ip, jp, kp+1,false);
wr_nodedata(output,ip+1,jp, kp+1,false);
wr_nodedata(output,ip, jp+1,kp+1,false);
wr_nodedata(output,ip+1,jp+1,kp+1,false);
writeln('xp = ',xp:12);
writeln('yp = ',yp:12);
writeln('zp = ',zp:12);
error_std(ID,'One or more of the coner points are undefined');
end;
f1:=GP[ip]^ [jp]^ [kp].c;
f2:=GP[ip+1]^[jp]^ [kp].c;
f3:=GP[ip]^ [jp+1]^[kp].c;
f4:=GP[ip+1]^[jp+1]^[kp].c;
f5:=GP[ip]^ [jp]^ [kp+1].c;
f6:=GP[ip+1]^[jp]^ [kp+1].c;
f7:=GP[ip]^ [jp+1]^[kp+1].c;
f8:=GP[ip+1]^[jp+1]^[kp+1].c;
fp:=(1-t1)*(1-t2)*(1-t3)*f1+
(t1)* (1-t2)*(1-t3)*f2+
(1-t1)*(t2)* (1-t3)*f3+
(t1)* (t2)* (1-t3)*f4+
(1-t1)*(1-t2)*(t3)* f5+
(t1)* (1-t2)*(t3)* f6+
(1-t1)*(t2)* (t3)* f7+
(t1)* (t2)* (t3)* f8;
fieldvalue_old:=fp;
end; (* fieldvalue *)
procedure interpolate(xp,yp,zp:datatype;
i1,i2,j1,j2,k1,k2:integer;
var fp:datatype;
var valid:boolean);
var xA,xB,yA,yB,zA,zB,
f1,f2,f3,f4,f5,f6,f7,f8,
t1,t2,t3:datatype;
begin
valid:=true;
fp:=dumreal;
if (i1>=i2) or (i1<1) or (i2>imax) then valid:=false;
if (j1>=j2) or (j1<1) or (j2>jmax) then valid:=false;
if (k1>=k2) or (k1<1) or (k2>kmax) then valid:=false;
if valid then
begin (* Do not do these tests, if you are outside valid ranges ! *)
if (GP[i1]^[j1]^[k1].valid_fieldvalue = false) or
(GP[i2]^[j1]^[k1].valid_fieldvalue = false) or
(GP[i1]^[j1]^[k2].valid_fieldvalue = false) or
(GP[i2]^[j1]^[k2].valid_fieldvalue = false) or
(GP[i1]^[j2]^[k1].valid_fieldvalue = false) or
(GP[i2]^[j2]^[k1].valid_fieldvalue = false) or
(GP[i1]^[j2]^[k2].valid_fieldvalue = false) or
(GP[i2]^[j2]^[k2].valid_fieldvalue = false)
then
valid:=false;
end;
if valid then
begin (* Still valid after all tests ! *)
xA:=xnod(i1);
xB:=xnod(i2);
yA:=ynod(j1);
yB:=ynod(j2);
zA:=znod(k1);
zB:=znod(k2);
if (xB-xA)<>0 then t1:=(xp-xA)/(xB-xA) else t1:=0;
if (yB-yA)<>0 then t2:=(yp-yA)/(yB-yA) else t2:=0;
if (zB-zA)<>0 then t3:=(zp-zA)/(zB-zA) else t3:=0;
f1:=GP[i1]^[j1]^[k1].c;
f2:=GP[i2]^[j1]^[k1].c;
f3:=GP[i1]^[j2]^[k1].c;
f4:=GP[i2]^[j2]^[k1].c;
f5:=GP[i1]^[j1]^[k2].c;
f6:=GP[i2]^[j1]^[k2].c;
f7:=GP[i1]^[j2]^[k2].c;
f8:=GP[i2]^[j2]^[k2].c;
fp:=(1-t1)*(1-t2)*(1-t3)*f1+
(t1)* (1-t2)*(1-t3)*f2+
(1-t1)*(t2)* (1-t3)*f3+
(t1)* (t2)* (1-t3)*f4+
(1-t1)*(1-t2)*(t3)* f5+
(t1)* (1-t2)*(t3)* f6+
(1-t1)*(t2)* (t3)* f7+
(t1)* (t2)* (t3)* f8;
end;
end; (* interpolate *)
function fieldvalue(xp,yp,zp:datatype; var valid:boolean):datatype;
const ID='fieldvalue';
var iA1,iB1,iA2,iB2,icv:itype;
jA1,jB1,jA2,jB2,jcv:jtype;
kA1,kB1,kA2,kB2,kcv:ktype;
found:boolean;
res:datatype;
dum,dV:datatype;
begin
icv:=find_i_cv(xp);
jcv:=find_j_cv(yp);
kcv:=find_k_cv(zp);
set_cvsize(icv,jcv,kcv,dum,dum,dum,dum,dum,dum,dV);
if (dV<>0) and (GP[icv]^[jcv]^[kcv].nodetyp=NOP) then
begin
valid:=false;
if ord(warning_priority_screen)<=ord(war_other) then writeln('x = ',xp:14:7,'y = ',yp:14:7,' z = ',zp:14:7);
if ord(warning_priority_log)<=ord(war_other) then writeln(LOG,'x = ',xp:14:7,'y = ',yp:14:7,' z = ',zp:14:7);
warning_std(ID,'This point is within a NOP node of non-zero volume',
war_other);
end;
find_i_intpol(xp,iA1,iB1,iA2,iB2); (* NB: iB1=iA1+1 and iB2:=iA2+1 *)
find_j_intpol(yp,jA1,jB1,jA2,jB2);
find_k_intpol(zp,kA1,kB1,kA2,kB2);
found:=false;
(* if not GP[icv]^[jcv]^[kcv].valid_fieldvalue then
begin
valid:=false;
found:=true;
res:=dumreal;
end; !!!!!!!!!!!!!!!! claus *)
(* Try four different squares. Normally these squares are all equal ! *)
if not found then interpolate(xp,yp,zp,iA1,iB1,jA1,jB1,kA1,kB1,res,found);
if not found then interpolate(xp,yp,zp,iA2,iB2,jA1,jB1,kA1,kB1,res,found);
if not found then interpolate(xp,yp,zp,iA1,iB1,jA2,jB2,kA1,kB1,res,found);
if not found then interpolate(xp,yp,zp,iA2,iB2,jA2,jB2,kA1,kB1,res,found);
if not found then interpolate(xp,yp,zp,iA1,iB1,jA1,jB1,kA2,kB2,res,found);
if not found then interpolate(xp,yp,zp,iA2,iB2,jA1,jB1,kA2,kB2,res,found);
if not found then interpolate(xp,yp,zp,iA1,iB1,jA2,jB2,kA2,kB2,res,found);
if not found then interpolate(xp,yp,zp,iA2,iB2,jA2,jB2,kA2,kB2,res,found);
if not found then
begin
found:=true;
res:=GP[icv]^[jcv]^[kcv].c;
if ord(warning_priority_screen)<=ord(war_interpolation) then
writeln('x = ',xp:14:7,'y = ',yp:14:7,' z = ',zp:14:7,' c = ',res:14);
if ord(warning_priority_log)<=ord(war_interpolation) then
writeln(LOG,'x = ',xp:14:7,'y = ',yp:14:7,' z = ',zp:14:7,' c = ',res:14);
warning_std(ID,'Could not find anything by bi-linear interpolation. '+cr+
'The field-value of the control volume is used.',
war_interpolation);
end;
valid:=found;
fieldvalue:=res;
end; (* fieldvalue *)
procedure interpolate2D(xp,zp:datatype;
i1,i2,k1,k2:integer;
var fp:datatype;
var valid:boolean);
var xA,xB,zA,zB,
f1,f2,f3,f4,
t1,t3:datatype;
begin
valid:=true;
fp:=dumreal;
if (i1>=i2) or (i1<1) or (i2>imax) then valid:=false;
if (k1>=k2) or (k1<1) or (k2>kmax) then valid:=false;
if valid then
begin (* Do not do these tests, if you are outside valid ranges ! *)
if (GP[i1]^[2]^[k1].valid_fieldvalue = false) or
(GP[i2]^[2]^[k1].valid_fieldvalue = false) or
(GP[i1]^[2]^[k2].valid_fieldvalue = false) or
(GP[i2]^[2]^[k2].valid_fieldvalue = false) then
valid:=false;
end;
if valid then
begin (* Still valid after all tests ! *)
xA:=xnod(i1);
xB:=xnod(i2);
zA:=znod(k1);
zB:=znod(k2);
if (xB-xA)<>0 then t1:=(xp-xA)/(xB-xA) else t1:=0;
if (zB-zA)<>0 then t3:=(zp-zA)/(zB-zA) else t3:=0;
f1:=GP[i1]^[2]^[k1].c;
f2:=GP[i2]^[2]^[k1].c;
f3:=GP[i1]^[2]^[k2].c;
f4:=GP[i2]^[2]^[k2].c;
fp:=(1-t1)*(1-t3)*f1+
(t1)* (1-t3)*f2+
(1-t1)*(t3)* f3+
(t1)* (t3)* f4;
end;
end; (* interpolate2D *)
function fieldvalue2D(xp,zp:datatype; var valid:boolean):datatype;
const ID='fieldvalue2D';
var iA1,iB1,iA2,iB2,icv:itype;
kA1,kB1,kA2,kB2,kcv:ktype;
found:boolean;
res:datatype;
dum,dV:datatype;
begin
icv:=find_i_cv(xp);
kcv:=find_k_cv(zp);
set_cvsize(icv,2,kcv,dum,dum,dum,dum,dum,dum,dV);
if (dV<>0) and (GP[icv]^[2]^[kcv].nodetyp=NOP) then
begin
valid:=false;
if ord(warning_priority_screen)<=ord(war_interpolation) then writeln('x = ',xp:14:7,' z = ',zp:14:7);
if ord(warning_priority_log)<=ord(war_interpolation) then writeln(LOG,'x = ',xp:14:7,' z = ',zp:14:7);
warning_std(ID,'This point is within a NOP node of non-zero volume',
war_interpolation);
end;
find_i_intpol(xp,iA1,iB1,iA2,iB2); (* NB: iB1=iA1+1 and iB2:=iA2+1 *)
find_k_intpol(zp,kA1,kB1,kA2,kB2);
found:=false;
if not GP[icv]^[2]^[kcv].valid_fieldvalue then
begin
valid:=false;
found:=true;
res:=dumreal;
end;
(* Try four different squares. Normally these squares are all equal ! *)
if not found then interpolate2D(xp,zp,iA1,iB1,kA1,kB1,res,found);
if not found then interpolate2D(xp,zp,iA2,iB2,kA1,kB1,res,found);
if not found then interpolate2D(xp,zp,iA1,iB1,kA2,kB2,res,found);
if not found then interpolate2D(xp,zp,iA2,iB2,kA2,kB2,res,found);
if not found then
begin
found:=true;
res:=GP[icv]^[2]^[kcv].c;
if ord(warning_priority_screen)<=ord(war_interpolation) then writeln('x = ',xp:14:7,' z = ',zp:14:7);
if ord(warning_priority_log)<=ord(war_interpolation) then writeln(LOG,'x = ',xp:14:7,' z = ',zp:14:7);
warning_std(ID,'Could not find anything by bi-linear interpolation. '+cr+
'The field-value of the control volume is used.',
war_interpolation);
end;
valid:=found;
fieldvalue2D:=res;
end; (* fieldvalue2D *)
procedure get_fieldvalue(xp,dx,yp,dy,zp,dz:datatype;
var c,dc:datatype;
var valid:boolean);
const ID='get_fieldvalue';
q=10; (* Resolution factor for numerical derivate calculations *)
var ddx,ddy,ddz,
dc_ddx,dc_ddy,dc_ddz,
x_minus,x_plus,
y_minus,y_plus,
z_minus,z_plus:datatype;
ip:itype;
jp:jtype;
kp:ktype;
(* The field value is found by bi-linear interpolation as described