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

JoshuaLampert / DispersiveShallowWater.jl / 6362649703

30 Sep 2023 12:01PM UTC coverage: 62.397% (-0.5%) from 62.94%
6362649703

push

github

web-flow
More figures (#50)

* add some more figures

* format

* create more figures

* several minor changes

* more figures

* fix typo

16 of 39 new or added lines in 6 files covered. (41.03%)

1 existing line in 1 file now uncovered.

604 of 968 relevant lines covered (62.4%)

157002.88 hits per line

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

46.88
/src/equations/equations.jl
1
"""
2
    AbstractEquations{NDIMS, NVARS}
3

4
An abstract supertype of specific equations such as the BBM-BBM equations.
5
The type parameters encode the number of spatial dimensions (`NDIMS`) and the
6
number of primary variables (`NVARS`) of the physics model.
7
"""
8
abstract type AbstractEquations{NDIMS, NVARS} end
9

10
# Retrieve number of variables from equation instance
11
@inline nvariables(::AbstractEquations{NDIMS, NVARS}) where {NDIMS, NVARS} = NVARS
256,104✔
12

13
"""
14
    eachvariable(equations::AbstractEquations)
15

16
Return an iterator over the indices that specify the location in relevant data structures
17
for the variables in `equations`. In particular, not the variables themselves are returned.
18
"""
19
@inline eachvariable(equations::AbstractEquations) = Base.OneTo(nvariables(equations))
29,655✔
20

21
"""
22
    get_name(equations::AbstractEquations)
23

24
Return the canonical, human-readable name for the given system of equations.
25
# Examples
26
```jldoctest
27
julia> DispersiveShallowWater.get_name(BBMBBMEquations1D(gravity_constant=1.0))
28
"BBMBBMEquations1D"
29
```
30
"""
31
get_name(equations::AbstractEquations) = equations |> typeof |> nameof |> string
1,773✔
32

33
"""
34
    varnames(conversion_function, equations)
35

36
Return the list of variable names when applying `conversion_function` to the
37
conserved variables associated to `equations`.
38
Common choices of the `conversion_function` are [`prim2prim`](@ref) and
39
[`prim2cons`](@ref).
40
"""
41
function varnames end
42

43
"""
44
    prim2prim(q, equations)
45

46
Return the primitive variables `q`. While this function is as trivial as `identity`,
47
it is also as useful.
48
"""
49
@inline prim2prim(q, ::AbstractEquations) = q
9✔
50

51
"""
52
    prim2cons(q, equations)
53

54
Convert the primitive variables `q` to the conserved variables for a given set of
55
`equations`. `q` is a vector type of the correct length `nvariables(equations)`.
56
Notice the function doesn't include any error checks for the purpose of efficiency,
57
so please make sure your input is correct.
58
The inverse conversion is performed by [`cons2prim`](@ref).
59
"""
60
function prim2cons end
61

62
"""
63
    cons2prim(u, equations)
64

65
Convert the conserved variables `u` to the primitive variables for a given set of
66
`equations`. `u` is a vector type of the correct length `nvariables(equations)`.
67
Notice the function doesn't include any error checks for the purpose of efficiency,
68
so please make sure your input is correct.
69
The inverse conversion is performed by [`prim2cons`](@ref).
70
"""
71
function cons2prim end
72

73
"""
74
    waterheight_total(q, equations)
75

76
Return the total waterheight of the primitive variables `q` for a given set of
77
`equations`, i.e. the waterheight plus the bathymetry.
78

79
`q` is a vector of the primitive variables at a single node, i.e., a vector
80
of the correct length `nvariables(equations)`.
81
"""
82
function waterheight_total end
83

NEW
84
varnames(::typeof(waterheight_total), equations) = ("η",)
×
85

86
"""
87
    waterheight(q, equations)
88

89
Return the waterheight of the primitive variables `q` for a given set of
90
`equations`, i.e. the waterheight above the bathymetry.
91

92
`q` is a vector of the primitive variables at a single node, i.e., a vector
93
of the correct length `nvariables(equations)`.
94
"""
95
function waterheight end
96

97
varnames(::typeof(waterheight), equations) = ("h",)
×
98

99
"""
100
    velocity(q, equations)
101

102
Return the velocity of the primitive variables `q` for a given set of
103
`equations`.
104

105
`q` is a vector of the primitive variables at a single node, i.e., a vector
106
of the correct length `nvariables(equations)`.
107
"""
108
function velocity end
109

110
varnames(::typeof(velocity), equations) = ("v",)
×
111

112
"""
113
    momentum(q, equations)
114

115
Return the momentum of the primitive variables `q` for a given set of
116
`equations`, i.e. the waterheight times the velocity.
117

118
`q` is a vector of the primitive variables at a single node, i.e., a vector
119
of the correct length `nvariables(equations)`.
120
"""
121
@inline function momentum(q, equations::AbstractEquations)
301,218✔
122
    return waterheight(q, equations) * velocity(q, equations)
301,218✔
123
end
124

125
varnames(::typeof(momentum), equations) = ("P",)
×
126

127
"""
128
    discharge(q, equations)
129

130
See [`momentum`](@ref).
131
"""
132
@inline discharge(q, equations::AbstractEquations) = momentum(q, equations)
9✔
133

134
varnames(::typeof(discharge), equations) = ("P",)
×
135

136
"""
137
    entropy(q, equations)
138

139
Return the entropy of the primitive variables `q` for a given set of
140
`equations`.
141

142
`q` is a vector of the primitive variables at a single node, i.e., a vector
143
of the correct length `nvariables(equations)`.
144
"""
145
function entropy end
146

147
varnames(::typeof(entropy), equations) = ("U",)
×
148

149
"""
150
    energy_total(q, equations)
151

152
Return the total energy of the primitive variables `q` for a given set of
153
`equations`.
154

155
`q` is a vector of the primitive variables at a single node, i.e., a vector
156
of the correct length `nvariables(equations)`.
157
"""
158
function energy_total end
159

160
varnames(::typeof(energy_total), equations) = ("e_total",)
×
161

162
# Add methods to show some information on systems of equations.
163
function Base.show(io::IO, equations::AbstractEquations)
9✔
164
    # Since this is not performance-critical, we can use `@nospecialize` to reduce latency.
165
    @nospecialize equations # reduce precompilation time
9✔
166

167
    print(io, get_name(equations), " with ")
9✔
168
    if nvariables(equations) == 1
9✔
169
        println(io, "one variable")
×
170
    else
171
        println(io, nvariables(equations), " variables")
9✔
172
    end
173
end
174

175
function Base.show(io::IO, ::MIME"text/plain", equations::AbstractEquations)
×
176
    # Since this is not performance-critical, we can use `@nospecialize` to reduce latency.
177
    @nospecialize equations # reduce precompilation time
×
178

179
    if get(io, :compact, false)
×
180
        show(io, equations)
×
181
    else
182
        println(io, get_name(equations))
×
183
        println(io, "#variables: ", nvariables(equations))
×
184
        for variable in eachvariable(equations)
×
185
            println("    variable " * string(variable), ": ",
×
186
                    varnames(prim2prim, equations)[variable])
187
        end
×
188
    end
189
end
190

191
@inline Base.ndims(::AbstractEquations{NDIMS}) where {NDIMS} = NDIMS
39✔
192

193
"""
194
    default_analysis_errors(equations)
195

196
Default analysis errors used by the [`AnalysisCallback`](@ref).
197
"""
198
default_analysis_errors(::AbstractEquations) = (:l2_error, :linf_error)
39✔
199

200
"""
201
    default_analysis_integrals(equations)
202

203
Default analysis integrals used by the [`AnalysisCallback`](@ref).
204
"""
205
default_analysis_integrals(::AbstractEquations) = Symbol[]
39✔
206

207
# BBM-BBM equations
208
abstract type AbstractBBMBBMEquations{NDIMS, NVARS} <: AbstractEquations{NDIMS, NVARS} end
209
include("bbm_bbm_1d.jl")
210
include("bbm_bbm_variable_bathymetry_1d.jl")
211

212
# Svärd-Kalisch equations
213
abstract type AbstractSvaerdKalischEquations{NDIMS, NVARS} <:
214
              AbstractEquations{NDIMS, NVARS} end
215
include("svaerd_kalisch_1d.jl")
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

© 2024 Coveralls, Inc