|
| 1 | +! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ! |
| 2 | +! |
| 3 | + |
| 4 | +! Official Repository : https://github.com/FluidNumerics/self/ |
| 5 | +! |
| 6 | +! Copyright © 2024 Fluid Numerics LLC |
| 7 | +! |
| 8 | +! Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
| 9 | +! |
| 10 | +! 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
| 11 | +! |
| 12 | +! 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in |
| 13 | +! the documentation and/or other materials provided with the distribution. |
| 14 | +! |
| 15 | +! 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from |
| 16 | +! this software without specific prior written permission. |
| 17 | +! |
| 18 | +! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | +! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | +! HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 21 | +! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | +! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | +! THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | +! |
| 25 | +! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ! |
| 26 | + |
| 27 | +program linear_shallow_water2d_rossbywave |
| 28 | + use self_data |
| 29 | + use self_LinearShallowWater2D |
| 30 | + use self_mesh_2d |
| 31 | + |
| 32 | + implicit none |
| 33 | + character(SELF_INTEGRATOR_LENGTH),parameter :: integrator = 'rk3' ! Which integrator method |
| 34 | + integer,parameter :: controlDegree = 7 ! Degree of control polynomial |
| 35 | + integer,parameter :: targetDegree = 16 ! Degree of target polynomial |
| 36 | + real(prec),parameter :: dt = 0.5_prec ! Time-step size |
| 37 | + real(prec),parameter :: endtime = 1000.0_prec ! (s); 1-day |
| 38 | + real(prec),parameter :: f0 = 0.0_prec !10.0_prec**(-4) ! reference coriolis parameter (1/s) |
| 39 | + real(prec),parameter :: beta = 0.0_prec ! 10.0_prec**(-11) ! beta parameter (1/ms) |
| 40 | + real(prec),parameter :: iointerval = 10.0 ! Write files 10 times per day |
| 41 | + |
| 42 | + real(prec) :: e0,ef ! Initial and final entropy |
| 43 | + type(LinearShallowWater2D) :: modelobj ! Shallow water model |
| 44 | + type(Lagrange),target :: interp ! Interpolant |
| 45 | + integer :: bcids(1:4) ! Boundary conditions for structured mesh |
| 46 | + type(Mesh2D),target :: mesh ! Mesh class |
| 47 | + type(SEMQuad),target :: geometry ! Geometry class |
| 48 | + |
| 49 | + real(prec),parameter :: g = 10.0_prec ! Acceleration due to gravity |
| 50 | + real(prec),parameter :: H = 1000.0_prec ! Uniform resting depth |
| 51 | + real(prec),parameter :: dx = 10.0_prec**(5) ! grid spacing in x-direction (m) |
| 52 | + real(prec),parameter :: dy = 10.0_prec**(5) ! grid spacing in y-direction (m) |
| 53 | + integer,parameter :: ntx = 2 ! number of tiles in x-direction |
| 54 | + integer,parameter :: nty = 2 ! number of tiles in y-direction |
| 55 | + integer,parameter :: nxp = 5 ! number of element per tile in x-direction |
| 56 | + integer,parameter :: nyp = 5 ! number of element per tile in y-direction |
| 57 | + |
| 58 | + ! Set no normal flow boundary conditions |
| 59 | + bcids(1:4) = [SELF_BC_NONORMALFLOW, & ! South |
| 60 | + SELF_BC_NONORMALFLOW, & ! East |
| 61 | + SELF_BC_NONORMALFLOW, & ! North |
| 62 | + SELF_BC_NONORMALFLOW] ! West |
| 63 | + |
| 64 | + ! Create a uniform block mesh |
| 65 | + call mesh%StructuredMesh(nxp,nyp,ntx,nty,dx,dy,bcids) |
| 66 | + |
| 67 | + ! Create an interpolant |
| 68 | + call interp%Init(N=controlDegree, & |
| 69 | + controlNodeType=GAUSS, & |
| 70 | + M=targetDegree, & |
| 71 | + targetNodeType=UNIFORM) |
| 72 | + |
| 73 | + ! Generate geometry (metric terms) from the mesh elements |
| 74 | + call geometry%Init(interp,mesh%nElem) |
| 75 | + call geometry%GenerateFromMesh(mesh) |
| 76 | + |
| 77 | + ! Initialize the model |
| 78 | + call modelobj%Init(mesh,geometry) |
| 79 | + modelobj%prescribed_bcs_enabled = .false. ! Disables prescribed boundary condition block for gpu accelerated implementations |
| 80 | + modelobj%tecplot_enabled = .false. ! Disables tecplot output |
| 81 | + |
| 82 | + ! Set the resting surface height and gravity |
| 83 | + modelobj%H = H |
| 84 | + modelobj%g = g |
| 85 | + |
| 86 | + ! Set the initial conditions |
| 87 | + call modelobj%solution%SetEquation(1,'f = 0') |
| 88 | + call modelobj%solution%SetEquation(2,'f = 0') |
| 89 | + call modelobj%solution%SetEquation(3,'f = 0.01*exp( -( (x-500000.0)^2 + (y-500000.0)^2 )/(2.0*(10.0^10)) )') |
| 90 | + call modelobj%solution%SetInteriorFromEquation(geometry,0.0_prec) |
| 91 | + |
| 92 | + ! call modelobj%SetCoriolis(f0,beta) |
| 93 | + !call modelobj%DiagnoseGeostrophicVelocity() |
| 94 | + |
| 95 | + call modelobj%WriteModel() |
| 96 | + call modelobj%IncrementIOCounter() |
| 97 | + |
| 98 | + call modelobj%CalculateEntropy() |
| 99 | + call modelobj%ReportEntropy() |
| 100 | + call modelobj%ReportMetrics() |
| 101 | + e0 = modelobj%entropy |
| 102 | + |
| 103 | + ! Set the model's time integration method |
| 104 | + call modelobj%SetTimeIntegrator(integrator) |
| 105 | + |
| 106 | + ! forward step the model to `endtime` using a time step |
| 107 | + ! of `dt` and outputing model data every `iointerval` |
| 108 | + call modelobj%ForwardStep(endtime,dt,iointerval) |
| 109 | + |
| 110 | + ef = modelobj%entropy |
| 111 | + |
| 112 | + print*,e0,ef |
| 113 | + if(abs(ef-e0) > epsilon(e0)) then |
| 114 | + print*,"Error: Final entropy greater than initial entropy! ",e0,ef |
| 115 | + stop 1 |
| 116 | + endif |
| 117 | + |
| 118 | + ! Clean up |
| 119 | + call modelobj%free() |
| 120 | + call mesh%free() |
| 121 | + call geometry%free() |
| 122 | + call interp%free() |
| 123 | + |
| 124 | +endprogram linear_shallow_water2d_rossbywave |
0 commit comments