Mercurial > repos > public > sbplib_julia
annotate src/Grids/EquidistantGrid.jl @ 1118:6104db60b7a3 feature/lazy_arrays
Export binary operations for LazyArrays and scalars
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Fri, 15 Jul 2022 15:23:16 +0200 |
| parents | 5b3d4a8ec3ab |
| children | 4e4c5011140d |
| rev | line source |
|---|---|
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
1 export EquidistantGrid |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
2 export spacing |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
3 export inverse_spacing |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
4 export restrict |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
5 export boundary_identifiers |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
6 export boundary_grid |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
7 export refine |
| 907 | 8 export coarsen |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
9 |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
10 """ |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
11 EquidistantGrid{Dim,T<:Real} <: AbstractGrid |
|
75
93c833019857
Make EquidistantGrid more concrete
Jonatan Werpers <jonatan@werpers.com>
parents:
74
diff
changeset
|
12 |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
13 `Dim`-dimensional equidistant grid with coordinates of type `T`. |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
14 """ |
|
75
93c833019857
Make EquidistantGrid more concrete
Jonatan Werpers <jonatan@werpers.com>
parents:
74
diff
changeset
|
15 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
16 size::NTuple{Dim, Int} |
|
75
93c833019857
Make EquidistantGrid more concrete
Jonatan Werpers <jonatan@werpers.com>
parents:
74
diff
changeset
|
17 limit_lower::NTuple{Dim, T} |
|
93c833019857
Make EquidistantGrid more concrete
Jonatan Werpers <jonatan@werpers.com>
parents:
74
diff
changeset
|
18 limit_upper::NTuple{Dim, T} |
|
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
19 |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
20 function EquidistantGrid{Dim,T}(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where {Dim,T} |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
21 if any(size .<= 0) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
22 throw(DomainError("all components of size must be postive")) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
23 end |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
24 if any(limit_upper.-limit_lower .<= 0) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
25 throw(DomainError("all side lengths must be postive")) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
26 end |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
27 return new{Dim,T}(size, limit_lower, limit_upper) |
|
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
28 end |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
29 end |
|
680
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
30 |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
31 """ |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
32 EquidistantGrid(size, limit_lower, limit_upper) |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
33 |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
34 Construct an equidistant grid with corners at the coordinates `limit_lower` and |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
35 `limit_upper`. |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
36 |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
37 The length of the domain sides are given by the components of |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
38 `limit_upper-limit_lower`. E.g for a 2D grid with `limit_lower=(-1,0)` and `limit_upper=(1,2)` the domain is defined |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
39 as `(-1,1)x(0,2)`. The side lengths of the grid are not allowed to be negative. |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
40 |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
41 The number of equidistantly spaced points in each coordinate direction are given |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
42 by the tuple `size`. |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
43 """ |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
44 function EquidistantGrid(size, limit_lower, limit_upper) |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
45 return EquidistantGrid{length(size), eltype(limit_lower)}(size, limit_lower, limit_upper) |
|
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
46 end |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
47 |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
48 """ |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
49 EquidistantGrid{T}() |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
50 |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
51 Constructs a 0-dimensional grid. |
|
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
52 """ |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
53 EquidistantGrid{T}() where T = EquidistantGrid{0,T}((),(),()) # Convenience constructor for 0-dim grid |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
54 |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
55 """ |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
56 EquidistantGrid(size::Int, limit_lower::T, limit_upper::T) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
57 |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
58 Convenience constructor for 1D grids. |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
59 """ |
|
324
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
270
diff
changeset
|
60 function EquidistantGrid(size::Int, limit_lower::T, limit_upper::T) where T |
|
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
270
diff
changeset
|
61 return EquidistantGrid((size,),(limit_lower,),(limit_upper,)) |
|
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
270
diff
changeset
|
62 end |
|
047dee8efaef
Grids.EquidistantGrid: Add constructor for 1d grid
Jonatan Werpers <jonatan@werpers.com>
parents:
270
diff
changeset
|
63 |
|
688
e9e46a587370
Add eltype function to EquidistantGrids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
686
diff
changeset
|
64 Base.eltype(grid::EquidistantGrid{Dim,T}) where {Dim,T} = T |
|
e9e46a587370
Add eltype function to EquidistantGrids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
686
diff
changeset
|
65 |
|
e9e46a587370
Add eltype function to EquidistantGrids
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
686
diff
changeset
|
66 Base.eachindex(grid::EquidistantGrid) = CartesianIndices(grid.size) |
|
129
1aaeb46ba5f4
Improve efficiency of apply by the following:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
124
diff
changeset
|
67 |
|
241
1128ab4f5758
Add size method to EquidistantGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
221
diff
changeset
|
68 Base.size(g::EquidistantGrid) = g.size |
|
1128ab4f5758
Add size method to EquidistantGrid
Jonatan Werpers <jonatan@werpers.com>
parents:
221
diff
changeset
|
69 |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
70 """ |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
71 dimension(grid::EquidistantGrid) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
72 |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
73 The dimension of the grid. |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
74 """ |
|
658
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
75 dimension(grid::EquidistantGrid{Dim}) where Dim = Dim |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
76 |
|
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
77 """ |
|
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
78 spacing(grid::EquidistantGrid) |
|
261
01017d2b46b0
Store grid spacing as property in EquidistantGrid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
256
diff
changeset
|
79 |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
80 The spacing between grid points. |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
81 """ |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
82 spacing(grid::EquidistantGrid) = (grid.limit_upper.-grid.limit_lower)./(grid.size.-1) |
|
95
9d53ecca34f7
Switch to using cartesian indicies
Jonatan Werpers <jonatan@werpers.com>
parents:
85
diff
changeset
|
83 |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
84 """ |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
85 inverse_spacing(grid::EquidistantGrid) |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
86 |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
87 The reciprocal of the spacing between grid points. |
|
381
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
88 """ |
|
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
89 inverse_spacing(grid::EquidistantGrid) = 1 ./ spacing(grid) |
|
dacbcba33d7d
Refactor EquidistantGrid to not store spacing or inverse spacing
Jonatan Werpers <jonatan@werpers.com>
parents:
358
diff
changeset
|
90 |
|
406
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
91 """ |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
92 points(grid::EquidistantGrid) |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
93 |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
94 The point of the grid as an array of tuples with the same dimension as the grid. |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
95 The points are stored as [(x1,y1), (x1,y2), … (x1,yn); |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
96 (x2,y1), (x2,y2), … (x2,yn); |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
97 ⋮ ⋮ ⋮ |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
98 (xm,y1), (xm,y2), … (xm,yn)] |
|
c377fc37c04b
Clean up EquidistantGrid and tests after deciding that side lengths must be positive.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
405
diff
changeset
|
99 """ |
|
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
100 function points(grid::EquidistantGrid) |
|
124
631eb9b35d72
Make grid spacing a property of EquidistantGrid. Create plotting module for sbplib.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
95
diff
changeset
|
101 indices = Tuple.(CartesianIndices(grid.size)) |
|
130
155bbecf18bb
Fix bug in points(::EquidistantGrid)
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
129
diff
changeset
|
102 h = spacing(grid) |
|
155bbecf18bb
Fix bug in points(::EquidistantGrid)
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
129
diff
changeset
|
103 return broadcast(I -> grid.limit_lower .+ (I.-1).*h, indices) |
|
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
104 end |
|
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
105 |
|
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
106 """ |
|
358
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
107 restrict(::EquidistantGrid, dim) |
|
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
108 |
|
909
b900fea1c057
Clean up the docs a bit
Jonatan Werpers <jonatan@werpers.com>
parents:
908
diff
changeset
|
109 Pick out given dimensions from the grid and return a grid for them. |
|
353
8257cc75ea6b
Add doc string and allow picking several dimensions
Jonatan Werpers <jonatan@werpers.com>
parents:
352
diff
changeset
|
110 """ |
|
358
64ad8ec0eae0
Change name from subgrid to restrict
Jonatan Werpers <jonatan@werpers.com>
parents:
353
diff
changeset
|
111 function restrict(grid::EquidistantGrid, dim) |
|
352
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
112 size = grid.size[dim] |
|
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
113 limit_lower = grid.limit_lower[dim] |
|
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
114 limit_upper = grid.limit_upper[dim] |
|
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
115 |
|
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
116 return EquidistantGrid(size, limit_lower, limit_upper) |
|
a18bd337a280
Add function for getting a one dimensional grid for a given dimension from a equidistant grid
Jonatan Werpers <jonatan@werpers.com>
parents:
333
diff
changeset
|
117 end |
|
658
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
118 |
|
1111
5b3d4a8ec3ab
Change to using filter for picking out orthogonal dimensions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
909
diff
changeset
|
119 |
|
658
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
120 """ |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
121 boundary_identifiers(::EquidistantGrid) |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
122 |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
123 Returns a tuple containing the boundary identifiers for the grid, stored as |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
124 (CartesianBoundary(1,Lower), |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
125 CartesianBoundary(1,Upper), |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
126 CartesianBoundary(2,Lower), |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
127 ...) |
|
26b0eb83aea4
Add function for getting boundary identifiers from equidistant grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
406
diff
changeset
|
128 """ |
|
661
f0ceddeae993
Fix and test type stability of boundary_identifiers.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
659
diff
changeset
|
129 boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dimension(g)))...)...,) |
|
680
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
130 |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
131 |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
132 """ |
|
1111
5b3d4a8ec3ab
Change to using filter for picking out orthogonal dimensions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
909
diff
changeset
|
133 boundary_grid(grid::EquidistantGrid, id::CartesianBoundary) |
|
680
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
134 |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
135 Creates the lower-dimensional restriciton of `grid` spanned by the dimensions |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
136 orthogonal to the boundary specified by `id`. The boundary grid of a 1-dimensional |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
137 grid is a zero-dimensional grid. |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
138 """ |
|
1111
5b3d4a8ec3ab
Change to using filter for picking out orthogonal dimensions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
909
diff
changeset
|
139 function boundary_grid(grid::EquidistantGrid, id::CartesianBoundary) |
|
5b3d4a8ec3ab
Change to using filter for picking out orthogonal dimensions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
909
diff
changeset
|
140 dims = 1:dimension(grid) |
|
5b3d4a8ec3ab
Change to using filter for picking out orthogonal dimensions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
909
diff
changeset
|
141 # Extract dimensions orthogonal to dim(id) |
|
5b3d4a8ec3ab
Change to using filter for picking out orthogonal dimensions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
909
diff
changeset
|
142 orth_dims = filter(i -> i != dim(id), dims) |
|
682
3ed922e95a35
Make boundary_grid throw if invalid boundary identifier is passed.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
680
diff
changeset
|
143 if orth_dims == dims |
|
3ed922e95a35
Make boundary_grid throw if invalid boundary identifier is passed.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
680
diff
changeset
|
144 throw(DomainError("boundary identifier not matching grid")) |
|
3ed922e95a35
Make boundary_grid throw if invalid boundary identifier is passed.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
680
diff
changeset
|
145 end |
|
680
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
146 return restrict(grid,orth_dims) |
|
1d3e29ffc6c6
Add support for 0-dimensional grid, and add method boundary_grid
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
661
diff
changeset
|
147 end |
|
686
27dcac8fb350
Fix type parameter for a 0-dimensional grid and update docs
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
684
diff
changeset
|
148 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}() |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
149 |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
150 |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
151 """ |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
152 refine(grid::EquidistantGrid, r::Int) |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
153 |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
154 Refines `grid` by a factor `r`. The factor is applied to the number of |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
155 intervals which is 1 less than the size of the grid. |
| 908 | 156 |
| 157 See also: [`coarsen`](@ref) | |
|
877
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
158 """ |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
159 function refine(grid::EquidistantGrid, r::Int) |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
160 sz = size(grid) |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
161 new_sz = (sz .- 1).*r .+ 1 |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
162 return EquidistantGrid{dimension(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) |
|
dd2ab001a7b6
Implement refine function, move exports to the top of the file, change location of constuctors.
Jonatan Werpers <jonatan@werpers.com>
parents:
688
diff
changeset
|
163 end |
| 907 | 164 |
| 908 | 165 """ |
| 166 coarsen(grid::EquidistantGrid, r::Int) | |
| 167 | |
| 168 Coarsens `grid` by a factor `r`. The factor is applied to the number of | |
| 169 intervals which is 1 less than the size of the grid. If the number of | |
| 170 intervals are not divisible by `r` an error is raised. | |
| 171 | |
| 172 See also: [`refine`](@ref) | |
| 173 """ | |
| 907 | 174 function coarsen(grid::EquidistantGrid, r::Int) |
| 175 sz = size(grid) | |
| 176 | |
| 177 if !all(n -> (n % r == 0), sz.-1) | |
| 178 throw(DomainError(r, "Size minus 1 must be divisible by the ratio.")) | |
| 179 end | |
| 180 | |
| 181 new_sz = (sz .- 1).÷r .+ 1 | |
| 182 | |
| 183 return EquidistantGrid{dimension(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) | |
| 184 end |
