Skip to content

Commit 69da2c9

Browse files
committed
Merge branch 'main' into HM/normal-aligned-interpolation-weights
2 parents 412fbdc + 30a8518 commit 69da2c9

File tree

6 files changed

+19
-67
lines changed

6 files changed

+19
-67
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
The format used for this `changelog` is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Notice that until the package reaches version `v1.0.0` minor releases are likely to be `breaking`. Starting from version `v0.3.1` breaking changes will be recorded here.
55

6-
## Version [v0.5.2] - 2025-01-16
6+
## Version [v0.5.3] - 2026-02-19
77

88
### Added
99
* No new functionality added
1010

1111

1212
### Fixed
1313
* Add implementation of `Periodic` boundaries to handle the implicit source term - fixes operation of models that use `Si` terms [#95](@ref)
14+
* Fixed implementation of implicit boundaries in [#96](@ref) which where missing atomics [#100](@ref)
1415

1516
### Changed
1617
* Improved stability of `Periodic` boundaries by making the implementation fully implicit [#96](@ref)
1718
* 4x speed improvement for the method `construct_periodic` [#97](@ref)
19+
* +50x speed improvement for the method `construct_periodic` and also more robust algorithm used [#100](@ref)
20+
* Implementation to correct mass flux uses matrix coefficients directly for better stability when using periodic boundary conditions [#100](@ref)
21+
* New method to enforce matrix symmetry of scalar model equations when the only term is a laplacian [#100](@ref)
1822

1923
### Breaking
2024
* No breaking changes

src/Solve/Solve_1_api.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ function solve_equation!(
169169

170170
discretise!(eqn, phi, config)
171171
apply_boundary_conditions!(eqn, phiBCs, nothing, time, config)
172-
make_symmetric!(eqn, config) # added this to test stability of periodic boundaries
172+
if length(eqn.model.terms) == 1 && typeof(eqn.model.terms[1]) <: Laplacian
173+
make_symmetric!(eqn, config) # added this to test stability of periodic boundaries
174+
end
173175
setReference!(eqn, ref, 1, config)
174176
if !isnothing(irelax)
175177
implicit_relaxation!(eqn, phi.values, irelax, nothing, config)

src/Solvers/Solvers_1_CSIMPLE.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ function CSIMPLE(
226226
# Pressure correction
227227
inverse_diagonal!(rD, U_eqn, config)
228228
interpolate!(rhorDf, rD, config)
229+
correct_interpolation_periodic(rhorDf, rD, boundaries.U, config)
229230
@. rhorDf.values *= rhof.values
230231

231232
remove_pressure_source!(U_eqn, ∇p, config)
@@ -297,11 +298,11 @@ function CSIMPLE(
297298

298299
if typeof(model.fluid) <: Compressible
299300
# @. mdotf.values += (pconv.values*(pf.values) - pgrad.values*rhorDf.values)
300-
correct_mass_flux(mdotf, p, rhorDf, config)
301+
correct_mass_flux(mdotf, p_eqn, config)
301302
@. mdotf.values += pconv.values*(pf.values)
302303
elseif typeof(model.fluid) <: WeaklyCompressible
303304
# @. mdotf.values -= pgrad.values*rhorDf.values
304-
correct_mass_flux(mdotf, p, rhorDf, config)
305+
correct_mass_flux(mdotf, p_eqn, config)
305306
end
306307

307308
correct_velocity!(U, Hv, ∇p, rD, config)

src/Solvers/Solvers_1_SIMPLE.jl

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,10 @@ function setup_incompressible_solvers(
7575

7676
p_eqn = (
7777
- Laplacian{schemes.p.laplacian}(rDf, p) == - Source(divHv)
78-
# Laplacian{schemes.p.laplacian}(rDf, p) == Source(divHv)
79-
# Laplacian{schemes.p.laplacian}(rDf, p) == Source(divHv)
8078
) ScalarEquation(p, boundaries.p)
8179

8280
@info "Initialising preconditioners..."
8381

84-
# @reset U_eqn.preconditioner = set_preconditioner(
85-
# solvers.U.preconditioner, U_eqn, boundaries.U, config)
86-
# @reset p_eqn.preconditioner = set_preconditioner(
87-
# solvers.p.preconditioner, p_eqn, boundaries.p, config)
88-
8982
@reset U_eqn.preconditioner = set_preconditioner(solvers.U.preconditioner, U_eqn)
9083
@reset p_eqn.preconditioner = set_preconditioner(solvers.p.preconditioner, p_eqn)
9184

@@ -141,7 +134,6 @@ function SIMPLE(
141134

142135
# Pre-allocate auxiliary variables
143136
TF = _get_float(mesh)
144-
# prev = _convert_array!(prev, backend)
145137
prev = KernelAbstractions.zeros(backend, TF, n_cells)
146138

147139
# Pre-allocate vectors to hold residuals
@@ -212,17 +204,7 @@ function SIMPLE(
212204
limit_gradient!(schemes.p.limiter, ∇p, p, config)
213205
end
214206

215-
# explicit_relaxation!(p, prev, solvers.p.relax, config)
216-
217-
# Velocity and boundaries correction
218-
219-
# old approach
220-
# correct_velocity!(U, Hv, ∇p, rD, config)
221-
# interpolate!(Uf, U, config)
222-
# correct_boundaries!(Uf, U, boundaries.U, time, config)
223-
# flux!(mdotf, Uf, config)
224-
225-
# new approach
207+
# correct mass flux and velocity
226208
correct_mass_flux(mdotf, p_eqn, config)
227209
correct_velocity!(U, Hv, ∇p, rD, config)
228210

@@ -278,7 +260,7 @@ function SIMPLE(
278260
return (Ux=R_ux, Uy=R_uy, Uz=R_uz, p=R_p)
279261
end
280262

281-
### TEMP LOCATION FOR PROTOTYPING - NONORTHOGONAL CORRECTION
263+
### TEMP LOCATION FOR PROTOTYPING
282264

283265
function nonorthogonal_face_correction(eqn, grad, flux, config)
284266
mesh = grad.mesh
@@ -331,19 +313,11 @@ end
331313
T_hat = Sf - Ef # original
332314
faceCorrection = flux[fID]*gradfT_hat
333315

334-
Atomix.@atomic b[cID1] += faceCorrection #*cell1.volume
335-
Atomix.@atomic b[cID2] -= faceCorrection #*cell2.volume # should this be -ve?
336-
337-
# Atomix.@atomic b[cID1] -= faceCorrection #*cell1.volume
338-
# Atomix.@atomic b[cID2] += faceCorrection #*cell2.volume # should this be -ve?
339-
316+
Atomix.@atomic b[cID1] += faceCorrection
317+
Atomix.@atomic b[cID2] -= faceCorrection
318+
340319
end
341320

342-
# +- => good match
343-
# -+ => looks worse at edges for gradient
344-
# -- => looks bad on top-right corner for gradient
345-
# ++ => looks bad on left grad and oscillations on the right
346-
347321
function correction_weight(cells, faces, fi)
348322
(; ownerCells, centre) = faces[fi]
349323
cID1 = ownerCells[1]
@@ -405,31 +379,12 @@ end
405379
# need to get aN from sparse system
406380
zID = spindex(rowptr, colval, cID1, cID2)
407381
aN = nzval[zID]
408-
# mdotf[fID] += -aN*(p2 - p1) # this worked well with periodics
409382
mdotf[fID] += aN*(p2 - p1) # positive because pressure eqn has negative sign
410383
end
411384
end
412385

413386
### Correct mass flux at periodic boundaries
414387

415-
# function correct_mass_periodic(mdotf, p_eqn, pBCs, config)
416-
# (; faces, cells, boundary_cellsID) = mdotf.mesh
417-
# (; hardware) = config
418-
# (; backend, workgroup) = hardware
419-
420-
# p = p_eqn.model.terms[1].phi
421-
# A = _A(p_eqn)
422-
# nzval = _nzval(A)
423-
# colval = _colval(A)
424-
# rowptr = _rowptr(A)
425-
426-
# for BC ∈ pBCs
427-
# _correct_mass_periodic_dispatch(
428-
# BC, mdotf, p, nzval, colval, rowptr, cells, faces, backend, workgroup)
429-
# end
430-
431-
# end
432-
433388
correct_mass_periodic(arg...) = nothing
434389

435390
function correct_mass_periodic(
@@ -463,7 +418,6 @@ end
463418

464419
end
465420

466-
467421
### Correct interpolation at periodic boundaries
468422

469423
function correct_interpolation_periodic(phif, phi, BCs, config)

src/Solvers/Solvers_2_CPISO.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ function CPISO(
249249
# Pressure correction
250250
inverse_diagonal!(rD, U_eqn, config)
251251
interpolate!(rhorDf, rD, config)
252+
correct_interpolation_periodic(rhorDf, rD, boundaries.U, config)
252253
@. rhorDf.values *= rhof.values
253254

254255
remove_pressure_source!(U_eqn, ∇p, config)
@@ -313,10 +314,10 @@ function CPISO(
313314
end
314315

315316
if typeof(model.fluid) <: Compressible
316-
correct_mass_flux(mdotf, p, rhorDf, config)
317+
correct_mass_flux(mdotf, p_eqn, config)
317318
@. mdotf.values += pconv.values*(pf.values)
318319
elseif typeof(model.fluid) <: WeaklyCompressible
319-
correct_mass_flux(mdotf, p, rhorDf, config)
320+
correct_mass_flux(mdotf, p_eqn, config)
320321
end
321322

322323
# TO-DO: this needs to be exposed to users eventually
@@ -325,10 +326,6 @@ function CPISO(
325326

326327
# Velocity and boundaries correction
327328
correct_velocity!(U, Hv, ∇p, rD, config) # why is this not rhorD?
328-
329-
# Lines below should not be needed, interpolation to Uf happens in grad calcs
330-
# interpolate!(Uf, U, config)
331-
# correct_boundaries!(Uf, U, boundaries.U, time, config)
332329

333330
@. dpdt.values = (p.values-prev)/runtime.dt
334331

src/Solvers/Solvers_2_PISO.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@ function PISO(
161161
limit_gradient!(schemes.p.limiter, ∇p, p, config)
162162
end
163163

164-
# old approach - keep for now!
165-
# correct_velocity!(U, Hv, ∇p, rD, config)
166-
# interpolate!(Uf, U, config)
167-
# correct_boundaries!(Uf, U, boundaries.U, time, config)
168-
# flux!(mdotf, Uf, config) # old approach
169-
170164
# new approach
171165
correct_mass_flux(mdotf, p_eqn, config)
172166
correct_velocity!(U, Hv, ∇p, rD, config)

0 commit comments

Comments
 (0)