Mercurial > repos > public > sbplib_julia
comparison grid.jl @ 26:d2896e70cd4f
Merge with default
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Mon, 17 Dec 2018 16:35:08 +0100 |
parents | af8469bc1cb3 |
children | 2dbdd00eaea0 aff8ea85ca70 |
comparison
equal
deleted
inserted
replaced
25:1e845cd91cd3 | 26:d2896e70cd4f |
---|---|
1 abstract type BoundaryID end | 1 module grid |
2 | |
3 abstract type Grid end | |
4 | |
5 function numberOfDimensions(grid::Grid) | |
6 error("Not yet implemented") | |
7 end | |
8 | |
9 function numberOfPoints(grid::Grid) | |
10 error("Not yet implemented") | |
11 end | |
12 | |
13 function points(grid::Grid) | |
14 error("Not yet implemented") | |
15 end | |
16 | |
17 abstract type BoundaryId end | |
18 | |
19 # Move to seperate file. | |
20 struct EquidistantGrid <: Grid | |
21 nPointsPerDim::Vector{Int} | |
22 limits::Vector{Pair{Real, Real}} | |
23 function EquidistantGrid(nPointsPerDim, lims) | |
24 @assert length(lims) == length(nPointsPerDim) | |
25 return new(nPointsPerDim, lims) | |
26 end | |
27 end | |
28 | |
29 function numberOfDimensions(grid::EquidistantGrid) | |
30 return length(grid.nPointsPerDim) | |
31 end | |
32 | |
33 function numberOfPoints(grid::EquidistantGrid) | |
34 numberOfPoints = grid.nPointsPerDim[1]; | |
35 for i = 2:length(grid.nPointsPerDim); | |
36 numberOfPoints = numberOfPoints*grid.nPointsPerDim[i] | |
37 end | |
38 return numberOfPoints | |
39 end | |
40 | |
41 function points(grid::EquidistantGrid) | |
42 points = Vector{Real}(undef, numberOfPoints(grid)) | |
43 for i = 1:numberOfDimensions(grid) | |
44 lims = limitsForDimension(grid,i) | |
45 points = range(lims.first, stop=lims.second, length=grid.nPointsPerDim[i]) | |
46 end | |
47 return points | |
48 end | |
49 | |
50 function limitsForDimension(grid::EquidistantGrid, dim::Int) | |
51 return grid.limits[dim] | |
52 end | |
53 | |
54 end |