@@ -3,7 +3,7 @@ use crate::{OdeSolverTrait, Params, System, Workspace};
3
3
use russell_lab:: math:: SQRT_6 ;
4
4
use russell_lab:: { complex_vec_zip, cpx, format_fortran, vec_copy, Complex64 , ComplexVector , Vector } ;
5
5
use russell_sparse:: { numerical_jacobian, ComplexCscMatrix , CooMatrix , CscMatrix } ;
6
- use russell_sparse:: { ComplexLinSolver , ComplexSparseMatrix , Genie , LinSolver , SparseMatrix } ;
6
+ use russell_sparse:: { ComplexLinSolver , ComplexSparseMatrix , Genie , LinSolver } ;
7
7
use std:: thread;
8
8
9
9
/// Implements the Radau5 method (Radau IIA) (implicit, order 5, embedded) for ODEs and DAEs
@@ -35,10 +35,10 @@ pub(crate) struct Radau5<'a, A> {
35
35
mass : Option < CooMatrix > ,
36
36
37
37
/// Holds the Jacobian matrix. J = df/dy
38
- jj : SparseMatrix ,
38
+ jj : CooMatrix ,
39
39
40
40
/// Coefficient matrix (for real system). K_real = γ M - J
41
- kk_real : SparseMatrix ,
41
+ kk_real : CooMatrix ,
42
42
43
43
/// Coefficient matrix (for real system). K_comp = (α + βi) M - J
44
44
kk_comp : ComplexSparseMatrix ,
@@ -146,8 +146,8 @@ impl<'a, A> Radau5<'a, A> {
146
146
params,
147
147
system,
148
148
mass,
149
- jj : SparseMatrix :: new_coo ( ndim, ndim, jac_nnz, sym) . unwrap ( ) ,
150
- kk_real : SparseMatrix :: new_coo ( ndim, ndim, nnz, sym) . unwrap ( ) ,
149
+ jj : CooMatrix :: new ( ndim, ndim, jac_nnz, sym) . unwrap ( ) ,
150
+ kk_real : CooMatrix :: new ( ndim, ndim, nnz, sym) . unwrap ( ) ,
151
151
kk_comp : ComplexSparseMatrix :: new_coo ( ndim, ndim, nnz, sym) . unwrap ( ) ,
152
152
solver_real : LinSolver :: new ( params. newton . genie ) . unwrap ( ) ,
153
153
solver_comp : ComplexLinSolver :: new ( params. newton . genie ) . unwrap ( ) ,
@@ -193,8 +193,8 @@ impl<'a, A> Radau5<'a, A> {
193
193
/// Assembles the K_real and K_comp matrices
194
194
fn assemble ( & mut self , work : & mut Workspace , x : f64 , y : & Vector , h : f64 , args : & mut A ) -> Result < ( ) , StrError > {
195
195
// auxiliary
196
- let jj = self . jj . get_coo_mut ( ) . unwrap ( ) ; // J = df/dy
197
- let kk_real = self . kk_real . get_coo_mut ( ) . unwrap ( ) ; // K_real = γ M - J
196
+ let jj = & mut self . jj ; // J = df/dy
197
+ let kk_real = & mut self . kk_real ; // K_real = γ M - J
198
198
let kk_comp = self . kk_comp . get_coo_mut ( ) . unwrap ( ) ; // K_comp = (α + βi) M - J
199
199
200
200
// Jacobian matrix
@@ -258,7 +258,7 @@ impl<'a, A> Radau5<'a, A> {
258
258
fn factorize ( & mut self ) -> Result < ( ) , StrError > {
259
259
self . solver_real
260
260
. actual
261
- . factorize ( & mut self . kk_real , self . params . newton . lin_sol_params ) ?;
261
+ . factorize ( & self . kk_real , self . params . newton . lin_sol_params ) ?;
262
262
self . solver_comp
263
263
. actual
264
264
. factorize ( & mut self . kk_comp , self . params . newton . lin_sol_params )
@@ -270,7 +270,7 @@ impl<'a, A> Radau5<'a, A> {
270
270
let handle_real = scope. spawn ( || {
271
271
self . solver_real
272
272
. actual
273
- . factorize ( & mut self . kk_real , self . params . newton . lin_sol_params )
273
+ . factorize ( & self . kk_real , self . params . newton . lin_sol_params )
274
274
. unwrap ( ) ;
275
275
} ) ;
276
276
let handle_comp = scope. spawn ( || {
@@ -295,9 +295,7 @@ impl<'a, A> Radau5<'a, A> {
295
295
296
296
/// Solves the real and complex linear systems
297
297
fn solve_lin_sys ( & mut self ) -> Result < ( ) , StrError > {
298
- self . solver_real
299
- . actual
300
- . solve ( & mut self . dw0 , & self . kk_real , & self . v0 , false ) ?;
298
+ self . solver_real . actual . solve ( & mut self . dw0 , & self . v0 , false ) ?;
301
299
self . solver_comp
302
300
. actual
303
301
. solve ( & mut self . dw12 , & self . kk_comp , & self . v12 , false ) ?;
@@ -308,10 +306,7 @@ impl<'a, A> Radau5<'a, A> {
308
306
fn solve_lin_sys_concurrently ( & mut self ) -> Result < ( ) , StrError > {
309
307
thread:: scope ( |scope| {
310
308
let handle_real = scope. spawn ( || {
311
- self . solver_real
312
- . actual
313
- . solve ( & mut self . dw0 , & self . kk_real , & self . v0 , false )
314
- . unwrap ( ) ;
309
+ self . solver_real . actual . solve ( & mut self . dw0 , & self . v0 , false ) . unwrap ( ) ;
315
310
} ) ;
316
311
let handle_comp = scope. spawn ( || {
317
312
self . solver_comp
@@ -567,7 +562,7 @@ impl<'a, A> OdeSolverTrait<A> for Radau5<'a, A> {
567
562
}
568
563
569
564
// err := K_real⁻¹ rhs = (γ M - J)⁻¹ rhs (HW-VII p123 Eq.(8.20))
570
- self . solver_real . actual . solve ( err, & self . kk_real , rhs, false ) ?;
565
+ self . solver_real . actual . solve ( err, rhs, false ) ?;
571
566
work. rel_error = rms_norm ( err, & self . scaling ) ;
572
567
573
568
// done with the error estimate
@@ -587,7 +582,7 @@ impl<'a, A> OdeSolverTrait<A> for Radau5<'a, A> {
587
582
for m in 0 ..ndim {
588
583
rhs[ m] = mez[ m] + fpe[ m] ;
589
584
}
590
- self . solver_real . actual . solve ( err, & self . kk_real , rhs, false ) ?;
585
+ self . solver_real . actual . solve ( err, rhs, false ) ?;
591
586
work. rel_error = rms_norm ( err, & self . scaling ) ;
592
587
}
593
588
Ok ( ( ) )
0 commit comments