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

Add numerical support of other real types (Float32) #1909

Merged
merged 34 commits into from
Jun 3, 2024
Merged

Add numerical support of other real types (Float32) #1909

merged 34 commits into from
Jun 3, 2024

Conversation

huiyuxie
Copy link
Member

@huiyuxie huiyuxie commented Apr 19, 2024

Address parts of #591 and redo #1604.

Tasks:

  • acoustic_perturbation_2d
  • compressible_euler_1d, compressible_euler_2d, compressible_euler_3d
  • unit tests for above

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.

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution. Please find below some comments/suggestions.

src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
@huiyuxie
Copy link
Member Author

huiyuxie commented Apr 23, 2024

General question here: Is it better to conduct unit testing while making changes, or to perform the tests after completing all the changes? Are there any good examples of testing from this repository? Thanks!

@ranocha
Copy link
Member

ranocha commented Apr 23, 2024

General question here: Is it better to conduct unit testing while making changes, or to perform the tests after completing all the changes? Are there any good examples of testing from this repository? Thanks!

When you're working on numerical fluxes, you can add some unit tests, e.g., to parts like

Trixi.jl/test/test_unit.jl

Lines 633 to 660 in 1745df4

@timed_testset "Consistency check for HLL flux (naive): CEE" begin
flux_hll = FluxHLL(min_max_speed_naive)
# Set up equations and dummy conservative variables state
equations = CompressibleEulerEquations1D(1.4)
u = SVector(1.1, 2.34, 5.5)
orientations = [1]
for orientation in orientations
@test flux_hll(u, u, orientation, equations) flux(u, orientation, equations)
end
equations = CompressibleEulerEquations2D(1.4)
u = SVector(1.1, -0.5, 2.34, 5.5)
orientations = [1, 2]
for orientation in orientations
@test flux_hll(u, u, orientation, equations) flux(u, orientation, equations)
end
equations = CompressibleEulerEquations3D(1.4)
u = SVector(1.1, -0.5, 2.34, 2.4, 5.5)
orientations = [1, 2, 3]
for orientation in orientations
@test flux_hll(u, u, orientation, equations) flux(u, orientation, equations)
end
end

for the compressible Euler equations. Here, you could add additional tests using inputs with eltype(u) == Float32.

We should also add some full integration tests once something works completely - maybe by adding one or two new example elixirs showing how to run simulations with Float32.

@DanielDoehring DanielDoehring added the enhancement New feature or request label Apr 24, 2024
Copy link

codecov bot commented Apr 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.12%. Comparing base (3b52a30) to head (60836bb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1909      +/-   ##
==========================================
+ Coverage   96.11%   96.12%   +0.01%     
==========================================
  Files         460      460              
  Lines       36926    36952      +26     
==========================================
+ Hits        35490    35520      +30     
+ Misses       1436     1432       -4     
Flag Coverage Δ
unittests 96.12% <100.00%> (+0.01%) ⬆️

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.

@huiyuxie
Copy link
Member Author

Hi @ranocha I have revised the code based on our discussion. Please review it once more, and if this version is satisfactory, I will apply similar revisions to the subsequent tasks.

For dual numbers, I have no idea whether it will be copied to the GPU and I think CUDA.jl does not directly support this type. If they are to be executed on GPUs, I will explore alternative methods (probably through struct) to manage them.

For documentation, are you referring to a general overview that explains the purpose of using a function like oftype, or to detailed documentation that points to each specific instance in the code?

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! I just have some minor suggestions.

For documentation, are you referring to a general overview that explains the purpose of using a function like oftype, or to detailed documentation that points to each specific instance in the code?

I had something in mind like adding a new section to https://trixi-framework.github.io/Trixi.jl/stable/conventions/ where we explain

  • why we use 0.5f0 * instead of 0.5 *
  • why we use patterns such as RealT = eltype(x) and v1_prime = zero(RealT) or A = convert(RealT, 0.2)

There is no need to point to specific code lines from my point of view.

src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
src/equations/acoustic_perturbation_2d.jl Show resolved Hide resolved
src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
@ranocha
Copy link
Member

ranocha commented Apr 29, 2024

@sloede Could you please have a look as well?

@ranocha ranocha requested a review from sloede April 29, 2024 13:40
@huiyuxie huiyuxie self-assigned this Apr 30, 2024
@huiyuxie huiyuxie requested review from ranocha and benegee May 2, 2024 18:40
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Let's please wait for a review by @sloede before you start modifying more files.

src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
src/equations/acoustic_perturbation_2d.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_1d.jl Outdated Show resolved Hide resolved
@huiyuxie
Copy link
Member Author

I left a message in slack - Please check and collaborate as otherwise there will be more and more bugs in the long run.

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! The checkbox "unit tests for above" in the first ost is still open. Do you want to add more unit tests to this PR?

If not, I think it would be nice to go ahead and merge this PR soon so that others can use the infrastructure for adding new unit tests (and using the existing tests) in other PRs

@ranocha
Copy link
Member

ranocha commented May 27, 2024

Could you please run the formatter, e.g., like this?

import Pkg
Pkg.activate(temp = true)
Pkg.add(PackageSpec(name = "JuliaFormatter", version="1.0.45"))
using JuliaFormatter
format(["benchmark", "examples", "ext", "src", "test", "utils"])

(when executed in the main directory of your clone of Trixi.jl)

@huiyuxie huiyuxie requested a review from ranocha May 28, 2024 04:58
@huiyuxie
Copy link
Member Author

Please review again - already formatted and added 3D test

Sorry that I am extremely busy until next Wednesday (including the weekends) please wait and take your time :)

@huiyuxie
Copy link
Member Author

Please help me rerun CI as I have no rights to do so

Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nearly ready to merge from my side, just a few small questions 🙂

src/Trixi.jl Outdated Show resolved Hide resolved
src/Trixi.jl Outdated Show resolved Hide resolved
src/equations/compressible_euler_3d.jl Show resolved Hide resolved
@huiyuxie huiyuxie requested a review from sloede May 30, 2024 00:19
@huiyuxie huiyuxie removed the request for review from benegee June 1, 2024 00:52
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

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.

5 participants