forked from jeremylt/LFAToolkit.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMesh.jl
187 lines (155 loc) · 2.96 KB
/
Mesh.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# ------------------------------------------------------------------------------
# rectangular meshes
# ------------------------------------------------------------------------------
"""
Rectangular mesh with independent scaling in each dimesion
"""
abstract type Mesh end
"""
```julia
Mesh1D(dx)
```
One dimensional regular background mesh
# Arguments:
- `dx`: deformation in x dimension
# Returns:
- One dimensional mesh object
# Example:
```jldoctest
# generate 1D mesh
mesh = Mesh1D(1.0);
# verify
println(mesh)
# output
1d mesh:
dx: 1.0
```
"""
struct Mesh1D <: Mesh
# data
dimension::Int
dx::Float64
volume::Float64
# inner constructor
Mesh1D(dx::Float64) = (
# validity checking
if dx < 1e-14
error("Mesh scaling must be positive") # COV_EXCL_LINE
end;
# constructor
new(1, dx, dx)
)
end
# printing
# COV_EXCL_START
Base.show(io::IO, mesh::Mesh1D) = print(
io,
"1d mesh:
dx: ",
mesh.dx,
)
# COV_EXCL_STOP
"""
```julia
Mesh2D(dx, dy)
```
Two dimensional regular background mesh
# Arguments:
- `dx`: deformation in x dimension
- `dy`: deformation in y dimension
# Returns:
- Two dimensional mesh object
# Example:
```jldoctest
# generate 2D mesh
mesh = Mesh2D(1.0, 0.5);
# verify
println(mesh)
# output
2d mesh:
dx: 1.0
dy: 0.5
```
"""
struct Mesh2D <: Mesh
# data
dimension::Int
dx::Float64
dy::Float64
volume::Float64
# inner constructor
Mesh2D(dx::Float64, dy::Float64) = (
# validity checking
if dx < 1e-14 || dy < 1e-14
error("Mesh scaling must be positive") # COV_EXCL_LINE
end;
# constructor
new(2, dx, dy, dx * dy)
)
end
# printing
# COV_EXCL_START
Base.show(io::IO, mesh::Mesh2D) = print(
io,
"2d mesh:
dx: ",
mesh.dx,
"\n dy: ",
mesh.dy,
)
# COV_EXCL_STOP
"""
```julia
Mesh3D(dx, dy, dz)
```
Three dimensional regular background mesh
# Arguments:
- `dx`: deformation in x dimension
- `dy`: deformation in y dimension
- `dz`: deformation in z dimension
# Returns:
- Three dimensional mesh object
# Example:
```jldoctest
# generate 3D mesh
mesh = Mesh3D(1.0, 0.5, 0.3);
# verify
println(mesh)
# output
3d mesh:
dx: 1.0
dy: 0.5
dz: 0.3
```
"""
struct Mesh3D <: Mesh
# data
dimension::Int
dx::Float64
dy::Float64
dz::Float64
volume::Float64
# inner constructor
Mesh3D(dx::Float64, dy::Float64, dz::Float64) = (
# validity checking
if dx < 1e-14 || dy < 1e-14 || dz < 1e-14
error("Mesh scaling must be positive") # COV_EXCL_LINE
end;
# constructor
new(3, dx, dy, dz, dx * dy * dz)
)
end
# printing
# COV_EXCL_START
Base.show(io::IO, mesh::Mesh3D) = print(
io,
"3d mesh:
dx: ",
mesh.dx,
"\n dy: ",
mesh.dy,
"\n dz: ",
mesh.dz,
)
# COV_EXCL_STOP
# ------------------------------------------------------------------------------