Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgiaActon committed Jan 20, 2025
1 parent 537edd4 commit 9d9b7b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
22 changes: 10 additions & 12 deletions ffs_solve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ subroutine get_source_ffs_itteration (phi, phi_bar, g, source)
real :: scratch

allocate (g0(naky, nakx, -nzgrid:nzgrid, ntubes)) ; g0 = 0.0

allocate (dgphi_dz(naky, nakx, -nzgrid:nzgrid, ntubes)) ; dgphi_dz = 0.0
allocate (dphi_dz(naky, nakx, -nzgrid:nzgrid, ntubes)) ; dphi_dz = 0.0
allocate (dgdz(naky, nakx, -nzgrid:nzgrid, ntubes)) ; dgdz = 0.0
Expand All @@ -94,7 +94,6 @@ subroutine get_source_ffs_itteration (phi, phi_bar, g, source)
!>
allocate (dphi_dz2(naky, nakx, -nzgrid:nzgrid, ntubes)) ; dphi_dz2 = 0.0
allocate (g4y(ny, ikx_max, -nzgrid:nzgrid, ntubes)) ; g4y = 0.0

source = 0.0

do ivmu = vmu_lo%llim_proc, vmu_lo%ulim_proc
Expand All @@ -111,10 +110,10 @@ subroutine get_source_ffs_itteration (phi, phi_bar, g, source)
call get_dzed(iv, phi, dphi_dz)
!> dg/dz
call get_dzed(iv, g(:, :, :, :, ivmu), dgdz)

!> !?
call get_dzed(iv, phi_bar, dphi_dz2)

!> get these quantities in real space
do it = 1, ntubes
do iz = -nzgrid, nzgrid
Expand Down Expand Up @@ -145,26 +144,25 @@ subroutine get_source_ffs_itteration (phi, phi_bar, g, source)
call center_zed(iv, coeff(ia, :) , -nzgrid)
call center_zed(iv, coeff2(ia, :) , -nzgrid)
end do
g2y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * g2y + spread(spread(coeff2, 2, ikx_max), 4, ntubes) * g0y

g4y = spread(spread(coeff2, 2, ikx_max), 4, ntubes) * (g0y - g4y)
! g2y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * g2y + spread(spread(coeff2, 2, ikx_max), 4, ntubes) * g0y
g2y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * g2y + spread(spread(coeff2, 2, ikx_max), 4, ntubes) * g4y

!> This is (b.grad z) * Z/T * (F_0 - avg(F_0)) * d phi^j /dz
coeff = stream_store_full (:,:,iv,is) * (maxwell_mu(:, :, imu, is) - maxwell_mu_avg(:, :, imu, is)) * scratch
do ia = 1, ny
call center_zed(iv, coeff(ia, :) , -nzgrid)
end do
g3y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * g1y
g3y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * g4y

!> This is (b.grad z) * Z/T * F_0 * d(<phi^j> - phi^j)/dz
coeff = stream_store_full (:,:,iv,is) * maxwell_mu(:, :, imu, is)
coeff = stream_store_full (:,:,iv,is) * maxwell_mu(:, :, imu, is) * scratch
do ia = 1, ny
call center_zed(iv, coeff(ia, :) , -nzgrid)
end do
g0y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * (g0y - g1y) * scratch
g0y = spread(spread(coeff, 2, ikx_max), 4, ntubes) * (g0y - g1y)

!> Add them all together and transform back to (kx, ky) space
g0y = g0y + g2y + g3y + g4y
g0y = g0y + g2y + g3y !!+ g4y

do it = 1, ntubes
do iz = -nzgrid, nzgrid
Expand All @@ -175,7 +173,7 @@ subroutine get_source_ffs_itteration (phi, phi_bar, g, source)

source(1, 1, :, :, :) = 0.0
end do

deallocate(g0)
deallocate(dgphi_dz, dphi_dz, dgdz)
deallocate(g_swap)
Expand Down
22 changes: 5 additions & 17 deletions implicit_solve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ subroutine advance_implicit_terms(g, phi, apar, bpar)

fields_updated = .false.
call advance_fields(g2, phi, apar, bpar, dist=trim(dist_choice))
fields_updated = .false.
call advance_fields(g, phi_store, apar, bpar, dist=trim(dist_choice), implicit_solve = .true.)
! phi_store = phi
if (driftkinetic_implicit) then
fields_updated = .false.
call advance_fields(g, phi_store, apar, bpar, dist=trim(dist_choice), implicit_solve = .true.)
end if
phi_old = phi

!> if using delphi formulation for response matrix, then phi = phi^n replaces
Expand Down Expand Up @@ -203,22 +204,9 @@ subroutine advance_implicit_terms(g, phi, apar, bpar)
call advance_fields(g, phi, apar, bpar, dist=trim(dist_choice))
fields_updated = .false.
!> For checking
call advance_fields(g2, phi_store, apar, bpar, dist=trim(dist_choice), implicit_solve = .true.)
if(proc0) then
do iz = -nzgrid, nzgrid
do iky = 1, naky
do ikx = 1, nakx
write(108, *) iz, iky, ikx, real(phi_store(iky, ikx, iz,1)), aimag(phi_store(iky, ikx, iz,1))
write(98, *) iz, iky, ikx, real(phi(iky, ikx, iz, 1)), aimag(phi(iky, ikx, iz, 1))
write(88, *) iz, iky, ikx, real(phi(iky, ikx, iz, 1) - phi_store(iky, ikx, iz,1)), aimag(phi(iky, ikx, iz, 1) - phi_store(iky, ikx, iz,1))
end do
end do
end do
end if

call advance_fields(g, phi_store, apar, bpar, dist=trim(dist_choice), implicit_solve = .true.)
g2 = g
phi_old = phi
! phi_store = phi
else
call update_pdf
end if
Expand Down

0 comments on commit 9d9b7b9

Please sign in to comment.