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);
313 PstreamBuffers pBufs(comm);
330 bitSet validCoeffs(interfaces.size());
331 forAll(interfaceBouCoeffs, intI)
333 if (interfaceBouCoeffs.set(intI))
335 validCoeffs.set(intI);
340 bitSet validInterface(interfaces.size());
343 const label allIntI = boundaryMap[proci][intI];
344 if (interfaces.set(intI) && allIntI != -1)
346 validInterface.set(intI);
357 for (
const label intI : validCoeffs)
360 << interfaceBouCoeffs[intI]
361 << interfaceIntCoeffs[intI];
363 for (
const label intI : validInterface)
365 const auto&
interface =
refCast<const GAMGInterfaceField>
376 pBufs.finishedGathers();
383 const lduMesh& destMesh = agglomeration_.meshLevel(destLevel);
387 otherMats.
resize(nProcs-1);
388 otherBouCoeffs.resize(nProcs-1);
389 otherIntCoeffs.resize(nProcs-1);
390 otherInterfaces.resize(nProcs-1);
394 const label otherI = proci-1;
396 UIPstream fromProc(proci, pBufs);
398 otherMats.set(otherI,
new lduMatrix(destMesh, fromProc));
401 const bitSet validCoeffs(fromProc);
402 const bitSet validInterface(fromProc);
404 otherBouCoeffs.emplace_set(otherI, validCoeffs.size());
405 otherIntCoeffs.emplace_set(otherI, validCoeffs.size());
406 otherInterfaces.emplace_set(otherI, validInterface.size());
409 for (
const label intI : validCoeffs)
411 otherBouCoeffs[otherI].emplace_set(intI, fromProc);
412 otherIntCoeffs[otherI].emplace_set(intI, fromProc);
416 for (
const label intI : validInterface)
418 const word coupleType(fromProc);
420 const label allIntI = boundaryMap[proci][intI];
422 otherInterfaces[otherI].set
428 refCast<const GAMGInterface>
430 destInterfaces[allIntI]
441 void Foam::GAMGSolver::procAgglomerateMatrix
445 const List<label>& agglomProcIDs,
450 autoPtr<lduMatrix>& allMatrixPtr,
451 FieldField<Field, scalar>& allInterfaceBouCoeffs,
452 FieldField<Field, scalar>& allInterfaceIntCoeffs,
453 PtrList<lduInterfaceField>& allPrimitiveInterfaces,
457 const lduMatrix& coarsestMatrix = matrixLevels_[levelI];
459 interfaceLevels_[levelI];
460 const FieldField<Field, scalar>& coarsestBouCoeffs =
461 interfaceLevelsBouCoeffs_[levelI];
462 const FieldField<Field, scalar>& coarsestIntCoeffs =
463 interfaceLevelsIntCoeffs_[levelI];
467 const label agglomComm = agglomeration_.agglomCommunicator(levelI+1);
473 PtrList<lduMatrix> otherMats;
474 PtrList<FieldField<Field, scalar>> otherBouCoeffs;
475 PtrList<FieldField<Field, scalar>> otherIntCoeffs;
476 PtrList<PtrList<lduInterfaceField>> otherInterfaces;
499 const lduMesh& allMesh = agglomeration_.meshLevel(levelI+1);
500 const labelList& cellOffsets = agglomeration_.cellOffsets(levelI+1);
502 const labelListList& boundaryMap = agglomeration_.boundaryMap(levelI+1);
504 agglomeration_.boundaryFaceMap(levelI+1);
506 allMatrixPtr.reset(
new lduMatrix(allMesh));
507 lduMatrix& allMatrix = allMatrixPtr();
509 if (coarsestMatrix.hasDiag())
516 coarsestMatrix.diag().size()
517 ) = coarsestMatrix.diag();
524 otherMats[i].diag().size(),
526 ) = otherMats[i].
diag();
529 if (coarsestMatrix.hasLower())
532 UIndirectList<scalar>
536 ) = coarsestMatrix.lower();
539 UIndirectList<scalar>
543 ) = otherMats[i].
lower();
546 if (coarsestMatrix.hasUpper())
549 UIndirectList<scalar>
553 ) = coarsestMatrix.upper();
556 UIndirectList<scalar>
560 ) = otherMats[i].
upper();
570 allInterfaceBouCoeffs.
setSize(allMeshInterfaces.size());
571 allInterfaceIntCoeffs.setSize(allMeshInterfaces.size());
572 allPrimitiveInterfaces.setSize(allMeshInterfaces.size());
573 allInterfaces.setSize(allMeshInterfaces.size());
575 forAll(allMeshInterfaces, intI)
577 const lduInterface&
patch = allMeshInterfaces[intI];
578 label size =
patch.faceCells().size();
580 allInterfaceBouCoeffs.set(intI,
new scalarField(size));
581 allInterfaceIntCoeffs.set(intI,
new scalarField(size));
584 UPtrList<lduInterfaceField> otherFlds(0);
586 forAll(boundaryMap, proci)
588 const FieldField<Field, scalar>& procBouCoeffs
592 : otherBouCoeffs[proci-1]
594 const FieldField<Field, scalar>& procIntCoeffs
598 : otherIntCoeffs[proci-1]
602 const labelList& bMap = boundaryMap[proci];
605 label allIntI = bMap[procIntI];
612 if (!allInterfaces.set(allIntI))
614 const GAMGInterface& intf = refCast<const GAMGInterface>
616 allMeshInterfaces[allIntI]
626 refCast<const GAMGInterfaceField>
628 coarsestInterfaces[procIntI]
631 allPrimitiveInterfaces.set
644 if (otherInterfaces[proci-1].
set(procIntI))
647 refCast<const GAMGInterfaceField>
649 otherInterfaces[proci-1][procIntI]
652 allPrimitiveInterfaces.set
668 allPrimitiveInterfaces.set
683 allPrimitiveInterfaces.get(allIntI)
690 scalarField& allBou = allInterfaceBouCoeffs[allIntI];
691 scalarField& allInt = allInterfaceIntCoeffs[allIntI];
693 const labelList& map = boundaryFaceMap[proci][procIntI];
695 const scalarField& procBou = procBouCoeffs[procIntI];
696 const scalarField& procInt = procIntCoeffs[procIntI];
700 label allFacei = map[i];
706 allBou[allFacei] = procBou[i];
707 allInt[allFacei] = procInt[i];
710 else if (procBouCoeffs.set(procIntI))
714 const labelList& map = boundaryFaceMap[proci][procIntI];
715 const scalarField& procBou = procBouCoeffs[procIntI];
716 const scalarField& procInt = procIntCoeffs[procIntI];
722 label allFacei = map[i];
724 if (coarsestMatrix.hasUpper())
726 allMatrix.upper()[allFacei] = -procBou[i];
728 if (coarsestMatrix.hasLower())
730 allMatrix.lower()[allFacei] = -procInt[i];
735 label allFacei = -map[i]-1;
737 if (coarsestMatrix.hasUpper())
739 allMatrix.upper()[allFacei] = -procInt[i];
741 if (coarsestMatrix.hasLower())
743 allMatrix.lower()[allFacei] = -procBou[i];
779 void Foam::GAMGSolver::procAgglomerateMatrix
782 const List<label>& agglomProcIDs,
787 autoPtr<lduMatrix> allMatrixPtr;
788 autoPtr<FieldField<Field, scalar>> allInterfaceBouCoeffs
790 new FieldField<Field, scalar>(0)
792 autoPtr<FieldField<Field, scalar>> allInterfaceIntCoeffs
794 new FieldField<Field, scalar>(0)
796 autoPtr<PtrList<lduInterfaceField>> allPrimitiveInterfaces
798 new PtrList<lduInterfaceField>(0)
800 autoPtr<lduInterfaceFieldPtrsList> allInterfaces
805 procAgglomerateMatrix
815 allInterfaceBouCoeffs(),
816 allInterfaceIntCoeffs(),
817 allPrimitiveInterfaces(),
821 matrixLevels_.set(levelI, allMatrixPtr);
822 interfaceLevelsBouCoeffs_.set(levelI, allInterfaceBouCoeffs);
823 interfaceLevelsIntCoeffs_.set(levelI, allInterfaceIntCoeffs);
824 primitiveInterfaceLevels_.set(levelI, allPrimitiveInterfaces);
825 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) to Type reference.
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.
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.
void resize(const label newLen)
Change the size of the list. Any new entries are nullptr.
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.
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)