-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_construction_R.f90
281 lines (266 loc) · 8.03 KB
/
grid_construction_R.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
! ===================================================================
!
! Grid_construction_Right
!
! ===================================================================
!
! Region Right (R):
!
! From the Triple Point specific internal energy in the vapour region
! up to the specific internal energy value referred to the maximum point
! on the saturation curve.
! Bounded by the saturated vapour curve and the minimum pressure line
!
! note: 23/11/2017 equidistance on vvv_R for derivatives
! ===================================================================
SUBROUTINE grid_construction_right()
USE def_constants
USE def_variables
USE non_linear_solvers
USE properties
USE grid_functions
!
IMPLICIT NONE
!
INTEGER :: i, j, Niter, exitflag
INTEGER, DIMENSION (NNN_R,MMM_R) :: res_R
!
REAL(pr) :: u_min, res, delta, T_guess,v_guess, vliq,vliq_guess,&
& sound, press, temp, out_2,in_2
!
REAL(pr), DIMENSION (NNN_sat_R) :: T_sat_sat, T_pmin, res_sp
REAL(pr), DIMENSION (NNN_R,MMM_R) :: vvv_log
REAL(pr), DIMENsION (NNN_R) :: v_max, v_min
!
! data used for bicubic interpolation
!
!REAL(pr) :: v1, v2, v3, v4, u1, u2, u3, u4
!REAL(pr) :: F1, F2, F3, F4, G1, G2, G3, G4
!REAL(pr) :: a1, a2, a3, a4, b1, b2, b3, b4
!REAL(pr) :: dF1v, dF2v, dF3v, dF4v, dF1u, dF2u, dF3u, dF4u, dF1vu, dF2vu,dF3vu, dF4vu
!REAL(pr) :: dF1vv, dF2vv, dF3vv, dF4vv, dF1uu, dF2uu, dF3uu, dF4uu
!REAL(pr) :: dF1x, dF2x, dF3x, dF4x, dF1y, dF2y, dF3y, dF4y, dF1xy, dF2xy,dF3xy, dF4xy
!REAL(pr), DIMENSION (4, 4) :: A_bicub, C_bicub
!
!--------------------------------------------------
!
!1) DEFINITION OF ARRAY u:
!
!--------------------------------------------------
!
u_min = e_tri_R
!
! arrays x_mesh_R, y_mesh_R
!
delta = (e_umax - u_min)/(NNN_R-1)
y_mesh_R = u_min + (/(i*delta, i=0,NNN_R-1)/)
delta = (x_mesh_max - x_mesh_min)/(MMM_R-1)
x_mesh_R = x_mesh_min + (/(i*delta, i=0,MMM_R-1)/)
!
! array y_mesh_sat_R
!
delta = (e_umax - u_min)/(NNN_sat_R-1)
y_mesh_sat_R = u_min + (/(i*delta, i=0,NNN_sat_R-1)/)
!
!-----------------------------------------------------------------------
!
!2) EVALUATION OF v_max(u) AND v_min(u) FOR EACH ELEMENT OF THE ARRAY u:
!
! Since the vapour part is now analyzed, v_max(u) is referred to points
! corresponding to the p_min curve, while v_min(u) is referred to points
! associated to the saturated vapour line.vmax(1,1) = vmin(1,1)
!
!-----------------------------------------------------------------------
!
!-----------------vmax(pmin = p_tri)-----------------------------------
vvv_R(1,:) = v_tri_R
TTT_R(1,:) = T_tri
ppp_R(1,:) = p_tri
ppp_R(:,MMM_R) = p_tri
ccc_R(1,:) = c_tri_R
!
T_guess = T_tri
v_guess = v_tri_R
!
DO i=2,NNN_R
!
CALL New_Rap2D(2, TTT_R(i,MMM_R), vvv_R(i,MMM_R), &
& res, Niter, exitflag, ppp_R(i,MMM_R), y_mesh_R(i),&
& T_guess, v_guess)
!
CALL sound_speed(TTT_R(i,MMM_R),vvv_R(i,MMM_R), sound)
ccc_R(i,MMM_R) = sound
!
IF (res > res_ref) THEN
print*, "right_R", res, i ,"flag",exitflag
STOP
ENDIF
T_guess = TTT_R(i,MMM_R)
v_guess = vvv_R(i,MMM_R)
! print*, "v_left", vvv_LL(i,1)
END DO
!---------------------------------------------------------------------------
!---------------vmin(saturation line from triple point to umax)-----------
!
v_guess = v_tri_R
T_guess = T_tri
vliq_guess = v_tri_L
!
DO i=2, NNN_R-1
!
CALL New_Rap3D(4,vliq,vvv_R(i,1),TTT_R(i,1),&
& res, Niter, exitflag, y_mesh_R(i),in_2,&
& vliq_guess, v_guess,T_guess)
!
CALL pressure(TTT_R(i,1),vvv_R(i,1),press)
ppp_R(i,1) = press
!
CALL sound_speed(TTT_R(i,1),vvv_R(i,1), sound)
ccc_R(i,1) = sound
!
IF (res > res_ref) THEN
print*, "left R", res,i, "iter", Niter
STOP
ENDIF
!
v_guess = vvv_R(i,1)
T_guess = TTT_R(i,1)
vliq_guess = vliq
END DO
vvv_R(NNN_R,1) = v_umax
ppp_R(NNN_R,1) = p_umax
TTT_R(NNN_R,1) = T_umax
ccc_R(NNN_R,1) = c_umax
!--------------------------------------------------------------------------
!------------vmin < v < vmax ---------------------------------------------
!
DO i = 2,NNN_R
DO j = 2,MMM_R - 1
! vvv_log(i,j) = ((x_mesh_R(j) - x_mesh_min)/(x_mesh_max - x_mesh_min))*&
! & (LOG10(vvv_R(i,MMM_R))-LOG10(vvv_R(i,1)))+ LOG10(vvv_R(i,1))
! vvv_R(i,j) = 10_pr **vvv_log(i,j)
vvv_R(i,j) = ((x_mesh_R(j) - x_mesh_min)/(x_mesh_max - x_mesh_min))*&
& (vvv_R(i,MMM_R)-vvv_R(i,1))+ vvv_R(i,1)
IF (vvv_R(i,j) .GT. vvv_R(i,MMM_R)) THEN
print*, vvv_R(i,1),vvv_R(i,MMM_R), x_mesh_R(j)
print*, ''
print*, vvv_R(i,j), i, j
print*, LOG10(vvv_R(i,1)), LOG10(vvv_R(i,MMM_R))
stop
ENDIF
ENDDO
ENDDO
!
! ppp_R, TTT_R, ccc_R
!
T_guess = T_tri
!
DO j=2,MMM_R-1
DO i=2, NNN_R
!
CALL New_Rap1D(1, temp, out_2, res, Niter,&
& exitflag, y_mesh_R(i), T_guess,&
& vvv_R(i,j), out_2)
!
TTT_R(i,j) = temp
!
!
CALL pressure(TTT_R(i,j),vvv_R(i,j),press)
ppp_R(i,j) = press
!
CALL sound_speed(TTT_R(i,j),vvv_R(i,j), sound)
ccc_R(i,j) = sound
!
IF (res > res_ref) THEN
print*, "middle R", res, i,j, "iter", Niter
STOP
ENDIF
!
T_guess = temp
END DO
END DO
!
!
!
!
! grid for Cp
!
DO j = 1,MMM_R
DO i = 1, NNN_R
CALL heat_cap_p(TTT_R(i,j),vvv_R(i,j),cpcp_R(i,j))
!
IF ( (cpcp_R(i,j) /= cpcp_R(i,j)) .OR. (cpcp_R(i,j) <= 0.0) .OR.&
& (cpcp_R(i,j) > cp_cr ) ) THEN
print*,'cp no values in R (kJ/kgK)', cpcp_R(i,j)/1000.0,i,j
cpcp_R(i,j) = cp_cr
ENDIF
!
ENDDO
ENDDO
!
!
!----------------------------------------------------------------
!
! MESH CONSTRUCTION for spline coefficients
!------------------------------------------------------------
!
v_Vsat(1) = v_tri_R
v_Vsat(NNN_sat_R) = v_umax
v_Vpmin(1) = v_tri_R
!Pmin line(right boundary)
!
T_guess = T_tri
v_guess = v_tri_R
!
DO i = 2, NNN_sat_R
!
CALL New_Rap2D(2, T_pmin(i), v_Vpmin(i), &
& res_sp(i), Niter, exitflag, p_tri, y_mesh_sat_R(i),&
& T_guess, v_guess)
!
T_guess = T_pmin(i)
v_guess = v_Vpmin(i)
!
IF (res_sp(i) > res_ref) THEN
print*,'R-Convergence failed calculating v_Vpmin(',i,')'
print*,'resnorm = ',res_sp(i),'N_iter_New = ',Niter
ENDIF
ENDDO
!
!v_Vsat(NNN_sat_R) = v_Vsat(NNN_sat_R-1) ! near the maximum on the saturation curve
!
! saturation line
v_guess = v_tri_R
T_guess = T_tri
vliq_guess = v_tri_L
!
DO i=2, NNN_sat_R-1
!
CALL New_Rap3D(4,vliq,v_Vsat(i),T_sat_sat(i),&
& res_sp(i), Niter, exitflag, y_mesh_sat_R(i),in_2,&
& vliq_guess, v_guess,T_guess)
!
IF (res_sp(i) > res_ref) THEN
print*, 'R-Convergence failed calculating v_Vsat(',i,')'
print*,'resnorm = ',res_sp(i),'N_iter_New = ',Niter
ENDIF
!
v_guess = v_Vsat(i)
T_guess = T_sat_sat(i)
vliq_guess = vliq
END DO
!
! construction of spline coefficients associated to saturation curve nodes and
! pmin curve nodes
!
DO i = 1, NNN_R-1
j = 3 * (i-1) + 1
call polyfit(spline_Vsat(:,i), y_mesh_sat_R(j:j+3), v_Vsat (j:j+3),ord_spline)
call polyfit(spline_pmin(:,i), y_mesh_sat_R(j:j+3), v_Vpmin(j:j+3),ord_spline)
ENDDO
!print*,'------------------------------------------------------'
print*, 'R GRID FINISH'
!print*,'------------------------------------------------------'
!
!
END SUBROUTINE grid_construction_right