Repository navigation
Geometry Tutorial #1094
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
Merged
svchb
merged 23 commits into
trixi-framework:main
from
svchb:add_tutorial_for_STL_geoms
Oct 22, 2026
Merged
Geometry Tutorial #1094
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
54502ee
better overview page
svchb 9d9a040
add
svchb e211388
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb 0f089a2
Merge remote-tracking branch 'upstream/main' into add_tutorial_for_ST…
svchb bed33ff
fix
svchb 6583c15
fix geom
svchb 4f8d3e3
format
svchb 9bcf0ec
fix docs
svchb 73ccf79
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb 50c19db
fix tests
svchb 6149a79
review
svchb aed359e
Merge remote-tracking branch 'origin/main' into add_tutorial_for_STL_…
svchb 6f73c44
fix
svchb 557aae5
fix docs @ref for Documenter 1.18
svchb dcfad31
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb 048af7b
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb 918c1cf
Add 0.5.5 release note
svchb 395e494
Address geometry tutorial review feedback
svchb 404b904
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb ec3da97
review
svchb 01a1df1
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb 4779ae2
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb 5a6dae6
Merge branch 'main' into add_tutorial_for_STL_geoms
svchb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # # [Setting up a 2D simulation from geometry files](@id tut_2d_geometry) | ||
|
|
||
| # In this tutorial, we build two 2D setups from geometry files: | ||
| # 1. a curved pipe, where one geometry file defines the outer wall and another | ||
| # defines the channel cut out of it, | ||
| # 2. a dam-break basin with a coastline profile, where one geometry file defines | ||
| # the coastline wall and the seawall on the right. | ||
| # | ||
| # We use 2D geometry formats such as `.asc` or `.dxf` for 2D setups. | ||
| # STL files are supported only for 3D geometries. | ||
|
|
||
| # First, we import TrixiParticles.jl together with | ||
| # `OrdinaryDiffEqLowStorageRK` of | ||
| # [OrdinaryDiffEq.jl](https://github.com/SciML/OrdinaryDiffEq.jl) | ||
| # and [Plots.jl](https://docs.juliaplots.org/stable/). | ||
| using TrixiParticles | ||
| using OrdinaryDiffEqLowStorageRK | ||
| using Plots | ||
|
|
||
| # ## Building the geometry | ||
|
|
||
| # We use the same particle spacing for the fluid and for the wall geometries. | ||
| particle_spacing = 0.03 | ||
| fluid_density = 1000.0 | ||
| gravity = 9.81 | ||
| sound_speed = 10.0 | ||
| state_equation = StateEquationCole(; sound_speed, reference_density=fluid_density, | ||
| exponent=7) | ||
| nothing # hide | ||
|
|
||
| # ### Loading the 2D geometry files | ||
|
|
||
| # The following helper loads a closed 2D geometry file and samples particles in its interior: | ||
| # 1. load the polygon with [`load_geometry`](@ref), | ||
| # 2. fill the polygon with [`ComplexShape`](@ref). | ||
| # | ||
| # This creates a filled 2D solid region rather than particles only along the polygon edges. | ||
| # The half-spacing `grid_offset` shifts the sampling grid in each coordinate direction | ||
| # to avoid placing particles directly on the grid-aligned edges of these geometries. | ||
| function solid_from_geometry_file(file; particle_spacing, density) | ||
| geometry = load_geometry(file) | ||
| solid = ComplexShape(geometry; particle_spacing, density, | ||
| grid_offset=0.5particle_spacing) | ||
|
|
||
| return (; geometry, solid) | ||
| end | ||
|
svchb marked this conversation as resolved.
Resolved
|
||
| nothing # hide | ||
|
|
||
| # ### A curved pipe from two filled geometries | ||
|
|
||
| # The pipe wall is an L-shaped solid region with a channel cut out of it: | ||
| # 1. one geometry file describes the outer pipe envelope, | ||
| # 2. one geometry file describes the empty channel, | ||
| # 3. `setdiff` subtracts the channel from the solid envelope. | ||
| pipe_outer_file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", | ||
| "curved_pipe_outer_2d.asc") | ||
| pipe_channel_file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", | ||
| "curved_pipe_channel_2d.asc") | ||
|
|
||
| pipe_outer = solid_from_geometry_file(pipe_outer_file; particle_spacing, | ||
| density=fluid_density) | ||
| pipe_channel = load_geometry(pipe_channel_file) | ||
|
|
||
| pipe_setup = (; wall=setdiff(pipe_outer.solid, pipe_channel), | ||
| outer_geometry=pipe_outer.geometry, | ||
| channel_geometry=pipe_channel) | ||
|
svchb marked this conversation as resolved.
Resolved
|
||
|
|
||
| p_pipe = plot(pipe_setup.wall, label="wall", size=(450, 450), showaxis=false, | ||
| xlims=(-0.03, 1.23), ylims=(-0.03, 1.23)) | ||
| plot!(p_pipe, dpi=300) # hide | ||
| savefig(p_pipe, "tut_2d_geometry_pipe.png"); # hide | ||
| #  | ||
|
|
||
| # ### A dam-break basin with a coastline profile | ||
|
|
||
| # In the second setup, one 2D geometry file defines the coastline wall: | ||
| # the beach profile, a finite wall thickness below it, and the seawall on the right. | ||
| coast_file = pkgdir(TrixiParticles, "examples", "preprocessing", "data", | ||
| "coastline_profile_2d.asc") | ||
| coast = solid_from_geometry_file(coast_file; particle_spacing, density=fluid_density) | ||
|
svchb marked this conversation as resolved.
Resolved
|
||
| nothing # hide | ||
|
|
||
| # The geometry file defines the coastline bed and right wall as a solid region. | ||
| # We add the left wall as a rectangular particle block and place a rectangular | ||
| # dam-break water column beside it. | ||
| left_wall = RectangularShape(particle_spacing, (5, 50), (0.0, -0.12), | ||
| density=fluid_density) | ||
| reservoir = RectangularShape(particle_spacing, (28, 42), (0.15, 0.03), | ||
| acceleration=(0.0, -gravity), | ||
| state_equation=state_equation) | ||
| coast_setup = (; geometry=coast.geometry, | ||
| wall=union(coast.solid, left_wall), | ||
| fluid=setdiff(reservoir, coast.geometry)) | ||
|
|
||
| p_coast = plot(coast_setup.fluid, coast_setup.wall, labels=["fluid" "wall"], | ||
| size=(700, 360), showaxis=false, xlims=(0.0, 2.75), ylims=(-0.15, 1.35)) | ||
| plot!(p_coast, dpi=200) # hide | ||
| savefig(p_coast, "tut_2d_geometry_coast.png"); # hide | ||
| #  | ||
|
|
||
| # ## Running a coastline simulation | ||
|
|
||
| # We continue with the coastline setup using the systems, semidiscretization, and time | ||
| # integration described in [Setting up your simulation from scratch](@ref tut_setup). | ||
| setup = coast_setup | ||
| tspan = (0.0, 1.0) | ||
|
|
||
| smoothing_length = 1.2 * particle_spacing | ||
| smoothing_kernel = SchoenbergCubicSplineKernel{2}() | ||
| viscosity = ArtificialViscosityMonaghan(alpha=0.02, beta=0.0) | ||
|
|
||
| fluid_density_calculator = ContinuityDensity() | ||
| density_diffusion = DensityDiffusionMolteniColagrossi(delta=0.1) | ||
|
|
||
| fluid_system = WeaklyCompressibleSPHSystem(setup.fluid; | ||
| density_calculator=fluid_density_calculator, | ||
| state_equation, smoothing_kernel, | ||
| smoothing_length, viscosity=viscosity, | ||
| density_diffusion=density_diffusion, | ||
| acceleration=(0.0, -gravity)) | ||
|
|
||
| boundary_model = BoundaryModelDummyParticles(setup.wall.density, setup.wall.mass, | ||
| state_equation=state_equation, | ||
| AdamiPressureExtrapolation(), | ||
| smoothing_kernel, smoothing_length) | ||
| boundary_system = WallBoundarySystem(setup.wall, boundary_model) | ||
|
|
||
| semi = Semidiscretization(fluid_system, boundary_system) | ||
| ode = semidiscretize(semi, tspan) | ||
|
|
||
| callbacks = CallbackSet(InfoCallback(interval=10)) | ||
|
|
||
| sol = solve(ode, RDPK3SpFSAL35(), save_everystep=false, callback=callbacks) | ||
|
|
||
| plot(sol, title="Coastline dam break at t = $(sol.t[end])", | ||
| size=(700, 360), showaxis=false, legend=:topleft) | ||
| plot!(dpi=200) # hide | ||
| savefig("tut_2d_geometry_solution.png"); # hide | ||
| #  | ||
|
|
||
| # For more accurate body-fitted particles around sharper features, you can also | ||
| # apply the [particle packing workflow](@ref tut_packing) to the 2D geometry files | ||
| # before starting the simulation. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # ASCII | ||
| 0.15 -0.12 0 | ||
| 2.68 -0.12 0 | ||
| 2.68 1.08 0 | ||
| 2.62 0.66 0 | ||
| 2.53 0.52 0 | ||
| 2.42 0.40 0 | ||
| 2.30 0.42 0 | ||
| 2.18 0.33 0 | ||
| 2.05 0.24 0 | ||
| 1.92 0.26 0 | ||
| 1.78 0.18 0 | ||
| 1.62 0.11 0 | ||
| 1.46 0.14 0 | ||
| 1.28 0.06 0 | ||
| 1.05 0.02 0 | ||
| 0.82 0.05 0 | ||
| 0.55 0.03 0 | ||
| 0.15 0.03 0 | ||
| 0.15 -0.12 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # ASCII | ||
| 0.00 0.12 0 | ||
| 0.60 0.12 0 | ||
| 0.72423 0.13646 0 | ||
| 0.84000 0.18431 0 | ||
| 0.93941 0.26059 0 | ||
| 1.01569 0.36000 0 | ||
| 1.06354 0.47577 0 | ||
| 1.08 0.60 0 | ||
| 1.08 1.20 0 | ||
| 0.72 1.20 0 | ||
| 0.72 0.60 0 | ||
| 0.71591 0.56894 0 | ||
| 0.70392 0.54000 0 | ||
| 0.68485 0.51515 0 | ||
| 0.66000 0.49608 0 | ||
| 0.63106 0.48409 0 | ||
| 0.60 0.48 0 | ||
| 0.00 0.48 0 | ||
| 0.00 0.12 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # ASCII | ||
| 0.00 0.00 0 | ||
| 0.60 0.00 0 | ||
| 0.75529 0.02044 0 | ||
| 0.90000 0.08038 0 | ||
| 1.02426 0.17574 0 | ||
| 1.11962 0.30000 0 | ||
| 1.17956 0.44471 0 | ||
| 1.20 0.60 0 | ||
| 1.20 1.20 0 | ||
| 0.60 1.20 0 | ||
| 0.60 0.60 0 | ||
| 0.00 0.60 0 | ||
| 0.00 0.00 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.