Skip to content

Commit

Permalink
optimize error calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmontoya committed Oct 21, 2023
1 parent 1822de9 commit 3197d8d
Show file tree
Hide file tree
Showing 6 changed files with 1,311 additions and 1,315 deletions.
278 changes: 136 additions & 142 deletions examples/euler_1d_gauss_collocation.ipynb

Large diffs are not rendered by default.

2,320 changes: 1,159 additions & 1,161 deletions examples/euler_vortex_2d.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Analysis/Analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Analysis
using ..File
using ..Visualize

export AbstractAnalysis, AbstractAnalysisResults, analyze, save_analysis, tabulate_analysis, tabulate_analysis_for_paper
export AbstractAnalysis, AbstractAnalysisResults, analyze, analyze_new, save_analysis, tabulate_analysis, tabulate_analysis_for_paper

abstract type AbstractAnalysis end
abstract type AbstractAnalysisResults end
Expand Down
3 changes: 1 addition & 2 deletions src/Analysis/conservation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ function evaluate_conservation_residual(
end

@inline @views function evaluate_conservation_residual(
analysis::EntropyConservationAnalysis,
u::Array{Float64,3},
analysis::EntropyConservationAnalysis, u::Array{Float64,3},
dudt::Array{Float64,3})
(; mass_solver, conservation_law, N_c, N_e, V, WJ) = analysis

Expand Down
21 changes: 13 additions & 8 deletions src/Analysis/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ function analyze(analysis::ErrorAnalysis{d}, sol::Array{Float64,3},

(; N_c, N_e, WJ_err, V_err, x_err, total_volume, results_path) = analysis

u_exact = evaluate(exact_solution, x_err, t)
nodal_error = Tuple(u_exact[:,e,:] - Matrix(V_err * sol[:,e,:])
for e in 1:N_c)

squared_error = [sum(dot(nodal_error[e][:,k], WJ_err[k]*nodal_error[e][:,
k]) for k in 1:N_e) for e in 1:N_c]
u_approx = Matrix{Float64}(undef, size(V_err,1), N_c)
error = zeros(N_c)
@inbounds @views for k in 1:N_e
u_exact = evaluate(exact_solution,
Tuple(x_err[m][:,k] for m in 1:d), t)
mul!(u_approx, V_err, sol[:,:,k])
for e in 1:N_c
error_nodal = u_exact[:,e,k] .- u_approx[:,e]
error[e] += dot(error_nodal, WJ_err[k]*error_nodal)
end
end

if normalize
error = sqrt.(squared_error ./ total_volume)
error = sqrt.(error ./ total_volume)
else
error = sqrt.(squared_error)
error = sqrt.(error)
end

if write_to_file
Expand Down
2 changes: 1 addition & 1 deletion src/ConservationLaws/euler_navierstokes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ end
u::AbstractVector{Float64}) where {d}
(; γ, γ_minus_1, inv_γ_minus_1) = conservation_law
p = γ_minus_1 * (u[end] - (0.5/u[1]) * (sum(u[m+1]^2 for m in 1:d)))
return -u[1]*log(p/u[1]^γ)*inv_γ_minus_1
return -u[1]*log(p/(u[1]^γ))*inv_γ_minus_1
end

@inline function conservative_to_entropy!(
Expand Down

0 comments on commit 3197d8d

Please sign in to comment.