Commit a27dbfc0 authored by rabgra's avatar rabgra
Browse files

Merge branch 'master' of git.math.uzh.ch:remi.abgrall/RD_public

parents 4f7fe35f 52a6e305
!!! HIGH ORDER IN SPACE AND TIME DEFERRED CORRECTION (EXPLICIT)
!!! RESIDUAL DISTRIBUTION METHOD
!!! DESIGNED FOR THE SYSTEM GIVEN BY THE EULER EQUATIONS in 1D and 2D
!!!
!!! Authors:
!!! Remi Abgrall (University of Zurich),
!!! Paola Bacigaluppi (University of Zurich),
!!! Svetlana Tokareva (University of Zurich)
!!! Institute of Mathematics and Institute of Computational Sciences
!!! University of Zurich
!!! July 10, 2018
!!! Correspondance: remi.abgrall@math.uzh.ch
!!! ------------------------------------------
!==================================================
! Definition of variables for the 1D wave equation
! u_tt - a^2 u_xx = 0
......@@ -21,13 +8,12 @@
!==================================================
MODULE variable_def
USE algebra
use precision
IMPLICIT NONE
INTEGER, PUBLIC, PARAMETER:: n_vars = 1 ! number of primitive variables
INTEGER, PUBLIC, PARAMETER:: n_dim = 1 ! number of physical dimensions
REAL(dp), PARAMETER:: pi=ACOS(-1.) ! pi
REAL(dp), PUBLIC, PARAMETER:: a = 1.0
REAL(dp), PUBLIC, PARAMETER:: aa = 100., bb = 100.
REAL(dp), PARAMETER:: pi=ACOS(-1._dp) ! pi
REAL(dp), PUBLIC, PARAMETER:: a = 1.0_dp
! Type for the vector of primitive variables
TYPE, PUBLIC :: PVar
......@@ -36,16 +22,17 @@ MODULE variable_def
CONTAINS
PROCEDURE, PUBLIC:: flux => flux_w
PROCEDURE, PUBLIC:: source => source_s
PROCEDURE, PUBLIC:: entropy_flux => flux_scal_e !!! Introduced for the entropy correction!
PROCEDURE, PUBLIC:: evalues => evalues_w
PROCEDURE, PUBLIC:: spectral_radius => spectral_radius_w
PROCEDURE, PUBLIC:: rvectors => rvectors_w
PROCEDURE, PUBLIC:: lvectors => lvectors_w
PROCEDURE, PUBLIC:: Jacobian => Jacobian_w
PROCEDURE, PUBLIC:: Nmat => Nmat_w
END TYPE PVar
PRIVATE
PUBLIC:: convert_cons2prim
PUBLIC:: convert_cons2prim, entropyProduct
CONTAINS
......@@ -72,50 +59,57 @@ CONTAINS
!!!!-----------------------
FUNCTION roe_w(e,u,n) RESULT (J)
! evaluate a roe average to estimate a rough speed for
! Burman jump operator
CLASS(Pvar), INTENT(in):: e
REAL(dp), DIMENSION(N_Vars), INTENT(in):: u
REAL(dp), DIMENSION(n_dim), INTENT(in):: n ! here it will be a normal of norme 1
REAL(dp), DIMENSION(n_vars,n_vars):: J
REAL(dp), DIMENSION(n_vars,n_vars,n_dim):: JJ
REAL(dp), DIMENSION(n_dim):: v=0.
JJ=Jacobian_w(e,v)
J(:,:) = JJ(:,:,1)*n(1)
END FUNCTION roe_w
FUNCTION flux_w(e,x) RESULT(f)
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
TYPE(PVar), DIMENSION(n_dim) :: f
F(1)%u(:)=e%u(:)
REAL(dp), DIMENSION(n_vars,n_vars,n_dim):: JJ
JJ=Jacobian_w(e,x)
F(1)%u(:)=MATMUL(JJ(:,:,1),e%u)
END FUNCTION flux_w
FUNCTION source_s(e,x,test) RESULT(s)
CLASS(PVar), INTENT(IN) :: e
REAL(dp), DIMENSION(n_dim), INTENT(IN) :: x
INTEGER , INTENT(IN) :: test
TYPE(PVar) :: s
s%u = 0._dp
END FUNCTION source_s
FUNCTION Jacobian_w(e,x) RESULT(J)
CLASS(Pvar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_Vars,n_Vars,n_dim) :: J
J=1.
J(1,1,1) = a
END FUNCTION Jacobian_w
FUNCTION evalues_w(e,x,n) RESULT(lambda)
! eigenvalues: diagonal matrix. It is written as a matrix for ease of calculations
CLASS(PVar), INTENT(in) :: e
REAL(DP), DIMENSION(n_dim), INTENT(in) :: x
REAL(DP), DIMENSION(n_dim) :: n
REAL(DP), DIMENSION(n_Vars,n_Vars) :: lambda
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
REAL, DIMENSION(n_vars, n_vars, n_dim) :: J
REAL(dp), DIMENSION(n_vars, n_vars, n_dim) :: J
INTEGER:: i
lambda=1.
lambda(1,1) = a;
END FUNCTION evalues_w
!!! Entropy flux for the scalar equation
FUNCTION flux_scal_e(e, x) RESULT(f)
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
TYPE(PVar), dimension(n_dim) :: f
! transport
f(1)%U(1) = 0.5_dp*e%u(1)**2_dp
END FUNCTION flux_scal_e
REAL(dp) FUNCTION spectral_radius_w(e,x,n)
! compute the maximum value of eigenvalues:
......@@ -123,10 +117,8 @@ CONTAINS
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim), INTENT(in) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
lambda = evalues_w(e,x,n)
spectral_radius_w = MAXVAL(ABS(lambda))
spectral_radius_w = a
END FUNCTION spectral_radius_w
......@@ -136,8 +128,7 @@ CONTAINS
REAL(dp), DIMENSION(n_dim) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
R(:,:) = 1.0
R(1,1) = 1._dp;
END FUNCTION rvectors_w
FUNCTION lvectors_w(e,n) RESULT(L)
......@@ -146,65 +137,19 @@ CONTAINS
REAL(dp), DIMENSION(n_dim) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
L(:,:) = 1.0
L(1,1) = 1.0_dp;
END FUNCTION lvectors_w
FUNCTION Nmat_w(e, n_ord, grad, x) RESULT (Nmat)
CLASS(Pvar), INTENT(in) :: e
INTEGER, INTENT(in) :: n_ord
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim,n_ord), INTENT(in) :: grad
REAL(dp), DIMENSION(n_vars,n_vars) :: Nmat
REAL(dp), DIMENSION(n_vars, n_vars, n_dim) :: J
INTEGER:: l
J= Jacobian_w(e,x)
Nmat=0
DO l=1, n_ord
Nmat = Nmat + ABS( grad(1,l)*J(1,1,1) )
ENDDO
Nmat =0.!Inverse(Nmat)
END FUNCTION Nmat_w
FUNCTION min_mat_w(e, x, n, alpha) RESULT (Ap)
! in this A must be the result of tensor*vec where tensor are
! the jacobian evaluated for class e. It computes the negative part of A
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), INTENT(in) :: alpha
REAL(dp), DIMENSION(n_dim), INTENT(IN) :: n
REAL(dp), DIMENSION(N_vars, N_vars) :: Ap
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
lambda = evalues_w(e,x,n)
R = rvectors_w(e,n)
L = lvectors_w(e,n)
Ap = MATMUL( R, MATMUL( MIN(lambda(:,:),alpha), L) )
END FUNCTION min_mat_w
FUNCTION max_mat_w(e,x,n,alpha) RESULT (Ap)
! in this A must be the result of tensor*vec where tensor are
! the jacobian evaluated for class e. It computes the negative part of A
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), INTENT(in) :: alpha
REAL(dp), DIMENSION(n_dim), INTENT(in) :: n
REAL(dp), DIMENSION(N_vars, N_vars) :: Ap
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
FUNCTION entropyProduct(v1,v2) RESULT(prod)
CLASS(PVar), INTENT(in) :: v1,v2
REAL(dp) :: prod
prod = v1%U(1)*v2%U(1)
END FUNCTION entropyProduct
!--------------------------
lambda = evalues_w(e,x,n)
R = rvectors_w(e,n)
L = lvectors_w(e,n)
Ap = MATMUL( R, MATMUL( MAX(lambda(:,:),alpha), L) )
END FUNCTION max_mat_w
!--------------------------
......
MODULE variable_def
!------------------------------------------------------------------------------------------------
! MODULE SPECIFICALLY DESIGNED FOR 1D SYSTEM OF SW EQUATIONS
!------------------------------------------------------------------------------------------------
! This module collects all the information related to the following items:
! - equations of state: pressure, internal specific energy, speed of sound
! - conversion from conservative to primitive and viceversa
! - definition of the Jacobian of the considered system
! - definition of the Fluxes of the considered system
! - definition of the Jacobian in absolute values as: |J|=R* |lambda| *L (cf. AbsJacobian_sw)
! - definition of the Eigenvalues (cf. evalues_sw)
! - defintion of the Spectral Radius = max ( |lambda|)
! - definition of the Right eigenvectors
! - definition of the Left eigenvectors
! - definition of the positive and negative Jacobian
USE algebra
USE precision
USE utils
IMPLICIT NONE
INTEGER, PUBLIC, PARAMETER:: n_vars = 2 ! number of primitive variables
INTEGER, PUBLIC, PARAMETER:: n_dim = 1 ! number of physical dimensions
REAL(dp), PARAMETER:: pi=ACOS(-1._dp) ! pi
REAL(dp), PUBLIC :: grav=9.81_dp ! EOS parameters
! Type for the vector of primitive variables
TYPE, PUBLIC :: PVar
INTEGER :: NVars = n_vars
REAL(dp), DIMENSION(n_vars) :: U
CONTAINS
PROCEDURE, PUBLIC:: flux => flux_sw
PROCEDURE, PUBLIC:: source => source_sw
! PROCEDURE, PUBLIC:: evalues => evalues_eul
PROCEDURE, PUBLIC:: spectral_radius => spectral_radius_sw
PROCEDURE, PUBLIC:: rvectors => rvectors_sw
PROCEDURE, PUBLIC:: lvectors => lvectors_sw
PROCEDURE, PUBLIC:: Jacobian => Jacobian_sw
PROCEDURE, PUBLIC:: AbsJacobian => AbsJacobian_sw
PROCEDURE, PUBLIC:: Nmat => Nmat_sw
END TYPE PVar
PRIVATE
PUBLIC:: convert_cons2prim, convert_prim2cons
CONTAINS
!--------------------------
! Speed of sound
!--------------------------
FUNCTION SoundSpeed(rho) RESULT(a)
REAL(dp), INTENT(in) :: rho
REAL(dp) :: a
a = SQRT(grav*rho)
END FUNCTION SoundSpeed
!---------------------------------------------
! Convert conservative variables to primitive
!---------------------------------------------
FUNCTION convert_cons2prim(Q) RESULT(W)
TYPE(Pvar), INTENT(in) :: Q
TYPE(Pvar) :: W
REAL(dp) :: eps
! rho
W%U(1) = Q%U(1)
! u
W%U(2) = Q%U(2)/Q%U(1)
END FUNCTION convert_cons2prim
!---------------------------------------------
! Convert primitive variables to conservative
!---------------------------------------------
FUNCTION convert_prim2cons(W) RESULT(Q)
TYPE(Pvar), INTENT(in) :: W
TYPE(Pvar) :: Q
REAL(dp) :: eps
! q1 = rho
Q%U(1) = W%U(1)
! q2 = rho*u
Q%U(2) = W%U(1)*W%U(2)
END FUNCTION convert_prim2cons
!!!!-----------------------
FUNCTION roe_sw(e,u,n) RESULT (J)
! evaluate a roe average to estimate a rough speed for
! Burman jump operator
CLASS(Pvar), INTENT(in):: e
REAL(dp),DIMENSION(N_Vars), INTENT(in):: u
REAL(dp), DIMENSION(n_dim), INTENT(in):: n ! here it will be a normal of norme 1
REAL(dp), DIMENSION(n_vars,n_vars):: J
REAL(dp), DIMENSION(n_vars,n_vars,n_dim):: JJ
REAL(dp),DIMENSION(n_dim):: v=0.
JJ=Jacobian_sw(e,v)
J(:,:) = JJ(:,:,1)*n(1)
END FUNCTION roe_sw
FUNCTION flux_sw(Var,x) RESULT(f)
CLASS(PVar), INTENT(in) :: Var ! vector of conservative variables
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
TYPE(PVar), DIMENSION(n_dim) :: f
F(1)%u(1) = Var%u(2)
F(1)%u(2) = Var%u(2)**2._dp/Var%u(1) + grav*0.5_dp*Var%u(1)**2._dp
END FUNCTION flux_sw
FUNCTION source_sw(e,x,test) RESULT(s)
CLASS(PVar), INTENT(IN) :: e
REAL(dp), DIMENSION(n_dim), INTENT(IN) :: x
INTEGER , INTENT(IN) :: test
TYPE(PVar) :: s
s%u(1) = 0._dp
s%u(2) = grav*e%u(1)*deriv_bathymetry(test,x(1))
END FUNCTION source_sw
FUNCTION Jacobian_sw(Var,x) RESULT(J)
CLASS(Pvar), INTENT(in) :: Var
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_Vars,n_Vars,n_dim) :: J
REAL(dp) :: Vi2, u
u = Var%u(2)/Var%u(1)
Vi2 = u**2._dp
J=0.
J(1,:,1) = (/ 0.0_dp, 1.0_dp /)
J(2,:,1) = (/ -u**2._dp + grav*Var%u(1), 2.0_dp*u /)
END FUNCTION Jacobian_sw
FUNCTION AbsJacobian_sw(Var,x) RESULT(J)
!compute abs value of jacobian matrix
REAL(dp), DIMENSION(n_dim), PARAMETER:: nn=(/1.0_dp/),xx=(/1.0_dp/)
CLASS(Pvar), INTENT(in) :: Var
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_Vars,n_Vars,n_dim) :: J
REAL(dp) :: Vi2, u, H, eps, p
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
INTEGER:: i
R=rvectors_sw(Var,nn)
L=lvectors_sw(Var,nn)
lambda=evalues_sw(var,xx,nn)
lambda=ABS(lambda)
J(:,:,1)=MATMUL(R,MATMUL(lambda,L))
END FUNCTION AbsJacobian_sw
FUNCTION evalues_sw(Var,x,n) RESULT(lambda)
! eigenvalues: diagonal matrix. It is written as a matrix for ease of calculations
CLASS(PVar), INTENT(in) :: Var
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
REAL(dp) :: un, c
c = SoundSpeed(Var%u(1))
lambda = 0._dp
un = ( Var%u(2)*n(1) )/Var%u(1)
lambda(1,1) = un-c
lambda(2,2) = un+c
END FUNCTION evalues_sw
REAL(dp) FUNCTION spectral_radius_sw(Var,x,n)
! compute the maximum value of eigenvalues:
! max_i {lambda_ii}
CLASS(PVar), INTENT(in) :: Var
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim), INTENT(in) :: n
REAL(dp),DIMENSION(n_Vars,n_Vars) :: lambda
lambda = evalues_sw(Var,x,n)
spectral_radius_sw = MAXVAL(ABS(lambda))
END FUNCTION spectral_radius_sw
FUNCTION rvectors_sw(Q,n) RESULT(R)
! right e-vectors
! assume ||n||=1
CLASS(PVar), INTENT(in) :: Q
REAL(dp), DIMENSION(n_dim) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp) :: rho, u, a
rho = Q%U(1)
u = Q%U(2)/Q%U(1)
a = SoundSpeed(rho)
R(:,1) = (/ 1.0_dp, u-a /)
R(:,2) = (/ 1.0_dp, u+a /)
END FUNCTION rvectors_sw
FUNCTION lvectors_sw(Q,n) RESULT(L)
! left e-vectors
! assumes ||n||=1
CLASS(PVar), INTENT(in) :: Q
REAL(dp), DIMENSION(n_dim) :: n
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp) :: rho, u, p, a, E, H, gmm1, eps
R=rvectors_sw(Q,n)
L=inverse(R)
END FUNCTION lvectors_sw
FUNCTION Nmat_sw(e, n_ord, grad, x) RESULT (Nmat)
CLASS(Pvar), INTENT(in) :: e
INTEGER, INTENT(in) :: n_ord
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim,n_ord), INTENT(in) :: grad
REAL(dp), DIMENSION(n_vars,n_vars) :: Nmat
REAL(dp), DIMENSION(n_vars, n_vars, n_dim) :: J
INTEGER:: l
J= Jacobian_sw(e,x)
Nmat=0_dp
DO l=1, n_ord
Nmat = Nmat + ABS( grad(1,l)*J(1,1,1) )
ENDDO
Nmat =0._dp!Inverse(Nmat)
END FUNCTION Nmat_sw
FUNCTION min_mat_sw(e, x, n, alpha) RESULT (Ap)
! in this A must be the result of tensor*vec where tensor are
! the jacobian evaluated for class e. It computes the negative part of A
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), INTENT(in) :: alpha
REAL(dp), DIMENSION(n_dim), INTENT(IN) :: n
REAL(dp), DIMENSION(N_vars, N_vars) :: Ap
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
lambda = evalues_sw(e,x,n)
R = rvectors_sw(e,n)
L = lvectors_sw(e,n)
Ap = MATMUL( R, MATMUL( MIN(lambda(:,:),alpha), L) )
END FUNCTION min_mat_sw
FUNCTION max_mat_sw(e,x,n,alpha) RESULT (Ap)
! in this A must be the result of tensor*vec where tensor are
! the jacobian evaluated for class e. It computes the negative part of A
CLASS(PVar), INTENT(in) :: e
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), INTENT(in) :: alpha
REAL(dp), DIMENSION(n_dim), INTENT(in) :: n
REAL(dp), DIMENSION(N_vars, N_vars) :: Ap
REAL(dp), DIMENSION(n_Vars,n_Vars) :: lambda
REAL(dp), DIMENSION(n_Vars,n_Vars) :: R
REAL(dp), DIMENSION(n_Vars,n_Vars) :: L
lambda = evalues_sw(e,x,n)
R = rvectors_sw(e,n)
L = lvectors_sw(e,n)
Ap = MATMUL( R, MATMUL( MAX(lambda(:,:),alpha), L) )
END FUNCTION max_mat_sw
!--------------------------
END MODULE variable_def
......@@ -24,18 +24,19 @@ MODULE variable_def
IMPLICIT NONE
INTEGER, PUBLIC, PARAMETER:: n_vars = 2 ! number of primitive variables
INTEGER, PUBLIC, PARAMETER:: n_dim = 1 ! number of physical dimensions
REAL(8), PARAMETER:: pi=ACOS(-1.) ! pi
REAL(8), PUBLIC, PARAMETER:: a = 1.0
REAL(8), PUBLIC, PARAMETER:: aa = 100., bb = 100.
INTEGER, PUBLIC, PARAMETER:: n_dim = 1 ! number of physical dimensions
REAL(dp), PARAMETER:: pi=ACOS(-1._dp) ! pi
REAL(dp), PUBLIC, PARAMETER:: a = 1.0_dp
REAL(dp), PUBLIC, PARAMETER:: aa = 100._dp, bb = 100._dp
! Type for the vector of primitive variables
TYPE, PUBLIC :: PVar
INTEGER :: NVars = n_vars
REAL(8), DIMENSION(n_vars) :: U
REAL(dp), DIMENSION(n_vars) :: U
CONTAINS
PROCEDURE, PUBLIC:: flux => flux_w
PROCEDURE, PUBLIC:: source => source_w
PROCEDURE, PUBLIC:: evalues => evalues_w
PROCEDURE, PUBLIC:: spectral_radius => spectral_radius_w
PROCEDURE, PUBLIC:: rvectors => rvectors_w
......@@ -76,11 +77,11 @@ CONTAINS
! evaluate a roe average to estimate a rough speed for
! Burman jump operator
CLASS(Pvar), INTENT(in):: e
REAL(8), DIMENSION(N_Vars), INTENT(in):: u
REAL(8), DIMENSION(n_dim), INTENT(in):: n ! here it will be a normal of norme 1
REAL(8), DIMENSION(n_vars,n_vars):: J
REAL(8), DIMENSION(n_vars,n_vars,n_dim):: JJ
REAL(8), DIMENSION(n_dim):: v=0.
REAL(dp), DIMENSION(N_Vars), INTENT(in):: u
REAL(dp), DIMENSION(n_dim), INTENT(in):: n ! here it will be a normal of norme 1
REAL(dp), DIMENSION(n_vars,n_vars):: J
REAL(dp), DIMENSION(n_vars,n_vars,n_dim):: JJ
REAL(dp), DIMENSION(n_dim):: v=0.
JJ=Jacobian_w(e,v)
J(:,:) = JJ(:,:,1)*n(1)
......@@ -88,47 +89,56 @@ CONTAINS
FUNCTION flux_w(e,x) RESULT(f)
CLASS(PVar), INTENT(in) :: e
REAL(8), DIMENSION(n_dim), INTENT(in) :: x
REAL(dp), DIMENSION(n_dim), INTENT(in) :: x
TYPE(PVar), DIMENSION(n_dim) :: f
REAL(8), DIMENSION(n_vars,n_vars,n_dim):: JJ
REAL(dp), DIMENSION(n_vars,n_vars,n_dim):: JJ
JJ=Jacobian_w(e,x)
F(1)%u(:)=MATMUL(JJ(:,:,1),e%u)
END FUNCTION flux_w