Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointwise boundary surface values #1920

Open
wants to merge 71 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9284b11
Add analysis_surface_2d.jl
Arpit-Babbar Apr 26, 2024
0f6ad41
Format
Arpit-Babbar Apr 26, 2024
2e79e4e
Apply suggestions from code review
DanielDoehring Apr 30, 2024
500518a
Pointwise analysis
DanielDoehring Apr 30, 2024
eb93c31
Merge branch 'main' into surface_pressure_friction
DanielDoehring Apr 30, 2024
9c1cc7a
cosmetics
DanielDoehring May 3, 2024
9e4ad12
routines similar to timeseries
DanielDoehring May 3, 2024
0fef7b4
write pointwise data to jhdf5
DanielDoehring May 5, 2024
dd426b9
fmt
DanielDoehring May 5, 2024
b29b2a9
Merge branch 'main' into surface_pressure_friction
DanielDoehring May 5, 2024
f010eab
not needed
DanielDoehring May 5, 2024
c10c3c6
rm unnecessary
DanielDoehring May 5, 2024
a281eee
re-organize
DanielDoehring May 5, 2024
178af8c
remove todo
DanielDoehring May 5, 2024
e0e7320
Merge branch 'main' into surface_pressure_friction
DanielDoehring May 6, 2024
a0abcda
Apply suggestions from code review
DanielDoehring May 7, 2024
1310ade
Sort
DanielDoehring May 8, 2024
de99163
remove prnt
DanielDoehring May 8, 2024
3ba6031
Merge branch 'surface_pressure_friction' of https://github.com/Arpit-…
DanielDoehring May 8, 2024
bda1a2b
name/symbol
DanielDoehring May 8, 2024
e939485
Merge branch 'main' into surface_pressure_friction
DanielDoehring May 8, 2024
6f8eb63
Add analysis_surface_2d.jl
Arpit-Babbar Apr 26, 2024
9c51d7f
Format
Arpit-Babbar Apr 26, 2024
022dc28
Apply suggestions from code review
DanielDoehring Apr 30, 2024
8419088
Pointwise analysis
DanielDoehring Apr 30, 2024
10cfb00
cosmetics
DanielDoehring May 3, 2024
57d2b38
routines similar to timeseries
DanielDoehring May 3, 2024
b995e3f
write pointwise data to jhdf5
DanielDoehring May 5, 2024
cb826db
fmt
DanielDoehring May 5, 2024
f39d7f3
not needed
DanielDoehring May 5, 2024
cf2fb11
rm unnecessary
DanielDoehring May 5, 2024
2bc6001
re-organize
DanielDoehring May 5, 2024
f8b2473
remove todo
DanielDoehring May 5, 2024
cd18b83
Sort
DanielDoehring May 8, 2024
bdb82f1
remove prnt
DanielDoehring May 8, 2024
5f5f464
Apply suggestions from code review
DanielDoehring May 7, 2024
db33b64
name/symbol
DanielDoehring May 8, 2024
b9021a4
Update src/callbacks_step/analysis_surface_2d.jl
DanielDoehring May 9, 2024
bac4e4d
Add test
Arpit-Babbar May 13, 2024
29d2663
Bug fix
Arpit-Babbar May 13, 2024
a7b9ec1
Accidental add fix
Arpit-Babbar May 13, 2024
efe8ddf
Apply suggestions from code review
DanielDoehring May 14, 2024
6c7657e
Merge branch 'main' into surface_pressure_friction
DanielDoehring May 14, 2024
4180757
Update examples/p4est_2d_dgsem/elixir_navierstokes_NACA0012airfoil_ma…
DanielDoehring May 21, 2024
ed3abf0
Merge branch 'main' into surface_pressure_friction
DanielDoehring May 23, 2024
9fd0b58
Merge branch 'surface_pressure_friction' of https://github.com/Arpit-…
DanielDoehring May 24, 2024
9785a83
remove sorting
DanielDoehring May 24, 2024
e25e462
Update examples/p4est_2d_dgsem/elixir_navierstokes_NACA0012airfoil_ma…
DanielDoehring May 24, 2024
f0e7047
Update src/callbacks_step/analysis.jl
DanielDoehring May 24, 2024
012680c
pointwise
DanielDoehring May 24, 2024
880674e
rename
DanielDoehring May 24, 2024
1b52899
viscous spelled out
DanielDoehring May 24, 2024
c37b203
fmt
DanielDoehring May 24, 2024
e6ad84b
Merge branch 'main' into surface_pressure_friction
DanielDoehring May 24, 2024
a7b5f8f
distinguish func and var
DanielDoehring May 24, 2024
842eaeb
fix coords
DanielDoehring May 24, 2024
0374850
fmt
DanielDoehring May 24, 2024
ce61866
Merge branch 'main' into surface_pressure_friction
DanielDoehring Jul 5, 2024
f04c1ee
update
DanielDoehring Jul 5, 2024
42afa38
correct docstring
DanielDoehring Jul 5, 2024
b9d2fcb
sort arrays
DanielDoehring Jul 5, 2024
a289eb1
mno in place
DanielDoehring Jul 5, 2024
634f60c
Use counter instead of index to avoid confusion
DanielDoehring Sep 5, 2024
d3a57ed
Comments
DanielDoehring Sep 5, 2024
5fa43da
Merge branch 'main' into surface_pressure_friction
DanielDoehring Sep 5, 2024
84f1352
Update docstring
DanielDoehring Sep 5, 2024
3c952f7
More comments
DanielDoehring Sep 5, 2024
ed971ac
fmt
DanielDoehring Sep 5, 2024
2f79a03
update test vals
DanielDoehring Sep 5, 2024
9d7231d
do not pollute `analysis.dat`
DanielDoehring Sep 5, 2024
4745ec8
Merge branch 'main' into surface_pressure_friction
DanielDoehring Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Trixi
# Structured and Unstructured Grid Methods (2016)
# [https://ntrs.nasa.gov/citations/20160003623] (https://ntrs.nasa.gov/citations/20160003623)
# - Deep Ray, Praveen Chandrashekar (2017)
# An entropy stable finite volume scheme for the
# An entropy stable finite volume scheme for the
# two dimensional Navier–Stokes equations on triangular grids
# [DOI:10.1016/j.amc.2017.07.020](https://doi.org/10.1016/j.amc.2017.07.020)

Expand Down Expand Up @@ -142,14 +142,26 @@ lift_coefficient_shear_force = AnalysisSurfaceIntegral(semi, force_boundary_name
u_inf(equations),
l_inf()))

friction_coefficient = AnalysisSurface(semi, force_boundary_names,
SurfaceFrictionCoefficient(rho_inf(),
u_inf(equations),
l_inf()))

pressure_coefficient = AnalysisSurface(semi, force_boundary_names,
SurfacePressureCoefficient(p_inf(), rho_inf(),
u_inf(equations),
l_inf()))

analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
output_directory = "out",
save_analysis = true,
analysis_errors = Symbol[],
analysis_integrals = (drag_coefficient,
lift_coefficient,
drag_coefficient_shear_force,
lift_coefficient_shear_force))
lift_coefficient_shear_force),
analysis_pointwise = (friction_coefficient,
pressure_coefficient))

alive_callback = AliveCallback(analysis_interval = analysis_interval)

Expand Down
6 changes: 4 additions & 2 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ export SummaryCallback, SteadyStateCallback, AnalysisCallback, AliveCallback,
AMRCallback, StepsizeCallback,
GlmSpeedCallback, LBMCollisionCallback, EulerAcousticsCouplingCallback,
TrivialCallback, AnalysisCallbackCoupled,
AnalysisSurfaceIntegral, DragCoefficientPressure, LiftCoefficientPressure,
DragCoefficientShearStress, LiftCoefficientShearStress
AnalysisSurface, AnalysisSurfaceIntegral,
DragCoefficientPressure, LiftCoefficientPressure,
DragCoefficientShearStress, LiftCoefficientShearStress,
SurfacePressureCoefficient, SurfaceFrictionCoefficient

export load_mesh, load_time, load_timestep, load_timestep!, load_dt,
load_adaptive_time_integrator!
Expand Down
72 changes: 62 additions & 10 deletions src/callbacks_step/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ or `extra_analysis_errors = (:conservation_error,)`.
If you want to omit the computation (to safe compute-time) of the [`default_analysis_errors`](@ref), specify
`analysis_errors = Symbol[]`.
Note: `default_analysis_errors` are `:l2_error` and `:linf_error` for all equations.
If you want to compute `extra_analysis_errors` such as `:conservation_error` solely, i.e.,
without `:l2_error, :linf_error` you need to specify
If you want to compute `extra_analysis_errors` such as `:conservation_error` solely, i.e.,
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
without `:l2_error, :linf_error` you need to specify
`analysis_errors = [:conservation_error]` instead of `extra_analysis_errors = [:conservation_error]`.

Further scalar functions `func` in `extra_analysis_integrals` are applied to the numerical
Expand All @@ -43,7 +43,8 @@ evaluating the computational performance, such as the total runtime, the perform
(time/DOF/rhs!), the time spent in garbage collection (GC), or the current memory usage (alloc'd
memory).
"""
mutable struct AnalysisCallback{Analyzer, AnalysisIntegrals, InitialStateIntegrals,
mutable struct AnalysisCallback{Analyzer, AnalysisIntegrals, AnalysisPointwise,
InitialStateIntegrals,
Cache}
start_time::Float64
start_time_last_analysis::Float64
Expand All @@ -56,6 +57,7 @@ mutable struct AnalysisCallback{Analyzer, AnalysisIntegrals, InitialStateIntegra
analyzer::Analyzer
analysis_errors::Vector{Symbol}
analysis_integrals::AnalysisIntegrals
analysis_pointwise::AnalysisPointwise
initial_state_integrals::InitialStateIntegrals
cache::Cache
end
Expand All @@ -80,6 +82,9 @@ function Base.show(io::IO, ::MIME"text/plain",
for (idx, integral) in enumerate(analysis_callback.analysis_integrals)
push!(setup, "│ integral " * string(idx) => integral)
end
for (idx, quantity) in enumerate(analysis_callback.analysis_pointwise)
push!(setup, "│ quantity " * string(idx) => quantity)
DanielDoehring marked this conversation as resolved.
Show resolved Hide resolved
end
push!(setup,
"save analysis to file" => analysis_callback.save_analysis ? "yes" : "no")
if analysis_callback.save_analysis
Expand Down Expand Up @@ -109,6 +114,7 @@ function AnalysisCallback(mesh, equations::AbstractEquations, solver, cache;
extra_analysis_integrals = (),
analysis_integrals = union(default_analysis_integrals(equations),
extra_analysis_integrals),
analysis_pointwise = (),
RealT = real(solver),
uEltype = eltype(cache.elements),
kwargs...)
Expand All @@ -132,6 +138,7 @@ function AnalysisCallback(mesh, equations::AbstractEquations, solver, cache;
analysis_filename,
analyzer,
analysis_errors, Tuple(analysis_integrals),
Tuple(analysis_pointwise),
SVector(ntuple(_ -> zero(uEltype),
Val(nvariables(equations)))),
cache_analysis)
Expand All @@ -158,7 +165,7 @@ function initialize!(cb::DiscreteCallback{Condition, Affect!}, u_ode, du_ode, t,

analysis_callback = cb.affect!
analysis_callback.initial_state_integrals = initial_state_integrals
@unpack save_analysis, output_directory, analysis_filename, analysis_errors, analysis_integrals = analysis_callback
@unpack save_analysis, output_directory, analysis_filename, analysis_errors, analysis_integrals, analysis_pointwise = analysis_callback

if save_analysis && mpi_isroot()
mkpath(output_directory)
Expand Down Expand Up @@ -203,6 +210,10 @@ function initialize!(cb::DiscreteCallback{Condition, Affect!}, u_ode, du_ode, t,
@printf(io, " %-14s", pretty_form_ascii(quantity))
end

for quantity in analysis_pointwise
@printf(io, " %-14s", pretty_form_ascii(quantity))
end

println(io)
end
end
Expand Down Expand Up @@ -339,8 +350,8 @@ function (analysis_callback::AnalysisCallback)(u_ode, du_ode, integrator, semi)
@notimeit timer() integrator.f(du_ode, u_ode, semi, t)
u = wrap_array(u_ode, mesh, equations, solver, cache)
du = wrap_array(du_ode, mesh, equations, solver, cache)
# Compute l2_error, linf_error
analysis_callback(io, du, u, u_ode, t, semi)
# Compute l2_error, linf_error among other quantities
analysis_callback(io, du, u, u_ode, t, semi, iter)

mpi_println("─"^100)
mpi_println()
Expand All @@ -367,8 +378,8 @@ end

# This method is just called internally from `(analysis_callback::AnalysisCallback)(integrator)`
# and serves as a function barrier. Additionally, it makes the code easier to profile and optimize.
function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi)
@unpack analyzer, analysis_errors, analysis_integrals = analysis_callback
function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi, iter)
@unpack analyzer, analysis_errors, analysis_integrals, analysis_pointwise = analysis_callback
cache_analysis = analysis_callback.cache
_, equations, _, _ = mesh_equations_solver_cache(semi)

Expand Down Expand Up @@ -486,6 +497,8 @@ function (analysis_callback::AnalysisCallback)(io, du, u, u_ode, t, semi)

# additional integrals
analyze_integrals(analysis_integrals, io, du, u, t, semi)
# additional pointwise quantities
analyze_pointwise(analysis_pointwise, du, u, t, semi, iter)

return nothing
end
Expand Down Expand Up @@ -606,6 +619,26 @@ function analyze_integrals(analysis_integrals::Tuple{}, io, du, u, t, semi)
nothing
end

# Iterate over tuples of pointwise analysis quantities in a type-stable way using "lispy tuple programming".
function analyze_pointwise(analysis_quantities::NTuple{N, Any}, du, u, t,
semi, iter) where {N}

# Extract the first pointwise analysis quantity and process it; keep the remaining to be processed later
quantity = first(analysis_quantities)
remaining_quantities = Base.tail(analysis_quantities)

analyze(quantity, du, u, t, semi, iter)

# Recursively call this method with the unprocessed pointwise analysis quantities
analyze_pointwise(remaining_quantities, du, u, t, semi, iter)
return nothing
end

# terminate the type-stable iteration over tuples
function analyze_pointwise(analysis_quantities::Tuple{}, du, u, t, semi, iter)
nothing
end

# used for error checks and EOC analysis
function (cb::DiscreteCallback{Condition, Affect!})(sol) where {Condition,
Affect! <:
Expand All @@ -627,6 +660,10 @@ function analyze(quantity, du, u, t, semi::AbstractSemidiscretization)
mesh, equations, solver, cache = mesh_equations_solver_cache(semi)
analyze(quantity, du, u, t, mesh, equations, solver, cache)
end
function analyze(quantity, du, u, t, semi::AbstractSemidiscretization, iter)
mesh, equations, solver, cache = mesh_equations_solver_cache(semi)
analyze(quantity, du, u, t, mesh, equations, solver, cache, iter)
end
function analyze(quantity, du, u, t, mesh, equations, solver, cache)
integrate(quantity, u, mesh, equations, solver, cache, normalize = true)
end
Expand Down Expand Up @@ -690,15 +727,17 @@ end # @muladd
include("analysis_dg1d.jl")
include("analysis_dg2d.jl")
include("analysis_surface_integral_2d.jl")
include("analysis_surface_2d.jl")
include("analysis_dg2d_parallel.jl")
include("analysis_dg3d.jl")
include("analysis_dg3d_parallel.jl")

# Special analyze for `SemidiscretizationHyperbolicParabolic` such that
# precomputed gradients are available. Required for `enstrophy` (see above) and viscous forces.
# Note that this needs to be included after `analysis_surface_integral_2d.jl` to
# Note that this needs to be included after `analysis_surface_integral_2d.jl` to
# have `VariableViscous` available.
function analyze(quantity::AnalysisSurfaceIntegral{Variable},
function analyze(quantity::Union{AnalysisSurfaceIntegral{Variable},
AnalysisSurface{Variable}},
du, u, t,
semi::SemidiscretizationHyperbolicParabolic) where {
Variable <:
Expand All @@ -709,3 +748,16 @@ function analyze(quantity::AnalysisSurfaceIntegral{Variable},
analyze(quantity, du, u, t, mesh, equations, equations_parabolic, solver, cache,
cache_parabolic)
end
function analyze(quantity::Union{AnalysisSurfaceIntegral{Variable},
AnalysisSurface{Variable}},
du, u, t,
semi::SemidiscretizationHyperbolicParabolic,
iter) where {
Variable <:
VariableViscous}
mesh, equations, solver, cache = mesh_equations_solver_cache(semi)
equations_parabolic = semi.equations_parabolic
cache_parabolic = semi.cache_parabolic
analyze(quantity, du, u, t, mesh, equations, equations_parabolic, solver, cache,
cache_parabolic, iter)
end
Loading
Loading