1 | include(dom.inc)
2 | PROGRAM Balance_flux
3 |
4 | ! ================================================================!
5 | ! !
6 | ! Balance_flux.F : Calculate flux at BC !
7 | ! !
8 | ! out : !
9 | ! !
10 | ! author : PEDOT T. (Sept 09) !
11 | ! !
12 | ! ================================================================!
13 |
14 | IMPLICIT NONE
15 |
16 | include 'dom_constants.h'
17 |
18 | CHARACTER*80 :: path,outpath
19 | CHARACTER*80 :: clpropfile,gdatfile,volafile
20 | CHARACTER*80 :: SrFile, QwFile, cnodefile
21 | CHARACTER*80 :: FMT
22 | DOM_INT :: i, j, l, k, icell,nface,nfaces
23 | DOM_INT :: num_patch, num_patchmax,inode
24 | DOM_INT :: ntcells,ntnodes,ntfaces,ntfacesmax,ndirs
25 | DOM_REAL :: Temp,SumSr,VolumeTot
26 |
27 | DOM_INT, ALLOCATABLE, DIMENSION(:,:) :: patch
28 | DOM_INT , allocatable, dimension(:) :: cnodes
29 | DOM_INT , allocatable, dimension(:,:) :: cnnode
30 |
31 | DOM_REAL, ALLOCATABLE, DIMENSION(:) :: QwTot,Sr,Surface,Volume
32 | DOM_REAL, ALLOCATABLE, DIMENSION(:) :: Sr_node
33 | DOM_REAL, ALLOCATABLE, DIMENSION(:,:) :: Surf,Qw
34 |
35 | ! ---------------------------------------------------------!
36 | ! Version 2.04 output files with data in the cell'Surf center !
37 | ! ---------------------------------------------------------!
38 |
39 | OPEN (FILE_CHCS , FILE='balance_flux.choices', FORM='FORMATTED')
40 | READ (FILE_CHCS,*) path ! Path for outfiles *.in
41 | READ (FILE_CHCS,*) outpath ! Path for outfiles *.out
42 | CLOSE(FILE_CHCS)
43 |
44 | !-------------------------------------------!
45 | ! Read all datas !
46 | !-------------------------------------------!
47 | gdatfile = trim(path)//'/Global.in'
48 | clpropfile = trim(path)//'/CLProperties.in'
49 | volafile = trim(path)//'/Volumesareas.in'
50 | SrFile = trim(outpath)//'/Sr.out'
51 | QwFile = trim(outpath)//'/Qw.out'
52 | cnodefile = trim(path)//'/Cellnodes.in'
53 |
54 | print*,' Read all the Datas'
55 | OPEN(FILE_GDATA, FILE=gdatfile, FORM='UNFORMATTED')
56 | OPEN(FILE_CLPRO, FILE=clpropfile, FORM='UNFORMATTED')
57 | OPEN(FILE_VOLA, FILE=volafile, FORM='UNFORMATTED')
58 | OPEN(FILE_Sr, FILE=SrFile, FORM='UNFORMATTED')
59 | OPEN(FILE_Qw, FILE=QwFile, FORM='UNFORMATTED')
60 | OPEN(FILE_CLNOD, FILE=cnodefile , FORM='UNFORMATTED')
61 |
62 | READ(FILE_GDATA) ntcells,ntnodes,ntfaces,ntfacesmax,ndirs
63 | print*,' - Global.in'
64 | ! Search the number of patch
65 | ALLOCATE(patch(ntcells,ntfacesmax))
66 | num_patch =0
67 | num_patchmax = 0
68 |
69 | ALLOCATE(cnodes(ntcells))
70 | ALLOCATE(cnnode(MAX_NNODES_CELL,ntcells))
71 |
72 | DO icell=1,ntcells
73 | READ(FILE_CLPRO) i,nfaces,(temp,patch(i,l),l=1,nfaces)
74 | READ(FILE_CLNOD) i, cnodes(icell), &
75 | & (cnnode(j,icell),j=1,cnodes(icell))
76 | ENDDO
77 |
78 | num_patchmax = maxval(patch)
79 | print*,' - CLProperties.in'
80 | rewind(FILE_CLPRO)
81 |
82 | ALLOCATE(Sr_node(ntnodes))
83 | DO i=1, ntnodes
84 | READ(FILE_Sr) icell,Sr_node(icell)
85 | ENDDO
86 |
87 | ALLOCATE(Sr(ntcells))
88 | Sr = 0
89 |
90 | DO i=1,ntcells
91 | DO inode=1,cnodes(i)
92 | k = cnnode(inode,i)
93 | Sr(i) = Sr(i) + Sr_node(k)
94 | ENDDO
95 | Sr(i) = Sr(i)/ real(cnodes(i))
96 | ENDDO
97 | print*,' - Sr.out'
98 |
99 | ALLOCATE(QwTot(num_patchmax+1)) ! Last row is the sum of the array
100 | ALLOCATE(Surface(num_patchmax+1)) ! Last row is the sum of the array
101 | ALLOCATE(Surf(ntcells,ntfacesmax))
102 | ALLOCATE(Qw(ntcells,ntfacesmax))
103 | ALLOCATE(Volume(ntcells))
104 | QwTot = 0
105 | Qw = 0
106 | Surface = 0
107 |
108 | do i=1,ntcells
109 | READ(FILE_VOLA) icell,nfaces,Volume(icell),(Surf(icell,nface) &
110 | & ,nface=1,nfaces)
111 |
112 | do j=1,nfaces
113 | if (patch(i,j) .eq. 0) cycle ! If not a BC, skip these step
114 | READ(FILE_Qw) nface,icell,Qw(icell,nface)
115 | enddo
116 | enddo
117 | print*,' - Qw.out'
118 |
119 | !-------------------------------------------!
120 | ! Summation of Qw over patchs !
121 | !-------------------------------------------!
122 | SumSr=0
123 | VolumeTot=0
124 | QwTot =0
125 | Surface=0
126 | print*,' Makes the summation over all patches'
127 | do icell=1,ntcells
128 | SumSr = SumSr + Sr(icell)*Volume(icell)
129 | VolumeTot = VolumeTot +Volume(icell)
130 | do nface=1,nfaces
131 | if (patch(icell,nface) .eq. 0) cycle ! If not a BC, skip these step
132 | num_patch = patch(icell,nface)
133 | QwTot(num_patch) = Qwtot(num_patch) + Qw(icell,nface)* &
134 | & Surf(icell,nface)
135 | Surface(num_patch) = Surface(num_patch) + Surf(icell,nface)
136 | enddo
137 | enddo
138 |
139 | FMT= "(A20,ES14.4)"
140 | do i=1,num_patchmax
141 | WRITE(*,*) " -------------"
142 | WRITE(*,*) " Patch number :",i
143 | WRITE(*,FMT) " *-> Surface = ", Surface(i)
144 | WRITE(*,FMT) " *-> QwTot*Surface = ", QwTot(i)
145 | Qwtot(num_patchmax+1) = QwTot(num_patchmax+1) +Qwtot(i)
146 | Surface(num_patchmax+1) = Surface(num_patchmax+1) +Surface(i)
147 | enddo
148 |
149 | WRITE(*,*) " "
150 | WRITE(*,*) " ---------------------------------------"
151 | WRITE(*,FMT) " *-> Sum of all Qw*S =", QwTot(num_patchmax+1)
152 | WRITE(*,*) " -------------"
153 | WRITE(*,FMT) " *-> SumSr = ", SumSr
154 | WRITE(*,*) " -------------"
155 | WRITE(*,FMT) " *-> Diff = ", abs(QwTot(num_patchmax+1)-SumSr)
156 | WRITE(*,*) " -------------"
157 |
158 | CLOSE(FILE_GDATA)
159 | CLOSE(FILE_VOLA)
160 | CLOSE(FILE_Sr)
161 | CLOSE(FILE_Qw)
162 |
163 | END PROGRAM Balance_flux
Balance_flux.F could be called by: