Skip to content

Commit

Permalink
Merge branch 'sensor_cb' of github.com:svchb/TrixiParticles.jl into s…
Browse files Browse the repository at this point in the history
…ensor_cb
  • Loading branch information
svchb committed Feb 7, 2024
2 parents 82f8d5e + f9693fc commit 7975a7b
Show file tree
Hide file tree
Showing 23 changed files with 303 additions and 338 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StrideArrays = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b"
ThreadingUtilities = "8290d209-cae3-49c0-8002-c8c24d57dab5"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
Expand All @@ -37,4 +38,5 @@ StaticArrays = "1"
StrideArrays = "0.1"
ThreadingUtilities = "0.5"
TimerOutputs = "0.5"
TrixiBase = "0.1"
WriteVTK = "1"
5 changes: 5 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284"
TrixiParticles = "66699cd8-9c01-4e9d-a059-b96c86d16b3a"

[compat]
Documenter = "1"
TrixiBase = "0.1"
7 changes: 5 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Documenter, TrixiParticles
using Documenter
using TrixiParticles
using TrixiBase

# Get TrixiParticles.jl root directory
trixiparticles_root_dir = dirname(@__DIR__)
Expand Down Expand Up @@ -67,8 +69,9 @@ makedocs(sitename="TrixiParticles.jl",
"total_lagrangian_sph.md"),
"Boundary" => joinpath("systems", "boundary.md"),
],
"Time integration" => "time_integration.md",
"Time Integration" => "time_integration.md",
"Callbacks" => "callbacks.md",
"TrixiBase.jl API Reference" => "reference-trixibase.md",
],
"Authors" => "authors.md",
"Contributing" => "contributing.md",
Expand Down
9 changes: 9 additions & 0 deletions docs/src/reference-trixibase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TrixiBase.jl API

```@meta
CurrentModule = TrixiBase
```

```@autodocs
Modules = [TrixiBase]
```
2 changes: 1 addition & 1 deletion examples/fluid/accelerated_tank_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-3, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/dam_break_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ callbacks = CallbackSet(info_callback, saving_callback, density_reinit_cb)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-6, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-5, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-3, # Limit stepsize to prevent crashing
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/dam_break_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-4, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/falling_water_column_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-3, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/moving_wall_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-6, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-4, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/periodic_channel_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-8, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-4, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
Expand Down
2 changes: 1 addition & 1 deletion examples/fluid/rectangular_tank_edac_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ callbacks = CallbackSet(info_callback, saving_callback)
# Sometimes, the method fails to do so because forces become extremely large when
# fluid particles are very close to boundary particles, and the time integration method
# interprets this as an instability.
sol = solve(ode, RDPK3SpFSAL49(),
sol = solve(ode, RDPK3SpFSAL35(),
abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-3, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
Expand Down
4 changes: 2 additions & 2 deletions examples/fsi/dam_break_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ boundary_system = BoundarySPHSystem(tank.boundary, boundary_model)

# ==========================================================================================
# ==== Solid
solid_smoothing_length = sqrt(2) * solid_particle_spacing
solid_smoothing_kernel = SchoenbergCubicSplineKernel{2}()
solid_smoothing_length = 2 * sqrt(2) * solid_particle_spacing
solid_smoothing_kernel = WendlandC2Kernel{2}()

# For the FSI we need the hydrodynamic masses and densities in the solid boundary model
hydrodynamic_densites = fluid_density * ones(size(solid.density))
Expand Down
4 changes: 2 additions & 2 deletions examples/fsi/dam_break_gate_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ boundary_system_gate = BoundarySPHSystem(gate, boundary_model_gate, movement=gat

# ==========================================================================================
# ==== Solid
solid_smoothing_length = sqrt(2) * solid_particle_spacing
solid_smoothing_kernel = SchoenbergCubicSplineKernel{2}()
solid_smoothing_length = 2 * sqrt(2) * solid_particle_spacing
solid_smoothing_kernel = WendlandC2Kernel{2}()

# For the FSI we need the hydrodynamic masses and densities in the solid boundary model
hydrodynamic_densites = fluid_density * ones(size(solid.density))
Expand Down
38 changes: 29 additions & 9 deletions examples/solid/oscillating_beam_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,44 @@ solid = union(beam, fixed_particles)

# ==========================================================================================
# ==== Solid
# The kernel in the reference uses a differently scaled smoothing length,
# so this is equivalent to the smoothing length of `sqrt(2) * particle_spacing` used in the paper.
smoothing_length = 2 * sqrt(2) * particle_spacing
smoothing_kernel = WendlandC2Kernel{2}()

smoothing_length = sqrt(2) * particle_spacing
smoothing_kernel = SchoenbergCubicSplineKernel{2}()

solid_system = TotalLagrangianSPHSystem(solid,
smoothing_kernel, smoothing_length,
E, nu,
solid_system = TotalLagrangianSPHSystem(solid, smoothing_kernel, smoothing_length,
E, nu, nothing, #No boundary model
n_fixed_particles=nparticles(fixed_particles),
acceleration=(0.0, -gravity),
nothing) # No boundary model
acceleration=(0.0, -gravity))

# ==========================================================================================
# ==== Simulation
semi = Semidiscretization(solid_system)
ode = semidiscretize(semi, tspan)

info_callback = InfoCallback(interval=100)
saving_callback = SolutionSavingCallback(dt=0.02, prefix="")

# Track the position of the particle in the middle of the tip of the beam.
particle_id = Int(n_particles_per_dimension[1] * (n_particles_per_dimension[2] + 1) / 2)

shift_x = beam.coordinates[1, particle_id]
shift_y = beam.coordinates[2, particle_id]

function x_deflection(v, u, t, system)
particle_position = TrixiParticles.current_coords(u, system, particle_id)

return particle_position[1] - shift_x
end

function y_deflection(v, u, t, system)
particle_position = TrixiParticles.current_coords(u, system, particle_id)

return particle_position[2] - shift_y
end

saving_callback = SolutionSavingCallback(dt=0.02, prefix="",
x_deflection=x_deflection,
y_deflection=y_deflection)

callbacks = CallbackSet(info_callback, saving_callback)

Expand Down
3 changes: 2 additions & 1 deletion src/TrixiParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Reexport: @reexport
using Dates
using DiffEqCallbacks: PeriodicCallback, PeriodicCallbackAffect
using FastPow: @fastpow
using ForwardDiff: ForwardDiff
using LinearAlgebra: norm, dot, I, tr, inv, pinv, det
using Morton: cartesian2morton
using MuladdMacro: @muladd
Expand All @@ -17,8 +18,8 @@ using StaticArrays: @SMatrix, SMatrix, setindex
using StrideArrays: PtrArray, StaticInt
using ThreadingUtilities
using TimerOutputs: TimerOutput, TimerOutputs, print_timer, reset_timer!
using TrixiBase: trixi_include
using WriteVTK: vtk_grid, MeshCell, VTKCellTypes, paraview_collection, vtk_save
using ForwardDiff

# util needs to be first because of macro @trixi_timeit
include("util.jl")
Expand Down
66 changes: 55 additions & 11 deletions src/schemes/solid/total_lagrangian_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ The zero subscript on quantities denotes that the quantity is to be measured in
The difference in the initial coordinates is denoted by $\bm{X}_{ab} = \bm{X}_a - \bm{X}_b$,
the difference in the current coordinates is denoted by $\bm{x}_{ab} = \bm{x}_a - \bm{x}_b$.
For the computation of the PK1 stress tensor, the deformation gradient $\bm{J}$ is computed per particle as
For the computation of the PK1 stress tensor, the deformation gradient $\bm{F}$ is computed per particle as
```math
\bm{J}_a = \sum_b \frac{m_{0b}}{\rho_{0b}} \bm{x}_{ba} (\bm{L}_{0a}\nabla_{0a} W(\bm{X}_{ab}))^T \\
\bm{F}_a = \sum_b \frac{m_{0b}}{\rho_{0b}} \bm{x}_{ba} (\bm{L}_{0a}\nabla_{0a} W(\bm{X}_{ab}))^T \\
\qquad = -\left(\sum_b \frac{m_{0b}}{\rho_{0b}} \bm{x}_{ab} (\nabla_{0a} W(\bm{X}_{ab}))^T \right) \bm{L}_{0a}^T
```
with $1 \leq i,j \leq d$.
From the deformation gradient, the Green-Lagrange strain
```math
\bm{E} = \frac{1}{2}(\bm{J}^T\bm{J} - \bm{I})
\bm{E} = \frac{1}{2}(\bm{F}^T\bm{F} - \bm{I})
```
and the second Piola-Kirchhoff stress tensor
```math
\bm{S} = \lambda \operatorname{tr}(\bm{E}) \bm{I} + 2\mu \bm{E}
```
are computed to obtain the PK1 stress tensor as
```math
\bm{P} = \bm{J}\bm{S}.
\bm{P} = \bm{F}\bm{S}.
```
Here,
Expand Down Expand Up @@ -283,8 +283,8 @@ end
calc_deformation_grad!(deformation_grad, neighborhood_search, system)

@threaded for particle in eachparticle(system)
J_particle = deformation_gradient(system, particle)
pk1_particle = pk1_stress_tensor(J_particle, system)
F_particle = deformation_gradient(system, particle)
pk1_particle = pk1_stress_tensor(F_particle, system)
pk1_particle_corrected = pk1_particle * correction_matrix(system, particle)

@inbounds for j in 1:ndims(system), i in 1:ndims(system)
Expand Down Expand Up @@ -330,18 +330,18 @@ end
end

# First Piola-Kirchhoff stress tensor
@inline function pk1_stress_tensor(J, system)
S = pk2_stress_tensor(J, system)
@inline function pk1_stress_tensor(F, system)
S = pk2_stress_tensor(F, system)

return J * S
return F * S
end

# Second Piola-Kirchhoff stress tensor
@inline function pk2_stress_tensor(J, system)
@inline function pk2_stress_tensor(F, system)
(; lame_lambda, lame_mu) = system

# Compute the Green-Lagrange strain
E = 0.5 * (transpose(J) * J - I)
E = 0.5 * (transpose(F) * F - I)

return lame_lambda * tr(E) * I + 2 * lame_mu * E
end
Expand Down Expand Up @@ -409,3 +409,47 @@ end
function viscosity_model(system::TotalLagrangianSPHSystem)
return system.boundary_model.viscosity
end

# An explanation of these equation can be found in
# J. Lubliner, 2008. Plasticity theory.
# See here below Equation 5.3.21 for the equation for the equivalent stress.
# The von-Mises stress is one form of equivalent stress, where sigma is the deviatoric stress.
# See pages 32 and 123.
function von_mises_stress(system::TotalLagrangianSPHSystem)
von_mises_stress = zeros(eltype(system.pk1_corrected), nparticles(system))

@threaded for particle in each_moving_particle(system)
F = deformation_gradient(system, particle)
J = det(F)
P = pk1_corrected(system, particle)
sigma = (1.0 / J) * P * F'

# Calculate deviatoric stress tensor
s = sigma - (1.0 / 3.0) * tr(sigma) * I

von_mises_stress[particle] = sqrt(3.0 / 2.0 * sum(s .^ 2))
end

return von_mises_stress
end

# An explanation of these equation can be found in
# J. Lubliner, 2008. Plasticity theory.
# See here page 473 for the relation between the `pk1`, the first Piola-Kirchhoff tensor,
# and the Cauchy stress.
function cauchy_stress(system::TotalLagrangianSPHSystem)
NDIMS = ndims(system)

cauchy_stress_tensors = zeros(eltype(system.pk1_corrected), NDIMS, NDIMS,
nparticles(system))

@threaded for particle in each_moving_particle(system)
F = deformation_gradient(system, particle)
J = det(F)
P = pk1_corrected(system, particle)
sigma = (1.0 / J) * P * F'
cauchy_stress_tensors[:, :, particle] = sigma
end

return cauchy_stress_tensors
end
Loading

0 comments on commit 7975a7b

Please sign in to comment.