Skip to content
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

Reopen #382: Extrude shapes/geometry #437

Merged
merged 29 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2255b4a
implement `ExtrudeFace`
LasNikas Feb 5, 2024
48a753d
Merge branch 'main' into extrude-shape
LasNikas Feb 7, 2024
e299960
use `sample_face` in `interpolate_plane_3d`
LasNikas Feb 7, 2024
68b3546
add docs
LasNikas Feb 7, 2024
198eadd
add tests
LasNikas Feb 7, 2024
6c7cbde
Merge branch 'main' into extrude-shape
LasNikas Feb 7, 2024
4fe0358
fix bug
LasNikas Feb 7, 2024
a509489
fix bug
LasNikas Feb 8, 2024
1d5d99c
add `tlsph=true`
LasNikas Feb 8, 2024
2b472c9
fix tuple bug
LasNikas Feb 8, 2024
8d3c622
fix typo
LasNikas Feb 8, 2024
a5e2f1c
fix again
LasNikas Feb 8, 2024
bde240d
fix layers
LasNikas Feb 8, 2024
b3a979b
calculate particle spacing differently
LasNikas Feb 9, 2024
3521b0d
Merge branch 'main' into extrude-shape
LasNikas Feb 9, 2024
f4cd243
change `floor` to `ceil`
LasNikas Feb 9, 2024
7e01ecc
Merge branch 'main' into extrude-shape
LasNikas Feb 12, 2024
199678b
change `round` to `isapprox`
LasNikas Feb 13, 2024
36fe5fd
adapt docs
LasNikas Feb 14, 2024
cf010c9
Merge branch 'main' into extrude-shape
LasNikas Feb 14, 2024
c2a4916
Merge branch 'main' into extrude-shape
LasNikas Mar 5, 2024
a1f575d
Merge branch 'main' into extrude-shape
LasNikas Mar 26, 2024
3e10d16
implement suggestions
LasNikas Apr 2, 2024
d018266
add doctests
LasNikas Apr 2, 2024
1df1cf2
Merge branch 'main' into extrude-shape
LasNikas Apr 2, 2024
5ca362c
try to fix doctest
LasNikas Apr 2, 2024
36137e4
implement suggestions
LasNikas Apr 3, 2024
9f5ad6e
Merge branch 'main' into extrude-shape
LasNikas Apr 3, 2024
9429c09
implement suggestion
LasNikas Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/general/interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ function interpolate_plane_3d(point1, point2, point3, resolution, semi, ref_syst
sol::ODESolution;
smoothing_length=ref_system.smoothing_length,
cut_off_bnd=true, clip_negative_pressure=false)
v_ode = sol.u[end].x[1]
u_ode = sol.u[end].x[2]
LasNikas marked this conversation as resolved.
Show resolved Hide resolved

interpolate_plane_3d(point1, point2, point3, resolution, semi, ref_system,
v_ode, u_ode; smoothing_length, cut_off_bnd,
clip_negative_pressure)
end

function interpolate_plane_3d(point1, point2, point3, resolution, semi, ref_system,
v_ode, u_ode; smoothing_length=ref_system.smoothing_length,
cut_off_bnd=true, clip_negative_pressure=false)
if ndims(ref_system) != 3
throw(ArgumentError("`interpolate_plane_3d` requires a 3D simulation"))
LasNikas marked this conversation as resolved.
Show resolved Hide resolved
end
Expand Down
37 changes: 25 additions & 12 deletions src/setups/extrude_geometry.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
@doc raw"""
extrude_geometry(geometry; particle_spacing, direction, n_extrude=1,
velocity=zeros(length(direction)),
mass=nothing, density=nothing, pressure=0.0)
extrude_geometry(geometry; particle_spacing, direction, n_extrude::Integer,
velocity=zeros(length(direction)),
mass=nothing, density=nothing, pressure=0.0)

Extrude either a line, a plane or a shape along a specific direction.

# Arguments
- `geometry`: Either points defining a 3D plane (2D line)
or particle coordinates defining a specific shape.
- `geometry`: Either particle coordinates or an [`InitialCondition`](@ref)
defining a 2D shape to extrude to a 3D volume, or two 2D points
defining a line to extrude to a plane in 2D, or three 3D points defining
a parallelogram to extrude to a parallelepiped.

# Keywords
- `particle_spacing`: Spacing between the particles.
- `particle_spacing`: Spacing between the particles. Can be omitted when `geometry` is an
`InitialCondition` (unless `geometry.particle_spacing == -1`).
- `direction`: A vector that specifies the direction in which to extrude.
- `n_extrude=2` Number of layers of particles created in the direction of extrusion.
- `n_extrude`: Number of layers of particles created in the direction of extrusion.
- `velocity`: Either a function mapping each particle's coordinates to its velocity,
or, for a constant fluid velocity, a vector holding this velocity.
Velocity is constant zero by default.
Expand All @@ -31,7 +35,7 @@ Extrude either a line, a plane or a shape along a specific direction.
When `tlsph=true`, particles will be placed on the boundary of the shape.

# Examples
```jldoctest; output = false, filter = [r"┌ Info: The desired size .*\n", r"└ New particle spacing is set to .*\n"]
```jldoctest; output = false
# Extrude a line in 2D to a plane in 2D
p1 = [0.0, 0.0]
p2 = [1.0, 1.0]
Expand All @@ -58,24 +62,33 @@ direction = [0.0, 0.0, 1.0]
shape = extrude_geometry(shape; direction, particle_spacing=0.1, n_extrude=4, density=1000.0)

# output
LasNikas marked this conversation as resolved.
Show resolved Hide resolved
┌ Info: The desired size is not a multiple of the particle spacing 0.1.
└ New particle spacing is set to 0.09387239731236392.
┌ Info: The desired size is not a multiple of the particle spacing 0.1.
└ New particle spacing is set to 0.09198039027185569.
InitialCondition{Float64}(0.1, [0.44999999999999996 0.43096988312782164 … -0.23871756048182058 -0.24999999999999994; 0.4 0.4956708580912724 … 0.5001344202803415 0.4000000000000001; 0.05 0.05 … 0.35000000000000003 0.35000000000000003], [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0], [1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002 … 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002, 1.0000000000000002], [1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0 … 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
```

!!! warning "Experimental Implementation"
This is an experimental feature and may change in any future releases.
"""
function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude=2,
function extrude_geometry(geometry; particle_spacing=-1, direction, n_extrude::Integer,
velocity=zeros(length(direction)), tlsph=false,
mass=nothing, density=nothing, pressure=0.0)
direction_ = normalize(direction)
NDIMS = length(direction_)

if !(geometry isa InitialCondition) && particle_spacing == -1
throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`"))
elseif geometry isa InitialCondition
if geometry isa InitialCondition && geometry.particle_spacing > 0
if particle_spacing > 0 && particle_spacing != geometry.particle_spacing
throw(ArgumentError("`particle_spacing` must be -1 when using an `InitialCondition`"))
end
particle_spacing = geometry.particle_spacing
end

if particle_spacing <= 0
throw(ArgumentError("`particle_spacing` must be specified when not extruding an `InitialCondition`"))
end

geometry = shift_plane_corners(geometry, direction_, particle_spacing, tlsph)

face_coords, particle_spacing_ = sample_plane(geometry, particle_spacing; tlsph=tlsph)
Expand Down
Loading