35void Foam::GAMGSolver::agglomerateMatrix
37 const label fineLevelIndex,
38 const lduMesh& coarseMesh,
39 const lduInterfacePtrsList& coarseMeshInterfaces
43 const lduMatrix& fineMatrix = matrixLevel(fineLevelIndex);
47 const label nCoarseFaces = agglomeration_.
nFaces(fineLevelIndex);
48 const label nCoarseCells = agglomeration_.
nCells(fineLevelIndex);
54 new lduMatrix(coarseMesh)
56 lduMatrix& coarseMatrix = matrixLevels_[fineLevelIndex];
63 scalarField& coarseDiag = coarseMatrix.diag(nCoarseCells);
75 interfaceLevel(fineLevelIndex);
78 primitiveInterfaceLevels_.set
81 new PtrList<lduInterfaceField>(fineInterfaces.size())
84 PtrList<lduInterfaceField>& coarsePrimInterfaces =
85 primitiveInterfaceLevels_[fineLevelIndex];
94 interfaceLevels_[fineLevelIndex];
97 interfaceLevelsBouCoeffs_.set
100 new FieldField<Field, scalar>(fineInterfaces.size())
102 FieldField<Field, scalar>& coarseInterfaceBouCoeffs =
103 interfaceLevelsBouCoeffs_[fineLevelIndex];
106 interfaceLevelsIntCoeffs_.set
109 new FieldField<Field, scalar>(fineInterfaces.size())
111 FieldField<Field, scalar>& coarseInterfaceIntCoeffs =
112 interfaceLevelsIntCoeffs_[fineLevelIndex];
115 agglomerateInterfaceCoefficients
118 coarseMeshInterfaces,
119 coarsePrimInterfaces,
121 coarseInterfaceBouCoeffs,
122 coarseInterfaceIntCoeffs
134 if (fineMatrix.hasLower())
141 scalarField& coarseUpper = coarseMatrix.upper(nCoarseFaces);
142 scalarField& coarseLower = coarseMatrix.lower(nCoarseFaces);
144 forAll(faceRestrictAddr, fineFacei)
146 label cFace = faceRestrictAddr[fineFacei];
152 if (!faceFlipMap[fineFacei])
154 coarseUpper[cFace] += fineUpper[fineFacei];
155 coarseLower[cFace] += fineLower[fineFacei];
159 coarseUpper[cFace] += fineLower[fineFacei];
160 coarseLower[cFace] += fineUpper[fineFacei];
166 coarseDiag[-1 - cFace] +=
167 fineUpper[fineFacei] + fineLower[fineFacei];
177 scalarField& coarseUpper = coarseMatrix.upper(nCoarseFaces);
179 forAll(faceRestrictAddr, fineFacei)
181 label cFace = faceRestrictAddr[fineFacei];
185 coarseUpper[cFace] += fineUpper[fineFacei];
190 coarseDiag[-1 - cFace] += 2*fineUpper[fineFacei];
198void Foam::GAMGSolver::agglomerateInterfaceCoefficients
200 const label fineLevelIndex,
202 PtrList<lduInterfaceField>& coarsePrimInterfaces,
204 FieldField<Field, scalar>& coarseInterfaceBouCoeffs,
205 FieldField<Field, scalar>& coarseInterfaceIntCoeffs
210 interfaceLevel(fineLevelIndex);
213 const FieldField<Field, scalar>& fineInterfaceBouCoeffs =
214 interfaceBouCoeffsLevel(fineLevelIndex);
217 const FieldField<Field, scalar>& fineInterfaceIntCoeffs =
218 interfaceIntCoeffsLevel(fineLevelIndex);
221 agglomeration_.patchFaceRestrictAddressing(fineLevelIndex);
224 agglomeration_.nPatchFaces(fineLevelIndex);
228 forAll(fineInterfaces, inti)
230 if (fineInterfaces.set(inti))
232 const GAMGInterface& coarseInterface =
233 refCast<const GAMGInterface>
235 coarseMeshInterfaces[inti]
238 coarsePrimInterfaces.set
250 &coarsePrimInterfaces[inti]
253 const labelList& faceRestrictAddressing = patchFineToCoarse[inti];
255 coarseInterfaceBouCoeffs.
set
260 agglomeration_.restrictField
262 coarseInterfaceBouCoeffs[inti],
263 fineInterfaceBouCoeffs[inti],
264 faceRestrictAddressing
267 coarseInterfaceIntCoeffs.set
272 agglomeration_.restrictField
274 coarseInterfaceIntCoeffs[inti],
275 fineInterfaceIntCoeffs[inti],
276 faceRestrictAddressing
283void Foam::GAMGSolver::gatherMatrices
286 const lduMesh& dummyMesh,
287 const label meshComm,
289 const lduMatrix& mat,
290 const FieldField<Field, scalar>& interfaceBouCoeffs,
291 const FieldField<Field, scalar>& interfaceIntCoeffs,
294 PtrList<lduMatrix>& otherMats,
295 PtrList<FieldField<Field, scalar>>& otherBouCoeffs,
296 PtrList<FieldField<Field, scalar>>& otherIntCoeffs,
297 List<boolList>& otherTransforms,
298 List<List<label>>& otherRanks
303 Pout<<
"GAMGSolver::gatherMatrices :"
304 <<
" collecting matrices from procs:" << procIDs
305 <<
" using comm:" << meshComm <<
endl;
311 otherMats.setSize(procIDs.size()-1);
312 otherBouCoeffs.setSize(procIDs.size()-1);
313 otherIntCoeffs.setSize(procIDs.size()-1);
314 otherTransforms.setSize(procIDs.size()-1);
315 otherRanks.setSize(procIDs.size()-1);
317 for (label proci = 1; proci < procIDs.size(); proci++)
319 label otherI = proci-1;
330 otherMats.set(otherI,
new lduMatrix(dummyMesh, fromSlave));
333 boolList& procTransforms = otherTransforms[otherI];
334 List<label>& procRanks = otherRanks[otherI];
336 fromSlave >> procTransforms;
337 fromSlave >> procRanks;
343 new FieldField<Field, scalar>(procRanks.size())
348 new FieldField<Field, scalar>(procRanks.size())
352 if (procRanks[intI] != -1)
354 otherBouCoeffs[otherI].set
359 otherIntCoeffs[otherI].set
373 boolList procTransforms(interfaceBouCoeffs.size(),
false);
374 List<label> procRanks(interfaceBouCoeffs.size(), -1);
377 if (interfaces.set(intI))
379 const processorLduInterfaceField&
interface =
380 refCast<const processorLduInterfaceField>
385 procTransforms[intI] =
interface.doTransform();
399 toMaster << mat << procTransforms << procRanks;
402 if (procRanks[intI] != -1)
405 << interfaceBouCoeffs[intI]
406 << interfaceIntCoeffs[intI];
413void Foam::GAMGSolver::procAgglomerateMatrix
417 const List<label>& agglomProcIDs,
422 autoPtr<lduMatrix>& allMatrixPtr,
423 FieldField<Field, scalar>& allInterfaceBouCoeffs,
424 FieldField<Field, scalar>& allInterfaceIntCoeffs,
425 PtrList<lduInterfaceField>& allPrimitiveInterfaces,
429 const lduMatrix& coarsestMatrix = matrixLevels_[levelI];
431 interfaceLevels_[levelI];
432 const FieldField<Field, scalar>& coarsestBouCoeffs =
433 interfaceLevelsBouCoeffs_[levelI];
434 const FieldField<Field, scalar>& coarsestIntCoeffs =
435 interfaceLevelsIntCoeffs_[levelI];
436 const lduMesh& coarsestMesh = coarsestMatrix.mesh();
438 label coarseComm = coarsestMesh.comm();
443 PtrList<lduMatrix> otherMats;
444 PtrList<FieldField<Field, scalar>> otherBouCoeffs;
445 PtrList<FieldField<Field, scalar>> otherIntCoeffs;
446 List<boolList> otherTransforms;
447 List<List<label>> otherRanks;
483 const lduMesh& allMesh = agglomeration_.meshLevel(levelI+1);
484 const labelList& cellOffsets = agglomeration_.cellOffsets(levelI+1);
486 const labelListList& boundaryMap = agglomeration_.boundaryMap(levelI+1);
488 agglomeration_.boundaryFaceMap(levelI+1);
490 allMatrixPtr.reset(
new lduMatrix(allMesh));
491 lduMatrix& allMatrix = allMatrixPtr();
493 if (coarsestMatrix.hasDiag())
500 coarsestMatrix.diag().size()
501 ) = coarsestMatrix.diag();
508 otherMats[i].
diag().size(),
510 ) = otherMats[i].diag();
513 if (coarsestMatrix.hasLower())
516 UIndirectList<scalar>
520 ) = coarsestMatrix.lower();
523 UIndirectList<scalar>
527 ) = otherMats[i].lower();
530 if (coarsestMatrix.hasUpper())
533 UIndirectList<scalar>
537 ) = coarsestMatrix.upper();
540 UIndirectList<scalar>
544 ) = otherMats[i].upper();
554 allInterfaceBouCoeffs.
setSize(allMeshInterfaces.size());
555 allInterfaceIntCoeffs.setSize(allMeshInterfaces.size());
556 allPrimitiveInterfaces.setSize(allMeshInterfaces.size());
557 allInterfaces.setSize(allMeshInterfaces.size());
559 forAll(allMeshInterfaces, intI)
561 const lduInterface&
patch = allMeshInterfaces[intI];
562 label size =
patch.faceCells().size();
564 allInterfaceBouCoeffs.set(intI,
new scalarField(size));
565 allInterfaceIntCoeffs.set(intI,
new scalarField(size));
568 labelList nBounFaces(allMeshInterfaces.size());
569 forAll(boundaryMap, proci)
571 const FieldField<Field, scalar>& procBouCoeffs
575 : otherBouCoeffs[proci-1]
577 const FieldField<Field, scalar>& procIntCoeffs
581 : otherIntCoeffs[proci-1]
584 const labelList& bMap = boundaryMap[proci];
587 label allIntI = bMap[procIntI];
594 if (!allInterfaces.set(allIntI))
598 bool doTransform =
false;
602 const processorGAMGInterfaceField& procInt =
605 const processorGAMGInterfaceField
608 coarsestInterfaces[procIntI]
610 doTransform = procInt.doTransform();
611 rank = procInt.rank();
616 otherTransforms[proci-1][procIntI];
617 rank = otherRanks[proci-1][procIntI];
620 allPrimitiveInterfaces.set
625 refCast<const GAMGInterface>
627 allMeshInterfaces[allIntI]
636 &allPrimitiveInterfaces[allIntI]
643 scalarField& allBou = allInterfaceBouCoeffs[allIntI];
644 scalarField& allInt = allInterfaceIntCoeffs[allIntI];
646 const labelList& map = boundaryFaceMap[proci][procIntI];
648 const scalarField& procBou = procBouCoeffs[procIntI];
649 const scalarField& procInt = procIntCoeffs[procIntI];
653 label allFacei = map[i];
659 allBou[allFacei] = procBou[i];
660 allInt[allFacei] = procInt[i];
663 else if (procBouCoeffs.set(procIntI))
667 const labelList& map = boundaryFaceMap[proci][procIntI];
668 const scalarField& procBou = procBouCoeffs[procIntI];
669 const scalarField& procInt = procIntCoeffs[procIntI];
676 label allFacei = map[i];
678 if (coarsestMatrix.hasUpper())
680 allMatrix.upper()[allFacei] = -procBou[i];
682 if (coarsestMatrix.hasLower())
684 allMatrix.lower()[allFacei] = -procInt[i];
689 label allFacei = -map[i]-1;
691 if (coarsestMatrix.hasUpper())
693 allMatrix.upper()[allFacei] = -procInt[i];
695 if (coarsestMatrix.hasLower())
697 allMatrix.lower()[allFacei] = -procBou[i];
733void Foam::GAMGSolver::procAgglomerateMatrix
736 const List<label>& agglomProcIDs,
741 autoPtr<lduMatrix> allMatrixPtr;
742 autoPtr<FieldField<Field, scalar>> allInterfaceBouCoeffs
744 new FieldField<Field, scalar>(0)
746 autoPtr<FieldField<Field, scalar>> allInterfaceIntCoeffs
748 new FieldField<Field, scalar>(0)
750 autoPtr<PtrList<lduInterfaceField>> allPrimitiveInterfaces
752 new PtrList<lduInterfaceField>(0)
754 autoPtr<lduInterfaceFieldPtrsList> allInterfaces
759 procAgglomerateMatrix
769 allInterfaceBouCoeffs(),
770 allInterfaceIntCoeffs(),
771 allPrimitiveInterfaces(),
775 matrixLevels_.set(levelI, allMatrixPtr);
776 interfaceLevelsBouCoeffs_.set(levelI, allInterfaceBouCoeffs);
777 interfaceLevelsIntCoeffs_.set(levelI, allInterfaceIntCoeffs);
778 primitiveInterfaceLevels_.set(levelI, allPrimitiveInterfaces);
779 interfaceLevels_.set(levelI, allInterfaces);
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)
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
static int & msgType() noexcept
Message tag of standard messages.
void setSize(const label n)
Alias for resize()
int myProcNo() const noexcept
Return processor number.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const std::string patch
OpenFOAM patch number as a std::string.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
To & refCast(From &r)
Reference type cast template function.
List< label > labelList
A List of labels.
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< labelList > labelListList
A List of labelList.
UPtrList< const lduInterface > lduInterfacePtrsList
Store lists of lduInterface as a UPtrList.
List< labelListList > labelListListList
A List of labelListList.
errorManip< error > abort(error &err)
List< bool > boolList
A List of bools.
static constexpr const zero Zero
Global zero (0)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
#define forAll(list, i)
Loop across all elements in list.