MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
RowMaxColMaxMatrixScale< T > Class Template Reference

#include <dgeequ.h>

Inheritance diagram for RowMaxColMaxMatrixScale< T >:
Collaboration diagram for RowMaxColMaxMatrixScale< T >:

Public Member Functions

 RowMaxColMaxMatrixScale (const SolutionManager::ScaleOpt &scale)
 
virtual ~RowMaxColMaxMatrixScale ()
 
- Public Member Functions inherited from MatrixScale< T >
 MatrixScale (const SolutionManager::ScaleOpt &scale)
 
virtual ~MatrixScale ()
 
T & ScaleMatrix (T &mh) const
 
bool ComputeScaleFactors (const T &mh)
 
- Public Member Functions inherited from MatrixScaleBase
 MatrixScaleBase (const SolutionManager::ScaleOpt &scale)
 
virtual ~MatrixScaleBase ()
 
VectorHandlerScaleRightHandSide (VectorHandler &bVH) const
 
VectorHandlerScaleSolution (VectorHandler &xVH) const
 
std::ostream & Report (std::ostream &os) const
 
const std::vector< doublereal > & GetRowScale () const
 
const std::vector< doublereal > & GetColScale () const
 
bool bGetInitialized () const
 

Protected Member Functions

virtual bool ComputeScaleFactors (const T &mh, std::vector< doublereal > &rowScale, std::vector< doublereal > &colScale)
 
virtual std::ostream & vReport (std::ostream &os) const
 
- Protected Member Functions inherited from MatrixScaleBase
MatrixHandler::Norm_t GetCondNumNorm () const
 
void Prepare (const MatrixHandler &mh, integer &nrows, integer &ncols)
 
void PrepareRows (const MatrixHandler &mh, integer &nrows)
 
void PrepareCols (const MatrixHandler &mh, integer &ncols)
 
bool bReport () const
 

Private Attributes

const doublereal dTol
 
doublereal maxNormRow
 
doublereal maxNormCol
 
std::vector< doublerealnormRow
 
std::vector< doublerealnormCol
 

Additional Inherited Members

- Static Public Member Functions inherited from MatrixScale< T >
static MatrixScale< T > * Allocate (const SolutionManager::ScaleOpt &scale)
 
- Protected Attributes inherited from MatrixScaleBase
std::vector< doublerealrowScale
 
std::vector< doublerealcolScale
 
doublereal dCondBefore
 
doublereal dCondAfter
 
const unsigned uFlags
 
bool bOK
 

Detailed Description

template<typename T>
class RowMaxColMaxMatrixScale< T >

Definition at line 200 of file dgeequ.h.

Constructor & Destructor Documentation

template<typename T >
RowMaxColMaxMatrixScale< T >::RowMaxColMaxMatrixScale ( const SolutionManager::ScaleOpt scale)
inline

Definition at line 833 of file dgeequ.h.

834 :MatrixScale<T>(scale),
835  dTol(scale.dTol),
836  maxNormRow(-1.),
837  maxNormCol(-1.)
838 {
839 
840 }
doublereal maxNormCol
Definition: dgeequ.h:212
doublereal maxNormRow
Definition: dgeequ.h:212
const doublereal dTol
Definition: dgeequ.h:211
template<typename T >
RowMaxColMaxMatrixScale< T >::~RowMaxColMaxMatrixScale ( )
virtual

Definition at line 843 of file dgeequ.h.

844 {
845 
846 }

Member Function Documentation

template<typename T >
bool RowMaxColMaxMatrixScale< T >::ComputeScaleFactors ( const T &  mh,
std::vector< doublereal > &  rowScale,
std::vector< doublereal > &  colScale 
)
protectedvirtual

Implements MatrixScale< T >.

Definition at line 849 of file dgeequ.h.

References MBDYN_EXCEPT_ARGS.

850 {
851  const integer nrows = mh.iGetNumRows();
852  const integer ncols = mh.iGetNumCols();
853 
854  if (nrows <= 0) {
856  "invalid null or negative row number");
857  }
858 
859  if (ncols <= 0) {
861  "invalid null or negative column number");
862  }
863 
864  if (rowScale.empty()) {
865  rowScale.resize(nrows, 1.);
866  normRow.resize(nrows);
867  } else if (rowScale.size() != static_cast<size_t>(nrows)) {
868  throw ErrGeneric(MBDYN_EXCEPT_ARGS, "row number mismatch");
869  }
870 
871  if (colScale.empty()) {
872  colScale.resize(ncols, 1.);
873  normCol.resize(ncols);
874  } else if (colScale.size() != static_cast<size_t>(ncols)) {
875  throw ErrGeneric(MBDYN_EXCEPT_ARGS, "column number mismatch");
876  }
877 
878  std::fill(normRow.begin(), normRow.end(), 0.);
879 
880  for (typename T::const_iterator im = mh.begin(); im != mh.end(); ++im) {
881  doublereal d = im->dCoef;
882 
883  if (d == 0.) {
884  continue;
885  }
886 
887  d = std::abs(d);
888 
889  if (d > normRow[im->iRow]) {
890  normRow[im->iRow] = d;
891  }
892  }
893 
894  for (integer i = 0; i < nrows; ++i) {
895  rowScale[i] = 1. / normRow[i];
896  }
897 
898  std::fill(normCol.begin(), normCol.end(), 0.);
899 
900  for (typename T::const_iterator im = mh.begin(); im != mh.end(); ++im) {
901  doublereal d = im->dCoef;
902 
903  if (d == 0.) {
904  continue;
905  }
906 
907  d = std::abs(rowScale[im->iRow] * d);
908 
909  if (d > normCol[im->iCol]) {
910  normCol[im->iCol] = d;
911  }
912  }
913 
914  for (integer i = 0; i < ncols; ++i) {
915  colScale[i] = 1. / normCol[i];
916  }
917 
918  if (!this->bReport()) {
919  // Test for convergence will not be checked
920  // It would be a waste of time to compute the row and column norms
921  return true;
922  }
923 
924  std::fill(normRow.begin(), normRow.end(), 0.);
925  std::fill(normCol.begin(), normCol.end(), 0.);
926 
927  for (typename T::const_iterator im = mh.begin(); im != mh.end(); ++im) {
928  doublereal d = im->dCoef;
929 
930  if (d == 0.) {
931  continue;
932  }
933 
934  d = std::abs(colScale[im->iCol] * rowScale[im->iRow] * d);
935 
936  if (d > normRow[im->iRow]) {
937  normRow[im->iRow] = d;
938  }
939 
940  if (d > normCol[im->iCol]) {
941  normCol[im->iCol] = d;
942  }
943  }
944 
945  maxNormRow = 0.;
946 
947  for (std::vector<doublereal>::const_iterator ir = normRow.begin();
948  ir != normRow.end(); ++ir) {
949  maxNormRow = std::max(maxNormRow, std::abs(1. - *ir));
950  }
951 
952  maxNormCol = 0.;
953 
954  for (std::vector<doublereal>::const_iterator ic = normCol.begin();
955  ic != normCol.end(); ++ic) {
956  maxNormCol = std::max(maxNormCol, std::abs(1. - *ic));
957  }
958 
959  return (maxNormRow < dTol && maxNormCol < dTol);
960 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
bool bReport() const
Definition: dgeequ.h:249
std::vector< doublereal > colScale
Definition: dgeequ.h:68
std::vector< doublereal > normCol
Definition: dgeequ.h:213
std::vector< doublereal > normRow
Definition: dgeequ.h:213
doublereal maxNormCol
Definition: dgeequ.h:212
doublereal maxNormRow
Definition: dgeequ.h:212
std::vector< doublereal > rowScale
Definition: dgeequ.h:68
const doublereal dTol
Definition: dgeequ.h:211
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
template<typename T >
std::ostream & RowMaxColMaxMatrixScale< T >::vReport ( std::ostream &  os) const
protectedvirtual

Implements MatrixScaleBase.

Definition at line 963 of file dgeequ.h.

References MatrixScaleBase::bOK.

964 {
965  if (!MatrixScaleBase::bOK) {
966  os << "Warning: matrix scale did not converge\n";
967  }
968 
969  os << "row scale: " << maxNormRow << std::endl
970  << "col scale: " << maxNormCol << std::endl;
971 
972  return os;
973 }
doublereal maxNormCol
Definition: dgeequ.h:212
doublereal maxNormRow
Definition: dgeequ.h:212

Member Data Documentation

template<typename T >
const doublereal RowMaxColMaxMatrixScale< T >::dTol
private

Definition at line 211 of file dgeequ.h.

template<typename T >
doublereal RowMaxColMaxMatrixScale< T >::maxNormCol
private

Definition at line 212 of file dgeequ.h.

template<typename T >
doublereal RowMaxColMaxMatrixScale< T >::maxNormRow
private

Definition at line 212 of file dgeequ.h.

template<typename T >
std::vector<doublereal> RowMaxColMaxMatrixScale< T >::normCol
private

Definition at line 213 of file dgeequ.h.

template<typename T >
std::vector<doublereal> RowMaxColMaxMatrixScale< T >::normRow
private

Definition at line 213 of file dgeequ.h.


The documentation for this class was generated from the following file: