@@ -125,30 +125,36 @@ end
125125 @pointfield b_ext:: Matrix{Float64}
126126 @pointfield density_matrix:: Matrix{Float64}
127127 @pointfield damage:: Vector{Float64}
128- bond_stretch :: Vector{Float64}
128+ bond_length :: Vector{Float64}
129129 bond_active:: Vector{Bool}
130130 @pointfield n_active_bonds:: Vector{Int}
131+ @pointfield strain_energy_density:: Vector{Float64}
131132end
132133
133- function init_field (:: BBMaterial , :: AbstractTimeSolver , system:: BondSystem ,
134- :: Val{:bond_stretch } )
134+ function init_field (:: AbstractBondBasedMaterial , :: AbstractTimeSolver , system:: BondSystem ,
135+ :: Val{:bond_length } )
135136 return zeros (get_n_bonds (system))
136137end
137138
139+ function init_field (:: AbstractBondBasedMaterial , :: AbstractTimeSolver , system:: BondSystem ,
140+ :: Val{:strain_energy_density} )
141+ return zeros (get_n_loc_points (system))
142+ end
143+
138144# Customized calc_failure to save the bond stretch ε for force density calculation
139145function calc_failure! (storage:: AbstractStorage , system:: BondSystem ,
140146 :: AbstractBondBasedMaterial , :: CriticalStretch ,
141147 paramsetup:: AbstractParameterSetup , i)
142148 (; εc) = get_params (paramsetup, i)
143- (; position, n_active_bonds, bond_active, bond_stretch ) = storage
149+ (; position, n_active_bonds, bond_active, bond_length ) = storage
144150 (; bonds) = system
145151 for bond_id in each_bond_idx (system, i)
146152 bond = bonds[bond_id]
147153 j, L = bond. neighbor, bond. length
148154 Δxij = get_vector_diff (position, i, j)
149155 l = norm (Δxij)
150156 ε = (l - L) / L
151- bond_stretch [bond_id] = ε / l # note that this is ε / l!
157+ bond_length [bond_id] = l # store current bond length
152158 if ε > εc && bond. fail_permit
153159 bond_active[bond_id] = false
154160 end
@@ -159,34 +165,66 @@ end
159165
160166function force_density_point! (storage:: BBStorage , system:: BondSystem , :: BBMaterial ,
161167 params:: StandardPointParameters , t, Δt, i)
162- (; position, bond_stretch , bond_active, b_int) = storage
168+ (; position, bond_length , bond_active, b_int) = storage
163169 (; bonds, correction, volume) = system
164170 for bond_id in each_bond_idx (system, i)
165171 bond = bonds[bond_id]
166- j = bond. neighbor
172+ j, L = bond. neighbor, bond . length
167173 Δxij = get_vector_diff (position, i, j)
168- ε = bond_stretch[bond_id]
174+ l = bond_length[bond_id]
175+ ε = (l - L) / L
169176 ω = bond_active[bond_id] * surface_correction_factor (correction, bond_id)
170- b = ω * params. bc * ε * volume[j] .* Δxij
177+ b = ω * params. bc * ε * volume[j] .* Δxij / l
171178 update_add_vector! (b_int, i, b)
172179 end
173180 return nothing
174181end
175182
176183function force_density_point! (storage:: BBStorage , system:: BondSystem , :: BBMaterial ,
177184 paramhandler:: ParameterHandler , t, Δt, i)
178- (; position, bond_stretch , bond_active, b_int) = storage
185+ (; position, bond_length , bond_active, b_int) = storage
179186 (; bonds, correction, volume) = system
180187 params_i = get_params (paramhandler, i)
181188 for bond_id in each_bond_idx (system, i)
182189 bond = bonds[bond_id]
183- j = bond. neighbor
190+ j, L = bond. neighbor, bond . length
184191 Δxij = get_vector_diff (position, i, j)
185- ε = bond_stretch[bond_id]
192+ l = bond_length[bond_id]
193+ ε = (l - L) / L
186194 params_j = get_params (paramhandler, j)
187195 ω = bond_active[bond_id] * surface_correction_factor (correction, bond_id)
188- b = ω * (params_i. bc + params_j. bc) / 2 * ε * volume[j] .* Δxij
196+ b = ω * (params_i. bc + params_j. bc) / 2 * ε * volume[j] .* Δxij / l
189197 update_add_vector! (b_int, i, b)
190198 end
191199 return nothing
192200end
201+
202+ function strain_energy_density_point! (storage:: AbstractStorage , system:: BondSystem ,
203+ :: AbstractBondBasedMaterial ,
204+ paramsetup:: AbstractParameterSetup , i)
205+ (; bond_active, bond_length, strain_energy_density) = storage
206+ (; bonds, correction, volume) = system
207+ params_i = get_params (paramsetup, i)
208+ Ψ = 0.0
209+ for bond_id in each_bond_idx (system, i)
210+ bond = bonds[bond_id]
211+ j, L = bond. neighbor, bond. length
212+ l = bond_length[bond_id]
213+ ε = (l - L) / L
214+ params_j = get_params (paramsetup, j)
215+ ωij = bond_active[bond_id] * surface_correction_factor (correction, bond_id)
216+ bc = (params_i. bc + params_j. bc) / 2
217+ Ψ += 0.25 * ωij * bc * ε * ε * L * volume[j]
218+ end
219+ strain_energy_density[i] = Ψ
220+ return nothing
221+ end
222+
223+ function export_field (:: Val{:strain_energy_density} , mat:: AbstractBondBasedMaterial ,
224+ system:: BondSystem , storage:: AbstractStorage ,
225+ paramsetup:: AbstractParameterSetup , t)
226+ for i in each_point_idx (system)
227+ strain_energy_density_point! (storage, system, mat, paramsetup, i)
228+ end
229+ return storage. strain_energy_density
230+ end
0 commit comments