• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Atmospheric-Dynamics-GUF / PinCFlow.jl / 18561934460

16 Oct 2025 12:54PM UTC coverage: 65.961% (-0.03%) from 65.988%
18561934460

push

github

web-flow
Removed `test_case` and made several dispatches more precise (#104)

* Removed `test_case`.

* Made several dispatches more precise.

* Removed `examples.md` (was comitted by accident).

* Renamed `AbstractVariable` to `AbstractPredictand` and removed some of its subtypes (these are direct subtypes of `Any` now).

* Some simplifications and additional comments in initialize_rays!.

* Corrected a few typos.

* Moved the namelist parameter "model" to AtmosphereNamelist and removed SettingNamelist. Reformatted the code.

104 of 119 new or added lines in 44 files covered. (87.39%)

4 existing lines in 4 files now uncovered.

4951 of 7506 relevant lines covered (65.96%)

1423740.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.78
/src/MSGWaM/MeanFlowEffect/smooth_gw_tendencies!.jl
1
"""
2
```julia
3
smooth_gw_tendencies!(state::State)
4
```
5

6
Apply spatial smoothing to gravity-wave tendency fields by dispatching to a method specific for the chosen filter (`state.namelists.wkb.filter_type`) and dimensionality of the domain.
7

8
```julia
9
smooth_gw_tendencies!(
10
    output::AbstractArray{<:AbstractFloat, 3},
11
    state::State,
12
    filter_type::Box,
13
    direction::XYZ,
14
)
15
```
16

17
Apply a 3D box filter to smooth in all spatial directions.
18

19
Applies the moving average
20

21
```math
22
\\widetilde{\\phi}_{i, j, k} = \\left(2 N_\\mathrm{s} + 1\\right)^{- 3} \\sum\\limits_{\\lambda = i - N_\\mathrm{s}}^{i + N_\\mathrm{s}} \\sum\\limits_{\\mu = j - N_\\mathrm{s}}^{j + N_\\mathrm{s}} \\sum\\limits_{\\nu = k - N_\\mathrm{s}}^{k + N_\\mathrm{s}} \\phi_{\\lambda, \\mu, \\nu},
23
```
24

25
where ``N_\\mathrm{s}`` is the order of the filter (`state.namelists.wkb.filter_order`).
26

27
```julia
28
smooth_gw_tendencies!(
29
    output::AbstractArray{<:AbstractFloat, 3},
30
    state::State,
31
    filter_type::Box,
32
    direction::XZ,
33
)
34
```
35

36
Apply a 2D box filter to smooth in ``\\widehat{x}`` and ``\\widehat{z}``.
37

38
Applies the moving average
39

40
```math
41
\\widetilde{\\phi}_{i, j, k} = \\left(2 N_\\mathrm{s} + 1\\right)^{- 2} \\sum\\limits_{\\lambda = i - N_\\mathrm{s}}^{i + N_\\mathrm{s}} \\sum\\limits_{\\nu = k - N_\\mathrm{s}}^{k + N_\\mathrm{s}} \\phi_{\\lambda, j, \\nu},
42
```
43

44
where ``N_\\mathrm{s}`` is the order of the filter (`state.namelists.wkb.filter_order`).
45

46
```julia
47
smooth_gw_tendencies!(
48
    output::AbstractArray{<:AbstractFloat, 3},
49
    state::State,
50
    filter_type::Box,
51
    direction::YZ,
52
)
53
```
54

55
Apply a 2D box filter to smooth in ``\\widehat{y}`` and ``\\widehat{z}``.
56

57
Applies the moving average
58

59
```math
60
\\widetilde{\\phi}_{i, j, k} = \\left(2 N_\\mathrm{s} + 1\\right)^{- 2} \\sum\\limits_{\\mu = j - N_\\mathrm{s}}^{j + N_\\mathrm{s}} \\sum\\limits_{\\nu = k - N_\\mathrm{s}}^{k + N_\\mathrm{s}} \\phi_{i, \\mu, \\nu},
61
```
62

63
where ``N_\\mathrm{s}`` is the order of the filter (`state.namelists.wkb.filter_order`).
64

65
```julia
66
smooth_gw_tendencies!(
67
    output::AbstractArray{<:AbstractFloat, 3},
68
    state::State,
69
    filter_type::Box,
70
    direction::Z,
71
)
72
```
73

74
Apply a 1D box filter to smooth in ``\\widehat{z}``.
75

76
Applies the moving average
77

78
```math
79
\\widetilde{\\phi}_{i, j, k} = \\left(2 N_\\mathrm{s} + 1\\right)^{- 1} \\sum\\limits_{\\nu = k - N_\\mathrm{s}}^{k + N_\\mathrm{s}} \\phi_{i, j, \\nu},
80
```
81

82
where ``N_\\mathrm{s}`` is the order of the filter (`state.namelists.wkb.filter_order`).
83

84
```julia
85
smooth_gw_tendencies!(
86
    output::AbstractArray{<:AbstractFloat, 3},
87
    state::State,
88
    filter_type::Shapiro,
89
    direction::XYZ,
90
)
91
```
92

93
Apply a 3D Shapiro filter to smooth in all spatial directions.
94

95
A 1D Shapiro filter is applied sequentially in ``\\widehat{x}``, ``\\widehat{y}`` and ``\\widehat{z}``.
96

97
```julia
98
smooth_gw_tendencies!(
99
    output::AbstractArray{<:AbstractFloat, 3},
100
    state::State,
101
    filter_type::Shapiro,
102
    direction::XZ,
103
)
104
```
105

106
Apply a 2D Shapiro filter to smooth in ``\\widehat{x}`` and ``\\widehat{z}``.
107

108
A 1D Shapiro filter is applied sequentially in ``\\widehat{x}`` and ``\\widehat{z}``.
109

110
```julia
111
smooth_gw_tendencies!(
112
    output::AbstractArray{<:AbstractFloat, 3},
113
    state::State,
114
    filter_type::Shapiro,
115
    direction::YZ,
116
)
117
```
118

119
Apply a 2D Shapiro filter to smooth in ``\\widehat{y}`` and ``\\widehat{z}``.
120

121
A 1D Shapiro filter is applied sequentially in ``\\widehat{y}`` and ``\\widehat{z}``.
122

123
```julia
124
smooth_gw_tendencies!(
125
    output::AbstractArray{<:AbstractFloat, 3},
126
    state::State,
127
    filter_type::Shapiro,
128
    direction::Z,
129
)
130
```
131

132
Apply a 1D Shapiro filter to smooth in ``\\widehat{z}``.
133

134
```julia
135
smooth_gw_tendencies!(
136
    output::AbstractArray{<:AbstractFloat, 3},
137
    state::State,
138
    filter_type::Shapiro,
139
    direction::Y,
140
)
141
```
142

143
Apply a 1D Shapiro filter to smooth in ``\\widehat{y}``.
144

145
```julia
146
smooth_gw_tendencies!(
147
    output::AbstractArray{<:AbstractFloat, 3},
148
    state::State,
149
    filter_type::Shapiro,
150
    direction::X,
151
)
152
```
153

154
Apply a 1D Shapiro filter to smooth in ``\\widehat{x}``.
155

156
```julia
157
smooth_gw_tendencies!(state::State, tracer_setup::TracerOn)
158
```
159

160
Apply smoothing to tracer tendencies.
161

162
```julia
163
smooth_gw_tendencies!(state::State, tracer_setup::NoTracer)
164
```
165

166
Return for configurations without tracer transport.
167

168
# Arguments
169

170
  - `state`: Model state.
171

172
  - `output`: Field to smooth.
173

174
  - `filter_type`: Filter type.
175

176
  - `direction`: Directions to smooth in.
177

178
  - `tracer_setup`: General tracer-transport configuration.
179

180
# See also
181

182
  - [`PinCFlow.MSGWaM.MeanFlowEffect.apply_shapiro_filter!`](@ref)
183
"""
184
function smooth_gw_tendencies! end
185

186
function smooth_gw_tendencies!(state::State)
26✔
187
    (; x_size, y_size) = state.namelists.domain
26✔
188
    (; smooth_tendencies, filter_type) = state.namelists.wkb
26✔
189
    (; dudt, dvdt, dthetadt) = state.wkb.tendencies
26✔
190
    (; tracer_setup) = state.namelists.tracer
26✔
191

192
    if !smooth_tendencies
26✔
193
        return
×
194
    end
195

196
    if x_size == y_size == 1
26✔
197
        smooth_gw_tendencies!(dudt, state, filter_type, Z())
×
198
        smooth_gw_tendencies!(dvdt, state, filter_type, Z())
×
199
        smooth_gw_tendencies!(dthetadt, state, filter_type, Z())
×
200
    elseif x_size == 1
26✔
201
        smooth_gw_tendencies!(dudt, state, filter_type, YZ())
×
202
        smooth_gw_tendencies!(dvdt, state, filter_type, YZ())
×
203
        smooth_gw_tendencies!(dthetadt, state, filter_type, YZ())
×
204
    elseif y_size == 1
26✔
205
        smooth_gw_tendencies!(dudt, state, filter_type, XZ())
×
206
        smooth_gw_tendencies!(dvdt, state, filter_type, XZ())
×
207
        smooth_gw_tendencies!(dthetadt, state, filter_type, XZ())
×
208
    else
209
        smooth_gw_tendencies!(dudt, state, filter_type, XYZ())
26✔
210
        smooth_gw_tendencies!(dvdt, state, filter_type, XYZ())
26✔
211
        smooth_gw_tendencies!(dthetadt, state, filter_type, XYZ())
26✔
212
    end
213

214
    smooth_gw_tendencies!(state, tracer_setup)
26✔
215

216
    return
26✔
217
end
218

219
function smooth_gw_tendencies!(
×
220
    output::AbstractArray{<:AbstractFloat, 3},
221
    state::State,
222
    filter_type::Box,
223
    direction::XYZ,
224
)
225
    (; nbx, nby, nbz) = state.namelists.domain
×
226
    (; filter_order) = state.namelists.wkb
×
227
    (; i0, i1, j0, j1, k0, k1) = state.domain
×
228

229
    if nbx < filter_order
×
230
        error("Error in smooth_gw_tendencies!: nbx < filter_order!")
×
231
    end
232
    if nby < filter_order
×
233
        error("Error in smooth_gw_tendencies!: nby < filter_order!")
×
234
    end
235
    if nbz < filter_order
×
236
        error("Error in smooth_gw_tendencies!: nbz < filter_order!")
×
237
    end
238

239
    input = copy(output)
×
240
    @ivy for k in k0:k1, j in j0:j1, i in i0:i1
×
241
        output[i, j, k] =
×
242
            sum(
243
                input[
244
                    (i - filter_order):(i + filter_order),
245
                    (j - filter_order):(j + filter_order),
246
                    (k - filter_order):(k + filter_order),
247
                ],
248
            ) / (2 * filter_order + 1)^3
249
    end
×
250

251
    return
×
252
end
253

254
function smooth_gw_tendencies!(
×
255
    output::AbstractArray{<:AbstractFloat, 3},
256
    state::State,
257
    filter_type::Box,
258
    direction::XZ,
259
)
260
    (; nbx, nbz) = state.namelists.domain
×
261
    (; filter_order) = state.namelists.wkb
×
262
    (; i0, i1, j0, j1, k0, k1) = state.domain
×
263

264
    if nbx < filter_order
×
265
        error("Error in smooth_gw_tendencies!: nbx < filter_order!")
×
266
    end
267
    if nbz < filter_order
×
268
        error("Error in smooth_gw_tendencies!: nbz < filter_order!")
×
269
    end
270

271
    input = copy(output)
×
272
    @ivy for k in k0:k1, j in j0:j1, i in i0:i1
×
273
        output[i, j, k] =
×
274
            sum(
275
                input[
276
                    (i - filter_order):(i + filter_order),
277
                    j,
278
                    (k - filter_order):(k + filter_order),
279
                ],
280
            ) / (2 * filter_order + 1)^2
281
    end
×
282

283
    return
×
284
end
285

286
function smooth_gw_tendencies!(
×
287
    output::AbstractArray{<:AbstractFloat, 3},
288
    state::State,
289
    filter_type::Box,
290
    direction::YZ,
291
)
292
    (; nby, nbz) = state.namelists.domain
×
293
    (; filter_order) = state.namelists.wkb
×
294
    (; i0, i1, j0, j1, k0, k1) = state.domain
×
295

296
    if nby < filter_order
×
297
        error("Error in smooth_gw_tendencies!: nby < filter_order!")
×
298
    end
299
    if nbz < filter_order
×
300
        error("Error in smooth_gw_tendencies!: nbz < filter_order!")
×
301
    end
302

303
    input = copy(output)
×
304
    @ivy for k in k0:k1, j in j0:j1, i in i0:i1
×
305
        output[i, j, k] =
×
306
            sum(
307
                input[
308
                    i,
309
                    (j - filter_order):(j + filter_order),
310
                    (k - filter_order):(k + filter_order),
311
                ],
312
            ) / (2 * filter_order + 1)^2
313
    end
×
314

315
    return
×
316
end
317

318
function smooth_gw_tendencies!(
×
319
    output::AbstractArray{<:AbstractFloat, 3},
320
    state::State,
321
    filter_type::Box,
322
    direction::Z,
323
)
324
    (; nbz) = state.namelists.domain
×
325
    (; filter_order) = state.namelists.wkb
×
326
    (; i0, i1, j0, j1, k0, k1) = state.domain
×
327

328
    if nbz < filter_order
×
329
        error("Error in smooth_gw_tendencies!: nbz < filter_order!")
×
330
    end
331

332
    input = copy(output)
×
333
    @ivy for k in k0:k1, j in j0:j1, i in i0:i1
×
334
        output[i, j, k] =
×
335
            sum(input[i, j, (k - filter_order):(k + filter_order)]) /
336
            (2 * filter_order + 1)
337
    end
×
338

339
    return
×
340
end
341

342
function smooth_gw_tendencies!(
78✔
343
    output::AbstractArray{<:AbstractFloat, 3},
344
    state::State,
345
    filter_type::Shapiro,
346
    direction::XYZ,
347
)
348
    smooth_gw_tendencies!(output, state, filter_type, X())
78✔
349
    smooth_gw_tendencies!(output, state, filter_type, Y())
78✔
350
    smooth_gw_tendencies!(output, state, filter_type, Z())
78✔
351
    return
78✔
352
end
353

354
function smooth_gw_tendencies!(
×
355
    output::AbstractArray{<:AbstractFloat, 3},
356
    state::State,
357
    filter_type::Shapiro,
358
    direction::XZ,
359
)
360
    smooth_gw_tendencies!(output, state, filter_type, X())
×
361
    smooth_gw_tendencies!(output, state, filter_type, Z())
×
362
    return
×
363
end
364

365
function smooth_gw_tendencies!(
×
366
    output::AbstractArray{<:AbstractFloat, 3},
367
    state::State,
368
    filter_type::Shapiro,
369
    direction::YZ,
370
)
371
    smooth_gw_tendencies!(output, state, filter_type, Y())
×
372
    smooth_gw_tendencies!(output, state, filter_type, Z())
×
373
    return
×
374
end
375

376
function smooth_gw_tendencies!(
78✔
377
    output::AbstractArray{<:AbstractFloat, 3},
378
    state::State,
379
    filter_type::Shapiro,
380
    direction::Z,
381
)
382
    (; nbz) = state.namelists.domain
78✔
383
    (; filter_order) = state.namelists.wkb
78✔
384
    (; nxx, nyy, k0, k1) = state.domain
78✔
385

386
    if nbz < filter_order
78✔
387
        error("Error in smooth_gw_tendencies!: nbz < filter_order!")
×
388
    end
389

390
    input = copy(output)
78✔
391
    @ivy for j in 1:nyy, i in 1:nxx
1,248✔
392
        apply_shapiro_filter!(
19,968✔
393
            output[i, j, :],
394
            input[i, j, :],
395
            k0:k1,
396
            Val(filter_order),
397
        )
398
    end
×
399

400
    return
78✔
401
end
402

403
function smooth_gw_tendencies!(
78✔
404
    output::AbstractArray{<:AbstractFloat, 3},
405
    state::State,
406
    filter_type::Shapiro,
407
    direction::Y,
408
)
409
    (; nby) = state.namelists.domain
78✔
410
    (; filter_order) = state.namelists.wkb
78✔
411
    (; nxx, nzz, j0, j1) = state.domain
78✔
412

413
    if nby < filter_order
78✔
414
        error("Error in smooth_gw_tendencies!: nby < filter_order!")
×
415
    end
416

417
    input = copy(output)
78✔
418
    @ivy for k in 1:nzz, i in 1:nxx
1,248✔
419
        apply_shapiro_filter!(
19,968✔
420
            output[i, :, k],
421
            input[i, :, k],
422
            j0:j1,
423
            Val(filter_order),
424
        )
425
    end
×
426

427
    return
78✔
428
end
429

430
function smooth_gw_tendencies!(
78✔
431
    output::AbstractArray{<:AbstractFloat, 3},
432
    state::State,
433
    filter_type::Shapiro,
434
    direction::X,
435
)
436
    (; nbx) = state.namelists.domain
78✔
437
    (; filter_order) = state.namelists.wkb
78✔
438
    (; nyy, nzz, i0, i1) = state.domain
78✔
439

440
    if nbx < filter_order
78✔
441
        error("Error in smooth_gw_tendencies!: nbx < filter_order!")
×
442
    end
443

444
    input = copy(output)
78✔
445
    @ivy for k in 1:nzz, j in 1:nyy
1,248✔
446
        apply_shapiro_filter!(
19,968✔
447
            output[:, j, k],
448
            input[:, j, k],
449
            i0:i1,
450
            Val(filter_order),
451
        )
452
    end
×
453

454
    return
78✔
455
end
456

NEW
457
function smooth_gw_tendencies!(state::State, tracer_setup::TracerOn)
×
458
    (; x_size, y_size) = state.namelists.domain
×
459
    (; smooth_tendencies, filter_type) = state.namelists.wkb
×
460
    (; dchidt) = state.tracer.tracerforcings.chiq0
×
461

462
    if !smooth_tendencies
×
463
        return
×
464
    end
465

466
    if x_size == y_size == 1
×
467
        smooth_gw_tendencies!(dchidt, state, filter_type, Z())
×
468
    elseif x_size == 1
×
469
        smooth_gw_tendencies!(dchidt, state, filter_type, YZ())
×
470
    elseif y_size == 1
×
471
        smooth_gw_tendencies!(dchidt, state, filter_type, XZ())
×
472
    else
473
        smooth_gw_tendencies!(dchidt, state, filter_type, XYZ())
×
474
    end
475

476
    return
×
477
end
478

479
function smooth_gw_tendencies!(state::State, tracer_setup::NoTracer)
26✔
480
    return
26✔
481
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc