Skip to content

Commit

Permalink
[wip] Rename derivative structs
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Jul 2, 2023
1 parent ac55bac commit 12b0457
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
30 changes: 15 additions & 15 deletions russell_tensor/src/order_high_derivatives.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
t2_dyad_t2, t2_odyad_t2, t2_qsd_t2, t2_ssd, Deriv1InvariantJ2, Deriv1InvariantJ3, Mandel, StrError, Tensor2,
Tensor4, ONE_BY_3, SQRT_3, TOL_J2, TWO_BY_3,
t2_dyad_t2, t2_odyad_t2, t2_qsd_t2, t2_ssd, FirstDerivJ2, FirstDerivJ3, Mandel, StrError, Tensor2, Tensor4,
ONE_BY_3, SQRT_3, TOL_J2, TWO_BY_3,
};
use russell_lab::{mat_add, mat_mat_mul, mat_update};

Expand Down Expand Up @@ -323,7 +323,7 @@ impl Deriv2InvariantSigmaD {
if jj2 > TOL_J2 {
let a = 0.5 * SQRT_3 / f64::powf(jj2, 0.5);
let b = 0.25 * SQRT_3 / f64::powf(jj2, 1.5);
Deriv1InvariantJ2::compute(&mut self.d1_jj2, sigma).unwrap();
FirstDerivJ2::calc(&mut self.d1_jj2, sigma).unwrap();
// sigma.deriv1_invariant_jj2(&mut self.d1_jj2).unwrap();
deriv2_invariant_jj2(&mut self.d2_jj2, sigma).unwrap();
t2_dyad_t2(d2, -b, &self.d1_jj2, &self.d1_jj2).unwrap();
Expand All @@ -340,7 +340,7 @@ pub struct Deriv2InvariantLode {
pub aux_jj3: Deriv2InvariantJ3,

/// TEMPORARY
pub temp: Deriv1InvariantJ3,
pub temp: FirstDerivJ3,

/// auxiliary second-order tensor (Symmetric or Symmetric2D)
pub tt: Tensor2,
Expand Down Expand Up @@ -375,7 +375,7 @@ impl Deriv2InvariantLode {
}
Ok(Deriv2InvariantLode {
aux_jj3: Deriv2InvariantJ3::new(case).unwrap(),
temp: Deriv1InvariantJ3::new(case).unwrap(),
temp: FirstDerivJ3::new(case).unwrap(),
tt: Tensor2::new(case),
d1_jj2: Tensor2::new(case),
d1_jj3: Tensor2::new(case),
Expand Down Expand Up @@ -427,8 +427,8 @@ impl Deriv2InvariantLode {
let a = 1.5 * SQRT_3 / f64::powf(jj2, 1.5);
let b = 2.25 * SQRT_3 / f64::powf(jj2, 2.5);
let c = 5.625 * SQRT_3 / f64::powf(jj2, 3.5);
Deriv1InvariantJ2::compute(&mut self.d1_jj2, sigma).unwrap();
self.temp.compute(&mut self.d1_jj3, sigma).unwrap();
FirstDerivJ2::calc(&mut self.d1_jj2, sigma).unwrap();
self.temp.calc(&mut self.d1_jj3, sigma).unwrap();
// sigma.deriv1_invariant_jj2(&mut self.d1_jj2).unwrap();
// sigma.deriv1_invariant_jj3(&mut self.d1_jj3, &mut self.tt).unwrap();
deriv2_invariant_jj2(&mut self.d2_jj2, sigma).unwrap();
Expand All @@ -453,8 +453,8 @@ mod tests {
use super::{Tensor2, Tensor4};
use crate::{
deriv2_invariant_jj2, deriv_inverse_tensor, deriv_inverse_tensor_sym, deriv_squared_tensor,
deriv_squared_tensor_sym, Deriv1InvariantJ2, Deriv1InvariantJ3, Deriv1InvariantLode, Deriv1InvariantSigmaD,
Deriv2InvariantJ3, Deriv2InvariantLode, Deriv2InvariantSigmaD, Mandel, SamplesTensor2, MN_TO_IJKL, SQRT_2,
deriv_squared_tensor_sym, FirstDerivLode, FirstDerivSigmaD, Deriv2InvariantJ3, Deriv2InvariantLode,
Deriv2InvariantSigmaD, FirstDerivJ2, FirstDerivJ3, Mandel, SamplesTensor2, MN_TO_IJKL, SQRT_2,
};
use russell_chk::{approx_eq, deriv_central5};
use russell_lab::{mat_approx_eq, Matrix};
Expand Down Expand Up @@ -926,23 +926,23 @@ mod tests {
args.sigma.vec[args.n] = x;
match args.inv {
Invariant::J2 => {
Deriv1InvariantJ2::compute(&mut args.d1, &args.sigma).unwrap();
FirstDerivJ2::calc(&mut args.d1, &args.sigma).unwrap();
//args.sigma.deriv1_invariant_jj2(&mut args.d1).unwrap(),
}
Invariant::J3 => {
let mut aux = Deriv1InvariantJ3::new(args.sigma.case()).unwrap();
aux.compute(&mut args.d1, &args.sigma).unwrap();
let mut aux = FirstDerivJ3::new(args.sigma.case()).unwrap();
aux.calc(&mut args.d1, &args.sigma).unwrap();
//args.sigma.deriv1_invariant_jj3(&mut args.d1, &mut args.s).unwrap(),
}
Invariant::SigmaD => {
Deriv1InvariantSigmaD::compute(&mut args.d1, &args.sigma)
FirstDerivSigmaD::calc(&mut args.d1, &args.sigma)
.unwrap()
.unwrap();
// args.sigma.deriv1_invariant_sigma_d(&mut args.d1).unwrap().unwrap();
}
Invariant::Lode => {
let mut aux = Deriv1InvariantLode::new(args.sigma.case()).unwrap();
aux.compute(&mut args.d1, &args.sigma).unwrap().unwrap();
let mut aux = FirstDerivLode::new(args.sigma.case()).unwrap();
aux.calc(&mut args.d1, &args.sigma).unwrap().unwrap();
// args.sigma
// .deriv1_invariant_lode(&mut args.d1, &mut args.s)
// .unwrap()
Expand Down
96 changes: 48 additions & 48 deletions russell_tensor/src/order_low_derivatives.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{Mandel, StrError, Tensor2, ONE_BY_3, SQRT_3, TOL_J2, TWO_BY_3};

/// Computes the first derivative of the norm
pub struct Deriv1Norm {}
/// Calculates the first derivative of the norm
pub struct FirstDerivNorm {}

impl Deriv1Norm {
/// Computes the first derivative of the norm
impl FirstDerivNorm {
/// Calculates the first derivative of the norm
///
/// ```text
/// d‖σ‖ σ
Expand All @@ -16,7 +16,7 @@ impl Deriv1Norm {
///
/// If `‖σ‖ > 0`, returns `‖σ‖` and `d1` is valid;
/// Otherwise, returns `None` and `d1` is unchanged.
pub fn compute(d1: &mut Tensor2, sigma: &Tensor2) -> Result<Option<f64>, StrError> {
pub fn calc(d1: &mut Tensor2, sigma: &Tensor2) -> Result<Option<f64>, StrError> {
let dim = d1.vec.dim();
if sigma.vec.dim() != dim {
return Err("sigma and d1 tensors are incompatible");
Expand All @@ -33,11 +33,11 @@ impl Deriv1Norm {
}
}

/// Computes the first derivative of the J2 invariant
pub struct Deriv1InvariantJ2 {}
/// Calculates the first derivative of the J2 invariant
pub struct FirstDerivJ2 {}

impl Deriv1InvariantJ2 {
/// Computes the first derivative of the J2 invariant
impl FirstDerivJ2 {
/// Calculates the first derivative of the J2 invariant
///
/// ```text
/// s = deviator(σ)
Expand All @@ -50,32 +50,32 @@ impl Deriv1InvariantJ2 {
/// ```
///
/// Note: `sigma` must be Symmetric or Symmetric2D.
pub fn compute(d1: &mut Tensor2, sigma: &Tensor2) -> Result<(), StrError> {
pub fn calc(d1: &mut Tensor2, sigma: &Tensor2) -> Result<(), StrError> {
if sigma.case() == Mandel::General {
return Err("sigma tensor must be Symmetric or Symmetric2D");
}
sigma.deviator(d1)
}
}

/// Computes the first derivative of the J3 invariant
pub struct Deriv1InvariantJ3 {
/// Calculates the first derivative of the J3 invariant
pub struct FirstDerivJ3 {
/// Deviator tensor (Symmetric or Symmetric2D)
pub s: Tensor2,
}

impl Deriv1InvariantJ3 {
impl FirstDerivJ3 {
/// Returns a new instance
///
/// Note: `case` must be Symmetric or Symmetric2D
pub fn new(case: Mandel) -> Result<Self, StrError> {
if case == Mandel::General {
return Err("case must be Symmetric or Symmetric2D");
}
Ok(Deriv1InvariantJ3 { s: Tensor2::new(case) })
Ok(FirstDerivJ3 { s: Tensor2::new(case) })
}

/// Computes the first derivative of the J3 invariant
/// Calculates the first derivative of the J3 invariant
///
/// ```text
/// s = deviator(σ)
Expand All @@ -88,7 +88,7 @@ impl Deriv1InvariantJ3 {
/// ```
///
/// Note: `sigma` must be Symmetric or Symmetric2D.
pub fn compute(&mut self, d1: &mut Tensor2, sigma: &Tensor2) -> Result<(), StrError> {
pub fn calc(&mut self, d1: &mut Tensor2, sigma: &Tensor2) -> Result<(), StrError> {
let dim = self.s.vec.dim();
if sigma.vec.dim() != dim {
return Err("sigma tensor is incompatible");
Expand All @@ -106,18 +106,18 @@ impl Deriv1InvariantJ3 {
}
}

/// Computes the first derivative of the mean stress
pub struct Deriv1InvariantSigmaM {}
/// Calculates the first derivative of the mean stress
pub struct FirstDerivSigmaM {}

impl Deriv1InvariantSigmaM {
/// Computes the first derivative of the deviatoric stress invariant (von Mises)
impl FirstDerivSigmaM {
/// Calculates the first derivative of the deviatoric stress invariant (von Mises)
///
/// ```text
/// dσm 1
/// ─── = ─ I
/// dσ 3
/// ```
pub fn compute(d1: &mut Tensor2, sigma: &Tensor2) -> Result<(), StrError> {
pub fn calc(d1: &mut Tensor2, sigma: &Tensor2) -> Result<(), StrError> {
let dim = d1.vec.dim();
if sigma.vec.dim() != dim {
return Err("sigma and d1 tensors are incompatible");
Expand All @@ -132,11 +132,11 @@ impl Deriv1InvariantSigmaM {
}
}

/// Computes the first derivative of the deviatoric stress invariant (von Mises)
pub struct Deriv1InvariantSigmaD {}
/// Calculates the first derivative of the deviatoric stress invariant (von Mises)
pub struct FirstDerivSigmaD {}

impl Deriv1InvariantSigmaD {
/// Computes the first derivative of the deviatoric stress invariant (von Mises)
impl FirstDerivSigmaD {
/// Calculates the first derivative of the deviatoric stress invariant (von Mises)
///
/// ```text
/// s = deviator(σ)
Expand All @@ -154,7 +154,7 @@ impl Deriv1InvariantSigmaD {
///
/// If `J2 > TOL_J2`, returns `J2` and `result` is valid;
/// Otherwise, returns `None` and `result` is invalid.
pub fn compute(d1: &mut Tensor2, sigma: &Tensor2) -> Result<Option<f64>, StrError> {
pub fn calc(d1: &mut Tensor2, sigma: &Tensor2) -> Result<Option<f64>, StrError> {
if sigma.case() == Mandel::General {
return Err("sigma tensor must be Symmetric or Symmetric2D");
}
Expand All @@ -165,7 +165,7 @@ impl Deriv1InvariantSigmaD {
let jj2 = sigma.invariant_jj2();
if jj2 > TOL_J2 {
let a = 0.5 * SQRT_3 / f64::powf(jj2, 0.5);
Deriv1InvariantJ2::compute(d1, sigma).unwrap();
FirstDerivJ2::calc(d1, sigma).unwrap();
for i in 0..dim {
d1.vec[i] *= a;
}
Expand All @@ -175,34 +175,34 @@ impl Deriv1InvariantSigmaD {
}
}

/// Computes the first derivative of the Lode invariant
pub struct Deriv1InvariantLode {
/// Calculates the first derivative of the Lode invariant
pub struct FirstDerivLode {
/// first derivative of J2: dJ2/dσ (Symmetric or Symmetric2D)
pub d1_jj2: Tensor2,

/// first derivative of J3: dJ3/dσ (Symmetric or Symmetric2D)
pub d1_jj3: Tensor2,

/// Auxiliary structure to compute the first derivative of J3
pub aux_jj3: Deriv1InvariantJ3,
/// Auxiliary structure to calculate the first derivative of J3
pub aux_jj3: FirstDerivJ3,
}

impl Deriv1InvariantLode {
impl FirstDerivLode {
/// Returns a new instance
///
/// Note: `case` must be Symmetric or Symmetric2D
pub fn new(case: Mandel) -> Result<Self, StrError> {
if case == Mandel::General {
return Err("case must be Symmetric or Symmetric2D");
}
Ok(Deriv1InvariantLode {
Ok(FirstDerivLode {
d1_jj2: Tensor2::new(case),
d1_jj3: Tensor2::new(case),
aux_jj3: Deriv1InvariantJ3::new(case).unwrap(),
aux_jj3: FirstDerivJ3::new(case).unwrap(),
})
}

/// Computes the first derivative of the Lode invariant
/// Calculates the first derivative of the Lode invariant
///
/// ```text
/// dl dJ3 dJ2
Expand All @@ -222,7 +222,7 @@ impl Deriv1InvariantLode {
///
/// If `J2 > TOL_J2`, returns `J2` and `d1` is valid;
/// Otherwise, returns `None` and `d1` is unchanged.
pub fn compute(&mut self, d1: &mut Tensor2, sigma: &Tensor2) -> Result<Option<f64>, StrError> {
pub fn calc(&mut self, d1: &mut Tensor2, sigma: &Tensor2) -> Result<Option<f64>, StrError> {
let dim = self.d1_jj2.vec.dim();
if sigma.vec.dim() != dim {
return Err("sigma tensor is incompatible");
Expand All @@ -232,8 +232,8 @@ impl Deriv1InvariantLode {
}
let jj2 = sigma.invariant_jj2();
if jj2 > TOL_J2 {
Deriv1InvariantJ2::compute(&mut self.d1_jj2, sigma).unwrap();
self.aux_jj3.compute(&mut self.d1_jj3, sigma).unwrap();
FirstDerivJ2::calc(&mut self.d1_jj2, sigma).unwrap();
self.aux_jj3.calc(&mut self.d1_jj3, sigma).unwrap();
let jj3 = sigma.invariant_jj3();
let a = 1.5 * SQRT_3 / f64::powf(jj2, 1.5);
let b = 2.25 * SQRT_3 / f64::powf(jj2, 2.5);
Expand All @@ -253,8 +253,8 @@ impl Deriv1InvariantLode {
mod tests {
use super::Tensor2;
use crate::{
Deriv1InvariantJ2, Deriv1InvariantJ3, Deriv1InvariantLode, Deriv1InvariantSigmaD, Deriv1InvariantSigmaM,
Deriv1Norm, Mandel, SampleTensor2, SamplesTensor2, IJ_TO_M, ONE_BY_3, SQRT_3_BY_2,
FirstDerivJ2, FirstDerivJ3, FirstDerivLode, FirstDerivNorm, FirstDerivSigmaD, FirstDerivSigmaM, Mandel,
SampleTensor2, SamplesTensor2, IJ_TO_M, ONE_BY_3, SQRT_3_BY_2,
};
use russell_chk::{approx_eq, deriv_central5, vec_approx_eq};
use russell_lab::{mat_approx_eq, Matrix};
Expand All @@ -280,21 +280,21 @@ mod tests {
fn analytical_deriv(fn_name: F, d1: &mut Tensor2, sigma: &Tensor2) {
match fn_name {
F::Norm => {
Deriv1Norm::compute(d1, sigma).unwrap().unwrap();
FirstDerivNorm::calc(d1, sigma).unwrap().unwrap();
}
F::J2 => Deriv1InvariantJ2::compute(d1, sigma).unwrap(),
F::J2 => FirstDerivJ2::calc(d1, sigma).unwrap(),
F::J3 => {
let mut s = Tensor2::new(sigma.case());
let mut aux = Deriv1InvariantJ3::new(sigma.case()).unwrap();
aux.compute(d1, sigma).unwrap();
let mut aux = FirstDerivJ3::new(sigma.case()).unwrap();
aux.calc(d1, sigma).unwrap();
}
F::SigmaM => Deriv1InvariantSigmaM::compute(d1, sigma).unwrap(),
F::SigmaM => FirstDerivSigmaM::calc(d1, sigma).unwrap(),
F::SigmaD => {
Deriv1InvariantSigmaD::compute(d1, sigma).unwrap().unwrap();
FirstDerivSigmaD::calc(d1, sigma).unwrap().unwrap();
}
F::Lode => {
let mut aux = Deriv1InvariantLode::new(sigma.case()).unwrap();
aux.compute(d1, sigma).unwrap().unwrap();
let mut aux = FirstDerivLode::new(sigma.case()).unwrap();
aux.calc(d1, sigma).unwrap().unwrap();
}
};
}
Expand Down

0 comments on commit 12b0457

Please sign in to comment.