GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
GmNumSolverPrinter Class Reference

A proxy class that can wrap and behave like a GmNumSolver object, adding the possibility for printing and / or saving the linear system matrices and vectors according to the given configuration. This feature was not included directly in the numeric solver API since numeric solvers can be shared between multiple solver processes with different print options. More...

#include <gmNumSolverPrinter.h>

Collaboration diagram for GmNumSolverPrinter:

Public Types

enum  PrintAndSaveOptions {
  GM_NS_PRINT_MATRIX = 0x01 , GM_NS_PRINT_VECTOR = 0x02 , GM_NS_PRINT_RESULT = 0x04 , GM_NS_SAVE_MATRIX = 0x10 ,
  GM_NS_SAVE_VECTOR = 0x20 , GM_NS_SAVE_RESULT = 0x40
}
 Options for printing and saving parts of the linear system Ax = b. More...
 

Public Member Functions

 GmNumSolverPrinter (GmNumSolver *solver)
 Constructor. Receives as parameter the wrapped solver object.
 
GmNumSolversolver () const
 Returns the wrapped numeric solver.
 
void setPrintAndSaveOptions (int options, QString baseFileName, int fieldWidth=0, char format='g', int precision=-1, int filterAttr=-1, const QVector< double > &attrValues=QVector< double >())
 Set print and save options. Options is an or of PrintAndSaveOptions flags. If filterAttr is different from -1, the print or save operation will only be executed if the value of the given filter attribute (from GmRunProgress) is in attrValues (uses GmDoubleCmp::equal() for comparisons). The attribute
should be a numeric attribute that increases with the simulation evolution. The attrValues list MUST be ordered.
 
bool solve (GmSolverMatrix *A, const GmVector &b, GmVector &x, bool xIsGuess=false) const
 Solves the linear system Ax = b, filling the vector x with the calculated result. See comments on GmNumSolver::solve().
 
GmSolverMatrixnewMatrix (int nlin, int ncol, const GmSolverMatrix *sharedLayout, int numThreads=-1) const
 
QString id () const
 
QString description () const
 
QString pluginTypeName () const
 
const char * pluginCategory () const
 
const char * pluginName () const
 
const char * pluginType () const
 
bool setSolverTolerance (double tol)
 
QString quickDescription () const
 
int trackItemId () const
 
void printParameters (const GmLogCategory &logger)
 

Private Member Functions

void printAndSave (const GmSolverMatrix *A, const GmVector &b, QString filterStr) const
 Prints / saves the linear system A and b terms, depending on the configuration.
 
void printAndSave (const GmVector &x, QString filterStr) const
 Prints / saves the linear system x term, depending on the configuration.
 
bool saveMatrix (FILE *f, const GmSolverMatrix *A, bool extended) const
 Saves the matrix vector contents to the given file using Matrix market format. If extended is true, adjusts the header for saving a vector afterwards.
 
bool saveVector (FILE *f, const GmVector &v, bool header) const
 Saves the given vector contents to the given file using Matrix market format. The header will only be saved if header is true.
 
bool checkPrintAndSaveFilter (QString &filterStr) const
 Returns true if the current Linear system should be printed / saved. In that case, if there is a filter, fills filterStr with the file name suffix for the applied filter.
 

Private Attributes

GmNumSolver_solver
 The wrapped solver object.
 
int _psOptions
 Print and save options. An or of PrintAndSaveOptions flags

 
int _printFieldWidth
 Print format parameter: The matrix column minimum width.
 
char _printFormat
 Print format parameter: The format type f' or 'g'.
 
int _printPrecision
 Print format parameter: The number of decimal places.
 
QString _saveBaseFileName
 The base file name for saving.
 
int _saveIndex
 The unique index used to guarantee file name unicity.
 
int _psFilterAttr
 The print and save filter attribute, -1 for no filtering.
 
QVector< double > _psAttrValues
 The sorted list of attribute values for printing and saving when the filter is active.
 
QString _psFilterSuffix
 The file suffix with the name of the active filter attribute (with : characters converted to -)
 
int _nextAttrValIndex
 The index in _psAttrValues of the next attr value for the save / print filter.
 

Detailed Description

A proxy class that can wrap and behave like a GmNumSolver object, adding the possibility for printing and / or saving the linear system matrices and vectors according to the given configuration. This feature was not included directly in the numeric solver API since numeric solvers can be shared between multiple solver processes with different print options.

Member Enumeration Documentation

◆ PrintAndSaveOptions

Options for printing and saving parts of the linear system Ax = b.

Enumerator
GM_NS_PRINT_MATRIX 

Should we print the A matrix before solving?

GM_NS_PRINT_VECTOR 

Should we print the b vector before solving?

GM_NS_PRINT_RESULT 

Should we print the x vector after solving?

GM_NS_SAVE_MATRIX 

Should we save to a file the A matrix before solving?

GM_NS_SAVE_VECTOR 

Should we save to a file the b vector before solving?

GM_NS_SAVE_RESULT 

Should we save to a file the x vector after solving?

Member Function Documentation

◆ setPrintAndSaveOptions()

void GmNumSolverPrinter::setPrintAndSaveOptions ( int options,
QString baseFileName,
int fieldWidth = 0,
char format = 'g',
int precision = -1,
int filterAttr = -1,
const QVector< double > & attrValues = QVector<double>() )

Set print and save options. Options is an or of PrintAndSaveOptions flags. If filterAttr is different from -1, the print or save operation will only be executed if the value of the given filter attribute (from GmRunProgress) is in attrValues (uses GmDoubleCmp::equal() for comparisons). The attribute
should be a numeric attribute that increases with the simulation evolution. The attrValues list MUST be ordered.

When printing, the given fieldWidth, format and precision parameters control the format for printing each matrix / vector entry (for file saving, full precision is always used).

When saving, the matrix market format is used. If both A and b are selected for saving, they will be written to the same file in extended matrix market format. The result vector is always saved in a separate file. The base file name can have path attributes but should not contain an extension. The saved file name will be: base_count[_filter_val]["_result"].mtx where base is the baseFileName, count is an integer that increments at each saved file, filter is the filter attribute name and val is the attribute value. When saving the result vector, the "_result" suffix will be added.

◆ solve()

bool GmNumSolverPrinter::solve ( GmSolverMatrix * A,
const GmVector & b,
GmVector & x,
bool xIsGuess = false ) const

Solves the linear system Ax = b, filling the vector x with the calculated result. See comments on GmNumSolver::solve().

If configured through setPrintAndSaveOptions(), matrices will be printed and / or saved to disk.


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