 SUBROUTINE bal2prim(w)
!=========================== DOCUMENTATION ============================= 
!DOCDEBh*    PHY/Bal2Prim  *
!
!    NOM
! bal2prim(w)
!
!    DESCRIPTION 
!*
! Calcul des variables primitives a partir des variables conservatives 
! Calculating primitive variables from conservative variables 
!*
! 
!    ENTREES / INPUT
! w    : objet de type "state" contenant les variables conservatives et primitives
!      / object of type "state" containing conservative and primitive variables
!
!    SORTIES / OUTPUT
! w    : objet de type "state" contenant les variables conservatives et primitives
!      / object of type "state" containing 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,p,phi,r0,h
!=========================== DEBUT DU CODE EXECUTABLE ==================
!-------  Initialisations communes

  SELECT CASE (imodel_phy)
 
  CASE (2) ! bifluide isotherme non conservatif
        r=w%vbal%v(1)
        phi=w%vbal%v(5)
        r0=phi*rho0A_phy+(1.d0-phi)*rho0W_phy
        p=p0_phy+c_phy**2*(r-r0)

        w%vprim%v(1)=r
        w%vprim%v(2)=w%vbal%v(2)/r
        w%vprim%v(3)=w%vbal%v(3)/r
        w%vprim%v(4)=w%vbal%v(4)/r
        w%vprim%v(5)=p

!----------------------------------------------------
  CASE (1) ! SaintVenant
      h=w%vbal%v(1)
      if (h <= hzero_phy) then      
        h=0.d0
        u1=0.d0
        u2=0.d0
      else
        u1=w%vbal%v(2)/h
        u2=w%vbal%v(3)/h
      endif
      w%vprim%v(1)=h
      w%vprim%v(2)=u1
      w%vprim%v(3)=u2
      
  CASE DEFAULT 
       call print_err('BAL2PRIM','Physical model not defined')

 !----------------------------------------------------
  END SELECT
!===========================   FIN DE LA ROUTINE    ====================
END SUBROUTINE bal2prim
!DOCFIN