23 (coreprof_in, toroidfield_in, equilibrium_in, &
45 USE deallocate_structures
51 TYPE (type_equilibrium
),
POINTER :: equilibrium_in(:)
52 TYPE (type_equilibrium
),
POINTER :: equilibrium_out(:)
53 TYPE (type_toroidfield
),
POINTER :: toroidfield_in(:)
54 TYPE (type_coreprof
),
POINTER :: coreprof_in(:)
67 REAL (R8),
ALLOCATABLE ::
pressure(:)
68 REAL (R8),
DIMENSION (:),
POINTER :: rho_tor, psi, rho_vol
70 REAL (R8),
ALLOCATABLE :: j_edge_mask(:)
71 REAL (R8) :: j_edge_pos, j_edge_pow
72 CHARACTER*3 :: char1, char2
73 CHARACTER*1000 :: output_diag
75 real (R8),
allocatable,
dimension(:):: psi_tmp,q_tmp,jtot_tmp,jphi_tmp
80 diag%ERROR_MESSAGE =
" "
85 nrho =
SIZE (coreprof_in(1)%rho_tor, dim=1)
86 nion =
SIZE (coreprof_in(1)%ni%value, dim=2)
87 neq =
SIZE (equilibrium_in(1)%profiles_1d%psi, dim=1)
92 IF (
ASSOCIATED(equilibrium_out)) &
93 CALL deallocate_cpo(equilibrium_out)
94 ALLOCATE (equilibrium_out(1))
95 CALL copy_cpo(equilibrium_in(1), equilibrium_out(1))
97 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%rho_tor))
ALLOCATE(equilibrium_out(1)%profiles_1d%rho_tor(neq))
98 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%rho_vol))
ALLOCATE(equilibrium_out(1)%profiles_1d%rho_vol(neq))
99 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%psi))
ALLOCATE(equilibrium_out(1)%profiles_1d%psi(neq))
100 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%q))
ALLOCATE(equilibrium_out(1)%profiles_1d%q(neq))
101 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%jphi))
ALLOCATE(equilibrium_out(1)%profiles_1d%jphi(neq))
102 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%jparallel))
ALLOCATE(equilibrium_out(1)%profiles_1d%jparallel(neq))
103 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%pressure))
ALLOCATE(equilibrium_out(1)%profiles_1d%pressure(neq))
104 IF (.NOT.
ASSOCIATED(equilibrium_out(1)%profiles_1d%phi))
ALLOCATE(equilibrium_out(1)%profiles_1d%phi(neq))
109 ALLOCATE(j_edge_mask(neq))
114 j_edge_mask = exp(-(j_edge_pos/(1.0_r8+1.0e-12_r8-equilibrium_in(1)%profiles_1d%rho_tor/equilibrium_in(1)%profiles_1d%rho_tor(neq)))**j_edge_pow)
119 equilibrium_out(1)%profiles_1d%rho_tor = equilibrium_in(1)%profiles_1d%rho_tor
121 IF (coreprof_in(1)%rho_tor(nrho).LT.equilibrium_in(1)%profiles_1d%rho_tor(neq)) &
122 coreprof_in(1)%rho_tor(nrho) = equilibrium_in(1)%profiles_1d%rho_tor(neq)
124 IF (
ASSOCIATED(equilibrium_in(1)%profiles_1d%rho_vol ))
THEN
125 equilibrium_out(1)%profiles_1d%rho_vol = equilibrium_in(1)%profiles_1d%rho_vol
126 ELSE IF (
ASSOCIATED( equilibrium_in(1)%profiles_1d%volume))
THEN
127 equilibrium_out(1)%profiles_1d%rho_vol = sqrt(equilibrium_in(1)%profiles_1d%volume &
128 /equilibrium_in(1)%profiles_1d%volume(neq))
129 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"No rho_vol supplied; calculated from volume "
130 diag%IERR = diag%IERR + 1
132 equilibrium_out(1)%profiles_1d%rho_vol = itm_invalid_float
133 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"No rho_vol supplied; set to itm_unvalid "
134 diag%IERR = diag%IERR + 1
138 IF (
ASSOCIATED (coreprof_in(1)%psi%value))
THEN
140 if (any(coreprof_in(1)%psi%value.ne. 0.0)) noll_cond=0
143 IF (noll_cond.eq.0)
THEN
144 CALL
l3interp(coreprof_in(1)%psi%value, coreprof_in(1)%rho_tor, nrho, &
145 equilibrium_out(1)%profiles_1d%psi, equilibrium_out(1)%profiles_1d%rho_tor, neq)
146 else if (
associated(equilibrium_in(1)%profiles_1d%psi))
then
147 allocate(psi_tmp(nrho))
148 call
l3interp(equilibrium_in(1)%profiles_1d%psi,equilibrium_in(1)%profiles_1d%rho_tor,neq, &
149 psi_tmp,coreprof_in(1)%rho_tor,nrho)
150 call
l3interp(psi_tmp,coreprof_in(1)%rho_tor,nrho, &
151 equilibrium_out(1)%profiles_1d%psi,equilibrium_out(1)%profiles_1d%rho_tor,neq)
153 equilibrium_out(1)%profiles_1d%psi = 0.0_r8
154 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"No Psi supplied; "
155 diag%IERR = diag%IERR + 1
158 equilibrium_out(1)%global_param%psi_ax = equilibrium_out(1)%profiles_1d%psi(1)
159 equilibrium_out(1)%global_param%psi_bound = equilibrium_out(1)%profiles_1d%psi(neq)
162 IF (
ASSOCIATED (coreprof_in(1)%profiles1d%q%value))
THEN
164 if (any(coreprof_in(1)%profiles1d%q%value.ne. 0.0)) noll_cond=0
167 IF (noll_cond.eq.0)
THEN
168 CALL
l3interp(coreprof_in(1)%profiles1d%q%value, coreprof_in(1)%rho_tor, nrho, &
169 equilibrium_out(1)%profiles_1d%q, equilibrium_out(1)%profiles_1d%rho_tor, neq)
170 else if (
associated(equilibrium_in(1)%profiles_1d%q))
then
171 allocate(q_tmp(nrho))
172 call
l3interp(equilibrium_in(1)%profiles_1d%q,equilibrium_in(1)%profiles_1d%rho_tor,neq, &
173 q_tmp,coreprof_in(1)%rho_tor,nrho)
174 call
l3interp(q_tmp,coreprof_in(1)%rho_tor,nrho, &
175 equilibrium_out(1)%profiles_1d%q,equilibrium_out(1)%profiles_1d%rho_tor,neq)
177 equilibrium_out(1)%profiles_1d%q = 0.0_r8
178 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"No q supplied; "
179 diag%IERR = diag%IERR + 1
183 IF (
ASSOCIATED (coreprof_in(1)%profiles1d%jtot%value))
THEN
185 if (any(coreprof_in(1)%profiles1d%jtot%value.ne. 0.0)) noll_cond=0
188 IF (noll_cond.eq.0)
THEN
189 CALL
l3interp(coreprof_in(1)%profiles1d%jtot%value, coreprof_in(1)%rho_tor, nrho, &
190 equilibrium_out(1)%profiles_1d%jparallel,equilibrium_out(1)%profiles_1d%rho_tor, neq)
191 else if (
associated(equilibrium_in(1)%profiles_1d%jparallel))
then
192 allocate(jtot_tmp(nrho))
193 call
l3interp(equilibrium_in(1)%profiles_1d%jparallel,equilibrium_in(1)%profiles_1d%rho_tor,neq, &
194 jtot_tmp,coreprof_in(1)%rho_tor,nrho)
195 call
l3interp(jtot_tmp,coreprof_in(1)%rho_tor,nrho, &
196 equilibrium_out(1)%profiles_1d%jparallel,equilibrium_out(1)%profiles_1d%rho_tor,neq)
204 equilibrium_out(1)%profiles_1d%jparallel = 0.0_r8
205 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"No Jpar supplied; "
206 diag%IERR = diag%IERR + 1
211 IF (
ASSOCIATED (coreprof_in(1)%profiles1d%jphi%value))
THEN
213 if (any(coreprof_in(1)%profiles1d%jphi%value.ne. 0.0)) noll_cond=0
216 IF (noll_cond.eq.0)
THEN
217 CALL
l3interp(coreprof_in(1)%profiles1d%jphi%value, coreprof_in(1)%rho_tor, nrho, &
218 equilibrium_out(1)%profiles_1d%jphi,equilibrium_out(1)%profiles_1d%rho_tor, neq)
219 else if (
associated(equilibrium_in(1)%profiles_1d%jphi))
then
220 allocate(jphi_tmp(nrho))
221 call
l3interp(equilibrium_in(1)%profiles_1d%jphi,equilibrium_in(1)%profiles_1d%rho_tor,neq, &
222 jphi_tmp,coreprof_in(1)%rho_tor,nrho)
223 call
l3interp(jphi_tmp,coreprof_in(1)%rho_tor,nrho, &
224 equilibrium_out(1)%profiles_1d%jphi,equilibrium_out(1)%profiles_1d%rho_tor,neq)
232 equilibrium_out(1)%profiles_1d%jphi = 0.0_r8
233 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"No jphi supplied; "
234 diag%IERR = diag%IERR + 1
241 IF(
ASSOCIATED (coreprof_in(1)%profiles1d%pr_perp%value))
THEN
242 CALL
l3interp(coreprof_in(1)%profiles1d%pr_perp%value, coreprof_in(1)%rho_tor, nrho, &
243 equilibrium_out(1)%profiles_1d%pressure, equilibrium_out(1)%profiles_1d%rho_tor, neq)
245 pressure = coreprof_in(1)%ne%value * coreprof_in(1)%te%value * itm_ev
247 rho_loop1:
DO irho=1,nrho
248 ion_loop1:
DO iion=1,nion
250 coreprof_in(1)%ni%value(irho,iion) * coreprof_in(1)%ti%value(irho,iion) * itm_ev
255 equilibrium_out(1)%profiles_1d%pressure, equilibrium_out(1)%profiles_1d%rho_tor, neq)
256 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"Total perpendicular pressure not found in coreprof%profiles1d%pr_perp. Pressure calculated from thermal profiles (fast ion pressure is not included); "
257 diag%IERR = diag%IERR + 1
266 rho_tor => equilibrium_out(1)%profiles_1d%rho_tor
267 psi => equilibrium_out(1)%profiles_1d%psi
269 IF(psi(1) .LT. psi(neq))
THEN
271 ELSE IF(psi(1) .GT. psi(neq))
THEN
274 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"PSI end points equal; "
279 DO WHILE(ieq .LT. neq)
280 IF(psi(ieq)*sign .LT. psi(ieq+1)*sign)
THEN
284 IF(ieq1 .LT. neq)
THEN
285 DO WHILE(ieq1 .LT. neq .AND. &
286 psi(ieq)*sign .GE. psi(ieq1)*sign)
290 IF(ieq1 .LT. neq)
THEN
291 WRITE (char1,
'(i3)') ieq
292 WRITE (char2,
'(i3)') ieq1
293 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"fixed problem in PSI between "//trim(char1)//
" and"//trim(char2)//
"; "
294 diag%IERR = diag%IERR + 1
295 DO ieq2 = ieq+1, ieq1-1
296 psi(ieq2) = psi(ieq) + &
297 (rho_tor(ieq2) - rho_tor(ieq))/(rho_tor(ieq1) - rho_tor(ieq)) * &
298 (psi(ieq1) - psi(ieq))
303 DO WHILE(ieq1 .GT. 1 .AND. &
304 psi(ieq1)*sign .GE. psi(neq)*sign)
308 WRITE (char1,
'(i3)') ieq
309 WRITE (char2,
'(i3)') neq
310 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"fixed problem in PSI between "//trim(char1)//
" and"//trim(char2)//
"; "
311 diag%IERR = diag%IERR + 1
312 DO ieq2 = ieq1+1, neq-1
313 psi(ieq2) = psi(ieq1) + &
314 (rho_tor(ieq2) - rho_tor(ieq1))/(rho_tor(neq) - rho_tor(ieq1)) * &
315 (psi(neq) - psi(ieq1))
319 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"this should not happen! "
329 rho_tor => equilibrium_out(1)%profiles_1d%rho_tor
330 rho_vol => equilibrium_out(1)%profiles_1d%rho_vol
332 IF(rho_vol(1) .LT. rho_vol(neq))
THEN
334 ELSE IF(rho_vol(1) .GT. rho_vol(neq))
THEN
337 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"RHO_VOL end points equal; "
338 diag%IERR = diag%IERR + 1
341 DO WHILE(ieq .LT. neq)
342 IF(rho_vol(ieq)*sign .LT. rho_vol(ieq+1)*sign)
THEN
346 IF(ieq1 .LT. neq)
THEN
347 DO WHILE(ieq1 .LT. neq .AND. &
348 rho_vol(ieq)*sign .GE. rho_vol(ieq1)*sign)
352 IF(ieq1 .LT. neq)
THEN
353 WRITE (char1,
'(i3)') ieq
354 WRITE (char2,
'(i3)') ieq1
355 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"fixed problem in RHO_VOL between "//trim(char1)//
" and"//trim(char2)//
"; "
356 diag%IERR = diag%IERR + 1
357 DO ieq2 = ieq+1, ieq1-1
358 rho_vol(ieq2) = rho_vol(ieq) + &
359 (rho_tor(ieq2) - rho_tor(ieq))/(rho_tor(ieq1) - rho_tor(ieq)) * &
360 (rho_vol(ieq1) - rho_vol(ieq))
365 DO WHILE(ieq1 .GT. 1 .AND. &
366 rho_vol(ieq1)*sign .GE. rho_vol(neq)*sign)
370 WRITE (char1,
'(i3)') ieq
371 WRITE (char2,
'(i3)') neq
372 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"fixed problem in RHO_VOL between "//trim(char1)//
" and"//trim(char2)//
"; "
373 diag%IERR = diag%IERR + 1
374 DO ieq2 = ieq1+1, neq-1
375 rho_vol(ieq2) = rho_vol(ieq1) + &
376 (rho_tor(ieq2) - rho_tor(ieq1))/(rho_tor(neq) - rho_tor(ieq1)) * &
377 (rho_vol(neq) - rho_vol(ieq1))
381 diag%ERROR_MESSAGE = trim(adjustl(diag%ERROR_MESSAGE))//
"this should not happen! "
391 equilibrium_out(1)%global_param%psi_ax = equilibrium_out(1)%profiles_1d%psi(1)
392 equilibrium_out(1)%global_param%psi_bound = equilibrium_out(1)%profiles_1d%psi(neq)
393 equilibrium_out(1)%global_param%volume = equilibrium_out(1)%profiles_1d%volume(neq)
397 IF(
ALLOCATED(j_edge_mask))
DEALLOCATE(j_edge_mask)
400 112 output_diag =
"EQUILIBRIUM_INPUT: "//trim(adjustl(diag%ERROR_MESSAGE))
401 nline = floor(len_trim(adjustl(output_diag))/132.001)+1
402 IF(
ASSOCIATED(equilibrium_out(1)%codeparam%codename)) &
403 DEALLOCATE(equilibrium_out(1)%codeparam%codename)
404 IF(
ASSOCIATED(equilibrium_out(1)%codeparam%codeversion)) &
405 DEALLOCATE(equilibrium_out(1)%codeparam%codeversion)
406 IF(
ASSOCIATED(equilibrium_out(1)%codeparam%output_diag)) &
407 DEALLOCATE(equilibrium_out(1)%codeparam%output_diag)
408 ALLOCATE (equilibrium_out(1)%codeparam%codename(1))
409 ALLOCATE (equilibrium_out(1)%codeparam%codeversion(1))
410 ALLOCATE (equilibrium_out(1)%codeparam%output_diag(nline))
412 equilibrium_out(1)%codeparam%codename =
'EQILIBRIUM_INPUT'
413 equilibrium_out(1)%codeparam%codeversion =
'EQILIBRIUM_INPUT_4.10b.10'
414 equilibrium_out(1)%codeparam%output_flag = diag%IERR
416 equilibrium_out(1)%codeparam%output_diag(i) = output_diag(((i-1)*132+1):(i*132))
420 if(
allocated(psi_tmp))
deallocate(psi_tmp)
421 if(
allocated(q_tmp))
deallocate(q_tmp)
422 if(
allocated(jtot_tmp))
deallocate(jtot_tmp)
423 if(
allocated(jphi_tmp))
deallocate(jphi_tmp)
441 (equilibrium_in, coreprof_out)
462 TYPE (type_equilibrium
),
POINTER :: equilibrium_in(:)
463 TYPE (type_coreprof
),
POINTER :: coreprof_out(:)
476 neq =
SIZE (equilibrium_in(1)%profiles_1d%rho_tor, dim=1)
477 nrho =
SIZE (coreprof_out(1)%rho_tor, dim=1)
486 CALL
l3interp(equilibrium_in(1)%profiles_1d%q, &
487 equilibrium_in(1)%profiles_1d%rho_tor / equilibrium_in(1)%profiles_1d%rho_tor(neq), &
489 coreprof_out(1)%profiles1d%q%value, &
490 coreprof_out(1)%rho_tor / coreprof_out(1)%rho_tor(nrho), &
subroutine l3interp(y_in, x_in, nr_in, y_out, x_out, nr_out)
The module declares types of variables used in ETS (transport code)
real(r8) function pressure(flux)