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
base: main
Are you sure you want to change the base?
Pointwise boundary surface values #1920
Conversation
Review checklistThis checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging. Purpose and scope
Code quality
Documentation
Testing
Performance
Verification
Created with ❤️ by the Trixi.jl community. |
I currently have two issues
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1920 +/- ##
==========================================
- Coverage 96.11% 86.39% -9.72%
==========================================
Files 460 461 +1
Lines 36926 37054 +128
==========================================
- Hits 35490 32011 -3479
- Misses 1436 5043 +3607
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not do a full review, just left a question about the need to add another package dependency. As far as your other concerns here are my preliminary thoughts.
- A
.txt
file is fine as ACSII data can be post-processed by nearly any program. However, if we are willing to useDelimitedFiles
would something like.csv
be better? Just thinking out loud. - Since no integral is computed, then, as far as I understand it, the
analysis_integral
is basically being overloaded for easier dispatch purposes. Then the pointwise values are computed on the fly with similar drag and lift functions and the write-to-file occurs within the loop over all nodes instead of afterwards. My initial reaction is that this could be confusing. It would be better to be more explicit and create a new generic function called something likeanalysis_pointwise
that could still reuse the caches and such from theAnalysisCallback
struct.
examples/p4est_2d_dgsem/elixir_navierstokes_NACA0012airfoil_mach08.jl
Outdated
Show resolved
Hide resolved
I suggest we adapt/copy this code Trixi.jl/src/callbacks_step/analysis.jl Lines 583 to 607 in 6554973
to non-integrated quantities, i.e., some which are not returning a scalar value possibly like this: # Iterate over tuples of analysis integrals in a type-stable way using "lispy tuple programming".
function analyze_pointwise(analysis_quantities::NTuple{N, Any}, io, du, u, t,
semi) where {N}
# Extract the first analysis integral 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)
# Recursively call this method with the unprocessed integrals
analyze_integrals(remaining_quantities, io, du, u, t, semi)
return nothing
end and then call this here: Trixi.jl/src/callbacks_step/analysis.jl Lines 487 to 488 in 6554973
|
Regarding the type of file, I think we should aim for something that is easily post-processed, as now one does not get a single value but instead many, which are most likely also accompanied by spatial positions. |
I recommend to take a look at how I/O is implemented in the Overall, the decision on which file format to use IMHO depends heavily on data set size: If either the number of recording points or the number of recordings is at most 10-20, an ASCII file might still work. However, if you want to record at, say, 100 points, and do so for 1000 times over the course of a simulation, I'd probably opt for an HDF5 file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me! As I was involved in the coding, it would be nice to get an additional review, preferably by someone who coded up some h5 export as well, such as @sloede and/or @andrewwinters5000
These are the plots from Arpits gist:
examples/p4est_2d_dgsem/elixir_navierstokes_NACA0012airfoil_mach08.jl
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this is a nice feature addition to Trixi.jl, thanks a lot for your effort!
Generally, I am not 100% sure if the current implementation is really the optimal way to go: Naively, I assume much more code could probably be shared with the AnalysisSurfaceIntegral
implementation. Also, I am wondering if it really makes sense to write out these rather heavy files from the AnalysisCallback
or whether they would make more sense in the TimeSeriesCallback
.
I've left a few more comments (some rather general ones, some more specific ones). I do not want to slow down your development pace, but on the other hand I'd like to avoid that we have a multitude of (or too many) different analysis-like tools (integral quantities over the entire domain, integral quantities over surfaces, pointwise time series over the whole domain, pointwise time series over surfaces) with vastly differing implementations, making it harder to maintain in the intermediate and long term.
examples/p4est_2d_dgsem/elixir_navierstokes_NACA0012airfoil_mach08.jl
Outdated
Show resolved
Hide resolved
@@ -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., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't attach this to the proper line, but the docstring should include the pointwise analysis in its list of arguments and ideally also (briefly) explain how it can be properly used.
@@ -48,31 +48,31 @@ struct AnalysisSurfaceIntegral{Variable} | |||
end | |||
end | |||
|
|||
struct ForceState{RealT <: Real} | |||
struct FlowStateDirectional{RealT <: Real} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the name change, or at least why the "Directional" suffix? Are their other states that might be considered? Maybe "FreestreamFlowState" would be more appropriate?
Also, what does psi
stand for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the name change, I felt FlowState
would be more descriptive.
Directional
is since this flow state carries the vector of the free-stream velocity uinf
.
The non-directional version of this has only the remaining three quantities.
values, t, iter) | ||
end | ||
|
||
varname(::Any) = @assert false "Surface variable name not assigned" # This makes sure default behaviour is not overwriting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
varname(::Any) = @assert false "Surface variable name not assigned" # This makes sure default behaviour is not overwriting |
Why define a default at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default is defined to give a helpful error message in case a user forgets to define varname
for their new surface quantity. The comment answers the question “Why not set the default name to something trivial like 'variable'?". I am open to doing it differently or removing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to particular lines of code, but more a general remark:
Does it really make sense to have a completely separate implementation for pointwise surface data and surface integrals? Wouldn't they naturally share a lot of the implementation, maybe except the integration part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is certainly true. We could try to refactor the current implementation by calling different functions after
index_range = eachnode(dg)
for boundary in indices
element = boundaries.neighbor_ids[boundary]
node_indices = boundaries.node_indices[boundary]
direction = indices2direction(node_indices)
i_node_start, i_node_step = index_to_start_step_2d(node_indices[1], index_range)
j_node_start, j_node_step = index_to_start_step_2d(node_indices[2], index_range)
i_node = i_node_start
j_node = j_node_start
for node_index in index_range
u_node = Trixi.get_node_vars(cache.boundaries.u, equations, dg, node_index,
boundary)
since this part is shared among all 4 versions (integrals/points, viscous/inviscid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be able to call this from one function we would need to add variables to the AnalysisSurfaceIntegral/Pointwise
structs.
For Integral, this would be surface_integral = zero(eltype(u))
and for the pointwise stuff
coordinates = Matrix{real(dg)}(undef, n_elements * n_nodes, dim) # physical coordinates of indices
values = Vector{real(dg)}(undef, n_elements * n_nodes) # variable values at indices
Then we still have to figure out how to treat the passing in of the iteration number.
Having said this, while we certainly have code-duplication in the boilerplate part, we currently have analyze
methods with 4 different function signatures.
return SurfaceFrictionCoefficient(FlowState(rhoinf, uinf, linf)) | ||
end | ||
|
||
function (pressure_coefficient::SurfacePressureCoefficient)(u, equations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function (and most others in this file) would benefit from having at least a short, one-line comment on what they are doing or when they are called. For example, below there are two fairly complex analyze
methods that have very similar arguments and it takes a while to figure out their different use cases.
function pretty_form_ascii(::AnalysisSurface{<:SurfacePressureCoefficient{<:Any}}) | ||
"CP(x)" | ||
end | ||
function pretty_form_utf(::AnalysisSurface{<:SurfacePressureCoefficient{<:Any}}) | ||
"CP(x)" | ||
end | ||
|
||
function pretty_form_ascii(::AnalysisSurface{<:SurfaceFrictionCoefficient{<:Any}}) | ||
"CF(x)" | ||
end | ||
function pretty_form_utf(::AnalysisSurface{<:SurfaceFrictionCoefficient{<:Any}}) | ||
"CF(x)" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If "CF_x" are changed above, they should be adapted here as well
…Babbar/Trixi.jl into ArpitBabbar_PointWiseSurfForces
…ch08.jl Co-authored-by: Michael Schlottke-Lakemper <michael@sloede.com>
Co-authored-by: Michael Schlottke-Lakemper <michael@sloede.com>
This PR add pointwise values on the surface like the coefficient of pressure and friction.
The computation has been verified using the reference data from Roy Charles Swanson, Stefan Langer, Structured and Unstructured Grid Methods (2016)
The verification requires plotting along with reference data, for which the script is available at https://gist.github.com/Arpit-Babbar/924823c08f4be962856a99c107b18fb5
TODO