@@ -213,10 +213,16 @@ function init_auxiliary_node_variables!(auxiliary_variables, mesh::P4estMesh{2,
213
213
aux_node_vars[17 : 19 , i, j, element] = SVector (metric_contravariant[1 , 1 ],
214
214
metric_contravariant[1 , 2 ],
215
215
metric_contravariant[2 , 2 ])
216
- end
217
216
218
- # Christoffel symbols of the second kind (aux_node_vars[20:25, :, :, element])
219
- calc_christoffel_symbols! (aux_node_vars, mesh, equations, dg, element)
217
+ # Christoffel symbols of the second kind
218
+ aux_node_vars[20 : 25 , i, j, element] = calc_christoffel_symbols (v1, v2, v3,
219
+ v4,
220
+ dg. basis. nodes[i],
221
+ dg. basis. nodes[j],
222
+ radius,
223
+ metric_contravariant,
224
+ equations)
225
+ end
220
226
end
221
227
222
228
return nothing
@@ -290,68 +296,46 @@ end
290
296
return SMatrix {3, 2} (A[1 , 1 ], A[2 , 1 ], 0.0f0 , A[1 , 2 ], A[2 , 2 ], 0.0f0 )
291
297
end
292
298
293
- # Calculate Christoffel symbols approximately using the collocation derivative. Note that
294
- # they could alternatively be computed exactly without affecting the entropy stability
295
- # properties of the scheme.
296
- function calc_christoffel_symbols! (aux_node_vars, mesh:: P4estMesh{2, 3} ,
297
- equations:: AbstractCovariantEquations{2, 3} , dg,
298
- element)
299
- (; derivative_matrix) = dg. basis
300
-
301
- for j in eachnode (dg), i in eachnode (dg)
302
-
303
- # Numerically differentiate covariant metric components with respect to ξ¹
304
- dG11dxi1 = zero (eltype (aux_node_vars))
305
- dG12dxi1 = zero (eltype (aux_node_vars))
306
- dG22dxi1 = zero (eltype (aux_node_vars))
307
- for ii in eachnode (dg)
308
- aux_node_ii = get_node_aux_vars (aux_node_vars, equations, dg, ii, j,
309
- element)
310
- Gcov_ii = metric_covariant (aux_node_ii, equations)
311
- dG11dxi1 = dG11dxi1 + derivative_matrix[i, ii] * Gcov_ii[1 , 1 ]
312
- dG12dxi1 = dG12dxi1 + derivative_matrix[i, ii] * Gcov_ii[1 , 2 ]
313
- dG22dxi1 = dG22dxi1 + derivative_matrix[i, ii] * Gcov_ii[2 , 2 ]
314
- end
315
-
316
- # Numerically differentiate covariant metric components with respect to ξ²
317
- dG11dxi2 = zero (eltype (aux_node_vars))
318
- dG12dxi2 = zero (eltype (aux_node_vars))
319
- dG22dxi2 = zero (eltype (aux_node_vars))
320
- for jj in eachnode (dg)
321
- aux_node_jj = get_node_aux_vars (aux_node_vars, equations, dg, i, jj,
322
- element)
323
- Gcov_jj = metric_covariant (aux_node_jj, equations)
324
- dG11dxi2 = dG11dxi2 + derivative_matrix[j, jj] * Gcov_jj[1 , 1 ]
325
- dG12dxi2 = dG12dxi2 + derivative_matrix[j, jj] * Gcov_jj[1 , 2 ]
326
- dG22dxi2 = dG22dxi2 + derivative_matrix[j, jj] * Gcov_jj[2 , 2 ]
327
- end
299
+ # Calculate the covariant metric tensor components G₁₁, G₁₂ (= G₂₁), and G₂₂ and return in
300
+ # that order as an SVector of length 3
301
+ function calc_metric_covariant (v1, v2, v3, v4, xi1, xi2, radius, equations)
302
+ A = calc_basis_covariant (v1, v2, v3, v4, xi1, xi2, radius,
303
+ equations. global_coordinate_system)
304
+ Gcov = A' * A
305
+ return SVector (Gcov[1 , 1 ], Gcov[1 , 2 ], Gcov[2 , 2 ])
306
+ end
328
307
329
- # Compute Christoffel symbols of the first kind
330
- christoffel_firstkind_1 = SMatrix {2, 2} (0.5f0 * dG11dxi1,
331
- 0.5f0 * dG11dxi2,
332
- 0.5f0 * dG11dxi2,
333
- dG12dxi2 - 0.5f0 * dG22dxi1)
334
- christoffel_firstkind_2 = SMatrix {2, 2} (dG12dxi1 - 0.5f0 * dG11dxi2,
335
- 0.5f0 * dG22dxi1,
336
- 0.5f0 * dG22dxi1,
337
- 0.5f0 * dG22dxi2)
338
-
339
- # Raise indices to get Christoffel symbols of the second kind
340
- aux_node = get_node_aux_vars (aux_node_vars, equations, dg, i, j, element)
341
- Gcon = metric_contravariant (aux_node, equations)
342
- aux_node_vars[20 , i, j, element] = Gcon[1 , 1 ] * christoffel_firstkind_1[1 , 1 ] +
343
- Gcon[1 , 2 ] * christoffel_firstkind_2[1 , 1 ]
344
- aux_node_vars[21 , i, j, element] = Gcon[1 , 1 ] * christoffel_firstkind_1[1 , 2 ] +
345
- Gcon[1 , 2 ] * christoffel_firstkind_2[1 , 2 ]
346
- aux_node_vars[22 , i, j, element] = Gcon[1 , 1 ] * christoffel_firstkind_1[2 , 2 ] +
347
- Gcon[1 , 2 ] * christoffel_firstkind_2[2 , 2 ]
348
-
349
- aux_node_vars[23 , i, j, element] = Gcon[2 , 1 ] * christoffel_firstkind_1[1 , 1 ] +
350
- Gcon[2 , 2 ] * christoffel_firstkind_2[1 , 1 ]
351
- aux_node_vars[24 , i, j, element] = Gcon[2 , 1 ] * christoffel_firstkind_1[1 , 2 ] +
352
- Gcon[2 , 2 ] * christoffel_firstkind_2[1 , 2 ]
353
- aux_node_vars[25 , i, j, element] = Gcon[2 , 1 ] * christoffel_firstkind_1[2 , 2 ] +
354
- Gcon[2 , 2 ] * christoffel_firstkind_2[2 , 2 ]
355
- end
308
+ # Calculate the Christoffel symbols of the second kind using ForwardDiff to automatically
309
+ # differentiate the metric, and return the components Γ¹₁₁, Γ¹₁₂ (= Γ¹₂₁), Γ¹₂₂, Γ²₁₁,
310
+ # Γ²₁₂ (= Γ²₂₁), and Γ²₂₂ as an SVector of length 6
311
+ function calc_christoffel_symbols (v1, v2, v3, v4, xi1, xi2, radius, Gcon, equations)
312
+
313
+ # Use ForwardDiff to differentiate the covariant metric tensor components
314
+ dGdxi1 = derivative (x -> calc_metric_covariant (v1, v2, v3, v4, x, xi2, radius,
315
+ equations), xi1)
316
+ dGdxi2 = derivative (x -> calc_metric_covariant (v1, v2, v3, v4, xi1, x, radius,
317
+ equations), xi2)
318
+
319
+ # Extract SVector components from derivatives of vectors
320
+ dG11dxi1, dG12dxi1, dG22dxi1 = dGdxi1
321
+ dG11dxi2, dG12dxi2, dG22dxi2 = dGdxi2
322
+
323
+ # Compute Christoffel symbols of the first kind
324
+ Gamma_1 = SMatrix {2, 2} (0.5f0 * dG11dxi1, # Γ₁₁₁
325
+ 0.5f0 * dG11dxi2, # Γ₁₂₁
326
+ 0.5f0 * dG11dxi2, # Γ₁₁₂
327
+ dG12dxi2 - 0.5f0 * dG22dxi1) # Γ₁₂₂
328
+ Gamma_2 = SMatrix {2, 2} (dG12dxi1 - 0.5f0 * dG11dxi2, # Γ₂₁₁
329
+ 0.5f0 * dG22dxi1, # Γ₂₂₁
330
+ 0.5f0 * dG22dxi1, # Γ₂₁₂
331
+ 0.5f0 * dG22dxi2) # Γ₂₂₂
332
+
333
+ # Raise indices to get Christoffel symbols of the second kind
334
+ return SVector (Gcon[1 , 1 ] * Gamma_1[1 , 1 ] + Gcon[1 , 2 ] * Gamma_2[1 , 1 ], # Γ¹₁₁
335
+ Gcon[1 , 1 ] * Gamma_1[1 , 2 ] + Gcon[1 , 2 ] * Gamma_2[1 , 2 ], # Γ¹₁₂ (= Γ¹₂₁)
336
+ Gcon[1 , 1 ] * Gamma_1[2 , 2 ] + Gcon[1 , 2 ] * Gamma_2[2 , 2 ], # Γ¹₂₂
337
+ Gcon[2 , 1 ] * Gamma_1[1 , 1 ] + Gcon[2 , 2 ] * Gamma_2[1 , 1 ], # Γ²₁₁
338
+ Gcon[2 , 1 ] * Gamma_1[1 , 2 ] + Gcon[2 , 2 ] * Gamma_2[1 , 2 ], # Γ²₁₂ (= Γ²₂₁)
339
+ Gcon[2 , 1 ] * Gamma_1[2 , 2 ] + Gcon[2 , 2 ] * Gamma_2[2 , 2 ]) # Γ²₂₂
356
340
end
357
341
end # @muladd
0 commit comments