Skip to content

Commit 9d306e2

Browse files
LasNikasLasNikasefaulhaber
authored
Fix convert_particle! (#926)
* fix * fix face normal * fix again * avoid signbit * fix unit test * Update src/preprocessing/geometries/geometries.jl Co-authored-by: Erik Faulhaber <[email protected]> --------- Co-authored-by: LasNikas <[email protected]> Co-authored-by: Erik Faulhaber <[email protected]>
1 parent da445e3 commit 9d306e2

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/preprocessing/geometries/geometries.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ function planar_geometry_to_face(planar_geometry::TriangleMesh)
102102
throw(ArgumentError("geometry is not planar"))
103103
end
104104

105+
# The `face_normal` computed above might not be exactly orthogonal to the plane
106+
# spanned by `edge1` and `edge2`, but this is important for some computations later.
107+
computed_face_normal = SVector(Tuple(normalize(cross(edge1, edge2))))
108+
computed_face_normal *= sign(dot(computed_face_normal, face_normal))
109+
105110
return (; face=(face_vertices[:, 1], face_vertices[:, 2], face_vertices[:, 3]),
106-
face_normal=face_normal)
111+
face_normal=computed_face_normal)
107112
end
108113

109114
# According to:

src/schemes/boundary/open_boundary/boundary_zones.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function set_up_boundary_zone(boundary_face, face_normal, density, particle_spac
327327
# First vector of `spanning_vectors` is normal to the boundary face.
328328
dot_face_normal = dot(normalize(spanning_set[:, 1]), face_normal)
329329

330-
if !isapprox(abs(dot_face_normal), 1, rtol=1e-5)
330+
if !isapprox(abs(dot_face_normal), 1)
331331
throw(ArgumentError("`face_normal` is not normal to the boundary face"))
332332
end
333333

@@ -426,6 +426,12 @@ function update_boundary_zone_indices!(system, u, boundary_zones, semi)
426426
system.boundary_zone_indices[particle] = zone_id
427427
end
428428
end
429+
430+
# This only occurs if `face_normal` is not exactly normal to the `boundary_face`.
431+
# In such cases, particles that are actually outside the simulation domain (outflow particles)
432+
# may be incorrectly kept active as inflow particles and therefore cannot be assigned to any boundary zone.
433+
# This issue should not occur and has been fixed in https://github.com/trixi-framework/TrixiParticles.jl/pull/926 .
434+
@assert system.boundary_zone_indices[particle] != 0 "No boundary zone found for active buffer particle"
429435
end
430436

431437
return system

src/schemes/boundary/open_boundary/system.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,16 @@ end
301301
@inline function convert_particle!(system::OpenBoundarySystem, fluid_system,
302302
boundary_zone, particle, particle_new,
303303
v, u, v_fluid, u_fluid)
304+
# Position relative to the origin of the transition face
304305
relative_position = current_coords(u, system, particle) - boundary_zone.zone_origin
305306

306307
# Check if particle is in- or outside the fluid domain.
307308
# `face_normal` is always pointing into the fluid domain.
308-
if signbit(dot(relative_position, boundary_zone.face_normal))
309+
# Since this function is called for a particle that left the boundary zone,
310+
# it is sufficient to check if the dot product between the relative position and the face normal is negative
311+
# to determine if it exited the boundary zone through the free surface (outflow).
312+
if dot(relative_position, boundary_zone.face_normal) < 0
313+
# Particle is outside the fluid domain
309314
deactivate_particle!(system, particle, u)
310315

311316
return system

test/preprocessing/geometries/geometries.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
expected_face = ([-0.10239515072676975, 0.2644994251485518, -0.36036119092034713],
139139
[0.3064669575380171, 0.2392044626289733, -0.10866880239395837],
140140
[-0.02275190052262935, 0.299506937268509, -0.034649329562556])
141-
ecpected_normal = [0.14372397390844055, 0.979596249614303, -0.14047991694743392]
141+
ecpected_normal = [0.1475390528366601, 0.9789123605574772, -0.1412898376948919]
142142

143143
@test any(isapprox.(face, expected_face))
144144
@test isapprox(face_normal, ecpected_normal)

0 commit comments

Comments
 (0)