Advertisement
krishnab75

Untitled

Jun 8th, 2022
1,798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Fortran 12.93 KB | None | 0 0
  1. *
  2. *----------------------------------------------------------------------*
  3. *                                                                      *
  4. C     Godunov's  Method for the inviscid Burgers's equation            *
  5. *                                                                      *
  6. C     Name of program: HL-BUGOD                                        *
  7. *                                                                      *
  8. C     Purpose: to solve the inviscid Burgers equation                  *
  9. C              using the Godunov first order upwind                    *
  10. C              scheme in conjunction with the exact                    *
  11. C              Riemann solver                                          *
  12. *                                                                      *
  13. C     Input  file: bugod.ini                                           *
  14. C     output file: bugod.out                                           *
  15. *                                                                      *
  16. C     Programer: E. F. Toro                                            *
  17. *                                                                      *
  18. C     Last revision: 31st May 1999                                     *
  19. *                                                                      *
  20. C     Theory is found in Section 5.3.3 of Chapter 5 and                *
  21. C     in Chapt. 6 of Reference 1. See also original references         *
  22. C     quoted in Ref. 1                                                 *
  23. *                                                                      *
  24. C     1. Toro, E. F., "Riemann Solvers and Numerical                   *
  25. C                      Methods for Fluid Dynamics"                     *
  26. C                      Springer-Verlag,                                *
  27. C                      Second Edition, 1999                            *
  28. *                                                                      *
  29. C     This program is part of                                          *
  30. *                                                                      *
  31. C     NUMERICA                                                         *
  32. C     A Library of Source Codes for Teaching,                          *
  33. C     Research and Applications,                                       *
  34. C     by E. F. Toro                                                    *
  35. C     Published by NUMERITEK LTD,                                      *
  36. C     Website: www.numeritek.com                                       *
  37. *                                                                      *
  38. *----------------------------------------------------------------------*
  39. *
  40.       IMPLICIT NONE
  41. *
  42. C     Declaration of variables:
  43. *
  44.       INTEGER CELLS, ITEST, N, NFREQ, NTMAXI
  45. *
  46.       REAL    CFLCOE, DOMLEN, DT, TIME, TIMEOU, TIMETO
  47. *
  48.       COMMON /DATAIN/ CFLCOE, DOMLEN, ITEST, CELLS,
  49.      &                NFREQ, NTMAXI, TIMEOU
  50.       COMMON /DELTAT/ DT
  51. *
  52.       DATA TIMETO /1.0E-07/
  53. *
  54. C     Parameters of problem are read in from file "bugod.ini"
  55. *
  56.       CALL READER
  57. *
  58. C     Initial conditions are set up
  59. *
  60.       CALL INITIA(DOMLEN, ITEST, CELLS)
  61. *
  62.       WRITE(6,*)'-----------------------------------'
  63.       WRITE(6,*)'   Time step N        TIME         '
  64.       WRITE(6,*)'-----------------------------------'
  65. *
  66. C     Time marching procedure
  67. *
  68.       TIME = 0.0
  69. *
  70.       DO 10 N = 1, NTMAXI
  71. *
  72. C        Boundary conditions are set
  73. *
  74.          CALL BCONDI(CELLS)
  75. *
  76. C        Courant-Friedrichs-Lewy (CFL) condition imposed
  77. *
  78.          CALL CFLCON(CFLCOE, CELLS, TIME, TIMEOU)
  79. *
  80.          TIME = TIME + DT
  81. *
  82. C        Intercell numerical fluxes are computed
  83. *
  84.          CALL FLUXES(CELLS)
  85. *
  86. C        Solution is updated according to
  87. C        conservative formula
  88. *
  89.          CALL UPDATE(CELLS)
  90. *
  91.          IF(MOD(N,NFREQ).EQ.0)WRITE(6,20)N, TIME
  92. *
  93. C        Check output time
  94. *
  95.          IF(ABS(TIME - TIMEOU).LE.TIMETO)THEN
  96. *
  97. C           Solution is written to "bugod.out' at
  98. C           specified time TIMEOU
  99. *
  100.             CALL OUTPUT(CELLS)
  101. *
  102.             WRITE(6,*)'-----------------------------------'
  103.             WRITE(6,*)'   Number of time steps = ',N
  104. *
  105.             GOTO 30
  106.          ENDIF
  107. *
  108.  10   CONTINUE
  109. *
  110.  20   FORMAT(I12,6X, F12.7)
  111.  30   CONTINUE
  112. *
  113.       END
  114. *
  115. *----------------------------------------------------------------------*
  116. *
  117.       SUBROUTINE READER
  118. *
  119. C     Purpose: to read initial parameters of the problem
  120. *
  121.       IMPLICIT NONE
  122. *
  123. C     Declaration of variables
  124. *
  125.       INTEGER  CELLS, ITEST, NFREQ, NTMAXI
  126. *
  127.       REAL     CFLCOE, DOMLEN, TIMEOU
  128. *
  129.       COMMON /DATAIN/ CFLCOE, DOMLEN, ITEST, CELLS, NFREQ,
  130.      &                NTMAXI, TIMEOU
  131. *
  132.       OPEN(UNIT = 1,FILE = 'bugod.ini',STATUS = 'UNKNOWN')
  133. *
  134. C     Input variables
  135. *
  136. C     CFLCOE   : Courant number coefficient
  137. C     DOMLEN   : Domain length
  138. C     ITEST    : Test problem
  139. C     CELLS    : Number of cells in domain
  140. C     NFREQ    : Output frequency to screen
  141. C     NTMAXI   : Maximum number of time steps
  142. C     TIMEOU   : Output time
  143. *
  144.       READ(1,*)CFLCOE
  145.       READ(1,*)DOMLEN
  146.       READ(1,*)ITEST
  147.       READ(1,*)CELLS
  148.       READ(1,*)NFREQ
  149.       READ(1,*)NTMAXI
  150.       READ(1,*)TIMEOU
  151. *
  152.       CLOSE(1)
  153. *
  154.       WRITE(6,*)'--------------------------------'
  155.       WRITE(6,*)'Data read in is echoed to screen'
  156.       WRITE(6,*)'--------------------------------'
  157.       WRITE(6,*)'CFLCOE = ',CFLCOE
  158.       WRITE(6,*)'DOMLEN = ',DOMLEN
  159.       WRITE(6,*)'ITEST  = ',ITEST
  160.       WRITE(6,*)'CELLS  = ',CELLS
  161.       WRITE(6,*)'NFREQ  = ',NFREQ
  162.       WRITE(6,*)'NTMAXI = ',NTMAXI
  163.       WRITE(6,*)'TIMEOU = ',TIMEOU
  164.       WRITE(6,*)'--------------------------------'
  165. *
  166.       END
  167. *
  168. *----------------------------------------------------------------------*
  169. *
  170.       SUBROUTINE INITIA(DOMLEN, ITEST, CELLS)
  171. *
  172. C     Purpose: to set initial conditions for solution U
  173. C              and initialise other variables. There are
  174. C              two choices of initial conditions,
  175. C              determined by ITEST
  176. *
  177. C     Main variables
  178. *
  179. C     DX            Spatial mesh  size
  180. C     I             Variable in do loop
  181. C     ITEST         Defines test problem
  182. C     FLUX          Array for intercell fluxes
  183. C     U             Array for numerical solution
  184. C     XPOS          Position along x-axis
  185. C     XRIGHT        Left diaphragm
  186. C     XMIDDL        Middle diaphragm
  187. C     XRIGHT        Right diaphragm
  188. *
  189.       IMPLICIT NONE
  190. *
  191. C     Declaration of variables
  192. *
  193.       INTEGER CELLS, I, ITEST, IDIM
  194. *
  195.       REAL    DOMLEN, DX, FLUX, U, XLEFT, XPOS, XMIDDL,
  196.      &        XRIGHT
  197. *
  198.       PARAMETER (IDIM = 1000)
  199. *
  200.       DIMENSION FLUX(0:IDIM + 1), U(0:IDIM + 1)
  201. *
  202.       COMMON /DELTAX/ DX
  203.       COMMON /FLUXFS/ FLUX
  204.       COMMON /SOLUTI/ U
  205. *
  206. C     Calculate mesh size DX
  207. *
  208.       DX = DOMLEN/REAL(CELLS)
  209. *
  210. C     Initialise arrays
  211. *
  212.       DO 10 I = 0, IDIM + 1
  213.          FLUX(I) = 0.0
  214.          U(I)    = 0.0
  215.  10   CONTINUE
  216. *
  217.       IF(ITEST.EQ.1)THEN
  218. *
  219. C        Test 1: smooth profile
  220. *
  221.          XPOS    = -1.0
  222. *
  223.          DO 20 I = 1,  CELLS
  224.             XPOS = XPOS + 2.0/REAL(CELLS)
  225.             U(I) = EXP(-8.0*XPOS*XPOS)
  226.  20      CONTINUE
  227. *
  228.       ELSE
  229. *
  230. C        Test 2: square waves
  231. *
  232.          XLEFT  = 0.1*DOMLEN
  233.          XMIDDL = 0.5*DOMLEN
  234.          XRIGHT = 0.9*DOMLEN
  235. *
  236.          DO 30 I = 1, CELLS
  237. *
  238.             XPOS = (REAL(I) - 0.5)*DX
  239. *
  240.             IF(XPOS.LT.XLEFT)THEN
  241.                U(I) = -1.0
  242.             ENDIF
  243. *
  244.             IF(XPOS.GE.XLEFT.AND.XPOS.LE.XMIDDL)THEN
  245.                U(I) = 1.0
  246.             ENDIF
  247. *
  248.             IF(XPOS.GT.XMIDDL.AND.XPOS.LE.XRIGHT)THEN
  249.                U(I) = 0.0
  250.             ENDIF
  251. *
  252.             IF(XPOS.GT.XRIGHT)THEN
  253.                U(I) = -1.0
  254.             ENDIF
  255. *
  256.  30      CONTINUE
  257. *
  258.       ENDIF
  259. *
  260.       END
  261. *
  262. *----------------------------------------------------------------------*
  263. *
  264.       SUBROUTINE BCONDI(CELLS)
  265. *
  266. C     Purpose: to apply boundary conditions
  267. *
  268.       IMPLICIT NONE
  269. *
  270. C     Declaration of variables
  271. *
  272.       INTEGER CELLS, IDIM
  273. *
  274.       REAL    U
  275. *
  276.       PARAMETER (IDIM = 1000)
  277. *
  278.       DIMENSION U(0:IDIM + 1)
  279. *
  280.       COMMON /SOLUTI/ U
  281. *
  282. C     Left boundary, periodic boundary condition
  283. *
  284.       U(0)  = U(CELLS)
  285. *
  286. C     Right boundary, periodic boundary condition
  287. *
  288.       U(CELLS + 1) =  U(1)
  289. *
  290.       END
  291. *
  292. *----------------------------------------------------------------------*
  293. *
  294.       SUBROUTINE CFLCON(CFLCOE, CELLS, TIME, TIMEOU)
  295. *
  296. C     Purpose: to apply the CFL condition to compute a
  297. C              stable time step DT
  298. *
  299.       IMPLICIT NONE
  300. *
  301. C     Declaration of variables
  302. *
  303.       INTEGER  CELLS, I, IDIM
  304. *
  305.       REAL     CFLCOE, DT, DX, SMAX, TIME, TIMEOU, U
  306. *
  307.       PARAMETER (IDIM = 1000)
  308. *
  309.       DIMENSION U(0:IDIM + 1)
  310. *
  311.       COMMON /SOLUTI/ U
  312.       COMMON /DELTAT/ DT
  313.       COMMON /DELTAX/ DX
  314. *
  315.       SMAX = -1.0E+06
  316. *
  317. C     Find maximum characteristic speed
  318. *
  319.       DO 10 I = 0, CELLS + 1
  320.          IF(ABS(U(I)).GT.SMAX)SMAX = ABS(U(I))
  321.  10   CONTINUE
  322. *
  323.       DT = CFLCOE*DX/SMAX
  324. *
  325. C     Check size of DT to avoid exceeding output time
  326. *
  327.       IF((TIME + DT).GT.TIMEOU)THEN
  328. *
  329. C        Recompute DT
  330. *
  331.          DT = TIMEOU - TIME
  332.       ENDIF
  333. *
  334.       END
  335. *
  336. *----------------------------------------------------------------------*
  337. *
  338.       SUBROUTINE UPDATE(CELLS)
  339. *
  340. C     Purpose: to update the solution to a new time level
  341. C              using the explicit conservative formula
  342. *
  343.       IMPLICIT NONE
  344. *
  345. C     Declaration of variables
  346. *
  347.       INTEGER I, CELLS, IDIM
  348. *
  349.       REAL    DT, DX, DTODX, FLUX, U
  350. *
  351.       PARAMETER (IDIM = 1000)
  352. *
  353.       DIMENSION U(0:IDIM + 1), FLUX(0:IDIM + 1)
  354. *
  355.       COMMON /DELTAT/ DT
  356.       COMMON /DELTAX/ DX
  357.       COMMON /FLUXFS/ FLUX
  358.       COMMON /SOLUTI/ U
  359. *
  360.       DTODX = DT/DX
  361. *
  362.       DO 10 I = 1, CELLS
  363.          U(I) = U(I) + DTODX*(FLUX(I-1) - FLUX(I))
  364.  10   CONTINUE
  365. *
  366.       END
  367. *
  368. *----------------------------------------------------------------------*
  369. *
  370.       SUBROUTINE OUTPUT(CELLS)
  371. *
  372. C     Purpose: to output the solution at a specified time
  373. C              TIMEOU
  374. *
  375.       IMPLICIT NONE
  376. *
  377. C     Declaration of variables
  378. *
  379.       INTEGER I, CELLS, IDIM
  380. *
  381.       REAL    DX, U, XPOS
  382. *
  383.       PARAMETER (IDIM = 1000)
  384. *
  385.       DIMENSION U(0:IDIM + 1)
  386. *
  387.       COMMON /DELTAX/ DX
  388.       COMMON /SOLUTI/ U
  389. *
  390.       OPEN(UNIT = 1,FILE = 'bugod.out',STATUS = 'UNKNOWN')
  391. *
  392.       DO 10 I = 1, CELLS
  393. *
  394. C        Find position of cell centre
  395. *
  396.          XPOS = (REAL(I) - 0.5)*DX
  397.          WRITE(1,20)XPOS, U(I)
  398. *
  399.  10   CONTINUE
  400. *
  401.       CLOSE(1)
  402. *
  403.  20   FORMAT(2(4X, F10.5))
  404. *
  405.       END
  406. *
  407. *----------------------------------------------------------------------*
  408. *
  409.       SUBROUTINE FLUXES(CELLS)
  410. *
  411. C     Purpose: to compute intercell fluxes according to
  412. C              the Godunov first-order upwind method,
  413. C              in conjunction with the exact Riemann
  414. C              solver
  415. *
  416.       IMPLICIT NONE
  417. *
  418. C     Declaration of variables
  419. *
  420.       INTEGER CELLS, I, IDIM
  421. *
  422.       REAL    FLUX, U, UL, UR, USTAR
  423. *
  424.       PARAMETER (IDIM = 1000)
  425. *
  426.       DIMENSION FLUX(0:IDIM + 1), U(0:IDIM + 1)
  427. *
  428.       COMMON /FLUXFS/ FLUX
  429.       COMMON /SOLUTI/ U
  430. *
  431. C     Compute intercell flux FLUX(I), I = 0, CELLS
  432. C     Solution of Riemann problem RP(I, I+1) is stored
  433. C     in FLUX(I)
  434. *
  435.       DO 10 I = 0, CELLS
  436. *
  437. C        Define states UL (Left) and UR (Right) for local
  438. C        Riemann problem  RP(UL, UR)
  439. *
  440.          UL = U(I)
  441.          UR = U(I+1)
  442. *
  443. C        Solve the Riemann problem RP(UL, UR) exactly
  444. *
  445.          CALL RIEMANN(UL, UR, USTAR)
  446. *
  447. C        Compute Godunov intercell flux
  448. *
  449.          FLUX(I) = 0.5*USTAR*USTAR
  450. *
  451.  10   CONTINUE
  452. *
  453.       END
  454. *
  455. *----------------------------------------------------------------------*
  456. *
  457.       SUBROUTINE RIEMANN(UL, UR, USTAR)
  458. *
  459. C     Purpose: to solve the Riemann problem for the inviscid
  460. C              Burgers equation exactly.
  461. *
  462. C     Variables:
  463. *
  464. C     UL         Left data state
  465. C     UR         Right data state
  466. C     S          Shock speed
  467. C     USTAR      Sampled state
  468. *
  469.       IMPLICIT NONE
  470. *
  471.       REAL   S, UL, UR, USTAR
  472. *
  473.       IF(UL.GT.UR)THEN
  474. *
  475. C        Solution is a shock wave
  476. C        Compute shock speed S
  477. *
  478.          S = 0.5*(UL + UR)
  479. *
  480. C        Sample the state along the t-axis
  481. *
  482.          IF(S.GE.0.0)THEN
  483.             USTAR = UL
  484.          ELSE
  485.             USTAR = UR
  486.          ENDIF
  487. *
  488.       ELSE
  489. *
  490. C        Solution is a rarefaction wave.
  491. C        There are 3 cases:
  492. *
  493.          IF(UL.GE.0.0)THEN
  494. *
  495. C           Right supersonic rarefaction
  496. *
  497.             USTAR = UL
  498.          ENDIF
  499. *
  500.          IF(UR.LE.0.0)THEN
  501. *
  502. C           Left supersonic rarefaction
  503. *
  504.             USTAR = UR
  505.          ENDIF
  506. *
  507.          IF(UL.LE.0.0.AND.UR.GE.0.0)THEN
  508. *
  509. C           Transonic rarefaction
  510. *
  511.             USTAR = 0.0
  512.          ENDIF
  513. *
  514.       ENDIF
  515. *
  516.       END
  517. *
  518. *----------------------------------------------------------------------*
  519. *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement