Skip to content

Commit a4f9ebe

Browse files
Default solving grid stretching w Float64
1 parent 632eef3 commit a4f9ebe

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Meshes/interval.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ function IntervalMesh(
191191
domain::IntervalDomain{CT},
192192
stretch::GeneralizedExponentialStretching{FT};
193193
nelems::Int,
194+
FT_solve = Float64,
195+
tol = 1e-3,
194196
reverse_mode::Bool = false,
195197
) where {CT <: Geometry.Abstract1DPoint{FT}} where {FT}
196198
if nelems 1
197199
throw(ArgumentError("`nelems` must be ≥ 2"))
198200
end
199201

200-
dz_bottom, dz_top = stretch.dz_bottom, stretch.dz_top
202+
dz_bottom = FT_solve(stretch.dz_bottom)
203+
dz_top = FT_solve(stretch.dz_top)
201204
if !(dz_bottom dz_top) && !reverse_mode
202205
throw(ArgumentError("dz_bottom must be ≤ dz_top"))
203206
end
@@ -222,20 +225,22 @@ function IntervalMesh(
222225
exp_stretch(ζ, h) = ζ == 1 ? ζ : -h * log(1 - (1 - exp(-1 / h)) * ζ)
223226

224227
# nondimensional vertical coordinate (]0.0, 1.0])
225-
ζ_n = LinRange(one(FT), nelems, nelems) / nelems
228+
ζ_n = LinRange(one(FT_solve), nelems, nelems) / nelems
226229

227230
# find bottom height variation
228231
find_bottom(h) = dz_bottom - z_top * exp_stretch(ζ_n[1], h)
229232
# we use linearization
230233
# h_bottom ≈ -dz_bottom / (z_top - z_bottom) / log(1 - 1/nelems)
231234
# to approx bracket the lower / upper bounds of root sol
232-
guess₋ = -dz_bottom / (z_top - z_bottom) / log(1 - FT(1 / (nelems - 1)))
233-
guess₊ = -dz_bottom / (z_top - z_bottom) / log(1 - FT(1 / (nelems + 1)))
235+
guess₋ =
236+
-dz_bottom / (z_top - z_bottom) / log(1 - FT_solve(1 / (nelems - 1)))
237+
guess₊ =
238+
-dz_bottom / (z_top - z_bottom) / log(1 - FT_solve(1 / (nelems + 1)))
234239
h_bottom_sol = RootSolvers.find_zero(
235240
find_bottom,
236241
RootSolvers.SecantMethod(guess₋, guess₊),
237242
RootSolvers.CompactSolution(),
238-
RootSolvers.ResidualTolerance(FT(1e-3)),
243+
RootSolvers.ResidualTolerance(FT_solve(tol)),
239244
)
240245
if h_bottom_sol.converged !== true
241246
error(
@@ -249,13 +254,13 @@ function IntervalMesh(
249254
# we use the linearization
250255
# h_top ≈ (z_top - dz_top) / z_top / log(nelem)
251256
# to approx braket the lower, upper bounds of root sol
252-
guess₋ = ((z_top - z_bottom) - dz_top) / z_top / FT(log(nelems + 1))
253-
guess₊ = ((z_top - z_bottom) - dz_top) / z_top / FT(log(nelems - 1))
257+
guess₋ = ((z_top - z_bottom) - dz_top) / z_top / FT_solve(log(nelems + 1))
258+
guess₊ = ((z_top - z_bottom) - dz_top) / z_top / FT_solve(log(nelems - 1))
254259
h_top_sol = RootSolvers.find_zero(
255260
find_top,
256261
RootSolvers.SecantMethod(guess₋, guess₊),
257262
RootSolvers.CompactSolution(),
258-
RootSolvers.ResidualTolerance(FT(1e-3)),
263+
RootSolvers.ResidualTolerance(FT_solve(1e-3)),
259264
)
260265
if h_top_sol.converged !== true
261266
error(
@@ -271,7 +276,7 @@ function IntervalMesh(
271276
faces = (z_bottom + (z_top - z_bottom)) * exp_stretch.(ζ_n, h)
272277

273278
# add the bottom level
274-
faces = [z_bottom; faces...]
279+
faces = FT_solve[z_bottom; faces...]
275280
if reverse_mode
276281
reverse!(faces)
277282
faces = map(f -> eltype(faces)(-f), faces)

0 commit comments

Comments
 (0)