Skip to content

Commit

Permalink
Fix docs and compile docs in CI (#241)
Browse files Browse the repository at this point in the history
* Fix docs

* Add docs for `InitialCondition`

* Compile docs automatically in CI

* Fix setup docs

* Fix CI

* Fix CI

* Fix NHS in docs

* Add examples for initial condition
  • Loading branch information
efaulhaber authored Oct 17, 2023
1 parent 83000d8 commit b6f8710
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ jobs:
files: lcov.info
fail_ci_if_error: true
flags: unit
- name: Compile docs
run: |
julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
julia --project=docs --color=yes docs/make.jl
- name: Run example tests
uses: julia-actions/julia-runtest@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
TrixiParticles = "66699cd8-9c01-4e9d-a059-b96c86d16b3a"
28 changes: 8 additions & 20 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ Modules = [TrixiParticles]
Pages = [joinpath("general", "initial_condition.jl")]
```

### File neighborhood_search.jl
```@autodocs
Modules = [TrixiParticles]
Pages = [joinpath("general", "neighborhood_search.jl")]
```

### File semidiscretization.jl
```@autodocs
Modules = [TrixiParticles]
Expand All @@ -39,6 +33,13 @@ Modules = [TrixiParticles]
Pages = [joinpath("general", "smoothing_kernels.jl")]
```

## Neighborhood Search

```@autodocs
Modules = [TrixiParticles]
Pages = map(file -> joinpath("neighborhood_search", file), readdir(joinpath("..", "src", "neighborhood_search")))
```

## Schemes

### Boundary
Expand Down Expand Up @@ -104,22 +105,9 @@ Pages = [joinpath("schemes", "solid", "total_lagrangian_sph", "penalty_force.jl"

## Setups

### File rectangular_tank.jl
```@autodocs
Modules = [TrixiParticles]
Pages = [joinpath("setups", "rectangular_tank.jl")]
```

### File rectangular_shape.jl
```@autodocs
Modules = [TrixiParticles]
Pages = [joinpath("setups", "rectangular_shape.jl")]
```

### File circular_shape.jl
```@autodocs
Modules = [TrixiParticles]
Pages = [joinpath("setups", "circular_shape.jl")]
Pages = map(file -> joinpath("setups", file), readdir(joinpath("..", "src", "setups")))
```

## Util
Expand Down
6 changes: 3 additions & 3 deletions src/callbacks/density_reinit.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
DensityReinitializationCallback(; interval::Integer=0, dt=0.0)
Callback to reinitialize the density field when using [ContinuityDensity](@ref).
Callback to reinitialize the density field when using [`ContinuityDensity`](@ref).
# Keywords
- `interval=0`: Reinitialize the density every `interval` time steps.
Expand All @@ -10,8 +10,8 @@ Callback to reinitialize the density field when using [ContinuityDensity](@ref).
- `reinit_initial_solution`: Reinitialize the initial solution (default=false)
## References:
- Panizzo, Andrea, Giovanni Cuomo, and Robert A. Dalrymple. "3D-SPH simulation of landslide generated waves."
In: Coastal Engineering 2006: (In 5 Volumes). 2007. 1503-1515.
[doi:10.1142/9789812709554_0128](https://doi.org/10.1142/9789812709554_0128)
In: Coastal Engineering 2006 (2007), pages 1503-1515.
[doi: 10.1142/9789812709554_0128](https://doi.org/10.1142/9789812709554_0128)
"""
mutable struct DensityReinitializationCallback{I}
interval::I
Expand Down
58 changes: 58 additions & 0 deletions src/general/initial_condition.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
@doc raw"""
InitialCondition(coordinates, velocities, masses, densities; pressure=0.0,
particle_spacing=-1.0)
Struct to hold the initial configuration of the particles.
The following setups return `InitialCondition`s for commonly used setups:
- [`RectangularShape`](@ref)
- [`SphereShape`](@ref)
- [`RectangularTank`](@ref)
`InitialCondition`s support the set operations `union`, `setdiff` and `intersect` in order
to build more complex geometries.
# Arguments
- `coordinates`: An array where the $i$-th column holds the coordinates of particle $i$.
- `velocities`: An array where the $i$-th column holds the velocity of particle $i$.
- `masses`: A vector holding the mass of each particle.
- `densities`: A vector holding the density of each particle.
# Keywords
- `pressure`: Either a vector of pressure values of each particle or a number for a constant
pressure over all particles. This is optional and only needed when using
the [`EntropicallyDampedSPHSystem`](@ref).
- `particle_spacing`: The spacing between the particles. This is a number, as the spacing
is assumed to be uniform. This is only needed when using
set operations on the `InitialCondition`.
# Examples
```julia
# Rectangle filled with particles
initial_condition = RectangularShape(0.1, (3, 4), (-1.0, 1.0), 1.0)
# Two spheres in one initial condition
initial_condition = union(SphereShape(0.15, 0.5, (-1.0, 1.0), 1.0),
SphereShape(0.15, 0.2, (0.0, 1.0), 1.0))
# Rectangle with a spherical hole
shape1 = RectangularShape(0.1, (16, 13), (-0.8, 0.0), 1.0)
shape2 = SphereShape(0.1, 0.35, (0.0, 0.6), 1.0, sphere_type=RoundSphere())
initial_condition = setdiff(shape1, shape2)
# Intersect of a rectangle with a sphere. Note that this keeps the particles of the
# rectangle that are in the intersect, while `intersect(shape2, shape1)` would consist of
# the particles of the sphere that are in the intersect.
shape1 = RectangularShape(0.1, (16, 13), (-0.8, 0.0), 1.0)
shape2 = SphereShape(0.1, 0.35, (0.0, 0.6), 1.0, sphere_type=RoundSphere())
initial_condition = intersect(shape1, shape2)
# Build `InitialCondition` manually
coordinates = [0.0 1.0 1.0
0.0 0.0 1.0]
velocities = zero(coordinates)
masses = ones(3)
densities = 1000 * ones(3)
initial_condition = InitialCondition(coordinates, velocities, masses, densities)
```
"""
struct InitialCondition{ELTYPE}
particle_spacing :: ELTYPE
coordinates :: Array{ELTYPE, 2}
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/boundary/dummy_particles/dummy_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Boundaries modeled as dummy particles, which are treated like fluid particles,
but their positions and velocities are not evolved in time. Since the force towards the fluid
should not change with the material density when used with a `TotalLagrangianSPHSystem`, the
should not change with the material density when used with a [`TotalLagrangianSPHSystem`](@ref), the
dummy particles need to have a mass corresponding to the fluid's rest density, which we call
"hydrodynamic mass", as opposed to mass corresponding to the material density of a
`TotalLagrangianSPHSystem`.
[`TotalLagrangianSPHSystem`](@ref).
Here, `initial_density` and `hydrodynamic_mass` are vectors that contains the initial density
and the hydrodynamic mass respectively for each boundary particle.
Expand Down
4 changes: 2 additions & 2 deletions src/schemes/fluid/weakly_compressible_sph/state_equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ where ``c`` denotes the speed of sound, ``\rho`` the density, ``p`` the pressure
at the reference density, and ``p_{\text{background}}`` the atmospheric or
background pressure (to be used with free surfaces).
When using [`SummationDensity`](@ref) (or [DensityReinitializationCallback](@ref))
When using [`SummationDensity`](@ref) (or [`DensityReinitializationCallback`](@ref))
and free surfaces, initializing particles with equal spacing will cause underestimated
density and therefore strong attractive forces between particles at the free surface.
Setting `clip_negative_pressure=true` can avoid this.
Expand Down Expand Up @@ -64,7 +64,7 @@ background pressure (to be used with free surfaces).
For water, an average value of ``\gamma = 7.15`` is usually used (Cole 1948, p. 39).
When using [`SummationDensity`](@ref) (or [DensityReinitializationCallback](@ref))
When using [`SummationDensity`](@ref) (or [`DensityReinitializationCallback`](@ref))
and free surfaces, initializing particles with equal spacing will cause underestimated
density and therefore strong attractive forces between particles at the free surface.
Setting `clip_negative_pressure=true` can avoid this.
Expand Down
2 changes: 1 addition & 1 deletion src/setups/rectangular_shape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Rectangular shape filled with particles. Returns an [`InitialCondition`](@ref).
- `density`: Initial density of particles.
# Keywords
- `tlsph`: With the [TotalLagrangianSPHSystem](@ref), particles need to be placed
- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed
on the boundary of the shape and not one particle radius away, as for fluids.
When `tlsph=true`, particles will be placed on the boundary of the shape.
- `init_velocity`: The initial velocity of the fluid particles as `(vel_x, vel_y)` (or `(vel_x, vel_y, vel_z)` in 3D).
Expand Down
12 changes: 7 additions & 5 deletions src/setups/sphere_shape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ coordinate directions as `cutout_min` and `cutout_max`.
cut out of the sphere.
- `cutout_max`: Corner in positive coordinate directions of a cuboid that is to be
cut out of the sphere.
- `tlsph`: With the [TotalLagrangianSPHSystem](@ref), particles need to be placed
- `tlsph`: With the [`TotalLagrangianSPHSystem`](@ref), particles need to be placed
on the boundary of the shape and not one particle radius away, as for fluids.
When `tlsph=true`, particles will be placed on the boundary of the shape.
- `init_velocity`: Initial velocity vector to be assigned to each particle.
Expand All @@ -49,16 +49,13 @@ SphereShape(0.1, 0.5, (0.2, 0.4), 1000.0, sphere_type=RoundSphere())
# Hollow circle with ~3 layers, outer radius 0.5, center in (0.2, 0.4) and a particle
# spacing of 0.1.
```julia
SphereShape(0.1, 0.5, (0.2, 0.4), 1000.0, n_layers=3)
```
# Same as before, but perfectly round
SphereShape(0.1, 0.5, (0.2, 0.4), 1000.0, n_layers=3, sphere_type=RoundSphere())
# Hollow circle with 3 layers, inner radius 0.5, center in (0.2, 0.4) and a particle spacing
# of 0.1.
```julia
SphereShape(0.1, 0.5, (0.2, 0.4), 1000.0, n_layers=3, layer_outwards=true)
# Filled circle with radius 0.1, center in (0.0, 0.0), particle spacing 0.1, but the
Expand All @@ -71,7 +68,6 @@ SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0)
# Same as before, but perfectly round
SphereShape(0.1, 0.5, (0.2, 0.4, 0.3), 1000.0, sphere_type=RoundSphere())
```
````
"""
function SphereShape(particle_spacing, radius, center_position, density;
sphere_type=VoxelSphere(), n_layers=-1, layer_outwards=false,
Expand Down Expand Up @@ -124,6 +120,9 @@ with a regular inner structure but corners on the surface.
Essentially, a grid of particles is generated and all particles outside the sphere are removed.
The resulting sphere will have a perfect inner structure, but is not perfectly round,
as it will have corners (like a sphere in Minecraft).
!!! note "Usage"
See [`SphereShape`](@ref) on how to use this.
"""
struct VoxelSphere end

Expand All @@ -132,6 +131,9 @@ struct VoxelSphere end
Construct a sphere by nesting perfectly round concentric spheres.
The resulting ball will be perfectly round, but will not have a regular inner structure.
!!! note "Usage"
See [`SphereShape`](@ref) on how to use this.
"""
struct RoundSphere end

Expand Down

0 comments on commit b6f8710

Please sign in to comment.