Index: mttroot/mtt/lib/cc/mtt_implicit.cc ================================================================== --- mttroot/mtt/lib/cc/mtt_implicit.cc +++ mttroot/mtt/lib/cc/mtt_implicit.cc @@ -1,63 +1,7 @@ #include -#include "useful-functions.hh" - #include -static inline int -result_ok (int info, double rcond, int warn = 1) -{ - assert (info != -1); - - if (info == -2) - { - if (warn) - warning ("matrix singular to machine precision, rcond = %g", rcond); - else - error ("matrix singular to machine precision, rcond = %g", rcond); - - return 0; - } - else - return 1; -} -bool -mx_leftdiv_conform (const Matrix& a, const ColumnVector& b) -{ - int a_nr = a.rows (); - int b_nr = b.length (); - - if (a_nr != b_nr) - { - int a_nc = a.cols (); - int b_nc = 1; - - gripe_nonconformant ("operator \\", a_nr, a_nc, b_nr, b_nc); - return false; - } - - return true; -} - -// need to update xdiv.cc ? -inline ColumnVector -ldiv (const Matrix &a, const ColumnVector &b) -{ - if (! mx_leftdiv_conform (a, b)) - return ColumnVector (); - - int info; - if (a.rows () == a.columns ()) - { - double rcond = 0.0; - ColumnVector result = a.solve (b, info, rcond); - if (result_ok (info, rcond)) - return result; - } - - int rank; - return a.lssolve (b, info, rank); -} #ifdef STANDALONE ColumnVector Fmtt_implicit ( ColumnVector &x, const ColumnVector &dx, const Matrix &AA, @@ -100,21 +44,21 @@ { n--; } } - static ColumnVector tmp_dx (n); - static ColumnVector tmp_x (n); - static ColumnVector tmp_AAx (n); - static Matrix tmp_AA (n, n); + static Matrix tmp_dx (n,1); + static Matrix tmp_x (n,1); + static Matrix tmp_AAx (n,1); + static Matrix tmp_AA (n,n); for (row_new = row_old = 0; row_old < Nx; row_old++) { if (0 == openx (row_old)) { - tmp_dx (row_new) = dx (row_old); - tmp_AAx (row_new) = AAx (row_old); + tmp_dx (row_new,0) = dx (row_old); + tmp_AAx (row_new,0) = AAx (row_old); for (col_new = col_old = 0; col_old < Nx; col_old++) { if (0 == openx (col_old)) { // xxx: this can be improved by symmetry @@ -124,20 +68,18 @@ } row_new++; } } - // can't get ldiv to work - doesn't like ColVector - // tmp_x = tmp_AA.pseudo_inverse () * tmp_AAx + t * tmp_dx; - tmp_x = ldiv (tmp_AA, (tmp_AAx + t * tmp_dx)); + tmp_x = xleftdiv (tmp_AA, (tmp_AAx + tmp_dx * t)); row_new = 0; for (row_old = 0; row_old < Nx; row_old++) { if (0 == openx (row_old)) { - x (row_old) = tmp_x (row_new); + x (row_old) = tmp_x (row_new,0); row_new++; } else { x (row_old) = 0.0;