Skip to content

Commit

Permalink
Fixed atan initial data
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Cipriani authored and Lorenzo Cipriani committed Sep 19, 2023
1 parent 636eacf commit b14daeb
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions src/initial_data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ subroutine initial_data(NX, x, dx, m, r0, a0, idx, u)
real(RK), dimension(2*NX), intent(out):: u

integer :: i, j
real(RK) :: th, Mass, heaviside, p
real(RK) :: th, Mass, heaviside, p, tmp
real(RK), dimension(NX) :: rr, Marray

real(RK), parameter :: PI=4._RK*DATAN(1._RK)
real(RK), parameter :: PI=4._RK*DATAN(1._RK), one = 1_RK, zero = 0_RK

! Full dynamics, starting from step function

if ( idx .eq. 0 ) then

! Physical values
Expand Down Expand Up @@ -58,29 +57,55 @@ subroutine initial_data(NX, x, dx, m, r0, a0, idx, u)

! Full dynamics, starting from atan density profile
else if ( idx .eq. 3 ) then
do i = 1, NX
rr(i) = 3_RK * m * (PI/2_RK - atan(x(i) - r0) ) / (8_RK * PI * r0**3)
end do

do i = 3, NX-1
p = 0_RK
do j = 3, i
p = p + (rr(j-1) * x(j-1)**2 + rr(j) * x(j)**2)
end do
Marray(i) = 4_RK * PI * p * dx * 0.5_RK
! Unnormalized density function
do i = 1, NX
rr(i) = PI/2_RK - atan(x(i) - r0)
end do

! Unnormalized mass function
Marray(1) = 0
Marray(2) = 0
p = 0_RK
do i = 3, NX-1
p = p + (rr(i-1)*x(i-1)**2 + rr(i)*x(i)**2)
Marray(i) = 4*PI * p * dx * 0.5_RK
end do
Marray(NX) = Marray(NX-1)

! Normalized mass function
do i = 1, NX
Marray(i) = m * Marray(i) / Marray(NX-1)
end do

! Physical values
do i = 2, NX-1
th = heaviside(r0 - x(i))
! E(x)
u(NX+i) = - x(i)**2 / a0**2 * th - r0**2 / a0**2 * (1_RK - th)

! Cubic interpolation around r0 to ensure epsilon is a C1 function
if ((x(i).le.(r0+1_RK)).and.(x(i).ge.(r0-1_RK))) then
u(NX+i) = x(i)**3 - (r0 + 2_RK) * x(i)**2 - (r0**2 - 1_RK) * x(i) + r0*(r0 - 1_RK)**2
u(NX+i) = u(NX+i) / (4_RK*a0**2)
else
u(NX+i) = - x(i)**2 / a0**2 * th - r0**2 / a0**2 * (1_RK - th)
end if

! B(x)
u(i) = - 0.5_RK*x(i)**2 * acos(1_RK - 4_RK * Marray(i) / x(i)**3_RK - 2_RK * u(NX+i) / x(i)**2_RK)
tmp = 1_RK - 4_RK * Marray(i) / x(i)**3_RK - 2_RK * u(NX+i) / x(i)**2
tmp = max(-one, min(tmp, one))
u(i) = - 0.5_RK*x(i)**2 * acos(tmp)

end do

u(2) = 0_RK
u(NX+2) = 0_RK

! Ghosts
u(1) = u(2)
u(NX) = u(NX-1)
u(NX+1) = u(NX+2)
u(2*NX) = u(2*NX-1)

! Full dynamics, flat case
else if ( idx .eq. 4 ) then

Expand Down

0 comments on commit b14daeb

Please sign in to comment.