36 void Foam::GAMGSolver::agglomerateMatrix
38 const label fineLevelIndex,
39 const lduMesh& coarseMesh,
44 const lduMatrix& fineMatrix = matrixLevel(fineLevelIndex);
48 const label nCoarseFaces = agglomeration_.
nFaces(fineLevelIndex);
49 const label nCoarseCells = agglomeration_.
nCells(fineLevelIndex);
55 new lduMatrix(coarseMesh)
57 lduMatrix& coarseMatrix = matrixLevels_[fineLevelIndex];
64 scalarField& coarseDiag = coarseMatrix.diag(nCoarseCells);
76 interfaceLevel(fineLevelIndex);
79 primitiveInterfaceLevels_.set
82 new PtrList<lduInterfaceField>(fineInterfaces.size())
85 PtrList<lduInterfaceField>& coarsePrimInterfaces =
86 primitiveInterfaceLevels_[fineLevelIndex];
95 interfaceLevels_[fineLevelIndex];
98 interfaceLevelsBouCoeffs_.set
101 new FieldField<Field, scalar>(fineInterfaces.size())
103 FieldField<Field, scalar>& coarseInterfaceBouCoeffs =
104 interfaceLevelsBouCoeffs_[fineLevelIndex];
107 interfaceLevelsIntCoeffs_.set
110 new FieldField<Field, scalar>(fineInterfaces.size())
112 FieldField<Field, scalar>& coarseInterfaceIntCoeffs =
113 interfaceLevelsIntCoeffs_[fineLevelIndex];
116 agglomerateInterfaceCoefficients
119 coarseMeshInterfaces,
120 coarsePrimInterfaces,
122 coarseInterfaceBouCoeffs,
123 coarseInterfaceIntCoeffs
135 if (fineMatrix.hasLower())
142 scalarField& coarseUpper = coarseMatrix.upper(nCoarseFaces);
143 scalarField& coarseLower = coarseMatrix.lower(nCoarseFaces);
145 forAll(faceRestrictAddr, fineFacei)
147 label cFace = faceRestrictAddr[fineFacei];
153 if (!faceFlipMap[fineFacei])
155 coarseUpper[cFace] += fineUpper[fineFacei];
156 coarseLower[cFace] += fineLower[fineFacei];
160 coarseUpper[cFace] += fineLower[fineFacei];
161 coarseLower[cFace] += fineUpper[fineFacei];
167 coarseDiag[-1 - cFace] +=
168 fineUpper[fineFacei] + fineLower[fineFacei];
178 scalarField& coarseUpper = coarseMatrix.upper(nCoarseFaces);
180 forAll(faceRestrictAddr, fineFacei)
182 label cFace = faceRestrictAddr[fineFacei];
186 coarseUpper[cFace] += fineUpper[fineFacei];
191 coarseDiag[-1 - cFace] += 2*fineUpper[fineFacei];
199 void Foam::GAMGSolver::agglomerateInterfaceCoefficients
201 const label fineLevelIndex,
203 PtrList<lduInterfaceField>& coarsePrimInterfaces,
205 FieldField<Field, scalar>& coarseInterfaceBouCoeffs,
206 FieldField<Field, scalar>& coarseInterfaceIntCoeffs
211 interfaceLevel(fineLevelIndex);
214 const FieldField<Field, scalar>& fineInterfaceBouCoeffs =
215 interfaceBouCoeffsLevel(fineLevelIndex);
218 const FieldField<Field, scalar>& fineInterfaceIntCoeffs =
219 interfaceIntCoeffsLevel(fineLevelIndex);
222 agglomeration_.patchFaceRestrictAddressing(fineLevelIndex);
225 agglomeration_.nPatchFaces(fineLevelIndex);
229 forAll(fineInterfaces, inti)
231 if (fineInterfaces.set(inti))
233 const GAMGInterface& coarseInterface =
234 refCast<const GAMGInterface>
236 coarseMeshInterfaces[inti]
239 coarsePrimInterfaces.set
251 &coarsePrimInterfaces[inti]
254 const labelList& faceRestrictAddressing = patchFineToCoarse[inti];
256 coarseInterfaceBouCoeffs.
set 261 agglomeration_.restrictField
263 coarseInterfaceBouCoeffs[inti],
264 fineInterfaceBouCoeffs[inti],
265 faceRestrictAddressing
268 coarseInterfaceIntCoeffs.set
273 agglomeration_.restrictField
275 coarseInterfaceIntCoeffs[inti],
276 fineInterfaceIntCoeffs[inti],
277 faceRestrictAddressing
284 void Foam::GAMGSolver::gatherMatrices
286 const label destLevel,
290 const lduMatrix& mat,
291 const FieldField<Field, scalar>& interfaceBouCoeffs,
292 const FieldField<Field, scalar>& interfaceIntCoeffs,
296 PtrList<lduMatrix>& otherMats,
297 PtrList<FieldField<Field, scalar>>& otherBouCoeffs,
298 PtrList<FieldField<Field, scalar>>& otherIntCoeffs,
299 PtrList<PtrList<lduInterfaceField>>& otherInterfaces
306 Pout<<
"GAMGSolver::gatherMatrices :" 307 <<
" collecting matrices from procs:" << procIDs
308 <<
" using comm:" << comm <<
endl;
311 const auto& boundaryMap = agglomeration_.boundaryMap(destLevel);
335 labelList validInterface(interfaces.size(), -1);
338 const label allIntI = boundaryMap[proci][intI];
339 if (interfaces.set(intI) && allIntI != -1)
341 validInterface[intI] = intI;
349 forAll(validInterface, intI)
351 if (validInterface[intI] != -1)
353 const auto&
interface =
refCast<const GAMGInterfaceField>
359 << interfaceBouCoeffs[intI]
360 << interfaceIntCoeffs[intI]
368 pBufs.finishedGathers();
375 const lduMesh& destMesh = agglomeration_.meshLevel(destLevel);
380 otherBouCoeffs.setSize(nProcs-1);
381 otherIntCoeffs.setSize(nProcs-1);
382 otherInterfaces.setSize(nProcs-1);
386 const label otherI = proci-1;
388 UIPstream fromProc(proci, pBufs);
390 otherMats.set(otherI,
new lduMatrix(destMesh, fromProc));
395 const labelList validInterface(fromProc);
400 new FieldField<Field, scalar>(validInterface.size())
405 new FieldField<Field, scalar>(validInterface.size())
410 new PtrList<lduInterfaceField>(validInterface.size())
413 forAll(validInterface, intI)
415 if (validInterface[intI] != -1)
417 otherBouCoeffs[otherI].set
422 otherIntCoeffs[otherI].set
428 const word coupleType(fromProc);
430 const label allIntI = boundaryMap[proci][intI];
432 otherInterfaces[otherI].set
438 refCast<const GAMGInterface>
440 destInterfaces[allIntI]
452 void Foam::GAMGSolver::procAgglomerateMatrix
456 const List<label>& agglomProcIDs,
461 autoPtr<lduMatrix>& allMatrixPtr,
462 FieldField<Field, scalar>& allInterfaceBouCoeffs,
463 FieldField<Field, scalar>& allInterfaceIntCoeffs,
464 PtrList<lduInterfaceField>& allPrimitiveInterfaces,
468 const lduMatrix& coarsestMatrix = matrixLevels_[levelI];
470 interfaceLevels_[levelI];
471 const FieldField<Field, scalar>& coarsestBouCoeffs =
472 interfaceLevelsBouCoeffs_[levelI];
473 const FieldField<Field, scalar>& coarsestIntCoeffs =
474 interfaceLevelsIntCoeffs_[levelI];
478 const label agglomComm = agglomeration_.agglomCommunicator(levelI+1);
484 PtrList<lduMatrix> otherMats;
485 PtrList<FieldField<Field, scalar>> otherBouCoeffs;
486 PtrList<FieldField<Field, scalar>> otherIntCoeffs;
487 PtrList<PtrList<lduInterfaceField>> otherInterfaces;
510 const lduMesh& allMesh = agglomeration_.meshLevel(levelI+1);
511 const labelList& cellOffsets = agglomeration_.cellOffsets(levelI+1);
513 const labelListList& boundaryMap = agglomeration_.boundaryMap(levelI+1);
515 agglomeration_.boundaryFaceMap(levelI+1);
517 allMatrixPtr.reset(
new lduMatrix(allMesh));
518 lduMatrix& allMatrix = allMatrixPtr();
520 if (coarsestMatrix.hasDiag())
527 coarsestMatrix.diag().size()
528 ) = coarsestMatrix.diag();
535 otherMats[i].diag().size(),
537 ) = otherMats[i].
diag();
540 if (coarsestMatrix.hasLower())
543 UIndirectList<scalar>
547 ) = coarsestMatrix.lower();
550 UIndirectList<scalar>
554 ) = otherMats[i].
lower();
557 if (coarsestMatrix.hasUpper())
560 UIndirectList<scalar>
564 ) = coarsestMatrix.upper();
567 UIndirectList<scalar>
571 ) = otherMats[i].
upper();
581 allInterfaceBouCoeffs.
setSize(allMeshInterfaces.size());
582 allInterfaceIntCoeffs.setSize(allMeshInterfaces.size());
583 allPrimitiveInterfaces.setSize(allMeshInterfaces.size());
584 allInterfaces.setSize(allMeshInterfaces.size());
586 forAll(allMeshInterfaces, intI)
588 const lduInterface&
patch = allMeshInterfaces[intI];
589 label size =
patch.faceCells().size();
591 allInterfaceBouCoeffs.set(intI,
new scalarField(size));
592 allInterfaceIntCoeffs.set(intI,
new scalarField(size));
595 UPtrList<lduInterfaceField> otherFlds(0);
597 forAll(boundaryMap, proci)
599 const FieldField<Field, scalar>& procBouCoeffs
603 : otherBouCoeffs[proci-1]
605 const FieldField<Field, scalar>& procIntCoeffs
609 : otherIntCoeffs[proci-1]
613 const labelList& bMap = boundaryMap[proci];
616 label allIntI = bMap[procIntI];
623 if (!allInterfaces.set(allIntI))
625 const GAMGInterface& intf = refCast<const GAMGInterface>
627 allMeshInterfaces[allIntI]
637 refCast<const GAMGInterfaceField>
639 coarsestInterfaces[procIntI]
642 allPrimitiveInterfaces.set
655 if (otherInterfaces[proci-1].
set(procIntI))
658 refCast<const GAMGInterfaceField>
660 otherInterfaces[proci-1][procIntI]
663 allPrimitiveInterfaces.set
679 allPrimitiveInterfaces.set
694 allPrimitiveInterfaces.get(allIntI)
701 scalarField& allBou = allInterfaceBouCoeffs[allIntI];
702 scalarField& allInt = allInterfaceIntCoeffs[allIntI];
704 const labelList& map = boundaryFaceMap[proci][procIntI];
706 const scalarField& procBou = procBouCoeffs[procIntI];
707 const scalarField& procInt = procIntCoeffs[procIntI];
711 label allFacei = map[i];
717 allBou[allFacei] = procBou[i];
718 allInt[allFacei] = procInt[i];
721 else if (procBouCoeffs.set(procIntI))
725 const labelList& map = boundaryFaceMap[proci][procIntI];
726 const scalarField& procBou = procBouCoeffs[procIntI];
727 const scalarField& procInt = procIntCoeffs[procIntI];
733 label allFacei = map[i];
735 if (coarsestMatrix.hasUpper())
737 allMatrix.upper()[allFacei] = -procBou[i];
739 if (coarsestMatrix.hasLower())
741 allMatrix.lower()[allFacei] = -procInt[i];
746 label allFacei = -map[i]-1;
748 if (coarsestMatrix.hasUpper())
750 allMatrix.upper()[allFacei] = -procInt[i];
752 if (coarsestMatrix.hasLower())
754 allMatrix.lower()[allFacei] = -procBou[i];
790 void Foam::GAMGSolver::procAgglomerateMatrix
793 const List<label>& agglomProcIDs,
798 autoPtr<lduMatrix> allMatrixPtr;
799 autoPtr<FieldField<Field, scalar>> allInterfaceBouCoeffs
801 new FieldField<Field, scalar>(0)
803 autoPtr<FieldField<Field, scalar>> allInterfaceIntCoeffs
805 new FieldField<Field, scalar>(0)
807 autoPtr<PtrList<lduInterfaceField>> allPrimitiveInterfaces
809 new PtrList<lduInterfaceField>(0)
811 autoPtr<lduInterfaceFieldPtrsList> allInterfaces
816 procAgglomerateMatrix
826 allInterfaceBouCoeffs(),
827 allInterfaceIntCoeffs(),
828 allPrimitiveInterfaces(),
832 matrixLevels_.set(levelI, allMatrixPtr);
833 interfaceLevelsBouCoeffs_.set(levelI, allInterfaceBouCoeffs);
834 interfaceLevelsIntCoeffs_.set(levelI, allInterfaceIntCoeffs);
835 primitiveInterfaceLevels_.set(levelI, allPrimitiveInterfaces);
836 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.
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.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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.
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Ostream & endl(Ostream &os)
Add newline and flush stream.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
static int & msgType() noexcept
Message tag of standard messages.
interfaceProperties interface(alpha1, U, thermo->transportPropertiesDict())
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
List< labelList > labelListList
List of labelList.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
#define forAll(list, i)
Loop across all elements in list.
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
UPtrList< const lduInterface > lduInterfacePtrsList
Store lists of lduInterface as a UPtrList.
List< labelListList > labelListListList
List of labelListList.
errorManip< error > abort(error &err)
int debug
Static debugging option.
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.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
static List< int > & procID(const label communicator)
The list of ranks within a given communicator.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
const std::string patch
OpenFOAM patch number as a std::string.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
List< label > labelList
A List of labels.
void setSize(const label n)
Alias for resize()
List< bool > boolList
A List of bools.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
label nCells(const label leveli) const
Return number of coarse cells (before processor agglomeration)
static constexpr const zero Zero
Global zero (0)