From b14daebfd0e56b899ce3621a2831c855ba96bce9 Mon Sep 17 00:00:00 2001 From: Lorenzo Cipriani Date: Tue, 19 Sep 2023 16:01:57 +0200 Subject: [PATCH] Fixed atan initial data --- src/initial_data.f90 | 55 ++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/initial_data.f90 b/src/initial_data.f90 index d91380f..e8f95b2 100644 --- a/src/initial_data.f90 +++ b/src/initial_data.f90 @@ -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 @@ -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