Skip to content

Commit f3d20e7

Browse files
committed
Refactoring, docstrings & test fixes
1 parent c2cda49 commit f3d20e7

File tree

9 files changed

+104
-40
lines changed

9 files changed

+104
-40
lines changed

src/Peridynamics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ abstract type AbstractBondSystemMaterial{Correction} <: AbstractMaterial end
7979
abstract type AbstractBondBasedMaterial{CM} <: AbstractBondSystemMaterial{CM} end
8080
abstract type AbstractCorrespondenceMaterial{CM,ZEM} <: AbstractBondSystemMaterial{ZEM} end
8181
abstract type AbstractRKCMaterial{CM,C} <: AbstractBondSystemMaterial{C} end
82-
abstract type AbstractBondAssociatedSystemMaterial <: AbstractMaterial end
82+
abstract type AbstractBondAssociatedSystemMaterial <: AbstractBondSystemMaterial{Nothing} end
8383
abstract type AbstractConstitutiveModel end
8484
abstract type AbstractStressIntegration end
8585
abstract type AbstractZEMStabilization <: AbstractCorrection end

src/discretization/interaction_system.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function calc_force_density!(chunk::AbstractBodyChunk{<:InteractionSystem}, t,
424424
calc_damage!(storage, system, mat, dmgmodel, paramsetup, point_id)
425425
force_density_point!(storage, system, mat, paramsetup, t, Δt, point_id)
426426
end
427-
nancheck(chunk, t, Δt)
427+
nancheck(storage, t, Δt)
428428
return nothing
429429
end
430430

src/physics/bond_based.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ When specifying the `fields` keyword of [`Job`](@ref) for a [`Body`](@ref) with
6969
- `b_ext::Matrix{Float64}`: External force density of each point.
7070
- `damage::Vector{Float64}`: Damage of each point.
7171
- `n_active_bonds::Vector{Int}`: Number of intact bonds of each point.
72+
- `strain_energy_density::Vector{Float64}`: Strain energy density of each point.
7273
"""
7374
struct BBMaterial{Correction,DM} <: AbstractBondBasedMaterial{Correction}
7475
dmgmodel::DM
@@ -200,8 +201,7 @@ function force_density_point!(storage::BBStorage, system::BondSystem, ::BBMateri
200201
end
201202

202203
function strain_energy_density_point!(storage::AbstractStorage, system::BondSystem,
203-
::AbstractBondBasedMaterial,
204-
paramsetup::AbstractParameterSetup, i)
204+
::BBMaterial, paramsetup::AbstractParameterSetup, i)
205205
(; bond_active, bond_length, strain_energy_density) = storage
206206
(; bonds, correction, volume) = system
207207
params_i = get_params(paramsetup, i)

src/physics/correspondence.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ When specifying the `fields` keyword of [`Job`](@ref) for a [`Body`](@ref) with
103103
- `b_ext::Matrix{Float64}`: External force density of each point.
104104
- `damage::Vector{Float64}`: Damage of each point.
105105
- `n_active_bonds::Vector{Int}`: Number of intact bonds of each point.
106-
- `stress::Matrix{Float64}`: Stress tensor of each point.
106+
- `cauchy_stress::Matrix{Float64}`: Cauchy stress tensor of each point.
107107
- `von_mises_stress::Vector{Float64}`: Von Mises stress of each point.
108108
"""
109109
struct CMaterial{CM,ZEM,K,DM} <: AbstractCorrespondenceMaterial{CM,ZEM}

src/physics/dh_bond_based.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ When specifying the `fields` keyword of [`Job`](@ref) for a [`Body`](@ref) with
6969
- `b_ext::Matrix{Float64}`: External force density of each point.
7070
- `damage::Vector{Float64}`: Damage of each point.
7171
- `n_active_bonds::Vector{Int}`: Number of intact bonds of each point.
72+
- `strain_energy_density::Vector{Float64}`: Strain energy density of each point.
7273
"""
7374
struct DHBBMaterial{Correction,DM} <: AbstractBondBasedMaterial{Correction}
7475
dmgmodel::DM
@@ -146,3 +147,23 @@ function force_density_point!(storage::DHBBStorage, system::BondSystem, ::DHBBMa
146147
end
147148
return nothing
148149
end
150+
151+
function strain_energy_density_point!(storage::AbstractStorage, system::BondSystem,
152+
::DHBBMaterial, paramsetup::AbstractParameterSetup, i)
153+
(; bond_active, bond_length, strain_energy_density) = storage
154+
(; bonds, correction, volume) = system
155+
params_i = get_params(paramsetup, i)
156+
Ψ = 0.0
157+
for bond_id in each_bond_idx(system, i)
158+
bond = bonds[bond_id]
159+
j, L = bond.neighbor, bond.length
160+
l = bond_length[bond_id]
161+
ε = (l - L) / L
162+
params_j = get_params(paramsetup, j)
163+
ωij = bond_active[bond_id] * surface_correction_factor(correction, bond_id)
164+
bc = (params_i.bc + params_j.bc) / 2
165+
Ψ += 0.5 * ωij * bc * ε * ε * L * volume[j] # added factor 2 here!
166+
end
167+
strain_energy_density[i] = Ψ
168+
return nothing
169+
end

src/physics/ordinary_state_based.jl

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ When specifying the `fields` keyword of [`Job`](@ref) for a [`Body`](@ref) with
7777
- `b_ext::Matrix{Float64}`: External force density of each point.
7878
- `damage::Vector{Float64}`: Damage of each point.
7979
- `n_active_bonds::Vector{Int}`: Number of intact bonds of each point.
80+
- `strain_energy_density::Vector{Float64}`: Strain energy density of each point.
8081
"""
8182
struct OSBMaterial{Correction,K,DM} <: AbstractBondSystemMaterial{Correction}
8283
kernel::K
@@ -226,33 +227,39 @@ function calc_dilatation(storage::OSBStorage, system::BondSystem, mat::OSBMateri
226227
return dil
227228
end
228229

229-
function export_field(::Val{:strain_energy_density}, mat::OSBMaterial, system::BondSystem,
230-
storage::AbstractStorage, paramsetup::AbstractParameterSetup, t)
230+
function strain_energy_density_point!(storage::AbstractStorage, system::BondSystem,
231+
mat::OSBMaterial, paramsetup::AbstractParameterSetup,
232+
i)
231233
(; bond_active, bond_length, strain_energy_density) = storage
232234
(; bonds, correction, volume) = system
233-
strain_energy_density .= 0.0
235+
params_i = get_params(paramsetup, i)
236+
wvol = calc_weighted_volume(storage, system, mat, params_i, i)
237+
iszero(wvol) && return nothing
238+
dil = calc_dilatation(storage, system, mat, params_i, wvol, i)
239+
Ψvol = 0.5 * params_i.K * dil^2
240+
Ψdev = 0.0
241+
for bond_id in each_bond_idx(system, i)
242+
bond = bonds[bond_id]
243+
j, L = bond.neighbor, bond.length
244+
l = bond_length[bond_id]
245+
e = l - L
246+
edev = e - 1/3 * dil * L
247+
ωij = kernel(system, bond_id) * bond_active[bond_id]
248+
β = surface_correction_factor(correction, bond_id)
249+
params_j = get_params(paramsetup, j)
250+
G = (params_i.G + params_j.G) / 2
251+
cdev = 15.0 * G / (2 * wvol)
252+
Ψdev += cdev * ωij * β * edev * edev * volume[j]
253+
end
254+
Ψ = Ψvol + Ψdev
255+
strain_energy_density[i] = Ψ
256+
return nothing
257+
end
258+
259+
function export_field(::Val{:strain_energy_density}, mat::OSBMaterial, system::BondSystem,
260+
storage::AbstractStorage, paramsetup::AbstractParameterSetup, t)
234261
for i in each_point_idx(system)
235-
params_i = get_params(paramsetup, i)
236-
wvol = calc_weighted_volume(storage, system, mat, params_i, i)
237-
iszero(wvol) && continue
238-
dil = calc_dilatation(storage, system, mat, params_i, wvol, i)
239-
Ψvol = 0.5 * params_i.K * dil^2
240-
Ψdev = 0.0
241-
for bond_id in each_bond_idx(system, i)
242-
bond = bonds[bond_id]
243-
j, L = bond.neighbor, bond.length
244-
l = bond_length[bond_id]
245-
e = l - L
246-
edev = e - 1/3 * dil * L
247-
ωij = kernel(system, bond_id) * bond_active[bond_id]
248-
β = surface_correction_factor(correction, bond_id)
249-
params_j = get_params(paramsetup, j)
250-
G = (params_i.G + params_j.G) / 2
251-
cdev = 15.0 * G / (2 * wvol)
252-
Ψdev += cdev * ωij * β * edev * edev * volume[j]
253-
end
254-
Ψ = Ψvol + Ψdev
255-
strain_energy_density[i] = Ψ
262+
strain_energy_density_point!(storage, system, mat, paramsetup, i)
256263
end
257-
return strain_energy_density
264+
return storage.strain_energy_density
258265
end

src/physics/rk_correspondence.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,14 @@ function rkc_defgrad!(storage::AbstractStorage, system::AbstractBondSystem,
447447
return nothing
448448
end
449449

450-
function calc_force_density!(chunk::BodyChunk{<:BondSystem,<:AbstractRKCMaterial}, t, Δt)
451-
(; system, mat, paramsetup, storage) = chunk
452-
storage.b_int .= 0
453-
for i in each_point_idx(chunk)
450+
function calc_force_density!(storage::AbstractStorage, system::AbstractBondSystem,
451+
mat::AbstractRKCMaterial, paramsetup::AbstractParameterSetup,
452+
t, Δt)
453+
storage.b_int .= 0.0
454+
for i in each_point_idx(system)
454455
force_density_point!(storage, system, mat, paramsetup, t, Δt, i)
455456
end
456-
nancheck(chunk, t, Δt)
457+
nancheck(storage, t, Δt)
457458
return nothing
458459
end
459460

test/auxiliary/test_nans.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ end
1717
body = Body(BBMaterial(), ref_position, volume)
1818
material!(body, horizon=δ, rho=1, E=E)
1919
dh = Peridynamics.threads_data_handler(body, VelocityVerlet(steps=1), 1)
20-
chunk = dh.chunks[1]
21-
(; b_int) = chunk.storage
20+
(; storage) = dh.chunks[1]
21+
(; b_int) = storage
2222

23-
@test Peridynamics.nancheck(chunk, 0.0, 0.0) === nothing
23+
@test Peridynamics.nancheck(storage, 0.0, 0.0) === nothing
2424

2525
b_int[3, end] = NaN
26-
@test_throws ErrorException Peridynamics.nancheck(chunk, 0.0, 0.0)
26+
@test_throws ErrorException Peridynamics.nancheck(storage, 0.0, 0.0)
2727
end

test/physics/test_strain_energy_density.jl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
@printf(" mean error: %7.2f %%\n", (Ψ̂_pd - Ψ_a) / Ψ_a * 100)
3737
@printf(" min rel. error: %7.2f %%\n", ΔΨ_min * 100)
3838
@printf(" max rel. error: %7.2f %%\n", ΔΨ_max * 100)
39-
println("-"^50)
4039

4140
@test ΔΨ_min > tols[1]
4241
@test ΔΨ_max < tols[2]
@@ -80,6 +79,42 @@ end
8079
test_stendens(body, ts, F_a, Ψ_a, tols; testcase)
8180
end
8281

82+
@testitem "Strain energy density export DHBBMaterial" setup=[PsiExport] begin
83+
Δx = 0.2
84+
horizon = 3.01Δx
85+
E = 210e9
86+
nu = 0.25
87+
λ = 1.05
88+
pos, vol = uniform_box(1,1,1,Δx)
89+
mat = DHBBMaterial{NoCorrection}()
90+
body = Body(mat, pos, vol)
91+
material!(body; horizon, rho=8000, E, nu)
92+
params = body.point_params[1]
93+
ts = VelocityVerlet(steps=1)
94+
95+
testcase = "homogeneous isotropic extension"
96+
ε = λ - 1
97+
F_a = @SMatrix0 0; 0 λ 0; 0 0 λ]
98+
Ψ_a = 9/2 * params.K * ε^2
99+
tols = (-0.9, 0.3)
100+
test_stendens(body, ts, F_a, Ψ_a, tols; testcase)
101+
102+
testcase = "pure shear deformation"
103+
β = 0.1
104+
F_a = @SMatrix [1 β 0; 0 1 0; 0 0 1]
105+
Ψ_a = 1/2 * params.G * β^2
106+
tols = (-0.9, 0.3)
107+
test_stendens(body, ts, F_a, Ψ_a, tols; testcase)
108+
109+
testcase = "uniform extension in x-direction"
110+
λ = 1.1
111+
ε = λ - 1
112+
F_a = @SMatrix0 0; 0 1 0; 0 0 1]
113+
Ψ_a = 3/5 * params.E * ε^2
114+
tols = (-0.9, 0.3)
115+
test_stendens(body, ts, F_a, Ψ_a, tols; testcase)
116+
end
117+
83118
@testitem "Strain energy density export OSBMaterial" setup=[PsiExport] begin
84119
Δx = 0.2
85120
horizon = 3.01Δx

0 commit comments

Comments
 (0)