forked from maxrudolph/gerya-julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.jl
112 lines (107 loc) · 3.38 KB
/
Grid.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
struct CartesianGrid
x::Array{Float64,1}
y::Array{Float64,1}
xc::Array{Float64,1}
yc::Array{Float64,1}
nx::Int64
ny::Int64
W::Float64
H::Float64
yperiodic::Bool
xperiodic::Bool
#dx::Float64
#dy::Float64
function CartesianGrid(W::Float64,H::Float64,nx::Int,ny::Int)
dx = W/(nx-1)
dy = H/(ny-1)
new(LinRange(0,W,nx),LinRange(0,H,ny),
LinRange(0-dx/2,W+dx/2,nx+1),LinRange(0-dy/2,H+dy/2,ny+1),
nx,ny,W,H,false,false)#,W/(nx-1),H/(ny-1))
end
end
# struct CylindricalGrid
# r::Array{Float64,1}
# z::Array{Float64,1}
# rc::Array{Float64,1}
# zc::Array{Float64,1}
# nr::Int64
# nz::Int64
# W::Float64
# H::Float64
# #dx::Float64
# #dy::Float64
# function CylindricalGrid(W::Float64,H::Float64,nr::Int,nz::Int)
# dr = W/(nr-1)
# dz = H/(nz-1)
# new(LinRange(0,W,nr),LinRange(0,H,nz),
# LinRange(0-dr/2,W+dz/2,nr+1),LinRange(0-dz/2,H+dz/2,nz+1),
# nr,nz,W,H)#,W/(nx-1),H/(ny-1))
# end
# end
struct ScalarField
#
# This is a data structure to hold data defined on a (staggered) grid.
# stagx and stagy are meant to indicate the offset (-1 or 0) in the x and y directions
# Name is a field name, to be used in visualization
# data contains the actual data.
#
stagx::Int64
stagy::Int64
name::String
data::Matrix{Float64}
function GridField(stagx::Int64,stagy::Int64,name::String,data::Matrix{Float64})
new(stagx,stagy,name,data)
end
end
struct VectorField
#
# This is a data structure to hold data defined on a (staggered) grid.
# stagx and stagy are meant to indicate the offset (-1 or 0) in the x and y directions
# Name is a field name, to be used in visualization
# data contains the actual data.
#
stagx::Int64
stagy::Int64
components::Int64
name::String
data::Array{Float64,3}
function GridField(stagx::Int64,stagy::Int64,components,name::String,data)
new(stagx,stagy,components,name,data)
end
end
struct EquatorialGrid
#
# This data structure represents an equatorial slice
# r is the radial coordinate
# psi is the azimuthal coordinate
# nr is the number of nodes in the radial direction
# npsi is the number of nodes in the azimuthal direction
# periodic indicates whether the grid is periodic (i.e. a complete spherical slice or a chunk)
#
r::Vector{Float64}
psi::Vector{Float64}
rc::Vector{Float64}
psic::Vector{Float64}
nr::Int64
npsi::Int64
periodic::Bool
function EquatorialGrid(psi_max::Float64,npsi::Int64,r_min::Float64,r_max::Float64,nr::Int64; periodic::Bool=false)
#
# Construct a new equatorial grid with psi_min <= psi <= psi_max and r_min <= r <= r_max
# if psi_max is 'close' to 2*pi, this is a complete spherical slice and periodic is set to true.
#
if psi_max ≈ 2.0*pi || periodic
periodic = true
else
periodic = false
end
psi_min = 0.0
dpsi = (psi_max-psi_min)/(npsi-1)
dr = (r_max-r_min)/(nr-1)
psi = LinRange(psi_min,psi_max,npsi)
r = LinRange(r_min,r_max,nr)
rc = LinRange(r_min-dr/2.,r_max+dr/2.,nr+1)
psic = LinRange(psi_min-dpsi/2.,psi_max+dpsi/2.,npsi+1)
new(r,psi,rc,psic,nr,npsi,periodic)
end
end