Skip to content

Commit 791866a

Browse files
committed
some assumptions
1 parent 7afac3e commit 791866a

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/bcs/generate_bc_eqs.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct UpperBoundary<: AbstractTruncatingBoundary
1313
end
1414

1515
struct CompleteBoundary <: AbstractTruncatingBoundary
16-
end#
16+
end
1717

1818
struct PeriodicBoundary <: AbstractBoundary
1919
end
@@ -37,6 +37,7 @@ function BoundaryHandler!!(u0, bceqs, bcs, s, depvar_ops, tspan, derivweights)
3737
end
3838

3939
# Create some rules to match which bundary/variable a bc concerns
40+
# * Assume that the term of the condition is applied additively and has no multiplier/divisor/power etc.
4041
# ? Is it nessecary to check whether all other args are present?
4142
lower_boundary_rules = vec([@rule operation(u)(~~a, lowerboundary(x), ~~b) => IfElse.ifelse(all(y-> y in vcat(~~a, ~~b), setdiff(x, arguments(u))), x, nothing) for x in setdiff(arguments(u), t), u in s.vars])
4243

@@ -61,7 +62,6 @@ function BoundaryHandler!!(u0, bceqs, bcs, s, depvar_ops, tspan, derivweights)
6162

6263
u_, x_ = (nothing, nothing)
6364
terms = vcat(lhs_arg,rhs_arg)
64-
# * Assume that the term of the condition is applied additively and has no multiplier/divisor/power etc.
6565
boundary = nothing
6666
# Check whether the bc is on the lower boundary, or periodic
6767
for term in terms, r in lower_boundary_rules
@@ -71,7 +71,7 @@ function BoundaryHandler!!(u0, bceqs, bcs, s, depvar_ops, tspan, derivweights)
7171
for term_ in setdiff(terms, term)
7272
for r in upper_boundary_rules
7373
if r(term_) !== nothing
74-
# boundary = :periodic
74+
# boundary = PeriodicBoundary()
7575
#TODO: Add handling for perioodic boundary conditions here
7676
end
7777
end
@@ -104,41 +104,49 @@ function generate_bc_rules(II, dim, s, bc, u_, x_, boundary::AbstractTruncatingB
104104
# depvarbcmaps will dictate what to replace the variable terms with in the bcs
105105
# replace u(t,0) with u₁, etc
106106
ufunc(v, I, x) = s.discvars[v][I]
107-
107+
# * Assume that the BC is in terms of an explicit expression, not containing references to variables other than u_ at the boundary
108108
for u in s.vars
109109
if isequal(operation(u), operation(u_))
110110
# What to replace derivatives at the boundary with
111-
depvarderivbcmaps = [(Differential(x)^d)(u_) => central_difference(derivweights.map[Differential(x_)^d], II, s, (s.x2i[x_],x_), u, ufunc) for d in derivweights.orders[x_]]
111+
depvarderivbcmaps = [(Differential(x)^d)(u_) => central_difference(derivweights.map[Differential(x_)^d], II, s, (s.x2i[x_], x_), u, ufunc) for d in derivweights.orders[x_]]
112112
# ? Does this need to be done for all variables at the boundary?
113113
depvarbcmaps = [u_ => s.discvars[u][II]]
114+
break
114115
end
115116
end
116117

117118
fd_rules = generate_finite_difference_rules(II, s, bc, derivweights)
118-
varrules = axiesvals(s, II)
119+
varrules = axiesvals(s, x_, II)
120+
121+
# valrules should be caught by depvarbcmaps and varrules if the above assumption holds
122+
#valr = valrules(s, II)
119123

120124
return vcat(depvarderivbcmaps, depvarbcmaps, fd_rules, varrules)
121125
end
122126

123127
function generate_bc_rules(II, dim, s, bc, u_, x_, boundary::AbstractTruncatingBoundary, derivweights, G::EdgeAlignedGrid)
124128

125-
boundaryoffset(::LowerBoundary) = 1/2
126-
boundaryoffset(::UpperBoundary) = -1/2
129+
offset(::LowerBoundary) = 1/2
130+
offset(::UpperBoundary) = -1/2
127131
ufunc(v, I, x) = s.discvars[v][I]
128132

129133
# depvarbcmaps will dictate what to replace the variable terms with in the bcs
130134
# replace u(t,0) with u₁, etc
135+
# * Assume that the BC is in terms of an explicit expression, not containing references to variables other than u_ at the boundary
131136
for u in s.vars
132137
if isequal(operation(u), operation(u_))
133138
depvarderivbcmaps = [(Differential(x)^d)(u_) => half_offset_centered_difference(derivweights.halfoffsetmap[Differential(x_)^d], II, s, offset(boundary), (s.x2i[x_],x_), u, ufunc) for d in derivweights.orders[x_]]
134139

135140
depvarbcmaps = [u_ => half_offset_centered_difference(derivweights.interpmap[x_], II, s, offset(boundary), (s.x2i[x_],x_), u, ufunc)]
141+
break
136142
end
137143
end
138144

139145
fd_rules = generate_finite_difference_rules(II, s, bc, derivweights)
140-
varrules = axiesvals(s, II)
141-
valr = valrules(s, II)
146+
varrules = axiesvals(s, x_, II)
147+
148+
# valrules should be caught by depvarbcmaps and varrules if the above assumption holds
149+
#valr = valrules(s, II)
142150

143151
return vcat(depvarderivbcmaps, depvarbcmaps, fd_rules, varrules)
144152
end

src/discretization/discretize_vars.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ params(s::DiscreteSpace{N,M}) where {N,M}= s.params
4242
grid_idxs(s::DiscreteSpace) = CartesianIndices(((axes(g)[1] for g in s.grid)...,))
4343
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])
4444

45-
axiesvals(s::DiscreteSpace{N}, I) where {N} = [x => s.axies[x][I[j]] for (j,x) in enumerate(s.nottime)]
45+
axiesvals(s::DiscreteSpace{N}, x_, I) where {N} = [x => (x == x_ ? s.axies[x][I[j]] : s.grid[x][I[j]]) for (j,x) in enumerate(s.nottime)]
4646
gridvals(s::DiscreteSpace{N}, I) where {N} = [x => s.grid[x][I[j]] for (j,x) in enumerate(s.nottime)]
4747

4848
## Boundary methods ##

src/discretization/generate_finite_difference_rules.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ There are of course more specific schemes that are used to improve stability/spe
148148
##Planned special cases include:
149149
- Up/Downwind schemes to be used for odd ordered derivatives multiplied by a coefficient, downwinding when the coefficient is positive, and upwinding when the coefficient is negative.
150150
151-
Please submit an issue if you know of any special cases that are not implemented, with links to papers and/or code that demonstrates the special case.
151+
Please submit an issue if you know of any special cases which impact stability or accuracy that are not implemented, with links to papers and/or code that demonstrates the special case.
152152
"""
153153
function generate_finite_difference_rules(II, s, pde, derivweights)
154154
# central_deriv_rules = [(Differential(s)^2)(u) => central_deriv(2,II,j,k) for (j,s) in enumerate(s.nottime), (k,u) in enumerate(s.vars)]

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const is_TRAVIS = haskey(ENV,"TRAVIS")
1010

1111
if GROUP == "All" || GROUP == "Component Tests"
1212
# @time @safetestset "Test for regression against original code" begin include("regression_test.jl") end
13-
#@time @safetestset "MOLFiniteDifference Utils" begin include("utils_test.jl") end
13+
@time @safetestset "MOLFiniteDifference Utils" begin include("utils_test.jl") end
1414
end
1515

1616
if GROUP == "All" || GROUP == "Integration Tests"

0 commit comments

Comments
 (0)