33 void Foam::GAMGSolver::agglomerateMatrix
35 const label fineLevelIndex,
36 const lduMesh& coarseMesh,
41 const lduMatrix& fineMatrix = matrixLevel(fineLevelIndex);
45 const label nCoarseFaces = agglomeration_.
nFaces(fineLevelIndex);
46 const label nCoarseCells = agglomeration_.
nCells(fineLevelIndex);
52 new lduMatrix(coarseMesh)
54 lduMatrix& coarseMatrix = matrixLevels_[fineLevelIndex];
61 scalarField& coarseDiag = coarseMatrix.diag(nCoarseCells);
73 interfaceLevel(fineLevelIndex);
76 primitiveInterfaceLevels_.set
79 new PtrList<lduInterfaceField>(fineInterfaces.size())
82 PtrList<lduInterfaceField>& coarsePrimInterfaces =
83 primitiveInterfaceLevels_[fineLevelIndex];
92 interfaceLevels_[fineLevelIndex];
95 interfaceLevelsBouCoeffs_.set
98 new FieldField<Field, scalar>(fineInterfaces.size())
100 FieldField<Field, scalar>& coarseInterfaceBouCoeffs =
101 interfaceLevelsBouCoeffs_[fineLevelIndex];
104 interfaceLevelsIntCoeffs_.set
107 new FieldField<Field, scalar>(fineInterfaces.size())
109 FieldField<Field, scalar>& coarseInterfaceIntCoeffs =
110 interfaceLevelsIntCoeffs_[fineLevelIndex];
113 agglomerateInterfaceCoefficients
116 coarseMeshInterfaces,
117 coarsePrimInterfaces,
119 coarseInterfaceBouCoeffs,
120 coarseInterfaceIntCoeffs
132 if (fineMatrix.hasLower())
139 scalarField& coarseUpper = coarseMatrix.upper(nCoarseFaces);
140 scalarField& coarseLower = coarseMatrix.lower(nCoarseFaces);
142 forAll(faceRestrictAddr, fineFacei)
144 label cFace = faceRestrictAddr[fineFacei];
150 if (!faceFlipMap[fineFacei])
152 coarseUpper[cFace] += fineUpper[fineFacei];
153 coarseLower[cFace] += fineLower[fineFacei];
157 coarseUpper[cFace] += fineLower[fineFacei];
158 coarseLower[cFace] += fineUpper[fineFacei];
164 coarseDiag[-1 - cFace] +=
165 fineUpper[fineFacei] + fineLower[fineFacei];
175 scalarField& coarseUpper = coarseMatrix.upper(nCoarseFaces);
177 forAll(faceRestrictAddr, fineFacei)
179 label cFace = faceRestrictAddr[fineFacei];
183 coarseUpper[cFace] += fineUpper[fineFacei];
188 coarseDiag[-1 - cFace] += 2*fineUpper[fineFacei];
196 void Foam::GAMGSolver::agglomerateInterfaceCoefficients
198 const label fineLevelIndex,
200 PtrList<lduInterfaceField>& coarsePrimInterfaces,
202 FieldField<Field, scalar>& coarseInterfaceBouCoeffs,
203 FieldField<Field, scalar>& coarseInterfaceIntCoeffs
208 interfaceLevel(fineLevelIndex);
211 const FieldField<Field, scalar>& fineInterfaceBouCoeffs =
212 interfaceBouCoeffsLevel(fineLevelIndex);
215 const FieldField<Field, scalar>& fineInterfaceIntCoeffs =
216 interfaceIntCoeffsLevel(fineLevelIndex);
219 agglomeration_.patchFaceRestrictAddressing(fineLevelIndex);
222 agglomeration_.nPatchFaces(fineLevelIndex);
226 forAll(fineInterfaces, inti)
228 if (fineInterfaces.set(inti))
230 const GAMGInterface& coarseInterface =
231 refCast<const GAMGInterface>
233 coarseMeshInterfaces[inti]
236 coarsePrimInterfaces.set
248 &coarsePrimInterfaces[inti]
251 const labelList& faceRestrictAddressing = patchFineToCoarse[inti];
253 coarseInterfaceBouCoeffs.set
258 agglomeration_.restrictField
260 coarseInterfaceBouCoeffs[inti],
261 fineInterfaceBouCoeffs[inti],
262 faceRestrictAddressing
265 coarseInterfaceIntCoeffs.set
270 agglomeration_.restrictField
272 coarseInterfaceIntCoeffs[inti],
273 fineInterfaceIntCoeffs[inti],
274 faceRestrictAddressing
281 void Foam::GAMGSolver::gatherMatrices
284 const lduMesh& dummyMesh,
285 const label meshComm,
287 const lduMatrix& mat,
288 const FieldField<Field, scalar>& interfaceBouCoeffs,
289 const FieldField<Field, scalar>& interfaceIntCoeffs,
292 PtrList<lduMatrix>& otherMats,
293 PtrList<FieldField<Field, scalar>>& otherBouCoeffs,
294 PtrList<FieldField<Field, scalar>>& otherIntCoeffs,
295 List<boolList>& otherTransforms,
296 List<List<label>>& otherRanks
301 Pout<<
"GAMGSolver::gatherMatrices :"
302 <<
" collecting matrices from procs:" << procIDs
303 <<
" using comm:" << meshComm <<
endl;
309 otherMats.setSize(procIDs.size()-1);
310 otherBouCoeffs.setSize(procIDs.size()-1);
311 otherIntCoeffs.setSize(procIDs.size()-1);
312 otherTransforms.setSize(procIDs.size()-1);
313 otherRanks.setSize(procIDs.size()-1);
315 for (
label proci = 1; proci < procIDs.size(); proci++)
317 label otherI = proci-1;
328 otherMats.set(otherI,
new lduMatrix(dummyMesh, fromSlave));
331 List<label>& procRanks = otherRanks[otherI];
333 fromSlave >> procRanks;
339 new FieldField<Field, scalar>(procRanks.size())
344 new FieldField<Field, scalar>(procRanks.size())
348 if (procRanks[intI] != -1)
350 otherBouCoeffs[otherI].set
355 otherIntCoeffs[otherI].set
369 List<label> procRanks(interfaceBouCoeffs.size(), -1);
372 if (interfaces.set(intI))
374 const processorLduInterfaceField&
interface =
375 refCast<const processorLduInterfaceField>
380 procRanks[intI] = interface.rank();
393 toMaster << mat << procRanks;
396 if (procRanks[intI] != -1)
399 << interfaceBouCoeffs[intI]
400 << interfaceIntCoeffs[intI];
407 void Foam::GAMGSolver::procAgglomerateMatrix
411 const List<label>& agglomProcIDs,
416 autoPtr<lduMatrix>& allMatrixPtr,
417 FieldField<Field, scalar>& allInterfaceBouCoeffs,
418 FieldField<Field, scalar>& allInterfaceIntCoeffs,
419 PtrList<lduInterfaceField>& allPrimitiveInterfaces,
423 const lduMatrix& coarsestMatrix = matrixLevels_[levelI];
425 interfaceLevels_[levelI];
426 const FieldField<Field, scalar>& coarsestBouCoeffs =
427 interfaceLevelsBouCoeffs_[levelI];
428 const FieldField<Field, scalar>& coarsestIntCoeffs =
429 interfaceLevelsIntCoeffs_[levelI];
430 const lduMesh& coarsestMesh = coarsestMatrix.mesh();
432 label coarseComm = coarsestMesh.comm();
437 PtrList<lduMatrix> otherMats;
438 PtrList<FieldField<Field, scalar>> otherBouCoeffs;
439 PtrList<FieldField<Field, scalar>> otherIntCoeffs;
440 List<boolList> otherTransforms;
441 List<List<label>> otherRanks;
477 const lduMesh& allMesh = agglomeration_.meshLevel(levelI+1);
478 const labelList& cellOffsets = agglomeration_.cellOffsets(levelI+1);
480 const labelListList& boundaryMap = agglomeration_.boundaryMap(levelI+1);
482 agglomeration_.boundaryFaceMap(levelI+1);
484 allMatrixPtr.reset(
new lduMatrix(allMesh));
485 lduMatrix& allMatrix = allMatrixPtr();
487 if (coarsestMatrix.hasDiag())
494 coarsestMatrix.diag().size()
495 ) = coarsestMatrix.diag();
502 otherMats[i].
diag().size(),
504 ) = otherMats[i].diag();
507 if (coarsestMatrix.hasLower())
510 UIndirectList<scalar>
514 ) = coarsestMatrix.lower();
517 UIndirectList<scalar>
521 ) = otherMats[i].lower();
524 if (coarsestMatrix.hasUpper())
527 UIndirectList<scalar>
531 ) = coarsestMatrix.upper();
534 UIndirectList<scalar>
538 ) = otherMats[i].upper();
548 allInterfaceBouCoeffs.
setSize(allMeshInterfaces.size());
549 allInterfaceIntCoeffs.setSize(allMeshInterfaces.size());
550 allPrimitiveInterfaces.setSize(allMeshInterfaces.size());
551 allInterfaces.setSize(allMeshInterfaces.size());
553 forAll(allMeshInterfaces, intI)
555 const lduInterface& patch = allMeshInterfaces[intI];
556 label size = patch.faceCells().size();
558 allInterfaceBouCoeffs.set(intI,
new scalarField(size));
559 allInterfaceIntCoeffs.set(intI,
new scalarField(size));
562 labelList nBounFaces(allMeshInterfaces.size());
563 forAll(boundaryMap, proci)
565 const FieldField<Field, scalar>& procBouCoeffs
569 : otherBouCoeffs[proci-1]
571 const FieldField<Field, scalar>& procIntCoeffs
575 : otherIntCoeffs[proci-1]
578 const labelList& bMap = boundaryMap[proci];
581 label allIntI = bMap[procIntI];
588 if (!allInterfaces.set(allIntI))
595 const processorGAMGInterfaceField& procInt =
598 const processorGAMGInterfaceField
601 coarsestInterfaces[procIntI]
603 rank = procInt.rank();
607 rank = otherRanks[proci-1][procIntI];
610 allPrimitiveInterfaces.set
615 refCast<const GAMGInterface>
617 allMeshInterfaces[allIntI]
625 &allPrimitiveInterfaces[allIntI]
632 scalarField& allBou = allInterfaceBouCoeffs[allIntI];
633 scalarField& allInt = allInterfaceIntCoeffs[allIntI];
635 const labelList& map = boundaryFaceMap[proci][procIntI];
637 const scalarField& procBou = procBouCoeffs[procIntI];
638 const scalarField& procInt = procIntCoeffs[procIntI];
642 label allFacei = map[i];
648 allBou[allFacei] = procBou[i];
649 allInt[allFacei] = procInt[i];
652 else if (procBouCoeffs.set(procIntI))
656 const labelList& map = boundaryFaceMap[proci][procIntI];
657 const scalarField& procBou = procBouCoeffs[procIntI];
658 const scalarField& procInt = procIntCoeffs[procIntI];
665 label allFacei = map[i];
667 if (coarsestMatrix.hasUpper())
669 allMatrix.upper()[allFacei] = -procBou[i];
671 if (coarsestMatrix.hasLower())
673 allMatrix.lower()[allFacei] = -procInt[i];
678 label allFacei = -map[i]-1;
680 if (coarsestMatrix.hasUpper())
682 allMatrix.upper()[allFacei] = -procInt[i];
684 if (coarsestMatrix.hasLower())
686 allMatrix.lower()[allFacei] = -procBou[i];
722 void Foam::GAMGSolver::procAgglomerateMatrix
725 const List<label>& agglomProcIDs,
730 autoPtr<lduMatrix> allMatrixPtr;
731 autoPtr<FieldField<Field, scalar>> allInterfaceBouCoeffs
733 new FieldField<Field, scalar>(0)
735 autoPtr<FieldField<Field, scalar>> allInterfaceIntCoeffs
737 new FieldField<Field, scalar>(0)
739 autoPtr<PtrList<lduInterfaceField>> allPrimitiveInterfaces
741 new PtrList<lduInterfaceField>(0)
743 autoPtr<lduInterfaceFieldPtrsList> allInterfaces
748 procAgglomerateMatrix
758 allInterfaceBouCoeffs(),
759 allInterfaceIntCoeffs(),
760 allPrimitiveInterfaces(),
764 matrixLevels_.set(levelI, allMatrixPtr);
765 interfaceLevelsBouCoeffs_.set(levelI, allInterfaceBouCoeffs);
766 interfaceLevelsIntCoeffs_.set(levelI, allInterfaceIntCoeffs);
767 primitiveInterfaceLevels_.set(levelI, allPrimitiveInterfaces);
768 interfaceLevels_.set(levelI, allInterfaces);
#define forAll(list, i)
Loop across all elements in list.
const labelList & faceRestrictAddressing(const label leveli) const
Return face restrict addressing of given level.
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
const boolList & faceFlipMap(const label leveli) const
Return face flip map of given level.
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
label nFaces(const label leveli) const
Return number of coarse faces (before processor agglomeration)
static autoPtr< GAMGInterfaceField > New(const GAMGInterface &GAMGCp, const lduInterfaceField &fineInterface)
Return a pointer to a new interface created on freestore given.
static int & msgType()
Message tag of standard messages.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
void setSize(const label)
Reset size of UPtrList. This can only be used to set the size.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
To & refCast(From &r)
Reference type cast template function.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.
List< bool > boolList
Bool container classes.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
List< labelList > labelListList
A List of labelList.
UPtrList< const lduInterface > lduInterfacePtrsList
List of coupled interface fields to be used in coupling.
List< labelListList > labelListListList
A List of labelListList.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
prefixOSstream Pout(cout, "Pout")