-
Notifications
You must be signed in to change notification settings - Fork 104
Non-uniform boundary conditions #165
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
Merged
weymouth
merged 34 commits into
WaterLily-jl:master
from
marinlauber:add-nonuniform-BCs
Apr 19, 2025
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
111c8f7
initial commit
81724f0
correct inflow mass flux
31086c2
fix accelerate!
e97d012
fix test and accelerate!
marinlauber 2766de4
fix maintest error
marinlauber d451f1c
fix allocation issues, merge body_force! and update test
marinlauber 633b6d9
tidy interface and update test
marinlauber cde7299
merge master and start fixing stuff
marinlauber ab62bbc
try solve compatibility issue
05336b5
fix Simulation constructor
3653bbf
fix BC time and constructor
5226d1a
Small adjustements on how to create u_BC and uλ in Simulation constru…
b-fg 247c1a8
Reverted from zero(T) to 0 in defining uλ cause of GPU nonbits error
b-fg f4f4697
u_BC everywhere (instead of mixed with uBC) and same default Float32 …
b-fg be9e85f
Added a user defined function (udf) feature to pass functions into si…
b-fg 24aa6b7
Fixed body_force tests. Remember to always runs all the tests...
b-fg a932639
removes body_force and defines acceleration g as a function of g(i,x,…
b-fg 404ddab
Added test for when both g and U are present.
b-fg 2e6a49b
Added assert for g function definition in Simulation constructor.
b-fg 05a989d
Reactivated tests (forgot to do it in last commit).
b-fg 35c1b23
Removed EllipsisNotation from Flow.jl (not needed anymore) and added …
b-fg c9a4db2
Uses arg names instead of underscore because it breaks (unsure why no…
b-fg 5cb8752
Fixed tests.
b-fg 3026334
Fixed viscous force tests.
b-fg 341f046
Added type stable check for g function in Simulation constructor. Fix…
b-fg c80d198
improve tests for non-uniform BCs and improve error message
marinlauber 311b5b1
Change tangential BCs and add rotating Ref test
weymouth 9a7753d
fix typo in rotating reference test
weymouth 8c55457
check type with x,t not only t
marinlauber 561db0d
remove uλ from Simulation and Flow
marinlauber 957aed0
remove old checks in WaterLily.jl
marinlauber bbbc15a
Name and doc changes
weymouth 01d9a24
Slightly better Uλ doc string
weymouth 399061a
Reverted behaviour to uBC and uλ for BCs and IC, respectively. Also c…
b-fg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,26 +30,27 @@ include("Metrics.jl") | |
|
|
||
| abstract type AbstractSimulation end | ||
| """ | ||
| Simulation(dims::NTuple, u_BC::Union{NTuple,Function}, L::Number; | ||
| U=norm2(u_BC), Δt=0.25, ν=0., ϵ=1, perdir=() | ||
| uλ::nothing, g=nothing, exitBC=false, | ||
| Simulation(dims::NTuple, uBC::Union{NTuple,Function}, L::Number; | ||
| U=norm2(Uλ), Δt=0.25, ν=0., ϵ=1, g=nothing, | ||
| perdir=(), exitBC=false, | ||
| body::AbstractBody=NoBody(), | ||
| T=Float32, mem=Array) | ||
|
|
||
| Constructor for a WaterLily.jl simulation: | ||
|
|
||
| - `dims`: Simulation domain dimensions. | ||
| - `u_BC`: Simulation domain velocity boundary conditions, either a | ||
| tuple `u_BC[i]=uᵢ, i=eachindex(dims)`, or a time-varying function `f(i,t)` | ||
| - `uBC`: Velocity field applied to boundary and acceleration conditions. | ||
| Define a `Tuple` for constant BCs, or a `Function` for space and time varying BCs `uBC(i,x,t)`. | ||
| - `L`: Simulation length scale. | ||
| - `U`: Simulation velocity scale. | ||
| - `U`: Simulation velocity scale. Required if using `Uλ::Function`. | ||
| - `Δt`: Initial time step. | ||
| - `ν`: Scaled viscosity (`Re=UL/ν`). | ||
| - `g`: Domain acceleration, `g(i,t)=duᵢ/dt` | ||
| - `g`: Domain acceleration, `g(i,x,t)=duᵢ/dt` | ||
| - `ϵ`: BDIM kernel width. | ||
| - `perdir`: Domain periodic boundary condition in the `(i,)` direction. | ||
| - `uλ`: Velocity field applied to the initial condition. | ||
| Define a Tuple for homogeneous (per direction) IC, or a `Function` for space varying IC `uλ(i,x)`. | ||
| - `exitBC`: Convective exit boundary condition in the `i=1` direction. | ||
| - `uλ`: Function to generate the initial velocity field. | ||
| - `body`: Immersed geometry. | ||
| - `T`: Array element type. | ||
| - `mem`: memory location. `Array`, `CuArray`, `ROCm` to run on CPU, NVIDIA, or AMD devices, respectively. | ||
|
|
@@ -63,16 +64,14 @@ mutable struct Simulation <: AbstractSimulation | |
| flow :: Flow | ||
| body :: AbstractBody | ||
| pois :: AbstractPoisson | ||
| function Simulation(dims::NTuple{N}, u_BC, L::Number; | ||
| function Simulation(dims::NTuple{N}, uBC, L::Number; | ||
| Δt=0.25, ν=0., g=nothing, U=nothing, ϵ=1, perdir=(), | ||
| uλ=nothing, exitBC=false, body::AbstractBody=NoBody(), | ||
| T=Float32, mem=Array) where N | ||
| @assert !(isa(u_BC,Function) && isa(uλ,Function)) "`u_BC` and `uλ` cannot be both specified as Function" | ||
| @assert !(isnothing(U) && isa(u_BC,Function)) "`U` must be specified if `u_BC` is a Function" | ||
| isa(u_BC,Function) && @assert all(typeof.(ntuple(i->u_BC(i,zero(T)),N)).==T) "`u_BC` is not type stable" | ||
| uλ = isnothing(uλ) ? ifelse(isa(u_BC,Function),(i,x)->u_BC(i,0.),(i,x)->u_BC[i]) : uλ | ||
| U = isnothing(U) ? √sum(abs2,u_BC) : U # default if not specified | ||
| flow = Flow(dims,u_BC;uλ,Δt,ν,g,T,f=mem,perdir,exitBC) | ||
| @assert !(isnothing(U) && isa(uBC,Function)) "`U` (velocity scale) must be specified if boundary conditions `uBC` is a `Function`" | ||
| isnothing(U) && (U = √sum(abs2,uBC)) | ||
| check_fn(uBC,N,T,3); check_fn(g,N,T,3); check_fn(uλ,N,T,2) | ||
| flow = Flow(dims,uBC;uλ,Δt,ν,g,T,f=mem,perdir,exitBC) | ||
| measure!(flow,body;ϵ) | ||
| new(U,L,ϵ,flow,body,MultiLevelPoisson(flow.p,flow.μ₀,flow.σ;perdir)) | ||
| end | ||
|
|
@@ -94,18 +93,20 @@ sim_time(sim::AbstractSimulation) = time(sim)*sim.U/sim.L | |
| Integrate the simulation `sim` up to dimensionless time `t_end`. | ||
| If `remeasure=true`, the body is remeasured at every time step. | ||
| Can be set to `false` for static geometries to speed up simulation. | ||
| A user-defined function `udf` can be passed to arbitrarily modify the `::Flow` during the predictor and corrector steps. | ||
| If the `udf` user keyword arguments, these needs to be included in the `sim_step!` call as well. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably want to add something in the documentation here about the type returned by these functions needing to match |
||
| """ | ||
| function sim_step!(sim::AbstractSimulation,t_end;remeasure=true,max_steps=typemax(Int),verbose=false) | ||
| function sim_step!(sim::AbstractSimulation,t_end;remeasure=true,max_steps=typemax(Int),udf=nothing,verbose=false,kwargs...) | ||
| steps₀ = length(sim.flow.Δt) | ||
| while sim_time(sim) < t_end && length(sim.flow.Δt) - steps₀ < max_steps | ||
| sim_step!(sim; remeasure) | ||
| sim_step!(sim; remeasure, udf, kwargs...) | ||
| verbose && println("tU/L=",round(sim_time(sim),digits=4), | ||
| ", Δt=",round(sim.flow.Δt[end],digits=3)) | ||
| end | ||
| end | ||
| function sim_step!(sim::AbstractSimulation;remeasure=true) | ||
| function sim_step!(sim::AbstractSimulation;remeasure=true,udf=nothing,kwargs...) | ||
| remeasure && measure!(sim) | ||
| mom_step!(sim.flow,sim.pois) | ||
| mom_step!(sim.flow, sim.pois; udf, kwargs...) | ||
| end | ||
|
|
||
| """ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.