Skip to content

Commit d16269e

Browse files
authored
Merge branch 'main' into energy_surface_correction
2 parents 04c866d + 4462dd9 commit d16269e

File tree

9 files changed

+2527
-46
lines changed

9 files changed

+2527
-46
lines changed

src/auxiliary/io.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ end
102102
function check_export_fields(::Type{S}, fields::Vector{Symbol}) where {S}
103103
allowed_fields = point_data_fields(S)
104104
for f in fields
105-
if !in(f, allowed_fields) && !custom_field(f)
105+
if !in(f, allowed_fields) && !custom_field(S, f)
106106
msg = "unknown point data field `:$(f)` specified for export!\n"
107107
msg *= "If you intend to export a custom field, please define a method:"
108-
msg *= "\n `custom_field(::Val{:$(f)}) = true`\n"
108+
msg *= "\n `custom_field(::Type{MyStorage}, ::Val{:$(f)}) = true`\n"
109109
msg *= "Otherwise, see here all available point data fields of $S:\n"
110110
for allowed_name in allowed_fields
111111
msg *= " - $allowed_name\n"
@@ -116,10 +116,10 @@ function check_export_fields(::Type{S}, fields::Vector{Symbol}) where {S}
116116
return nothing
117117
end
118118

119-
custom_field(field::Symbol) = custom_field(Val(field))
119+
custom_field(S::Type{<:AbstractStorage}, field::Symbol) = custom_field(S, Val(field))
120120
# this function can be specialized to indicate custom fields
121121
# if this is not done, the export_field function will error out!
122-
custom_field(::Val{field}) where {field} = false
122+
custom_field(::Type{<:AbstractStorage}, ::Val{field}) where {field} = false
123123

124124
function get_vtk_filebase(body::AbstractBody, root::AbstractString)
125125
body_name = replace(string(get_name(body)), " " => "_")

src/physics/correspondence.jl

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ When specifying the `fields` keyword of [`Job`](@ref) for a [`Body`](@ref) with
105105
- `n_active_bonds::Vector{Int}`: Number of intact bonds of each point.
106106
- `cauchy_stress::Matrix{Float64}`: Cauchy stress tensor of each point.
107107
- `von_mises_stress::Vector{Float64}`: Von Mises stress of each point.
108+
- `hydrostatic_stress::Vector{Float64}`: Hydrostatic stress of each point.
109+
- `strain_energy_density::Vector{Float64}`: Strain energy density of each point.
108110
"""
109111
struct CMaterial{CM,ZEM,K,DM} <: AbstractCorrespondenceMaterial{CM,ZEM}
110112
kernel::K
@@ -182,36 +184,48 @@ end
182184
@pointfield damage::Vector{Float64}
183185
bond_active::Vector{Bool}
184186
@pointfield n_active_bonds::Vector{Int}
187+
@pointfield defgrad::Matrix{Float64}
185188
@pointfield cauchy_stress::Matrix{Float64}
186189
@pointfield von_mises_stress::Vector{Float64}
190+
@pointfield strain_energy_density::Vector{Float64}
187191
end
188192

189193
function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem, ::Val{:b_int})
190194
return zeros(3, get_n_points(system))
191195
end
192196

193-
function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem,
194-
::Val{:cauchy_stress})
197+
function init_field(::AbstractCorrespondenceMaterial, ::AbstractTimeSolver,
198+
system::BondSystem, ::Val{:defgrad})
195199
return zeros(9, get_n_loc_points(system))
196200
end
197201

198-
function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem,
199-
::Val{:von_mises_stress})
202+
function init_field(::AbstractCorrespondenceMaterial, ::AbstractTimeSolver,
203+
system::BondSystem, ::Val{:cauchy_stress})
204+
return zeros(9, get_n_loc_points(system))
205+
end
206+
207+
function init_field(::AbstractCorrespondenceMaterial, ::AbstractTimeSolver,
208+
system::BondSystem, ::Val{:von_mises_stress})
209+
return zeros(get_n_loc_points(system))
210+
end
211+
212+
function init_field(::AbstractCorrespondenceMaterial, ::AbstractTimeSolver,
213+
system::BondSystem, ::Val{:strain_energy_density})
200214
return zeros(get_n_loc_points(system))
201215
end
202216

203217
function force_density_point!(storage::AbstractStorage, system::AbstractSystem,
204218
mat::AbstractCorrespondenceMaterial,
205219
params::AbstractPointParameters, t, Δt, i)
206-
defgrad_res = calc_deformation_gradient(storage, system, mat, params, i)
220+
defgrad_res = calc_deformation_gradient!(storage, system, mat, params, i)
207221
too_much_damage!(storage, system, mat, defgrad_res, i) && return nothing
208222
PKinv = calc_first_piola_kirchhoff!(storage, mat, params, defgrad_res, Δt, i)
209223
c_force_density!(storage, system, mat, params, mat.zem, PKinv, defgrad_res, i)
210224
return nothing
211225
end
212226

213-
function calc_deformation_gradient(storage::CStorage, system::BondSystem, ::CMaterial,
214-
::CPointParameters, i)
227+
function calc_deformation_gradient!(storage::CStorage, system::BondSystem, ::CMaterial,
228+
::CPointParameters, i)
215229
(; bonds, volume) = system
216230
(; bond_active) = storage
217231
K = zero(SMatrix{3,3,Float64,9})
@@ -231,6 +245,7 @@ function calc_deformation_gradient(storage::CStorage, system::BondSystem, ::CMat
231245
end
232246
Kinv = inv(K)
233247
F = _F * Kinv
248+
Peridynamics.update_tensor!(storage.defgrad, i, F)
234249
return (; F, Kinv, ω0)
235250
end
236251

@@ -317,11 +332,35 @@ function too_much_damage!(storage::AbstractStorage, system::AbstractSystem,
317332
end
318333

319334
# calculate the von Mises stress from the Cauchy stress tensor just when exporting
320-
function export_field(::Val{:von_mises_stress}, ::CMaterial, system::BondSystem,
321-
storage::AbstractStorage, ::AbstractParameterSetup, t)
335+
function export_field(::Val{:von_mises_stress}, ::CMaterial,
336+
system::BondSystem, storage::AbstractStorage, ::AbstractParameterSetup, t)
322337
for i in each_point_idx(system)
323338
σ = get_tensor(storage.cauchy_stress, i)
324339
storage.von_mises_stress[i] = von_mises_stress(σ)
325340
end
326341
return storage.von_mises_stress
327342
end
343+
344+
# calculate the von hydrostatic stress from the Cauchy stress tensor just when exporting,
345+
# use the `von_mises_stress` field to store the hydrostatic stress
346+
function export_field(::Val{:hydrostatic_stress}, ::CMaterial,
347+
system::BondSystem, storage::CStorage, ::AbstractParameterSetup, t)
348+
for i in each_point_idx(system)
349+
σ = get_tensor(storage.cauchy_stress, i)
350+
storage.von_mises_stress[i] = 1/3 * (σ[1,1] + σ[2,2] + σ[3,3])
351+
end
352+
return storage.von_mises_stress
353+
end
354+
custom_field(::Type{CStorage}, ::Val{:hydrostatic_stress}) = true
355+
356+
# calculate the strain energy density from the deformation gradient just when exporting
357+
function export_field(::Val{:strain_energy_density}, mat::CMaterial, system::BondSystem,
358+
storage::AbstractStorage, paramsetup::AbstractParameterSetup, t)
359+
model = mat.constitutive_model
360+
for i in each_point_idx(system)
361+
params = get_params(paramsetup, i)
362+
F = get_tensor(storage.defgrad, i)
363+
storage.strain_energy_density[i] = strain_energy_density(model, storage, params, F)
364+
end
365+
return storage.strain_energy_density
366+
end

src/physics/correspondence_rotated.jl

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ end
5757
bond_active::Vector{Bool}
5858
@pointfield n_active_bonds::Vector{Int}
5959
@pointfield unrotated_stress::Matrix{Float64}
60+
@pointfield defgrad::Matrix{Float64}
61+
@pointfield cauchy_stress::Matrix{Float64}
6062
@pointfield von_mises_stress::Vector{Float64}
63+
@pointfield strain_energy_density::Vector{Float64}
6164
@pointfield left_stretch::Matrix{Float64}
6265
@pointfield rotation::Matrix{Float64}
6366
zem_stiffness_rotated::MArray{NTuple{4,3},Float64,4,81}
@@ -77,11 +80,6 @@ function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem,
7780
return zeros(9, get_n_loc_points(system))
7881
end
7982

80-
function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem,
81-
::Val{:von_mises_stress})
82-
return zeros(get_n_loc_points(system))
83-
end
84-
8583
function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem,
8684
::Val{:left_stretch})
8785
V = zeros(9, get_n_loc_points(system))
@@ -101,8 +99,8 @@ function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem,
10199
return zero(MArray{NTuple{4,3},Float64,4,81})
102100
end
103101

104-
function calc_deformation_gradient(storage::CRStorage, system::BondSystem, ::CRMaterial,
105-
::CPointParameters, i)
102+
function calc_deformation_gradient!(storage::CRStorage, system::BondSystem, ::CRMaterial,
103+
::CPointParameters, i)
106104
(; bonds, volume) = system
107105
(; bond_active) = storage
108106
K = zero(SMatrix{3,3,Float64,9})
@@ -126,6 +124,7 @@ function calc_deformation_gradient(storage::CRStorage, system::BondSystem, ::CRM
126124
Kinv = inv(K)
127125
F = _F * Kinv
128126
= _Ḟ * Kinv
127+
Peridynamics.update_tensor!(storage.defgrad, i, F)
129128
return (; F, Ḟ, Kinv, ω0)
130129
end
131130

@@ -158,6 +157,17 @@ function calc_zem_stiffness_tensor!(storage::CRStorage, system::BondSystem, mat:
158157
return C_1
159158
end
160159

160+
# calculate the von Mises stress from the Cauchy stress tensor just when exporting
161+
function export_field(::Val{:cauchy_stress}, ::CRMaterial, system::BondSystem,
162+
storage::AbstractStorage, ::AbstractParameterSetup, t)
163+
for i in each_point_idx(system)
164+
σ = get_tensor(storage.unrotated_stress, i)
165+
T = rotate_stress(storage::AbstractStorage, σ, i)
166+
Peridynamics.update_tensor!(storage.cauchy_stress, i, T)
167+
end
168+
return storage.cauchy_stress
169+
end
170+
161171
# calculate the von Mises stress from the Cauchy stress tensor just when exporting
162172
function export_field(::Val{:von_mises_stress}, ::CRMaterial, system::BondSystem,
163173
storage::AbstractStorage, ::AbstractParameterSetup, t)
@@ -168,3 +178,28 @@ function export_field(::Val{:von_mises_stress}, ::CRMaterial, system::BondSystem
168178
end
169179
return storage.von_mises_stress
170180
end
181+
182+
# calculate the von hydrostatic stress from the Cauchy stress tensor just when exporting,
183+
# use the `von_mises_stress` field to store the hydrostatic stress
184+
function export_field(::Val{:hydrostatic_stress}, ::CRMaterial,
185+
system::BondSystem, storage::CRStorage, ::AbstractParameterSetup, t)
186+
for i in each_point_idx(system)
187+
σ = get_tensor(storage.unrotated_stress, i)
188+
T = rotate_stress(storage::AbstractStorage, σ, i)
189+
storage.von_mises_stress[i] = 1/3 * (T[1,1] + T[2,2] + T[3,3])
190+
end
191+
return storage.von_mises_stress
192+
end
193+
custom_field(::Type{CRStorage}, ::Val{:hydrostatic_stress}) = true
194+
195+
# calculate the strain energy density from the deformation gradient just when exporting
196+
function export_field(::Val{:strain_energy_density}, mat::CRMaterial, system::BondSystem,
197+
storage::AbstractStorage, paramsetup::AbstractParameterSetup, t)
198+
model = mat.constitutive_model
199+
for i in each_point_idx(system)
200+
params = get_params(paramsetup, i)
201+
F = get_tensor(storage.defgrad, i)
202+
storage.strain_energy_density[i] = strain_energy_density(model, storage, params, F)
203+
end
204+
return storage.strain_energy_density
205+
end

src/physics/rk_correspondence.jl

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ When specifying the `fields` keyword of [`Job`](@ref) for a [`Body`](@ref) with
113113
- `b_ext::Matrix{Float64}`: External force density of each point
114114
- `damage::Vector{Float64}`: Damage of each point
115115
- `n_active_bonds::Vector{Int}`: Number of intact bonds of each point
116-
- `stress::Matrix{Float64}`: Stress tensor of each point
116+
- `cauchy_stress::Matrix{Float64}`: Cauchy stress tensor of each point
117117
- `von_mises_stress::Vector{Float64}`: Von Mises stress of each point
118+
- `hydrostatic_stress::Vector{Float64}`: Hydrostatic stress of each point.
119+
- `strain_energy_density::Vector{Float64}`: Strain energy density of each point.
118120
"""
119121
struct RKCMaterial{CM,K,DM} <: AbstractRKCMaterial{CM,NoCorrection}
120122
kernel::K
@@ -172,12 +174,13 @@ end
172174
bond_active::Vector{Bool}
173175
@pointfield n_active_bonds::Vector{Int}
174176
@pointfield update_gradients::Vector{Bool}
175-
@pointfield stress::Matrix{Float64}
177+
@pointfield cauchy_stress::Matrix{Float64}
176178
@pointfield von_mises_stress::Vector{Float64}
179+
@pointfield strain_energy_density::Vector{Float64}
177180
@lthfield defgrad::Matrix{Float64}
178181
@lthfield weighted_volume::Vector{Float64}
179182
gradient_weight::Matrix{Float64}
180-
first_piola_kirchhoff::Matrix{Float64}
183+
bond_first_piola_kirchhoff::Matrix{Float64}
181184
end
182185

183186
function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSystem,
@@ -191,7 +194,7 @@ function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSys
191194
end
192195

193196
function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSystem,
194-
::Val{:stress})
197+
::Val{:cauchy_stress})
195198
return zeros(9, get_n_loc_points(system))
196199
end
197200

@@ -200,6 +203,11 @@ function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSys
200203
return zeros(get_n_loc_points(system))
201204
end
202205

206+
function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSystem,
207+
::Val{:strain_energy_density})
208+
return zeros(get_n_loc_points(system))
209+
end
210+
203211
function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSystem,
204212
::Val{:defgrad})
205213
return zeros(9, get_n_points(system))
@@ -216,7 +224,7 @@ function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSys
216224
end
217225

218226
function init_field(::AbstractRKCMaterial, ::AbstractTimeSolver, system::BondSystem,
219-
::Val{:first_piola_kirchhoff})
227+
::Val{:bond_first_piola_kirchhoff})
220228
return zeros(9, get_n_bonds(system))
221229
end
222230

@@ -499,15 +507,15 @@ function rkc_force_density!(storage::AbstractStorage, system::AbstractBondSystem
499507
mat::AbstractRKCMaterial, params::AbstractPointParameters,
500508
∑P, t, Δt, i)
501509
(; bonds, volume) = system
502-
(; bond_active, gradient_weight, first_piola_kirchhoff, weighted_volume,
510+
(; bond_active, gradient_weight, bond_first_piola_kirchhoff, weighted_volume,
503511
b_int) = storage
504512
wi = weighted_volume[i]
505513
for bond_id in each_bond_idx(system, i)
506514
if bond_active[bond_id]
507515
bond = bonds[bond_id]
508516
j, L = bond.neighbor, bond.length
509517
ΔXij = get_vector_diff(system.position, i, j)
510-
Pij = get_tensor(first_piola_kirchhoff, bond_id)
518+
Pij = get_tensor(bond_first_piola_kirchhoff, bond_id)
511519
Φij = get_vector(gradient_weight, bond_id)
512520
ϕ = 1 / wi
513521
ω̃ij = kernel(system, bond_id) * ϕ
@@ -522,7 +530,7 @@ end
522530
function calc_first_piola_kirchhoff!(storage::RKCStorage, mat::RKCMaterial,
523531
params::StandardPointParameters, F, bond_id)
524532
P = first_piola_kirchhoff(mat.constitutive_model, storage, params, F)
525-
update_tensor!(storage.first_piola_kirchhoff, bond_id, P)
533+
update_tensor!(storage.bond_first_piola_kirchhoff, bond_id, P)
526534
return P
527535
end
528536

@@ -542,3 +550,77 @@ function bond_avg(Fi, Fj, ΔXij, Δxij, L)
542550
Fij = Favg + Fcor
543551
return Fij
544552
end
553+
554+
function cauchy_stress_point!(storage::AbstractStorage, system::BondSystem,
555+
::AbstractRKCMaterial, ::StandardPointParameters, i)
556+
(; bonds) = system
557+
(; bond_active, defgrad, bond_first_piola_kirchhoff, n_active_bonds) = storage
558+
Fi = get_tensor(defgrad, i)
559+
σi = zero(SMatrix{3,3,Float64,9})
560+
for bond_id in each_bond_idx(system, i)
561+
if bond_active[bond_id]
562+
bond = bonds[bond_id]
563+
j, L = bond.neighbor, bond.length
564+
ΔXij = get_vector_diff(system.position, i, j)
565+
Δxij = get_vector_diff(storage.position, i, j)
566+
Fj = get_tensor(defgrad, j)
567+
Fij = bond_avg(Fi, Fj, ΔXij, Δxij, L)
568+
Pij = get_tensor(bond_first_piola_kirchhoff, bond_id)
569+
σij = cauchy_stress(Pij, Fij)
570+
σi += σij
571+
end
572+
end
573+
update_tensor!(storage.cauchy_stress, i, σi ./ n_active_bonds[i])
574+
return nothing
575+
end
576+
577+
# calculate the Cauchy stress tensor just when exporting
578+
function export_field(::Val{:cauchy_stress}, mat::AbstractRKCMaterial, system::BondSystem,
579+
storage::AbstractStorage, paramsetup::AbstractParameterSetup, t)
580+
for i in each_point_idx(system)
581+
params = get_params(paramsetup, i)
582+
cauchy_stress_point!(storage, system, mat, params, i)
583+
end
584+
return storage.cauchy_stress
585+
end
586+
587+
# calculate the von Mises stress from the Cauchy stress tensor just when exporting
588+
function export_field(::Val{:von_mises_stress}, mat::AbstractRKCMaterial,
589+
system::BondSystem, storage::AbstractStorage,
590+
paramsetup::AbstractParameterSetup, t)
591+
for i in each_point_idx(system)
592+
params = get_params(paramsetup, i)
593+
cauchy_stress_point!(storage, system, mat, params, i)
594+
σ = get_tensor(storage.cauchy_stress, i)
595+
storage.von_mises_stress[i] = von_mises_stress(σ)
596+
end
597+
return storage.von_mises_stress
598+
end
599+
600+
# calculate the von hydrostatic stress from the Cauchy stress tensor just when exporting,
601+
# use the `von_mises_stress` field to store the hydrostatic stress
602+
function export_field(::Val{:hydrostatic_stress}, mat::AbstractRKCMaterial,
603+
system::BondSystem, storage::AbstractStorage,
604+
paramsetup::AbstractParameterSetup, t)
605+
for i in each_point_idx(system)
606+
params = get_params(paramsetup, i)
607+
cauchy_stress_point!(storage, system, mat, params, i)
608+
σ = get_tensor(storage.cauchy_stress, i)
609+
storage.von_mises_stress[i] = 1/3 * (σ[1,1] + σ[2,2] + σ[3,3])
610+
end
611+
return storage.von_mises_stress
612+
end
613+
custom_field(::Type{RKCStorage}, ::Val{:hydrostatic_stress}) = true
614+
615+
# calculate the strain energy density from the deformation gradient just when exporting
616+
function export_field(::Val{:strain_energy_density}, mat::AbstractRKCMaterial,
617+
system::BondSystem, storage::AbstractStorage,
618+
paramsetup::AbstractParameterSetup, t)
619+
model = mat.constitutive_model
620+
for i in each_point_idx(system)
621+
params = get_params(paramsetup, i)
622+
F = get_tensor(storage.defgrad, i)
623+
storage.strain_energy_density[i] = strain_energy_density(model, storage, params, F)
624+
end
625+
return storage.strain_energy_density
626+
end

0 commit comments

Comments
 (0)