Skip to content

Commit 14f4bc9

Browse files
authored
Merge pull request #101 from mberto79/HM/normal-aligned-interpolation-weights
Face interpolation weights using face normal distances
2 parents 30a8518 + ccc019c commit 14f4bc9

File tree

5 files changed

+57
-24
lines changed

5 files changed

+57
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* +50x speed improvement for the method `construct_periodic` and also more robust algorithm used [#100](@ref)
2020
* Implementation to correct mass flux uses matrix coefficients directly for better stability when using periodic boundary conditions [#100](@ref)
2121
* New method to enforce matrix symmetry of scalar model equations when the only term is a laplacian [#100](@ref)
22+
* Change calculation of face interpolation weights to use face normal aligned weights, this is more physical than the current method using face-based distances (in preparation for formal support for non-orthogonality correction)[#101](@ref)
2223

2324
### Breaking
2425
* No breaking changes

src/Discretise/Discretise_1_schemes.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ end
109109
) where {F,P,I}
110110

111111
w = face.weight
112-
signbit(ns) ? w = one(w) - w : w
112+
# signbit(ns) ? w = one(w) - w : w
113+
w = 0.5 + ns*(w - 0.5)
113114

114115
# Calculate link coefficients
115116
ap = term.sign*(term.flux[fID]*ns)

src/Discretise/boundary_conditions/periodic.jl

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,23 @@ end
326326
pfID = bc.value.face_map[i] # id of periodic face
327327
pface = faces[pfID]
328328
pcellID = pface.ownerCells[1]
329+
C1 = cell.centre
330+
C2 = cells[pcellID].centre - transform.distance
331+
Cf = face.centre
332+
n = face.normal
333+
334+
Pf = Cf - C1
335+
PN = C2 - C1
329336

330-
w = pface.delta/(face.delta + pface.delta)
337+
wn = (Pfn)/(PNn)
338+
w = one(wn) - wn
339+
# w = pface.delta/(face.delta + pface.delta)
340+
# wn = one(w) - w
331341

332342
# Calculate link coefficients
333343
ap = term.sign*(term.flux[fID])
334344
ac = ap*w
335-
an = ap*(one(w) - w)
345+
an = ap*wn
336346

337347
NN = spindex(rowptr, colval, pcellID, pcellID)
338348
NP = spindex(rowptr, colval, pcellID, cellID)
@@ -395,15 +405,21 @@ end
395405
pfID = bc.value.face_map[i] # id of periodic face
396406
pface = faces[pfID]
397407
pcellID = pface.ownerCells[1]
408+
C1 = cell.centre
409+
C2 = cells[pcellID].centre - transform.distance
410+
Cf = face.centre
411+
n = face.normal
398412

413+
Pf = Cf - C1
414+
PN = C2 - C1
399415

400-
# Calculate interpoloation weight
401-
w = pface.delta/(face.delta + pface.delta)
416+
wn = (Pfn)/(PNn)
417+
w = one(wn) - wn
402418

403419
# Calculate link coefficients
404420
mdot = term.sign*(term.flux[fID])
405421
acLinear = mdot*w
406-
anLinear = mdot*(one(w) - w)
422+
anLinear = mdot*wn
407423
acUpwind = max(mdot, 0.0)
408424
anUpwind = -max(-mdot, 0.0)
409425
ac = 0.75*acLinear + 0.25*acUpwind

src/Discretise/boundary_conditions/periodic_interpolation.jl

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,24 @@ end
1414
pfID = BC.value.face_map[i] # id of periodic face
1515
pface = faces[pfID]
1616
pcID = pface.ownerCells[1]
17-
# pcell = cells[pcID]
17+
pcell = cells[pcID]
1818
face = faces[fID]
19-
cID = boundary_cellsID[fID]
19+
# cID = boundary_cellsID[fID]
20+
cID = face.ownerCells[1]
21+
cell = cells[cID]
2022

21-
delta1 = face.delta #*norm(face.e ⋅ face.normal)
22-
delta2 = pface.delta #*norm(pface.e ⋅ pface.normal)
23-
delta = delta1 + delta2
24-
weight = delta2/delta
23+
# delta1 = face.delta #*norm(face.e ⋅ face.normal)
24+
# delta2 = pface.delta #*norm(pface.e ⋅ pface.normal)
25+
# delta = delta1 + delta2
26+
# w = delta2/delta
2527

26-
one_minus_weight = one(weight) - weight
28+
Pf = face.centre - cell.centre
29+
PN = (pcell.centre - transform.distance) - cell.centre
30+
normal = face.normal
31+
wn = (Pfnormal)/(PNnormal)
32+
w = one(wn) - wn
2733

28-
# phif_values[fID] = 0.5*(phi_values[cID] + phi_values[pcID]) # linear interpolation
29-
phifi = weight*phi[cID] + one_minus_weight*phi[pcID]
34+
phifi = w*phi[cID] + wn*phi[pcID]
3035
phif[fID] = phifi
3136
phif[pfID] = phifi
3237
end
@@ -38,21 +43,29 @@ end
3843
boundary_cellsID, time, fID)
3944
@inbounds begin
4045
i = fID - BC.IDs_range.start + 1
41-
(; transform) = BC.value
46+
(; transform ) = BC.value
4247
(; faces, cells) = psif.mesh
4348
pfID = BC.value.face_map[i] # id of periodic face
4449
pface = faces[pfID]
4550
pcID = pface.ownerCells[1]
51+
pcell = cells[pcID]
4652
face = faces[fID]
47-
cID = boundary_cellsID[fID]
53+
# cID = boundary_cellsID[fID]
54+
cID = face.ownerCells[1]
55+
cell = cells[cID]
56+
57+
# delta1 = face.delta #*norm(face.e ⋅ face.normal)
58+
# delta2 = pface.delta #*norm(pface.e ⋅ pface.normal)
59+
# delta = delta1 + delta2
60+
# w = delta2/delta
4861

49-
delta1 = face.delta #*norm(face.e ⋅ face.normal)
50-
delta2 = pface.delta #*norm(pface.e ⋅ pface.normal)
51-
delta = delta1 + delta2
52-
w = delta2/delta
53-
one_w = one(w) - w
62+
Pf = face.centre - cell.centre
63+
PN = (pcell.centre - transform.distance) - cell.centre
64+
normal = face.normal
65+
wn = (Pfnormal)/(PNnormal)
66+
w = one(wn) - wn
5467

55-
psifi = w*psi[cID] + one_w*psi[pcID] # linear interpolation
68+
psifi = w*psi[cID] + wn*psi[pcID] # linear interpolation
5669
psif[fID] = psifi
5770
psif[pfID] = psifi
5871
end

src/Mesh/Mesh_1_functions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ _get_backend(mesh) = get_backend(mesh.cells)
1616
# C2F1 = distance vector from cell2 centre to face centre
1717
# C1C2 = distance vector from cell1 to cell2
1818
weight_delta_e(C1F1, C2F1, C1C2, normal) = begin
19-
weight = norm(C2F1)/(norm(C1F1) + norm(C2F1))
19+
# weight = norm(C2F1)/(norm(C1F1) + norm(C2F1)) # face-distance based
20+
wi = (C1F1normal)/(C1C2normal)
21+
weight = one(wi) - wi # normal aligned interpolation weight
2022
delta = norm(C1C2)
2123
e = C1C2/delta
2224
return weight, delta, e

0 commit comments

Comments
 (0)