Skip to content

Commit 95d3cca

Browse files
committed
Custom export of von Mises stress
1 parent 213834d commit 95d3cca

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

src/auxiliary/io.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ end
161161

162162
function export_fields!(vtk, chunk, fields::Vector{Symbol}, t)
163163
for field in fields
164-
point_data = export_field(Val(field), chunk, t)
164+
point_data = export_field(Val(field), chunk.mat, chunk.system, chunk.storage, t)
165165
vtk[string(field), VTKPointData()] = point_data
166166
end
167167
return nothing
@@ -174,8 +174,8 @@ function export_fields!(vtk, chunk, fields_spec::Dict{Symbol,Vector{Symbol}}, t)
174174
end
175175

176176
# this function can be specialized for each field, even custom export fields can be written!
177-
function export_field(::Val{field}, chunk, t) where {field}
178-
return get_loc_point_data(chunk.storage, chunk.system, field)
177+
function export_field(::Val{field}, mat, system, storage, t) where {field}
178+
return get_loc_point_data(storage, system, field)
179179
end
180180

181181
@inline function get_loc_position(chunk::AbstractBodyChunk)

src/physics/correspondence.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,16 @@ end
182182
@pointfield damage::Vector{Float64}
183183
bond_active::Vector{Bool}
184184
@pointfield n_active_bonds::Vector{Int}
185-
@pointfield stress::Matrix{Float64}
185+
@pointfield cauchy_stress::Matrix{Float64}
186186
@pointfield von_mises_stress::Vector{Float64}
187187
end
188188

189189
function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem, ::Val{:b_int})
190190
return zeros(3, get_n_points(system))
191191
end
192192

193-
function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem, ::Val{:stress})
193+
function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem,
194+
::Val{:cauchy_stress})
194195
return zeros(9, get_n_loc_points(system))
195196
end
196197

@@ -239,8 +240,7 @@ function calc_first_piola_kirchhoff!(storage::CStorage, mat::CMaterial,
239240
P = first_piola_kirchhoff(mat.constitutive_model, storage, params, F)
240241
PKinv = P * Kinv
241242
σ = cauchy_stress(P, F)
242-
update_tensor!(storage.stress, i, σ)
243-
storage.von_mises_stress[i] = von_mises_stress(σ)
243+
update_tensor!(storage.cauchy_stress, i, σ)
244244
return PKinv
245245
end
246246

@@ -315,3 +315,13 @@ function too_much_damage!(storage::AbstractStorage, system::AbstractSystem,
315315
end
316316
return false
317317
end
318+
319+
# 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, t)
322+
for i in each_point_idx(system)
323+
σ = get_tensor(storage.cauchy_stress, i)
324+
storage.von_mises_stress[i] = von_mises_stress(σ)
325+
end
326+
return storage.von_mises_stress
327+
end

src/physics/correspondence_rotated.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ end
148148
@pointfield damage::Vector{Float64}
149149
bond_active::Vector{Bool}
150150
@pointfield n_active_bonds::Vector{Int}
151-
@pointfield stress::Matrix{Float64}
151+
@pointfield unrotated_stress::Matrix{Float64}
152152
@pointfield von_mises_stress::Vector{Float64}
153153
@pointfield left_stretch::Matrix{Float64}
154154
@pointfield rotation::Matrix{Float64}
@@ -164,7 +164,8 @@ function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem, ::Va
164164
return zeros(3, get_n_points(system))
165165
end
166166

167-
function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem, ::Val{:stress})
167+
function init_field(::CRMaterial, ::AbstractTimeSolver, system::BondSystem,
168+
::Val{:unrotated_stress})
168169
return zeros(9, get_n_loc_points(system))
169170
end
170171

@@ -231,11 +232,10 @@ function calc_first_piola_kirchhoff!(storage::CRStorage, mat::CRMaterial,
231232
Δε = D * Δt
232233
Δθ = tr(Δε)
233234
Δεᵈᵉᵛ = Δε - Δθ / 3 * I
234-
σ = get_tensor(storage.stress, i)
235+
σ = get_tensor(storage.unrotated_stress, i)
235236
σₙ₊₁ = σ + 2 * params.G * Δεᵈᵉᵛ + params.K * Δθ * I
236-
update_tensor!(storage.stress, i, σₙ₊₁)
237+
update_tensor!(storage.unrotated_stress, i, σₙ₊₁)
237238
T = rotate_stress(storage, σₙ₊₁, i)
238-
storage.von_mises_stress[i] = von_mises_stress(T)
239239
P = first_piola_kirchhoff(T, F)
240240
PKinv = P * Kinv
241241
return PKinv
@@ -249,3 +249,14 @@ function calc_zem_stiffness_tensor!(storage::CRStorage, system::BondSystem, mat:
249249
C_1 = calc_rotated_zem_stiffness_tensor!(zem_stiffness_rotated, params.C, Kinv, R)
250250
return C_1
251251
end
252+
253+
# calculate the von Mises stress from the Cauchy stress tensor just when exporting
254+
function export_field(::Val{:von_mises_stress}, ::CRMaterial, system::BondSystem,
255+
storage::AbstractStorage, t)
256+
for i in each_point_idx(system)
257+
σ = get_tensor(storage.unrotated_stress, i)
258+
T = rotate_stress(storage::AbstractStorage, σ, i)
259+
storage.von_mises_stress[i] = von_mises_stress(T)
260+
end
261+
return storage.von_mises_stress
262+
end

0 commit comments

Comments
 (0)