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

Adjusts velocity boundary conditions for accelerated flows #108

Merged
merged 11 commits into from
Feb 17, 2024

Conversation

marinlauber
Copy link
Member

@marinlauber marinlauber commented Jan 29, 2024

I have adjusted the velocity boundary conditions to allow for either a Tuple or a Function(i,t). This is required if we have an accelerated flow without periodic BC in the forced direction. The resulting body force is computed with ForwardDiff on the body velocity function.

Either boundary condition type is dispatched to a BCTuple function that generates a Tuple that is then passed to the BC!() function.

I added an example, examples/TwoD_SlowStartCircle.jl, that demonstrates how to use the time-varying velocity boundary conditions.

I have added some tests (not run on the GPU yet) for the new functions.

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5dea927) 96.44% compared to head (c90de26) 96.55%.
Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
+ Coverage   96.44%   96.55%   +0.11%     
==========================================
  Files          12       12              
  Lines         450      465      +15     
==========================================
+ Hits          434      449      +15     
  Misses         16       16              

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

@b-fg
Copy link
Member

b-fg commented Jan 30, 2024

This requires storing the velocity BC as an Array instead of a Tuple. I am not sure if this needs to be stored on the GPU or not (I will test this).

That's indeed required for the GPU. We cannot have a small CuArray and access it by index as with an Array, so this is why tuples are used instead.

@marinlauber

This comment was marked as outdated.

src/Flow.jl Outdated Show resolved Hide resolved
@b-fg
Copy link
Member

b-fg commented Jan 30, 2024

Have a look here: https://juliaarrays.github.io/StaticArrays.jl/stable/pages/api/#Mutable-arrays:-MVector,-MMatrix-and-MArray

I think MVector structures is what you are looking for.

@weymouth
Copy link
Collaborator

Shouldn't we just use functions instead of arrays? @TzuYaoHuang's g function works fine on GPUs. Why do we need an array or Tuple at all?

@marinlauber
Copy link
Member Author

Shouldn't we just use functions instead of arrays? @TzuYaoHuang's g function works fine on GPUs. Why do we need an array or Tuple at all?

Yes, we can, but this will mean that the boundary condition function will now call these functions every time.

@b-fg
Copy link
Member

b-fg commented Feb 1, 2024

Maybe we can dispatch to the tuple for static conditions and dispatch to the functions for dynamic ones.

src/Flow.jl Show resolved Hide resolved
src/Flow.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
@b-fg
Copy link
Member

b-fg commented Feb 6, 2024

I think this is ready to merge? @weymouth @marinlauber

@marinlauber
Copy link
Member Author

This is ready!

The tests are passing on CPU/GPU

Test Summary: | Pass  Total   Time
util.jl       |   34     34  20.8s
Test Summary: | Pass  Total   Time
Poisson.jl    |   14     14  18.8s
Test Summary:        | Pass  Total  Time
MultiLevelPoisson.jl |   13     13  6.2s
Test Summary: | Pass  Total  Time
Flow.jl       |   18     18  9.4s
Test Summary: | Pass  Total  Time
Body.jl       |    3      3  0.1s
Test Summary: | Pass  Total  Time
AutoBody.jl   |   11     11  5.3s
Test Summary:        | Pass  Total  Time
Flow.jl periodic TGV |    2      2  5.1s
Test Summary:                      | Pass  Total   Time
Flow.jl with increasing body force |    2      2  10.0s
Test Summary: | Pass  Total  Time
Metrics.jl    |   17     17  6.8s
Test Summary: | Pass  Total  Time
WaterLily.jl  |   34     34  6.4s
Test Summary: | Pass  Total   Time
VTKExt.jl     |   28     28  14.2s
     Testing WaterLily tests passed

And the benchmark results compared to master (d0ec1d2).

--------------------------------------
Running benchmark tests for:
 - Julia:        1.10.0
 - Backends:     Array CuArray
 - CPU threads:  1 6
 - Cases:        tgv jelly
 - Size:         6,7 5,6
 - Sim. steps:   100 100
 - Data type:    Float32 Float32
--------------------------------------

Julia 1.10.0 benchmaks
Updating environment to Julia 1.10.0
   Resolving package versions...
  No Changes to `~/Workspace/WaterLily.jl/benchmark/Project.toml`
  No Changes to `~/Workspace/WaterLily.jl/benchmark/Manifest.toml`
    Updating registry at `/scratch/marinlauber/.julia/registries/General.toml`
  No Changes to `~/Workspace/WaterLily.jl/benchmark/Project.toml`
  No Changes to `~/Workspace/WaterLily.jl/benchmark/Manifest.toml`
Running: julia --project --startup-file=no -t 1 benchmark.jl --backend=Array --cases=["tgv","jelly"] --log2p=[(6,7),(5,6)] --max_steps=[100,100] --ftype=[Float32,Float32]
Benchmarking: tgv
(1/2) benchmarking "6"...
  (1/1) benchmarking "sim_step!"...
  done (took 9.153122932 seconds)
done (took 9.664080328 seconds)
(2/2) benchmarking "7"...
  (1/1) benchmarking "sim_step!"...
  done (took 55.775909505 seconds)
done (took 56.219365421 seconds)
Benchmarking: jelly
(1/2) benchmarking "5"...
  (1/1) benchmarking "sim_step!"...
  done (took 10.31607692 seconds)
done (took 10.762646285 seconds)
(2/2) benchmarking "6"...
  (1/1) benchmarking "sim_step!"...
  done (took 48.866873048 seconds)
done (took 49.323129197 seconds)
Running: julia --project --startup-file=no -t 6 benchmark.jl --backend=Array --cases=["tgv","jelly"] --log2p=[(6,7),(5,6)] --max_steps=[100,100] --ftype=[Float32,Float32]
Benchmarking: tgv
(1/2) benchmarking "6"...
  (1/1) benchmarking "sim_step!"...
  done (took 3.224376419 seconds)
done (took 3.562162138 seconds)
(2/2) benchmarking "7"...
  (1/1) benchmarking "sim_step!"...
  done (took 15.920800915 seconds)
done (took 16.161406035 seconds)
Benchmarking: jelly
(1/2) benchmarking "5"...
  (1/1) benchmarking "sim_step!"...
  done (took 3.995909223 seconds)
done (took 4.262310484 seconds)
(2/2) benchmarking "6"...
  (1/1) benchmarking "sim_step!"...
  done (took 18.140882184 seconds)
done (took 18.3939807 seconds)
Running: julia --project --startup-file=no benchmark.jl --backend=CuArray --cases=["tgv","jelly"] --log2p=[(6,7),(5,6)] --max_steps=[100,100] --ftype=[Float32,Float32]
Benchmarking: tgv
(1/2) benchmarking "6"...
  (1/1) benchmarking "sim_step!"...
  done (took 1.097216626 seconds)
done (took 1.657903387 seconds)
(2/2) benchmarking "7"...
  (1/1) benchmarking "sim_step!"...
  done (took 1.639622323 seconds)
done (took 2.123524882 seconds)
Benchmarking: jelly
(1/2) benchmarking "5"...
  (1/1) benchmarking "sim_step!"...
  done (took 1.510458438 seconds)
done (took 2.007634304 seconds)
(2/2) benchmarking "6"...
  (1/1) benchmarking "sim_step!"...
  done (took 2.660584546 seconds)
done (took 3.166380567 seconds)
Benchmark environment: tgv sim_step! (max_steps=100)
▶ log2p = 6
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   afa03a3 │ 1.10.0 │   Float32 │     1271464 │   0.09 │     8.67 │     1.00 │
│   CPUx1 │   d0ec1d2 │ 1.10.0 │   Float32 │     1357166 │   0.23 │     8.95 │     0.97 │
│   CPUx6 │   afa03a3 │ 1.10.0 │   Float32 │     4677363 │   1.00 │     2.92 │     2.97 │
│   CPUx6 │   d0ec1d2 │ 1.10.0 │   Float32 │     4999132 │   0.94 │     3.13 │     2.77 │
│     GPU │   afa03a3 │ 1.10.0 │   Float32 │     2304525 │   1.56 │     0.57 │    15.17 │
│     GPU │   d0ec1d2 │ 1.10.0 │   Float32 │     2467970 │   1.58 │     0.60 │    14.57 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘
▶ log2p = 7
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   afa03a3 │ 1.10.0 │   Float32 │     1145360 │   0.09 │    55.34 │     1.00 │
│   CPUx1 │   d0ec1d2 │ 1.10.0 │   Float32 │     1329041 │   0.14 │    57.37 │     0.96 │
│   CPUx6 │   afa03a3 │ 1.10.0 │   Float32 │     3994709 │   0.40 │    15.65 │     3.54 │
│   CPUx6 │   d0ec1d2 │ 1.10.0 │   Float32 │     4683048 │   0.67 │    16.54 │     3.35 │
│     GPU │   afa03a3 │ 1.10.0 │   Float32 │     1918194 │   0.38 │     1.16 │    47.86 │
│     GPU │   d0ec1d2 │ 1.10.0 │   Float32 │     2263519 │   0.68 │     1.31 │    42.10 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘
Benchmark environment: jelly sim_step! (max_steps=100)
▶ log2p = 5
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   afa03a3 │ 1.10.0 │   Float32 │     2263424 │   0.15 │     9.86 │     1.00 │
│   CPUx1 │   d0ec1d2 │ 1.10.0 │   Float32 │     2701319 │   0.17 │    10.94 │     0.90 │
│   CPUx6 │   afa03a3 │ 1.10.0 │   Float32 │     8318725 │   1.44 │     3.72 │     2.65 │
│   CPUx6 │   d0ec1d2 │ 1.10.0 │   Float32 │     9932893 │   1.35 │     4.29 │     2.30 │
│     GPU │   afa03a3 │ 1.10.0 │   Float32 │     4202842 │   1.23 │     1.00 │     9.87 │
│     GPU │   d0ec1d2 │ 1.10.0 │   Float32 │     5081193 │   1.40 │     1.18 │     8.34 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘
▶ log2p = 6
┌─────────┬───────────┬────────┬───────────┬─────────────┬────────┬──────────┬──────────┐
│ Backend │ WaterLily │ Julia  │ Precision │ Allocations │ GC [%] │ Time [s] │ Speed-up │
├─────────┼───────────┼────────┼───────────┼─────────────┼────────┼──────────┼──────────┤
│   CPUx1 │   afa03a3 │ 1.10.0 │   Float32 │     3192831 │   0.19 │    48.40 │     1.00 │
│   CPUx1 │   d0ec1d2 │ 1.10.0 │   Float32 │     4208670 │   0.22 │    53.38 │     0.91 │
│   CPUx6 │   afa03a3 │ 1.10.0 │   Float32 │    11729531 │   0.84 │    17.86 │     2.71 │
│   CPUx6 │   d0ec1d2 │ 1.10.0 │   Float32 │    15448298 │   0.88 │    20.85 │     2.32 │
│     GPU │   afa03a3 │ 1.10.0 │   Float32 │     5958203 │   0.89 │     2.15 │    22.48 │
│     GPU │   d0ec1d2 │ 1.10.0 │   Float32 │     7945566 │   1.02 │     2.69 │    17.99 │
└─────────┴───────────┴────────┴───────────┴─────────────┴────────┴──────────┴──────────┘

src/Flow.jl Show resolved Hide resolved
src/Flow.jl Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
test/runtests.jl Show resolved Hide resolved
@marinlauber
Copy link
Member Author

I think this is ready to merge, or do you want me to change other things? @b-fg @weymouth

@b-fg
Copy link
Member

b-fg commented Feb 16, 2024

Looks fine to me.

@weymouth weymouth merged commit 3bbbca1 into WaterLily-jl:master Feb 17, 2024
8 checks passed
@weymouth weymouth mentioned this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants