forked from 1b-agent/fieldcraft-upstream
Explicit X2: large deformation, J2 and Johnson-Cook plasticity, damage and erosion (M10)
- model: materials gain solver-neutral plastic (bilinear isotropic/kinematic, hardening table, Johnson-Cook with adiabatic heating), damage (Johnson-Cook D1-D5) and erosion (plastic strain); explicit steps gain nonlinear_geometry (default on) and stress_rate (jaumann | green_naghdi). - fem: rotation (Hughes-Winget, Flanagan-Taylor), plasticity (radial return, capped bracketed Newton for Johnson-Cook, damage; the update takes the mechanical strain increment so thermal strains can be subtracted), closed-form hex8 gradients for deformed configurations. - explicit: updated Lagrangian hex8/tet4, per-element material state, erosion with reported energy, plastic work in the energy account. - solver: warns that the linear solver uses the elastic constants of plastic materials (results hash-identical). - decks: Abaqus *PLASTIC (+ Johnson-Cook keywords), Nastran MATS1/TABLES1, LS-DYNA *MAT_PLASTIC_KINEMATIC / *MAT_PIECEWISE_LINEAR_PLASTICITY; what a format cannot express is reported as Unsupported. - engine: model.material.plasticity, model.material.damage (catalogue ready), explicit element probe, eroded elements in the solve summary. Step commits before the rebase onto the DOF framework: branch explicit-x2-steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm
This commit is contained in:
1 parent
4c0fcc80ad
commit
50764def18
38 files changed
+2839
-254
No files matched your search
+412
-111
@@ -1,24 +1,41 @@
|
||||
//! Element internal forces and critical time increments.
|
||||
//! Element internal forces, the material update and critical time increments.
|
||||
//!
|
||||
//! **Kinematics.** With nonlinear geometry the elements are updated Lagrangian (T. Belytschko,
|
||||
//! W. K. Liu, B. Moran, K. Elkhodary, *Nonlinear Finite Elements for Continua and Structures*,
|
||||
//! 2nd ed., Wiley 2014, ch. 4 and 6): the strain and spin increments of an increment come from
|
||||
//! the displacement increment Δu and the gradients of the **midpoint** configuration
|
||||
//! x_{n−½} = X + u_n − ½Δu, ΔG = (1/V) Σ_I Δu_I ⊗ b_I(x_{n−½}), which makes the update
|
||||
//! incrementally objective (T. J. R. Hughes, J. Winget, IJNME 15(12):1862–1867, 1980); the nodal
|
||||
//! forces of the Cauchy stress use the gradients of the current configuration,
|
||||
//! f_iI = σ_ij b_jI(x_n). Without it, both are the gradients of the undeformed mesh and the
|
||||
//! update is small-strain elasticity (and plasticity).
|
||||
//!
|
||||
//! **Stress update** in rate form: the material state (stress, back stress, the accumulated
|
||||
//! strain and the stiffness-form hourglass forces) is rotated with the increment's rotation —
|
||||
//! the Cayley transform of the spin increment (Jaumann rate, Hughes & Winget 1980) or the
|
||||
//! increment of the polar rotation (Green–Naghdi rate, D. P. Flanagan, L. M. Taylor, CMAME
|
||||
//! 62(3):305–320, 1987), see [`modelcraft_fem::rotation`] — then the constitutive increment is
|
||||
//! added: hypoelastic, or J2 radial return with Johnson–Cook damage
|
||||
//! ([`modelcraft_fem::plasticity`]). Orthotropic elasticity is updated in the polar frame (its
|
||||
//! axes turn with the material) whichever rate the step names.
|
||||
//!
|
||||
//! **One-point hexahedron** (D. P. Flanagan, T. Belytschko, IJNME 17(5):679–706, 1981): the
|
||||
//! stress of the mean strain gives the forces f_iI = σ_ij b_jI ([`modelcraft_fem::uniform`]).
|
||||
//! The hourglass modes are resisted through the shape vectors γ_α: with the hourglass rates
|
||||
//! q̇_iα = Σ_I v_iI γ_αI (or displacements q_iα = Σ_I u_iI γ_αI for the stiffness form), the
|
||||
//! generalized forces Q_iα = C q̇_iα (viscous) or k q_iα (stiffness) give the nodal forces
|
||||
//! f_iI = Σ_α Q_iα γ_αI. Because the γ_α are orthogonal to linear fields, these forces do no work
|
||||
//! in a constant strain state. The coefficients are scaled from the dimensionless hourglass
|
||||
//! coefficient κ with the element's size h = V / √(2 λ_max(Σ b bᵀ)) (the edge, for a cube),
|
||||
//! density ρ and wave speed c: C = κ ρ c h² / 16 damps a cube's hourglass modes at a fraction κ
|
||||
//! of critical at the frequency 2c/h, and k = κ ρ c² h / 16 puts their frequency at √κ · 2c/h.
|
||||
//! (These normalizations are ours; the paper leaves the scale of the coefficient to the user.)
|
||||
//! hourglass modes are resisted through the shape vectors γ_α of the current configuration:
|
||||
//! with the hourglass rates q̇_iα = Σ_I v_iI γ_αI, the generalized forces are Q_iα = C q̇_iα
|
||||
//! (viscous) or accumulate as Q_iα += k Σ_I Δu_iI γ_αI (stiffness, rotated with the element),
|
||||
//! and give the nodal forces f_iI = Σ_α Q_iα γ_αI. Because the γ_α are orthogonal to linear
|
||||
//! fields, these forces do no work in a constant strain state. The coefficients are scaled from
|
||||
//! the dimensionless hourglass coefficient κ with the element's current size
|
||||
//! h = V / √(2 λ_max(Σ b bᵀ)) (the edge, for a cube), density ρ and wave speed c:
|
||||
//! C = κ ρ c h² / 16 damps a cube's hourglass modes at a fraction κ of critical at the frequency
|
||||
//! 2c/h, and k = κ ρ c² h / 16 puts their frequency at √κ · 2c/h. (These normalizations are ours;
|
||||
//! the paper leaves the scale of the coefficient to the user.)
|
||||
//!
|
||||
//! **Average nodal pressure tetrahedron** (J. Bonet, A. J. Burton, *A simple average nodal
|
||||
//! pressure tetrahedral element for incompressible and nearly incompressible dynamic explicit
|
||||
//! applications*, Commun. Numer. Methods Eng. 14(5):437–449, 1998): the volumetric strain of each
|
||||
//! node is the volume-weighted mean of its tetrahedra's, and each tetrahedron takes the mean of
|
||||
//! its nodes' as its own: σ = 2μ dev ε + K θ̄ I. The forces are those of the strain energy
|
||||
//! Σ_e V_e μ ‖dev ε_e‖² + ½ K Σ_a V_a θ_a², so the element conserves energy, and it does not lock
|
||||
//! when the material is nearly incompressible.
|
||||
//! **Average nodal pressure tetrahedron** (J. Bonet, A. J. Burton, Commun. Numer. Methods Eng.
|
||||
//! 14(5):437–449, 1998), in rate form: the volumetric strain increment of each node is the
|
||||
//! volume-weighted mean of its tetrahedra's, and each tetrahedron takes the mean of its nodes' as
|
||||
//! its own, so its pressure increment is K times that mean while the deviator is its own. It does
|
||||
//! not lock when the material is nearly incompressible or flows plastically.
|
||||
//!
|
||||
//! **Bulk viscosity** (J. von Neumann, R. D. Richtmyer, J. Appl. Phys. 21(3):232–237, 1950; M. L.
|
||||
//! Wilkins, J. Comput. Phys. 36(3):281–303, 1980): in compression (volumetric strain rate
|
||||
@@ -27,60 +44,118 @@
|
||||
//! Δt = L / (Q + √(Q² + c²)), Q = C_l c + C_q L |ε̇ᵥ| (Wilkins 1980).
|
||||
//!
|
||||
//! **Critical increment.** Each element's stable length L = 2c/ω_max comes from the bound on its
|
||||
//! highest frequency ([`modelcraft_fem::uniform::UniformStrain::frequency_bound`], plus the
|
||||
//! hourglass stiffness when it is used), so without bulk viscosity its critical increment is
|
||||
//! 2/ω_max (T. Belytschko, W. K. Liu, B. Moran, K. Elkhodary, 2014, §6.3; the element eigenvalue
|
||||
//! inequality makes the smallest of them stable for the mesh). For the nodal-pressure
|
||||
//! tetrahedron the averaging only lowers the volumetric energy (the mean of squares bounds the
|
||||
//! square of the mean), so the plain tetrahedron's bound holds.
|
||||
//! highest frequency in its current shape ([`modelcraft_fem::uniform`], with the element's lumped
|
||||
//! masses, plus the hourglass stiffness when it is used), so without bulk viscosity its critical
|
||||
//! increment is 2/ω_max (Belytschko et al. 2014, §6.3). The elastic moduli bound the tangent
|
||||
//! moduli of plastic flow, so the bound holds for the inelastic materials too.
|
||||
//!
|
||||
//! **Erosion** (G. R. Johnson, R. A. Stryk, Int. J. Impact Eng. 5:411–421, 1987; T. Belytschko,
|
||||
//! J. I. Lin, ibid. 5:111–127, 1987): an element whose material point fails (damage 1) or
|
||||
//! reaches its material's erosion plastic strain is removed: it carries no stress from then on,
|
||||
//! its nodes keep their mass and momentum, and its internal energy at that moment is reported.
|
||||
|
||||
use modelcraft_fem::material::stress;
|
||||
use modelcraft_fem::uniform::UniformStrain;
|
||||
use modelcraft_model::{BulkViscosity, HourglassKind};
|
||||
use modelcraft_fem::plasticity::{Increment, PointState};
|
||||
use modelcraft_fem::rotation::{self, IDENTITY, Mat3, Polar};
|
||||
use modelcraft_fem::uniform::{Hex8, Tet4, UniformStrain};
|
||||
use modelcraft_model::{BulkViscosity, HourglassKind, StressRate};
|
||||
|
||||
use crate::system::{Material, NODE_DOFS, System};
|
||||
use crate::{Error, Result};
|
||||
|
||||
/// Scratch vectors and the element state of the latest evaluation.
|
||||
/// Scratch vectors of one evaluation.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Workspace {
|
||||
/// Internal forces per degree of freedom, by origin.
|
||||
pub stress_force: Vec<f64>,
|
||||
pub hourglass_force: Vec<f64>,
|
||||
pub viscous_force: Vec<f64>,
|
||||
/// Per element (in [`System::elements`] order): the material stress and the strain.
|
||||
pub stress: Vec<[f64; 6]>,
|
||||
pub strain: Vec<[f64; 6]>,
|
||||
/// Per node: the mean volumetric strain of its tetrahedra (a volume-weighted sum until it is
|
||||
/// divided by `tet_volume`).
|
||||
/// Per node: the volume-weighted volumetric strain increments of its tetrahedra, and their
|
||||
/// volume.
|
||||
theta: Vec<f64>,
|
||||
tet_volume: Vec<f64>,
|
||||
/// Per tetrahedron (in [`System::tets`] order): its increment between the two passes.
|
||||
tet_increment: Vec<Option<TetIncrement>>,
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
pub fn new(sys: &System) -> Workspace {
|
||||
let n = sys.labels.len();
|
||||
let mut tet_volume = vec![0.0; n];
|
||||
for t in &sys.tets {
|
||||
for node in t.nodes {
|
||||
if let Some(v) = tet_volume.get_mut(node) {
|
||||
*v += t.kinematics.volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
let dofs = sys.dofs();
|
||||
let elements = sys.elements.len();
|
||||
Workspace {
|
||||
stress_force: vec![0.0; dofs],
|
||||
hourglass_force: vec![0.0; dofs],
|
||||
viscous_force: vec![0.0; dofs],
|
||||
stress: vec![[0.0; 6]; elements],
|
||||
strain: vec![[0.0; 6]; elements],
|
||||
theta: vec![0.0; n],
|
||||
tet_volume,
|
||||
tet_volume: vec![0.0; n],
|
||||
tet_increment: vec![None; sys.tets.len()],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Why an element was eroded.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Failure {
|
||||
/// Its damage reached 1.
|
||||
Damage,
|
||||
/// Its equivalent plastic strain reached the material's erosion strain.
|
||||
PlasticStrain,
|
||||
}
|
||||
|
||||
/// The state of one element (its single material point).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ElementState {
|
||||
pub point: PointState,
|
||||
/// The accumulated (rotated) strain increments: engineering shears.
|
||||
pub strain: [f64; 6],
|
||||
/// The polar rotation and stretch (Green–Naghdi rate and orthotropic materials).
|
||||
pub polar: Polar,
|
||||
/// Stiffness-form hourglass generalized forces Q_α (one-point hexahedra).
|
||||
pub hourglass: [[f64; 3]; 4],
|
||||
/// Work of the stress on the element (its internal energy, hourglass apart).
|
||||
pub energy: f64,
|
||||
/// Plastic work on the element.
|
||||
pub plastic_work: f64,
|
||||
pub failed: Option<Failure>,
|
||||
}
|
||||
|
||||
/// The element states and the erosions of a run.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct State {
|
||||
/// Per element, in [`System::elements`] order.
|
||||
pub elements: Vec<ElementState>,
|
||||
/// Elements eroded during the latest evaluation: (index, failure).
|
||||
pub eroded: Vec<(usize, Failure)>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new(sys: &System) -> State {
|
||||
let mut material = vec![usize::MAX; sys.elements.len()];
|
||||
for (index, m) in sys.hexes.iter().map(|h| (h.index, h.material)).chain(sys.tets.iter().map(|t| (t.index, t.material))) {
|
||||
if let Some(slot) = material.get_mut(index) {
|
||||
*slot = m;
|
||||
}
|
||||
}
|
||||
let elements = material
|
||||
.into_iter()
|
||||
.map(|m| {
|
||||
let temperature = sys.materials.get(m).and_then(|m| m.j2.as_ref()).map_or(0.0, |j| j.initial_temperature());
|
||||
ElementState {
|
||||
point: PointState::new(temperature),
|
||||
strain: [0.0; 6],
|
||||
polar: Polar::default(),
|
||||
hourglass: [[0.0; 3]; 4],
|
||||
energy: 0.0,
|
||||
plastic_work: 0.0,
|
||||
failed: None,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
State { elements, eroded: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn gather<const N: usize>(x: &[f64], nodes: &[usize; N]) -> [[f64; 3]; N] {
|
||||
nodes.map(|n| [0, 1, 2].map(|k| x.get(NODE_DOFS * n + k).copied().unwrap_or(0.0)))
|
||||
}
|
||||
@@ -112,102 +187,328 @@ pub fn critical_increment(rate: f64, length: f64, wave_speed: f64, b: &BulkVisco
|
||||
length / (q + (q * q + wave_speed * wave_speed).sqrt())
|
||||
}
|
||||
|
||||
/// What the hexahedron and the tetrahedron share once their stress is known: the stress and bulk
|
||||
/// viscosity forces, the element state and the critical increment.
|
||||
struct Finish<'a, const N: usize> {
|
||||
kinematics: &'a UniformStrain<N>,
|
||||
nodes: &'a [usize; N],
|
||||
index: usize,
|
||||
length: f64,
|
||||
/// The largest absolute row sum of the hourglass vectors' Gram matrix Σ_I γ_αI γ_βI / m_I (an
|
||||
/// upper bound of its largest eigenvalue, exact for parallelepipeds where the γ_α are
|
||||
/// orthogonal).
|
||||
pub fn hourglass_gram_bound(gamma: &[[f64; 8]; 4], mass: &[f64; 8]) -> f64 {
|
||||
let mut worst: f64 = 0.0;
|
||||
for a in gamma {
|
||||
let row: f64 = gamma.iter().map(|b| a.iter().zip(b).zip(mass).map(|((x, y), m)| x * y / m).sum::<f64>().abs()).sum();
|
||||
worst = worst.max(row);
|
||||
}
|
||||
worst
|
||||
}
|
||||
|
||||
impl<const N: usize> Finish<'_, N> {
|
||||
fn apply(&self, ws: &mut Workspace, mat: &Material, v: &[f64], sigma: [f64; 6], strain: [f64; 6], bulk: &BulkViscosity) -> f64 {
|
||||
let k = self.kinematics;
|
||||
let rate = k.divergence(&gather(v, self.nodes));
|
||||
let q = bulk_pressure(rate, mat.density, self.length, mat.wave_speed, bulk);
|
||||
scatter(&mut ws.stress_force, self.nodes, &k.forces(&sigma));
|
||||
if q != 0.0 {
|
||||
scatter(&mut ws.viscous_force, self.nodes, &k.pressure_forces(q));
|
||||
}
|
||||
if let Some(s) = ws.stress.get_mut(self.index) {
|
||||
*s = sigma;
|
||||
}
|
||||
if let Some(s) = ws.strain.get_mut(self.index) {
|
||||
*s = strain;
|
||||
}
|
||||
critical_increment(rate, self.length, mat.wave_speed, bulk)
|
||||
/// What one evaluation of the internal forces is given.
|
||||
pub struct Motion<'a> {
|
||||
/// Displacements u^n.
|
||||
pub u: &'a [f64],
|
||||
/// The displacement increment that led to `u`, Δt^{n−½} v^{n−½}.
|
||||
pub du: &'a [f64],
|
||||
/// The velocity v^{n−½}.
|
||||
pub v: &'a [f64],
|
||||
/// The increment's length Δt^{n−½} (0 at the start).
|
||||
pub dt: f64,
|
||||
pub time: f64,
|
||||
pub bulk: &'a BulkViscosity,
|
||||
}
|
||||
|
||||
/// The element's nodal values: rest positions, displacements, displacement increments and
|
||||
/// velocities, gathered once per evaluation.
|
||||
struct Nodal<const N: usize> {
|
||||
x: [[f64; 3]; N],
|
||||
u: [[f64; 3]; N],
|
||||
du: [[f64; 3]; N],
|
||||
v: [[f64; 3]; N],
|
||||
}
|
||||
|
||||
impl<const N: usize> Nodal<N> {
|
||||
fn gather(sys: &System, nodes: &[usize; N], m: &Motion) -> Nodal<N> {
|
||||
Nodal { x: nodes.map(|n| sys.xyz.get(n).copied().unwrap_or_default()), u: gather(m.u, nodes), du: gather(m.du, nodes), v: gather(m.v, nodes) }
|
||||
}
|
||||
|
||||
/// The positions X + u − s·Δu.
|
||||
fn positions(&self, s: f64) -> [[f64; 3]; N] {
|
||||
std::array::from_fn(|i| [0, 1, 2].map(|k| self.x[i][k] + self.u[i][k] - s * self.du[i][k]))
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate the internal forces at displacements `u` and velocities `v` into `ws` and return the
|
||||
/// smallest critical increment of the elements.
|
||||
pub fn internal_forces(sys: &System, u: &[f64], v: &[f64], bulk: &BulkViscosity, ws: &mut Workspace) -> f64 {
|
||||
fn inverted(label: u32, time: f64) -> Error {
|
||||
Error::Unstable(format!("element {label} turned inside out at time {time:.6e} (its volume is no longer positive)"))
|
||||
}
|
||||
|
||||
/// The rotation of an increment for an element's state, advancing its polar decomposition when
|
||||
/// it is tracked.
|
||||
fn rotation_of(sys: &System, mat: &Material, es: &mut ElementState, g: &Mat3, label: u32, time: f64) -> Result<Mat3> {
|
||||
if !sys.nonlinear {
|
||||
return Ok(IDENTITY);
|
||||
}
|
||||
if sys.stress_rate == StressRate::GreenNaghdi || mat.j2.is_none() {
|
||||
es.polar.advance(g).ok_or_else(|| inverted(label, time))
|
||||
} else {
|
||||
let (_, w) = rotation::split(g);
|
||||
rotation::cayley(&w).ok_or_else(|| inverted(label, time))
|
||||
}
|
||||
}
|
||||
|
||||
/// Rotate an element's state with `q`, then add the constitutive increment for the strain
|
||||
/// increment `d` (engineering shears) with volumetric part `vol` (the tetrahedron's averaged
|
||||
/// one; the trace of `d` for the hexahedron), track its energy at the midpoint volume `volume`,
|
||||
/// and check for erosion.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn update(mat: &Material, es: &mut ElementState, q: &Mat3, d: &[f64; 6], vol: f64, dt: f64, density: f64, volume: f64) {
|
||||
let p = &mut es.point;
|
||||
if *q != IDENTITY {
|
||||
// Only the parts of the state that are in use (a back stress with kinematic hardening,
|
||||
// hourglass forces with stiffness-form control).
|
||||
p.stress = rotation::rotate(q, &p.stress);
|
||||
if p.back != [0.0; 6] {
|
||||
p.back = rotation::rotate(q, &p.back);
|
||||
}
|
||||
es.strain = rotation::rotate_strain(q, &es.strain);
|
||||
if es.hourglass != [[0.0; 3]; 4] {
|
||||
for h in &mut es.hourglass {
|
||||
*h = rotation::apply(q, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
let before = p.stress;
|
||||
let inc = match &mat.j2 {
|
||||
Some(j2) => j2.update(p, d, vol, dt, density),
|
||||
None => {
|
||||
// Orthotropic: in the polar frame, σ̂ += D d̂.
|
||||
let r = es.polar.rotation;
|
||||
if r == IDENTITY {
|
||||
for (s, x) in p.stress.iter_mut().zip(stress(&mat.elasticity, d)) {
|
||||
*s += x;
|
||||
}
|
||||
} else {
|
||||
let local = rotation::rotate_strain(&rotation::transpose(&r), d);
|
||||
for (s, x) in p.stress.iter_mut().zip(rotation::rotate(&r, &stress(&mat.elasticity, &local))) {
|
||||
*s += x;
|
||||
}
|
||||
}
|
||||
Increment::default()
|
||||
}
|
||||
};
|
||||
// Stress work over the increment, ½(σ_n + σ_{n+1}) : Δε, with the volumetric strain the
|
||||
// stress took.
|
||||
let shift = (d[0] + d[1] + d[2] - vol) / 3.0;
|
||||
let mut work = 0.0;
|
||||
for k in 0..6 {
|
||||
let dk = if k < 3 { d[k] - shift } else { d[k] };
|
||||
work += 0.5 * (before[k] + p.stress[k]) * dk;
|
||||
es.strain[k] += dk;
|
||||
}
|
||||
es.energy += work * volume;
|
||||
es.plastic_work += inc.plastic_work * volume;
|
||||
if es.failed.is_none() {
|
||||
if p.damage >= 1.0 {
|
||||
es.failed = Some(Failure::Damage);
|
||||
} else if mat.erosion.is_some_and(|e| p.plastic_strain >= e) {
|
||||
es.failed = Some(Failure::PlasticStrain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The density and dilatational wave speed of an element of rest volume `rest`, now of volume
|
||||
/// `volume`.
|
||||
fn current(mat: &Material, rest: f64, volume: f64) -> (f64, f64) {
|
||||
let rho = mat.density * rest / volume;
|
||||
(rho, (mat.stiffest / rho).sqrt())
|
||||
}
|
||||
|
||||
/// The bound ω² ≤ k λ_max(Σ b bᵀ) / (V m_min) on an element's highest frequency
|
||||
/// ([`modelcraft_fem::uniform`]), with the lumped masses of the undeformed element and
|
||||
/// `gradient_norm` = λ_max(Σ b bᵀ).
|
||||
pub fn frequency_bound<const N: usize>(k: &UniformStrain<N>, gradient_norm: f64, modulus: f64, mass: &[f64; N]) -> f64 {
|
||||
let lightest = mass.iter().copied().fold(f64::INFINITY, f64::min);
|
||||
modulus * gradient_norm / (k.volume * lightest)
|
||||
}
|
||||
|
||||
/// A hexahedron's size h, hourglass coefficient (damping or stiffness) and frequency bound ω²
|
||||
/// (with the hourglass stiffness), at density `density`.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct HexScales {
|
||||
pub size: f64,
|
||||
pub coefficient: f64,
|
||||
pub omega2: f64,
|
||||
}
|
||||
|
||||
/// The [`HexScales`] of a hexahedron in configuration `k` with shape vectors `gamma`.
|
||||
pub fn hex_scales(
|
||||
k: &Hex8,
|
||||
gamma: &[[f64; 8]; 4],
|
||||
mass: &[f64; 8],
|
||||
mat: &Material,
|
||||
density: f64,
|
||||
hourglass: modelcraft_model::Hourglass,
|
||||
) -> HexScales {
|
||||
let norm = k.gradient_norm();
|
||||
// h: the edge of the cube with the element's volume and gradient norm.
|
||||
let size = k.volume / (2.0 * norm).sqrt();
|
||||
let wave2 = mat.stiffest / density;
|
||||
let mut omega2 = frequency_bound(k, norm, mat.modulus, mass);
|
||||
let kappa = hourglass.coefficient;
|
||||
let coefficient = match hourglass.kind {
|
||||
HourglassKind::Viscous => kappa * density * wave2.sqrt() * size * size / 16.0,
|
||||
HourglassKind::Stiffness => {
|
||||
let stiffness = kappa * density * wave2 * size / 16.0;
|
||||
omega2 += stiffness * hourglass_gram_bound(gamma, mass);
|
||||
stiffness
|
||||
}
|
||||
};
|
||||
HexScales { size, coefficient, omega2 }
|
||||
}
|
||||
|
||||
/// Evaluate the internal forces at the motion `m` into `ws`, updating the element states, and
|
||||
/// return the smallest critical increment of the elements still in the analysis.
|
||||
pub fn internal_forces(sys: &System, m: &Motion, state: &mut State, ws: &mut Workspace) -> Result<f64> {
|
||||
for f in [&mut ws.stress_force, &mut ws.hourglass_force, &mut ws.viscous_force] {
|
||||
f.fill(0.0);
|
||||
}
|
||||
state.eroded.clear();
|
||||
let mut critical = f64::INFINITY;
|
||||
let hourglass = modelcraft_model::Hourglass { kind: sys.hourglass, coefficient: sys.hourglass_coefficient };
|
||||
for h in &sys.hexes {
|
||||
let Some(mat) = sys.materials.get(h.material) else { continue };
|
||||
let ue = gather(u, &h.nodes);
|
||||
let strain = h.kinematics.strain(&ue);
|
||||
let sigma = stress(&mat.elasticity, &strain);
|
||||
// Hourglass forces on the displacement (stiffness) or velocity (viscous) modes.
|
||||
let modes = match sys.hourglass {
|
||||
HourglassKind::Viscous => gather(v, &h.nodes),
|
||||
HourglassKind::Stiffness => ue,
|
||||
let (Some(mat), Some(es)) = (sys.materials.get(h.material), state.elements.get_mut(h.index)) else { continue };
|
||||
if es.failed.is_some() {
|
||||
continue;
|
||||
}
|
||||
let e = Nodal::gather(sys, &h.nodes, m);
|
||||
let x_now = e.positions(0.0);
|
||||
let (mid, now) = if sys.nonlinear {
|
||||
let at = |x: &[[f64; 3]; 8]| Hex8::hex8_deformed(x).map_err(|_| inverted(h.label, m.time));
|
||||
(at(&e.positions(0.5))?, at(&x_now)?)
|
||||
} else {
|
||||
(h.kinematics, h.kinematics)
|
||||
};
|
||||
let g = mid.gradient(&e.du);
|
||||
let q = rotation_of(sys, mat, es, &g, h.label, m.time)?;
|
||||
let (d, _) = rotation::split(&g);
|
||||
let (rho, c) = current(mat, h.kinematics.volume, now.volume);
|
||||
update(mat, es, &q, &d, d[0] + d[1] + d[2], m.dt, rho, mid.volume);
|
||||
if let Some(failure) = es.failed {
|
||||
state.eroded.push((h.index, failure));
|
||||
continue;
|
||||
}
|
||||
// Hourglass forces with the current shape vectors and size (fixed without nonlinear
|
||||
// geometry).
|
||||
let (gamma, scales) = if sys.nonlinear {
|
||||
let gamma = now.hourglass_vectors(&x_now);
|
||||
let scales = hex_scales(&now, &gamma, &h.mass, mat, rho, hourglass);
|
||||
(gamma, scales)
|
||||
} else {
|
||||
(h.gamma, h.rest)
|
||||
};
|
||||
let mut f = [[0.0; 3]; 8];
|
||||
for g in &h.gamma {
|
||||
let mut generalized = [0.0; 3];
|
||||
for (x, gk) in modes.iter().zip(g) {
|
||||
for i in 0..3 {
|
||||
generalized[i] += x[i] * gk;
|
||||
let modes = if sys.hourglass == HourglassKind::Viscous { &e.v } else { &e.du };
|
||||
for (k, g) in gamma.iter().enumerate() {
|
||||
let rate: [f64; 3] = [0, 1, 2].map(|i| modes.iter().zip(g).map(|(x, gk)| x[i] * gk).sum());
|
||||
// Viscous: Q = C q̇; stiffness: Q accumulates k Δq.
|
||||
let generalized = match (sys.hourglass, es.hourglass.get_mut(k)) {
|
||||
(HourglassKind::Stiffness, Some(qa)) => {
|
||||
for i in 0..3 {
|
||||
qa[i] += scales.coefficient * rate[i];
|
||||
}
|
||||
*qa
|
||||
}
|
||||
}
|
||||
_ => rate.map(|r| scales.coefficient * r),
|
||||
};
|
||||
for (fk, gk) in f.iter_mut().zip(g) {
|
||||
for i in 0..3 {
|
||||
fk[i] += h.hourglass * generalized[i] * gk;
|
||||
fk[i] += generalized[i] * gk;
|
||||
}
|
||||
}
|
||||
}
|
||||
scatter(&mut ws.hourglass_force, &h.nodes, &f);
|
||||
let finish = Finish { kinematics: &h.kinematics, nodes: &h.nodes, index: h.index, length: h.length };
|
||||
critical = critical.min(finish.apply(ws, mat, v, sigma, strain, bulk));
|
||||
let element = Element { now: &now, mid: &mid, nodes: &h.nodes, density: rho, wave_speed: c, length: 2.0 * c / scales.omega2.sqrt() };
|
||||
critical = critical.min(element.finish(ws, &es.point.stress, &e.v, m.bulk));
|
||||
}
|
||||
if !sys.tets.is_empty() {
|
||||
// Pass 1: each tetrahedron's strain, and each node's mean volumetric strain.
|
||||
// Pass 1: each tetrahedron's increment, and each node's mean volumetric increment.
|
||||
ws.theta.fill(0.0);
|
||||
for t in &sys.tets {
|
||||
let strain = t.kinematics.strain(&gather(u, &t.nodes));
|
||||
ws.tet_volume.fill(0.0);
|
||||
for (k, t) in sys.tets.iter().enumerate() {
|
||||
let Some(slot) = ws.tet_increment.get_mut(k) else { continue };
|
||||
*slot = None;
|
||||
if state.elements.get(t.index).is_none_or(|e| e.failed.is_some()) {
|
||||
continue;
|
||||
}
|
||||
let e = Nodal::gather(sys, &t.nodes, m);
|
||||
let (mid, now) = if sys.nonlinear {
|
||||
let at = |x: &[[f64; 3]; 4]| Tet4::tet4(x).map_err(|_| inverted(t.label, m.time));
|
||||
(at(&e.positions(0.5))?, at(&e.positions(0.0))?)
|
||||
} else {
|
||||
(t.kinematics, t.kinematics)
|
||||
};
|
||||
let g = mid.gradient(&e.du);
|
||||
for node in t.nodes {
|
||||
if let Some(x) = ws.theta.get_mut(node) {
|
||||
*x += t.kinematics.volume * (strain[0] + strain[1] + strain[2]);
|
||||
if let (Some(x), Some(w)) = (ws.theta.get_mut(node), ws.tet_volume.get_mut(node)) {
|
||||
*x += mid.volume * (g[0][0] + g[1][1] + g[2][2]);
|
||||
*w += mid.volume;
|
||||
}
|
||||
}
|
||||
if let Some(s) = ws.strain.get_mut(t.index) {
|
||||
*s = strain;
|
||||
*slot = Some(TetIncrement { g, mid, now, v: e.v });
|
||||
}
|
||||
for (x, w) in ws.theta.iter_mut().zip(&ws.tet_volume) {
|
||||
if *w > 0.0 {
|
||||
*x /= w;
|
||||
}
|
||||
}
|
||||
for (x, v) in ws.theta.iter_mut().zip(&ws.tet_volume) {
|
||||
if *v > 0.0 {
|
||||
*x /= v;
|
||||
}
|
||||
}
|
||||
// Pass 2: each tetrahedron's pressure from the mean of its nodes' volumetric strains.
|
||||
for t in &sys.tets {
|
||||
let Some(mat) = sys.materials.get(t.material) else { continue };
|
||||
let strain = ws.strain.get(t.index).copied().unwrap_or_default();
|
||||
// Pass 2: each tetrahedron's update with the mean of its nodes' volumetric increments.
|
||||
for (k, t) in sys.tets.iter().enumerate() {
|
||||
let (Some(mat), Some(es), Some(Some(inc))) =
|
||||
(sys.materials.get(t.material), state.elements.get_mut(t.index), ws.tet_increment.get(k).copied())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let averaged = t.nodes.iter().map(|n| ws.theta.get(*n).copied().unwrap_or(0.0)).sum::<f64>() / 4.0;
|
||||
let own = strain[0] + strain[1] + strain[2];
|
||||
let mut sigma = stress(&mat.elasticity, &strain);
|
||||
let shift = mat.bulk.unwrap_or(0.0) * (averaged - own);
|
||||
for s in sigma.iter_mut().take(3) {
|
||||
*s += shift;
|
||||
let q = rotation_of(sys, mat, es, &inc.g, t.label, m.time)?;
|
||||
let (d, _) = rotation::split(&inc.g);
|
||||
let (rho, c) = current(mat, t.kinematics.volume, inc.now.volume);
|
||||
update(mat, es, &q, &d, averaged, m.dt, rho, inc.mid.volume);
|
||||
if let Some(failure) = es.failed {
|
||||
state.eroded.push((t.index, failure));
|
||||
continue;
|
||||
}
|
||||
let finish = Finish { kinematics: &t.kinematics, nodes: &t.nodes, index: t.index, length: t.length };
|
||||
critical = critical.min(finish.apply(ws, mat, v, sigma, strain, bulk));
|
||||
let omega2 = if sys.nonlinear { frequency_bound(&inc.now, inc.now.gradient_norm(), mat.modulus, &t.mass) } else { t.omega2 };
|
||||
let element = Element { now: &inc.now, mid: &inc.mid, nodes: &t.nodes, density: rho, wave_speed: c, length: 2.0 * c / omega2.sqrt() };
|
||||
critical = critical.min(element.finish(ws, &es.point.stress, &inc.v, m.bulk));
|
||||
}
|
||||
}
|
||||
critical
|
||||
Ok(critical)
|
||||
}
|
||||
|
||||
/// A tetrahedron's increment between the two passes: the gradient of its displacement increment,
|
||||
/// its midpoint and current kinematics, and its nodal velocities.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct TetIncrement {
|
||||
g: Mat3,
|
||||
mid: Tet4,
|
||||
now: Tet4,
|
||||
v: [[f64; 3]; 4],
|
||||
}
|
||||
|
||||
/// What the hexahedron and the tetrahedron share once their stress is known.
|
||||
struct Element<'a, const N: usize> {
|
||||
now: &'a UniformStrain<N>,
|
||||
mid: &'a UniformStrain<N>,
|
||||
nodes: &'a [usize; N],
|
||||
density: f64,
|
||||
wave_speed: f64,
|
||||
length: f64,
|
||||
}
|
||||
|
||||
impl<const N: usize> Element<'_, N> {
|
||||
/// Add the stress and bulk viscosity forces and return the critical increment.
|
||||
fn finish(&self, ws: &mut Workspace, sigma: &[f64; 6], v: &[[f64; 3]; N], bulk: &BulkViscosity) -> f64 {
|
||||
let rate = self.mid.divergence(v);
|
||||
let q = bulk_pressure(rate, self.density, self.length, self.wave_speed, bulk);
|
||||
scatter(&mut ws.stress_force, self.nodes, &self.now.forces(sigma));
|
||||
if q != 0.0 {
|
||||
scatter(&mut ws.viscous_force, self.nodes, &self.now.pressure_forces(q));
|
||||
}
|
||||
critical_increment(rate, self.length, self.wave_speed, bulk)
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
use modelcraft_model::{ExplicitDynamic, Model, OutputVariable, Procedure, Step};
|
||||
|
||||
use crate::elements::{Workspace, internal_forces};
|
||||
use crate::result::{ControllingElement, Energies, ExplicitResult, Frame, History};
|
||||
use crate::elements::{Motion, State, Workspace, internal_forces};
|
||||
use crate::result::{ControllingElement, Energies, ErodedElement, ExplicitResult, Frame, History};
|
||||
use crate::system::{NODE_DOFS, System};
|
||||
use crate::{Error, Limits, Result};
|
||||
|
||||
@@ -178,13 +178,17 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
let total_mass: f64 = sys.mass.iter().sum();
|
||||
let mut ws = Workspace::new(&sys);
|
||||
let mut previous = Workspace::new(&sys);
|
||||
let mut state = State::new(&sys);
|
||||
let mut eroded: Vec<ErodedElement> = Vec::new();
|
||||
let mut u = vec![0.0; n];
|
||||
let mut du = vec![0.0; n];
|
||||
let v0 = sys.initial_velocity.clone();
|
||||
let initial_kinetic = 0.5 * v0.iter().zip(&mass).map(|(v, m)| m * v * v).sum::<f64>();
|
||||
let inelastic = sys.materials.iter().any(|m| m.j2.as_ref().is_some_and(|j| j.flow.is_some()));
|
||||
|
||||
// Start: forces at rest with the initial velocities, then the half increment.
|
||||
let crit = internal_forces(&sys, &u, &v0, &bulk, &mut ws);
|
||||
let start = Motion { u: &u, du: &du, v: &v0, dt: 0.0, time: 0.0, bulk: &bulk };
|
||||
let crit = internal_forces(&sys, &start, &mut state, &mut ws)?;
|
||||
let mut dt_half = (scale * crit).min(end);
|
||||
let initial_increment = dt_half;
|
||||
let mut v_half = vec![0.0; n];
|
||||
@@ -222,17 +226,28 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
history.displacement.push(pick(u));
|
||||
history.velocity.push(pick(v));
|
||||
};
|
||||
let frame = |t: f64, u: &[f64], v: &[f64], ws: &Workspace| Frame {
|
||||
time: t,
|
||||
displacement: if output.displacement { per_node(u) } else { Vec::new() },
|
||||
velocity: if output.displacement { per_node(v) } else { Vec::new() },
|
||||
stress: if output.stress { ws.stress.clone() } else { Vec::new() },
|
||||
strain: if output.strain { ws.strain.clone() } else { Vec::new() },
|
||||
let frame = |t: f64, u: &[f64], v: &[f64], state: &State| {
|
||||
let each = |on: bool, f: &dyn Fn(&crate::elements::ElementState) -> f64| -> Vec<f64> {
|
||||
if on { state.elements.iter().map(f).collect() } else { Vec::new() }
|
||||
};
|
||||
let inelastic = output.stress && inelastic;
|
||||
Frame {
|
||||
time: t,
|
||||
displacement: if output.displacement { per_node(u) } else { Vec::new() },
|
||||
velocity: if output.displacement { per_node(v) } else { Vec::new() },
|
||||
stress: if output.stress { state.elements.iter().map(|e| e.point.stress).collect() } else { Vec::new() },
|
||||
strain: if output.strain { state.elements.iter().map(|e| e.strain).collect() } else { Vec::new() },
|
||||
plastic_strain: each(inelastic, &|e| e.point.plastic_strain),
|
||||
damage: each(inelastic, &|e| e.point.damage),
|
||||
temperature: each(inelastic, &|e| e.point.temperature),
|
||||
failed: if output.stress { state.elements.iter().map(|e| e.failed.is_some()).collect() } else { Vec::new() },
|
||||
}
|
||||
};
|
||||
let plastic = |state: &State| state.elements.iter().map(|e| e.plastic_work).sum::<f64>();
|
||||
let mut histories = Schedule { interval: settings.history_interval(), next: settings.history_interval() };
|
||||
let mut frames_due = Schedule { interval: settings.output_interval(), next: settings.output_interval() };
|
||||
sample(&mut history, 0.0, dt_half, energy, &u, &v0, &reaction);
|
||||
out_frames.push(frame(0.0, &u, &v0, &ws));
|
||||
out_frames.push(frame(0.0, &u, &v0, &state));
|
||||
|
||||
let mut t = 0.0;
|
||||
let mut increments = 0u64;
|
||||
@@ -253,7 +268,14 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
t += dt_half;
|
||||
increments += 1;
|
||||
std::mem::swap(&mut ws, &mut previous);
|
||||
let crit = internal_forces(&sys, &u, &v_half, &bulk, &mut ws);
|
||||
let motion = Motion { u: &u, du: &du, v: &v_half, dt: dt_half, time: t, bulk: &bulk };
|
||||
let crit = internal_forces(&sys, &motion, &mut state, &mut ws)?;
|
||||
for &(index, failure) in &state.eroded {
|
||||
let element = state.elements.get(index);
|
||||
let internal = element.map_or(0.0, |e| e.energy);
|
||||
energy.eroded += internal;
|
||||
eroded.push(ErodedElement { label: sys.elements.get(index).copied().unwrap_or(0), time: t, failure, internal_energy: internal });
|
||||
}
|
||||
let remaining = end - t;
|
||||
let last = remaining <= 1e-12 * end;
|
||||
let dt_next = if last { 0.0 } else { (scale * crit).min(remaining) };
|
||||
@@ -269,8 +291,8 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
let [mut internal, mut hourglass, mut viscous, mut external, mut constraint, mut kinetic] = [0.0; 6];
|
||||
let forces = ws.stress_force.iter().zip(&ws.hourglass_force).zip(&ws.viscous_force);
|
||||
let before = previous.stress_force.iter().zip(&previous.hourglass_force).zip(&previous.viscous_force);
|
||||
let state = v_now.iter_mut().zip(&v_half).zip(&v_new).zip(&mass).zip(&du).zip(&sys.external).zip(&reaction);
|
||||
for ((((((((now, vh), vn), m), dx), e), r), ((s, h), q)), ((s0, h0), q0)) in state.zip(forces).zip(before) {
|
||||
let per_dof = v_now.iter_mut().zip(&v_half).zip(&v_new).zip(&mass).zip(&du).zip(&sys.external).zip(&reaction);
|
||||
for ((((((((now, vh), vn), m), dx), e), r), ((s, h), q)), ((s0, h0), q0)) in per_dof.zip(forces).zip(before) {
|
||||
*now = vh + weight * (vn - vh);
|
||||
internal += dx * (s0 + s);
|
||||
hourglass += dx * (h0 + h);
|
||||
@@ -287,14 +309,16 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
energy.kinetic = 0.5 * kinetic;
|
||||
peak_internal = peak_internal.max(energy.internal.abs());
|
||||
energy.balance = energy.kinetic + energy.internal + energy.hourglass + energy.viscous - energy.external - energy.constraint - initial_kinetic;
|
||||
if !(energy.balance.is_finite() && crit.is_finite()) {
|
||||
// Every element eroded leaves an infinite critical increment: the nodes fly freely.
|
||||
if !(energy.balance.is_finite() && !crit.is_nan()) {
|
||||
return Err(Error::Unstable(format!("the solution is not finite at time {t:.6e} (increment {increments})")));
|
||||
}
|
||||
if histories.due(t) || last {
|
||||
energy.plastic = plastic(&state);
|
||||
sample(&mut history, t, dt_half, energy, &u, &v_now, &reaction);
|
||||
}
|
||||
if frames_due.due(t) || last {
|
||||
out_frames.push(frame(t, &u, &v_now, &ws));
|
||||
out_frames.push(frame(t, &u, &v_now, &state));
|
||||
}
|
||||
std::mem::swap(&mut v_half, &mut v_new);
|
||||
dt_half = dt_next;
|
||||
@@ -307,9 +331,17 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
sample(&mut history, t, dt_half, energy, &u, &v_now, &reaction);
|
||||
}
|
||||
if out_frames.last().map(|f| f.time) != Some(t) {
|
||||
out_frames.push(frame(t, &u, &v_now, &ws));
|
||||
out_frames.push(frame(t, &u, &v_now, &state));
|
||||
}
|
||||
}
|
||||
energy.plastic = plastic(&state);
|
||||
if !eroded.is_empty() {
|
||||
warnings.push(format!(
|
||||
"{} elements eroded (their material failed); their internal energy at erosion was {:.4e}",
|
||||
eroded.len(),
|
||||
energy.eroded
|
||||
));
|
||||
}
|
||||
|
||||
let error = energy.relative_error(initial_kinetic);
|
||||
if error > BALANCE_TOLERANCE {
|
||||
@@ -338,6 +370,7 @@ pub fn solve_explicit(model: &Model, step: Option<&str>, limits: &Limits) -> Res
|
||||
total_mass,
|
||||
energy,
|
||||
initial_kinetic,
|
||||
eroded,
|
||||
warnings,
|
||||
})
|
||||
}
|
||||
@@ -17,10 +17,12 @@
|
||||
//! - **Integration** ([`integrate`]): the time loop, kinematic constraints, energy accounting
|
||||
//! with a balance check, history samples and field frames ([`result`]).
|
||||
//!
|
||||
//! This first version is geometrically linear (small displacements and strains; the elements'
|
||||
//! gradients are those of the undeformed mesh) with linear elastic materials, which is what the
|
||||
//! analytic verification problems need. Large deformation kinematics with objective stress rates
|
||||
//! and inelastic materials come next (docs/solvers/literature.md, Part F, X2).
|
||||
//! With nonlinear geometry (the default) the elements are updated Lagrangian and the material
|
||||
//! state is integrated in rate form with an objective stress rate (Jaumann by Hughes–Winget,
|
||||
//! Green–Naghdi by Flanagan–Taylor); materials are hypoelastic or J2 plastic (bilinear,
|
||||
//! tabulated, Johnson–Cook) with Johnson–Cook damage and element erosion ([`elements`];
|
||||
//! docs/solvers/literature.md, Parts F and J). Without it the gradients stay those of the
|
||||
//! undeformed mesh (small displacements).
|
||||
//!
|
||||
//! Everything is sequential, with elements in label order and no parallel reductions, so the
|
||||
//! same model gives the same numbers bit for bit; sizes, increments and output are capped by
|
||||
@@ -35,8 +37,9 @@ pub mod integrate;
|
||||
pub mod result;
|
||||
pub mod system;
|
||||
|
||||
pub use elements::Failure;
|
||||
pub use integrate::solve_explicit;
|
||||
pub use result::{ControllingElement, Energies, ExplicitResult, Frame, History};
|
||||
pub use result::{ControllingElement, Energies, ErodedElement, ExplicitResult, Frame, History};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
|
||||
pub enum Error {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::elements::Failure;
|
||||
|
||||
/// The energy account at one time (Belytschko, Liu, Moran, Elkhodary 2014, §6.2.3). The works of
|
||||
/// the internal and external forces are integrated with the trapezoidal rule over each
|
||||
/// increment's displacement; the constraints' with their impulses (see [`crate::integrate`]).
|
||||
@@ -20,6 +22,10 @@ pub struct Energies {
|
||||
pub external: f64,
|
||||
/// Work of the boundary conditions and rigid walls on the model.
|
||||
pub constraint: f64,
|
||||
/// Plastic work: the part of `internal` dissipated by plastic flow.
|
||||
pub plastic: f64,
|
||||
/// Internal energy of the eroded elements when they eroded (part of `internal`).
|
||||
pub eroded: f64,
|
||||
/// kinetic + internal + hourglass + viscous − external − constraint − the initial kinetic
|
||||
/// energy: zero when energy is conserved.
|
||||
pub balance: f64,
|
||||
@@ -45,7 +51,26 @@ pub struct Frame {
|
||||
/// Per element in [`ExplicitResult::elements`] order (one-point elements: one value each):
|
||||
/// xx, yy, zz, xy, xz, yz, engineering shear strains.
|
||||
pub stress: Vec<[f64; 6]>,
|
||||
/// The accumulated strain increments (small strain: the strain; large deformation: the
|
||||
/// integral of the rate of deformation, rotated with the material).
|
||||
pub strain: Vec<[f64; 6]>,
|
||||
/// Per element, with stress output in a model with plasticity: equivalent plastic strain,
|
||||
/// damage and temperature.
|
||||
pub plastic_strain: Vec<f64>,
|
||||
pub damage: Vec<f64>,
|
||||
pub temperature: Vec<f64>,
|
||||
/// Per element, with stress output: whether it has eroded.
|
||||
pub failed: Vec<bool>,
|
||||
}
|
||||
|
||||
/// An element removed from the analysis.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
|
||||
pub struct ErodedElement {
|
||||
pub label: u32,
|
||||
pub time: f64,
|
||||
pub failure: Failure,
|
||||
/// Its internal energy (stress work) when it eroded.
|
||||
pub internal_energy: f64,
|
||||
}
|
||||
|
||||
/// Quantities sampled through the run.
|
||||
@@ -95,5 +120,7 @@ pub struct ExplicitResult {
|
||||
/// The energy account at the end.
|
||||
pub energy: Energies,
|
||||
pub initial_kinetic: f64,
|
||||
/// Elements eroded during the run, in the order they eroded.
|
||||
pub eroded: Vec<ErodedElement>,
|
||||
pub warnings: Vec<String>,
|
||||
}
|
||||
@@ -3,11 +3,14 @@
|
||||
//! vector of an explicit dynamic step.
|
||||
|
||||
use modelcraft_fem::material::Elasticity;
|
||||
use modelcraft_fem::plasticity::J2;
|
||||
use modelcraft_fem::uniform::{Hex8, Tet4, modulus_bound};
|
||||
use modelcraft_fem::{DofKind, DofLayout, DofSet, face};
|
||||
use modelcraft_model::{Elastic, ElementKind, ExplicitDynamic, HourglassKind, Integration, Load, Model, Resolved, SectionKind, Step, Target};
|
||||
use modelcraft_model::{
|
||||
Elastic, ElementKind, ExplicitDynamic, HourglassKind, Integration, Load, Model, Resolved, SectionKind, Step, StressRate, Target,
|
||||
};
|
||||
|
||||
use crate::elements::add_at;
|
||||
use crate::elements::{HexScales, add_at, frequency_bound, hex_scales};
|
||||
use crate::{Error, Result};
|
||||
|
||||
/// Degrees of freedom per node: the three translations, node-major (see [`System`]).
|
||||
@@ -27,8 +30,13 @@ pub struct Material {
|
||||
pub wave_speed: f64,
|
||||
/// The bound of [`modelcraft_fem::uniform::modulus_bound`].
|
||||
pub modulus: f64,
|
||||
/// Bulk modulus, for the nodal-pressure tetrahedron (isotropic materials).
|
||||
pub bulk: Option<f64>,
|
||||
/// The largest normal stiffness M (λ + 2μ when isotropic): c = √(M/ρ).
|
||||
pub stiffest: f64,
|
||||
/// The hypoelastic(–plastic) update of an isotropic material; `None` for orthotropic
|
||||
/// elasticity, updated with [`Material::elasticity`].
|
||||
pub j2: Option<J2>,
|
||||
/// The equivalent plastic strain at which elements erode.
|
||||
pub erosion: Option<f64>,
|
||||
}
|
||||
|
||||
/// A one-point hexahedron.
|
||||
@@ -41,9 +49,10 @@ pub struct Hex {
|
||||
pub material: usize,
|
||||
pub kinematics: Hex8,
|
||||
pub gamma: [[f64; 8]; 4],
|
||||
/// The hourglass coefficient: a damping (viscous) or a stiffness (stiffness form), see
|
||||
/// [`crate::elements`].
|
||||
pub hourglass: f64,
|
||||
/// Row-sum lumped masses of the element's nodes.
|
||||
pub mass: [f64; 8],
|
||||
/// Size, hourglass coefficient and frequency bound of the undeformed element.
|
||||
pub rest: HexScales,
|
||||
/// The element's stable length: its critical increment without bulk viscosity is
|
||||
/// `length / wave_speed`.
|
||||
pub length: f64,
|
||||
@@ -57,6 +66,9 @@ pub struct Tet {
|
||||
pub nodes: [usize; 4],
|
||||
pub material: usize,
|
||||
pub kinematics: Tet4,
|
||||
pub mass: [f64; 4],
|
||||
/// The frequency bound ω² of the undeformed element.
|
||||
pub omega2: f64,
|
||||
pub length: f64,
|
||||
}
|
||||
|
||||
@@ -97,6 +109,10 @@ pub struct System {
|
||||
/// Nodes whose histories are recorded.
|
||||
pub history_nodes: Vec<usize>,
|
||||
pub hourglass: HourglassKind,
|
||||
pub hourglass_coefficient: f64,
|
||||
/// Large deformation (updated Lagrangian) or the undeformed mesh's gradients.
|
||||
pub nonlinear: bool,
|
||||
pub stress_rate: StressRate,
|
||||
pub warnings: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -114,8 +130,11 @@ fn material(model: &Model, name: &str) -> Result<Material> {
|
||||
.ok_or_else(|| invalid(format!("material `{name}` has no density, and explicit dynamics needs one")))?;
|
||||
let d = modelcraft_fem::elasticity(elastic).map_err(|e| invalid(format!("material `{name}`: {e}")))?;
|
||||
let stiffest = d[0][0].max(d[1][1]).max(d[2][2]);
|
||||
let bulk = match *elastic {
|
||||
Elastic::Isotropic { young, poisson } => Some(young / (3.0 * (1.0 - 2.0 * poisson))),
|
||||
// The model keeps plasticity, damage and erosion to isotropic materials.
|
||||
let j2 = match *elastic {
|
||||
Elastic::Isotropic { .. } => {
|
||||
Some(J2::from_model(elastic, m.plastic.as_ref(), m.damage.as_ref()).map_err(|e| invalid(format!("material `{name}`: {e}")))?)
|
||||
}
|
||||
Elastic::EngineeringConstants { .. } => None,
|
||||
};
|
||||
Ok(Material {
|
||||
@@ -124,22 +143,12 @@ fn material(model: &Model, name: &str) -> Result<Material> {
|
||||
density,
|
||||
wave_speed: (stiffest / density).sqrt(),
|
||||
modulus: modulus_bound(elastic, &d),
|
||||
bulk,
|
||||
stiffest,
|
||||
j2,
|
||||
erosion: m.erosion.map(|e| e.plastic_strain),
|
||||
})
|
||||
}
|
||||
|
||||
/// The largest absolute row sum of the hourglass vectors' Gram matrix Σ_I γ_αI γ_βI / v_I (an
|
||||
/// upper bound of its largest eigenvalue, exact for parallelepipeds where the γ_α are
|
||||
/// orthogonal).
|
||||
fn hourglass_gram_bound(gamma: &[[f64; 8]; 4], nodal_volume: &[f64; 8]) -> f64 {
|
||||
let mut worst: f64 = 0.0;
|
||||
for a in gamma {
|
||||
let row: f64 = gamma.iter().map(|b| a.iter().zip(b).zip(nodal_volume).map(|((x, y), v)| x * y / v).sum::<f64>().abs()).sum();
|
||||
worst = worst.max(row);
|
||||
}
|
||||
worst
|
||||
}
|
||||
|
||||
/// The section's elements of a kind the explicit solver has, or why not.
|
||||
fn check_formulation(kind: ElementKind, section_name: &str, f: &modelcraft_model::Formulation) -> Result<()> {
|
||||
let refuse = |why: &str| Err(Error::NotSupported(format!("section `{section_name}`: {why}")));
|
||||
@@ -183,7 +192,7 @@ impl System {
|
||||
for &label in &set.elements {
|
||||
let el = model.element(label).ok_or_else(|| invalid(format!("element {label} is missing")))?;
|
||||
check_formulation(el.kind, name, §ion.formulation)?;
|
||||
if el.kind == ElementKind::Tet4 && materials.get(mi).is_some_and(|m| m.bulk.is_none()) {
|
||||
if el.kind == ElementKind::Tet4 && materials.get(mi).is_some_and(|m| m.j2.is_none()) {
|
||||
return Err(Error::NotSupported(format!(
|
||||
"nodal-pressure tet4 elements of the orthotropic material `{}` (section `{name}`)",
|
||||
section.material
|
||||
@@ -222,6 +231,9 @@ impl System {
|
||||
external: vec![0.0; dofs],
|
||||
history_nodes: Vec::new(),
|
||||
hourglass: settings.hourglass.kind,
|
||||
hourglass_coefficient: settings.hourglass.coefficient,
|
||||
nonlinear: settings.nonlinear_geometry,
|
||||
stress_rate: settings.stress_rate,
|
||||
warnings: resolved.warnings.iter().map(ToString::to_string).collect(),
|
||||
labels,
|
||||
xyz,
|
||||
@@ -237,28 +249,20 @@ impl System {
|
||||
let x = nodes.map(|i| sys.xyz.get(i).copied().unwrap_or_default());
|
||||
let k = Hex8::hex8(&x).map_err(at)?;
|
||||
let gamma = k.hourglass_vectors(&x);
|
||||
// h: the edge of the cube with the element's volume and gradient norm.
|
||||
let h = k.volume / (2.0 * k.gradient_norm()).sqrt();
|
||||
let kappa = settings.hourglass.coefficient;
|
||||
let mut omega2 = k.frequency_bound(mat.modulus, rho);
|
||||
let hourglass = match settings.hourglass.kind {
|
||||
HourglassKind::Viscous => kappa * rho * c * h * h / 16.0,
|
||||
HourglassKind::Stiffness => {
|
||||
let stiffness = kappa * rho * c * c * h / 16.0;
|
||||
omega2 += stiffness * hourglass_gram_bound(&gamma, &k.nodal_volume) / rho;
|
||||
stiffness
|
||||
}
|
||||
};
|
||||
sys.lump(&nodes, &k.nodal_volume, rho);
|
||||
sys.hexes.push(Hex { label, index, nodes, material: mi, kinematics: k, gamma, hourglass, length: 2.0 * c / omega2.sqrt() });
|
||||
let mass = k.nodal_volume.map(|v| rho * v);
|
||||
let rest = hex_scales(&k, &gamma, &mass, mat, rho, settings.hourglass);
|
||||
sys.lump(&nodes, &mass);
|
||||
let length = 2.0 * c / rest.omega2.sqrt();
|
||||
sys.hexes.push(Hex { label, index, nodes, material: mi, kinematics: k, gamma, mass, rest, length });
|
||||
}
|
||||
ElementKind::Tet4 => {
|
||||
let nodes: [usize; 4] = idx.try_into().map_err(|_| invalid(format!("element {label} does not have 4 nodes")))?;
|
||||
let x = nodes.map(|i| sys.xyz.get(i).copied().unwrap_or_default());
|
||||
let k = Tet4::tet4(&x).map_err(at)?;
|
||||
let omega2 = k.frequency_bound(mat.modulus, rho);
|
||||
sys.lump(&nodes, &k.nodal_volume, rho);
|
||||
sys.tets.push(Tet { label, index, nodes, material: mi, kinematics: k, length: 2.0 * c / omega2.sqrt() });
|
||||
let mass = k.nodal_volume.map(|v| rho * v);
|
||||
let omega2 = frequency_bound(&k, k.gradient_norm(), mat.modulus, &mass);
|
||||
sys.lump(&nodes, &mass);
|
||||
sys.tets.push(Tet { label, index, nodes, material: mi, kinematics: k, mass, omega2, length: 2.0 * c / omega2.sqrt() });
|
||||
}
|
||||
other => return Err(Error::Internal(format!("{} element kind", other.name()))),
|
||||
}
|
||||
@@ -270,10 +274,10 @@ impl System {
|
||||
}
|
||||
|
||||
/// Add an element's row-sum lumped masses.
|
||||
fn lump(&mut self, nodes: &[usize], nodal_volume: &[f64], density: f64) {
|
||||
for (node, v) in nodes.iter().zip(nodal_volume) {
|
||||
fn lump(&mut self, nodes: &[usize], mass: &[f64]) {
|
||||
for (node, v) in nodes.iter().zip(mass) {
|
||||
if let Some(m) = self.mass.get_mut(*node) {
|
||||
*m += density * v;
|
||||
*m += v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user