 SUBROUTINE prim2bal(w)
!=========================== DOCUMENTATION ============================= 
!DOCDEBh*    PHY/prim2bal  *
!
!    NOM
! prim2bal(w)
!    DESCRIPTION 
!*
! Calcul des variables conservatives a partir des variables primitives 
! Calculating conservative variables from primitive variables 
!*
! 
!    ENTREES / INPUT
! w    : objet de type "state" contenant les variables conservatives et primitives
!      / object of type "state" containing the conservative and primitive variables
!
!    SORTIES / OUTPUT
! w    : objet de type "state" contenant les variables conservatives et primitives
!      / object of type "state" containing the conservative and primitive variables
!
!    SOURCE
! Ce logiciel est regi par la licence [CeCILL-B]
! This software is governed by the [CeCILL-B] license
!=========================== DEBUT DES DECLARATIONS ==================== 
!.1-----  Implicit, Use
  use phy_typ
  IMPLICIT NONE
!.2-----  Declaration
  type(state),intent(inout) :: w !! Variables d etat / State variables
  real(kind=kind(0.d0))     :: r,u1,u2,u3,p,phi,h
!=========================== DEBUT DU CODE EXECUTABLE ==================

  SELECT CASE (imodel_phy)

!----------------------------------------------------
      CASE (2) ! bifluide isotherme
          r = w%vprim%v(1)  
          u1= w%vprim%v(2)
          u2= w%vprim%v(3)
          u3= w%vprim%v(4)
          p = w%vprim%v(5)
          phi=((p-p0_phy)/c_phy**2+rho0W_phy-r)/(rho0W_phy-rho0A_phy)

          IF (phi.gt.1.d0) phi=1.d0
          IF (phi.lt.0.d0) phi=0.d0

          w%vbal%v(1)=r
          w%vbal%v(2)=r*u1
          w%vbal%v(3)=r*u2
          w%vbal%v(4)=r*u3
          w%vbal%v(5)=phi

!----------------------------------------------------
      CASE (1) ! Saint Venant
          h=w%vprim%v(1)
          u1=w%vprim%v(2)
          u2=w%vprim%v(3)
          w%vbal%v(1)=h
          w%vbal%v(2)=h*u1
          w%vbal%v(3)=h*u2

  END SELECT
!===========================   FIN DE LA ROUTINE    ====================
END SUBROUTINE prim2bal
!DOCFIN