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

Conversation

Arpit-Babbar
Copy link
Member

@Arpit-Babbar Arpit-Babbar commented Apr 26, 2024

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

  • Add tests for pointwise surface values (How to do it?)
  • The many TODOs within the code

Copy link
Contributor

Review checklist

This 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

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

@Arpit-Babbar Arpit-Babbar changed the title Add analysis_surface_2d.jl WIP: Compute pointwise values on boundary surface Apr 26, 2024
@Arpit-Babbar Arpit-Babbar changed the title WIP: Compute pointwise values on boundary surface WIP: Pointwise boundary surface values Apr 26, 2024
@Arpit-Babbar
Copy link
Member Author

Arpit-Babbar commented Apr 26, 2024

I currently have two issues

  1. The output of pointwise values is saved into a .txt file. Does that need to be changed?

  2. The pointwise surface values are currently being computed as analysis_integral quantities in the AnalysisCallback. Where else can they belong? I think that it should be given its own place within the AnalysisCallback, one that does not print any values to the screen (because there are no values to be printed).

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

Attention: Patch coverage is 91.41104% with 14 lines in your changes missing coverage. Please review.

Project coverage is 93.88%. Comparing base (480aea9) to head (4745ec8).

Files with missing lines Patch % Lines
...rc/callbacks_step/analysis_surface_pointwise_2d.jl 92.24% 9 Missing ⚠️
src/callbacks_step/analysis.jl 82.14% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1920      +/-   ##
==========================================
- Coverage   96.34%   93.88%   -2.46%     
==========================================
  Files         470      471       +1     
  Lines       37497    37626     +129     
==========================================
- Hits        36125    35323     -802     
- Misses       1372     2303     +931     
Flag Coverage Δ
unittests 93.88% <91.41%> (-2.46%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@andrewwinters5000 andrewwinters5000 left a 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.

  1. A .txt file is fine as ACSII data can be post-processed by nearly any program. However, if we are willing to use DelimitedFiles would something like .csv be better? Just thinking out loud.
  2. 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 like analysis_pointwise that could still reuse the caches and such from the AnalysisCallback struct.

src/callbacks_step/analysis_surface_2d.jl Outdated Show resolved Hide resolved
@DanielDoehring DanielDoehring self-assigned this Apr 27, 2024
@DanielDoehring
Copy link
Contributor

DanielDoehring commented Apr 28, 2024

I suggest we adapt/copy this code

# Iterate over tuples of analysis integrals in a type-stable way using "lispy tuple programming".
function analyze_integrals(analysis_integrals::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_integrals)
remaining_quantities = Base.tail(analysis_integrals)
res = analyze(quantity, du, u, t, semi)
if mpi_isroot()
@printf(" %-12s:", pretty_form_utf(quantity))
@printf(" % 10.8e", res)
@printf(io, " % 10.8e", res)
end
mpi_println()
# Recursively call this method with the unprocessed integrals
analyze_integrals(remaining_quantities, io, du, u, t, semi)
return nothing
end
# terminate the type-stable iteration over tuples
function analyze_integrals(analysis_integrals::Tuple{}, io, du, u, t, semi)
nothing
end

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:

# additional integrals
analyze_integrals(analysis_integrals, io, du, u, t, semi)

@DanielDoehring
Copy link
Contributor

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.

@sloede
Copy link
Member

sloede commented Apr 29, 2024

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 TimeSeriesCallback, which allows to record data at each time step at a given set of "recording points". We use an internal caching infrastructure and write all data to HDF5 files. There's also the output of the AnalysisCallback, which writes integral quantities to an ASCII file using CSV formatting.

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.

@DanielDoehring
Copy link
Contributor

We should put this on hold until #1959 is tackled / we decide how we address #1955

@DanielDoehring DanielDoehring marked this pull request as draft May 28, 2024 08:29
@DanielDoehring
Copy link
Contributor

@Arpit-Babbar : I did some changes to be AMR-ready, see #1959 . Now the test fail, however. Can you take a look if we still match the reference data or if I messed something up?

@Arpit-Babbar
Copy link
Member Author

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:

c_p c_f

I regenerated the data and saw that both the plots look exactly the same as this. Did we remove the reordering (following Michael's suggestion?)? That will need the CI to be updated.

@DanielDoehring
Copy link
Contributor

I regenerated the data and saw that both the plots look exactly the same as this. Did we remove the reordering (following Michael's suggestion?)? That will need the CI to be updated.

That is good!

Yes, the sorting is not longer done.
Take a look at the test files/CI test, I now sort there, but the values do not agree. This is why I asked you to check this again :)

@Arpit-Babbar
Copy link
Member Author

Arpit-Babbar commented Jul 8, 2024

Yes, the sorting is not longer done. Take a look at the test files/CI test, I now sort there, but the values do not agree. This is why I asked you to check this again :)

I see it now. The sorting

    @test sort(cp_vals[1:10])  [1.5152278762705806
           1.5182860925755697
           1.7417814818119175
           1.871513931283643
           1.874247697759559
           2.0354491762572806
           2.0400855926847936
           2.0956920203526193
           2.098639791879171
           2.1591959225932777]

does not look equivalent to sorting along the increasing x direction. For that, you will have to sort along read(Trixi.h5open("out/CP_x_000007.h5"))["point_coordinates"][:,1]

@DanielDoehring
Copy link
Contributor

DanielDoehring commented Jul 8, 2024

I see it now. The sorting
does not look equivalent to sorting along the increasing x direction.

Yes, but this is also not intended. As you can see, the reference data is also sorting in ascending order, so I seek to do the same with the data, as I am not sure whether the order of the indices is deterministic.

We match some values, while some we miss, see : https://github.com/trixi-framework/Trixi.jl/actions/runs/9810227214/job/27089931612?pr=1920#step:7:8617

@DanielDoehring DanielDoehring marked this pull request as ready for review September 5, 2024 12:59
@DanielDoehring DanielDoehring marked this pull request as draft September 5, 2024 14:00
@DanielDoehring DanielDoehring marked this pull request as ready for review September 5, 2024 19:12
@DanielDoehring
Copy link
Contributor

I guess we could also move this into a package called TrixiAero or something similar that implements this specialized analysis routines, thereby not polluting the analyze file even more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants