You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#TODO: Seperate out Iedge in to individual boundaries and map each seperately to save time and catch the periodic case, have a look at the old maps for how to match the bcs
# ufunc is a function that returns the correct discretization indexed at Itap, it is designed this way to allow for central differences of arbitrary expressions which may be needed in some schemes
32
33
functioncentral_difference(D, II, s, jx, u, ufunc)
33
34
j, x = jx
34
35
# unit index in direction of the derivative
35
36
I1 =unitindices(nparams(s))[j]
36
37
# offset is important due to boundary proximity
38
+
37
39
if II[j] <= D.boundary_point_count
38
40
weights = D.low_boundary_coefs[II[j]]
39
-
offset =D.boundary_point_count- II[j]+1
40
-
Itap = [II + (i+offset)*I1 for i inhalf_range(D.boundary_stencil_length)]
41
+
offset =1- II[j]
42
+
Itap = [II + (i+offset)*I1 for i in0:(D.boundary_stencil_length-1)]
Itap = [II + (i+offset)*I1 for i inhalf_range(D.boundary_stencil_length)]
45
+
offset =length(s, x) - II[j]
46
+
Itap = [II + (i+offset)*I1 for i in(-D.boundary_stencil_length+1):1:0]
45
47
else
46
48
weights = D.stencil_coefs
47
49
Itap = [II + i*I1 for i inhalf_range(D.stencil_length)]
@@ -60,13 +62,12 @@ function _get_weights_and_stencil(D, II, I1, s, k, j, x)
60
62
# The low boundary coeffs has a heirarchy of coefficients following: number of indices from boundary -> which half offset point does it correspond to -> weights
61
63
if II[j] <= (D.boundary_point_count-1)
62
64
weights = D.low_boundary_coefs[II[j]][k]
63
-
offset = D.boundary_point_count - II[j] +1
64
-
# ? Is this offset correct?
65
-
Itap = [II + (i+offset)*I1 for i inhalf_range(D.boundary_stencil_length)]
65
+
offset =1- II[j]
66
+
Itap = [II + (i+offset)*I1 for i in0:(D.boundary_stencil_length-1)]
nottime # Note that these aren't necessarily @parameters
23
24
params
24
25
axies
@@ -41,8 +42,8 @@ params(s::DiscreteSpace{N,M}) where {N,M}= s.params
41
42
grid_idxs(s::DiscreteSpace) =CartesianIndices(((axes(g)[1] for g in s.grid)...,))
42
43
edge_idxs(s::DiscreteSpace{N}) where {N} =reduce(vcat, [[vcat([Colon() for j =1:i-1], 1, [Colon() for j = i+1:N]), vcat([Colon() for j =1:i-1], length(s.axies[i]), [Colon() for j = i+1:N])] for i =1:N])
43
44
44
-
axiesvals(s::DiscreteSpace{N}) where {N} =map(y -> [s.nottime[i] => s.axies[i][y.I[i]] for i =1:N], s.Iaxies)
45
-
gridvals(s::DiscreteSpace{N}) where {N} =map(y -> [s.nottime[i] => s.grid[i][y.I[i]] for i =1:N], s.Igrid)
45
+
axiesvals(s::DiscreteSpace{N}) where {N} =map(y -> [s.nottime[i] => s.axies[s.nottime[i]][y.I[i]] for i =1:N], s.Iaxies)
46
+
gridvals(s::DiscreteSpace{N}) where {N} =map(y -> [s.nottime[i] => s.grid[s.nottime[i]][y.I[i]] for i =1:N], s.Igrid)
46
47
47
48
## Boundary methods ##
48
49
edgevals(s::DiscreteSpace{N}) where {N} =reduce(vcat, [get_edgevals(s.nottime, s.axies, i) for i =1:N])
@@ -53,8 +54,11 @@ edgevars(s::DiscreteSpace) = [[d[e...] for e in s.Iedge] for d in s.discvars]
53
54
returnDict(bclocs(s) .=> [axiesvals(s)[e...] for e in s.Iedge])
54
55
end
55
56
57
+
Iinterior(s::DiscreteSpace) = s.Igrid[[2:(length(s, x)-1) for x in s.nottime]...]
58
+
56
59
map_symbolic_to_discrete(II::CartesianIndex, s::DiscreteSpace{N,M}) where {N,M} =vcat([s.vars[k] => s.discvars[k][II] for k =1:M], [s.nottime[j] => s.grid[j][II[j]] for j =1:N])
57
60
61
+
# ? How rude is this? Makes Iedge work
58
62
59
63
#TODO: Allow other grids
60
64
@@ -91,7 +95,7 @@ function DiscreteSpace(domain, depvars, indvars, nottime, discretization)
91
95
# Build symbolic variables
92
96
Iaxies =CartesianIndices(((axes(s.second)[1] for s in axies)...,))
93
97
Igrid =CartesianIndices(((axes(g.second)[1] for g in grid)...,))
94
-
@show depvars
98
+
95
99
depvarsdisc =map(depvars) do u
96
100
if t ===nothing
97
101
sym =nameof(SymbolicUtils.operation(u))
@@ -104,14 +108,12 @@ function DiscreteSpace(domain, depvars, indvars, nottime, discretization)
104
108
end
105
109
end
106
110
107
-
108
111
# Build symbolic maps for boundaries
109
-
Iedge =reduce(vcat, [[Igrid[vcat([Colon() for j =1:i-1], 1, [Colon() for j = i+1:nspace])],
110
-
Igrid[vcat([Colon() for j =1:i-1], length(axies[i].second), [Colon() for j = i+1:nspace])]] for i =1:nspace])
112
+
Iedge =vcat((vcat(vec(selectdim(Igrid, dim, 1)), vec(selectdim(Igrid, dim, length(grid[dim].second)))) for dim in1:nspace)...)
0 commit comments