@@ -64,10 +64,12 @@ direction = [0.0, 0.0, 1.0]
6464shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, density=1000.0)
6565
6666# output
67- ┌ Info: The desired size is not a multiple of the particle spacing 0.1.
68- └ New particle spacing is set to 0.09387239731236392.
69- ┌ Info: The desired size is not a multiple of the particle spacing 0.1.
70- └ New particle spacing is set to 0.09198039027185569.
67+ ┌ Info: The desired line length 1.314213562373095 is not a multiple of the particle spacing 0.1.
68+ └ New line length is set to 1.3.
69+ ┌ Info: The desired edge 1 length 1.0180339887498948 is not a multiple of the particle spacing 0.1.
70+ └ New edge 1 length is set to 1.0.
71+ ┌ Info: The desired edge 2 length 0.9198039027185568 is not a multiple of the particle spacing 0.1.
72+ └ New edge 2 length is set to 0.9.
7173┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
7274│ InitialCondition{Float64} │
7375│ ═════════════════════════ │
@@ -99,16 +101,9 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I
99101
100102 geometry = shift_plane_corners (geometry, direction_, particle_spacing, place_on_shell)
101103
102- face_coords,
103- particle_spacing_ = sample_plane (geometry, particle_spacing;
104- place_on_shell= place_on_shell)
104+ face_coords = sample_plane (geometry, particle_spacing; place_on_shell= place_on_shell)
105105
106- if ! isapprox (particle_spacing, particle_spacing_, rtol= 5e-2 )
107- @info " The desired size is not a multiple of the particle spacing $particle_spacing ." *
108- " \n New particle spacing is set to $particle_spacing_ ."
109- end
110-
111- coords = (face_coords .+ i * particle_spacing_ * direction_ for i in 0 : (n_extrude - 1 ))
106+ coords = (face_coords .+ i * particle_spacing * direction_ for i in 0 : (n_extrude - 1 ))
112107
113108 # In this context, `stack` is faster than `hcat(coords...)`
114109 coordinates = reshape (stack (coords), (NDIMS, size (face_coords, 2 ) * n_extrude))
@@ -118,7 +113,7 @@ function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::I
118113 end
119114
120115 return InitialCondition (; coordinates, velocity, density, mass, pressure,
121- particle_spacing= particle_spacing_ )
116+ particle_spacing= particle_spacing )
122117end
123118
124119# For corners/endpoints of a plane/line, sample the plane/line with particles.
@@ -132,10 +127,10 @@ function sample_plane(geometry::AbstractMatrix, particle_spacing; place_on_shell
132127 fill (place_on_shell ? 0 : particle_spacing / 2 , size (geometry, 2 ))' )
133128
134129 # TODO : 2D shapes not only in x-y plane but in any user-defined plane
135- return coords, particle_spacing
130+ return coords
136131 end
137132
138- return geometry, particle_spacing
133+ return geometry
139134end
140135
141136function sample_plane (shape:: InitialCondition , particle_spacing; place_on_shell)
@@ -148,10 +143,10 @@ function sample_plane(shape::InitialCondition, particle_spacing; place_on_shell)
148143 size (shape. coordinates, 2 ))' )
149144
150145 # TODO : 2D shapes not only in x-y plane but in any user-defined plane
151- return coords, particle_spacing
146+ return coords
152147 end
153148
154- return shape. coordinates, particle_spacing
149+ return shape. coordinates
155150end
156151
157152function sample_plane (plane_points, particle_spacing; place_on_shell= nothing )
@@ -166,12 +161,19 @@ function sample_plane(plane_points::NTuple{2}, particle_spacing; place_on_shell=
166161 throw (ArgumentError (" all points must be 2D coordinates" ))
167162 end
168163
169- n_points = ceil (Int, norm (plane_points[2 ] - plane_points[1 ]) / particle_spacing) + 1
164+ p1 = plane_points[1 ]
165+ p2 = plane_points[2 ]
166+
167+ line_dir = p2 - p1
168+ line_length = norm (line_dir)
170169
171- coords = stack (range (plane_points[1 ], plane_points[2 ], length= n_points))
172- particle_spacing_new = norm (coords[:, 1 ] - coords[:, 2 ])
170+ n_particles,
171+ new_length = round_n_particles (line_length, particle_spacing,
172+ " line length" )
173173
174- return coords, particle_spacing_new
174+ coords = stack ([p1 + i * particle_spacing * normalize (line_dir) for i in 0 : n_particles])
175+
176+ return coords
175177end
176178
177179function sample_plane (plane_points:: NTuple{3} , particle_spacing; place_on_shell= nothing )
@@ -194,25 +196,28 @@ function sample_plane(plane_points::NTuple{3}, particle_spacing; place_on_shell=
194196 end
195197
196198 # Determine the number of points along each edge
197- num_points_edge1 = ceil (Int, norm (edge1) / particle_spacing)
198- num_points_edge2 = ceil (Int, norm (edge2) / particle_spacing)
199-
199+ num_points_edge1,
200+ new_length = round_n_particles (norm (edge1), particle_spacing,
201+ " edge 1 length" )
202+ num_points_edge2,
203+ new_length = round_n_particles (norm (edge2), particle_spacing,
204+ " edge 2 length" )
205+
206+ dir1 = normalize (edge1)
207+ dir2 = normalize (edge2)
200208 coords = zeros (3 , (num_points_edge1 + 1 ) * (num_points_edge2 + 1 ))
201209
202210 index = 1
203211 for i in 0 : num_points_edge1
204212 for j in 0 : num_points_edge2
205- point_on_plane = point1_ + (i / num_points_edge1) * edge1 +
206- (j / num_points_edge2) * edge2
213+ point_on_plane = point1_ + i * particle_spacing * dir1 +
214+ j * particle_spacing * dir2
207215 coords[:, index] = point_on_plane
208216 index += 1
209217 end
210218 end
211219
212- particle_spacing_new = min (norm (edge1 / num_points_edge1),
213- norm (edge2 / num_points_edge2))
214-
215- return coords, particle_spacing_new
220+ return coords
216221end
217222
218223# Shift corners of the plane/line inwards by half a particle spacing with `place_on_shell=false`
0 commit comments