Gitdeeper4 commited on
Commit
16c4441
·
1 Parent(s): 12834b7

إضافة ملف nswe_solver.f90 في المسار الصحيح

Browse files
Files changed (1) hide show
  1. src/core/nswe_solver.f90 +88 -0
src/core/nswe_solver.f90 ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ! TSU-WAVE NSWE Solver (Fortran 90)
2
+ ! Nonlinear Shallow-Water Equations for Tsunami Propagation
3
+
4
+ module nswe_solver
5
+ implicit none
6
+ real, parameter :: g = 9.81 ! gravity
7
+ real, parameter :: rho = 1025.0 ! seawater density
8
+
9
+ contains
10
+
11
+ subroutine solve_nswe(eta, u, v, H, nx, ny, dt, dx, dy, nt)
12
+ ! Solve 2D Nonlinear Shallow-Water Equations
13
+ implicit none
14
+ integer, intent(in) :: nx, ny, nt
15
+ real, intent(inout) :: eta(nx, ny), u(nx, ny), v(nx, ny)
16
+ real, intent(in) :: H(nx, ny)
17
+ real, intent(in) :: dt, dx, dy
18
+
19
+ integer :: i, j, t
20
+ real :: eta_new(nx, ny), u_new(nx, ny), v_new(nx, ny)
21
+ real :: du_dx, du_dy, dv_dx, dv_dy, deta_dx, deta_dy
22
+
23
+ do t = 1, nt
24
+ ! Continuity equation
25
+ do i = 2, nx-1
26
+ do j = 2, ny-1
27
+ du_dx = (u(i+1,j) - u(i-1,j)) / (2*dx)
28
+ dv_dy = (v(i,j+1) - v(i,j-1)) / (2*dy)
29
+ eta_new(i,j) = eta(i,j) - dt * ((H(i,j) + eta(i,j)) * (du_dx + dv_dy))
30
+ end do
31
+ end do
32
+
33
+ ! Momentum equations (simplified)
34
+ do i = 2, nx-1
35
+ do j = 2, ny-1
36
+ deta_dx = (eta_new(i+1,j) - eta_new(i-1,j)) / (2*dx)
37
+ u_new(i,j) = u(i,j) - dt * (u(i,j) * (u(i+1,j)-u(i-1,j))/(2*dx) + &
38
+ v(i,j) * (u(i,j+1)-u(i,j-1))/(2*dy) + &
39
+ g * deta_dx)
40
+
41
+ deta_dy = (eta_new(i,j+1) - eta_new(i,j-1)) / (2*dy)
42
+ v_new(i,j) = v(i,j) - dt * (u(i,j) * (v(i+1,j)-v(i-1,j))/(2*dx) + &
43
+ v(i,j) * (v(i,j+1)-v(i,j-1))/(2*dy) + &
44
+ g * deta_dy)
45
+ end do
46
+ end do
47
+
48
+ ! Update boundaries
49
+ call apply_boundary_conditions(eta_new, u_new, v_new, nx, ny)
50
+
51
+ ! Copy back
52
+ eta = eta_new
53
+ u = u_new
54
+ v = v_new
55
+ end do
56
+
57
+ end subroutine solve_nswe
58
+
59
+ subroutine apply_boundary_conditions(eta, u, v, nx, ny)
60
+ implicit none
61
+ integer, intent(in) :: nx, ny
62
+ real, intent(inout) :: eta(nx, ny), u(nx, ny), v(nx, ny)
63
+ integer :: i, j
64
+
65
+ ! Zero-gradient at boundaries
66
+ ! Left boundary
67
+ eta(1,:) = eta(2,:)
68
+ u(1,:) = u(2,:)
69
+ v(1,:) = v(2,:)
70
+
71
+ ! Right boundary
72
+ eta(nx,:) = eta(nx-1,:)
73
+ u(nx,:) = u(nx-1,:)
74
+ v(nx,:) = v(nx-1,:)
75
+
76
+ ! Bottom boundary
77
+ eta(:,1) = eta(:,2)
78
+ u(:,1) = u(:,2)
79
+ v(:,1) = v(:,2)
80
+
81
+ ! Top boundary
82
+ eta(:,ny) = eta(:,ny-1)
83
+ u(:,ny) = u(:,ny-1)
84
+ v(:,ny) = v(:,ny-1)
85
+
86
+ end subroutine apply_boundary_conditions
87
+
88
+ end module nswe_solver