11@doc raw """
2- OpenBoundarySPHSystem(boundary_zone::Union{InFlow, OutFlow} ;
2+ OpenBoundarySPHSystem(boundary_zone::BoundaryZone ;
33 fluid_system::FluidSystem, buffer_size::Integer,
44 boundary_model,
55 reference_velocity=nothing,
99Open boundary system for in- and outflow particles.
1010
1111# Arguments
12- - `boundary_zone`: Use [`InFlow `](@ref) for an inflow and [`OutFlow`](@ref) for an outflow boundary .
12+ - `boundary_zone`: See [`BoundaryZone `](@ref).
1313
1414# Keywords
1515- `fluid_system`: The corresponding fluid system
@@ -39,15 +39,14 @@ struct OpenBoundarySPHSystem{BM, BZ, NDIMS, ELTYPE <: Real, IC, FS, ARRAY1D, RV,
3939 volume :: ARRAY1D # Array{ELTYPE, 1}: [particle]
4040 pressure :: ARRAY1D # Array{ELTYPE, 1}: [particle]
4141 boundary_zone :: BZ
42- flow_direction :: SVector{NDIMS, ELTYPE}
4342 reference_velocity :: RV
4443 reference_pressure :: RP
4544 reference_density :: RD
4645 buffer :: B
4746 update_callback_used :: Ref{Bool}
4847 cache :: C
4948
50- function OpenBoundarySPHSystem (boundary_zone:: Union{InFlow, OutFlow} ;
49+ function OpenBoundarySPHSystem (boundary_zone:: BoundaryZone ;
5150 fluid_system:: FluidSystem ,
5251 buffer_size:: Integer , boundary_model,
5352 reference_velocity= nothing ,
@@ -116,8 +115,6 @@ struct OpenBoundarySPHSystem{BM, BZ, NDIMS, ELTYPE <: Real, IC, FS, ARRAY1D, RV,
116115 reference_density_ = wrap_reference_function (reference_density, Val (NDIMS))
117116 end
118117
119- flow_direction_ = boundary_zone. flow_direction
120-
121118 cache = create_cache_open_boundary (boundary_model, initial_condition)
122119
123120 return new{typeof (boundary_model), typeof (boundary_zone), NDIMS, ELTYPE,
@@ -126,7 +123,7 @@ struct OpenBoundarySPHSystem{BM, BZ, NDIMS, ELTYPE <: Real, IC, FS, ARRAY1D, RV,
126123 typeof (reference_density_), typeof (buffer),
127124 typeof (cache)}(initial_condition, fluid_system, boundary_model, mass,
128125 density, volume, pressure, boundary_zone,
129- flow_direction_, reference_velocity_, reference_pressure_,
126+ reference_velocity_, reference_pressure_,
130127 reference_density_, buffer, false , cache)
131128 end
132129end
@@ -143,12 +140,13 @@ end
143140
144141timer_name (:: OpenBoundarySPHSystem ) = " open_boundary"
145142vtkname (system:: OpenBoundarySPHSystem ) = " open_boundary"
143+ boundary_type_name (:: BoundaryZone{ZT} ) where {ZT} = string (nameof (ZT))
146144
147145function Base. show (io:: IO , system:: OpenBoundarySPHSystem )
148146 @nospecialize system # reduce precompilation time
149147
150148 print (io, " OpenBoundarySPHSystem{" , ndims (system), " }(" )
151- print (io, type2string (system. boundary_zone))
149+ print (io, boundary_type_name (system. boundary_zone))
152150 print (io, " ) with " , nparticles (system), " particles" )
153151end
154152
@@ -163,8 +161,7 @@ function Base.show(io::IO, ::MIME"text/plain", system::OpenBoundarySPHSystem)
163161 summary_line (io, " #buffer_particles" , system. buffer. buffer_size)
164162 summary_line (io, " fluid system" , type2string (system. fluid_system))
165163 summary_line (io, " boundary model" , type2string (system. boundary_model))
166- summary_line (io, " boundary" , type2string (system. boundary_zone))
167- summary_line (io, " flow direction" , system. flow_direction)
164+ summary_line (io, " boundary type" , boundary_type_name (system. boundary_zone))
168165 summary_line (io, " prescribed velocity" , type2string (system. reference_velocity))
169166 summary_line (io, " prescribed pressure" , type2string (system. reference_pressure))
170167 summary_line (io, " prescribed density" , type2string (system. reference_density))
258255
259256# Outflow particle is outside the boundary zone
260257@inline function convert_particle! (system:: OpenBoundarySPHSystem , fluid_system,
261- boundary_zone:: OutFlow , particle, v, u,
258+ boundary_zone:: BoundaryZone{ OutFlow} , particle, v, u,
262259 v_fluid, u_fluid)
263260 deactivate_particle! (system, particle, u)
264261
267264
268265# Inflow particle is outside the boundary zone
269266@inline function convert_particle! (system:: OpenBoundarySPHSystem , fluid_system,
270- boundary_zone:: InFlow , particle, v, u,
267+ boundary_zone:: BoundaryZone{ InFlow} , particle, v, u,
271268 v_fluid, u_fluid)
272269 (; spanning_set) = boundary_zone
273270
282279 return system
283280end
284281
282+ # Buffer particle is outside the boundary zone
283+ @inline function convert_particle! (system:: OpenBoundarySPHSystem , fluid_system,
284+ boundary_zone:: BoundaryZone{BidirectionalFlow} , particle,
285+ v, u, v_fluid, u_fluid)
286+ relative_position = current_coords (u, system, particle) - boundary_zone. zone_origin
287+
288+ # Check if particle is in- or outside the fluid domain.
289+ # `plane_normal` is always pointing into the fluid domain.
290+ if signbit (dot (relative_position, boundary_zone. plane_normal))
291+ deactivate_particle! (system, particle, u)
292+
293+ return system
294+ end
295+
296+ # Activate a new particle in simulation domain
297+ transfer_particle! (fluid_system, system, particle, v_fluid, u_fluid, v, u)
298+
299+ # Reset position of boundary particle
300+ for dim in 1 : ndims (system)
301+ u[dim, particle] = boundary_zone. plane_normal[dim]
302+ end
303+
304+ return system
305+ end
306+
285307# Fluid particle is in boundary zone
286308@inline function convert_particle! (fluid_system:: FluidSystem , system,
287309 boundary_zone, particle, v, u, v_fluid, u_fluid)
0 commit comments