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
287 const lduMesh& dummyMesh,
288 const label meshComm,
290 const lduMatrix& mat,
291 const FieldField<Field, scalar>& interfaceBouCoeffs,
292 const FieldField<Field, scalar>& interfaceIntCoeffs,
295 PtrList<lduMatrix>& otherMats,
296 PtrList<FieldField<Field, scalar>>& otherBouCoeffs,
297 PtrList<FieldField<Field, scalar>>& otherIntCoeffs,
298 List<boolList>& otherTransforms,
299 List<List<label>>& otherRanks
304 Pout<<
"GAMGSolver::gatherMatrices :" 305 <<
" collecting matrices from procs:" << procIDs
306 <<
" using comm:" << meshComm <<
endl;
312 otherMats.setSize(procIDs.size()-1);
313 otherBouCoeffs.setSize(procIDs.size()-1);
314 otherIntCoeffs.setSize(procIDs.size()-1);
315 otherTransforms.setSize(procIDs.size()-1);
316 otherRanks.setSize(procIDs.size()-1);
318 for (label proci = 1; proci < procIDs.size(); proci++)
320 label otherI = proci-1;
331 otherMats.set(otherI,
new lduMatrix(dummyMesh, fromProc));
334 boolList& procTransforms = otherTransforms[otherI];
335 List<label>& procRanks = otherRanks[otherI];
337 fromProc >> procTransforms;
338 fromProc >> procRanks;
344 new FieldField<Field, scalar>(procRanks.size())
349 new FieldField<Field, scalar>(procRanks.size())
353 if (procRanks[intI] != -1)
355 otherBouCoeffs[otherI].set
360 otherIntCoeffs[otherI].set
374 boolList procTransforms(interfaceBouCoeffs.size(),
false);
375 List<label> procRanks(interfaceBouCoeffs.size(), -1);
378 if (interfaces.set(intI))
380 const processorLduInterfaceField&
interface =
381 refCast<const processorLduInterfaceField>
386 procTransforms[intI] =
interface.doTransform();
400 toMaster << mat << procTransforms << procRanks;
403 if (procRanks[intI] != -1)
406 << interfaceBouCoeffs[intI]
407 << interfaceIntCoeffs[intI];
414 void Foam::GAMGSolver::procAgglomerateMatrix
418 const List<label>& agglomProcIDs,
423 autoPtr<lduMatrix>& allMatrixPtr,
424 FieldField<Field, scalar>& allInterfaceBouCoeffs,
425 FieldField<Field, scalar>& allInterfaceIntCoeffs,
426 PtrList<lduInterfaceField>& allPrimitiveInterfaces,
430 const lduMatrix& coarsestMatrix = matrixLevels_[levelI];
432 interfaceLevels_[levelI];
433 const FieldField<Field, scalar>& coarsestBouCoeffs =
434 interfaceLevelsBouCoeffs_[levelI];
435 const FieldField<Field, scalar>& coarsestIntCoeffs =
436 interfaceLevelsIntCoeffs_[levelI];
437 const lduMesh& coarsestMesh = coarsestMatrix.mesh();
439 label coarseComm = coarsestMesh.comm();
444 PtrList<lduMatrix> otherMats;
445 PtrList<FieldField<Field, scalar>> otherBouCoeffs;
446 PtrList<FieldField<Field, scalar>> otherIntCoeffs;
447 List<boolList> otherTransforms;
448 List<List<label>> otherRanks;
484 const lduMesh& allMesh = agglomeration_.meshLevel(levelI+1);
485 const labelList& cellOffsets = agglomeration_.cellOffsets(levelI+1);
487 const labelListList& boundaryMap = agglomeration_.boundaryMap(levelI+1);
489 agglomeration_.boundaryFaceMap(levelI+1);
491 allMatrixPtr.reset(
new lduMatrix(allMesh));
492 lduMatrix& allMatrix = allMatrixPtr();
494 if (coarsestMatrix.hasDiag())
501 coarsestMatrix.diag().size()
502 ) = coarsestMatrix.diag();
509 otherMats[i].diag().size(),
511 ) = otherMats[i].
diag();
514 if (coarsestMatrix.hasLower())
517 UIndirectList<scalar>
521 ) = coarsestMatrix.lower();
524 UIndirectList<scalar>
528 ) = otherMats[i].
lower();
531 if (coarsestMatrix.hasUpper())
534 UIndirectList<scalar>
538 ) = coarsestMatrix.upper();
541 UIndirectList<scalar>
545 ) = otherMats[i].
upper();
555 allInterfaceBouCoeffs.
setSize(allMeshInterfaces.size());
556 allInterfaceIntCoeffs.setSize(allMeshInterfaces.size());
557 allPrimitiveInterfaces.setSize(allMeshInterfaces.size());
558 allInterfaces.setSize(allMeshInterfaces.size());
560 forAll(allMeshInterfaces, intI)
562 const lduInterface&
patch = allMeshInterfaces[intI];
563 label size =
patch.faceCells().size();
565 allInterfaceBouCoeffs.set(intI,
new scalarField(size));
566 allInterfaceIntCoeffs.set(intI,
new scalarField(size));
569 labelList nBounFaces(allMeshInterfaces.size());
570 forAll(boundaryMap, proci)
572 const FieldField<Field, scalar>& procBouCoeffs
576 : otherBouCoeffs[proci-1]
578 const FieldField<Field, scalar>& procIntCoeffs
582 : otherIntCoeffs[proci-1]
585 const labelList& bMap = boundaryMap[proci];
588 label allIntI = bMap[procIntI];
595 if (!allInterfaces.set(allIntI))
599 bool doTransform =
false;
603 const processorGAMGInterfaceField& procInt =
606 const processorGAMGInterfaceField
609 coarsestInterfaces[procIntI]
611 doTransform = procInt.doTransform();
612 rank = procInt.rank();
617 otherTransforms[proci-1][procIntI];
618 rank = otherRanks[proci-1][procIntI];
621 allPrimitiveInterfaces.set
626 refCast<const GAMGInterface>
628 allMeshInterfaces[allIntI]
637 &allPrimitiveInterfaces[allIntI]
644 scalarField& allBou = allInterfaceBouCoeffs[allIntI];
645 scalarField& allInt = allInterfaceIntCoeffs[allIntI];
647 const labelList& map = boundaryFaceMap[proci][procIntI];
649 const scalarField& procBou = procBouCoeffs[procIntI];
650 const scalarField& procInt = procIntCoeffs[procIntI];
654 label allFacei = map[i];
660 allBou[allFacei] = procBou[i];
661 allInt[allFacei] = procInt[i];
664 else if (procBouCoeffs.set(procIntI))
668 const labelList& map = boundaryFaceMap[proci][procIntI];
669 const scalarField& procBou = procBouCoeffs[procIntI];
670 const scalarField& procInt = procIntCoeffs[procIntI];
677 label allFacei = map[i];
679 if (coarsestMatrix.hasUpper())
681 allMatrix.upper()[allFacei] = -procBou[i];
683 if (coarsestMatrix.hasLower())
685 allMatrix.lower()[allFacei] = -procInt[i];
690 label allFacei = -map[i]-1;
692 if (coarsestMatrix.hasUpper())
694 allMatrix.upper()[allFacei] = -procInt[i];
696 if (coarsestMatrix.hasLower())
698 allMatrix.lower()[allFacei] = -procBou[i];
734 void Foam::GAMGSolver::procAgglomerateMatrix
737 const List<label>& agglomProcIDs,
742 autoPtr<lduMatrix> allMatrixPtr;
743 autoPtr<FieldField<Field, scalar>> allInterfaceBouCoeffs
745 new FieldField<Field, scalar>(0)
747 autoPtr<FieldField<Field, scalar>> allInterfaceIntCoeffs
749 new FieldField<Field, scalar>(0)
751 autoPtr<PtrList<lduInterfaceField>> allPrimitiveInterfaces
753 new PtrList<lduInterfaceField>(0)
755 autoPtr<lduInterfaceFieldPtrsList> allInterfaces
760 procAgglomerateMatrix
770 allInterfaceBouCoeffs(),
771 allInterfaceIntCoeffs(),
772 allPrimitiveInterfaces(),
776 matrixLevels_.set(levelI, allMatrixPtr);
777 interfaceLevelsBouCoeffs_.set(levelI, allInterfaceBouCoeffs);
778 interfaceLevelsIntCoeffs_.set(levelI, allInterfaceIntCoeffs);
779 primitiveInterfaceLevels_.set(levelI, allPrimitiveInterfaces);
780 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 > &)
"scheduled" : (MPI_Send, MPI_Recv)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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.
const std::string patch
OpenFOAM patch number as a std::string.
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)