LUscalarMatrix.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "LUscalarMatrix.H"
00028 #include "lduMatrix.H"
00029 #include "procLduMatrix.H"
00030 #include "procLduInterface.H"
00031
00032
00033
00034 Foam::LUscalarMatrix::LUscalarMatrix(const scalarSquareMatrix& matrix)
00035 :
00036 scalarSquareMatrix(matrix),
00037 pivotIndices_(n())
00038 {
00039 LUDecompose(*this, pivotIndices_);
00040 }
00041
00042
00043 Foam::LUscalarMatrix::LUscalarMatrix
00044 (
00045 const lduMatrix& ldum,
00046 const FieldField<Field, scalar>& interfaceCoeffs,
00047 const lduInterfaceFieldPtrsList& interfaces
00048 )
00049 {
00050 if (Pstream::parRun())
00051 {
00052 PtrList<procLduMatrix> lduMatrices(Pstream::nProcs());
00053
00054 label lduMatrixi = 0;
00055
00056 lduMatrices.set
00057 (
00058 lduMatrixi++,
00059 new procLduMatrix
00060 (
00061 ldum,
00062 interfaceCoeffs,
00063 interfaces
00064 )
00065 );
00066
00067 if (Pstream::master())
00068 {
00069 for
00070 (
00071 int slave=Pstream::firstSlave();
00072 slave<=Pstream::lastSlave();
00073 slave++
00074 )
00075 {
00076 lduMatrices.set
00077 (
00078 lduMatrixi++,
00079 new procLduMatrix(IPstream(Pstream::scheduled, slave)())
00080 );
00081 }
00082 }
00083 else
00084 {
00085 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00086 procLduMatrix cldum
00087 (
00088 ldum,
00089 interfaceCoeffs,
00090 interfaces
00091 );
00092 toMaster<< cldum;
00093
00094 }
00095
00096 if (Pstream::master())
00097 {
00098 label nCells = 0;
00099 forAll(lduMatrices, i)
00100 {
00101 nCells += lduMatrices[i].size();
00102 }
00103
00104 scalarSquareMatrix m(nCells, nCells, 0.0);
00105 transfer(m);
00106 convert(lduMatrices);
00107 }
00108 }
00109 else
00110 {
00111 label nCells = ldum.lduAddr().size();
00112 scalarSquareMatrix m(nCells, nCells, 0.0);
00113 transfer(m);
00114 convert(ldum, interfaceCoeffs, interfaces);
00115 }
00116
00117 if (Pstream::master())
00118 {
00119 pivotIndices_.setSize(n());
00120 LUDecompose(*this, pivotIndices_);
00121 }
00122 }
00123
00124
00125
00126
00127 void Foam::LUscalarMatrix::convert
00128 (
00129 const lduMatrix& ldum,
00130 const FieldField<Field, scalar>& interfaceCoeffs,
00131 const lduInterfaceFieldPtrsList& interfaces
00132 )
00133 {
00134 const label* __restrict__ uPtr = ldum.lduAddr().upperAddr().begin();
00135 const label* __restrict__ lPtr = ldum.lduAddr().lowerAddr().begin();
00136
00137 const scalar* __restrict__ diagPtr = ldum.diag().begin();
00138 const scalar* __restrict__ upperPtr = ldum.upper().begin();
00139 const scalar* __restrict__ lowerPtr = ldum.lower().begin();
00140
00141 register const label nCells = ldum.diag().size();
00142 register const label nFaces = ldum.upper().size();
00143
00144 for (register label cell=0; cell<nCells; cell++)
00145 {
00146 operator[](cell)[cell] = diagPtr[cell];
00147 }
00148
00149 for (register label face=0; face<nFaces; face++)
00150 {
00151 label uCell = uPtr[face];
00152 label lCell = lPtr[face];
00153
00154 operator[](uCell)[lCell] = lowerPtr[face];
00155 operator[](lCell)[uCell] = upperPtr[face];
00156 }
00157
00158 forAll(interfaces, inti)
00159 {
00160 if (interfaces.set(inti))
00161 {
00162 const lduInterface& interface = interfaces[inti].interface();
00163
00164 const label* __restrict__ ulPtr = interface.faceCells().begin();
00165 const scalar* __restrict__ upperLowerPtr =
00166 interfaceCoeffs[inti].begin();
00167
00168 register label inFaces = interface.faceCells().size()/2;
00169
00170 for (register label face=0; face<inFaces; face++)
00171 {
00172 label uCell = ulPtr[face];
00173 label lCell = ulPtr[face + inFaces];
00174
00175 operator[](uCell)[lCell] -= upperLowerPtr[face + inFaces];
00176 operator[](lCell)[uCell] -= upperLowerPtr[face];
00177 }
00178 }
00179 }
00180
00181
00182 }
00183
00184
00185 void Foam::LUscalarMatrix::convert
00186 (
00187 const PtrList<procLduMatrix>& lduMatrices
00188 )
00189 {
00190 procOffsets_.setSize(lduMatrices.size() + 1);
00191 procOffsets_[0] = 0;
00192
00193 forAll(lduMatrices, ldumi)
00194 {
00195 procOffsets_[ldumi+1] = procOffsets_[ldumi] + lduMatrices[ldumi].size();
00196 }
00197
00198 forAll(lduMatrices, ldumi)
00199 {
00200 const procLduMatrix& lduMatrixi = lduMatrices[ldumi];
00201 label offset = procOffsets_[ldumi];
00202
00203 const label* __restrict__ uPtr = lduMatrixi.upperAddr_.begin();
00204 const label* __restrict__ lPtr = lduMatrixi.lowerAddr_.begin();
00205
00206 const scalar* __restrict__ diagPtr = lduMatrixi.diag_.begin();
00207 const scalar* __restrict__ upperPtr = lduMatrixi.upper_.begin();
00208 const scalar* __restrict__ lowerPtr = lduMatrixi.lower_.begin();
00209
00210 register const label nCells = lduMatrixi.size();
00211 register const label nFaces = lduMatrixi.upper_.size();
00212
00213 for (register label cell=0; cell<nCells; cell++)
00214 {
00215 label globalCell = cell + offset;
00216 operator[](globalCell)[globalCell] = diagPtr[cell];
00217 }
00218
00219 for (register label face=0; face<nFaces; face++)
00220 {
00221 label uCell = uPtr[face] + offset;
00222 label lCell = lPtr[face] + offset;
00223
00224 operator[](uCell)[lCell] = lowerPtr[face];
00225 operator[](lCell)[uCell] = upperPtr[face];
00226 }
00227
00228 const PtrList<procLduInterface>& interfaces =
00229 lduMatrixi.interfaces_;
00230
00231 forAll(interfaces, inti)
00232 {
00233 const procLduInterface& interface = interfaces[inti];
00234
00235 if (interface.myProcNo_ == interface.neighbProcNo_)
00236 {
00237 const label* __restrict__ ulPtr = interface.faceCells_.begin();
00238
00239 const scalar* __restrict__ upperLowerPtr =
00240 interface.coeffs_.begin();
00241
00242 register label inFaces = interface.faceCells_.size()/2;
00243
00244 for (register label face=0; face<inFaces; face++)
00245 {
00246 label uCell = ulPtr[face] + offset;
00247 label lCell = ulPtr[face + inFaces] + offset;
00248
00249 operator[](uCell)[lCell] -= upperLowerPtr[face + inFaces];
00250 operator[](lCell)[uCell] -= upperLowerPtr[face];
00251 }
00252 }
00253 else if (interface.myProcNo_ < interface.neighbProcNo_)
00254 {
00255 const PtrList<procLduInterface>& neiInterfaces =
00256 lduMatrices[interface.neighbProcNo_].interfaces_;
00257
00258 label neiInterfacei = -1;
00259
00260 forAll(neiInterfaces, ninti)
00261 {
00262 if
00263 (
00264 neiInterfaces[ninti].neighbProcNo_
00265 == interface.myProcNo_
00266 )
00267 {
00268 neiInterfacei = ninti;
00269 break;
00270 }
00271 }
00272
00273 if (neiInterfacei == -1)
00274 {
00275 FatalErrorIn("LUscalarMatrix::convert") << exit(FatalError);
00276 }
00277
00278 const procLduInterface& neiInterface =
00279 neiInterfaces[neiInterfacei];
00280
00281 const label* __restrict__ uPtr = interface.faceCells_.begin();
00282 const label* __restrict__ lPtr = neiInterface.faceCells_.begin();
00283
00284 const scalar* __restrict__ upperPtr = interface.coeffs_.begin();
00285 const scalar* __restrict__ lowerPtr = neiInterface.coeffs_.begin();
00286
00287 register label inFaces = interface.faceCells_.size();
00288 label neiOffset = procOffsets_[interface.neighbProcNo_];
00289
00290 for (register label face=0; face<inFaces; face++)
00291 {
00292 label uCell = uPtr[face] + offset;
00293 label lCell = lPtr[face] + neiOffset;
00294
00295 operator[](uCell)[lCell] -= lowerPtr[face];
00296 operator[](lCell)[uCell] -= upperPtr[face];
00297 }
00298 }
00299 }
00300 }
00301
00302
00303 }
00304
00305
00306 void Foam::LUscalarMatrix::printDiagonalDominance() const
00307 {
00308 for (label i=0; i<n(); i++)
00309 {
00310 scalar sum = 0.0;
00311 for (label j=0; j<n(); j++)
00312 {
00313 if (i != j)
00314 {
00315 sum += operator[](i)[j];
00316 }
00317 }
00318 Info<< mag(sum)/mag(operator[](i)[i]) << endl;
00319 }
00320 }
00321
00322
00323
Copyright © 2000-2009 OpenCFD Ltd