Skip to content

Commit 97995f9

Browse files
authored
Merge branch 'main' into more_semi_cleanup
2 parents 655e8a1 + 56dfe41 commit 97995f9

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

src/schemes/boundary/open_boundary/boundary_zones.jl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,19 @@ bidirectional_flow = BoundaryZone(; boundary_face=face_vertices, face_normal,
162162
!!! warning "Experimental Implementation"
163163
This is an experimental feature and may change in any future releases.
164164
"""
165-
struct BoundaryZone{IC, S, ZO, ZW, FD, FN, ELTYPE, R, C}
165+
struct BoundaryZone{NDIMS, ELTYPE, IC, S, R, C}
166166
initial_condition :: IC
167167
spanning_set :: S
168-
zone_origin :: ZO
169-
zone_width :: ZW
170-
flow_direction :: FD
171-
face_normal :: FN
168+
zone_origin :: SVector{NDIMS, ELTYPE}
169+
zone_width :: ELTYPE
170+
flow_direction :: SVector{NDIMS, ELTYPE}
171+
face_normal :: SVector{NDIMS, ELTYPE}
172172
rest_pressure :: ELTYPE # Only required for `BoundaryModelDynamicalPressureZhang`
173173
reference_values :: R
174174
cache :: C
175175
# Note that the following can't be static type parameters, as all boundary zones in a system
176176
# must have the same type, so that we can loop over them in a type-stable way.
177+
is_bidirectional :: Bool
177178
average_inflow_velocity :: Bool
178179
prescribed_density :: Bool
179180
prescribed_pressure :: Bool
@@ -202,7 +203,7 @@ function BoundaryZone(; boundary_face, face_normal, density, particle_spacing,
202203
NDIMS = ndims(ic)
203204
ELTYPE = eltype(ic)
204205
if !(reference_velocity isa Function || isnothing(reference_velocity) ||
205-
(reference_velocity isa Vector && length(reference_velocity) == NDIMS))
206+
(reference_velocity isa AbstractVector && length(reference_velocity) == NDIMS))
206207
throw(ArgumentError("`reference_velocity` must be either a function mapping " *
207208
"each particle's coordinates and time to its velocity, " *
208209
"or, for a constant fluid velocity, a vector of length $NDIMS for a $(NDIMS)D problem holding this velocity"))
@@ -281,16 +282,18 @@ function BoundaryZone(; boundary_face, face_normal, density, particle_spacing,
281282
cache = (;
282283
create_cache_boundary_zone(ic, boundary_face, face_normal_, sample_points)...)
283284

285+
is_bidirectional = boundary_type isa BidirectionalFlow
286+
284287
return BoundaryZone(ic, spanning_set_, zone_origin, zone_width,
285288
flow_direction, face_normal_, rest_pressure, reference_values,
286-
cache, average_inflow_velocity, prescribed_density,
287-
prescribed_pressure, prescribed_velocity)
289+
cache, is_bidirectional, average_inflow_velocity,
290+
prescribed_density, prescribed_pressure, prescribed_velocity)
288291
end
289292

290293
function boundary_type_name(boundary_zone::BoundaryZone)
291-
(; flow_direction, face_normal) = boundary_zone
294+
(; flow_direction, face_normal, is_bidirectional) = boundary_zone
292295

293-
if isnothing(flow_direction)
296+
if is_bidirectional
294297
return "bidirectional_flow"
295298
elseif signbit(dot(flow_direction, face_normal))
296299
return "outflow"
@@ -378,7 +381,7 @@ function set_up_boundary_zone(boundary_face, face_normal, density, particle_spac
378381
# Unit vector pointing in downstream direction
379382
flow_direction = -face_normal
380383
elseif boundary_type isa BidirectionalFlow
381-
flow_direction = nothing
384+
flow_direction = zero(face_normal)
382385
end
383386

384387
# Sample particles in boundary zone
@@ -565,7 +568,7 @@ function wrap_reference_function(constant_vector::AbstractVector,
565568
return @inline((coords, t)->SVector{NDIMS, ELTYPE}(constant_vector))
566569
end
567570

568-
function reference_pressure(boundary_zone, v, system, particle, pos, t)
571+
@inline function reference_pressure(boundary_zone, v, system, particle, pos, t)
569572
(; prescribed_pressure) = boundary_zone
570573
(; pressure_reference_values) = system.cache
571574

@@ -579,7 +582,7 @@ function reference_pressure(boundary_zone, v, system, particle, pos, t)
579582
end
580583
end
581584

582-
function reference_density(boundary_zone, v, system, particle, pos, t)
585+
@inline function reference_density(boundary_zone, v, system, particle, pos, t)
583586
(; prescribed_density) = boundary_zone
584587
(; density_reference_values) = system.cache
585588

@@ -593,7 +596,7 @@ function reference_density(boundary_zone, v, system, particle, pos, t)
593596
end
594597
end
595598

596-
function reference_velocity(boundary_zone, v, system, particle, pos, t)
599+
@inline function reference_velocity(boundary_zone, v, system, particle, pos, t)
597600
(; prescribed_velocity) = boundary_zone
598601
(; velocity_reference_values) = system.cache
599602

src/schemes/boundary/open_boundary/dynamical_pressure.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ function write_v0!(v0, system::OpenBoundarySystem, ::BoundaryModelDynamicalPress
9898
return v0
9999
end
100100

101-
function reference_pressure(boundary_zone, v,
102-
system::OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang},
103-
particle, pos, t)
101+
@inline function reference_pressure(boundary_zone, v,
102+
system::OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang},
103+
particle, pos, t)
104104
(; prescribed_pressure, rest_pressure) = boundary_zone
105105
(; pressure_reference_values) = system.cache
106106

src/schemes/boundary/open_boundary/mirroring.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,11 @@ end
486486

487487
# Only for inflow boundary zones
488488
function average_velocity!(v, u, system, boundary_zone, semi)
489-
(; face_normal, zone_origin, initial_condition, flow_direction) = boundary_zone
489+
(; face_normal, zone_origin, initial_condition, flow_direction,
490+
is_bidirectional) = boundary_zone
490491

491492
# Bidirectional flow
492-
isnothing(flow_direction) && return v
493+
is_bidirectional && return v
493494

494495
# Outflow
495496
signbit(dot(flow_direction, face_normal)) && return v
@@ -526,10 +527,10 @@ end
526527
# Only for inflow boundary zones
527528
function project_velocity_on_face_normal!(v, system, particle, boundary_zone,
528529
boundary_model)
529-
(; face_normal, flow_direction) = boundary_zone
530+
(; face_normal, flow_direction, is_bidirectional) = boundary_zone
530531

531532
# Bidirectional flow
532-
isnothing(flow_direction) && return v
533+
is_bidirectional && return v
533534

534535
# Outflow
535536
signbit(dot(flow_direction, face_normal)) && return v

src/schemes/boundary/open_boundary/system.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,7 @@ function OpenBoundarySystem(boundary_zones::Union{BoundaryZone, Nothing}...;
114114
# in the `BoundaryZone`, but they are not used in the actual simulation.
115115
# The reference values are extracted above in the "create cache" function
116116
# and then stored in `system.cache` as a `Tuple`.
117-
boundary_zones_new = map(zone -> BoundaryZone(zone.initial_condition,
118-
zone.spanning_set,
119-
zone.zone_origin,
120-
zone.zone_width,
121-
zone.flow_direction,
122-
zone.face_normal,
123-
zone.rest_pressure,
124-
nothing,
125-
zone.cache,
126-
zone.average_inflow_velocity,
127-
zone.prescribed_density,
128-
zone.prescribed_pressure,
129-
zone.prescribed_velocity),
130-
boundary_zones_)
117+
boundary_zones_new = map(zone -> @set(zone.reference_values = nothing), boundary_zones_)
131118

132119
return OpenBoundarySystem(boundary_model, initial_conditions, fluid_system,
133120
fluid_system_index, smoothing_kernel, smoothing_length, mass,
@@ -297,6 +284,11 @@ end
297284
return v
298285
end
299286

287+
function calculate_dt(v_ode, u_ode, cfl_number, system::OpenBoundarySystem, semi)
288+
# Open boundaries don't affect the timestep calculation
289+
return Inf
290+
end
291+
300292
@inline function add_velocity!(du, v, u, particle, system::OpenBoundarySystem, t)
301293
boundary_zone = current_boundary_zone(system, particle)
302294

0 commit comments

Comments
 (0)