1 /******************************************************************************
2  * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other
3  * HYPRE Project Developers. See the top-level COPYRIGHT file for details.
4  *
5  * SPDX-License-Identifier: (Apache-2.0 OR MIT)
6  ******************************************************************************/
7 
8 /***************************************************************************
9   Module:  LLNL_FEI_Matrix.h
10   Purpose: custom implementation of the FEI/Matrix
11  ***************************************************************************/
12 
13 #ifndef _LLNL_FEI_MATRIX_H_
14 #define _LLNL_FEI_MATRIX_H_
15 
16 #include "_hypre_utilities.h"
17 #include "HYPRE.h"
18 
19 /**************************************************************************
20  definition of the class to capture the FEI matrix information
21 ---------------------------------------------------------------------------*/
22 
23 class LLNL_FEI_Matrix
24 {
25    MPI_Comm mpiComm_;
26    int      mypid_;
27    int      outputLevel_;
28 
29    int    localNRows_;
30    int    nConstraints_;
31    int    extNRows_;
32    int    *constrEqns_;
33    int    *globalEqnOffsets_;
34    int    *globalCROffsets_;
35    int    *extColMap_;
36 
37    int    *diagIA_;
38    int    *diagJA_;
39    double *diagAA_;
40    int    *offdIA_;
41    int    *offdJA_;
42    double *offdAA_;
43    double *diagonal_;
44 
45    int    nRecvs_;
46    int    *recvLengs_;
47    int    *recvProcs_;
48    int    *recvProcIndices_;
49    double *dRecvBufs_;
50    double *dExtBufs_;
51 
52    int    nSends_;
53    int    *sendLengs_;
54    int    *sendProcs_;
55    int    *sendProcIndices_;
56    double *dSendBufs_;
57    MPI_Request *mpiRequests_;
58 
59    int    FLAG_PrintMatrix_;
60    int    FLAG_MatrixOverlap_;
61 
62 public :
63 
64    LLNL_FEI_Matrix(MPI_Comm comm);
65    ~LLNL_FEI_Matrix();
66 
67    int     parameters(int numParams, char **paramString);
68 
69    int     resetMatrix(double s);
70 
71    int     setMatrix(int nRows, int *diagIA, int *diagJA, double *diagAA,
72                      int nExtRows, int *colMap, int *offdIA, int *offdJA,
73                      double *offdAA, double *diagonal, int *eqnOffsets,
74                      int *crOffsets);
75 
76    int     setCommPattern(int nRecvs, int *recvLengs, int *recvProcs,
77                           int *recvProcIndices, int nSends, int *sendLengs,
78                           int *sendProcs, int *sendProcIndices);
79 
80    int     setComplete();
81 
82    int     setConstraints(int nConstraints, int *constEqns);
83 
84    int     residualNorm(int whichNorm, double *solnVector, double *rhsVector,
85                         double* norms);
86 
getNumLocalRows()87    int     getNumLocalRows() {return localNRows_;}
getNumExtRows()88    int     getNumExtRows() {return extNRows_;}
getEqnOffsets()89    int     *getEqnOffsets() {return globalEqnOffsets_;}
getMatrixDiagonal()90    double *getMatrixDiagonal() {return diagonal_;}
getLocalMatrix(int * nrows,int ** ia,int ** ja,double ** aa)91    int     getLocalMatrix(int *nrows, int **ia, int **ja, double **aa)
92                          {(*nrows) = localNRows_; (*ia) = diagIA_;
93                           (*ja) = diagJA_; (*aa) = diagAA_; return 0; }
getExtMatrix(int * nrows,int ** ia,int ** ja,double ** aa,int ** map)94    int     getExtMatrix(int *nrows, int **ia, int **ja, double **aa, int **map)
95                          {(*nrows) = extNRows_; (*ia) = offdIA_;
96                           (*ja) = offdJA_; (*aa) = offdAA_;
97                           (*map) = extColMap_; return 0; }
98 
99    void    matvec(double *x, double *y);
100 
101 private:
102    void scatterDData(double *x);
103    void gatherAddDData(double *x);
104    void printMatrix();
105    void matMult(int ANRows, int ANCols, int *AIA, int *AJA, double *AAA,
106                 int BNRows, int BNCols, int *BIA, int *BJA, double *BAA,
107                 int *DNRows, int *DNCols, int **DIA, int **DJA, double **DAA);
108    void exchangeSubMatrices();
109    int  BinarySearch2(int *list, int start, int lsize, int ind);
110    void IntSort(int *list1, int start, int theEnd);
111    void IntSort2(int *list1, int *list2, int start, int theEnd);
112    void IntSort2a(int *list1, double *list2, int start, int theEnd);
113 };
114 
115 #endif /* endif for _LLNL_FEI_MATRIX_H_ */
116 
117