@@ -750,7 +750,7 @@ integrate(u, dg::Dg3D; normalize=true) = integrate(identity, u, dg; normalize=no
750
750
751
751
752
752
# Calculate L2/Linf error norms based on "exact solution"
753
- function calc_error_norms (dg:: Dg3D , t)
753
+ function calc_error_norms (func, dg:: Dg3D , t)
754
754
# Gather necessary information
755
755
equation = equations (dg)
756
756
n_nodes_analysis = size (dg. analysis_vandermonde, 1 )
@@ -770,8 +770,8 @@ function calc_error_norms(dg::Dg3D, t)
770
770
3 , size (dg. analysis_vandermonde, 1 ), size (dg. analysis_vandermonde, 1 ), size (dg. analysis_vandermonde, 2 ))
771
771
772
772
# Set up data structures
773
- l2_error = @SVector zeros ( nvariables ( equation))
774
- linf_error = @SVector zeros ( nvariables ( equation))
773
+ l2_error = zero ( func ( get_node_vars (dg . elements . u, dg, 1 , 1 , 1 , 1 ), equation))
774
+ linf_error = zero ( func ( get_node_vars (dg . elements . u, dg, 1 , 1 , 1 , 1 ), equation))
775
775
776
776
# Iterate over all elements for error calculations
777
777
for element_id in 1 : dg. n_elements
@@ -784,7 +784,7 @@ function calc_error_norms(dg::Dg3D, t)
784
784
jacobian_volume = inv (dg. elements. inverse_jacobian[element_id])^ ndims (dg)
785
785
for k in 1 : n_nodes_analysis, j in 1 : n_nodes_analysis, i in 1 : n_nodes_analysis
786
786
u_exact = dg. initial_conditions (get_node_coords (x, dg, i, j, k), t, equation)
787
- diff = u_exact - get_node_vars (u, dg, i, j, k)
787
+ diff = func ( u_exact, equation) - func ( get_node_vars (u, dg, i, j, k), equation )
788
788
l2_error += diff.^ 2 * (weights[i] * weights[j] * weights[k] * jacobian_volume)
789
789
linf_error = @. max (linf_error, abs (diff))
790
790
end
@@ -968,7 +968,7 @@ function analyze_solution(dg::Dg3D, mesh::TreeMesh, time::Real, dt::Real, step::
968
968
end
969
969
970
970
# Calculate L2/Linf errors, which are also returned by analyze_solution
971
- l2_error, linf_error = calc_error_norms (dg, time)
971
+ l2_error, linf_error = calc_error_norms (dg, time)
972
972
973
973
# L2 error
974
974
if :l2_error in dg. analysis_quantities
@@ -1022,6 +1022,37 @@ function analyze_solution(dg::Dg3D, mesh::TreeMesh, time::Real, dt::Real, step::
1022
1022
println ()
1023
1023
end
1024
1024
1025
+ # L2/L∞ errors of the primitive variables
1026
+ if :l2_error_primitive in dg. analysis_quantities || :linf_error_primitive in dg. analysis_quantities
1027
+ l2_error_prim, linf_error_prim = calc_error_norms (cons2prim, dg, time)
1028
+
1029
+ print (" Variable: " )
1030
+ for v in 1 : nvariables (equation)
1031
+ @printf (" %-14s" , varnames_prim (equation)[v])
1032
+ end
1033
+ println ()
1034
+
1035
+ # L2 error
1036
+ if :l2_error_primitive in dg. analysis_quantities
1037
+ print (" L2 error prim.: " )
1038
+ for v in 1 : nvariables (equation)
1039
+ @printf (" %10.8e " , l2_error_prim[v])
1040
+ dg. save_analysis && @printf (f, " % 10.8e" , l2_error_prim[v])
1041
+ end
1042
+ println ()
1043
+ end
1044
+
1045
+ # L∞ error
1046
+ if :linf_error_primitive in dg. analysis_quantities
1047
+ print (" Linf error pri.:" )
1048
+ for v in 1 : nvariables (equation)
1049
+ @printf (" %10.8e " , linf_error_prim[v])
1050
+ dg. save_analysis && @printf (f, " % 10.8e" , linf_error_prim[v])
1051
+ end
1052
+ println ()
1053
+ end
1054
+ end
1055
+
1025
1056
# Entropy time derivative
1026
1057
if :dsdu_ut in dg. analysis_quantities
1027
1058
duds_ut = calc_entropy_timederivative (dg, time)
@@ -1181,6 +1212,16 @@ function save_analysis_header(filename, quantities, equation::AbstractEquation{3
1181
1212
@printf (f, " %-14s" , " res_" * v)
1182
1213
end
1183
1214
end
1215
+ if :l2_error_primitive in quantities
1216
+ for v in varnames_prim (equation)
1217
+ @printf (f, " %-14s" , " l2_" * v)
1218
+ end
1219
+ end
1220
+ if :linf_error_primitive in quantities
1221
+ for v in varnames_prim (equation)
1222
+ @printf (f, " %-14s" , " linf_" * v)
1223
+ end
1224
+ end
1184
1225
if :dsdu_ut in quantities
1185
1226
@printf (f, " %-14s" , " dsdu_ut" )
1186
1227
end
0 commit comments