18 SUBROUTINE emeq_e3m (EQUILIBRIUM_IN, EQUILIBRIUM_OUT, code_parameters)
38 USE deallocate_structures
46 TYPE (type_equilibrium
),
POINTER :: equilibrium_in(:)
47 TYPE (type_equilibrium
),
POINTER :: equilibrium_out(:)
48 TYPE (type_param
) :: code_parameters
49 INTEGER :: return_status
54 INTEGER :: ndim1, ndim2
55 INTEGER :: idim1, idim2
56 INTEGER :: max_npoints
57 INTEGER :: ipsi, itheta
76 REAL (R8),
ALLOCATABLE :: rho(:)
77 REAL (R8),
ALLOCATABLE :: jpar(:), intjpar(:)
78 REAL (R8),
ALLOCATABLE :: qsf(:)
79 REAL (R8),
ALLOCATABLE :: pr(:)
80 REAL (R8),
ALLOCATABLE :: psi(:)
82 REAL (R8),
ALLOCATABLE :: b2b02(:)
83 REAL (R8),
ALLOCATABLE :: g1(:), g2(:), g3(:)
84 REAL (R8),
ALLOCATABLE :: g4(:), g5(:), g6(:)
85 REAL (R8),
ALLOCATABLE :: g7(:)
86 REAL (R8),
ALLOCATABLE ::
fdia(:)
87 REAL (R8),
ALLOCATABLE :: vol(:), vprime(:), vprime_psi(:)
88 REAL (R8),
ALLOCATABLE :: triang(:)
89 REAL (R8),
ALLOCATABLE :: area(:), areaprime(:)
90 REAL (R8),
ALLOCATABLE :: elong(:), shafr_shift(:)
91 REAL (R8),
ALLOCATABLE :: pprime(:), ffprime(:)
93 REAL (R8),
ALLOCATABLE :: amid(:)
94 REAL (R8),
ALLOCATABLE ::
fun(:)
98 REAL (R8),
ALLOCATABLE :: amid_2d(:), rho_2d(:)
99 REAL (R8),
ALLOCATABLE :: psi_2d(:), jpar_2d(:), pr_2d(:)
100 REAL (R8),
ALLOCATABLE :: shafr_shift_2d(:)
101 REAL (R8),
ALLOCATABLE :: elong_2d(:), triang_l2d(:), triang_u2d(:)
104 REAL (R8),
SAVE :: aceqlb
105 REAL (R8),
SAVE :: convergence
106 INTEGER,
SAVE :: itermax
109 LOGICAL,
SAVE :: first=.true.
111 REAL (R8) :: s_ip, s_bt, s_q, s_psi, s_jpar
120 convergence = 1.0e-4_r8
124 IF(
ASSOCIATED(equilibrium_in))
THEN
125 IF(
ASSOCIATED(equilibrium_in(1)%profiles_1d%psi))
THEN
126 neq=
SIZE(equilibrium_in(1)%profiles_1d%psi)
127 WRITE(*,*)
'Initial NEQ set to ',neq,
' based on input equilibrium size of PSI'
128 ELSEIF(
ASSOCIATED(equilibrium_in(1)%profiles_1d%rho_vol))
THEN
129 neq=
SIZE(equilibrium_in(1)%profiles_1d%rho_vol)
130 WRITE(*,*)
'Initial NEQ set to ',neq,
' based on input equilibrium size of RHO_VOL'
131 ELSEIF(
ASSOCIATED(equilibrium_in(1)%profiles_1d%rho_tor))
THEN
132 neq=
SIZE(equilibrium_in(1)%profiles_1d%rho_tor)
133 WRITE(*,*)
'Initial NEQ set to ',neq,
' based on input equilibrium size of RHO_TOR'
136 WRITE(*,*)
'Initial NEQ set to ',neq
140 WRITE(*,*)
'Initial NEQ set to ',neq
143 IF (.NOT.
ASSOCIATED(code_parameters%parameters))
THEN
144 WRITE(6, *)
'ERROR: code parameters not associated!'
147 IF (.NOT.
ASSOCIATED(equilibrium_in(1)%codeparam%parameters)) &
148 ALLOCATE(equilibrium_in(1)%codeparam%parameters(
SIZE(code_parameters%parameters)))
149 call deallocate_cpo(equilibrium_in(1)%codeparam%parameters)
150 CALL copy_cpo(code_parameters%parameters, equilibrium_in(1)%codeparam%parameters)
154 WRITE(*,*)
'Final NEQ set to ',neq
156 IF (return_status /= 0)
THEN
157 WRITE(*,*)
'ERROR: Could not assign EMEQ parameters.'
170 npsi =
SIZE (equilibrium_in(1)%profiles_1d%rho_tor, dim=1)
171 ndim1 =
SIZE (equilibrium_in(1)%coord_sys%position%R, dim=1)
172 ndim2 =
SIZE (equilibrium_in(1)%coord_sys%position%R, dim=2)
173 max_npoints =
SIZE (equilibrium_in(1)%eqgeometry%boundary(1)%r, dim=1)
175 s_ip = sign(1.0_r8, equilibrium_in(1)%global_param%i_plasma)
176 s_bt = sign(1.0_r8, equilibrium_in(1)%global_param%toroid_field%b0)
181 write(*,*)
's_ip, s_bt, s_q, s_psi, s_jpar = ', s_ip, s_bt, s_q, s_psi, s_jpar
184 ALLOCATE (jpar(npsi))
185 ALLOCATE (intjpar(npsi))
189 ALLOCATE (b2b02(npsi))
197 ALLOCATE (
fdia(npsi))
199 ALLOCATE (vprime(npsi))
200 ALLOCATE (vprime_psi(npsi))
201 ALLOCATE (area(npsi))
202 ALLOCATE (areaprime(npsi))
203 ALLOCATE (amid(npsi))
204 ALLOCATE (shafr_shift(npsi))
205 ALLOCATE (elong(npsi))
206 ALLOCATE (triang(npsi))
207 ALLOCATE (pprime(npsi))
208 ALLOCATE (ffprime(npsi))
211 ALLOCATE (amid_2d(ndim1))
212 ALLOCATE (rho_2d(ndim1))
213 ALLOCATE (elong_2d(ndim1))
214 ALLOCATE (triang_l2d(ndim1))
215 ALLOCATE (triang_u2d(ndim1))
216 ALLOCATE (shafr_shift_2d(ndim1))
217 ALLOCATE (psi_2d(ndim1))
218 ALLOCATE (jpar_2d(ndim1))
219 ALLOCATE (pr_2d(ndim1))
223 r0 = equilibrium_in(1)%global_param%toroid_field%r0
224 b0 = equilibrium_in(1)%global_param%toroid_field%b0 * s_bt
226 rgeo = equilibrium_in(1)%eqgeometry%geom_axis%r
227 zgeo = equilibrium_in(1)%eqgeometry%geom_axis%z
228 bgeo = r0 * b0 / rgeo
230 rmag = equilibrium_in(1)%global_param%mag_axis%position%r
231 bmag = equilibrium_in(1)%global_param%mag_axis%bphi
233 amin = equilibrium_in(1)%eqgeometry%a_minor
236 el = equilibrium_in(1)%eqgeometry%elongation
237 tr = (equilibrium_in(1)%eqgeometry%tria_upper + equilibrium_in(1)%eqgeometry%tria_lower) / 2.0_r8
238 amin = equilibrium_in(1)%eqgeometry%a_minor
240 rho = equilibrium_in(1)%profiles_1d%rho_tor
241 jpar = equilibrium_in(1)%profiles_1d%jparallel * s_ip
242 qsf = equilibrium_in(1)%profiles_1d%q * s_q
243 pr = equilibrium_in(1)%profiles_1d%pressure
244 b2b02 = equilibrium_in(1)%profiles_1d%gm5 / b0**2
245 fdia = equilibrium_in(1)%profiles_1d%F_dia * s_bt / r0 / b0
246 psi = equilibrium_in(1)%profiles_1d%psi * s_psi
248 pc = equilibrium_in(1)%global_param%i_plasma / 1.0e6_r8 * s_ip
251 IF (jpar(ipsi).LT.0.0_r8) jpar(ipsi) = 0.0_r8
254 IF (
ASSOCIATED(equilibrium_in(1)%profiles_1d%r_inboard).AND. &
255 ASSOCIATED(equilibrium_in(1)%profiles_1d%r_outboard))
THEN
256 amid = 0.5_r8 * (equilibrium_in(1)%profiles_1d%r_outboard - equilibrium_in(1)%profiles_1d%r_inboard)
259 amid = rho / sqrt(el)
263 IF (amid(ipsi).LT.amid(ipsi-1))
THEN
264 WRITE(*,*)
'ERROR : AMID is non monotonic.'
265 amid = rho / sqrt(el)
269 IF (amid(npsi).NE.amin)
THEN
270 WRITE(*,*)
'ERROR : AMID(NPSI) is diffrent from AMIN.',amid(npsi),amin
271 amid = amid * amin / amid(npsi)
276 IF (amid(ipsi).LT.amid(ipsi-1))
THEN
277 WRITE(*,*)
'ERROR : AMID is non monotonic.'
278 amid = rho / sqrt(el)
282 IF (amid(npsi).NE.amin)
THEN
283 WRITE(*,*)
'ERROR : AMID(NPSI) is diffrent from AMIN.',amid(npsi),amin
284 amid = amid * amin / amid(npsi)
342 WRITE(*,*)
'Allocating EQUILIBRIUM_OUT'
343 ALLOCATE(equilibrium_out(1))
350 CALL
l3deriv(vol, psi, neq, vprime_psi, psi, neq)
352 WRITE(*,*)
'VOL(1) = ',vol(1)
358 call deallocate_cpo(equilibrium_out(1)%eqconstraint)
359 CALL copy_cpo(equilibrium_in(1)%eqconstraint, equilibrium_out(1)%eqconstraint)
363 call deallocate_cpo(equilibrium_out(1)%eqgeometry)
364 CALL copy_cpo(equilibrium_in(1)%eqgeometry, equilibrium_out(1)%eqgeometry)
367 equilibrium_out(1)%eqgeometry%tria_upper = triang(npsi)
368 equilibrium_out(1)%eqgeometry%tria_lower = triang(npsi)
373 call deallocate_cpo(equilibrium_out(1)%global_param)
374 CALL copy_cpo(equilibrium_in(1)%global_param, equilibrium_out(1)%global_param)
377 equilibrium_out(1)%global_param%area = area(npsi)
378 equilibrium_out(1)%global_param%volume = vol(npsi)
379 equilibrium_out(1)%global_param%i_plasma = pc * 1.0e6_r8 * s_ip
380 equilibrium_out(1)%global_param%psi_ax = psi(1) * s_psi
381 equilibrium_out(1)%global_param%psi_bound = psi(npsi) * s_psi
382 equilibrium_out(1)%global_param%mag_axis%position%R = rgeo + shafr_shift(1)
383 equilibrium_out(1)%global_param%mag_axis%position%Z = 0.0_r8
384 equilibrium_out(1)%global_param%mag_axis%bphi =
fdia(1) * r0 * b0 * s_bt / (rgeo + shafr_shift(1))
385 equilibrium_out(1)%global_param%mag_axis%q = qsf(1) * s_q
386 equilibrium_out(1)%global_param%q_min = minval(qsf) * s_q
392 ALLOCATE (equilibrium_out(1)%profiles_1d%psi(npsi))
393 ALLOCATE (equilibrium_out(1)%profiles_1d%phi(npsi))
394 ALLOCATE (equilibrium_out(1)%profiles_1d%pressure(npsi))
395 ALLOCATE (equilibrium_out(1)%profiles_1d%F_dia(npsi))
396 ALLOCATE (equilibrium_out(1)%profiles_1d%pprime(npsi))
397 ALLOCATE (equilibrium_out(1)%profiles_1d%ffprime(npsi))
398 ALLOCATE (equilibrium_out(1)%profiles_1d%jphi(npsi))
399 ALLOCATE (equilibrium_out(1)%profiles_1d%jparallel(npsi))
400 ALLOCATE (equilibrium_out(1)%profiles_1d%q(npsi))
401 ALLOCATE (equilibrium_out(1)%profiles_1d%r_inboard(npsi))
402 ALLOCATE (equilibrium_out(1)%profiles_1d%r_outboard(npsi))
403 ALLOCATE (equilibrium_out(1)%profiles_1d%rho_tor(npsi))
404 ALLOCATE (equilibrium_out(1)%profiles_1d%rho_vol(npsi))
405 ALLOCATE (equilibrium_out(1)%profiles_1d%beta_pol(npsi))
406 ALLOCATE (equilibrium_out(1)%profiles_1d%li(npsi))
407 ALLOCATE (equilibrium_out(1)%profiles_1d%elongation(npsi))
408 ALLOCATE (equilibrium_out(1)%profiles_1d%tria_upper(npsi))
409 ALLOCATE (equilibrium_out(1)%profiles_1d%tria_lower(npsi))
410 ALLOCATE (equilibrium_out(1)%profiles_1d%volume(npsi))
411 ALLOCATE (equilibrium_out(1)%profiles_1d%vprime(npsi))
412 ALLOCATE (equilibrium_out(1)%profiles_1d%area(npsi))
413 ALLOCATE (equilibrium_out(1)%profiles_1d%aprime(npsi))
414 ALLOCATE (equilibrium_out(1)%profiles_1d%surface(npsi))
415 ALLOCATE (equilibrium_out(1)%profiles_1d%ftrap(npsi))
416 ALLOCATE (equilibrium_out(1)%profiles_1d%dpsidrho_tor(npsi))
417 ALLOCATE (equilibrium_out(1)%profiles_1d%dvdrho(npsi))
418 ALLOCATE (equilibrium_out(1)%profiles_1d%b_av(npsi))
420 ALLOCATE (equilibrium_out(1)%profiles_1d%gm1(npsi))
421 ALLOCATE (equilibrium_out(1)%profiles_1d%gm2(npsi))
422 ALLOCATE (equilibrium_out(1)%profiles_1d%gm3(npsi))
423 ALLOCATE (equilibrium_out(1)%profiles_1d%gm4(npsi))
424 ALLOCATE (equilibrium_out(1)%profiles_1d%gm5(npsi))
425 ALLOCATE (equilibrium_out(1)%profiles_1d%gm6(npsi))
426 ALLOCATE (equilibrium_out(1)%profiles_1d%gm7(npsi))
427 ALLOCATE (equilibrium_out(1)%profiles_1d%gm8(npsi))
428 ALLOCATE (equilibrium_out(1)%profiles_1d%gm9(npsi))
431 equilibrium_out(1)%profiles_1d%psi = psi * s_psi
432 equilibrium_out(1)%profiles_1d%rho_tor = rho
433 equilibrium_out(1)%profiles_1d%phi = rho**2 * itm_pi * b0 * s_bt
434 equilibrium_out(1)%profiles_1d%q = qsf * s_q
435 equilibrium_out(1)%profiles_1d%pressure = pr
436 equilibrium_out(1)%profiles_1d%jparallel = jpar * s_ip
437 equilibrium_out(1)%profiles_1d%volume = vol
438 equilibrium_out(1)%profiles_1d%vprime = vprime_psi * s_psi
439 equilibrium_out(1)%profiles_1d%area = area
440 equilibrium_out(1)%profiles_1d%aprime = areaprime
441 equilibrium_out(1)%profiles_1d%F_dia =
fdia * r0 * b0 * s_bt
442 equilibrium_out(1)%profiles_1d%elongation = elong
443 equilibrium_out(1)%profiles_1d%tria_upper = triang
444 equilibrium_out(1)%profiles_1d%tria_lower = triang
445 equilibrium_out(1)%profiles_1d%r_inboard = rgeo + shafr_shift - amid
446 equilibrium_out(1)%profiles_1d%r_outboard = rgeo + shafr_shift + amid
447 equilibrium_out(1)%profiles_1d%rho_vol = sqrt(vol/vol(npsi))
449 equilibrium_out(1)%profiles_1d%gm1 = g1
450 equilibrium_out(1)%profiles_1d%gm2 = g2
451 equilibrium_out(1)%profiles_1d%gm3 = g3
452 equilibrium_out(1)%profiles_1d%gm4 = g4
453 equilibrium_out(1)%profiles_1d%gm5 = g5
454 equilibrium_out(1)%profiles_1d%gm6 = g6
455 equilibrium_out(1)%profiles_1d%gm7 = g7
456 equilibrium_out(1)%profiles_1d%gm8 = 1._r8/g1**0.5
457 equilibrium_out(1)%profiles_1d%gm9 = g1**0.5
460 pprime = (rgeo + shafr_shift) * qsf * s_q / b0 * s_bt / rho *
fun
461 IF (rho(1).EQ.0.0_r8) pprime(1) = pprime(2)
463 ffprime =
fdia * s_bt / b2b02 * (jpar * s_jpar * (rgeo + shafr_shift) / r0 - pprime)
465 equilibrium_out(1)%profiles_1d%pprime = pprime
466 equilibrium_out(1)%profiles_1d%ffprime = ffprime
467 equilibrium_out(1)%profiles_1d%dvdrho = vprime
468 equilibrium_out(1)%profiles_1d%b_av = g5**0.5
473 CALL
l3interp(equilibrium_in(1)%profiles_1d%gm2, &
474 equilibrium_in(1)%profiles_1d%rho_tor, &
475 SIZE (equilibrium_in(1)%profiles_1d%rho_tor), &
476 equilibrium_out(1)%profiles_1d%gm2, &
477 equilibrium_out(1)%profiles_1d%rho_tor, &
478 SIZE (equilibrium_out(1)%profiles_1d%rho_tor))
479 equilibrium_out(1)%profiles_1d%gm2 = equilibrium_out(1)%profiles_1d%gm2 * 0.9_r8 + g2 * 0.1_r8
482 ALLOCATE(equilibrium_out(1)%coord_sys%grid_type(4))
483 ALLOCATE(equilibrium_out(1)%coord_sys%grid%dim1(ndim1))
484 ALLOCATE(equilibrium_out(1)%coord_sys%grid%dim2(ndim2))
485 ALLOCATE(equilibrium_out(1)%coord_sys%position%R(ndim1,ndim2))
486 ALLOCATE(equilibrium_out(1)%coord_sys%position%Z(ndim1,ndim2))
488 rho_loop2:
DO idim1=1,ndim1
489 amid_2d(idim1) = amin/(ndim1-1)*(idim1-1)
491 CALL
l3interp(rho, amid, npsi, rho_2d, amid_2d, ndim1)
492 CALL
l3interp(elong, amid, npsi, elong_2d, amid_2d, ndim1)
493 CALL
l3interp(triang, amid, npsi, triang_l2d, amid_2d, ndim1)
494 CALL
l3interp(triang, amid, npsi, triang_u2d, amid_2d, ndim1)
495 CALL
l3interp(shafr_shift, amid, npsi, shafr_shift_2d, amid_2d, ndim1)
496 CALL
l3interp(psi, amid, npsi, psi_2d, amid_2d, ndim1)
497 fun = jpar * 1.0e6_r8
498 CALL
l3interp(
fun, amid, npsi, jpar_2d, amid_2d, ndim1)
500 CALL
l3interp(
fun, amid, npsi, pr_2d, amid_2d, ndim1)
504 theta =
REAL(itheta-1,r8)/
REAL(ndim2,r8)*2.0_r8*itm_pi
506 equilibrium_out(1)%coord_sys%grid_type(1) =
'2'
507 equilibrium_out(1)%coord_sys%grid_type(2) =
'inverse'
508 equilibrium_out(1)%coord_sys%grid_type(3) =
'3'
509 equilibrium_out(1)%coord_sys%grid_type(4) =
'polar'
510 equilibrium_out(1)%coord_sys%grid%dim1(ipsi) = psi_2d(ipsi) * s_psi
511 equilibrium_out(1)%coord_sys%grid%dim2(itheta) = theta
512 equilibrium_out(1)%coord_sys%position%R(ipsi, itheta) = r0 + shafr_shift_2d(ipsi) + amid_2d(ipsi) &
513 * (cos(theta)-(triang_u2d(ipsi)+triang_l2d(ipsi))/2._r8*(sin(theta))**2)
514 equilibrium_out(1)%coord_sys%position%Z(ipsi, itheta) = zgeo + amid_2d(ipsi) * elong_2d(ipsi) * sin(theta)
522 IF(
ASSOCIATED(equilibrium_out(1)%eqgeometry%boundary)) &
523 CALL deallocate_cpo(equilibrium_out(1)%eqgeometry%boundary)
524 ALLOCATE (equilibrium_out(1)%eqgeometry%boundary(1))
525 ALLOCATE (equilibrium_out(1)%eqgeometry%boundary(1)%r(max_npoints))
526 ALLOCATE (equilibrium_out(1)%eqgeometry%boundary(1)%z(max_npoints))
528 DO itheta=1, max_npoints
529 theta =
REAL(itheta-1,r8)/
REAL(max_npoints-1,r8)*2.0_r8*itm_pi
530 equilibrium_out(1)%eqgeometry%boundary(1)%r(itheta) = r0 + shafr_shift_2d(npsi) + amin * (cos(theta) - tr*(sin(theta))**2)
531 equilibrium_out(1)%eqgeometry%boundary(1)%z(itheta) = zgeo + amin * el * sin(theta)
532 IF (abs(equilibrium_out(1)%eqgeometry%boundary(1)%z(itheta)).LE.1.e-15_r8) &
533 equilibrium_out(1)%eqgeometry%boundary(1)%z(itheta) = 0.0e0_r8
535 equilibrium_out(1)%eqgeometry%boundarytype = 1
538 equilibrium_out(1)%eqgeometry%geom_axis%r = rgeo
539 equilibrium_out(1)%eqgeometry%geom_axis%z = zgeo
540 equilibrium_out(1)%eqgeometry%a_minor = amin
541 equilibrium_out(1)%eqgeometry%elong_upper = el
542 equilibrium_out(1)%eqgeometry%elong_lower = el
549 ALLOCATE (equilibrium_out(1)%profiles_2d(1))
550 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%grid_type(4))
551 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%grid%dim1(ndim1))
552 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%grid%dim2(ndim2))
553 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%R(ndim1, ndim2))
554 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%Z(ndim1, ndim2))
555 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%psi(ndim1, ndim2))
556 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%theta(ndim1, ndim2))
557 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%jphi(ndim1, ndim2))
558 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%jpar(ndim1, ndim2))
559 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%br(ndim1, ndim2))
560 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%bz(ndim1, ndim2))
561 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%bphi(ndim1, ndim2))
562 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%vphi(ndim1, ndim2))
563 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%vtheta(ndim1, ndim2))
564 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%rho_mass(ndim1, ndim2))
565 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%pressure(ndim1, ndim2))
566 ALLOCATE (equilibrium_out(1)%profiles_2d(1)%temperature(ndim1, ndim2))
570 theta =
REAL(itheta-1,r8)/
REAL(ndim2-1,r8)*2.0_r8*itm_pi
573 equilibrium_out(1)%profiles_2d(1)%grid_type(1) =
'2'
574 equilibrium_out(1)%profiles_2d(1)%grid_type(2) =
'inverse'
575 equilibrium_out(1)%profiles_2d(1)%grid_type(3) =
'3'
576 equilibrium_out(1)%profiles_2d(1)%grid_type(4) =
'polar'
577 equilibrium_out(1)%profiles_2d(1)%grid%dim1(ipsi) = psi_2d(ipsi) * s_psi
578 equilibrium_out(1)%profiles_2d(1)%grid%dim2(itheta) = theta
579 IF (theta.LE.itm_pi) tr = triang_u2d(ipsi)
580 IF (theta.GT.itm_pi) tr = triang_l2d(ipsi)
582 equilibrium_out(1)%profiles_2d(1)%R(ipsi, itheta) = r0 + shafr_shift_2d(ipsi) + amid_2d(ipsi) &
583 * (cos(theta)-tr*(sin(theta))**2)
584 equilibrium_out(1)%profiles_2d(1)%Z(ipsi, itheta) = zgeo + amid_2d(ipsi) * elong_2d(ipsi) * sin(theta)
585 equilibrium_out(1)%profiles_2d(1)%theta(ipsi, itheta) = theta
587 equilibrium_out(1)%profiles_2d(1)%psi(ipsi, itheta) = psi_2d(ipsi) * s_psi
588 equilibrium_out(1)%profiles_2d(1)%jpar(ipsi, itheta) = jpar_2d(ipsi) * s_jpar
589 equilibrium_out(1)%profiles_2d(1)%pressure(ipsi, itheta) = pr_2d(ipsi)
598 ALLOCATE (equilibrium_out(1)%codeparam%codename(1))
599 ALLOCATE (equilibrium_out(1)%codeparam%codeversion(1))
600 ALLOCATE (equilibrium_out(1)%codeparam%parameters(
SIZE(code_parameters%parameters)))
601 ALLOCATE (equilibrium_out(1)%codeparam%output_diag(1))
604 equilibrium_out(1)%codeparam%codename(1) =
'emeq'
605 equilibrium_out(1)%codeparam%codeversion(1) =
'01.03.2013'
606 equilibrium_out(1)%codeparam%output_diag(1) =
'my_output_diag'
607 equilibrium_out(1)%codeparam%output_flag = 0
608 equilibrium_out(1)%codeparam%parameters = code_parameters%parameters
613 ALLOCATE (equilibrium_out(1)%datainfo%dataprovider(1))
614 equilibrium_out(1)%datainfo%dataprovider(1) =
'Denis Kalupin'
615 equilibrium_out(1)%datainfo%cocos = 13
638 DEALLOCATE (vprime_psi)
640 DEALLOCATE (areaprime)
642 DEALLOCATE (shafr_shift)
651 DEALLOCATE (elong_2d)
652 DEALLOCATE (triang_l2d)
653 DEALLOCATE (triang_u2d)
654 DEALLOCATE (shafr_shift_2d)
683 TYPE (type_param
),
INTENT(in) :: codeparameters
684 INTEGER(ikind),
INTENT(out) :: return_status
686 TYPE(tree
) :: parameter_list
687 TYPE(element
),
POINTER :: temp_pointer
688 INTEGER(ikind) :: i, nparm, n_values
689 CHARACTER(len = 132) :: cname
695 WRITE(*,*)
'Calling euitm_xml_parse'
696 CALL euitm_xml_parse(codeparameters, nparm, parameter_list)
697 WRITE(*,*)
'Called euitm_xml_parse'
701 temp_pointer => parameter_list%first
704 cname = char2str(temp_pointer%cname)
707 temp_pointer => temp_pointer%child
712 temp_pointer => temp_pointer%child
715 IF (
ALLOCATED(temp_pointer%cvalue)) &
716 CALL char2num(temp_pointer%cvalue, neq)
720 temp_pointer => temp_pointer%child
723 IF (
ALLOCATED(temp_pointer%cvalue)) &
724 CALL char2num(temp_pointer%cvalue, convergence)
726 IF (
ALLOCATED(temp_pointer%cvalue)) &
727 CALL char2num(temp_pointer%cvalue, aceqlb)
729 IF (
ALLOCATED(temp_pointer%cvalue)) &
730 CALL char2num(temp_pointer%cvalue, itermax)
733 WRITE(*, *)
'ERROR: invalid parameter', cname
738 IF (
ASSOCIATED(temp_pointer%sibling))
THEN
739 temp_pointer => temp_pointer%sibling
742 IF (
ASSOCIATED(temp_pointer%parent, parameter_list%first )) &
744 IF (
ASSOCIATED(temp_pointer%parent))
THEN
745 temp_pointer => temp_pointer%parent
747 WRITE(*, *)
'ERROR: broken list.'
754 CALL destroy_xml_tree(parameter_list)
766 INTEGER n_lines, in_xml, ios, i
767 CHARACTER (len=*) :: filename
768 TYPE (type_codeparam
) :: codeparam
769 CHARACTER(len = 132) :: xml_line
771 OPEN (unit = in_xml, file = filename, status =
'old', &
772 action =
'read', iostat = ios)
775 WRITE(*,*)
'Could not open ',trim(filename)
776 stop
' ERROR: XML file does not exist '
782 READ (in_xml,
'(a)', iostat = ios) xml_line
784 n_lines = n_lines + 1
792 ALLOCATE(codeparam%codename(1))
793 codeparam%codename(1)=
'EMEQ'
794 ALLOCATE(codeparam%codeversion(1))
795 codeparam%codeversion(1)=version
796 WRITE(*,*)
'Code = ',trim(codeparam%codename(1)),
' version = ',trim(codeparam%codeversion(1))
797 ALLOCATE(codeparam%parameters(n_lines))
799 READ (in_xml,
'(a)', iostat = ios) codeparam%parameters(i)
870 INTEGER :: npsi, neq, i, iter
873 REAL (R8) :: rgeo, bgeo, pc
874 REAL (R8) :: delta, eln, trn
875 REAL (R8) :: aceqlb, convergence
879 REAL (R8) :: rho(npsi), rho_new(npsi)
880 REAL (R8) :: amid(npsi), amid_eq(neq)
881 REAL (R8) :: jpar(npsi), qsf(npsi)
882 REAL (R8) :: pr(npsi)
885 REAL (R8) :: g1(npsi), g1_eq(neq)
886 REAL (R8) :: g2(npsi), g2_eq(neq)
887 REAL (R8) :: g3(npsi), g3_eq(neq)
888 REAL (R8) :: g4(npsi), g4_eq(neq)
889 REAL (R8) :: g5(npsi), g5_eq(neq)
890 REAL (R8) :: g6(npsi), g6_eq(neq)
891 REAL (R8) :: g7(npsi), g7_eq(neq)
892 REAL (R8) :: area(npsi), area_eq(neq)
893 REAL (R8) :: areaprime(npsi), areaprime_eq(neq)
894 REAL (R8) :: vol(npsi), vol_eq(neq)
895 REAL (R8) :: vprime(npsi), vprime_eq(neq)
896 REAL (R8) ::
fdia(npsi), fdia_eq(neq)
897 REAL (R8) :: b2b02(npsi), b2b02_eq(neq)
898 REAL (R8) :: shafr_shift(npsi),gbd(neq)
899 REAL (R8) :: elong(npsi), gl(neq)
900 REAL (R8) :: triang(npsi), gsd(neq)
904 REAL (R8) :: ja(npsi), jaeq(neq)
905 REAL (R8) :: jb(npsi), jbeq(neq)
908 REAL (R8) :: r0, b0, amin
909 REAL (R8) :: dpr(npsi)
910 REAL (R8) :: nabrho(npsi), nabrho_eq(neq)
911 REAL (R8) :: vprime_n(npsi)
912 REAL (R8) :: nabrho_n(npsi)
913 REAL (R8) :: g2_n(npsi)
914 REAL (R8) :: qsf_n(npsi)
915 REAL (R8) ::
fun(npsi), intfun(npsi)
918 REAL (R8) :: gra(neq), sqgra(neq)
919 REAL (R8) :: grar(neq), avr2(neq)
920 REAL (R8) :: ai0(neq), dgrda(neq), avsqg(neq)
921 REAL (R8) :: grdaeq(neq), b2b0eq(neq)
922 REAL (R8) :: b0b2eq(neq), b0b0eq(neq), bmaxeq(neq)
923 REAL (R8) :: bmineq(neq), bmodeq(neq), fofbeq(neq)
925 REAL (R8) :: conv, err_vprime, err_nabrho, err_qsf, err_g2
938 CALL
l3deriv(pr, rho, npsi, dpr, rho, npsi)
943 dpr(i) = min(0.0_r8,dpr(i))
950 amid_eq(i) = amin /(neq-1)*(i-1)
967 WRITE(*,*)
'### ERROR! Equilibrium loop in EQUILIBRIUM_INTERFACE not converging'
968 stop
'Error - no convergence in EQUILIBRIUM_INTERFACE'
986 jb(i) = -r0/b0*qsf(i)/rho(i)*dpr(i)*1.d-6
988 ja(i) = jb(i)*(1.0_r8-
fdia(i)**2/b2b02(i)*rgeo**2/r0**2) &
989 + jpar(i)/1.d6*
fdia(i)/b2b02(i)*rgeo/r0
999 CALL
l3interp(ja, amid ,npsi, jaeq, amid_eq, neq)
1000 CALL
l3interp(jb, amid ,npsi, jbeq, amid_eq, neq)
1047 g2_eq = grar * dgrda**2
1048 g3_eq = gra * dgrda**2
1049 g4_eq = b0b0eq / b0**2
1050 g5_eq = b2b0eq * b0**2
1051 g6_eq = gra * dgrda**2 / b0**2
1052 g7_eq = sqgra * dgrda
1054 fdia_eq = ai0 / (b0*r0)
1057 nabrho_eq = gra * dgrda**2
1061 CALL
l3deriv(vol_eq, gr, neq, vprime_eq, gr, neq)
1063 area_eq = vprime_eq * sqgra * dgrda
1064 CALL
l3deriv(area_eq, gr, neq, areaprime_eq, gr, neq)
1071 rho_new(i) = gr(neq)*(i-1)/(npsi-1)
1075 CALL
l3interp(
fun, rho, npsi, jpar, rho_new, npsi)
1082 CALL
l3interp(amid_eq, gr, neq, amid, rho, npsi)
1083 CALL
l3interp(nabrho_eq, gr, neq, nabrho, rho, npsi)
1084 CALL
l3interp(vol_eq, gr, neq, vol, rho, npsi)
1085 CALL
l3interp(vprime_eq, gr, neq, vprime, rho, npsi)
1086 CALL
l3interp(g1_eq, gr, neq, g1, rho, npsi)
1087 CALL
l3interp(g2_eq, gr, neq, g2, rho, npsi)
1088 CALL
l3interp(g3_eq, gr, neq, g3, rho, npsi)
1089 CALL
l3interp(g4_eq, gr, neq, g4, rho, npsi)
1090 CALL
l3interp(g5_eq, gr, neq, g5, rho, npsi)
1091 CALL
l3interp(g6_eq, gr, neq, g6, rho, npsi)
1092 CALL
l3interp(g7_eq, gr, neq, g7, rho, npsi)
1094 CALL
l3interp(b2b02_eq, gr, neq, b2b02, rho, npsi)
1095 CALL
l3interp(area_eq, gr, neq, area, rho, npsi)
1096 CALL
l3interp(areaprime_eq, gr, neq, areaprime, rho, npsi)
1097 CALL
l3interp(gbd, gr, neq, shafr_shift,rho, npsi)
1098 CALL
l3interp(gl, gr, neq, elong , rho, npsi)
1099 CALL
l3interp(gsd, gr, neq, triang, rho, npsi)
1105 fun(i) = jpar(i)*vprime(i)*itm_mu0/(
fdia(i)*b0*r0)**2
1106 IF (rho(i).NE.0.0_r8.AND.i.GT.1)
THEN
1107 intfun(i) = intfun(i-1) + (
fun(i-1)+
fun(i))*(rho(i)-rho(i-1))/2.0_r8
1108 qsf(i) = rho(i)*vprime(i)*g2(i)/(
fdia(i)*b0*r0)/intfun(i)
1118 err_vprime = maxval(abs(1.0_r8-vprime_n(2:)/vprime(2:)))
1119 err_nabrho = maxval(abs(1.0_r8-nabrho_n/nabrho))
1120 err_qsf = maxval(abs(1.0_r8-qsf_n/qsf))
1121 err_g2 = maxval(abs(1.0_r8-g2_n/g2))
1123 WRITE(*,*)
'err_VPRIME ', err_vprime
1124 WRITE(*,*)
'err_NABRHO ', err_nabrho
1125 WRITE(*,*)
' err_QSF ', err_qsf
1126 WRITE(*,*)
' err_G2 ', err_g2
1128 conv = max( err_vprime, err_nabrho, err_qsf, err_g2)
1130 WRITE(*,*)
' CONV ', conv
1132 IF(conv.GT.convergence) goto 1
1137 IF(vol(1).LT.0)
THEN
1138 WRITE(*,*)
'VOL(1) = ',vol(1)
1141 IF(vprime(1).LT.0.0_r8)
THEN
1142 WRITE(*,*)
'### ', vprime(1),
' changed to 0'
1182 REAL (R8) :: h(n), r(n), f(n)
1189 f(1) = ((f(2)*r(4)/h(2)+f(4)*r(2)/h(3))*r(3) &
1190 -f(3)*(r(2)/h(2)+r(4)/h(3))*r(2)*r(4)/r(3)) &
subroutine emeq_e3m(EQUILIBRIUM_IN, EQUILIBRIUM_OUT, code_parameters)
subroutine axis_int(n, r, f)
subroutine l3deriv(y_in, x_in, nr_in, dydx_out, x_out, nr_out)
subroutine assign_code_parameters(codeparameters, return_status)
subroutine emeq_interface(
subroutine l3interp(y_in, x_in, nr_in, y_out, x_out, nr_out)
real(r8) function fdia(psi_n)
subroutine, public dealloc_emeq_equil
subroutine, public alloc_emeq_equil(NP_in)
subroutine, public e3astr
subroutine read_codeparam(in_xml, filename, codeparam)
replacement for the EMEQ common block