Changed crMatrix and crAddressing member naming

This commit is contained in:
Hrvoje Jasak 2017-05-10 13:19:15 +01:00
parent 9e9168c389
commit bae31764dc
6 changed files with 249 additions and 231 deletions

View file

@ -36,28 +36,30 @@ Author
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::crAddressing::setRowCount(const labelList& count) void Foam::crAddressing::setRowSizes(const labelList& rowSizes)
{ {
if (count.size() != nRows_) if (rowSizes.size() != nRows_)
{ {
FatalErrorIn("void crAddressing::setRowCount(const labelList& count)") FatalErrorIn
<< "Incorrect size of count: nRows =" << nRows_ (
<< " count = " << count.size() "void crAddressing::setRowSizes(const labelList& rowSizes)"
) << "Incorrect size of rowSizes: nRows =" << nRows_
<< " rowSizes = " << rowSizes.size()
<< abort(FatalError); << abort(FatalError);
} }
// Accumulate count // Accumulate rowSizes
row_[0] = 0; rowStart_[0] = 0;
forAll (count, i) forAll (rowSizes, i)
{ {
row_[i + 1] = row_[i] + count[i]; rowStart_[i + 1] = rowStart_[i] + rowSizes[i];
} }
// Resize and clear column array // Resize and clear column array
col_.setSize(row_[nRows_]); column_.setSize(rowStart_[nRows_]);
col_ = 0; column_ = 0;
} }
@ -68,16 +70,16 @@ Foam::crAddressing::crAddressing
( (
const label nRows, const label nRows,
const label nCols, const label nCols,
const labelList& count const labelList& rowSizes
) )
: :
refCount(), refCount(),
nRows_(nRows), nRows_(nRows),
nCols_(nCols), nCols_(nCols),
row_(nRows + 1), rowStart_(nRows + 1),
col_(0) column_(0)
{ {
setRowCount(count); setRowSizes(rowSizes);
} }
@ -93,8 +95,8 @@ Foam::crAddressing::crAddressing
refCount(), refCount(),
nRows_(nRows), nRows_(nRows),
nCols_(nCols), nCols_(nCols),
row_(row), rowStart_(row),
col_(col) column_(col)
{} {}
@ -104,8 +106,8 @@ Foam::crAddressing::crAddressing(const crAddressing& a)
refCount(), refCount(),
nRows_(a.nRows_), nRows_(a.nRows_),
nCols_(a.nCols_), nCols_(a.nCols_),
row_(a.row_), rowStart_(a.rowStart_),
col_(a.col_) column_(a.column_)
{} {}
@ -115,8 +117,8 @@ Foam::crAddressing::crAddressing(Istream& is)
refCount(), refCount(),
nRows_(readLabel(is)), nRows_(readLabel(is)),
nCols_(readLabel(is)), nCols_(readLabel(is)),
row_(is), rowStart_(is),
col_(is) column_(is)
{} {}
@ -124,31 +126,34 @@ Foam::crAddressing::crAddressing(Istream& is)
Foam::tmp<Foam::crAddressing> Foam::crAddressing::T() const Foam::tmp<Foam::crAddressing> Foam::crAddressing::T() const
{ {
const labelList& myRow = row(); const labelList& myRow = rowStart();
const labelList& myCol = col(); const labelList& myCol = column();
labelList trCount(nCols(), 0); labelList trRowSizes(nCols(), 0);
// Count number of entries in a row // Count number of entries in a row
for (label i = 0; i < nRows(); i++) for (label i = 0; i < nRows(); i++)
{ {
for (label ip = myRow[i]; ip < myRow[i + 1]; ip++) for (label ip = myRow[i]; ip < myRow[i + 1]; ip++)
{ {
trCount[myCol[ip]]++; trRowSizes[myCol[ip]]++;
} }
} }
// Create transpose addressing // Create transpose addressing
tmp<crAddressing> ttranspose(new crAddressing(nCols(), nRows(), trCount)); tmp<crAddressing> ttranspose
(
new crAddressing(nCols(), nRows(), trRowSizes)
);
crAddressing& transpose = ttranspose(); crAddressing& transpose = ttranspose();
// Set coefficients // Set coefficients
const labelList& trRow = transpose.row(); const labelList& trRow = transpose.rowStart();
labelList& trCol = transpose.col(); labelList& trCol = transpose.column();
trCol = 0; trCol = 0;
// Reset count to use as counter // Reset rowSizes to use as counter
trCount = 0; trRowSizes = 0;
label j; label j;
@ -158,9 +163,9 @@ Foam::tmp<Foam::crAddressing> Foam::crAddressing::T() const
{ {
j = myCol[ip]; j = myCol[ip];
trCol[trRow[j] + trCount[j]] = i; trCol[trRow[j] + trRowSizes[j]] = i;
trCount[j]++; trRowSizes[j]++;
} }
} }
@ -184,8 +189,8 @@ void Foam::crAddressing::operator=(const crAddressing& rhs)
nRows_ = rhs.nRows_; nRows_ = rhs.nRows_;
nCols_ = rhs.nCols_; nCols_ = rhs.nCols_;
row_ = rhs.row_; rowStart_ = rhs.rowStart_;
col_ = rhs.col_; column_ = rhs.column_;
} }
@ -194,8 +199,8 @@ void Foam::crAddressing::operator=(const crAddressing& rhs)
Foam::Ostream& Foam::operator<<(Ostream& os, const crAddressing& a) Foam::Ostream& Foam::operator<<(Ostream& os, const crAddressing& a)
{ {
os << a.nRows_ << tab << a.nCols_ << nl os << a.nRows_ << tab << a.nCols_ << nl
<< a.row_ << nl << a.rowStart_ << nl
<< a.col_ << endl; << a.column_ << endl;
return os; return os;
} }

View file

@ -64,15 +64,15 @@ class crAddressing
//- Row array. //- Row array.
// Provides start index for each row, dimensioned to nRows + 1 // Provides start index for each row, dimensioned to nRows + 1
labelList row_; labelList rowStart_;
//- Column array //- Column index array
labelList col_; labelList column_;
// Private Member Functions // Private Member Functions
//- Set row count //- Set row sizes
void setRowCount(const labelList& count); void setRowSizes(const labelList& count);
public: public:
@ -84,7 +84,7 @@ public:
( (
const label nRows, const label nRows,
const label nCols, const label nCols,
const labelList& count const labelList& nEntries
); );
//- Construct from components //- Construct from components
@ -92,8 +92,8 @@ public:
( (
const label nRows, const label nRows,
const label nCols, const label nCols,
const labelList& row, const labelList& rowStart,
const labelList& col const labelList& column
); );
//- Construct as copy //- Construct as copy
@ -125,28 +125,28 @@ public:
//- Return number of coefficients //- Return number of coefficients
label nEntries() const label nEntries() const
{ {
return col_.size(); return column_.size();
} }
//- Return row array //- Return row array
const labelList& row() const const labelList& rowStart() const
{ {
return row_; return rowStart_;
} }
//- Return column array //- Return column array
const labelList& col() const const labelList& column() const
{ {
return col_; return column_;
} }
// Edit // Edit
//- Return column array //- Return column array
labelList& col() labelList& column()
{ {
return col_; return column_;
} }
@ -160,6 +160,7 @@ public:
void operator=(const crAddressing&); void operator=(const crAddressing&);
// IOstream Operators // IOstream Operators
friend Ostream& operator<<(Ostream&, const crAddressing&); friend Ostream& operator<<(Ostream&, const crAddressing&);

View file

@ -109,8 +109,8 @@ Foam::tmp<Foam::crMatrix> Foam::crMatrix::T() const
{ {
// My addressing // My addressing
const label myNRows = crAddr().nRows(); const label myNRows = crAddr().nRows();
const labelList& myRow = crAddr().row(); const labelList& myRow = crAddr().rowStart();
const labelList& myCol = crAddr().col(); const labelList& myCol = crAddr().column();
const scalarField& myCoeffs = coeffs(); const scalarField& myCoeffs = coeffs();
// Create transpose // Create transpose
@ -123,8 +123,8 @@ Foam::tmp<Foam::crMatrix> Foam::crMatrix::T() const
tCoeffs = 0; tCoeffs = 0;
// Transpose addressing // Transpose addressing
const labelList& tRow = transpose.crAddr().row(); const labelList& tRow = transpose.crAddr().rowStart();
const labelList& tCol = transpose.crAddr().col(); const labelList& tCol = transpose.crAddr().column();
// Set transpose coefficients // Set transpose coefficients
@ -153,8 +153,8 @@ Foam::tmp<Foam::crMatrix> Foam::crMatrix::T() const
// Calculate b += A*x // Calculate b += A*x
void Foam::crMatrix::dotPlus(scalarField& b, const scalarField& x) const void Foam::crMatrix::dotPlus(scalarField& b, const scalarField& x) const
{ {
const labelList& row = crAddr_.row(); const labelList& row = crAddr_.rowStart();
const labelList& col = crAddr_.col(); const labelList& col = crAddr_.column();
forAll (b, i) forAll (b, i)
{ {

View file

@ -83,8 +83,8 @@ public:
( (
const label nRows, const label nRows,
const label nCols, const label nCols,
const labelList& row, const labelList& rowStart,
const labelList& col const labelList& column
); );
//- Construct as copy //- Construct as copy
@ -123,9 +123,9 @@ public:
} }
//- Return column array to be set //- Return column array to be set
labelList& col() labelList& column()
{ {
return crAddr_.col(); return crAddr_.column();
} }

View file

@ -45,210 +45,215 @@ namespace Foam
Foam::processorSAMGInterface::processorSAMGInterface Foam::processorSAMGInterface::processorSAMGInterface
( (
const lduPrimitiveMesh& lduMesh, const lduPrimitiveMesh& lduMesh,
const crMatrix& prolongation,
const lduInterfacePtrsList& coarseInterfaces, const lduInterfacePtrsList& coarseInterfaces,
const lduInterface& fineInterface, const lduInterface& fineInterface,
const labelField& localRestrictAddressing, const labelField& localRowLabel,
const labelField& neighbourRestrictAddressing const labelField& neighbourRowLabel
) )
: :
SAMGInterface(lduMesh), SAMGInterface(lduMesh, prolongation),
fineProcInterface_(refCast<const processorLduInterface>(fineInterface)), fineProcInterface_(refCast<const processorLduInterface>(fineInterface)),
comm_(fineProcInterface_.comm()), comm_(fineProcInterface_.comm()),
tag_(fineProcInterface_.tag()) tag_(fineProcInterface_.tag())
{ {
Pout<< "Creating processor SAMG interface" << endl; Pout<< "Creating processor SAMG interface" << endl;
/* HJ, Code missing here
// Make a lookup table of entries for owner/neighbour // Analyse the local and neighbour row label:
HashTable<SLList<label>, label, Hash<label> > neighboursTable // local coarse, remote coarse = regular coarse face
// local coarse, remote fine = local expanded face: receive prolonged data
// local fine, remote coarse = neighbour expanded face: send prolonged data
// Algorithm
// Go through local row labels and examine cases
// 1) coarse local and coarse remote:
// create coarse processor face and set faceCells. Set weight to 1
// 2) coarse local and fine remote:
// will receive coarse neighbours and weights from opposite side
// 3) fine local and coarse remote:
// assemble local coarse neighbours and weights from the prolongation
// 4) fine local and fine remote - ignore
//
// On completion of selection:
// send and receive local coarse neighbours for fine local/coarse remote
// sort coarse equations by increasing coarse index from master side
// create faceCells, fineAddressing and fineWeights
// First collect and communicate internal neighbours from the local fine
// side (ie neighbour processor cell is coarse)
HashTable<labelList, label, Hash<label> > neighboursFromLocalFine
( (
localRestrictAddressing.size() Foam::max(128, fineProcInterface_.interfaceSize()/4)
); );
// Table of face-sets to be agglomerated HashTable<scalarField, label, Hash<label> > weightsFromLocalFine
HashTable<SLList<SLList<label> >, label, Hash<label> > faceFaceTable
( (
localRestrictAddressing.size() Foam::max(128, fineProcInterface_.interfaceSize()/4)
); );
// Get access to the prolongation addressing and coefficients
const labelList& pRowStart = prolongation.crAddr().rowStart();
const labelList& pColumn = prolongation.crAddr().column();
const scalarField& pCoeffs = prolongation.coeffs();
// Get fine faceCells
const labelList& fineFaceCells = fineInterface.faceCells();
Pout<< "fineFaceCells: " << fineFaceCells << endl;
// Collect local fine to neighbour coarse connections for communication
forAll (localRowLabel, faceI)
{
if
(
localRowLabel[faceI] < 0
&& neighbourRowLabel[faceI] >= 0
)
{
// Found local fine to neighbour coarse interface
// Collect local coarse neighbours and weights from the
// prolongation matrix to send to other processor
const label curStart = pRowStart[fineFaceCells[faceI]];
const label curEnd = pRowStart[fineFaceCells[faceI] + 1];
const label nCoarse = curEnd - curStart;
Pout<< "Eqn: " << fineFaceCells[faceI] << " Span: " << curStart << " " << curEnd << " = " << nCoarse << endl;
labelList nbrs(nCoarse);
scalarField weights(nCoarse);
forAll (nbrs, i)
{
nbrs[i] = pColumn[curStart + i];
weights[i] = pCoeffs[curStart + i];
}
Pout<< "weights: " << weights << endl;
// Insert neighbours under remote coarse index
neighboursFromLocalFine.insert(neighbourRowLabel[faceI], nbrs);
weightsFromLocalFine.insert(neighbourRowLabel[faceI], weights);
}
}
// Receive remote prolongation data
HashTable<labelList, label, Hash<label> > neighboursFromRemoteFine;
HashTable<scalarField, label, Hash<label> > weightsFromRemoteFine;
// Send and receive the addressing from the other side
{
OPstream toNbr(Pstream::blocking, neighbProcNo());
toNbr<< neighboursFromLocalFine << weightsFromLocalFine;
}
{
IPstream fromNbr(Pstream::blocking, neighbProcNo());
neighboursFromRemoteFine =
HashTable<labelList, label, Hash<label> >(fromNbr);
weightsFromRemoteFine =
HashTable<scalarField, label, Hash<label> >(fromNbr);
}
// Assemble connectivity
// Resize arrays to size of fine interface
// Note: it is technically possible to have MORE coarse processor faces
// so a check will be made in the end
faceCells_.setSize(5*fineProcInterface_.interfaceSize());
fineAddressing_.setSize(5*fineProcInterface_.interfaceSize());
fineWeights_.setSize(5*fineProcInterface_.interfaceSize());
// Count coarse faces
label nCoarseFaces = 0; label nCoarseFaces = 0;
forAll (localRestrictAddressing, ffi) // Collect coarse-to-fine connections
forAll (localRowLabel, faceI)
{ {
label curMaster = -1; if
label curSlave = -1;
// Do switching on master/slave indexes based on the owner/neighbour of
// the processor index such that both sides get the same answer.
if (myProcNo() < neighbProcNo())
{
// Master side
curMaster = localRestrictAddressing[ffi];
curSlave = neighbourRestrictAddressing[ffi];
}
else
{
// Slave side
curMaster = neighbourRestrictAddressing[ffi];
curSlave = localRestrictAddressing[ffi];
}
// Look for the master cell. If it has already got a face,
// add the coefficient to the face. If not, create a new face.
if (neighboursTable.found(curMaster))
{
// Check all current neighbours to see if the current slave already
// exists and if so, add the fine face to the agglomeration.
SLList<label>& curNbrs = neighboursTable.find(curMaster)();
SLList<SLList<label> >& curFaceFaces =
faceFaceTable.find(curMaster)();
bool nbrFound = false;
SLList<label>::iterator nbrsIter = curNbrs.begin();
SLList<SLList<label> >::iterator faceFacesIter =
curFaceFaces.begin();
for
( (
; localRowLabel[faceI] >= 0
nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end(); && neighbourRowLabel[faceI] >= 0
++nbrsIter, ++faceFacesIter
) )
{ {
if (nbrsIter() == curSlave) // Found local coarse to neighbour coarse face
Pout<< "face " << faceI << " CC" << endl;
// Create new coarse face
faceCells_[nCoarseFaces] = localRowLabel[faceI];
fineAddressing_[nCoarseFaces] = faceI;
fineWeights_[nCoarseFaces] = 1;
nCoarseFaces++;
}
else if
(
localRowLabel[faceI] < 0
&& neighbourRowLabel[faceI] >= 0
)
{ {
nbrFound = true; // Found local fine to neighbour coarse face
faceFacesIter().append(ffi);
break; // Pick up local prolongation coarse entries and for all
// add a new face with appropriate weight
// Note: faceCells changes due to (internal) local coarse cells
const labelList& curLocalCoarseNbrs =
neighboursFromLocalFine[neighbourRowLabel[faceI]];
const scalarField& curLocalCoarseWeights =
weightsFromLocalFine[neighbourRowLabel[faceI]];
Pout<< "face " << faceI << " FC, size: " << curLocalCoarseNbrs.size()
<< " W: " << curLocalCoarseWeights << endl;
forAll (curLocalCoarseNbrs, curNbrI)
{
// Create new coarse face
faceCells_[nCoarseFaces] = curLocalCoarseNbrs[curNbrI];
fineAddressing_[nCoarseFaces] = faceI;
fineWeights_[nCoarseFaces] = curLocalCoarseWeights[curNbrI];
nCoarseFaces++;
} }
} }
else if
if (!nbrFound) (
localRowLabel[faceI] >= 0
&& neighbourRowLabel[faceI] < 0
)
{ {
curNbrs.append(curSlave); // Found local coarse to neighbour fine face
curFaceFaces.append(SLList<label>(ffi));
// New coarse face created // Pick up neighbour prolongation coarse entries and for all
// add a new face with appropriate weight
// Note: faceCells remains the same: single local coarse cell
const labelList& curNbrCoarseNbrs =
neighboursFromRemoteFine[localRowLabel[faceI]];
const scalarField& curNbrCoarseWeights =
weightsFromRemoteFine[localRowLabel[faceI]];
Pout<< "face " << faceI << " CF, size: " << curNbrCoarseNbrs.size()
<< " W: " << curNbrCoarseWeights << endl;
forAll (curNbrCoarseNbrs, curNbrI)
{
// Create new coarse face
faceCells_[nCoarseFaces] = localRowLabel[faceI];
fineAddressing_[nCoarseFaces] = faceI;
fineWeights_[nCoarseFaces] = curNbrCoarseWeights[curNbrI];
nCoarseFaces++; nCoarseFaces++;
} }
} }
else else
{ {
// This master has got no neighbours yet. Add a neighbour // Fine to fine. Ignore
// and a coefficient, thus creating a new face }
neighboursTable.insert(curMaster, SLList<label>(curSlave));
faceFaceTable.insert
(
curMaster,
SLList<SLList<label> >(SLList<label>(ffi))
);
// New coarse face created
nCoarseFaces++;
} }
} // end for all fine faces
// Check for fixed lists
faceCells_.setSize(nCoarseFaces, -1); if (nCoarseFaces > 5*fineProcInterface_.interfaceSize())
fineAddressing_.setSize(localRestrictAddressing.size(), -1);
restrictAddressing_.setSize(localRestrictAddressing.size(), -1);
// All weights are equal to 1: integral matching
restrictWeights_.setSize(localRestrictAddressing.size(), 1.0);
labelList contents = neighboursTable.toc();
// Sort makes sure the order is identical on both sides.
// HJ, 20/Feb.2009
sort(contents);
// Reset face counter for re-use
nCoarseFaces = 0;
if (myProcNo() < neighbProcNo())
{ {
// On master side, the owner addressing is stored in table of contents FatalErrorIn("processorSAMGInterface::processorSAMGInterface(...)")
forAll (contents, masterI) << "Coarse SAMG processor siginificantly bigger than fine: "
{ << "nCoarseFaces = " << nCoarseFaces
SLList<label>& curNbrs = neighboursTable.find(contents[masterI])(); << " nFineFaces = " << fineProcInterface_.interfaceSize()
<< abort(FatalError);
SLList<SLList<label> >& curFaceFaces =
faceFaceTable.find(contents[masterI])();
SLList<label>::iterator nbrsIter = curNbrs.begin();
SLList<SLList<label> >::iterator faceFacesIter =
curFaceFaces.begin();
for
(
;
nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
++nbrsIter, ++faceFacesIter
)
{
faceCells_[nCoarseFaces] = contents[masterI];
for
(
SLList<label>::iterator facesIter =
faceFacesIter().begin();
facesIter != faceFacesIter().end();
++facesIter
)
{
fineAddressing_[facesIter()] = facesIter();
restrictAddressing_[facesIter()] = nCoarseFaces;
} }
Pout<< "nCoarseFaces: " << nCoarseFaces << endl;
nCoarseFaces++; // Resize arrays to final size
} faceCells_.setSize(nCoarseFaces);
} fineAddressing_.setSize(nCoarseFaces);
} fineWeights_.setSize(nCoarseFaces);
else
{
// On slave side, the owner addressing is stored in linked lists
forAll (contents, masterI)
{
SLList<label>& curNbrs = neighboursTable.find(contents[masterI])();
SLList<SLList<label> >& curFaceFaces =
faceFaceTable.find(contents[masterI])();
SLList<label>::iterator nbrsIter = curNbrs.begin();
SLList<SLList<label> >::iterator faceFacesIter =
curFaceFaces.begin();
for
(
;
nbrsIter != curNbrs.end(), faceFacesIter != curFaceFaces.end();
++nbrsIter, ++faceFacesIter
)
{
faceCells_[nCoarseFaces] = nbrsIter();
for
(
SLList<label>::iterator facesIter = faceFacesIter().begin();
facesIter != faceFacesIter().end();
++facesIter
)
{
fineAddressing_[facesIter()] = facesIter();
restrictAddressing_[facesIter()] = nCoarseFaces;
}
nCoarseFaces++;
}
}
}
*/
} }

View file

@ -83,14 +83,15 @@ public:
// Constructors // Constructors
//- Construct from fine-level interface, //- Construct from fine-level interface,
// local and neighbour restrict addressing // local and neighbour row label
processorSAMGInterface processorSAMGInterface
( (
const lduPrimitiveMesh& lduMesh, const lduPrimitiveMesh& lduMesh,
const crMatrix& prolongation,
const lduInterfacePtrsList& coarseInterfaces, const lduInterfacePtrsList& coarseInterfaces,
const lduInterface& fineInterface, const lduInterface& fineInterface,
const labelField& localRestrictAddressing, const labelField& localRowLabel,
const labelField& neighbourRestrictAddressing const labelField& neighbourRowLabel
); );
@ -102,6 +103,12 @@ public:
// Access // Access
//- Return interface size
virtual label interfaceSize() const
{
return SAMGInterface::size();
}
//- Return true if interface is coupled //- Return true if interface is coupled
virtual bool coupled() const virtual bool coupled() const
{ {