From a31b02ab675416e080e0cd7ebe6c561adc4e4278 Mon Sep 17 00:00:00 2001 From: LasNikas Date: Mon, 16 Oct 2023 22:32:35 +0200 Subject: [PATCH 1/4] 1D support --- src/general/smoothing_kernels.jl | 2 ++ src/neighborhood_search/grid_nhs.jl | 11 +++++++++++ src/setups/rectangular_shape.jl | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/general/smoothing_kernels.jl b/src/general/smoothing_kernels.jl index 53097b615..0d8a216d1 100644 --- a/src/general/smoothing_kernels.jl +++ b/src/general/smoothing_kernels.jl @@ -104,6 +104,7 @@ end @inline compact_support(::SchoenbergCubicSplineKernel, h) = 2 * h +@inline normalization_factor(::SchoenbergCubicSplineKernel{1}, h) = 2 / (3 * h) @inline normalization_factor(::SchoenbergCubicSplineKernel{2}, h) = 10 / (7 * pi * h^2) @inline normalization_factor(::SchoenbergCubicSplineKernel{3}, h) = 1 / (pi * h^3) @@ -306,5 +307,6 @@ end @inline compact_support(::SchoenbergQuinticSplineKernel, h) = 3 * h +@inline normalization_factor(::SchoenbergQuinticSplineKernel{1}, h) = 1 / (120 * h) @inline normalization_factor(::SchoenbergQuinticSplineKernel{2}, h) = 7 / (478 * pi * h^2) @inline normalization_factor(::SchoenbergQuinticSplineKernel{3}, h) = 1 / (120 * pi * h^3) diff --git a/src/neighborhood_search/grid_nhs.jl b/src/neighborhood_search/grid_nhs.jl index 3a4ce3dd2..e19e26251 100644 --- a/src/neighborhood_search/grid_nhs.jl +++ b/src/neighborhood_search/grid_nhs.jl @@ -208,6 +208,17 @@ end end end +@inline function eachneighbor(coords, neighborhood_search::GridNeighborhoodSearch{1}) + cell = cell_coords(coords, neighborhood_search) + x = cell[1] + # Generator of all neighboring cells to consider + neighboring_cells = ((x + i) for i in -1:1) + + # Merge all lists of particles in the neighboring cells into one iterator + Iterators.flatten(particles_in_cell(cell, neighborhood_search) + for cell in neighboring_cells) +end + @inline function eachneighbor(coords, neighborhood_search::GridNeighborhoodSearch{2}) cell = cell_coords(coords, neighborhood_search) x, y = cell diff --git a/src/setups/rectangular_shape.jl b/src/setups/rectangular_shape.jl index dc63f4592..5692a64b5 100644 --- a/src/setups/rectangular_shape.jl +++ b/src/setups/rectangular_shape.jl @@ -82,6 +82,24 @@ function rectangular_shape_coords(particle_spacing, n_particles_per_dimension, return coordinates end +# 1D +function initialize_rectangular!(coordinates, particle_spacing, + min_coordinates, + n_particles_per_dimension::NTuple{1}, loop_order) + n_particles_x = n_particles_per_dimension[1] + particle = 0 + + if loop_order === :x_first + for x in 1:n_particles_x + particle += 1 + fill_coordinates!(coordinates, particle, min_coordinates, x, particle_spacing) + end + + else + throw(ArgumentError("$loop_order is not a valid loop order. Possible values are :x_first")) + end +end + # 2D function initialize_rectangular!(coordinates, particle_spacing, min_coordinates, @@ -141,6 +159,13 @@ function initialize_rectangular!(coordinates, particle_spacing, end end +@inline function fill_coordinates!(coordinates, particle, + min_coordinates, x, particle_spacing) + # The first particle starts at a distance `0.5particle_spacing` from `min_coordinates` + # in each dimension. + coordinates[1, particle] = min_coordinates[1] + (x - 0.5) * particle_spacing +end + @inline function fill_coordinates!(coordinates, particle, min_coordinates, x, y, particle_spacing) # The first particle starts at a distance `0.5particle_spacing` from `min_coordinates` From 1daf38e4611d502d2a44735d376598b82f2855a9 Mon Sep 17 00:00:00 2001 From: LasNikas Date: Sun, 22 Oct 2023 13:45:04 +0200 Subject: [PATCH 2/4] modify docs Make the docs more readable by adding a table for the kernel, which we provide. Thus, we can get rid of repetitions. --- src/general/smoothing_kernels.jl | 182 +++++++++++++------------------ 1 file changed, 74 insertions(+), 108 deletions(-) diff --git a/src/general/smoothing_kernels.jl b/src/general/smoothing_kernels.jl index 0d8a216d1..fe6b01bc3 100644 --- a/src/general/smoothing_kernels.jl +++ b/src/general/smoothing_kernels.jl @@ -1,3 +1,67 @@ +@doc raw""" + SmoothingKernel{NDIMS}() + +We provide three kernel functions, generated as the Fourier transform +```math + M_n(x, h) = \frac{1}{2 \pi}\int_{-\infty}^{\infty} + \left[ \frac{sin(k h /2)}{k h /2}\right]^n cos(k x) \mathrm{d}k \: . +``` +| B-Spline | | compact support | +| -------- | :---------------------------------------- | ----------------- | +| $M_4$ | [`SchoenbergCubicSplineKernel`](@ref) | $[0, 2h]$ | +| $M_5$ | [`SchoenbergQuarticSplineKernel`](@ref) | $[0, 2.5h]$ | +| $M_6$ | [`SchoenbergQuinticSplineKernel`](@ref) | $[0, 3h]$ | + +In general, the Kernels are defined as +```math + W(\Vert r_a - r_b \Vert, h) = \frac{1}{h^d} w(q) \: , +``` +where $h$ is the smoothing length, $d$ refers to the number of spatial dimensions and +$q=\Vert r_a - r_b \Vert/h$. + +For an overview of Schoenberg cubic ($M_4$), quartic ($M_5$) and quintic ($M_6$) spline +kernels including normalization factors, see (Price, 2012). +For an analytic formula for higher order kernels, see (Monaghan, 1985). + +!!! note "Usage" + The kernel can be called as + ``` + TrixiParticles.kernel(::SmoothingKernel{NDIMS}, r, h) + ``` + The length of the compact support can be obtained as + ``` + TrixiParticles.compact_support(::SmoothingKernel{NDIMS}, h) + ``` + + Note that ``r`` has to be a scalar, so in the context of SPH, the kernel + should be used as + ```math + W(\Vert r_a - r_b \Vert, h). + ``` + + The gradient required in SPH, + ```math + \frac{\partial}{\partial r_a} W(\Vert r_a - r_b \Vert, h) + ``` + can be called as + ``` + TrixiParticles.kernel_grad(kernel, pos_diff, distance, h) + + ``` + where `pos_diff` is $r_a - r_b$ and `distance` is $\Vert r_a - r_b \Vert$. + +## References: +- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". + In: Journal of Computational Physics 231.3 (2012), pages 759-794. + [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) +- Joseph J. Monaghan. "Particle methods for hydrodynamics". + In: Computer Physics Reports 3.2 (1985), pages 71–124. + [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) +- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. + Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." + In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. + [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) +""" abstract type SmoothingKernel{NDIMS} end @inline Base.ndims(::SmoothingKernel{NDIMS}) where {NDIMS} = NDIMS @@ -21,51 +85,18 @@ end Cubic spline kernel by Schoenberg (Schoenberg, 1946), given by ```math -W(r, h) = \frac{1}{h^d} w(r/h) -``` -with -```math w(q) = \sigma \begin{cases} \frac{1}{4} (2 - q)^3 - (1 - q)^3 & \text{if } 0 \leq q < 1, \\ \frac{1}{4} (2 - q)^3 & \text{if } 1 \leq q < 2, \\ 0 & \text{if } q \geq 2, \\ \end{cases} ``` -where ``d`` is the number of dimensions and ``\sigma = 17/(7\pi)`` -in two dimensions or ``\sigma = 1/\pi`` in three dimensions is a normalization factor. +where ``\sigma`` is a normalisation constant given by +$\sigma =[\frac{2}{3}, \frac{10}{7 \pi}, \frac{1}{\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 2h]``. -For an overview of Schoenberg cubic, quartic and quintic spline kernels -including normalization factors, see (Price, 2012). -For an analytic formula for higher order kernels, see (Monaghan, 1985). - -!!! note "Usage" - The kernel can be called as `TrixiParticles.kernel(::SchoenbergCubicSplineKernel, r, h)`. - The length of the compact support can be obtained as - `TrixiParticles.compact_support(::SchoenbergCubicSplineKernel, h)`. - - Note that ``r`` has to be a scalar, so in the context of SPH, the kernel - should be used as ``W(\Vert r_a - r_b \Vert, h)``. - The gradient required in SPH, - ```math - \frac{\partial}{\partial r_a} W(\Vert r_a - r_b \Vert, h) - ``` - can be called as - `TrixiParticles.kernel_grad(kernel, pos_diff, distance, h)`, - where `pos_diff` is $r_a - r_b$ and `distance` is $\Vert r_a - r_b \Vert$. - -## References: -- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". - In: Journal of Computational Physics 231.3 (2012), pages 759-794. - [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) -- Joseph J. Monaghan. "Particle methods for hydrodynamics". - In: Computer Physics Reports 3.2 (1985), pages 71–124. - [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) -- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. - Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." - In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. - [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) +For general information see [`SmoothingKernel`](@ref). """ struct SchoenbergCubicSplineKernel{NDIMS} <: SmoothingKernel{NDIMS} end @@ -113,10 +144,6 @@ end Quartic spline kernel by Schoenberg (Schoenberg, 1946), given by ```math -W(r, h) = \frac{1}{h^d} w(r/h) -``` -with -```math w(q) = \sigma \begin{cases} \left(5/2 - q \right)^4 - 5\left(3/2 - q \right)^4 + 10\left(1/2 - q \right)^4 & \text{if } 0 \leq q < \frac{1}{2}, \\ @@ -126,41 +153,12 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq \frac{5}{2}, \end{cases} ``` -where ``d`` is the number of dimensions and ``\sigma = 96/(1199\pi)`` -in two dimensions or ``\sigma = 1/(20\pi)`` in three dimensions is a normalization factor. +where ``\sigma`` is a normalisation constant given by +$\sigma =[\frac{1}{24}, \frac{96}{1199 \pi}, \frac{1}{20\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 2.5h]``. -For an overview of Schoenberg cubic, quartic and quintic spline kernels -including normalization factors, see (Price, 2012). -For an analytic formula for higher order kernels, see (Monaghan, 1985). - -!!! note "Usage" - The kernel can be called as `TrixiParticles.kernel(::SchoenbergQuarticSplineKernel, r, h)`. - The length of the compact support can be obtained as - `TrixiParticles.compact_support(::SchoenbergQuarticSplineKernel, h)`. - - Note that ``r`` has to be a scalar, so in the context of SPH, the kernel - should be used as ``W(\Vert r_a - r_b \Vert, h)``. - The gradient required in SPH, - ```math - \frac{\partial}{\partial r_a} W(\Vert r_a - r_b \Vert, h) - ``` - can be called as - `TrixiParticles.kernel_grad(kernel, pos_diff, distance, h)`, - where `pos_diff` is $r_a - r_b$ and `distance` is $\Vert r_a - r_b \Vert$. - -## References: -- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". - In: Journal of Computational Physics 231.3 (2012), pages 759-794. - [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) -- Joseph J. Monaghan. "Particle methods for hydrodynamics". - In: Computer Physics Reports 3.2 (1985), pages 71–124. - [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) -- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. - Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." - In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. - [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) +For general information see [`SmoothingKernel`](@ref). """ struct SchoenbergQuarticSplineKernel{NDIMS} <: SmoothingKernel{NDIMS} end @@ -207,6 +205,7 @@ end @inline compact_support(::SchoenbergQuarticSplineKernel, h) = 2.5 * h +@inline normalization_factor(::SchoenbergQuarticSplineKernel{1}, h) = 1 / (24 * h) @inline normalization_factor(::SchoenbergQuarticSplineKernel{2}, h) = 96 / (1199 * pi * h^2) @inline normalization_factor(::SchoenbergQuarticSplineKernel{3}, h) = 1 / (20 * pi * h^3) @@ -215,10 +214,6 @@ end Quintic spline kernel by Schoenberg (Schoenberg, 1946), given by ```math -W(r, h) = \frac{1}{h^d} w(r/h) -``` -with -```math w(q) = \sigma \begin{cases} (3 - q)^5 - 6(2 - q)^5 + 15(1 - q)^5 & \text{if } 0 \leq q < 1, \\ (3 - q)^5 - 6(2 - q)^5 & \text{if } 1 \leq q < 2, \\ @@ -226,41 +221,12 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq 3, \end{cases} ``` -where ``d`` is the number of dimensions and ``\sigma = 7/(478\pi)`` -in two dimensions or ``\sigma = 1/(120\pi)`` in three dimensions is a normalization factor. +where ``\sigma`` is a normalisation constant given by +$\sigma =[\frac{1}{120}, \frac{7}{478 \pi}, \frac{1}{120\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 3h]``. -For an overview of Schoenberg cubic, quartic and quintic spline kernels -including normalization factors, see (Price, 2012). -For an analytic formula for higher order kernels, see (Monaghan, 1985). - -!!! note "Usage" - The kernel can be called as `TrixiParticles.kernel(::SchoenbergQuinticSplineKernel, r, h)`. - The length of the compact support can be obtained as - `TrixiParticles.compact_support(::SchoenbergQuinticSplineKernel, h)`. - - Note that ``r`` has to be a scalar, so in the context of SPH, the kernel - should be used as ``W(\Vert r_a - r_b \Vert, h)``. - The gradient required in SPH, - ```math - \frac{\partial}{\partial r_a} W(\Vert r_a - r_b \Vert, h) - ``` - can be called as - `TrixiParticles.kernel_grad(kernel, pos_diff, distance, h)`, - where `pos_diff` is $r_a - r_b$ and `distance` is $\Vert r_a - r_b \Vert$. - -## References: -- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". - In: Journal of Computational Physics 231.3 (2012), pages 759-794. - [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) -- Joseph J. Monaghan. "Particle methods for hydrodynamics". - In: Computer Physics Reports 3.2 (1985), pages 71–124. - [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) -- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. - Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." - In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. - [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) +For general information see [`SmoothingKernel`](@ref). """ struct SchoenbergQuinticSplineKernel{NDIMS} <: SmoothingKernel{NDIMS} end From a4aa86d5dc1f0956bfcec40e29340b872c27ca76 Mon Sep 17 00:00:00 2001 From: LasNikas Date: Thu, 26 Oct 2023 22:53:09 +0200 Subject: [PATCH 3/4] implement suggestions --- src/general/smoothing_kernels.jl | 113 ++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 40 deletions(-) diff --git a/src/general/smoothing_kernels.jl b/src/general/smoothing_kernels.jl index 03b0f3921..cc59d6df7 100644 --- a/src/general/smoothing_kernels.jl +++ b/src/general/smoothing_kernels.jl @@ -1,27 +1,16 @@ @doc raw""" - SmoothingKernel{NDIMS}() + SmoothingKernel{NDIMS} -We provide three kernel functions, generated as the Fourier transform -```math - M_n(x, h) = \frac{1}{2 \pi}\int_{-\infty}^{\infty} - \left[ \frac{sin(k h /2)}{k h /2}\right]^n cos(k x) \mathrm{d}k \: . -``` -| B-Spline | | compact support | -| -------- | :---------------------------------------- | ----------------- | -| $M_4$ | [`SchoenbergCubicSplineKernel`](@ref) | $[0, 2h]$ | -| $M_5$ | [`SchoenbergQuarticSplineKernel`](@ref) | $[0, 2.5h]$ | -| $M_6$ | [`SchoenbergQuinticSplineKernel`](@ref) | $[0, 3h]$ | +An abstract supertype all smoothing kernels. The type parameter `NDIMS` encodes the number +of dimensions. -In general, the Kernels are defined as -```math - W(\Vert r_a - r_b \Vert, h) = \frac{1}{h^d} w(q) \: , -``` -where $h$ is the smoothing length, $d$ refers to the number of spatial dimensions and -$q=\Vert r_a - r_b \Vert/h$. +We provide the following smoothing kernels: -For an overview of Schoenberg cubic ($M_4$), quartic ($M_5$) and quintic ($M_6$) spline -kernels including normalization factors, see (Price, 2012). -For an analytic formula for higher order kernels, see (Monaghan, 1985). +| Smoothing Kernel | Compact Support | +| :----------------------------------------- | :---------------- | +| [`SchoenbergCubicSplineKernel`](@ref) | $[0, 2h]$ | +| [`SchoenbergQuarticSplineKernel`](@ref) | $[0, 2.5h]$ | +| [`SchoenbergQuinticSplineKernel`](@ref) | $[0, 3h]$ | !!! note "Usage" The kernel can be called as @@ -41,26 +30,13 @@ For an analytic formula for higher order kernels, see (Monaghan, 1985). The gradient required in SPH, ```math - \frac{\partial}{\partial r_a} W(\Vert r_a - r_b \Vert, h) + \nabla_{r_a} W(\Vert r_a - r_b \Vert, h) ``` can be called as ``` TrixiParticles.kernel_grad(kernel, pos_diff, distance, h) - ``` where `pos_diff` is $r_a - r_b$ and `distance` is $\Vert r_a - r_b \Vert$. - -## References: -- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". - In: Journal of Computational Physics 231.3 (2012), pages 759-794. - [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) -- Joseph J. Monaghan. "Particle methods for hydrodynamics". - In: Computer Physics Reports 3.2 (1985), pages 71–124. - [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) -- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. - Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." - In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. - [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) """ abstract type SmoothingKernel{NDIMS} end @inline Base.ndims(::SmoothingKernel{NDIMS}) where {NDIMS} = NDIMS @@ -84,6 +60,10 @@ end SchoenbergCubicSplineKernel{NDIMS}() Cubic spline kernel by Schoenberg (Schoenberg, 1946), given by +```math + W(r, h) = \frac{1}{h^d} w(r/h) +``` +with ```math w(q) = \sigma \begin{cases} \frac{1}{4} (2 - q)^3 - (1 - q)^3 & \text{if } 0 \leq q < 1, \\ @@ -91,12 +71,27 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq 2, \\ \end{cases} ``` -where ``\sigma`` is a normalisation constant given by +where ``d`` is the number of dimensions and ``\sigma`` is a normalisation constant given by $\sigma =[\frac{2}{3}, \frac{10}{7 \pi}, \frac{1}{\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 2h]``. -For general information see [`SmoothingKernel`](@ref). +For an overview of Schoenberg cubic, quartic and quintic spline kernels including +normalization factors, see (Price, 2012). +For an analytic formula for higher order Schoenberg kernels, see (Monaghan, 1985). +For general information and usage see [`SmoothingKernel`](@ref). + +## References: +- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". + In: Journal of Computational Physics 231.3 (2012), pages 759-794. + [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) +- Joseph J. Monaghan. "Particle methods for hydrodynamics". + In: Computer Physics Reports 3.2 (1985), pages 71–124. + [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) +- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. + Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." + In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. + [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) """ struct SchoenbergCubicSplineKernel{NDIMS} <: SmoothingKernel{NDIMS} end @@ -143,6 +138,10 @@ end SchoenbergQuarticSplineKernel{NDIMS}() Quartic spline kernel by Schoenberg (Schoenberg, 1946), given by +```math + W(r, h) = \frac{1}{h^d} w(r/h) +``` +with ```math w(q) = \sigma \begin{cases} \left(5/2 - q \right)^4 - 5\left(3/2 - q \right)^4 @@ -153,12 +152,27 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq \frac{5}{2}, \end{cases} ``` -where ``\sigma`` is a normalisation constant given by +where ``d`` is the number of dimensions and ``\sigma`` is a normalisation constant given by $\sigma =[\frac{1}{24}, \frac{96}{1199 \pi}, \frac{1}{20\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 2.5h]``. -For general information see [`SmoothingKernel`](@ref). +For an overview of Schoenberg cubic, quartic and quintic spline kernels including +normalization factors, see (Price, 2012). +For an analytic formula for higher order Schoenberg kernels, see (Monaghan, 1985). +For general information and usage see [`SmoothingKernel`](@ref). + +## References: +- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". + In: Journal of Computational Physics 231.3 (2012), pages 759-794. + [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) +- Joseph J. Monaghan. "Particle methods for hydrodynamics". + In: Computer Physics Reports 3.2 (1985), pages 71–124. + [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) +- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. + Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." + In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. + [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) """ struct SchoenbergQuarticSplineKernel{NDIMS} <: SmoothingKernel{NDIMS} end @@ -218,6 +232,10 @@ end SchoenbergQuinticSplineKernel{NDIMS}() Quintic spline kernel by Schoenberg (Schoenberg, 1946), given by +```math + W(r, h) = \frac{1}{h^d} w(r/h) +``` +with ```math w(q) = \sigma \begin{cases} (3 - q)^5 - 6(2 - q)^5 + 15(1 - q)^5 & \text{if } 0 \leq q < 1, \\ @@ -226,12 +244,27 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq 3, \end{cases} ``` -where ``\sigma`` is a normalisation constant given by +where ``d`` is the number of dimensions and ``\sigma`` is a normalisation constant given by $\sigma =[\frac{1}{120}, \frac{7}{478 \pi}, \frac{1}{120\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 3h]``. -For general information see [`SmoothingKernel`](@ref). +For an overview of Schoenberg cubic, quartic and quintic spline kernels including +normalization factors, see (Price, 2012). +For an analytic formula for higher order Schoenberg kernels, see (Monaghan, 1985). +For general information and usage see [`SmoothingKernel`](@ref). + +## References: +- Daniel J. Price. "Smoothed particle hydrodynamics and magnetohydrodynamics". + In: Journal of Computational Physics 231.3 (2012), pages 759-794. + [doi: 10.1016/j.jcp.2010.12.011](https://doi.org/10.1016/j.jcp.2010.12.011) +- Joseph J. Monaghan. "Particle methods for hydrodynamics". + In: Computer Physics Reports 3.2 (1985), pages 71–124. + [doi: 10.1016/0167-7977(85)90010-3](https://doi.org/10.1016/0167-7977(85)90010-3) +- Isaac J. Schoenberg. "Contributions to the problem of approximation of equidistant data by analytic functions. + Part B. On the problem of osculatory interpolation. A second class of analytic approximation formulae." + In: Quarterly of Applied Mathematics 4.2 (1946), pages 112–141. + [doi: 10.1090/QAM/16705](https://doi.org/10.1090/QAM/16705) """ struct SchoenbergQuinticSplineKernel{NDIMS} <: SmoothingKernel{NDIMS} end From c2e52a12f1f2d931f93ce7574b43f9a3f4699f04 Mon Sep 17 00:00:00 2001 From: LasNikas Date: Mon, 30 Oct 2023 20:37:00 +0100 Subject: [PATCH 4/4] implement suggestion --- src/general/smoothing_kernels.jl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/general/smoothing_kernels.jl b/src/general/smoothing_kernels.jl index cc59d6df7..1f2aead24 100644 --- a/src/general/smoothing_kernels.jl +++ b/src/general/smoothing_kernels.jl @@ -1,13 +1,13 @@ @doc raw""" SmoothingKernel{NDIMS} -An abstract supertype all smoothing kernels. The type parameter `NDIMS` encodes the number +An abstract supertype of all smoothing kernels. The type parameter `NDIMS` encodes the number of dimensions. We provide the following smoothing kernels: | Smoothing Kernel | Compact Support | -| :----------------------------------------- | :---------------- | +| :---------------------------------------- | :---------------- | | [`SchoenbergCubicSplineKernel`](@ref) | $[0, 2h]$ | | [`SchoenbergQuarticSplineKernel`](@ref) | $[0, 2.5h]$ | | [`SchoenbergQuinticSplineKernel`](@ref) | $[0, 3h]$ | @@ -39,6 +39,7 @@ We provide the following smoothing kernels: where `pos_diff` is $r_a - r_b$ and `distance` is $\Vert r_a - r_b \Vert$. """ abstract type SmoothingKernel{NDIMS} end + @inline Base.ndims(::SmoothingKernel{NDIMS}) where {NDIMS} = NDIMS @inline function kernel_grad(kernel, pos_diff, distance, h) @@ -71,7 +72,7 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq 2, \\ \end{cases} ``` -where ``d`` is the number of dimensions and ``\sigma`` is a normalisation constant given by +where ``d`` is the number of dimensions and ``\sigma`` is a normalization constant given by $\sigma =[\frac{2}{3}, \frac{10}{7 \pi}, \frac{1}{\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 2h]``. @@ -130,7 +131,7 @@ end @inline compact_support(::SchoenbergCubicSplineKernel, h) = 2 * h -@inline normalization_factor(::SchoenbergCubicSplineKernel{1}, h) = 2 / (3 * h) +@inline normalization_factor(::SchoenbergCubicSplineKernel{1}, h) = 2 / 3h @inline normalization_factor(::SchoenbergCubicSplineKernel{2}, h) = 10 / (7 * pi * h^2) @inline normalization_factor(::SchoenbergCubicSplineKernel{3}, h) = 1 / (pi * h^3) @@ -152,7 +153,7 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq \frac{5}{2}, \end{cases} ``` -where ``d`` is the number of dimensions and ``\sigma`` is a normalisation constant given by +where ``d`` is the number of dimensions and ``\sigma`` is a normalization constant given by $\sigma =[\frac{1}{24}, \frac{96}{1199 \pi}, \frac{1}{20\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 2.5h]``. @@ -224,7 +225,7 @@ end @inline compact_support(::SchoenbergQuarticSplineKernel, h) = 2.5 * h -@inline normalization_factor(::SchoenbergQuarticSplineKernel{1}, h) = 1 / (24 * h) +@inline normalization_factor(::SchoenbergQuarticSplineKernel{1}, h) = 1 / 24h @inline normalization_factor(::SchoenbergQuarticSplineKernel{2}, h) = 96 / (1199 * pi * h^2) @inline normalization_factor(::SchoenbergQuarticSplineKernel{3}, h) = 1 / (20 * pi * h^3) @@ -244,7 +245,7 @@ w(q) = \sigma \begin{cases} 0 & \text{if } q \geq 3, \end{cases} ``` -where ``d`` is the number of dimensions and ``\sigma`` is a normalisation constant given by +where ``d`` is the number of dimensions and ``\sigma`` is a normalization constant given by $\sigma =[\frac{1}{120}, \frac{7}{478 \pi}, \frac{1}{120\pi}]$ in $[1, 2, 3]$ dimensions. This kernel function has a compact support of ``[0, 3h]``. @@ -311,6 +312,6 @@ end @inline compact_support(::SchoenbergQuinticSplineKernel, h) = 3 * h -@inline normalization_factor(::SchoenbergQuinticSplineKernel{1}, h) = 1 / (120 * h) +@inline normalization_factor(::SchoenbergQuinticSplineKernel{1}, h) = 1 / 120h @inline normalization_factor(::SchoenbergQuinticSplineKernel{2}, h) = 7 / (478 * pi * h^2) @inline normalization_factor(::SchoenbergQuinticSplineKernel{3}, h) = 1 / (120 * pi * h^3)