-
Notifications
You must be signed in to change notification settings - Fork 13
/
domainVariables.jl
173 lines (156 loc) · 5.08 KB
/
domainVariables.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# ===============================
# Written by AAE
# TU Delft, Spring 2014
# simulkade.com
# Last edited: 30 December, 2014
# ===============================
# =====================================================================
# 2014-12-30: - cell variables can be created including bounddary cells
# =====================================================================
# ============================================================
"""
creates a cell variable over the domain m and assigns value phi0 to it
function createCellVariable(m::MeshStructure, phi0::Real)
"""
function createCellVariable(m::MeshStructure, phi0::Real)
# creates a cell variable and assigns value phi0 to it
CellValue(m, phi0*ones(tuple(m.dims.+2...)))
end
function createCellVariable(phi::CellValue)
# similar to copyCell
CellValue(phi.domain, Base.copy(phi.value))
end
# ============================================================
function createCellVariable(m::MeshStructure, phi0::Array{T}) where T<:Real
# creates a cell variable and assigns value phi0 to it
if prod(m.dims.+2)==length(phi0)
CellValue(m, phi0)
elseif prod(m.dims)==length(phi0)
d=m.dimension
phival = zeros(tuple(m.dims.+2...))
BC = createBC(m) # Neumann boundaries
if d==1 || d==1.5
phival[2:end-1] .= phi0
elseif d==2 d==2 || d==2.5 || d==2.8
phival[2:end-1, 2:end-1] .= phi0
elseif d==3 || d==3.2
phival[2:end-1,2:end-1,2:end-1] .= phi0
end
phi = CellValue(m, phival)
cellBoundary!(phi, BC)
else
error("JFVM: Matrix must be the same size as the domain.")
end
end
# ==============================================================
function createCellVariable(m::MeshStructure, phi0::Array{T}, BC::BoundaryCondition) where T<:Real
# creates a cell variable and assigns value phi0 to it
if prod(m.dims.+2)==length(phi0)
error("JFVM: Matrix must be the same size as the domain.")
elseif prod(m.dims)==length(phi0)
d=m.dimension
phival = zeros(tuple(m.dims.+2...))
if d==1 || d==1.5
phival[2:end-1] .= phi0
elseif d==2 || d==2.5 || d==2.8
phival[2:end-1, 2:end-1] .= phi0
elseif d==3 || d==3.2
phival[2:end-1,2:end-1,2:end-1] .= phi0
end
phi = CellValue(m, phival)
cellBoundary!(phi, BC)
else
error("JFVM: Matrix must be the same size as the domain.")
end
end
# ============================================================
function createCellVariable(m::MeshStructure, phi0::Real, BC::BoundaryCondition)
phi = CellValue(m, phi0*ones(tuple(m.dims.+2...)))
cellBoundary!(phi, BC)
end
# ============================================================
function createFaceVariable(m::MeshStructure, phi0::Array{T,1}) where T<:Real
# creates a face variable based on the mesh structure
d=m.dimension
if d==1 || d==1.5
FaceValue(m,
ones(m.dims[1]+1).*phi0[1],
[1.0],
[1.0])
elseif d==2 || d==2.5 || d==2.8
FaceValue(m,
ones(m.dims[1]+1, m.dims[2]).*phi0[1],
ones(m.dims[1], m.dims[2]+1).*phi0[2],
[1.0])
elseif d==3 || d==3.2
FaceValue(m,
ones(m.dims[1]+1, m.dims[2], m.dims[3]).*phi0[1],
ones(m.dims[1], m.dims[2]+1, m.dims[3]).*phi0[2],
ones(m.dims[1], m.dims[2], m.dims[3]+1).*phi0[3])
end
end
function createFaceVariable(m::MeshStructure, phi0::Real)
# creates a face variable based on the mesh structure
d=m.dimension
if d==1 || d==1.5
FaceValue(m,
ones(m.dims[1]+1).*phi0,
[1.0],
[1.0])
elseif d==2 || d==2.5 || d==2.8
FaceValue(m,
ones(m.dims[1]+1, m.dims[2]).*phi0,
ones(m.dims[1], m.dims[2]+1).*phi0,
[1.0])
elseif d==3 || d==3.2
FaceValue(m,
ones(m.dims[1]+1, m.dims[2], m.dims[3]).*phi0,
ones(m.dims[1], m.dims[2]+1, m.dims[3]).*phi0,
ones(m.dims[1], m.dims[2], m.dims[3]+1).*phi0)
end
end
# ============================================================
function createCellVector(m::MeshStructure, phi0::Array{T,1}) where T<:Real
# creates a cell vector based on the mesh structure
d=m.dimension
if d==1 || d==1.5
CellVector(m,
ones(m.dims[1]).*phi0[1],
[1.0],
[1.0])
elseif d==2 || d==2.5 || d==2.8
CellVector(m,
ones(m.dims[1], m.dims[2]).*phi0[1],
ones(m.dims[1], m.dims[2]).*phi0[2],
[1.0])
elseif d==3 || d==3.2
CellVector(m,
ones(m.dims[1], m.dims[2], m.dims[3]).*phi0[1],
ones(m.dims[1], m.dims[2], m.dims[3]).*phi0[2],
ones(m.dims[1], m.dims[2], m.dims[3]).*phi0[3])
end
end
function createCellVector(m::MeshStructure, phi0::Real)
# creates a cell vector based on the mesh structure
d=m.dimension
if d==1 || d==1.5
CellVector(m,
ones(m.dims[1]).*phi0,
[1.0],
[1.0])
elseif d==2 || d==2.5 || d==2.8
CellVector(m,
ones(m.dims[1], m.dims[2]).*phi0,
ones(m.dims[1], m.dims[2]).*phi0,
[1.0])
elseif d==3 || d==3.2
CellVector(m,
ones(m.dims[1], m.dims[2], m.dims[3]).*phi0,
ones(m.dims[1], m.dims[2], m.dims[3]).*phi0,
ones(m.dims[1], m.dims[2], m.dims[3]).*phi0)
end
end
# ================== copy function for cell variables ===================
function copyCell(phi::CellValue)
CellValue(phi.domain, Base.copy(phi.value))
end