fei_Aztec_LinSysCore.hpp

00001 #ifndef _fei_Aztec_LinSysCore_hpp_
00002 #define _fei_Aztec_LinSysCore_hpp_
00003 
00004 /*--------------------------------------------------------------------*/
00005 /*    Copyright 2005 Sandia Corporation.                              */
00006 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00007 /*    non-exclusive license for use of this work by or on behalf      */
00008 /*    of the U.S. Government.  Export of this program may require     */
00009 /*    a license from the United States Government.                    */
00010 /*--------------------------------------------------------------------*/
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_defs.h>
00014 #include <fei_Data.hpp>
00015 #include <fei_LinearSystemCore.hpp>
00016 
00017 #include <string>
00018 #include <map>
00019 
00020 #include <az_aztec.h>
00021 
00022 //
00023 //This is the Aztec implementation of LinSysCore.
00024 //
00025 namespace fei_trilinos {
00026 
00027 class Aztec_Map;
00028 class Aztec_BlockMap;
00029 class Aztec_Vector;
00030 class AztecDMSR_Matrix;
00031 class AztecDVBR_Matrix;
00032 
00033 class Aztec_LinSysCore: public LinearSystemCore {
00034  public:
00035    Aztec_LinSysCore(MPI_Comm comm);
00036    virtual ~Aztec_LinSysCore();
00037 
00038    //for creating another instance of LinearSystemCore without knowing
00039    //the run-time type of 'this' one.
00040    LinearSystemCore* clone();
00041 
00042    //int parameters:
00043    //for setting generic argc/argv style parameters.
00044 
00045    int parameters(int numParams, const char*const * params);
00046 
00047    int setLookup(Lookup& lookup);
00048 
00049    int setGlobalOffsets(int len, int* nodeOffsets, int* eqnOffsets,
00050                                  int* blkEqnOffsets);
00051 
00052    int setConnectivities(GlobalID elemBlock,
00053                           int numElements,
00054                           int numNodesPerElem,
00055                           const GlobalID* elemIDs,
00056                           const int* const* connNodes) ;
00057 
00058    int setStiffnessMatrices(GlobalID,
00059           int,
00060           const GlobalID*,
00061           const double *const *const *,
00062           int,
00063           const int *const *)
00064      { return(0); }
00065 
00066    int setLoadVectors(GlobalID,
00067           int,
00068           const GlobalID*,
00069           const double *const *,
00070           int,
00071           const int *const *)
00072      { return(0); }
00073 
00074    int setMatrixStructure(int** ptColIndices,
00075                            int* ptRowLengths,
00076                            int** blkColIndices,
00077                            int* blkRowLengths,
00078                            int* ptRowsPerBlkRow) ;
00079 
00080    int setMultCREqns(int,
00081          int, int,
00082          int**, int**,
00083          int*,
00084          int*)
00085      { return(0); }
00086 
00087    int setPenCREqns(int,
00088          int, int,
00089          int**, int**,
00090          int*)
00091      { return(0); }
00092 
00093    //int resetMatrixAndVector:
00094    //don't destroy the structure of the matrix, but set the value 's'
00095    //throughout the matrix and vectors.
00096 
00097    int resetMatrixAndVector(double s);
00098    int resetMatrix(double s);
00099    int resetRHSVector(double s);
00100 
00101    //int sumIntoSystemMatrix:
00102    //this is the primary assembly function. The coefficients 'values'
00103    //are to be accumumlated into (added to any values already in place)
00104    //global (0-based) equations in 'ptRows' of the matrix.
00105 
00106    int sumIntoSystemMatrix(int numPtRows, const int* ptRows,
00107                             int numPtCols, const int* ptCols,
00108                             int numBlkRows, const int* blkRows,
00109                             int numBlkCols, const int* blkCols,
00110                             const double* const* values);
00111 
00112    int sumIntoSystemMatrix(int numPtRows, const int* ptRows,
00113                             int numPtCols, const int* ptCols,
00114                             const double* const* values);
00115    int putIntoSystemMatrix(int numPtRows, const int* ptRows,
00116                             int numPtCols, const int* ptCols,
00117                             const double* const* values);
00118 
00119    int getMatrixRowLength(int row, int& length);
00120 
00121    int getMatrixRow(int row, double* coefs, int* indices,
00122                             int len, int& rowLength);
00123 
00124    //int sumIntoRHSVector:
00125    //this is the rhs vector equivalent to sumIntoSystemMatrix above.
00126 
00127    int sumIntoRHSVector(int num,
00128                           const double* values,
00129                           const int* indices);
00130    int putIntoRHSVector(int num,
00131                           const double* values,
00132                           const int* indices);
00133    int getFromRHSVector(int num,
00134                           double* values,
00135                           const int* indices);
00136 
00137    //int matrixLoadComplete:
00138    //do any internal synchronization/communication.
00139 
00140    int matrixLoadComplete();
00141    
00142    //functions for enforcing boundary conditions.
00143    int enforceEssentialBC(int* globalEqn,
00144                            double* alpha,
00145                            double* gamma, int len);
00146 
00147    int enforceBlkEssentialBC(int* blkEqn, int* blkOffset,
00148                               double* alpha, double* gamma,
00149                               int len);
00150 
00151    int enforceRemoteEssBCs(int numEqns, int* globalEqns,
00152                             int** colIndices, int* colIndLen,
00153                             double** coefs);
00154 
00155    int enforceBlkRemoteEssBCs(int numEqns, int* blkEqns,
00156                                int** blkColInds, int** blkColOffsets,
00157                                int* blkColLens, double** remEssBCCoefs);
00158 
00159    //functions for getting/setting matrix or vector pointers.
00160 
00161    //getMatrixPtr:
00162    //obtain a pointer to the 'A' matrix. This should be considered a
00163    //constant pointer -- i.e., this class remains responsible for the
00164    //matrix (e.g., de-allocation upon destruction). 
00165    int getMatrixPtr(Data& data);
00166 
00167    //copyInMatrix:
00168    //replaces the internal matrix with a copy of the input argument, scaled
00169    //by the coefficient 'scalar'.
00170 
00171    int copyInMatrix(double scalar, const Data& data);
00172 
00173    //copyOutMatrix:
00174    //passes out a copy of the internal matrix, scaled by the coefficient
00175    //'scalar'.
00176 
00177    int copyOutMatrix(double scalar, Data& data);
00178 
00179    //sumInMatrix:
00180    //accumulate (sum) a copy of the input argument into the internal
00181    //matrix, scaling the input by the coefficient 'scalar'.
00182 
00183    int sumInMatrix(double scalar, const Data& data);
00184 
00185    //get/setRHSVectorPtr:
00186    //the same semantics apply here as for the matrixPtr functions above.
00187 
00188    int getRHSVectorPtr(Data& data);
00189 
00190    //copyInRHSVector/copyOutRHSVector/sumInRHSVector:
00191    //the same semantics apply here as for the matrix functions above.
00192 
00193    int copyInRHSVector(double scalar, const Data& data);
00194    int copyOutRHSVector(double scalar, Data& data);
00195    int sumInRHSVector(double scalar, const Data& data);
00196 
00197    //destroyMatrixData/destroyVectorData:
00198    //Utility function for destroying the matrix (or vector) in Data
00199 
00200    int destroyMatrixData(Data& data);
00201    int destroyVectorData(Data& data);
00202 
00203    //functions for managing multiple rhs vectors
00204    int setNumRHSVectors(int numRHSs, const int* rhsIDs);
00205 
00206    //int setRHSID:
00207    //set the 'current' rhs context, assuming multiple rhs vectors.
00208    int setRHSID(int rhsID);
00209 
00210    //int putInitialGuess:
00211    //function for setting (a subset of) the initial-guess
00212    //solution values (i.e., in the 'x' vector).
00213 
00214    int putInitialGuess(const int* eqnNumbers, const double* values,
00215                         int len);
00216 
00217    //function for getting all of the answers ('x' vector).
00218    int getSolution(double* answers, int len);
00219 
00220    //function for getting the (single) entry at equation
00221    //number 'eqnNumber'.
00222    int getSolnEntry(int eqnNumber, double& answer);
00223 
00224    //function for obtaining the residual vector (using current solution or
00225    //initial guess)
00226    int formResidual(double* values, int len);
00227 
00228    //function for launching the linear solver
00229    int launchSolver(int& solveStatus, int& iterations);
00230 
00231    int putNodalFieldData(int, int, int*, int, const double*)
00232      { return(0); }
00233 
00234    int writeSystem(const char* name);
00235 
00236  private:        //functions
00237 
00238    int createMiscStuff();
00239 
00240    int allocateMatrix(int** ptColIndices, int* ptRowLengths,
00241                        int** blkColIndices, int* blkRowLengths,
00242                        int* ptRowsPerBlkRow);
00243 
00244    int VBRmatPlusScaledMat(AztecDVBR_Matrix* A, double scalar,
00245                             AztecDVBR_Matrix* source);
00246 
00247    int MSRmatPlusScaledMat(AztecDMSR_Matrix* A, double scalar,
00248                             AztecDMSR_Matrix* source);
00249 
00250    int createBlockMatrix(int** blkColIndices,
00251                           int* blkRowLengths,
00252                           int* ptRowsPerBlkRow);
00253 
00254    int sumIntoBlockRow(int numBlkRows, const int* blkRows,
00255                         int numBlkCols, const int* blkCols,
00256                         const double* const* values,
00257                         int numPtCols,
00258            bool overwriteInsteadOfAccumulate);
00259 
00260    int copyBlockRow(int i, const int* blkRows,
00261                      int numBlkCols, const int* blkCols,
00262                      const double* const* values,
00263                      double* coefs);
00264 
00265    int modifyRHSforBCs();
00266 
00267    int explicitlySetDirichletBCs();
00268 
00269    int blockRowToPointRow(int blkRow);
00270 
00271    int getBlockRow(int blkRow, double*& val, int& valLen,
00272                    int*& blkColInds, int& blkColIndLen,
00273                    int& numNzBlks, int& numNNZ);
00274 
00275    int getBlkEqnsAndOffsets(int* ptEqns, int* blkEqns, int* blkOffsets,
00276                              int numEqns);
00277 
00278    int getBlockSize(int blkInd);
00279 
00280    int sumIntoPointRow(int numPtRows, const int* ptRows,
00281            int numPtCols, const int* ptColIndices,
00282            const double* const* values,
00283            bool overwriteInsteadOfAccumulate);
00284 
00285    int sumPointIntoBlockRow(int blkRow, int rowOffset,
00286           int blkCol, int colOffset, double value);
00287 
00288    int setMatrixType(const char* name);
00289    int selectSolver(const char* name);
00290    int selectPreconditioner(const char* name);
00291    void setSubdomainSolve(const char* name);
00292    void setScalingOption(const char* param);
00293    void setConvTest(const char* param);
00294    void setPreCalc(const char* param);
00295    void setTypeOverlap(const char* param);
00296    void setOverlap(const char* param);
00297    void setOrthog(const char* param);
00298    void setAuxVec(const char* param);
00299    void setAZ_output(const char* param);
00300 
00301    void recordUserParams();
00302 
00303    void checkForParam(const char* paramName, int numParams_,
00304                       char** paramStrings,
00305                       double& param);
00306 
00307    void recordUserOptions();
00308 
00309    void checkForOption(const char* paramName, int numParams_,
00310                        char** paramStrings,
00311                        int& param);
00312 
00313    int blkRowEssBCMod(int blkEqn, int blkOffset, double* val, int* blkCols,
00314                         int numCols, int numPtNNZ, double alpha, double gamma);
00315 
00316    int blkColEssBCMod(int blkRow, int blkEqn, int blkOffset, double* val,
00317                       int* blkCols,
00318                       int numCols, int numPtNNZ, double alpha, double gamma);
00319 
00320    void setDebugOutput(const char* path, const char* name);
00321 
00322    void debugOutput(const char* msg) const;
00323 
00324    int writeA(const char* name);
00325    int writeVec(Aztec_Vector* v, const char* name);
00326 
00327    int messageAbort(const char* msg) const;
00328 
00329  private:            //variables
00330 
00331    MPI_Comm comm_;
00332 
00333    Lookup* lookup_;
00334    bool haveLookup_;
00335 
00336    int numProcs_;
00337    int thisProc_;
00338    int masterProc_;
00339 
00340    int* update_;
00341    Aztec_Map *map_;
00342    AztecDMSR_Matrix *A_;
00343    AztecDMSR_Matrix *A_ptr_;
00344    Aztec_Vector *x_, **b_, *bc_;
00345    int* essBCindices_;
00346    int numEssBCs_;
00347    bool bcsLoaded_;
00348    bool explicitDirichletBCs_;
00349    Aztec_Vector *b_ptr_;
00350    bool matrixAllocated_;
00351    bool vectorsAllocated_;
00352    bool blkMatrixAllocated_;
00353    bool matrixLoaded_;
00354    bool rhsLoaded_;
00355    bool needNewPreconditioner_;
00356 
00357    bool tooLateToChooseBlock_;
00358    bool blockMatrix_;
00359    Aztec_BlockMap* blkMap_;
00360    AztecDVBR_Matrix *blkA_;
00361    AztecDVBR_Matrix *blkA_ptr_;
00362    int* blkUpdate_;
00363 
00364    AZ_MATRIX *azA_;
00365    AZ_PRECOND *azP_;
00366    bool precondCreated_;
00367    AZ_SCALING *azS_;
00368    bool scalingCreated_;
00369 
00370    int *aztec_options_;
00371    double *aztec_params_;
00372    double *aztec_status_;
00373 
00374    double* tmp_x_;
00375    bool tmp_x_touched_;
00376    double** tmp_b_;
00377    double* tmp_bc_;
00378    bool tmp_b_allocated_;
00379 
00380    bool ML_Vanek_;
00381    int numLevels_;
00382 
00383    int* rhsIDs_;
00384    int numRHSs_;
00385 
00386    int currentRHS_;
00387 
00388    int numGlobalEqns_;
00389    int localOffset_;
00390    int numLocalEqns_;
00391 
00392    int numGlobalEqnBlks_;
00393    int localBlkOffset_;
00394    int numLocalEqnBlks_;
00395    int* localBlockSizes_;
00396 
00397    int numNonzeroBlocks_;
00398 
00399    int outputLevel_;
00400    int numParams_;
00401    char** paramStrings_;
00402 
00403    std::string name_;
00404    int debugOutput_;
00405    int debugFileCounter_;
00406    char* debugPath_;
00407    char* debugFileName_;
00408    FILE* debugFile_;
00409 
00410    std::map<std::string,unsigned>& named_solve_counter_;
00411 };
00412 
00413 }//namespace fei_trilinos
00414 
00415 #endif
00416 

Generated on Tue Jul 13 09:27:44 2010 for FEI by  doxygen 1.4.7