Makes [[libfida:beam_grid] from user defined inputs
subroutine make_beam_grid
!+ Makes [[libfida:beam_grid] from user defined inputs
integer(Int32) :: i, j, k, n
real(Float64) :: dx, dy, dz, ri(3)
logical :: inp
allocate(beam_grid%xc(beam_grid%nx), &
beam_grid%yc(beam_grid%ny), &
beam_grid%zc(beam_grid%nz))
dx = (beam_grid%xmax - beam_grid%xmin)/beam_grid%nx
dy = (beam_grid%ymax - beam_grid%ymin)/beam_grid%ny
dz = (beam_grid%zmax - beam_grid%zmin)/beam_grid%nz
do i=1, beam_grid%nx
beam_grid%xc(i) = beam_grid%xmin + (i-0.5)*dx
enddo
do i=1, beam_grid%ny
beam_grid%yc(i) = beam_grid%ymin + (i-0.5)*dy
enddo
do i=1, beam_grid%nz
beam_grid%zc(i) = beam_grid%zmin + (i-0.5)*dz
enddo
beam_grid%dr(1) = abs(beam_grid%xc(2)-beam_grid%xc(1))
beam_grid%dr(2) = abs(beam_grid%yc(2)-beam_grid%yc(1))
beam_grid%dr(3) = abs(beam_grid%zc(2)-beam_grid%zc(1))
beam_grid%lwh(1) = abs(beam_grid%xc(beam_grid%nx) - beam_grid%xc(1)) + beam_grid%dr(1)
beam_grid%lwh(2) = abs(beam_grid%yc(beam_grid%ny) - beam_grid%yc(1)) + beam_grid%dr(2)
beam_grid%lwh(3) = abs(beam_grid%zc(beam_grid%nz) - beam_grid%zc(1)) + beam_grid%dr(3)
beam_grid%volume = beam_grid%lwh(1)*beam_grid%lwh(2)*beam_grid%lwh(3)
beam_grid%center(1) = (minval(beam_grid%xc) - 0.5*beam_grid%dr(1)) + 0.5*beam_grid%lwh(1)
beam_grid%center(2) = (minval(beam_grid%yc) - 0.5*beam_grid%dr(2)) + 0.5*beam_grid%lwh(2)
beam_grid%center(3) = (minval(beam_grid%zc) - 0.5*beam_grid%dr(3)) + 0.5*beam_grid%lwh(3)
beam_grid%drmin = minval(beam_grid%dr)
beam_grid%dv = beam_grid%dr(1)*beam_grid%dr(2)*beam_grid%dr(3)
beam_grid%ntrack = (beam_grid%nx+beam_grid%ny+beam_grid%nz)*inputs%max_cell_splits
beam_grid%ngrid = beam_grid%nx*beam_grid%ny*beam_grid%nz
beam_grid%dims(1) = beam_grid%nx
beam_grid%dims(2) = beam_grid%ny
beam_grid%dims(3) = beam_grid%nz
call tb_zyx(beam_grid%alpha,beam_grid%beta,beam_grid%gamma, &
beam_grid%basis, beam_grid%inv_basis)
!! Check if beam grid is in the plasma
n = 0
do k=1,beam_grid%nz
do j=1,beam_grid%ny
do i=1,beam_grid%nx
ri = [beam_grid%xc(i),beam_grid%yc(j), beam_grid%zc(k)]
call in_plasma(ri, inp)
if(inp) n = n + 1
enddo
enddo
enddo
if(inputs%verbose.ge.1) then
write(*,'(a)') "---- Beam grid settings ----"
write(*,'(T2,"Nx: ", i3)') beam_grid%nx
write(*,'(T2,"Ny: ", i3)') beam_grid%ny
write(*,'(T2,"Nz: ", i3)') beam_grid%nz
write(*,'(T2,"dV: ", f5.2," [cm^3]")') beam_grid%dv
write(*,'(T2,"alpha: ",f5.2," [rad]")') beam_grid%alpha
write(*,'(T2,"beta: ",f5.2," [rad]")') beam_grid%beta
write(*,'(T2,"gamma: ",f5.2," [rad]")') beam_grid%gamma
write(*,'(T2,"origin: [",f7.2,",",f7.2,",",f7.2,"] [cm]")') beam_grid%origin
write(*,'(T2,"Number of cells in plasma: ",i8)') n
write(*,*) ''
endif
if(n.le.(0.1*beam_grid%ngrid)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') "MAKE_BEAM_GRID: Beam grid definition is poorly defined. &
&Less than 10% of the beam grid cells fall within the plasma."
endif
stop
endif
end subroutine make_beam_grid