00001 #ifndef DISTRIBUTEDMATRIXBUILDER_H
00002 #define DISTRIBUTEDMATRIXBUILDER_H
00003
00004 #include "SundanceDefs.h"
00005
00006 #include "WeakForm.h"
00007 #include "TSFRBTree.h"
00008 #include "DistributedDOFMap.h"
00009 #include "TSFSmartPtr.h"
00010 #include "CellType.h"
00011 #include "Mesh.h"
00012 #include "EssentialBC.h"
00013 #include "EquationSet.h"
00014 #include "TSFVector.h"
00015 #include "TSFHashtable.h"
00016 #include "WorkSet.h"
00017 #include "CellBlock.h"
00018 #include "TSFMatrixOperator.h"
00019 #include "TSFMultiVectorOperator.h"
00020 #include "TSFTimeMonitor.h"
00021
00022 namespace Sundance
00023 {
00024
00025 using namespace TSF;
00026 using std::string;
00027
00028 using std::ostream;
00029
00030
00031 class LocalMatrix;
00032
00033
00034
00035
00036
00037 class DistributedMatrixBuilder
00038 {
00039 public:
00040
00041 DistributedMatrixBuilder(const Mesh& mesh, const Expr& eqn,
00042 const EssentialBC& bc,
00043 const ExprArray& test, const ExprArray& unk);
00044
00045
00046 void buildMatrix(TSFArray<TSFArray<TSFMatrixOperator*> >& mat,
00047 TSFArray<TSFArray<TSFMultiVectorOperator*> >& mv) const ;
00048
00049
00050
00051 void buildVector(TSFArray<TSFVector>& vec) const ;
00052
00053
00054 void buildGeometricVector(TSFArray<TSFVector>& vec) const ;
00055
00056
00057 void buildParametricVector(TSFArray<TSFVector>& vec) const ;
00058
00059
00060 void buildSoln(int blockCol, const TSFVector& solnVec,
00061 Expr& soln) const ;
00062
00063 void buildRHSExpr(int blockRow, const TSFVector& solnVec,
00064 Expr& soln) const ;
00065
00066
00067 int numBlockRows() const {return var_.length();}
00068
00069
00070 int numBlockCols() const {return unk_.length();}
00071
00072
00073 bool needsMatrixConfiguration(int blockRow, int blockCol) const
00074 {return needsMatrixConfiguration_[blockRow][blockCol];}
00075
00076
00077 void flushConfiguration();
00078
00079
00080 TSFVectorSpace createRowSpace(int blockRow,
00081 const TSFVectorType& vt) const ;
00082
00083
00084 TSFVectorSpace createColumnSpace(int blockCol,
00085 const TSFVectorType& vt) const ;
00086
00087
00088
00089 bool isZeroBlock(int blockRow, int blockCol) const
00090 {return eqnSet_.isZeroBlock(blockRow, blockCol);}
00091
00092
00093 void printRowMaps() const ;
00094
00095
00096 void printColumnMaps() const ;
00097
00098
00099 void showGraph(ostream& os) const ;
00100
00101
00102 void showBCRows(ostream& os) const ;
00103
00104
00105 static void verboseMatrixInsertion() {verboseMatrixInsertion_=true;}
00106
00107
00108 static void verboseMatrixAssembly() {verboseMatrixAssembly_=true;}
00109
00110
00111 static void verboseVectorInsertion() {verboseVectorInsertion_=true;}
00112
00113
00114 static void verboseVectorAssembly() {verboseVectorAssembly_=true;}
00115
00116
00117 static void quietMatrixInsertion() {verboseMatrixInsertion_=false;}
00118
00119
00120 static void quietVectorInsertion() {verboseVectorInsertion_=false;}
00121
00122
00123 static int& workSetSize() {static int wss=-1; return wss;}
00124
00125 private:
00126
00127
00128 void init();
00129
00130
00131 void configureMatrix(int blockRow, int blockCol,
00132 TSFMatrixOperator* mat) const ;
00133
00134
00135 void getGraph(int blockRow, int blockCol,
00136 TSFArray<TSFNonDupArray<int> >& columnIndices) const ;
00137
00138
00139
00140 void getMarkedRows(int blockRow,
00141 const TSFArray<int>& globalRowIndex,
00142 TSFArray<bool>& isUpdate,
00143 TSFArray<bool>& isBC) const ;
00144
00145
00146 void setBCRows(int blockRow,
00147 const TSFArray<int>& globalRowIndex);
00148
00149
00150
00151 void insertLocalMatrix(bool isParametricRow,
00152 bool isParametricCol,
00153 int blockRow, int blockCol, int cellDim,
00154 int cellIndex,
00155 const WeakForm& wf,
00156 const LocalMatrix& localMat,
00157 TSFMatrixOperator* mat,
00158 TSFMultiVectorOperator* mv) const ;
00159
00160
00161
00162 void insertLocalVector(int blockRow, int cellDim,
00163 int cellIndex,
00164 const WeakForm& wf,
00165 const DenseSerialVector& localVec,
00166 TSFVector& vec) const ;
00167
00168
00169
00170 void insertLocalMatrixBatch(int blockRow, int blockCol,
00171 const WorkSet& workSet,
00172 const WeakForm& wf,
00173 const TSFArray<LocalMatrix>& localMat,
00174 TSFMatrixOperator* mat,
00175 TSFMultiVectorOperator* mv) const ;
00176
00177
00178
00179 void insertLocalVectorBatch(int blockRow, const WorkSet& workSet,
00180 const WeakForm& wf,
00181 const TSFArray<DenseSerialVector>& localVec,
00182 TSFVector& vec) const ;
00183
00184
00185 void showVectorInsertion(bool isBCTerm, int testID, double coeff,
00186 const TSFArray<int>& rowIndices,
00187 const TSFArray<bool>& isBCRow) const ;
00188
00189
00190 void buildParametricBlocks(TSFArray<TSFArray<TSFMatrixOperator*> >& mat) const ;
00191
00192
00193 void buildParametricVectorBlocks(TSFArray<TSFVector>& vec) const ;
00194
00195
00196 void printGraph(int br, int bc,
00197 const TSFArray<TSFNonDupArray<int> >& graph) const ;
00198
00199 static int defaultWorkSetSize_;
00200
00201 static bool verboseMatrixInsertion_;
00202
00203 static bool verboseVectorInsertion_;
00204
00205 static bool verboseMatrixAssembly_;
00206
00207 static bool verboseVectorAssembly_;
00208
00209 static bool verboseInit_;
00210
00211 ExprArray var_;
00212 ExprArray unk_;
00213
00214 Mesh mesh_;
00215
00216
00217 EquationSet eqnSet_;
00218
00219 TSFArray<AbstractFunctionSpace> rowSpace_;
00220 TSFArray<AbstractFunctionSpace> colSpace_;
00221 TSFArray<TSFSmartPtr<DOFMapBase> > testDOFMap_;
00222 TSFArray<TSFSmartPtr<DOFMapBase> > unkDOFMap_;
00223
00224
00225
00226
00227 TSFArray<TSFArray<bool> > localBCRowTable_;
00228 TSFArray<TSFHashtable<int, bool> > remoteBCRowTable_;
00229
00230 TSFArray<TSFHashtable<CellTopologyCode, TSFSmartPtr<TSFArray<CellBlock> > > > cellBlocks_;
00231 TSFArray<TSFNonDupArray<CellTopologyCode> > cellTypes_;
00232 TSFHashtable<CellTopologyCode, TSFSmartPtr<WorkSet> > workSetTable_;
00233
00234 int workSetSize_;
00235
00236 mutable TSFArray<TSFArray<bool> > needsMatrixConfiguration_;
00237
00238 static TSFTimer& initBuilderTimer();
00239
00240 static TSFTimer& matrixConfigurationTimer();
00241
00242 static TSFTimer& matrixAssemblyTimer();
00243
00244 static TSFTimer& vectorAssemblyTimer();
00245
00246 static TSFTimer& graphAssemblyTimer();
00247
00248 static TSFTimer& matrixInsertionTimer();
00249
00250 static TSFTimer& vectorInsertionTimer();
00251
00252
00253 };
00254
00255
00256
00257
00258
00259 }
00260 #endif
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276