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);
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
260 coarseInterfaceBouCoeffs[inti],
261 fineInterfaceBouCoeffs[inti],
262 faceRestrictAddressing
265 coarseInterfaceIntCoeffs.set
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 boolList& procTransforms = otherTransforms[otherI];
332 List<label>& procRanks = otherRanks[otherI];
334 fromSlave >> procTransforms;
335 fromSlave >> procRanks;
341 new FieldField<Field, scalar>(procRanks.size())
346 new FieldField<Field, scalar>(procRanks.size())
350 if (procRanks[intI] != -1)
352 otherBouCoeffs[otherI].set
357 otherIntCoeffs[otherI].set
371 boolList procTransforms(interfaceBouCoeffs.size(),
false);
372 List<label> procRanks(interfaceBouCoeffs.size(), -1);
375 if (interfaces.set(intI))
377 const processorLduInterfaceField&
interface =
378 refCast<const processorLduInterfaceField>
383 procTransforms[intI] = interface.doTransform();
384 procRanks[intI] = interface.rank();
397 toMaster << mat << procTransforms << procRanks;
400 if (procRanks[intI] != -1)
403 << interfaceBouCoeffs[intI]
404 << interfaceIntCoeffs[intI];
411 void Foam::GAMGSolver::procAgglomerateMatrix
415 const List<label>& agglomProcIDs,
420 autoPtr<lduMatrix>& allMatrixPtr,
421 FieldField<Field, scalar>& allInterfaceBouCoeffs,
422 FieldField<Field, scalar>& allInterfaceIntCoeffs,
423 PtrList<lduInterfaceField>& allPrimitiveInterfaces,
427 const lduMatrix& coarsestMatrix = matrixLevels_[levelI];
429 interfaceLevels_[levelI];
430 const FieldField<Field, scalar>& coarsestBouCoeffs =
431 interfaceLevelsBouCoeffs_[levelI];
432 const FieldField<Field, scalar>& coarsestIntCoeffs =
433 interfaceLevelsIntCoeffs_[levelI];
434 const lduMesh& coarsestMesh = coarsestMatrix.mesh();
436 label coarseComm = coarsestMesh.comm();
441 PtrList<lduMatrix> otherMats;
442 PtrList<FieldField<Field, scalar>> otherBouCoeffs;
443 PtrList<FieldField<Field, scalar>> otherIntCoeffs;
444 List<boolList> otherTransforms;
445 List<List<label>> otherRanks;
481 const lduMesh& allMesh = agglomeration_.
meshLevel(levelI+1);
488 allMatrixPtr.reset(
new lduMatrix(allMesh));
489 lduMatrix& allMatrix = allMatrixPtr();
491 if (coarsestMatrix.hasDiag())
498 coarsestMatrix.diag().size()
499 ) = coarsestMatrix.diag();
506 otherMats[i].diag().size(),
508 ) = otherMats[i].
diag();
511 if (coarsestMatrix.hasLower())
514 UIndirectList<scalar>
518 ) = coarsestMatrix.lower();
521 UIndirectList<scalar>
525 ) = otherMats[i].lower();
528 if (coarsestMatrix.hasUpper())
531 UIndirectList<scalar>
535 ) = coarsestMatrix.upper();
538 UIndirectList<scalar>
542 ) = otherMats[i].upper();
552 allInterfaceBouCoeffs.
setSize(allMeshInterfaces.size());
553 allInterfaceIntCoeffs.setSize(allMeshInterfaces.size());
554 allPrimitiveInterfaces.setSize(allMeshInterfaces.size());
555 allInterfaces.setSize(allMeshInterfaces.size());
557 forAll(allMeshInterfaces, intI)
559 const lduInterface& patch = allMeshInterfaces[intI];
560 label size = patch.faceCells().size();
562 allInterfaceBouCoeffs.set(intI,
new scalarField(size));
563 allInterfaceIntCoeffs.set(intI,
new scalarField(size));
566 labelList nBounFaces(allMeshInterfaces.size());
567 forAll(boundaryMap, proci)
569 const FieldField<Field, scalar>& procBouCoeffs
573 : otherBouCoeffs[proci-1]
575 const FieldField<Field, scalar>& procIntCoeffs
579 : otherIntCoeffs[proci-1]
582 const labelList& bMap = boundaryMap[proci];
585 label allIntI = bMap[procIntI];
592 if (!allInterfaces.set(allIntI))
596 bool doTransform =
false;
600 const processorGAMGInterfaceField& procInt =
603 const processorGAMGInterfaceField
606 coarsestInterfaces[procIntI]
608 doTransform = procInt.doTransform();
609 rank = procInt.rank();
614 otherTransforms[proci-1][procIntI];
615 rank = otherRanks[proci-1][procIntI];
618 allPrimitiveInterfaces.set
623 refCast<const GAMGInterface>
625 allMeshInterfaces[allIntI]
634 &allPrimitiveInterfaces[allIntI]
641 scalarField& allBou = allInterfaceBouCoeffs[allIntI];
642 scalarField& allInt = allInterfaceIntCoeffs[allIntI];
644 const labelList& map = boundaryFaceMap[proci][procIntI];
646 const scalarField& procBou = procBouCoeffs[procIntI];
647 const scalarField& procInt = procIntCoeffs[procIntI];
651 label allFacei = map[i];
657 allBou[allFacei] = procBou[i];
658 allInt[allFacei] = procInt[i];
661 else if (procBouCoeffs.set(procIntI))
665 const labelList& map = boundaryFaceMap[proci][procIntI];
666 const scalarField& procBou = procBouCoeffs[procIntI];
667 const scalarField& procInt = procIntCoeffs[procIntI];
674 label allFacei = map[i];
676 if (coarsestMatrix.hasUpper())
678 allMatrix.upper()[allFacei] = -procBou[i];
680 if (coarsestMatrix.hasLower())
682 allMatrix.lower()[allFacei] = -procInt[i];
687 label allFacei = -map[i]-1;
689 if (coarsestMatrix.hasUpper())
691 allMatrix.upper()[allFacei] = -procInt[i];
693 if (coarsestMatrix.hasLower())
695 allMatrix.lower()[allFacei] = -procBou[i];
731 void Foam::GAMGSolver::procAgglomerateMatrix
734 const List<label>& agglomProcIDs,
739 autoPtr<lduMatrix> allMatrixPtr;
740 autoPtr<FieldField<Field, scalar>> allInterfaceBouCoeffs
742 new FieldField<Field, scalar>(0)
744 autoPtr<FieldField<Field, scalar>> allInterfaceIntCoeffs
746 new FieldField<Field, scalar>(0)
748 autoPtr<PtrList<lduInterfaceField>> allPrimitiveInterfaces
750 new PtrList<lduInterfaceField>(0)
752 autoPtr<lduInterfaceFieldPtrsList> allInterfaces
757 procAgglomerateMatrix
767 allInterfaceBouCoeffs(),
768 allInterfaceIntCoeffs(),
769 allPrimitiveInterfaces(),
773 matrixLevels_.set(levelI, allMatrixPtr);
774 interfaceLevelsBouCoeffs_.set(levelI, allInterfaceBouCoeffs);
775 interfaceLevelsIntCoeffs_.set(levelI, allInterfaceIntCoeffs);
776 primitiveInterfaceLevels_.set(levelI, allPrimitiveInterfaces);
777 interfaceLevels_.set(levelI, allInterfaces);
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.
const labelList & faceRestrictAddressing(const label leveli) const
Return face restrict addressing of given level.
List< labelList > labelListList
A List of labelList.
const labelList & nPatchFaces(const label leveli) const
Return number of coarse patch faces (before processor.
#define forAll(list, i)
Loop across all elements in list.
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const boolList & faceFlipMap(const label leveli) const
Return face flip map of given level.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const lduMesh & meshLevel(const label leveli) const
Return LDU mesh of given level.
To & refCast(From &r)
Reference type cast template function.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
const labelListList & boundaryMap(const label fineLeveli) const
Mapping from processor to procMesh boundary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static int & msgType()
Message tag of standard messages.
List< bool > boolList
Bool container classes.
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
void setSize(const label)
Reset size of UPtrList. This can only be used to set the size.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
UPtrList< const lduInterface > lduInterfacePtrsList
List of coupled interface fields to be used in coupling.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
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.
const labelList & cellOffsets(const label fineLeveli) const
Mapping from processor to procMesh cells.
const labelListListList & boundaryFaceMap(const label fineLeveli) const
Mapping from processor to procMesh boundary face.
List< labelListList > labelListListList
A List of labelListList.
prefixOSstream Pout(cout, "Pout")
const labelListList & patchFaceRestrictAddressing(const label leveli) const
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
const labelListList & faceMap(const label fineLeveli) const
Mapping from processor to procMesh face.