Skip to content

Commit

Permalink
[sparse] Rename Symmetry to Sym
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Mar 9, 2024
1 parent 051f0f7 commit b9a8254
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 188 deletions.
8 changes: 4 additions & 4 deletions russell_ode/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::StrError;
use crate::{HasJacobian, NoArgs, System};
use russell_lab::math::PI;
use russell_lab::Vector;
use russell_sparse::{CooMatrix, Symmetry};
use russell_sparse::{CooMatrix, Sym};

/// Holds data corresponding to a sample ODE problem
pub struct SampleData {
Expand Down Expand Up @@ -164,7 +164,7 @@ impl Samples {
) {
// selected symmetry option (for both Mass and Jacobian matrices)
let symmetry = if lower_triangle {
Some(Symmetry::new_general_lower())
Some(Sym::new_general_lower())
} else {
None
};
Expand Down Expand Up @@ -789,7 +789,7 @@ mod tests {
use super::{NoArgs, Samples};
use crate::StrError;
use russell_lab::{deriv_central5, mat_approx_eq, vec_approx_eq, Matrix, Vector};
use russell_sparse::{CooMatrix, Symmetry};
use russell_sparse::{CooMatrix, Sym};

fn numerical_jacobian<F>(ndim: usize, x0: f64, y0: Vector, function: F, multiplier: f64) -> Matrix
where
Expand Down Expand Up @@ -1045,6 +1045,6 @@ mod tests {
println!("{}", mass.as_dense());
let ndim = system.ndim;
let nnz_mass = 5 + 4;
assert_eq!(mass.get_info(), (ndim, ndim, nnz_mass, Symmetry::No));
assert_eq!(mass.get_info(), (ndim, ndim, nnz_mass, Sym::No));
}
}
10 changes: 5 additions & 5 deletions russell_ode/src/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{HasJacobian, StrError};
use russell_lab::Vector;
use russell_sparse::{CooMatrix, Symmetry};
use russell_sparse::{CooMatrix, Sym};
use std::marker::PhantomData;

/// Indicates that the system functions do not require extra arguments
Expand Down Expand Up @@ -72,7 +72,7 @@ where
pub(crate) jac_nnz: usize,

/// Symmetry properties of the Jacobian matrix
pub(crate) jac_symmetry: Symmetry,
pub(crate) jac_symmetry: Sym,

/// Holds the mass matrix
pub(crate) mass_matrix: Option<CooMatrix>,
Expand Down Expand Up @@ -106,7 +106,7 @@ where
jacobian: J,
has_ana_jacobian: HasJacobian,
jac_nnz: Option<usize>,
jac_symmetry: Option<Symmetry>,
jac_symmetry: Option<Sym>,
) -> Self {
let jac_available = match has_ana_jacobian {
HasJacobian::Yes => true,
Expand All @@ -118,7 +118,7 @@ where
jacobian,
jac_available,
jac_nnz: if let Some(n) = jac_nnz { n } else { ndim * ndim },
jac_symmetry: if let Some(s) = jac_symmetry { s } else { Symmetry::No },
jac_symmetry: if let Some(s) = jac_symmetry { s } else { Sym::No },
mass_matrix: None,
phantom: PhantomData,
}
Expand All @@ -132,7 +132,7 @@ where
///
/// * `max_nnz` -- Max number of non-zero values
pub fn init_mass_matrix(&mut self, max_nnz: usize) -> Result<(), StrError> {
let sym = if self.jac_symmetry == Symmetry::No {
let sym = if self.jac_symmetry == Sym::No {
None
} else {
Some(self.jac_symmetry)
Expand Down
6 changes: 3 additions & 3 deletions russell_sparse/src/complex_coo_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ impl ComplexCooMatrix {

#[cfg(test)]
mod tests {
use crate::{ComplexCooMatrix, CooMatrix, Storage, Symmetry};
use crate::{ComplexCooMatrix, CooMatrix, Storage, Sym};
use num_complex::Complex64;
use russell_lab::cpx;

#[test]
fn assign_capture_errors() {
let sym = Some(Symmetry::General(Storage::Full));
let sym = Some(Sym::General(Storage::Full));
let nnz_a = 1;
let nnz_b = 2; // wrong: must be ≤ nnz_a
let mut a_1x2 = ComplexCooMatrix::new(1, 2, nnz_a, None).unwrap();
Expand Down Expand Up @@ -148,7 +148,7 @@ mod tests {

#[test]
fn augment_capture_errors() {
let sym = Some(Symmetry::General(Storage::Full));
let sym = Some(Sym::General(Storage::Full));
let nnz_a = 1;
let nnz_b = 1;
let mut a_1x2 = ComplexCooMatrix::new(1, 2, nnz_a /* + nnz_b */, None).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions russell_sparse/src/complex_solver_mumps.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{handle_mumps_error_code, mumps_ordering, mumps_scaling};
use super::{ComplexLinSolTrait, ComplexSparseMatrix, LinSolParams, StatsLinSol, Symmetry};
use super::{ComplexLinSolTrait, ComplexSparseMatrix, LinSolParams, StatsLinSol, Sym};
use super::{
MUMPS_ORDERING_AMD, MUMPS_ORDERING_AMF, MUMPS_ORDERING_AUTO, MUMPS_ORDERING_METIS, MUMPS_ORDERING_PORD,
MUMPS_ORDERING_QAMD, MUMPS_ORDERING_SCOTCH, MUMPS_SCALING_AUTO, MUMPS_SCALING_COLUMN, MUMPS_SCALING_DIAGONAL,
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct ComplexSolverMUMPS {
factorized: bool,

/// Holds the symmetry type used in the initialize
initialized_symmetry: Symmetry,
initialized_symmetry: Sym,

/// Holds the matrix dimension saved in initialize
initialized_ndim: usize,
Expand Down Expand Up @@ -161,7 +161,7 @@ impl ComplexSolverMUMPS {
solver,
initialized: false,
factorized: false,
initialized_symmetry: Symmetry::No,
initialized_symmetry: Sym::No,
initialized_ndim: 0,
initialized_nnz: 0,
effective_ordering: -1,
Expand Down Expand Up @@ -455,7 +455,7 @@ impl ComplexLinSolTrait for ComplexSolverMUMPS {
#[cfg(test)]
mod tests {
use super::*;
use crate::{ComplexCooMatrix, ComplexSparseMatrix, LinSolParams, Ordering, Samples, Scaling, Storage, Symmetry};
use crate::{ComplexCooMatrix, ComplexSparseMatrix, LinSolParams, Ordering, Samples, Scaling, Storage, Sym};
use num_complex::Complex64;
use russell_lab::{complex_approx_eq, complex_vec_approx_eq, cpx, ComplexVector};
use serial_test::serial;
Expand Down Expand Up @@ -492,7 +492,7 @@ mod tests {
solver.factorize(&mut mat, None).err(),
Some("the COO matrix must have at least one non-zero value")
);
let mut coo = ComplexCooMatrix::new(1, 1, 1, Some(Symmetry::General(Storage::Full))).unwrap();
let mut coo = ComplexCooMatrix::new(1, 1, 1, Some(Sym::General(Storage::Full))).unwrap();
coo.put(0, 0, cpx!(4.0, 4.0)).unwrap();
let mut mat = ComplexSparseMatrix::from_coo(coo);
assert_eq!(
Expand All @@ -508,7 +508,7 @@ mod tests {
// ... factorize once => OK
solver.factorize(&mut mat, None).unwrap();
// ... change matrix (symmetry)
let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap();
let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Sym::General(Storage::Full))).unwrap();
coo.put(0, 0, cpx!(1.0, 0.0)).unwrap();
coo.put(1, 1, cpx!(2.0, 0.0)).unwrap();
let mut mat = ComplexSparseMatrix::from_coo(coo);
Expand Down Expand Up @@ -576,7 +576,7 @@ mod tests {
);
// wrong symmetry
let rhs = ComplexVector::new(2);
let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap();
let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Sym::General(Storage::Full))).unwrap();
coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap();
coo_wrong.put(1, 1, cpx!(456.0, 2.0)).unwrap();
let mut mat_wrong = ComplexSparseMatrix::from_coo(coo_wrong);
Expand Down Expand Up @@ -658,7 +658,7 @@ mod tests {
complex_vec_approx_eq(x_again.as_data(), x_correct, 1e-14);

// solve with positive-definite matrix works
let sym = Some(Symmetry::PositiveDefinite(Storage::Lower));
let sym = Some(Sym::PositiveDefinite(Storage::Lower));
let nrow = 5;
let ncol = 5;
let mut coo_pd_lower = ComplexCooMatrix::new(nrow, ncol, 9, sym).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions russell_sparse/src/complex_solver_umfpack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{handle_umfpack_error_code, umfpack_ordering, umfpack_scaling};
use super::{ComplexLinSolTrait, ComplexSparseMatrix, LinSolParams, StatsLinSol, Symmetry};
use super::{ComplexLinSolTrait, ComplexSparseMatrix, LinSolParams, StatsLinSol, Sym};
use super::{
UMFPACK_ORDERING_AMD, UMFPACK_ORDERING_BEST, UMFPACK_ORDERING_CHOLMOD, UMFPACK_ORDERING_METIS,
UMFPACK_ORDERING_NONE, UMFPACK_SCALE_MAX, UMFPACK_SCALE_NONE, UMFPACK_SCALE_SUM, UMFPACK_STRATEGY_AUTO,
Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct ComplexSolverUMFPACK {
factorized: bool,

/// Holds the symmetry type used in initialize
initialized_symmetry: Symmetry,
initialized_symmetry: Sym,

/// Holds the matrix dimension saved in initialize
initialized_ndim: usize,
Expand Down Expand Up @@ -152,7 +152,7 @@ impl ComplexSolverUMFPACK {
solver,
initialized: false,
factorized: false,
initialized_symmetry: Symmetry::No,
initialized_symmetry: Sym::No,
initialized_ndim: 0,
initialized_nnz: 0,
effective_strategy: -1,
Expand Down Expand Up @@ -456,7 +456,7 @@ mod tests {
// ... factorize once => OK
solver.factorize(&mut mat, None).unwrap();
// ... change matrix (symmetry)
let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap();
let mut coo = ComplexCooMatrix::new(2, 2, 2, Some(Sym::General(Storage::Full))).unwrap();
coo.put(0, 0, cpx!(1.0, 0.0)).unwrap();
coo.put(1, 1, cpx!(2.0, 0.0)).unwrap();
let mut mat = ComplexSparseMatrix::from_coo(coo);
Expand Down Expand Up @@ -549,7 +549,7 @@ mod tests {
);
// wrong symmetry
let rhs = ComplexVector::new(2);
let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Symmetry::General(Storage::Full))).unwrap();
let mut coo_wrong = ComplexCooMatrix::new(2, 2, 2, Some(Sym::General(Storage::Full))).unwrap();
coo_wrong.put(0, 0, cpx!(123.0, 1.0)).unwrap();
coo_wrong.put(1, 1, cpx!(456.0, 2.0)).unwrap();
let mut mat_wrong = ComplexSparseMatrix::from_coo(coo_wrong);
Expand Down
Loading

0 comments on commit b9a8254

Please sign in to comment.