!======================================================================== ! BEARCLAW Boundary Embedded Adaptive Refinement Conservation LAW package !======================================================================== ! (c) Copyright Sorin Mitran, 2000 ! Department of Applied Mathematics ! University of Washington ! mitran@amath.washington.edu ! ----------------------------------------------------------------------- ! This code may be freely used for educational and research purposes. ! For any other use please contact the author. ! ----------------------------------------------------------------------- ! File: problem.f90 ! Purpose: Definition of problem specific data and procedures ! Contains: ! setprob - Initialize problem parameters ! qinit - Initialize field variables ! b4step - Called prior to each time step ! setaux - Initialize auxilliary variable fields ! src - Compute source terms ! physflux - Compute the physical flux, related quantities ! Compute wave decomposition ! ! Comments: This module is problem specific and must be written by the ! user. For exampels see the BEARCLAW documentation and also ! the examples and applications directories ! ! The encapsulation of all problem specific data and routines ! and data into a module is useful in exposing data that needs ! to be shared. ! Application: Euler equations, shock tube problem ! Contains: ! Revision History: Ver. 1.0 Oct. 2001 Sorin Mitran ! ----------------------------------------------------------------------- !************* MODULE problem !************* ! User definitions of data structures associated with each node USE NodeInfoDef IMPLICIT NONE ! It's safer to require explicit declarations SAVE ! Save module information PRIVATE ! Everything is implicitly private, i.e. accessible only ! to this module. ! These are the public entry points (acessible to other modules) PUBLIC setprob,qinit,b4step,setaux,src,physflux,problemBC,afterstep,problemIO ! Problem specific global variables: ! - Problem parameters REAL (KIND=qPrec) :: gamma,gamma1 REAL (KIND=qPrec) :: rhol,rhoul,el,rhor,rhour,er ! INTEGER, PARAMETER :: OK=0 REAL (KIND=qPrec), PARAMETER :: zero=0., half=0.5, one=1., two=2. !======= CONTAINS !======= SUBROUTINE setprob ! User definitions of data structures associated with each node USE NodeInfoDef REAL (KIND=qPrec) :: ul,pl,ur,pr ! Set the initial shock tube states OPEN(UNIT=7,FILE='setprob.data',STATUS='old',FORM='formatted') READ(7,*) gamma gamma1 = gamma - 1.d0 READ(7,*) rhol,ul,pl READ(7,*) rhor,ur,pr ! data in left state rhoul = rhol*ul el = pl/gamma1 + 0.5d0*rhol*ul**2 ! data in right state rhour = rhor*ur er = pr/gamma1 + 0.5d0*rhor*ur**2 CLOSE(7) END SUBROUTINE setprob SUBROUTINE problemBC(Info) ! User definitions of data structures associated with each node USE NodeInfoDef ! Interface declarations TYPE (NodeInfo) :: Info ! Data associated with this grid ! Internal declarations END SUBROUTINE problemBC SUBROUTINE qinit(Info) ! User definitions of data structures associated with each node USE NodeInfoDef ! Interface declarations TYPE (NodeInfo) :: Info ! Data associated with this grid ! Internal declarations INTEGER i REAL (KIND=xPrec), PARAMETER :: xDiscontinuity = 0.5 REAL (KIND=xPrec) :: x ! x=Info%Xlower(1)+Info%dX(1)/2.0 DO i=1,Info%mX(1) IF (xInfo%q1D SELECT CASE (irequest) CASE (Initialize) ! Allocate local work space ALLOCATE(sqrtrho(1-mbc:mx+mbc),pres(1-mbc:mx+mbc), & h(1-mbc:mx+mbc),c(1-mbc:mx+mbc),rho(1-mbc:mx+mbc), & u(1-mbc:mx+mbc), & STAT=iError) IF (iError/=OK) THEN PRINT *,'Cannot allocate work space in problem module, physflux' STOP END IF CASE (Finalize) ! Release local work space DEALLOCATE(sqrtrho,pres,h,c,rho,u,STAT=iError) IF (iError/=OK) THEN PRINT *,'Cannot allocate work space in problem module, physflux' STOP END IF CASE (RequestFluxes) IF (MINVAL(q1D(1-mbc:mx+mbc,1))<=zero) THEN PRINT *,'Error: Negative or zero density in physflux.' PRINT '(1x,a6,1x,32(f7.4,1x))','rho= ',q1D(1-mbc:mx+mbc,1) STOP END IF ! Compute cell centered quantities rho(1-mbc:mx+mbc) = q1D(1-mbc:mx+mbc,1) u(1-mbc:mx+mbc) = q1D(1-mbc:mx+mbc,2)/rho(1-mbc:mx+mbc) sqrtrho(1-mbc:mx+mbc) = SQRT(rho(1-mbc:mx+mbc)) pres(1-mbc:mx+mbc) = gamma1 * & ( q1D(1-mbc:mx+mbc,3) - half*q1D(1-mbc:mx+mbc,2)*u(1-mbc:mx+mbc) ) c(1-mbc:mx+mbc) = gamma*pres(1-mbc:mx+mbc)/rho(1-mbc:mx+mbc) IF (MINVAL(c(1-mbc:mx+mbc))<=zero) THEN PRINT *,'Error: Non-physical centered sound velocity in physflux.' PRINT '(1x,a6,1x,32(f7.4,1x))','c**2 = ',c(1-mbc:mx+mbc) STOP END IF c(1-mbc:mx+mbc) = SQRT(c(1-mbc:mx+mbc)) h(1-mbc:mx+mbc) = (q1D(1-mbc:mx+mbc,3) + pres(1-mbc:mx+mbc)) / & rho(1-mbc:mx+mbc) ! Compute the physical fluxes at cell centers f(1-mbc:mx+mbc,1)=q1D(1-mbc:mx+mbc,2) f(1-mbc:mx+mbc,2)=f(1-mbc:mx+mbc,1)*u(1-mbc:mx+mbc)+pres(1-mbc:mx+mbc) f(1-mbc:mx+mbc,3)=f(1-mbc:mx+mbc,1)*h(1-mbc:mx+mbc) CASE (RequestSpeeds) ! Not coded. Fill in later CASE (RequestJacobians) ! Not coded. Fill in later CASE DEFAULT PRINT *,'Error: the solver module Scheme.f90 emitted a request that' PRINT *,'is not implemented in the problem module problem.f90' STOP END SELECT END SUBROUTINE physflux !***************** END MODULE problem !*****************