97
97
"""
98
98
parsevalsum2(uh, grid)
99
99
100
- Return `Σ |uh|²` on the `grid`, which is equal to the domain integral of `u`. More specifically,
101
- it returns
100
+ Return `Σ |uh|²` on the `grid`, which is equal to the domain integral `u` squared.
101
+ For example on a 2D grid, `parsevalsum2` returns
102
+
102
103
```math
103
- \\ sum_{𝐤} |û_{𝐤}|² L_x L_y = \\ int u(𝐱) ² \\ , 𝖽x 𝖽y \\ ,,
104
+ \\ sum_{𝐤} |û_{𝐤}|² L_x L_y = \\ iint u ² \\ , 𝖽x 𝖽y \\ ,,
104
105
```
106
+
105
107
where ``û_{𝐤} =`` `uh` `` / (n_x e^{i 𝐤 ⋅ 𝐱₀})``. The elements of the vector ``𝐱₀`` are the
106
108
left-most position in each direction, e.g., for a 2D grid `(grid.x[1], grid.y[1])`.
107
109
"""
108
110
function parsevalsum2 (uh, grid:: TwoDGrid )
109
- if size (uh, 1 ) == grid. nkr # uh is in conjugate symmetric form
110
- U = sum (abs2, uh[1 , :]) # k=0 modes
111
- U += 2 * sum (abs2, uh[2 : end , :]) # sum k>0 modes twice
111
+ if size (uh, 1 ) == grid. nkr # uh is in conjugate symmetric form
112
+ U = sum (abs2, uh[1 , :]) # k=0 modes
113
+ U += sum (abs2, uh[grid. nkr, :]) # k=nx/2 modes
114
+ U += 2 * sum (abs2, uh[2 : grid. nkr- 1 , :]) # sum twice for 0 < k < nx/2 modes
112
115
else # count every mode once
113
116
U = sum (abs2, uh)
114
117
end
@@ -119,9 +122,10 @@ function parsevalsum2(uh, grid::TwoDGrid)
119
122
end
120
123
121
124
function parsevalsum2 (uh, grid:: OneDGrid )
122
- if size (uh, 1 ) == grid. nkr # uh is conjugate symmetric
123
- U = sum (abs2, CUDA. @allowscalar uh[1 ]) # k=0 modes
124
- U += @views 2 * sum (abs2, uh[2 : end ]) # sum k>0 modes twice
125
+ if size (uh, 1 ) == grid. nkr # uh is conjugate symmetric
126
+ U = sum (abs2, CUDA. @allowscalar uh[1 ]) # k=0 mode
127
+ U += sum (abs2, CUDA. @allowscalar uh[grid. nkr]) # k=nx/2 mode
128
+ U += @views 2 * sum (abs2, uh[2 : grid. nkr- 1 ]) # sum twice for 0 < k < nx/2 modes
125
129
else # count every mode once
126
130
U = sum (abs2, uh)
127
131
end
@@ -134,17 +138,20 @@ end
134
138
"""
135
139
parsevalsum(uh, grid)
136
140
137
- Return `real(Σ uh)` on the `grid`, i.e.
141
+ Return `real(Σ uh)` on the `grid`, i.e.,
142
+
138
143
```math
139
144
ℜ [ \\ sum_{𝐤} û_{𝐤} L_x L_y ] \\ ,,
145
+
140
146
```
141
147
where ``û_{𝐤} =`` `uh` `` / (n_x e^{i 𝐤 ⋅ 𝐱₀})``. The elements of the vector ``𝐱₀`` are the
142
148
left-most position in each direction, e.g., for a 2D grid `(grid.x[1], grid.y[1])`.
143
149
"""
144
150
function parsevalsum (uh, grid:: TwoDGrid )
145
- if size (uh, 1 ) == grid. nkr # uh is conjugate symmetric
146
- U = sum (uh[1 , :]) # k=0 modes
147
- U += 2 * sum (uh[2 : end , :]) # sum k>0 modes twice
151
+ if size (uh, 1 ) == grid. nkr # uh is conjugate symmetric
152
+ U = sum (uh[1 , :]) # k = 0 modes
153
+ U += sum (uh[grid. nkr, :]) # k = nx/2 modes
154
+ U += 2 * sum (uh[2 : grid. nkr- 1 , :]) # sum twice for 0 < k < nx/2 modes
148
155
else # count every mode once
149
156
U = sum (uh)
150
157
end
@@ -155,9 +162,10 @@ function parsevalsum(uh, grid::TwoDGrid)
155
162
end
156
163
157
164
function parsevalsum (uh, grid:: OneDGrid )
158
- if size (uh, 1 ) == grid. nkr # uh is conjugate symmetric
159
- U = uh[1 ] # k=0 mode
160
- U += 2 * sum (uh[2 : end ]) # sum k>0 modes twice
165
+ if size (uh, 1 ) == grid. nkr # uh is conjugate symmetric
166
+ U = uh[1 ] # k=0 mode
167
+ U += uh[grid. nkr] # k=nx/2 mode
168
+ U += 2 * sum (uh[2 : grid. nkr- 1 ]) # sum twice for 0 < k < nx/2 modes
161
169
else # count every mode once
162
170
U = sum (uh)
163
171
end
0 commit comments