• 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

81.63
/src/FluxCalculator/reconstruct!.jl
1
"""
2
```julia
3
reconstruct!(state::State)
4
```
5

6
Reconstruct the prognostic variables at the cell interfaces of their respective grids, using the Monotonic Upstream-centered Scheme for Conservation Laws (MUSCL).
7

8
This method calls specialized methods for each prognostic variable.
9

10
```julia
11
reconstruct!(state::State, variable::Rho)
12
```
13

14
Reconstruct the density.
15

16
Since the transporting velocity is ``P \\widehat{\\boldsymbol{u}}``, the density is divided by ``P`` before reconstruction.
17

18
```julia
19
reconstruct!(state::State, variable::RhoP)
20
```
21

22
Reconstruct the density fluctuations.
23

24
Similar to the density, the density fluctuations are divided by ``P`` before reconstruction.
25

26
```julia
27
reconstruct!(state::State, variable::U)
28
```
29

30
Reconstruct the zonal momentum.
31

32
Since the transporting velocity is ``P \\widehat{\\boldsymbol{u}}``, the zonal momentum is divided by ``P`` interpolated to the respective cell interfaces before reconstruction.
33

34
```julia
35
reconstruct!(state::State, variable::V)
36
```
37

38
Reconstruct the meridional momentum.
39

40
Similar to the zonal momentum, the meridional momentum is divided by ``P`` interpolated to the respective cell interfaces before reconstruction.
41

42
```julia
43
reconstruct!(state::State, variable::W)
44
```
45

46
Reconstruct the vertical momentum.
47

48
The vertical momentum is computed with `compute_vertical_wind`, `set_zonal_boundaries_of_field!` and `set_meridional_boundaries_of_field!`. Similar to the zonal and meridional momenta, the vertical momentum is divided by ``P`` interpolated to the respective cell interfaces before reconstruction.
49

50
```julia
51
reconstruct!(state::State, tracer_setup::NoTracer)
52
```
53

54
Return for configurations without tracer transport.
55

56
```julia
57
reconstruct!(state::State, tracer_setup::TracerOn)
58
```
59

60
Reconstruct the tracers.
61

62
Similar to the density, the tracers are divided by ``P`` before reconstruction.
63

64
# Arguments
65

66
  - `state`: Model state.
67

68
  - `variable`: The reconstructed variable.
69

70
  - `tracer_setup`: General tracer-transport configuration.
71

72
# See also
73

74
  - [`PinCFlow.FluxCalculator.apply_3d_muscl!`](@ref)
75

76
  - [`PinCFlow.Update.compute_vertical_wind`](@ref)
77

78
  - [`PinCFlow.Boundaries.set_zonal_boundaries_of_field!`](@ref)
79

80
  - [`PinCFlow.Boundaries.set_meridional_boundaries_of_field!`](@ref)
81
"""
82
function reconstruct! end
83

84
function reconstruct!(state::State)
1,044✔
85
    (; tracer_setup) = state.namelists.tracer
1,044✔
86

87
    reconstruct!(state, Rho())
1,044✔
88
    reconstruct!(state, RhoP())
1,044✔
89
    reconstruct!(state, U())
1,044✔
90
    reconstruct!(state, V())
1,044✔
91
    reconstruct!(state, W())
1,044✔
92

93
    reconstruct!(state, tracer_setup)
1,044✔
94

95
    return
1,044✔
96
end
97

98
function reconstruct!(state::State, variable::Rho)
1,044✔
99
    (; limiter_type) = state.namelists.discretization
1,044✔
100
    (; k0, k1, nxx, nyy, nzz) = state.domain
1,044✔
101
    (; rho) = state.variables.predictands
1,044✔
102
    (; phi) = state.variables.auxiliaries
1,044✔
103
    (; rhotilde) = state.variables.reconstructions
1,044✔
104
    (; pbar) = state.atmosphere
1,044✔
105

106
    kk = (k0 - 1):(k1 + 1)
1,044✔
107

108
    @ivy phi[:, :, kk] .= rho[:, :, kk] ./ pbar[:, :, kk]
2,088✔
109

110
    apply_3d_muscl!(phi, rhotilde, nxx, nyy, nzz, limiter_type)
1,044✔
111

112
    return
1,044✔
113
end
114

115
function reconstruct!(state::State, variable::RhoP)
1,044✔
116
    (; limiter_type) = state.namelists.discretization
1,044✔
117
    (; k0, k1, nxx, nyy, nzz) = state.domain
1,044✔
118
    (; rhop) = state.variables.predictands
1,044✔
119
    (; phi) = state.variables.auxiliaries
1,044✔
120
    (; rhoptilde) = state.variables.reconstructions
1,044✔
121
    (; pbar) = state.atmosphere
1,044✔
122

123
    kk = (k0 - 1):(k1 + 1)
1,044✔
124

125
    @ivy phi[:, :, kk] .= rhop[:, :, kk] ./ pbar[:, :, kk]
2,088✔
126

127
    apply_3d_muscl!(phi, rhoptilde, nxx, nyy, nzz, limiter_type)
1,044✔
128

129
    return
1,044✔
130
end
131

132
function reconstruct!(state::State, variable::U)
1,044✔
133
    (; limiter_type) = state.namelists.discretization
1,044✔
134
    (; k0, k1, nxx, nyy, nzz) = state.domain
1,044✔
135
    (; rho, u) = state.variables.predictands
1,044✔
136
    (; phi) = state.variables.auxiliaries
1,044✔
137
    (; utilde) = state.variables.reconstructions
1,044✔
138
    (; rhobar, pbar) = state.atmosphere
1,044✔
139

140
    @ivy for k in (k0 - 1):(k1 + 1), j in 1:nyy, i in 1:(nxx - 1)
12,528✔
141
        rhoedge =
2,287,440✔
142
            0.5 * (
143
                rho[i, j, k] +
144
                rho[i + 1, j, k] +
145
                rhobar[i, j, k] +
146
                rhobar[i + 1, j, k]
147
            )
148
        pedge = 0.5 * (pbar[i, j, k] + pbar[i + 1, j, k])
2,287,440✔
149
        phi[i, j, k] = u[i, j, k] * rhoedge / pedge
2,287,440✔
150
    end
×
151

152
    apply_3d_muscl!(phi, utilde, nxx, nyy, nzz, limiter_type)
1,044✔
153

154
    return
1,044✔
155
end
156

157
function reconstruct!(state::State, variable::V)
1,044✔
158
    (; limiter_type) = state.namelists.discretization
1,044✔
159
    (; k0, k1, nxx, nyy, nzz) = state.domain
1,044✔
160
    (; rho, v) = state.variables.predictands
1,044✔
161
    (; phi) = state.variables.auxiliaries
1,044✔
162
    (; vtilde) = state.variables.reconstructions
1,044✔
163
    (; rhobar, pbar) = state.atmosphere
1,044✔
164

165
    @ivy for k in (k0 - 1):(k1 + 1), j in 1:(nyy - 1), i in 1:nxx
12,528✔
166
        rhoedge =
2,239,488✔
167
            0.5 * (
168
                rho[i, j, k] +
169
                rho[i, j + 1, k] +
170
                rhobar[i, j, k] +
171
                rhobar[i, j + 1, k]
172
            )
173
        pedge = 0.5 * (pbar[i, j, k] + pbar[i, j + 1, k])
2,239,488✔
174
        phi[i, j, k] = v[i, j, k] * rhoedge / pedge
2,239,488✔
175
    end
×
176

177
    apply_3d_muscl!(phi, vtilde, nxx, nyy, nzz, limiter_type)
1,044✔
178

179
    return
1,044✔
180
end
181

182
function reconstruct!(state::State, variable::W)
1,044✔
183
    (; namelists, domain, grid) = state
1,044✔
184
    (; limiter_type) = state.namelists.discretization
1,044✔
185
    (; i0, i1, j0, j1, k0, k1, nxx, nyy, nzz) = domain
1,044✔
186
    (; jac) = grid
1,044✔
187
    (; predictands) = state.variables
1,044✔
188
    (; rho, w) = predictands
1,044✔
189
    (; phi) = state.variables.auxiliaries
1,044✔
190
    (; wtilde) = state.variables.reconstructions
1,044✔
191
    (; rhobar, pbar) = state.atmosphere
1,044✔
192

193
    @ivy phi[:, :, (k0 - 1):(k1 + 1)] .= w[:, :, (k0 - 1):(k1 + 1)]
1,044✔
194

195
    @ivy for k in (k0 - 1):(k1 + 1), j in j0:j1, i in i0:i1
12,528✔
196
        phi[i, j, k] = compute_vertical_wind(i, j, k, state)
773,280✔
197
    end
×
198

199
    set_zonal_boundaries_of_field!(phi, namelists, domain)
1,044✔
200
    set_meridional_boundaries_of_field!(phi, namelists, domain)
1,044✔
201

202
    @ivy for k in (k0 - 1):(k1 + 1), j in 1:nyy, i in 1:nxx
12,528✔
203
        rhoedgeu =
2,439,936✔
204
            (
205
                jac[i, j, k + 1] * (rho[i, j, k] + rhobar[i, j, k]) +
206
                jac[i, j, k] * (rho[i, j, k + 1] + rhobar[i, j, k + 1])
207
            ) / (jac[i, j, k] + jac[i, j, k + 1])
208
        pedgeu =
2,439,936✔
209
            (
210
                jac[i, j, k + 1] * pbar[i, j, k] +
211
                jac[i, j, k] * pbar[i, j, k + 1]
212
            ) / (jac[i, j, k] + jac[i, j, k + 1])
213
        phi[i, j, k] *= rhoedgeu / pedgeu
2,439,936✔
214
    end
×
215

216
    apply_3d_muscl!(phi, wtilde, nxx, nyy, nzz, limiter_type)
1,044✔
217

218
    return
1,044✔
219
end
220

221
function reconstruct!(state::State, tracer_setup::NoTracer)
1,044✔
222
    return
1,044✔
223
end
224

NEW
225
function reconstruct!(state::State, tracer_setup::TracerOn)
×
226
    (; limiter_type) = state.namelists.discretization
×
227
    (; k0, k1, nxx, nyy, nzz) = state.domain
×
228
    (; phi) = state.variables.auxiliaries
×
229
    (; pbar) = state.atmosphere
×
230
    (; tracerreconstructions, tracerpredictands) = state.tracer
×
231

232
    @ivy for field in 1:fieldcount(TracerPredictands)
×
233
        chi = getfield(tracerpredictands, field)[:, :, :]
×
234
        for k in (k0 - 1):(k1 + 1), j in 1:nyy, i in 1:nxx
×
235
            phi[i, j, k] = chi[i, j, k] / pbar[i, j, k]
×
236
        end
×
237
        apply_3d_muscl!(
×
238
            phi,
239
            getfield(tracerreconstructions, field),
240
            nxx,
241
            nyy,
242
            nzz,
243
            limiter_type,
244
        )
245
    end
×
246

247
    return
×
248
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