Fixing conflict and merging master.

This commit is contained in:
graham
2009-11-10 10:19:23 +00:00
497 changed files with 17240 additions and 4254 deletions

View File

@ -121,7 +121,7 @@ void Foam::SIBS::solve
kMax_ = kOpt_;
}
label k=0;
label k = 0;
scalar h = hTry;
yTemp_ = y;
@ -213,7 +213,7 @@ void Foam::SIBS::solve
x = xNew_;
hDid = h;
first_=0;
first_ = 0;
scalar wrkmin = GREAT;
scalar scale = 1.0;

View File

@ -61,8 +61,8 @@ $(sha1)/SHA1Digest.C
primitives/random/Random.C
containers/HashTables/HashTable/HashTableName.C
containers/HashTables/StaticHashTable/StaticHashTableName.C
containers/HashTables/HashTable/HashTableCore.C
containers/HashTables/StaticHashTable/StaticHashTableCore.C
containers/Lists/SortableList/ParSortableListName.C
containers/Lists/PackedList/PackedListName.C
containers/Lists/ListOps/ListOps.C
@ -108,11 +108,14 @@ StringStreams = $(Streams)/StringStreams
$(StringStreams)/StringStreamsPrint.C
Pstreams = $(Streams)/Pstreams
$(Pstreams)/Pstream.C
$(Pstreams)/PstreamCommsStruct.C
$(Pstreams)/UIPstream.C
$(Pstreams)/IPstream.C
$(Pstreams)/UPstream.C
$(Pstreams)/UPstreamCommsStruct.C
$(Pstreams)/Pstream.C
$(Pstreams)/UOPstream.C
$(Pstreams)/OPstream.C
$(Pstreams)/PstreamsPrint.C
$(Pstreams)/PstreamBuffers.C
dictionary = db/dictionary
$(dictionary)/dictionary.C

View File

@ -30,44 +30,15 @@ License
#include "HashTable.H"
#include "List.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::label Foam::HashTable<T, Key, Hash>::canonicalSize(const label size)
{
if (size < 1)
{
return 0;
}
// enforce power of two
unsigned int goodSize = size;
if (goodSize & (goodSize - 1))
{
// brute-force is fast enough
goodSize = 1;
while (goodSize < unsigned(size))
{
goodSize <<= 1;
}
}
return goodSize;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable(const label size)
:
HashTableName(),
HashTableCore(),
nElmts_(0),
tableSize_(canonicalSize(size)),
table_(NULL),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
tableSize_(HashTableCore::canonicalSize(size)),
table_(NULL)
{
if (tableSize_)
{
@ -84,12 +55,10 @@ Foam::HashTable<T, Key, Hash>::HashTable(const label size)
template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
:
HashTableName(),
HashTableCore(),
nElmts_(0),
tableSize_(ht.tableSize_),
table_(NULL),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
table_(NULL)
{
if (tableSize_)
{
@ -113,12 +82,10 @@ Foam::HashTable<T, Key, Hash>::HashTable
const Xfer<HashTable<T, Key, Hash> >& ht
)
:
HashTableName(),
HashTableCore(),
nElmts_(0),
tableSize_(0),
table_(NULL),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
table_(NULL)
{
transfer(ht());
}
@ -182,7 +149,7 @@ Foam::HashTable<T, Key, Hash>::find
{
if (key == ep->key_)
{
return iterator(*this, ep, hashIdx);
return iterator(this, ep, hashIdx);
}
}
}
@ -195,7 +162,7 @@ Foam::HashTable<T, Key, Hash>::find
}
# endif
return end();
return iterator();
}
@ -214,7 +181,7 @@ Foam::HashTable<T, Key, Hash>::find
{
if (key == ep->key_)
{
return const_iterator(*this, ep, hashIdx);
return const_iterator(this, ep, hashIdx);
}
}
}
@ -227,32 +194,32 @@ Foam::HashTable<T, Key, Hash>::find
}
# endif
return cend();
return const_iterator();
}
template<class T, class Key, class Hash>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::toc() const
{
List<Key> tofc(nElmts_);
label i = 0;
List<Key> keys(nElmts_);
label keyI = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
tofc[i++] = iter.key();
keys[keyI++] = iter.key();
}
return tofc;
return keys;
}
template<class T, class Key, class Hash>
Foam::List<Key> Foam::HashTable<T, Key, Hash>::sortedToc() const
{
List<Key> sortedList = this->toc();
sort(sortedList);
List<Key> sortedLst = this->toc();
sort(sortedLst);
return sortedList;
return sortedLst;
}
@ -290,7 +257,7 @@ bool Foam::HashTable<T, Key, Hash>::set
table_[hashIdx] = new hashedEntry(key, table_[hashIdx], newEntry);
nElmts_++;
if (double(nElmts_)/tableSize_ > 0.8)
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
{
# ifdef FULLDEBUG
if (debug)
@ -342,18 +309,22 @@ bool Foam::HashTable<T, Key, Hash>::set
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const iterator& cit)
bool Foam::HashTable<T, Key, Hash>::iteratorBase::erase()
{
if (cit.elmtPtr_) // note: endIter_ also has 0 elmtPtr_
// note: entryPtr_ is NULL for end(), so this catches that too
if (entryPtr_)
{
iterator& it = const_cast<iterator&>(cit);
// Search element before elmtPtr_
// Search element before entryPtr_
hashedEntry* prev = 0;
for (hashedEntry* ep = table_[it.hashIndex_]; ep; ep = ep->next_)
for
(
hashedEntry* ep = hashTable_->table_[hashIndex_];
ep;
ep = ep->next_
)
{
if (ep == it.elmtPtr_)
if (ep == entryPtr_)
{
break;
}
@ -362,98 +333,76 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& cit)
if (prev)
{
// Have element before elmtPtr
prev->next_ = it.elmtPtr_->next_;
delete it.elmtPtr_;
it.elmtPtr_ = prev;
// has an element before entryPtr - reposition to there
prev->next_ = entryPtr_->next_;
delete entryPtr_;
entryPtr_ = prev;
}
else
{
// elmtPtr is first element on SLList
table_[it.hashIndex_] = it.elmtPtr_->next_;
delete it.elmtPtr_;
// entryPtr was first element on SLList
hashTable_->table_[hashIndex_] = entryPtr_->next_;
delete entryPtr_;
// Search back for previous non-zero table entry
while (--it.hashIndex_ >= 0 && !table_[it.hashIndex_])
{}
// assign any non-NULL pointer value so it doesn't look
// like end()/cend()
entryPtr_ = reinterpret_cast<hashedEntry*>(this);
if (it.hashIndex_ >= 0)
{
// In table entry search for last element
it.elmtPtr_ = table_[it.hashIndex_];
while (it.elmtPtr_ && it.elmtPtr_->next_)
{
it.elmtPtr_ = it.elmtPtr_->next_;
}
}
else
{
// No previous found. Mark with special value which is
// - not end()/cend()
// - handled by operator++
it.elmtPtr_ = reinterpret_cast<hashedEntry*>(this);
it.hashIndex_ = -1;
}
// Mark with special hashIndex value to signal it has been rewound.
// The next increment will bring it back to the present location.
//
// From the current position 'curPos', we wish to continue at
// prevPos='curPos-1', which we mark as markPos='-curPos-1'.
// The negative lets us notice it is special, the extra '-1'
// is needed to avoid ambiguity for position '0'.
// To retrieve prevPos, we would later use '-(markPos+1) - 1'
hashIndex_ = -hashIndex_ - 1;
}
nElmts_--;
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTable<T, Key, Hash>::erase(iterator&) : "
<< "hashedEntry " << it.elmtPtr_->key_ << " removed.\n";
}
# endif
hashTable_->nElmts_--;
return true;
}
else
{
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTable<T, Key, Hash>::erase(iterator&) : "
<< "cannot remove hashedEntry from hash table\n";
}
# endif
return false;
}
}
// NOTE:
// We use (const iterator&) here, but manipulate its contents anyhow.
// The parameter should be (iterator&), but then the compiler doesn't find
// it correctly and tries to call as (iterator) instead.
//
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const iterator& iter)
{
// adjust iterator after erase
return const_cast<iterator&>(iter).erase();
}
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
{
iterator fnd = find(key);
if (fnd != end())
{
return erase(fnd);
}
else
{
return false;
}
return erase(find(key));
}
template<class T, class Key, class Hash>
Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys)
{
const label nTotal = nElmts_;
label count = 0;
// Remove listed keys from this table
if (this->size())
// Remove listed keys from this table - terminates early if possible
for (label keyI = 0; count < nTotal && keyI < keys.size(); ++keyI)
{
forAll(keys, keyI)
if (erase(keys[keyI]))
{
if (erase(keys[keyI]))
{
count++;
}
count++;
}
}
@ -462,24 +411,21 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys)
template<class T, class Key, class Hash>
template<class AnyType>
template<class AnyType, class AnyHash>
Foam::label Foam::HashTable<T, Key, Hash>::erase
(
const HashTable<AnyType, Key, Hash>& rhs
const HashTable<AnyType, Key, AnyHash>& rhs
)
{
label count = 0;
// Remove rhs elements from this table
if (this->size())
// Remove rhs keys from this table - terminates early if possible
// Could optimize depending on which hash is smaller ...
for (iterator iter = begin(); iter != end(); ++iter)
{
// NOTE: could further optimize depending on which hash is smaller
for (iterator iter = begin(); iter != end(); ++iter)
if (rhs.found(iter.key()) && erase(iter))
{
if (rhs.found(iter.key()) && erase(iter))
{
count++;
}
count++;
}
}
@ -490,7 +436,7 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::resize(const label sz)
{
label newSize = canonicalSize(sz);
label newSize = HashTableCore::canonicalSize(sz);
if (newSize == tableSize_)
{
@ -505,22 +451,22 @@ void Foam::HashTable<T, Key, Hash>::resize(const label sz)
return;
}
HashTable<T, Key, Hash>* newTable = new HashTable<T, Key, Hash>(newSize);
HashTable<T, Key, Hash>* tmpTable = new HashTable<T, Key, Hash>(newSize);
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
newTable->insert(iter.key(), *iter);
tmpTable->insert(iter.key(), *iter);
}
label oldTableSize = tableSize_;
tableSize_ = newTable->tableSize_;
newTable->tableSize_ = oldTableSize;
label oldSize = tableSize_;
tableSize_ = tmpTable->tableSize_;
tmpTable->tableSize_ = oldSize;
hashedEntry** oldTable = table_;
table_ = newTable->table_;
newTable->table_ = oldTable;
table_ = tmpTable->table_;
tmpTable->table_ = oldTable;
delete newTable;
delete tmpTable;
}
@ -556,6 +502,19 @@ void Foam::HashTable<T, Key, Hash>::clearStorage()
}
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::shrink()
{
const label newSize = HashTableCore::canonicalSize(nElmts_);
if (newSize < tableSize_)
{
// avoid having the table disappear on us
resize(newSize ? newSize : 2);
}
}
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& ht)
{
@ -619,18 +578,12 @@ bool Foam::HashTable<T, Key, Hash>::operator==
const HashTable<T, Key, Hash>& rhs
) const
{
// Are all my elements in rhs?
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
// sizes (number of keys) must match
if (size() != rhs.size())
{
const_iterator fnd = rhs.find(iter.key());
if (fnd == rhs.cend() || fnd() != iter())
{
return false;
}
return false;
}
// Are all rhs elements in me?
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
const_iterator fnd = find(iter.key());
@ -640,6 +593,7 @@ bool Foam::HashTable<T, Key, Hash>::operator==
return false;
}
}
return true;
}

View File

@ -71,23 +71,60 @@ Ostream& operator<<(Ostream&, const HashTable<T, Key, Hash>&);
/*---------------------------------------------------------------------------*\
Class HashTableName Declaration
Class HashTableCore Declaration
\*---------------------------------------------------------------------------*/
TemplateName(HashTable);
//- Template-invariant bits for HashTable
struct HashTableCore
{
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Maximum allowable table size
static const label maxTableSize;
//- Construct null
HashTableCore()
{}
//- Define template name and debug
ClassName("HashTable");
//- A zero-sized end iterator
struct iteratorEnd
{
//- Construct null
iteratorEnd()
{}
};
//- iteratorEnd set to beyond the end of any HashTable
inline static iteratorEnd cend()
{
return iteratorEnd();
}
//- iteratorEnd set to beyond the end of any HashTable
inline static iteratorEnd end()
{
return iteratorEnd();
}
};
/*---------------------------------------------------------------------------*\
Class HashTable Declaration
Class HashTable Declaration
\*---------------------------------------------------------------------------*/
template<class T, class Key=word, class Hash=string::hash>
class HashTable
:
public HashTableName
public HashTableCore
{
// Private data type for table entries
//- Structure to hold a hashed entry with SLList for collisions
struct hashedEntry
{
//- The lookup key
@ -99,18 +136,15 @@ class HashTable
//- The data object
T obj_;
//- Constructors
//- Construct from key, next pointer and object
inline hashedEntry(const Key&, hashedEntry* next, const T&);
//- Construct given key, next pointer and object
inline hashedEntry
(
const Key&,
hashedEntry* next,
const T& newEntry
);
private:
//- Disallow default bitwise copy construct
hashedEntry(const hashedEntry&);
//- Dissallow construction as copy
hashedEntry(const hashedEntry&);
//- Disallow default bitwise assignment
void operator=(const hashedEntry&);
};
@ -119,7 +153,7 @@ class HashTable
//- The current number of elements in table
label nElmts_;
//- Number of primary entries allocated in table (not necessarily used)
//- Number of primary entries allocated in table
label tableSize_;
//- The table of primary entries
@ -140,17 +174,23 @@ class HashTable
public:
// Forward declaration of iterators
class iteratorBase;
class iterator;
class const_iterator;
//- Declare friendship with the HashPtrTable class
template<class T2, class Key2, class Hash2>
friend class HashPtrTable;
//- Declare friendship with the iteratorBase
friend class iteratorBase;
// Forward declaration of STL iterators
class iterator;
//- Declare friendship with the iterator
friend class iterator;
class const_iterator;
//- Declare friendship with the const_iterator
friend class const_iterator;
@ -178,7 +218,10 @@ public:
// Access
//- Return number of elements in table.
//- The size of the underlying table
inline label capacity() const;
//- Return number of elements in table
inline label size() const;
//- Return true if the hash table is empty
@ -212,10 +255,11 @@ public:
//- Assign a new hashedEntry, overwriting existing entries
inline bool set(const Key&, const T& newElmt);
//- Erase an hashedEntry specified by given iterator
//- Erase a hashedEntry specified by given iterator
// This invalidates the iterator until the next operator++
bool erase(const iterator&);
//- Erase an hashedEntry specified by given key if in table
//- Erase a hashedEntry specified by the given key
bool erase(const Key&);
//- Remove entries given by the listed keys from this HashTable
@ -224,10 +268,10 @@ public:
//- Remove entries given by the given keys from this HashTable
// Return the number of elements removed.
// The parameter HashTable needs the same type of keys, but
// but the type of values held is arbitrary.
template<class AnyType>
label erase(const HashTable<AnyType, Key, Hash>&);
// The parameter HashTable needs the same type of key, but the
// type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash>
label erase(const HashTable<AnyType, Key, AnyHash>&);
//- Resize the hash table for efficiency
void resize(const label newSize);
@ -239,31 +283,33 @@ public:
// Equivalent to clear() followed by resize(0)
void clearStorage();
//- Shrink the allocated table to approx. twice number of elements
void shrink();
//- Transfer the contents of the argument table into this table
// and annull the argument table.
void transfer(HashTable<T, Key, Hash>&);
//- Transfer contents to the Xfer container
inline Xfer<HashTable<T, Key, Hash> > xfer();
inline Xfer< HashTable<T, Key, Hash> > xfer();
// Member Operators
//- Find and return an hashedEntry
//- Find and return a hashedEntry
inline T& operator[](const Key&);
//- Find and return an hashedEntry
//- Find and return a hashedEntry
inline const T& operator[](const Key&) const;
//- Find and return an hashedEntry, create it null if not present.
//- Find and return a hashedEntry, create it null if not present
inline T& operator()(const Key&);
//- Assignment
void operator=(const HashTable<T, Key, Hash>&);
//- Equality. Two hash tables are equal if all contents of first are
// also in second and vice versa. So does not depend on table size or
// order!
//- Equality. Hash tables are equal if the keys and values are equal.
// Independent of table storage size and table order.
bool operator==(const HashTable<T, Key, Hash>&) const;
//- The opposite of the equality operation. Takes linear time.
@ -289,134 +335,193 @@ public:
typedef label size_type;
// STL iterator
// Iterators and helpers
//- An STL-conforming iterator
class iterator
//- The iterator base for HashTable
// Note: data and functions are protected, to allow reuse by iterator
// and prevent most external usage.
// iterator and const_iterator have the same size, allowing
// us to reinterpret_cast between them (if desired)
class iteratorBase
{
friend class HashTable;
friend class const_iterator;
// Private Data
// Private data
//- Reference to the HashTable this is an iterator for
HashTable<T, Key, Hash>& hashTable_;
//- Pointer to the HashTable for which this is an iterator
// This also lets us use the default bitwise copy/assignment
HashTable<T, Key, Hash>* hashTable_;
//- Current element
hashedEntry* elmtPtr_;
hashedEntry* entryPtr_;
//- Current hash index
label hashIndex_;
protected:
// Protected Member Functions
// Constructors
//- Construct null - equivalent to an 'end' position
inline iteratorBase();
//- Construct from hash table, moving to its 'begin' position
inline explicit iteratorBase
(
const HashTable<T, Key, Hash>* curHashTable
);
//- Construct from hash table, element and hash index
inline explicit iteratorBase
(
const HashTable<T, Key, Hash>* curHashTable,
const hashedEntry* elmt,
const label hashIndex
);
//- Increment to the next position
inline void increment();
//- Erase the HashTable element at the current position
bool erase();
//- Return non-const access to referenced object
inline T& object();
//- Return const access to referenced object
inline const T& cobject() const;
public:
// Member operators
// Access
//- Return the Key corresponding to the iterator
inline const Key& key() const;
//- Compare hashedEntry element pointers
inline bool operator==(const iteratorBase&) const;
inline bool operator!=(const iteratorBase&) const;
//- Compare hashedEntry to iteratorEnd pointers
inline bool operator==(const iteratorEnd& unused) const;
inline bool operator!=(const iteratorEnd& unused) const;
};
//- An STL-conforming iterator
class iterator
:
public iteratorBase
{
friend class HashTable;
// Private Member Functions
//- Construct from hash table, moving to its 'begin' position
inline explicit iterator
(
HashTable<T, Key, Hash>* curHashTable
);
//- Construct from hash table, element and hash index
inline explicit iterator
(
HashTable<T, Key, Hash>* curHashTable,
hashedEntry* elmt,
const label hashIndex
);
public:
// Constructors
//- Construct from hash table, element and hash index
inline iterator
(
HashTable<T, Key, Hash>& curHashTable,
hashedEntry* elmt,
label hashIndex
);
//- Construct null (end iterator)
inline iterator();
//- Construct end iterator
inline iterator(const iteratorEnd& unused);
// Member operators
inline void operator=(const iterator&);
//- Conversion to a const_iterator
inline operator const_iterator() const;
inline bool operator==(const iterator&) const;
inline bool operator!=(const iterator&) const;
inline bool operator==(const const_iterator&) const;
inline bool operator!=(const const_iterator&) const;
// Access
//- Return referenced hash value
inline T& operator*();
inline T& operator()();
//- Return referenced hash value
inline const T& operator*() const;
inline const T& operator()() const;
inline iterator& operator++();
inline iterator operator++(int);
inline const Key& key() const;
};
//- iterator set to the begining of the HashTable
inline iterator begin();
//- iterator set to beyond the end of the HashTable
inline const iterator& end();
// STL const_iterator
//- An STL-conforming const_iterator
class const_iterator
:
public iteratorBase
{
friend class iterator;
friend class HashTable;
// Private data
// Private Member Functions
//- Reference to the HashTable this is an iterator for
const HashTable<T, Key, Hash>& hashTable_;
//- Current element
const hashedEntry* elmtPtr_;
//- Current hash index
label hashIndex_;
//- Construct from hash table, moving to its 'begin' position
inline explicit const_iterator
(
const HashTable<T, Key, Hash>* curHashTable
);
//- Construct from hash table, element and hash index
inline explicit const_iterator
(
const HashTable<T, Key, Hash>* curHashTable,
const hashedEntry* elmt,
const label hashIndex
);
public:
// Constructors
//- Construct from hash table, element and hash index
inline const_iterator
(
const HashTable<T, Key, Hash>& curHashTable,
const hashedEntry* elmt,
label hashIndex
);
//- Construct from the non-const iterator
inline const_iterator(const iterator&);
//- Construct null (end iterator)
inline const_iterator();
//- Construct end iterator
inline const_iterator(const iteratorEnd& unused);
// Member operators
inline void operator=(const const_iterator&);
inline bool operator==(const const_iterator&) const;
inline bool operator!=(const const_iterator&) const;
inline bool operator==(const iterator&) const;
inline bool operator!=(const iterator&) const;
// Access
//- Return referenced hash value
inline const T& operator*() const;
inline const T& operator()() const;
inline const_iterator& operator++();
inline const_iterator operator++(int);
inline const Key& key() const;
};
//- const_iterator set to the beginning of the HashTable
inline const_iterator cbegin() const;
//- const_iterator set to beyond the end of the HashTable
inline const const_iterator& cend() const;
//- const_iterator set to the beginning of the HashTable
inline const_iterator begin() const;
//- const_iterator set to beyond the end of the HashTable
inline const const_iterator& end() const;
// IOstream Operator
@ -432,14 +537,6 @@ public:
const HashTable<T, Key, Hash>&
);
private:
//- iterator returned by end()
iterator endIter_;
//- const_iterator returned by end()
const_iterator endConstIter_;
};

View File

@ -28,6 +28,40 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::HashTableName, 0);
defineTypeNameAndDebug(Foam::HashTableCore, 0);
const Foam::label Foam::HashTableCore::maxTableSize
(
Foam::HashTableCore::canonicalSize
(
Foam::labelMax/2
)
);
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::label Foam::HashTableCore::canonicalSize(const label size)
{
if (size < 1)
{
return 0;
}
// enforce power of two
unsigned int goodSize = size;
if (goodSize & (goodSize - 1))
{
// brute-force is fast enough
goodSize = 1;
while (goodSize < unsigned(size))
{
goodSize <<= 1;
}
}
return goodSize;
}
// ************************************************************************* //

View File

@ -33,12 +33,12 @@ inline Foam::HashTable<T, Key, Hash>::hashedEntry::hashedEntry
(
const Key& key,
hashedEntry* next,
const T& newEntry
const T& obj
)
:
key_(key),
next_(next),
obj_(newEntry)
obj_(obj)
{}
@ -55,6 +55,13 @@ Foam::HashTable<T, Key, Hash>::hashKeyIndex(const Key& key) const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTable<T, Key, Hash>::capacity() const
{
return tableSize_;
}
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTable<T, Key, Hash>::size() const
{
@ -152,70 +159,218 @@ inline T& Foam::HashTable<T, Key, Hash>::operator()(const Key& key)
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase()
:
hashTable_(0),
entryPtr_(0),
hashIndex_(0)
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase
(
HashTable<T, Key, Hash>& hashTbl,
hashedEntry* elmt,
label hashIndex
const HashTable<T, Key, Hash>* hashTbl
)
:
hashTable_(hashTbl),
elmtPtr_(elmt),
hashTable_(const_cast<HashTable<T, Key, Hash>*>(hashTbl)),
entryPtr_(0),
hashIndex_(0)
{
if (hashTable_->nElmts_ && hashTable_->table_)
{
// find first non-NULL table entry
while
(
!(entryPtr_ = hashTable_->table_[hashIndex_])
&& ++hashIndex_ < hashTable_->tableSize_
)
{}
if (hashIndex_ >= hashTable_->tableSize_)
{
// make into an end iterator
entryPtr_ = 0;
hashIndex_ = 0;
}
}
}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iteratorBase::iteratorBase
(
const HashTable<T, Key, Hash>* hashTbl,
const hashedEntry* elmt,
const label hashIndex
)
:
hashTable_(const_cast<HashTable<T, Key, Hash>*>(hashTbl)),
entryPtr_(const_cast<hashedEntry*>(elmt)),
hashIndex_(hashIndex)
{}
template<class T, class Key, class Hash>
inline void Foam::HashTable<T, Key, Hash>::iterator::operator=
inline void
Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
{
// A negative index is a special value from erase
if (hashIndex_ < 0)
{
// the markPos='-curPos-1', but we wish to continue at 'curPos-1'
// thus use '-(markPos+1) -1'
hashIndex_ = -(hashIndex_+1) - 1;
}
else if (entryPtr_)
{
if (entryPtr_->next_)
{
// Move to next element on the SLList
entryPtr_ = entryPtr_->next_;
return;
}
}
// else
// {
// // if we reach here (entryPtr_ is NULL) it is already at the end()
// // we should probably stop
// }
// Step to the next table entry
while
(
++hashIndex_ < hashTable_->tableSize_
&& !(entryPtr_ = hashTable_->table_[hashIndex_])
)
{}
if (hashIndex_ >= hashTable_->tableSize_)
{
// make into an end iterator
entryPtr_ = 0;
hashIndex_ = 0;
}
}
template<class T, class Key, class Hash>
inline
const Key& Foam::HashTable<T, Key, Hash>::iteratorBase::key() const
{
return entryPtr_->key_;
}
template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iteratorBase::object()
{
return entryPtr_->obj_;
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::iteratorBase::cobject() const
{
return entryPtr_->obj_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator==
(
const iterator& iter
const iteratorBase& iter
) const
{
return entryPtr_ == iter.entryPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator!=
(
const iteratorBase& iter
) const
{
return entryPtr_ != iter.entryPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator==
(
const iteratorEnd&
) const
{
return !entryPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iteratorBase::operator!=
(
const iteratorEnd&
) const
{
return entryPtr_;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator()
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
const iteratorEnd&
)
{
elmtPtr_ = iter.elmtPtr_;
hashIndex_ = iter.hashIndex_;
}
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator==
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
const iterator& iter
) const
{
return elmtPtr_ == iter.elmtPtr_;
}
HashTable<T, Key, Hash>* hashTbl
)
:
iteratorBase(hashTbl)
{}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator!=
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
const iterator& iter
) const
{
return elmtPtr_ != iter.elmtPtr_;
}
HashTable<T, Key, Hash>* hashTbl,
hashedEntry* elmt,
const label hashIndex
)
:
iteratorBase(hashTbl, elmt, hashIndex)
{}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator==
(
const const_iterator& iter
) const
inline Foam::HashTable<T, Key, Hash>::iterator::operator
typename Foam::HashTable<T, Key, Hash>::const_iterator() const
{
return elmtPtr_ == iter.elmtPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator!=
(
const const_iterator& iter
) const
{
return elmtPtr_ != iter.elmtPtr_;
return *reinterpret_cast
<
const typename Foam::HashTable<T, Key, Hash>::const_iterator*
>(this);
}
@ -223,7 +378,7 @@ template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iterator::operator*()
{
return elmtPtr_->obj_;
return this->object();
}
@ -231,7 +386,7 @@ template<class T, class Key, class Hash>
inline T&
Foam::HashTable<T, Key, Hash>::iterator::operator()()
{
return elmtPtr_->obj_;
return this->object();
}
@ -239,7 +394,7 @@ template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::iterator::operator*() const
{
return elmtPtr_->obj_;
return this->cobject();
}
@ -247,7 +402,7 @@ template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::iterator::operator()() const
{
return elmtPtr_->obj_;
return this->cobject();
}
@ -256,53 +411,18 @@ inline
typename Foam::HashTable<T, Key, Hash>::iterator&
Foam::HashTable<T, Key, Hash>::iterator::operator++()
{
// Check for special value from erase. (sets hashIndex to -1)
if (hashIndex_ >= 0)
{
// Do we have additional elements on the SLList?
if (elmtPtr_ && elmtPtr_->next_)
{
elmtPtr_ = elmtPtr_->next_;
return *this;
}
}
// Step to the next table entry
while
(
++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = hashTable_.table_[hashIndex_])
)
{}
if (hashIndex_ == hashTable_.tableSize_)
{
// make end iterator
elmtPtr_ = 0;
hashIndex_ = 0;
}
this->increment();
return *this;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::iterator::operator++
(
int
)
Foam::HashTable<T, Key, Hash>::iterator::operator++(int)
{
iterator tmp = *this;
++*this;
return tmp;
}
template<class T, class Key, class Hash>
inline
const Key& Foam::HashTable<T, Key, Hash>::iterator::key() const
{
return elmtPtr_->key_;
iterator old = *this;
this->increment();
return old;
}
@ -310,135 +430,64 @@ template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::begin()
{
label i = 0;
if (nElmts_)
{
while (table_ && !table_[i] && ++i < tableSize_)
{}
}
else
{
i = tableSize_;
}
if (i == tableSize_)
{
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTable is empty\n";
}
# endif
return HashTable<T, Key, Hash>::endIter_;
}
else
{
return iterator(*this, table_[i], i);
}
}
template<class T, class Key, class Hash>
inline const typename Foam::HashTable<T, Key, Hash>::iterator&
Foam::HashTable<T, Key, Hash>::end()
{
return HashTable<T, Key, Hash>::endIter_;
return iterator(this);
}
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator()
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const HashTable<T, Key, Hash>& hashTbl,
const iteratorEnd&
)
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const HashTable<T, Key, Hash>* hashTbl
)
:
iteratorBase(hashTbl)
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const HashTable<T, Key, Hash>* hashTbl,
const hashedEntry* elmt,
label hashIndex
const label hashIndex
)
:
hashTable_(hashTbl),
elmtPtr_(elmt),
hashIndex_(hashIndex)
iteratorBase(hashTbl, elmt, hashIndex)
{}
template<class T, class Key, class Hash>
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const iterator& iter
)
:
hashTable_(iter.hashTable_),
elmtPtr_(iter.elmtPtr_),
hashIndex_(iter.hashIndex_)
{}
template<class T, class Key, class Hash>
inline void Foam::HashTable<T, Key, Hash>::const_iterator::operator=
(
const const_iterator& iter
)
{
elmtPtr_ = iter.elmtPtr_;
hashIndex_ = iter.hashIndex_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator==
(
const const_iterator& iter
) const
{
return elmtPtr_ == iter.elmtPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator!=
(
const const_iterator& iter
) const
{
return elmtPtr_ != iter.elmtPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator==
(
const iterator& iter
) const
{
return elmtPtr_ == iter.elmtPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator!=
(
const iterator& iter
) const
{
return elmtPtr_ != iter.elmtPtr_;
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::const_iterator::operator*() const
{
return elmtPtr_->obj_;
return this->cobject();
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::const_iterator::operator()() const
{
return elmtPtr_->obj_;
return this->cobject();
}
@ -447,43 +496,18 @@ inline
typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::const_iterator::operator++()
{
if
(
!(elmtPtr_ = elmtPtr_->next_)
&& ++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = hashTable_.table_[hashIndex_])
)
{
while
(
++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = hashTable_.table_[hashIndex_])
)
{}
}
this->increment();
return *this;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::const_iterator::operator++
(
int
)
Foam::HashTable<T, Key, Hash>::const_iterator::operator++(int)
{
const_iterator tmp = *this;
++*this;
return tmp;
}
template<class T, class Key, class Hash>
inline
const Key& Foam::HashTable<T, Key, Hash>::const_iterator::key() const
{
return elmtPtr_->key_;
const_iterator old = *this;
this->increment();
return old;
}
@ -491,41 +515,7 @@ template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::cbegin() const
{
label i = 0;
if (nElmts_)
{
while (table_ && !table_[i] && ++i < tableSize_)
{}
}
else
{
i = tableSize_;
}
if (i == tableSize_)
{
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTable is empty\n";
}
# endif
return HashTable<T, Key, Hash>::endConstIter_;
}
else
{
return const_iterator(*this, table_[i], i);
}
}
template<class T, class Key, class Hash>
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::cend() const
{
return HashTable<T, Key, Hash>::endConstIter_;
return const_iterator(this);
}
@ -537,12 +527,4 @@ Foam::HashTable<T, Key, Hash>::begin() const
}
template<class T, class Key, class Hash>
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::end() const
{
return HashTable<T, Key, Hash>::endConstIter_;
}
// ************************************************************************* //

View File

@ -33,16 +33,19 @@ License
template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable(Istream& is, const label size)
:
HashTableName(),
HashTableCore(),
nElmts_(0),
tableSize_(canonicalSize(size)),
table_(new hashedEntry*[tableSize_]),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
tableSize_(HashTableCore::canonicalSize(size)),
table_(NULL)
{
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
if (tableSize_)
{
table_[hashIdx] = 0;
table_ = new hashedEntry*[tableSize_];
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[hashIdx] = 0;
}
}
operator>>(is, *this);

View File

@ -33,8 +33,7 @@ License
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::label Foam::StaticHashTable<T, Key, Hash>::canonicalSize(const label size)
Foam::label Foam::StaticHashTableCore::canonicalSize(const label size)
{
if (size < 1)
{
@ -64,8 +63,8 @@ Foam::label Foam::StaticHashTable<T, Key, Hash>::canonicalSize(const label size)
template<class T, class Key, class Hash>
Foam::StaticHashTable<T, Key, Hash>::StaticHashTable(const label size)
:
StaticHashTableName(),
keys_(canonicalSize(size)),
StaticHashTableCore(),
keys_(StaticHashTableCore::canonicalSize(size)),
objects_(keys_.size()),
nElmts_(0),
endIter_(*this, keys_.size(), 0),
@ -89,7 +88,7 @@ Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
const StaticHashTable<T, Key, Hash>& ht
)
:
StaticHashTableName(),
StaticHashTableCore(),
keys_(ht.keys_),
objects_(ht.objects_),
nElmts_(ht.nElmts_),
@ -105,7 +104,7 @@ Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
const Xfer< StaticHashTable<T, Key, Hash> >& ht
)
:
StaticHashTableName(),
StaticHashTableCore(),
keys_(0),
objects_(0),
nElmts_(0),
@ -224,15 +223,15 @@ Foam::StaticHashTable<T, Key, Hash>::find
template<class T, class Key, class Hash>
Foam::List<Key> Foam::StaticHashTable<T, Key, Hash>::toc() const
{
List<Key> tofc(nElmts_);
label i = 0;
List<Key> keys(nElmts_);
label keyI = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
tofc[i++] = iter.key();
keys[keyI++] = iter.key();
}
return tofc;
return keys;
}
@ -319,24 +318,9 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
if (it.elemIndex_ < 0)
{
// No previous element in the local list
// Search back for previous non-zero table entry
while (--it.hashIndex_ >= 0 && !objects_[it.hashIndex_].size())
{}
if (it.hashIndex_ >= 0)
{
// The last element in the local list
it.elemIndex_ = objects_[it.hashIndex_].size() - 1;
}
else
{
// No previous found. Mark with special value which is
// - not end()
// - handled by operator++
it.hashIndex_ = -1;
it.elemIndex_ = 0;
}
// Mark with as special value (see notes in HashTable)
it.hashIndex_ = -it.hashIndex_ - 1;
it.elemIndex_ = 0;
}
nElmts_--;
@ -407,8 +391,8 @@ Foam::label Foam::StaticHashTable<T, Key, Hash>::erase
template<class T, class Key, class Hash>
void Foam::StaticHashTable<T, Key, Hash>::resize(const label sz)
{
label newSize = canonicalSize(sz);
label newSize = StaticHashTableCore::canonicalSize(sz);
if (newSize == keys_.size())
{
# ifdef FULLDEBUG
@ -543,18 +527,8 @@ bool Foam::StaticHashTable<T, Key, Hash>::operator==
const StaticHashTable<T, Key, Hash>& rhs
) const
{
// Are all my elements in rhs?
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
const_iterator fnd = rhs.find(iter.key());
// sizes (number of keys) must match
if (fnd == rhs.cend() || fnd() != iter())
{
return false;
}
}
// Are all rhs elements in me?
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
const_iterator fnd = find(iter.key());
@ -564,6 +538,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::operator==
return false;
}
}
return true;
}

View File

@ -76,7 +76,33 @@ template<class T, class Key, class Hash> Ostream& operator<<
Class StaticHashTableName Declaration
\*---------------------------------------------------------------------------*/
TemplateName(StaticHashTable);
/*---------------------------------------------------------------------------*\
Class StaticHashTableCore Declaration
\*---------------------------------------------------------------------------*/
//- Template-invariant bits for StaticHashTable
struct StaticHashTableCore
{
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Construct null
StaticHashTableCore()
{}
//- Define template name and debug
ClassName("StaticHashTable");
//- A zero-sized end iterator
struct iteratorEnd
{
//- Construct null
iteratorEnd()
{}
};
};
/*---------------------------------------------------------------------------*\
@ -86,7 +112,7 @@ TemplateName(StaticHashTable);
template<class T, class Key=word, class Hash=string::hash>
class StaticHashTable
:
public StaticHashTableName
public StaticHashTableCore
{
// Private data type for table entries

View File

@ -28,6 +28,6 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::StaticHashTableName, 0);
defineTypeNameAndDebug(Foam::StaticHashTableCore, 0);
// ************************************************************************* //

View File

@ -267,8 +267,13 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator
TableRef
>::operator++()
{
// Check for special value from erase. (sets hashIndex to -1)
if (hashIndex_ >= 0)
// A negative index is a special value from erase
// (see notes in HashTable)
if (hashIndex_ < 0)
{
hashIndex_ = -(hashIndex_+1) - 1;
}
else
{
// Try the next element on the local list
elemIndex_++;

View File

@ -37,9 +37,9 @@ Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
const label size
)
:
StaticHashTableName(),
keys_(size),
objects_(size),
StaticHashTableCore(),
keys_(StaticHashTableCore::canonicalSize(size)),
objects_(StaticHashTableCore::canonicalSize(size)),
nElmts_(0),
endIter_(*this, keys_.size(), 0),
endConstIter_(*this, keys_.size(), 0)

View File

@ -28,16 +28,18 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList(const List<Container>& ll)
:
offsets_(ll.size())
size_(ll.size()),
offsets_(ll.size()+1)
{
label sumSize = 0;
offsets_[0] = 0;
forAll(ll, i)
{
sumSize += ll[i].size();
offsets_[i] = sumSize;
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize);
@ -45,7 +47,7 @@ Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
label k = 0;
forAll(ll, i)
{
const List<T>& lli = ll[i];
const Container& lli = ll[i];
forAll(lli, j)
{
@ -55,62 +57,67 @@ Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const UList<label>& rowSizes
)
:
offsets_(rowSizes.size())
size_(rowSizes.size()),
offsets_(rowSizes.size()+1)
{
label sumSize = 0;
offsets_[0] = 0;
forAll(rowSizes, i)
{
sumSize += rowSizes[i];
offsets_[i] = sumSize;
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize);
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const UList<label>& rowSizes,
const T& t
)
:
offsets_(rowSizes.size())
size_(rowSizes.size()),
offsets_(rowSizes.size()+1)
{
label sumSize = 0;
offsets_[0] = 0;
forAll(rowSizes, i)
{
sumSize += rowSizes[i];
offsets_[i] = sumSize;
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize, t);
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const Xfer<CompactListList<T> >& lst
const Xfer<CompactListList<T, Container> >& lst
)
{
transfer(lst());
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
CompactListList<T>& lst,
CompactListList<T, Container>& lst,
bool reUse
)
:
size_(lst.size()),
offsets_(lst.offsets_, reUse),
m_(lst.m_, reUse)
{}
@ -118,22 +125,25 @@ Foam::CompactListList<T>::CompactListList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
void Foam::CompactListList<T>::setSize(const label nRows)
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize(const label nRows)
{
if (nRows == 0)
{
clear();
}
if (nRows < offsets_.size())
if (nRows < size())
{
offsets_.setSize(nRows);
m_.setSize(offsets_[nRows - 1]);
size_ = nRows;
offsets_.setSize(nRows+1);
m_.setSize(offsets_[nRows]);
}
else if (nRows > offsets_.size())
else if (nRows > size())
{
FatalErrorIn("CompactListList<T>::setSize(const label nRows)")
<< "Cannot be used to extend the list from " << offsets_.size()
FatalErrorIn
(
"CompactListList<T, Container>::setSize(const label nRows)"
) << "Cannot be used to extend the list from " << offsets_.size()
<< " to " << nRows << nl
<< " Please use one of the other setSize member functions"
<< abort(FatalError);
@ -141,73 +151,83 @@ void Foam::CompactListList<T>::setSize(const label nRows)
}
template<class T>
void Foam::CompactListList<T>::setSize
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize
(
const label nRows,
const label nData
)
{
offsets_.setSize(nRows);
size_ = nRows;
offsets_.setSize(nRows+1);
m_.setSize(nData);
}
template<class T>
void Foam::CompactListList<T>::setSize
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize
(
const label nRows,
const label nData,
const T& t
)
{
offsets_.setSize(nRows);
size_ = nRows;
offsets_.setSize(nRows+1);
m_.setSize(nData, t);
}
template<class T>
void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes)
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize(const UList<label>& rowSizes)
{
offsets_.setSize(rowSizes.size());
size_ = rowSizes.size();
offsets_.setSize(rowSizes.size()+1);
label sumSize = 0;
offsets_[0] = 0;
forAll(rowSizes, i)
{
sumSize += rowSizes[i];
offsets_[i] = sumSize;
offsets_[i+1] = sumSize;
}
m_.setSize(sumSize);
}
template<class T>
Foam::labelList Foam::CompactListList<T>::sizes() const
template<class T, class Container>
Foam::labelList Foam::CompactListList<T, Container>::sizes() const
{
labelList rowSizes(offsets_.size());
labelList rowSizes(size());
label prevOffset = 0;
forAll(offsets_, i)
if (rowSizes.size() > 0)
{
rowSizes[i] = offsets_[i]-prevOffset;
prevOffset = offsets_[i];
forAll(rowSizes, i)
{
rowSizes[i] = offsets_[i+1] - offsets_[i];
}
}
return rowSizes;
}
template<class T>
void Foam::CompactListList<T>::clear()
template<class T, class Container>
void Foam::CompactListList<T, Container>::clear()
{
size_ = 0;
offsets_.clear();
m_.clear();
}
template<class T>
void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
template<class T, class Container>
void Foam::CompactListList<T, Container>::transfer
(
CompactListList<T, Container>& a
)
{
size_ = a.size_;
offsets_.transfer(a.offsets_);
m_.transfer(a.m_);
}
@ -215,24 +235,15 @@ void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
Foam::List<Foam::List<T> > Foam::CompactListList<T>::operator()() const
template<class T, class Container>
Foam::List<Container> Foam::CompactListList<T, Container>::operator()()
const
{
List<List<T> > ll(offsets_.size());
List<Container> ll(size());
label offsetPrev = 0;
forAll(offsets_, i)
forAll(ll, i)
{
List<T>& lst = ll[i];
lst.setSize(offsets_[i] - offsetPrev);
forAll(lst, j)
{
lst[j] = m_[offsetPrev + j];
}
offsetPrev = offsets_[i];
ll[i] = Container(operator[](i));
}
return ll;

View File

@ -29,15 +29,17 @@ Description
A packed storage unstructured matrix of objects of type \<T\>
using an offset table for access.
The offset table is the size of the number of rows whose elements are the
The offset table is the size of the number of rows+1
whose elements are the
accumulated sizes of the rows, i.e.
- offset[i] gives the index of first element of row i + 1
- offset[i] - offset[i-1] is the number of elements in row i
and for i = 0, offset[i-1] = 0.
- offset[i] gives the index of first element of row i
- offset[i+1] - offset[i] is the number of elements in row i
Storage is allocated on free-store during construction.
As a special case a null-contructed CompactListList has an empty
offsets_ (instead of size 1).
SourceFiles
CompactListList.C
CompactListListI.H
@ -57,21 +59,23 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class T> class CompactListList;
template<class T, class Container> class CompactListList;
template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
template<class T, class Container> Istream& operator>>(Istream&, CompactListList<T, Container>&);
template<class T, class Container> Ostream& operator<<(Ostream&, const CompactListList<T, Container>&);
/*---------------------------------------------------------------------------*\
Class CompactListList Declaration
\*---------------------------------------------------------------------------*/
template<class T>
template<class T, class Container = List<T> >
class CompactListList
{
// Private data
label size_;
//- Offset table
List<label> offsets_;
@ -84,7 +88,7 @@ public:
// Static Member Functions
//- Return a null CompactListList
inline static const CompactListList<T>& null();
inline static const CompactListList<T, Container>& null();
// Constructors
@ -92,7 +96,7 @@ public:
inline CompactListList();
//- Construct by converting given List<List<T> >
CompactListList(const List<List<T> >&);
explicit CompactListList(const List<Container>&);
//- Construct given size of offset table (number of rows)
// and number of data.
@ -103,22 +107,22 @@ public:
inline CompactListList(const label nRows, const label nData, const T&);
//- Construct given list of row-sizes.
CompactListList(const UList<label>& rowSizes);
explicit CompactListList(const UList<label>& rowSizes);
//- Construct given list of row-sizes
CompactListList(const UList<label>& rowSizes, const T&);
//- Construct by transferring the parameter contents
CompactListList(const Xfer<CompactListList<T> >&);
explicit CompactListList(const Xfer<CompactListList<T, Container> >&);
//- Construct as copy or re-use as specified.
CompactListList(CompactListList<T>&, bool reUse);
CompactListList(CompactListList<T, Container>&, bool reUse);
//- Construct from Istream.
CompactListList(Istream&);
//- Clone
inline autoPtr<CompactListList<T> > clone() const;
inline autoPtr<CompactListList<T, Container> > clone() const;
// Member Functions
@ -131,7 +135,7 @@ public:
//- Return true if the number of rows is zero
inline bool empty() const;
//- Return the offset table
//- Return the offset table (= size()+1)
inline const List<label>& offsets() const;
//- Return non-const access to the offset table
@ -180,10 +184,10 @@ public:
//- Transfer the contents of the argument CompactListList
// into this CompactListList and annull the argument list.
void transfer(CompactListList<T>&);
void transfer(CompactListList<T, Container>&);
//- Transfer the contents to the Xfer container
inline Xfer<CompactListList<T> > xfer();
inline Xfer<CompactListList<T, Container> > xfer();
// Other
@ -211,8 +215,8 @@ public:
//- Return const subscript-checked element.
inline const T& operator()(const label i, const label j) const;
//- Return as List<List<T> >
List<List<T> > operator()() const;
//- Return as List<Container>
List<Container> operator()() const;
//- Assignment of all entries to the given value
inline void operator=(const T&);
@ -222,10 +226,18 @@ public:
//- Read CompactListList from Istream, discarding contents
// of existing CompactListList.
friend Istream& operator>> <T>(Istream&, CompactListList<T>&);
friend Istream& operator>> <T, Container>
(
Istream&,
CompactListList<T, Container>&
);
// Write CompactListList to Ostream.
friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&);
friend Ostream& operator<< <T, Container>
(
Ostream&,
const CompactListList<T, Container>&
);
};

View File

@ -24,142 +24,140 @@ License
\*---------------------------------------------------------------------------*/
#include "ListOps.H"
#include "SubList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::CompactListList<T>::CompactListList()
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList()
:
size_(0)
{}
template<class T>
inline Foam::CompactListList<T>::CompactListList
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
(
const label nRows,
const label nData
)
:
offsets_(nRows, 0),
size_(nRows),
offsets_(nRows+1, 0),
m_(nData)
{}
template<class T>
inline Foam::CompactListList<T>::CompactListList
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
(
const label nRows,
const label nData,
const T& t
)
:
offsets_(nRows, 0),
size_(nRows),
offsets_(nRows+1, 0),
m_(nData, t)
{}
template<class T>
inline Foam::autoPtr<Foam::CompactListList<T> >
Foam::CompactListList<T>::clone() const
template<class T, class Container>
inline Foam::autoPtr<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::clone() const
{
return autoPtr<CompactListList<T> >(new CompactListList<T>(*this));
return autoPtr<CompactListList<T, Container> >
(
new CompactListList<T, Container>(*this)
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
template<class T, class Container>
inline const Foam::CompactListList<T, Container>&
Foam::CompactListList<T, Container>::null()
{
return *reinterpret_cast< CompactListList<T>* >(0);
return *reinterpret_cast< CompactListList<T, Container>* >(0);
}
template<class T>
inline Foam::label Foam::CompactListList<T>::size() const
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::size() const
{
return offsets_.size();
return size_;
}
template<class T>
inline bool Foam::CompactListList<T>::empty() const
template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const
{
return offsets_.empty();
return !size_;
}
template<class T>
inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const
template<class T, class Container>
inline const Foam::List<Foam::label>&
Foam::CompactListList<T, Container>::offsets() const
{
return offsets_;
}
template<class T>
inline Foam::List<Foam::label>& Foam::CompactListList<T>::offsets()
template<class T, class Container>
inline Foam::List<Foam::label>& Foam::CompactListList<T, Container>::offsets()
{
return offsets_;
}
template<class T>
inline const Foam::List<T>& Foam::CompactListList<T>::m() const
template<class T, class Container>
inline const Foam::List<T>& Foam::CompactListList<T, Container>::m()
const
{
return m_;
}
template<class T>
inline Foam::List<T>& Foam::CompactListList<T>::m()
template<class T, class Container>
inline Foam::List<T>& Foam::CompactListList<T, Container>::m()
{
return m_;
}
template<class T>
inline Foam::label Foam::CompactListList<T>::index
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::index
(
const label i,
const label j
) const
{
if (i == 0)
{
return j;
}
else
{
return offsets_[i-1] + j;
}
return offsets_[i] + j;
}
template<class T>
inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::whichRow(const label i)
const
{
if (i < 0 || i >= m_.size())
{
FatalErrorIn
(
"CompactListList<T>::whichRow(const label) const"
"CompactListList<T, Container>::whichRow(const label) const"
) << "Index " << i << " outside 0.." << m_.size()
<< abort(FatalError);
}
forAll(offsets_, rowI)
{
if (i < offsets_[rowI])
{
return rowI;
}
}
return -1;
return findLower(offsets_, i+1);
}
template<class T>
inline Foam::label Foam::CompactListList<T>::whichColumn
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::whichColumn
(
const label row,
const label i
@ -169,22 +167,23 @@ inline Foam::label Foam::CompactListList<T>::whichColumn
}
template<class T>
inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer()
template<class T, class Container>
inline Foam::Xfer<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::xfer()
{
return xferMove(*this);
}
template<class T>
inline void Foam::CompactListList<T>::resize(const label nRows)
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize(const label nRows)
{
this->setSize(nRows);
}
template<class T>
inline void Foam::CompactListList<T>::resize
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
const label nRows,
const label nData
@ -194,8 +193,8 @@ inline void Foam::CompactListList<T>::resize
}
template<class T>
inline void Foam::CompactListList<T>::resize
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
const label nRows,
const label nData,
@ -206,8 +205,11 @@ inline void Foam::CompactListList<T>::resize
}
template<class T>
inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
const UList<label>& rowSizes
)
{
this->setSize(rowSizes);
}
@ -215,42 +217,35 @@ inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline Foam::UList<T> Foam::CompactListList<T>::operator[]
template<class T, class Container>
inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
(
const label i
)
{
if (i == 0)
{
return UList<T>(m_.begin(), offsets_[i]);
}
else
{
return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
}
label start = offsets_[i];
return UList<T>(&m_[start], offsets_[i+1] - start);
}
template<class T>
inline const Foam::UList<T> Foam::CompactListList<T>::operator[]
template<class T, class Container>
inline const Foam::UList<T>
Foam::CompactListList<T, Container>::operator[]
(
const label i
) const
{
if (i == 0)
{
return UList<T>(m_.begin(), offsets_[i]);
}
else
{
return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
}
label start = offsets_[i];
return UList<T>
(
const_cast<T*>(&m_[start]),
offsets_[i+1] - start
);
}
template<class T>
inline T& Foam::CompactListList<T>::operator()
template<class T, class Container>
inline T& Foam::CompactListList<T, Container>::operator()
(
const label i,
const label j
@ -260,8 +255,8 @@ inline T& Foam::CompactListList<T>::operator()
}
template<class T>
inline const T& Foam::CompactListList<T>::operator()
template<class T, class Container>
inline const T& Foam::CompactListList<T, Container>::operator()
(
const label i,
const label j
@ -271,8 +266,8 @@ inline const T& Foam::CompactListList<T>::operator()
}
template<class T>
inline void Foam::CompactListList<T>::operator=(const T& t)
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::operator=(const T& t)
{
m_ = t;
}

View File

@ -29,8 +29,8 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
Foam::CompactListList<T>::CompactListList(Istream& is)
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList(Istream& is)
{
operator>>(is, *this);
}
@ -38,16 +38,25 @@ Foam::CompactListList<T>::CompactListList(Istream& is)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T>& lst)
template<class T, class Container>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T, Container>& lst)
{
is >> lst.offsets_ >> lst.m_;
// Note: empty list gets output as two empty lists
if (lst.offsets_.size() == 0)
{
lst.size_ = 0;
}
else
{
lst.size_ = lst.offsets_.size()-1;
}
return is;
}
template<class T>
Foam::Ostream& Foam::operator<<(Ostream& os, const CompactListList<T>& lst)
template<class T, class Container>
Foam::Ostream& Foam::operator<<(Ostream& os, const CompactListList<T, Container>& lst)
{
os << lst.offsets_ << lst.m_;
return os;

View File

@ -109,17 +109,17 @@ public:
//- Null constructor.
inline FixedList();
//- Construct from components
inline FixedList(const T v[Size]);
//- Construct from C-array.
explicit inline FixedList(const T v[Size]);
//- Construct from value
inline FixedList(const T&);
explicit inline FixedList(const T&);
//- Construct from UList.
inline FixedList(const UList<T>&);
explicit inline FixedList(const UList<T>&);
//- Construct from SLList.
inline FixedList(const SLList<T>&);
explicit inline FixedList(const SLList<T>&);
//- Copy constructor.
inline FixedList(const FixedList<T, Size>&);

View File

@ -123,22 +123,22 @@ public:
//- Construct as copy of FixedList<T, Size>
template<unsigned Size>
List(const FixedList<T, Size>&);
explicit List(const FixedList<T, Size>&);
//- Construct as copy of PtrList<T>
List(const PtrList<T>&);
explicit List(const PtrList<T>&);
//- Construct as copy of SLList<T>
List(const SLList<T>&);
explicit List(const SLList<T>&);
//- Construct as copy of IndirectList<T>
List(const IndirectList<T>&);
explicit List(const IndirectList<T>&);
//- Construct as copy of UIndirectList<T>
List(const UIndirectList<T>&);
explicit List(const UIndirectList<T>&);
//- Construct as copy of BiIndirectList<T>
List(const BiIndirectList<T>&);
explicit List(const BiIndirectList<T>&);
//- Construct from Istream.
List(Istream&);

View File

@ -162,7 +162,7 @@ public:
inline PackedList();
//- Construct with given size, initializes list to 0.
inline PackedList(const label size);
explicit inline PackedList(const label size);
//- Construct with given size and value for all elements.
PackedList(const label size, const unsigned val);
@ -174,7 +174,7 @@ public:
inline PackedList(const Xfer< PackedList<nBits> >&);
//- Construct from a list of labels
PackedList(const UList<label>&);
explicit PackedList(const UList<label>&);
//- Clone
inline autoPtr< PackedList<nBits> > clone() const;

View File

@ -136,7 +136,7 @@ public:
PtrList(PtrList<T>&, bool reUse);
//- Construct as copy of SLPtrList<T>
PtrList(const SLPtrList<T>&);
explicit PtrList(const SLPtrList<T>&);
//- Construct from Istream using given Istream constructor class
template<class INew>

View File

@ -114,7 +114,7 @@ void Foam::ParSortableList<Type>::checkAndSend
}
{
OPstream toSlave(destProcI);
OPstream toSlave(Pstream::blocking, destProcI);
toSlave << values << indices;
}
}
@ -311,7 +311,7 @@ void Foam::ParSortableList<Type>::sort()
Pout<< "Receiving from " << procI << endl;
}
IPstream fromSlave(procI);
IPstream fromSlave(Pstream::blocking, procI);
fromSlave >> recValues >> recIndices;

View File

@ -24,291 +24,22 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
inline void Foam::IPstream::checkEof()
{
if (bufPosition_ == messageSize_)
{
setEof();
}
}
template<class T>
inline void Foam::IPstream::readFromBuffer(T& t)
{
const size_t align = sizeof(T);
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
t = reinterpret_cast<T&>(buf_[bufPosition_]);
bufPosition_ += sizeof(T);
checkEof();
}
inline void Foam::IPstream::readFromBuffer
Foam::IPstream::IPstream
(
void* data,
size_t count,
size_t align
const commsTypes commsType,
const int fromProcNo,
const label bufSize,
streamFormat format,
versionNumber version
)
{
if (align > 1)
{
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
}
register const char* bufPtr = &buf_[bufPosition_];
register char* dataPtr = reinterpret_cast<char*>(data);
register size_t i = count;
while (i--) *dataPtr++ = *bufPtr++;
bufPosition_ += count;
checkEof();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::IPstream::~IPstream()
{
if (bufPosition_ < messageSize_)
{
FatalErrorIn("IPstream::~IPstream()")
<< "Message not fully consumed. messageSize:" << messageSize_
<< " bytes of which only " << bufPosition_
<< " consumed." << Foam::abort(FatalError);
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Istream& Foam::IPstream::read(token& t)
{
// Return the put back token if it exists
if (Istream::getBack(t))
{
return *this;
}
char c;
// return on error
if (!read(c))
{
t.setBad();
return *this;
}
// Set the line number of this token to the current stream line number
t.lineNumber() = lineNumber();
// Analyse input starting with this character.
switch (c)
{
// Punctuation
case token::END_STATEMENT :
case token::BEGIN_LIST :
case token::END_LIST :
case token::BEGIN_SQR :
case token::END_SQR :
case token::BEGIN_BLOCK :
case token::END_BLOCK :
case token::COLON :
case token::COMMA :
case token::ASSIGN :
case token::ADD :
case token::SUBTRACT :
case token::MULTIPLY :
case token::DIVIDE :
{
t = token::punctuationToken(c);
return *this;
}
// Word
case token::WORD :
{
word* pval = new word;
if (read(*pval))
{
if (token::compound::isCompound(*pval))
{
t = token::compound::New(*pval, *this).ptr();
delete pval;
}
else
{
t = pval;
}
}
else
{
delete pval;
t.setBad();
}
return *this;
}
// String
case token::STRING :
{
string* pval = new string;
if (read(*pval))
{
t = pval;
}
else
{
delete pval;
t.setBad();
}
return *this;
}
// Label
case token::LABEL :
{
label val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// floatScalar
case token::FLOAT_SCALAR :
{
floatScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// doubleScalar
case token::DOUBLE_SCALAR :
{
doubleScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// Character (returned as a single character word) or error
default:
{
if (isalpha(c))
{
t = word(c);
return *this;
}
setBad();
t.setBad();
return *this;
}
}
}
Foam::Istream& Foam::IPstream::read(char& c)
{
c = buf_[bufPosition_];
bufPosition_++;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(word& str)
{
size_t len;
readFromBuffer(len);
str = &buf_[bufPosition_];
bufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(string& str)
{
size_t len;
readFromBuffer(len);
str = &buf_[bufPosition_];
bufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::IPstream::read(label& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(floatScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(doubleScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("IPstream::read(char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
readFromBuffer(data, count, 8);
return *this;
}
Foam::Istream& Foam::IPstream::rewind()
{
bufPosition_ = 0;
return *this;
}
:
Pstream(commsType, bufSize),
UIPstream(commsType, fromProcNo, buf_)
{}
// ************************************************************************* //

View File

@ -38,7 +38,7 @@ SourceFiles
#ifndef IPstream_H
#define IPstream_H
#include "Istream.H"
#include "UIPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,26 +52,8 @@ namespace Foam
class IPstream
:
public Pstream,
public Istream
public UIPstream
{
// Private data
int fromProcNo_;
label messageSize_;
// Private member functions
//- Check the bufferPosition_ against messageSize_ for EOF
inline void checkEof();
//- Read a T from the transfer buffer
template<class T>
inline void readFromBuffer(T&);
//- Read data from the transfer buffer
inline void readFromBuffer(void* data, size_t count, size_t align);
public:
@ -88,76 +70,6 @@ public:
versionNumber version=currentVersion
);
// Destructor
~IPstream();
// Member functions
// Inquiry
//- Return flags of output stream
ios_base::fmtflags flags() const
{
return ios_base::fmtflags(0);
}
// Read functions
//- Read into given buffer from given processor and return the
// message size
static label read
(
const commsTypes commsType,
const int fromProcNo,
char* buf,
const std::streamsize bufSize
);
//- Return next token from stream
Istream& read(token&);
//- Read a character
Istream& read(char&);
//- Read a word
Istream& read(word&);
// Read a string (including enclosing double-quotes)
Istream& read(string&);
//- Read a label
Istream& read(label&);
//- Read a floatScalar
Istream& read(floatScalar&);
//- Read a doubleScalar
Istream& read(doubleScalar&);
//- Read binary block
Istream& read(char*, std::streamsize);
//- Rewind and return the stream so that it may be read again
Istream& rewind();
// Edit
//- Set flags of stream
ios_base::fmtflags flags(const ios_base::fmtflags)
{
return ios_base::fmtflags(0);
}
// Print
//- Print description of IOstream to Ostream
void print(Ostream&) const;
};

View File

@ -22,68 +22,9 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Write primitive and binary block from OPstream
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "OPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
template<class T>
inline void Foam::OPstream::writeToBuffer(const T& t)
{
writeToBuffer(&t, sizeof(T), sizeof(T));
}
inline void Foam::OPstream::writeToBuffer(const char& c)
{
if (size_t(buf_.size()) < bufPosition_ + 1U)
{
enlargeBuffer(1);
}
buf_[bufPosition_] = c;
bufPosition_ ++;
}
inline void Foam::OPstream::writeToBuffer
(
const void* data,
size_t count,
size_t align
)
{
label oldPos = bufPosition_;
if (align > 1)
{
// Align bufPosition. Pads bufPosition_ - oldPos characters.
bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
}
if (size_t(buf_.size()) < bufPosition_ + count)
{
enlargeBuffer(bufPosition_ - oldPos + count);
}
register char* bufPtr = &buf_[bufPosition_];
register const char* dataPtr = reinterpret_cast<const char*>(data);
register size_t i = count;
while (i--) *bufPtr++ = *dataPtr++;
bufPosition_ += count;
}
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
@ -92,137 +33,14 @@ Foam::OPstream::OPstream
const commsTypes commsType,
const int toProcNo,
const label bufSize,
const int tag,
streamFormat format,
versionNumber version
)
:
Pstream(commsType, bufSize),
Ostream(format, version),
toProcNo_(toProcNo)
{
setOpened();
setGood();
if (!bufSize)
{
buf_.setSize(1000);
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Ostream& Foam::OPstream::write(const token&)
{
notImplemented("Ostream& OPstream::write(const token&)");
setBad();
return *this;
}
Foam::Ostream& Foam::OPstream::write(const char c)
{
if (!isspace(c))
{
writeToBuffer(c);
}
return *this;
}
Foam::Ostream& Foam::OPstream::write(const char* str)
{
word nonWhiteChars(string::validate<word>(str));
if (nonWhiteChars.size() == 1)
{
return write(nonWhiteChars.c_str()[1]);
}
else if (nonWhiteChars.size())
{
return write(nonWhiteChars);
}
else
{
return *this;
}
}
Foam::Ostream& Foam::OPstream::write(const word& str)
{
write(char(token::WORD));
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::OPstream::write(const string& str)
{
write(char(token::STRING));
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::OPstream::writeQuoted(const std::string& str, const bool)
{
write(char(token::STRING));
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::OPstream::write(const label val)
{
write(char(token::LABEL));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::OPstream::write(const floatScalar val)
{
write(char(token::FLOAT_SCALAR));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::OPstream::write(const doubleScalar val)
{
write(char(token::DOUBLE_SCALAR));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::OPstream::write(const char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("Ostream::write(const char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
writeToBuffer(data, count, 8);
return *this;
}
UOPstream(commsType, toProcNo, buf_, tag, true, format, version)
{}
// ************************************************************************* //

View File

@ -38,7 +38,7 @@ SourceFiles
#ifndef OPstream_H
#define OPstream_H
#include "Ostream.H"
#include "UOPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,25 +52,8 @@ namespace Foam
class OPstream
:
public Pstream,
public Ostream
public UOPstream
{
// Private data
int toProcNo_;
// Private member functions
//- Write a T to the transfer buffer
template<class T>
inline void writeToBuffer(const T&);
//- Write a char to the transfer buffer
inline void writeToBuffer(const char&);
//- Write data to the transfer buffer
inline void writeToBuffer(const void* data, size_t count, size_t align);
public:
@ -83,126 +66,11 @@ public:
const commsTypes commsType,
const int toProcNo,
const label bufSize = 0,
const int tag = UPstream::msgType(),
streamFormat format=BINARY,
versionNumber version=currentVersion
);
// Destructor
~OPstream();
// Member functions
// Inquiry
//- Return flags of output stream
ios_base::fmtflags flags() const
{
return ios_base::fmtflags(0);
}
// Write functions
//- Write given buffer to given processor
static bool write
(
const commsTypes commsType,
const int toProcNo,
const char* buf,
const std::streamsize bufSize
);
//- Write next token to stream
Ostream& write(const token&);
//- Write character
Ostream& write(const char);
//- Write character string
Ostream& write(const char*);
//- Write word
Ostream& write(const word&);
//- Write string
Ostream& write(const string&);
//- Write std::string surrounded by quotes.
// Optional write without quotes.
Ostream& writeQuoted
(
const std::string&,
const bool quoted=true
);
//- Write label
Ostream& write(const label);
//- Write floatScalar
Ostream& write(const floatScalar);
//- Write doubleScalar
Ostream& write(const doubleScalar);
//- Write binary block
Ostream& write(const char*, std::streamsize);
//- Add indentation characters
void indent()
{}
// Stream state functions
//- Flush stream
void flush()
{}
//- Add newline and flush stream
void endl()
{}
//- Get width of output field
int width() const
{
return 0;
}
//- Set width of output field (and return old width)
int width(const int)
{
return 0;
}
//- Get precision of output field
int precision() const
{
return 0;
}
//- Set precision of output field (and return old precision)
int precision(const int)
{
return 0;
}
// Edit
//- Set flags of stream
ios_base::fmtflags flags(const ios_base::fmtflags)
{
return ios_base::fmtflags(0);
}
// Print
//- Print description of IOstream to Ostream
void print(Ostream&) const;
};

View File

@ -25,226 +25,16 @@ License
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#include "debug.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::Pstream, 0);
template<>
const char* Foam::NamedEnum<Foam::Pstream::commsTypes, 3>::names[] =
{
"blocking",
"scheduled",
"nonBlocking"
};
const Foam::NamedEnum<Foam::Pstream::commsTypes, 3>
Foam::Pstream::commsTypeNames;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::Pstream::setParRun()
{
parRun_ = true;
Pout.prefix() = '[' + name(myProcNo()) + "] ";
Perr.prefix() = '[' + name(myProcNo()) + "] ";
}
void Foam::Pstream::calcLinearComm(const label nProcs)
{
linearCommunication_.setSize(nProcs);
// Master
labelList belowIDs(nProcs - 1);
forAll(belowIDs, i)
{
belowIDs[i] = i + 1;
}
linearCommunication_[0] = commsStruct
(
nProcs,
0,
-1,
belowIDs,
labelList(0)
);
// Slaves. Have no below processors, only communicate up to master
for (label procID = 1; procID < nProcs; procID++)
{
linearCommunication_[procID] = commsStruct
(
nProcs,
procID,
0,
labelList(0),
labelList(0)
);
}
}
// Append my children (and my children children etc.) to allReceives.
void Foam::Pstream::collectReceives
(
const label procID,
const List<DynamicList<label> >& receives,
DynamicList<label>& allReceives
)
{
const DynamicList<label>& myChildren = receives[procID];
forAll(myChildren, childI)
{
allReceives.append(myChildren[childI]);
collectReceives(myChildren[childI], receives, allReceives);
}
}
// Tree like schedule. For 8 procs:
// (level 0)
// 0 receives from 1
// 2 receives from 3
// 4 receives from 5
// 6 receives from 7
// (level 1)
// 0 receives from 2
// 4 receives from 6
// (level 2)
// 0 receives from 4
//
// The sends/receives for all levels are collected per processor (one send per
// processor; multiple receives possible) creating a table:
//
// So per processor:
// proc receives from sends to
// ---- ------------- --------
// 0 1,2,4 -
// 1 - 0
// 2 3 0
// 3 - 2
// 4 5 0
// 5 - 4
// 6 7 4
// 7 - 6
void Foam::Pstream::calcTreeComm(label nProcs)
{
label nLevels = 1;
while ((1 << nLevels) < nProcs)
{
nLevels++;
}
List<DynamicList<label> > receives(nProcs);
labelList sends(nProcs, -1);
// Info<< "Using " << nLevels << " communication levels" << endl;
label offset = 2;
label childOffset = offset/2;
for (label level = 0; level < nLevels; level++)
{
label receiveID = 0;
while (receiveID < nProcs)
{
// Determine processor that sends and we receive from
label sendID = receiveID + childOffset;
if (sendID < nProcs)
{
receives[receiveID].append(sendID);
sends[sendID] = receiveID;
}
receiveID += offset;
}
offset <<= 1;
childOffset <<= 1;
}
// For all processors find the processors it receives data from
// (and the processors they receive data from etc.)
List<DynamicList<label> > allReceives(nProcs);
for (label procID = 0; procID < nProcs; procID++)
{
collectReceives(procID, receives, allReceives[procID]);
}
treeCommunication_.setSize(nProcs);
for (label procID = 0; procID < nProcs; procID++)
{
treeCommunication_[procID] = commsStruct
(
nProcs,
procID,
sends[procID],
receives[procID].shrink(),
allReceives[procID].shrink()
);
}
}
// Callback from Pstream::init() : initialize linear and tree communication
// schedules now that nProcs is known.
void Foam::Pstream::initCommunicationSchedule()
{
calcLinearComm(nProcs());
calcTreeComm(nProcs());
}
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Initialise my process number to 0 (the master)
int Foam::Pstream::myProcNo_(0);
// By default this is not a parallel run
bool Foam::Pstream::parRun_(false);
// List of process IDs
Foam::List<int> Foam::Pstream::procIDs_(1, 0);
// Standard transfer message type
int Foam::Pstream::msgType_(1);
// Linear communication schedule
Foam::List<Foam::Pstream::commsStruct> Foam::Pstream::linearCommunication_(0);
// Multi level communication schedule
Foam::List<Foam::Pstream::commsStruct> Foam::Pstream::treeCommunication_(0);
// Should compact transfer be used in which floats replace doubles
// reducing the bandwidth requirement at the expense of some loss
// in accuracy
bool Foam::Pstream::floatTransfer
(
debug::optimisationSwitch("floatTransfer", 0)
);
// Number of processors at which the reduce algorithm changes from linear to
// tree
int Foam::Pstream::nProcsSimpleSum
(
debug::optimisationSwitch("nProcsSimpleSum", 16)
);
// Default commsType
Foam::Pstream::commsTypes Foam::Pstream::defaultCommsType
(
commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
);
// ************************************************************************* //

View File

@ -30,22 +30,18 @@ Description
SourceFiles
Pstream.C
PstreamsPrint.C
PstreamCommsStruct.C
gatherScatter.C
combineGatherScatter.C
gatherScatterList.C
exchange.C
\*---------------------------------------------------------------------------*/
#ifndef Pstream_H
#define Pstream_H
#include "labelList.H"
#include "UPstream.H"
#include "DynamicList.H"
#include "HashTable.H"
#include "string.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,162 +53,16 @@ namespace Foam
\*---------------------------------------------------------------------------*/
class Pstream
:
public UPstream
{
public:
//- Types of communications
enum commsTypes
{
blocking,
scheduled,
nonBlocking
};
static const NamedEnum<commsTypes, 3> commsTypeNames;
//- Structure for communicating between processors
class commsStruct
{
// Private data
//- procID of above processor
label above_;
//- procIDs of processors directly below me
labelList below_;
//- procIDs of all processors below (so not just directly below)
labelList allBelow_;
//- procIDs of all processors not below. (inverse set of allBelow_
// and minus myProcNo)
labelList allNotBelow_;
public:
// Constructors
//- Construct null
commsStruct();
//- Construct from components
commsStruct
(
const label,
const labelList&,
const labelList&,
const labelList&
);
//- Construct from components; construct allNotBelow_
commsStruct
(
const label nProcs,
const label myProcID,
const label,
const labelList&,
const labelList&
);
// Member Functions
// Access
label above() const
{
return above_;
}
const labelList& below() const
{
return below_;
}
const labelList& allBelow() const
{
return allBelow_;
}
const labelList& allNotBelow() const
{
return allNotBelow_;
}
// Member operators
bool operator==(const commsStruct&) const;
bool operator!=(const commsStruct&) const;
// Ostream Operator
friend Ostream& operator<<(Ostream&, const commsStruct&);
};
private:
// Private data
static int myProcNo_;
static bool parRun_;
static List<int> procIDs_;
static int msgType_;
static List<commsStruct> linearCommunication_;
static List<commsStruct> treeCommunication_;
// Private member functions
//- Set data for parallel running
static void setParRun();
//- Calculate linear communication schedule
static void calcLinearComm(const label nProcs);
//- Calculate tree communication schedule
static void calcTreeComm(const label nProcs);
//- Helper function for tree communication schedule determination
// Collects all processorIDs below a processor
static void collectReceives
(
const label procID,
const List<DynamicList<label> >& receives,
DynamicList<label>& allReceives
);
//- Initialize all communication schedules. Callback from
// Pstream::init()
static void initCommunicationSchedule();
protected:
// Protected data
//- Communications type of this stream
commsTypes commsType_;
//- Transfer buffer
List<char> buf_;
//- Current buffer read/write location
int bufPosition_;
// Protected member functions
//- Increase the size of the transfer buffer
inline void enlargeBuffer(size_t count);
DynamicList<char> buf_;
public:
@ -220,21 +70,6 @@ public:
ClassName("Pstream");
// Static data
//- Should compact transfer be used in which floats replace doubles
// reducing the bandwidth requirement at the expense of some loss
// in accuracy
static bool floatTransfer;
//- Number of processors at which the sum algorithm changes from linear
// to tree
static int nProcsSimpleSum;
//- Default commsType
static commsTypes defaultCommsType;
// Constructors
//- Construct given optional buffer size
@ -244,151 +79,16 @@ public:
const label bufSize = 0
)
:
commsType_(commsType),
bufPosition_(0)
UPstream(commsType),
buf_(0)
{
if (bufSize)
{
buf_.setSize(bufSize + 2*sizeof(scalar) + 1);
buf_.setCapacity(bufSize + 2*sizeof(scalar) + 1);
}
}
// Member functions
//- Add the valid option this type of communications library
// adds/requires on the command line
static void addValidParOptions(HashTable<string>& validParOptions);
//- Initialisation function called from main
// Spawns slave processes and initialises inter-communication
static bool init(int& argc, char**& argv);
//- Non-blocking comms: wait until all have finished.
static void waitRequests();
//- Non-blocking comms: has request i finished?
static bool finishedRequest(const label i);
//- Is this a parallel run?
static bool parRun()
{
return parRun_;
}
//- Number of processes in parallel run
static label nProcs()
{
return procIDs_.size();
}
//- Am I the master process
static bool master()
{
return myProcNo_ == 0;
}
//- Process index of the master
static int masterNo()
{
return 0;
}
//- Number of this process (starting from masterNo() = 0)
static int myProcNo()
{
return myProcNo_;
}
//- Process IDs
static const List<int>& procIDs()
{
return procIDs_;
}
//- Process ID of given process index
static int procID(int procNo)
{
return procIDs_[procNo];
}
//- Process index of first slave
static int firstSlave()
{
return 1;
}
//- Process index of last slave
static int lastSlave()
{
return nProcs() - 1;
}
//- Communication schedule for linear all-to-master (proc 0)
static const List<commsStruct>& linearCommunication()
{
return linearCommunication_;
}
//- Communication schedule for tree all-to-master (proc 0)
static const List<commsStruct>& treeCommunication()
{
return treeCommunication_;
}
//- Message tag of standard messages
static int& msgType()
{
return msgType_;
}
//- Get the communications type of the stream
commsTypes commsType() const
{
return commsType_;
}
//- Set the communications type of the stream
commsTypes commsType(const commsTypes ct)
{
commsTypes oldCommsType = commsType_;
commsType_ = ct;
return oldCommsType;
}
//- Transfer buffer
const List<char>& buf() const
{
return buf_;
}
//- Transfer buffer
List<char>& buf()
{
return buf_;
}
//- Current buffer read/write location
int bufPosition() const
{
return bufPosition_;
}
//- Current buffer read/write location
int& bufPosition()
{
return bufPosition_;
}
//- Exit program
static void exit(int errnum = 1);
//- Abort program
static void abort();
// Gather and scatter
//- Gather data. Apply bop to combine Value
@ -501,8 +201,8 @@ public:
// Gather/scatter keeping the individual processor data separate.
// Values is a List of size Pstream::nProcs() where
// Values[Pstream::myProcNo()] is the data for the current processor.
// Values is a List of size UPstream::nProcs() where
// Values[UPstream::myProcNo()] is the data for the current processor.
//- Gather data but keep individual values separate
template <class T>
@ -527,18 +227,27 @@ public:
//- Like above but switches between linear/tree communication
template <class T>
static void scatterList(List<T>& Values);
// Exchange
//- Exchange data. Sends sendData, receives into recvData, sets
// sizes (not bytes). sizes[p0][p1] is what processor p0 has
// sent to p1. Continuous data only.
// If block=true will wait for all transfers to finish.
template <class Container, class T>
static void exchange
(
const List<Container >&,
List<Container >&,
labelListList& sizes,
const int tag = UPstream::msgType(),
const bool block = true
);
};
inline void Pstream::enlargeBuffer(size_t count)
{
buf_.setSize(max(int(buf_.size() + count), 2*buf_.size()));
}
Ostream& operator<<(Ostream&, const Pstream::commsStruct&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -549,9 +258,9 @@ Ostream& operator<<(Ostream&, const Pstream::commsStruct&);
# include "gatherScatter.C"
# include "combineGatherScatter.C"
# include "gatherScatterList.C"
# include "exchange.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -0,0 +1,117 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "PstreamBuffers.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
namespace Foam
{
DynamicList<char> PstreamBuffers::nullBuf(0);
}
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
Foam::PstreamBuffers::PstreamBuffers
(
const UPstream::commsTypes commsType,
const int tag,
IOstream::streamFormat format,
IOstream::versionNumber version
)
:
commsType_(commsType),
tag_(tag),
format_(format),
version_(version),
sendBuf_(UPstream::nProcs()),
recvBuf_(UPstream::nProcs()),
finishedSendsCalled_(false)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::PstreamBuffers::finishedSends(const bool block)
{
finishedSendsCalled_ = true;
if (commsType_ == UPstream::nonBlocking)
{
labelListList sizes;
Pstream::exchange<DynamicList<char>, char>
(
sendBuf_,
recvBuf_,
sizes,
tag_,
block
);
}
}
void Foam::PstreamBuffers::finishedSends(labelListList& sizes, const bool block)
{
finishedSendsCalled_ = true;
if (commsType_ == UPstream::nonBlocking)
{
labelListList sizes;
labelListList send,recv;
Pstream::exchange<DynamicList<char>, char>
(
sendBuf_,
recvBuf_,
sizes,
tag_,
block
);
}
else
{
sizes.setSize(UPstream::nProcs());
labelList& nsTransPs = sizes[UPstream::myProcNo()];
nsTransPs.setSize(UPstream::nProcs());
forAll(sendBuf_, procI)
{
nsTransPs[procI] = sendBuf_[procI].size();
}
// Send sizes across.
int oldTag = UPstream::msgType();
UPstream::msgType() = tag_;
combineReduce(sizes, UPstream::listEq());
UPstream::msgType() = oldTag;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,155 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::PstreamBuffers
Description
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Use UOPstream to stream data into buffers, call finishedSends() to
notify that data is in buffers and then use IUPstream to get data out
of received buffers. Works with both blocking and nonBlocking. Does
not make much sense with scheduled since there you would not need these
explicit buffers.
Example usage:
PstreamBuffers pBuffers(Pstream::nonBlocking);
for (label procI = 0; procI < Pstream::nProcs(); procI++)
{
if (procI != Pstream::myProcNo())
{
someObject vals;
UOPstream str(procI, pBuffers);
str << vals;
}
}
pBuffers.finishedSends(); // no-op for blocking
for (label procI = 0; procI < Pstream::nProcs(); procI++)
{
if (procI != Pstream::myProcNo())
{
UIPstream str(procI, pBuffers);
someObject vals(str);
}
}
SourceFiles
PstreamBuffers.C
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#ifndef PstreamBuffers_H
#define PstreamBuffers_H
#include "DynamicList.H"
#include "UPstream.H"
#include "IOstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class PstreamBuffers Declaration
\*---------------------------------------------------------------------------*/
class PstreamBuffers
{
friend class UOPstream;
friend class UIPstream;
// Private data
//- Communications type of this stream
const UPstream::commsTypes commsType_;
const int tag_;
const IOstream::streamFormat format_;
const IOstream::versionNumber version_;
//- send buffer
List<DynamicList<char> > sendBuf_;
//- receive buffer
List<DynamicList<char> > recvBuf_;
bool finishedSendsCalled_;
// Private member functions
public:
// Static data
static DynamicList<char> nullBuf;
// Constructors
//- Construct given comms type,
// write format and IO version
PstreamBuffers
(
const UPstream::commsTypes commsType,
const int tag = UPstream::msgType(),
IOstream::streamFormat format=IOstream::BINARY,
IOstream::versionNumber version=IOstream::currentVersion
);
// Member functions
//- Mark all sends as having been done. This will start receives
// in non-blocking mode. If block will wait for all transfers to
// finish (only relevant for nonBlocking mode)
void finishedSends(const bool block = true);
//- Mark all sends as having been done. Same as above but also returns
// sizes (bytes) transferred.
void finishedSends(labelListList& sizes, const bool block = true);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::Pstream
Foam
Description
Combination-Reduction operation for a parallel run. The
@ -37,6 +37,7 @@ Description
#ifndef PstreamCombineReduceOps_H
#define PstreamCombineReduceOps_H
#include "UPstream.H"
#include "Pstream.H"
#include "ops.H"
@ -50,7 +51,7 @@ namespace Foam
template <class T, class CombineOp>
void combineReduce
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
T& Value,
const CombineOp& cop
)
@ -63,15 +64,15 @@ void combineReduce
template <class T, class CombineOp>
void combineReduce(T& Value, const CombineOp& cop)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
Pstream::combineGather(Pstream::linearCommunication(), Value, cop);
Pstream::combineScatter(Pstream::linearCommunication(), Value);
Pstream::combineGather(UPstream::linearCommunication(), Value, cop);
Pstream::combineScatter(UPstream::linearCommunication(), Value);
}
else
{
Pstream::combineGather(Pstream::treeCommunication(), Value, cop);
Pstream::combineScatter(Pstream::treeCommunication(), Value);
Pstream::combineGather(UPstream::treeCommunication(), Value, cop);
Pstream::combineScatter(UPstream::treeCommunication(), Value);
}
}

View File

@ -41,7 +41,7 @@ namespace Foam
template <class T, class BinaryOp>
void reduce
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
T& Value,
const BinaryOp& bop
)
@ -59,13 +59,13 @@ void reduce
const BinaryOp& bop
)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
reduce(Pstream::linearCommunication(), Value, bop);
reduce(UPstream::linearCommunication(), Value, bop);
}
else
{
reduce(Pstream::treeCommunication(), Value, bop);
reduce(UPstream::treeCommunication(), Value, bop);
}
}
@ -80,13 +80,13 @@ T returnReduce
{
T WorkValue(Value);
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
reduce(Pstream::linearCommunication(), WorkValue, bop);
reduce(UPstream::linearCommunication(), WorkValue, bop);
}
else
{
reduce(Pstream::treeCommunication(), WorkValue, bop);
reduce(UPstream::treeCommunication(), WorkValue, bop);
}
return WorkValue;

View File

@ -0,0 +1,322 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "UIPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
inline void Foam::UIPstream::checkEof()
{
if (externalBufPosition_ == messageSize_)
{
setEof();
}
}
template<class T>
inline void Foam::UIPstream::readFromBuffer(T& t)
{
const size_t align = sizeof(T);
externalBufPosition_ = align + ((externalBufPosition_ - 1) & ~(align - 1));
t = reinterpret_cast<T&>(externalBuf_[externalBufPosition_]);
externalBufPosition_ += sizeof(T);
checkEof();
}
inline void Foam::UIPstream::readFromBuffer
(
void* data,
size_t count,
size_t align
)
{
if (align > 1)
{
externalBufPosition_ =
align
+ ((externalBufPosition_ - 1) & ~(align - 1));
}
register const char* bufPtr = &externalBuf_[externalBufPosition_];
register char* dataPtr = reinterpret_cast<char*>(data);
register size_t i = count;
while (i--) *dataPtr++ = *bufPtr++;
externalBufPosition_ += count;
checkEof();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::UIPstream::~UIPstream()
{
if (externalBufPosition_ < messageSize_)
{
FatalErrorIn("UIPstream::~UIPstream()")
<< "Message not fully consumed. messageSize:" << messageSize_
<< " bytes of which only " << externalBufPosition_
<< " consumed." << Foam::abort(FatalError);
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Istream& Foam::UIPstream::read(token& t)
{
// Return the put back token if it exists
if (Istream::getBack(t))
{
return *this;
}
char c;
// return on error
if (!read(c))
{
t.setBad();
return *this;
}
// Set the line number of this token to the current stream line number
t.lineNumber() = lineNumber();
// Analyse input starting with this character.
switch (c)
{
// Punctuation
case token::END_STATEMENT :
case token::BEGIN_LIST :
case token::END_LIST :
case token::BEGIN_SQR :
case token::END_SQR :
case token::BEGIN_BLOCK :
case token::END_BLOCK :
case token::COLON :
case token::COMMA :
case token::ASSIGN :
case token::ADD :
case token::SUBTRACT :
case token::MULTIPLY :
case token::DIVIDE :
{
t = token::punctuationToken(c);
return *this;
}
// Word
case token::WORD :
{
word* pval = new word;
if (read(*pval))
{
if (token::compound::isCompound(*pval))
{
t = token::compound::New(*pval, *this).ptr();
delete pval;
}
else
{
t = pval;
}
}
else
{
delete pval;
t.setBad();
}
return *this;
}
// String
case token::STRING :
{
string* pval = new string;
if (read(*pval))
{
t = pval;
}
else
{
delete pval;
t.setBad();
}
return *this;
}
// Label
case token::LABEL :
{
label val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// floatScalar
case token::FLOAT_SCALAR :
{
floatScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// doubleScalar
case token::DOUBLE_SCALAR :
{
doubleScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// Character (returned as a single character word) or error
default:
{
if (isalpha(c))
{
t = word(c);
return *this;
}
setBad();
t.setBad();
return *this;
}
}
}
Foam::Istream& Foam::UIPstream::read(char& c)
{
c = externalBuf_[externalBufPosition_];
externalBufPosition_++;
checkEof();
return *this;
}
Foam::Istream& Foam::UIPstream::read(word& str)
{
size_t len;
readFromBuffer(len);
str = &externalBuf_[externalBufPosition_];
externalBufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::UIPstream::read(string& str)
{
size_t len;
readFromBuffer(len);
str = &externalBuf_[externalBufPosition_];
externalBufPosition_ += len + 1;
checkEof();
return *this;
}
Foam::Istream& Foam::UIPstream::read(label& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::UIPstream::read(floatScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::UIPstream::read(doubleScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::UIPstream::read(char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("UIPstream::read(char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
readFromBuffer(data, count, 8);
return *this;
}
Foam::Istream& Foam::UIPstream::rewind()
{
externalBufPosition_ = 0;
return *this;
}
void Foam::UIPstream::print(Ostream& os) const
{
os << "Reading from processor " << fromProcNo_
<< " to processor " << myProcNo() << Foam::endl;
}
// ************************************************************************* //

View File

@ -0,0 +1,187 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::UIPstream
Description
Input inter-processor communications stream operating on external
buffer.
SourceFiles
UIPstream.C
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#ifndef UIPstream_H
#define UIPstream_H
#include "UPstream.H"
#include "Istream.H"
#include "PstreamBuffers.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class UIPstream Declaration
\*---------------------------------------------------------------------------*/
class UIPstream
:
public UPstream,
public Istream
{
// Private data
int fromProcNo_;
DynamicList<char>& externalBuf_;
label externalBufPosition_;
const int tag_;
label messageSize_;
// Private member functions
//- Check the bufferPosition against messageSize_ for EOF
inline void checkEof();
//- Read a T from the transfer buffer
template<class T>
inline void readFromBuffer(T&);
//- Read data from the transfer buffer
inline void readFromBuffer(void* data, size_t count, size_t align);
public:
// Constructors
//- Construct given process index to read from and optional buffer size,
// read format and IO version
UIPstream
(
const commsTypes commsType,
const int fromProcNo,
DynamicList<char>& externalBuf,
const int tag = UPstream::msgType(),
streamFormat format=BINARY,
versionNumber version=currentVersion
);
//- Construct given buffers
UIPstream(const int fromProcNo, PstreamBuffers&);
// Destructor
~UIPstream();
// Member functions
// Inquiry
//- Return flags of output stream
ios_base::fmtflags flags() const
{
return ios_base::fmtflags(0);
}
// Read functions
//- Read into given buffer from given processor and return the
// message size
static label read
(
const commsTypes commsType,
const int fromProcNo,
char* buf,
const std::streamsize bufSize,
const int tag = UPstream::msgType()
);
//- Return next token from stream
Istream& read(token&);
//- Read a character
Istream& read(char&);
//- Read a word
Istream& read(word&);
// Read a string (including enclosing double-quotes)
Istream& read(string&);
//- Read a label
Istream& read(label&);
//- Read a floatScalar
Istream& read(floatScalar&);
//- Read a doubleScalar
Istream& read(doubleScalar&);
//- Read binary block
Istream& read(char*, std::streamsize);
//- Rewind and return the stream so that it may be read again
Istream& rewind();
// Edit
//- Set flags of stream
ios_base::fmtflags flags(const ios_base::fmtflags)
{
return ios_base::fmtflags(0);
}
// Print
//- Print description of IOstream to Ostream
void print(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,275 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Write primitive and binary block from UOPstream
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "UOPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
// * * * * * * * * * * * * * Private member functions * * * * * * * * * * * //
template<class T>
inline void Foam::UOPstream::writeToBuffer(const T& t)
{
writeToBuffer(&t, sizeof(T), sizeof(T));
}
inline void Foam::UOPstream::writeToBuffer(const char& c)
{
if (!sendBuf_.capacity())
{
sendBuf_.setCapacity(1000);
}
sendBuf_.append(c);
}
inline void Foam::UOPstream::writeToBuffer
(
const void* data,
size_t count,
size_t align
)
{
if (!sendBuf_.capacity())
{
sendBuf_.setCapacity(1000);
}
label alignedPos = sendBuf_.size();
if (align > 1)
{
// Align bufPosition. Pads sendBuf_.size() - oldPos characters.
alignedPos = align + ((sendBuf_.size() - 1) & ~(align - 1));
}
// Extend if necessary
sendBuf_.setSize(alignedPos + count);
register const char* dataPtr = reinterpret_cast<const char*>(data);
register size_t i = count;
while (i--) sendBuf_[alignedPos++] = *dataPtr++;
}
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
Foam::UOPstream::UOPstream
(
const commsTypes commsType,
const int toProcNo,
DynamicList<char>& sendBuf,
const int tag,
const bool sendAtDestruct,
streamFormat format,
versionNumber version
)
:
UPstream(commsType),
Ostream(format, version),
toProcNo_(toProcNo),
sendBuf_(sendBuf),
tag_(tag),
sendAtDestruct_(sendAtDestruct)
{
setOpened();
setGood();
}
Foam::UOPstream::UOPstream(const int toProcNo, PstreamBuffers& buffers)
:
UPstream(buffers.commsType_),
Ostream(buffers.format_, buffers.version_),
toProcNo_(toProcNo),
sendBuf_(buffers.sendBuf_[toProcNo]),
tag_(buffers.tag_),
sendAtDestruct_(buffers.commsType_ != UPstream::nonBlocking)
{
setOpened();
setGood();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::UOPstream::~UOPstream()
{
if (sendAtDestruct_)
{
if
(
!UOPstream::write
(
commsType_,
toProcNo_,
sendBuf_.begin(),
sendBuf_.size(),
tag_
)
)
{
FatalErrorIn("UOPstream::~UOPstream()")
<< "Failed sending outgoing message of size " << sendBuf_.size()
<< " to processor " << toProcNo_
<< Foam::abort(FatalError);
}
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Ostream& Foam::UOPstream::write(const token&)
{
notImplemented("Ostream& UOPstream::write(const token&)");
setBad();
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const char c)
{
if (!isspace(c))
{
writeToBuffer(c);
}
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const char* str)
{
word nonWhiteChars(string::validate<word>(str));
if (nonWhiteChars.size() == 1)
{
return write(nonWhiteChars.c_str()[1]);
}
else if (nonWhiteChars.size())
{
return write(nonWhiteChars);
}
else
{
return *this;
}
}
Foam::Ostream& Foam::UOPstream::write(const word& str)
{
write(char(token::WORD));
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const string& str)
{
write(char(token::STRING));
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::UOPstream::writeQuoted(const std::string& str, const bool)
{
write(char(token::STRING));
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const label val)
{
write(char(token::LABEL));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const floatScalar val)
{
write(char(token::FLOAT_SCALAR));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const doubleScalar val)
{
write(char(token::DOUBLE_SCALAR));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const char* data, std::streamsize count)
{
if (format() != BINARY)
{
FatalErrorIn("Ostream::write(const char*, std::streamsize)")
<< "stream format not binary"
<< Foam::abort(FatalError);
}
writeToBuffer(data, count, 8);
return *this;
}
void Foam::UOPstream::print(Ostream& os) const
{
os << "Writing from processor " << toProcNo_
<< " to processor " << myProcNo() << Foam::endl;
}
// ************************************************************************* //

View File

@ -0,0 +1,233 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::UOPstream
Description
Output inter-processor communications stream operating on external
buffer.
SourceFiles
UOPstream.C
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#ifndef UOPstream_H
#define UOPstream_H
#include "UPstream.H"
#include "Ostream.H"
#include "DynamicList.H"
#include "PstreamBuffers.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class UOPstream Declaration
\*---------------------------------------------------------------------------*/
class UOPstream
:
public UPstream,
public Ostream
{
// Private data
int toProcNo_;
DynamicList<char>& sendBuf_;
const int tag_;
const bool sendAtDestruct_;
// Private member functions
//- Write a T to the transfer buffer
template<class T>
inline void writeToBuffer(const T&);
//- Write a char to the transfer buffer
inline void writeToBuffer(const char&);
//- Write data to the transfer buffer
inline void writeToBuffer(const void* data, size_t count, size_t align);
public:
// Constructors
//- Construct given process index to send to and optional buffer size,
// write format and IO version
UOPstream
(
const commsTypes commsType,
const int toProcNo,
DynamicList<char>& sendBuf,
const int tag = UPstream::msgType(),
const bool sendAtDestruct = true,
streamFormat format=BINARY,
versionNumber version=currentVersion
);
//- Construct given buffers
UOPstream(const int toProcNo, PstreamBuffers&);
// Destructor
~UOPstream();
// Member functions
// Inquiry
//- Return flags of output stream
ios_base::fmtflags flags() const
{
return ios_base::fmtflags(0);
}
// Write functions
//- Write given buffer to given processor
static bool write
(
const commsTypes commsType,
const int toProcNo,
const char* buf,
const std::streamsize bufSize,
const int tag = UPstream::msgType()
);
//- Write next token to stream
Ostream& write(const token&);
//- Write character
Ostream& write(const char);
//- Write character string
Ostream& write(const char*);
//- Write word
Ostream& write(const word&);
//- Write string
Ostream& write(const string&);
//- Write std::string surrounded by quotes.
// Optional write without quotes.
Ostream& writeQuoted
(
const std::string&,
const bool quoted=true
);
//- Write label
Ostream& write(const label);
//- Write floatScalar
Ostream& write(const floatScalar);
//- Write doubleScalar
Ostream& write(const doubleScalar);
//- Write binary block
Ostream& write(const char*, std::streamsize);
//- Add indentation characters
void indent()
{}
// Stream state functions
//- Flush stream
void flush()
{}
//- Add newline and flush stream
void endl()
{}
//- Get width of output field
int width() const
{
return 0;
}
//- Set width of output field (and return old width)
int width(const int)
{
return 0;
}
//- Get precision of output field
int precision() const
{
return 0;
}
//- Set precision of output field (and return old precision)
int precision(const int)
{
return 0;
}
// Edit
//- Set flags of stream
ios_base::fmtflags flags(const ios_base::fmtflags)
{
return ios_base::fmtflags(0);
}
// Print
//- Print description of IOstream to Ostream
void print(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,251 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "UPstream.H"
#include "debug.H"
#include "dictionary.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::UPstream, 0);
template<>
const char* Foam::NamedEnum<Foam::UPstream::commsTypes, 3>::names[] =
{
"blocking",
"scheduled",
"nonBlocking"
};
const Foam::NamedEnum<Foam::UPstream::commsTypes, 3>
Foam::UPstream::commsTypeNames;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::UPstream::setParRun()
{
parRun_ = true;
Pout.prefix() = '[' + name(myProcNo()) + "] ";
Perr.prefix() = '[' + name(myProcNo()) + "] ";
}
void Foam::UPstream::calcLinearComm(const label nProcs)
{
linearCommunication_.setSize(nProcs);
// Master
labelList belowIDs(nProcs - 1);
forAll(belowIDs, i)
{
belowIDs[i] = i + 1;
}
linearCommunication_[0] = commsStruct
(
nProcs,
0,
-1,
belowIDs,
labelList(0)
);
// Slaves. Have no below processors, only communicate up to master
for (label procID = 1; procID < nProcs; procID++)
{
linearCommunication_[procID] = commsStruct
(
nProcs,
procID,
0,
labelList(0),
labelList(0)
);
}
}
// Append my children (and my children children etc.) to allReceives.
void Foam::UPstream::collectReceives
(
const label procID,
const List<DynamicList<label> >& receives,
DynamicList<label>& allReceives
)
{
const DynamicList<label>& myChildren = receives[procID];
forAll(myChildren, childI)
{
allReceives.append(myChildren[childI]);
collectReceives(myChildren[childI], receives, allReceives);
}
}
// Tree like schedule. For 8 procs:
// (level 0)
// 0 receives from 1
// 2 receives from 3
// 4 receives from 5
// 6 receives from 7
// (level 1)
// 0 receives from 2
// 4 receives from 6
// (level 2)
// 0 receives from 4
//
// The sends/receives for all levels are collected per processor (one send per
// processor; multiple receives possible) creating a table:
//
// So per processor:
// proc receives from sends to
// ---- ------------- --------
// 0 1,2,4 -
// 1 - 0
// 2 3 0
// 3 - 2
// 4 5 0
// 5 - 4
// 6 7 4
// 7 - 6
void Foam::UPstream::calcTreeComm(label nProcs)
{
label nLevels = 1;
while ((1 << nLevels) < nProcs)
{
nLevels++;
}
List<DynamicList<label> > receives(nProcs);
labelList sends(nProcs, -1);
// Info<< "Using " << nLevels << " communication levels" << endl;
label offset = 2;
label childOffset = offset/2;
for (label level = 0; level < nLevels; level++)
{
label receiveID = 0;
while (receiveID < nProcs)
{
// Determine processor that sends and we receive from
label sendID = receiveID + childOffset;
if (sendID < nProcs)
{
receives[receiveID].append(sendID);
sends[sendID] = receiveID;
}
receiveID += offset;
}
offset <<= 1;
childOffset <<= 1;
}
// For all processors find the processors it receives data from
// (and the processors they receive data from etc.)
List<DynamicList<label> > allReceives(nProcs);
for (label procID = 0; procID < nProcs; procID++)
{
collectReceives(procID, receives, allReceives[procID]);
}
treeCommunication_.setSize(nProcs);
for (label procID = 0; procID < nProcs; procID++)
{
treeCommunication_[procID] = commsStruct
(
nProcs,
procID,
sends[procID],
receives[procID].shrink(),
allReceives[procID].shrink()
);
}
}
// Callback from UPstream::init() : initialize linear and tree communication
// schedules now that nProcs is known.
void Foam::UPstream::initCommunicationSchedule()
{
calcLinearComm(nProcs());
calcTreeComm(nProcs());
}
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Initialise my process number to 0 (the master)
int Foam::UPstream::myProcNo_(0);
// By default this is not a parallel run
bool Foam::UPstream::parRun_(false);
// List of process IDs
Foam::List<int> Foam::UPstream::procIDs_(1, 0);
// Standard transfer message type
int Foam::UPstream::msgType_(1);
// Linear communication schedule
Foam::List<Foam::UPstream::commsStruct> Foam::UPstream::linearCommunication_(0);
// Multi level communication schedule
Foam::List<Foam::UPstream::commsStruct> Foam::UPstream::treeCommunication_(0);
// Should compact transfer be used in which floats replace doubles
// reducing the bandwidth requirement at the expense of some loss
// in accuracy
bool Foam::UPstream::floatTransfer
(
debug::optimisationSwitch("floatTransfer", 0)
);
// Number of processors at which the reduce algorithm changes from linear to
// tree
int Foam::UPstream::nProcsSimpleSum
(
debug::optimisationSwitch("nProcsSimpleSum", 16)
);
// Default commsType
Foam::UPstream::commsTypes Foam::UPstream::defaultCommsType
(
commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
);
// ************************************************************************* //

View File

@ -0,0 +1,381 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::UPstream
Description
Inter-processor communications stream
SourceFiles
UPstream.C
UPstreamsPrint.C
UPstreamCommsStruct.C
gatherScatter.C
combineGatherScatter.C
gatherScatterList.C
\*---------------------------------------------------------------------------*/
#ifndef UPstream_H
#define UPstream_H
#include "labelList.H"
#include "DynamicList.H"
#include "HashTable.H"
#include "string.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class UPstream Declaration
\*---------------------------------------------------------------------------*/
class UPstream
{
public:
//- Types of communications
enum commsTypes
{
blocking,
scheduled,
nonBlocking
};
static const NamedEnum<commsTypes, 3> commsTypeNames;
// Public classes
//- Structure for communicating between processors
class commsStruct
{
// Private data
//- procID of above processor
label above_;
//- procIDs of processors directly below me
labelList below_;
//- procIDs of all processors below (so not just directly below)
labelList allBelow_;
//- procIDs of all processors not below. (inverse set of
// allBelow_ and minus myProcNo)
labelList allNotBelow_;
public:
// Constructors
//- Construct null
commsStruct();
//- Construct from components
commsStruct
(
const label,
const labelList&,
const labelList&,
const labelList&
);
//- Construct from components; construct allNotBelow_
commsStruct
(
const label nProcs,
const label myProcID,
const label,
const labelList&,
const labelList&
);
// Member Functions
// Access
label above() const
{
return above_;
}
const labelList& below() const
{
return below_;
}
const labelList& allBelow() const
{
return allBelow_;
}
const labelList& allNotBelow() const
{
return allNotBelow_;
}
// Member operators
bool operator==(const commsStruct&) const;
bool operator!=(const commsStruct&) const;
// Ostream Operator
friend Ostream& operator<<(Ostream&, const commsStruct&);
};
//- combineReduce operator for lists. Used for counting.
class listEq
{
public:
template<class T>
void operator()(T& x, const T& y) const
{
forAll(y, i)
{
if (y[i].size())
{
x[i] = y[i];
}
}
}
};
private:
// Private data
static int myProcNo_;
static bool parRun_;
static List<int> procIDs_;
static int msgType_;
static List<commsStruct> linearCommunication_;
static List<commsStruct> treeCommunication_;
// Private member functions
//- Set data for parallel running
static void setParRun();
//- Calculate linear communication schedule
static void calcLinearComm(const label nProcs);
//- Calculate tree communication schedule
static void calcTreeComm(const label nProcs);
//- Helper function for tree communication schedule determination
// Collects all processorIDs below a processor
static void collectReceives
(
const label procID,
const List<DynamicList<label> >& receives,
DynamicList<label>& allReceives
);
//- Initialize all communication schedules. Callback from
// UPstream::init()
static void initCommunicationSchedule();
protected:
// Protected data
//- Communications type of this stream
commsTypes commsType_;
public:
// Declare name of the class and its debug switch
ClassName("UPstream");
// Static data
//- Should compact transfer be used in which floats replace doubles
// reducing the bandwidth requirement at the expense of some loss
// in accuracy
static bool floatTransfer;
//- Number of processors at which the sum algorithm changes from linear
// to tree
static int nProcsSimpleSum;
//- Default commsType
static commsTypes defaultCommsType;
// Constructors
//- Construct given optional buffer size
UPstream(const commsTypes commsType)
:
commsType_(commsType)
{}
// Member functions
//- Add the valid option this type of communications library
// adds/requires on the command line
static void addValidParOptions(HashTable<string>& validParOptions);
//- Initialisation function called from main
// Spawns slave processes and initialises inter-communication
static bool init(int& argc, char**& argv);
//- Non-blocking comms: wait until all have finished.
static void waitRequests();
//- Non-blocking comms: has request i finished?
static bool finishedRequest(const label i);
//- Is this a parallel run?
static bool parRun()
{
return parRun_;
}
//- Number of processes in parallel run
static label nProcs()
{
return procIDs_.size();
}
//- Am I the master process
static bool master()
{
return myProcNo_ == 0;
}
//- Process index of the master
static int masterNo()
{
return 0;
}
//- Number of this process (starting from masterNo() = 0)
static int myProcNo()
{
return myProcNo_;
}
//- Process IDs
static const List<int>& procIDs()
{
return procIDs_;
}
//- Process ID of given process index
static int procID(int procNo)
{
return procIDs_[procNo];
}
//- Process index of first slave
static int firstSlave()
{
return 1;
}
//- Process index of last slave
static int lastSlave()
{
return nProcs() - 1;
}
//- Communication schedule for linear all-to-master (proc 0)
static const List<commsStruct>& linearCommunication()
{
return linearCommunication_;
}
//- Communication schedule for tree all-to-master (proc 0)
static const List<commsStruct>& treeCommunication()
{
return treeCommunication_;
}
//- Message tag of standard messages
static int& msgType()
{
return msgType_;
}
//- Get the communications type of the stream
commsTypes commsType() const
{
return commsType_;
}
//- Set the communications type of the stream
commsTypes commsType(const commsTypes ct)
{
commsTypes oldCommsType = commsType_;
commsType_ = ct;
return oldCommsType;
}
//- Exit program
static void exit(int errnum = 1);
//- Abort program
static void abort();
};
Ostream& operator<<(Ostream&, const UPstream::commsStruct&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -24,12 +24,12 @@ License
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#include "UPstream.H"
#include "boolList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Pstream::commsStruct::commsStruct()
Foam::UPstream::commsStruct::commsStruct()
:
above_(-1),
below_(0),
@ -38,7 +38,7 @@ Foam::Pstream::commsStruct::commsStruct()
{}
Foam::Pstream::commsStruct::commsStruct
Foam::UPstream::commsStruct::commsStruct
(
const label above,
const labelList& below,
@ -53,7 +53,7 @@ Foam::Pstream::commsStruct::commsStruct
{}
Foam::Pstream::commsStruct::commsStruct
Foam::UPstream::commsStruct::commsStruct
(
const label nProcs,
const label myProcID,
@ -91,7 +91,7 @@ Foam::Pstream::commsStruct::commsStruct
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
bool Foam::Pstream::commsStruct::operator==(const commsStruct& comm) const
bool Foam::UPstream::commsStruct::operator==(const commsStruct& comm) const
{
return
(
@ -103,7 +103,7 @@ bool Foam::Pstream::commsStruct::operator==(const commsStruct& comm) const
}
bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const
bool Foam::UPstream::commsStruct::operator!=(const commsStruct& comm) const
{
return !operator==(comm);
}
@ -111,7 +111,7 @@ bool Foam::Pstream::commsStruct::operator!=(const commsStruct& comm) const
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const Pstream::commsStruct& comm)
Foam::Ostream& Foam::operator<<(Ostream& os, const UPstream::commsStruct& comm)
{
os << comm.above_ << token::SPACE
<< comm.below_ << token::SPACE

View File

@ -49,15 +49,15 @@ namespace Foam
template <class T, class CombineOp>
void Pstream::combineGather
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
T& Value,
const CombineOp& cop
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Receive from my downstairs neighbours
forAll(myComm.below(), belowI)
@ -67,9 +67,9 @@ void Pstream::combineGather
if (contiguous<T>())
{
T value;
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
belowID,
reinterpret_cast<char*>(&value),
sizeof(T)
@ -85,7 +85,7 @@ void Pstream::combineGather
}
else
{
IPstream fromBelow(Pstream::scheduled, belowID);
IPstream fromBelow(UPstream::scheduled, belowID);
T value(fromBelow);
if (debug & 2)
@ -109,9 +109,9 @@ void Pstream::combineGather
if (contiguous<T>())
{
OPstream::write
UOPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<const char*>(&Value),
sizeof(T)
@ -119,7 +119,7 @@ void Pstream::combineGather
}
else
{
OPstream toAbove(Pstream::scheduled, myComm.above());
OPstream toAbove(UPstream::scheduled, myComm.above());
toAbove << Value;
}
}
@ -130,33 +130,37 @@ void Pstream::combineGather
template <class T, class CombineOp>
void Pstream::combineGather(T& Value, const CombineOp& cop)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
combineGather(Pstream::linearCommunication(), Value, cop);
combineGather(UPstream::linearCommunication(), Value, cop);
}
else
{
combineGather(Pstream::treeCommunication(), Value, cop);
combineGather(UPstream::treeCommunication(), Value, cop);
}
}
template <class T>
void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
void Pstream::combineScatter
(
const List<UPstream::commsStruct>& comms,
T& Value
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
const UPstream::commsStruct& myComm = comms[UPstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
if (contiguous<T>())
{
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<char*>(&Value),
sizeof(T)
@ -164,7 +168,7 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
}
else
{
IPstream fromAbove(Pstream::scheduled, myComm.above());
IPstream fromAbove(UPstream::scheduled, myComm.above());
Value = T(fromAbove);
}
@ -187,9 +191,9 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
if (contiguous<T>())
{
OPstream::write
UOPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
belowID,
reinterpret_cast<const char*>(&Value),
sizeof(T)
@ -197,7 +201,7 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
}
else
{
OPstream toBelow(Pstream::scheduled, belowID);
OPstream toBelow(UPstream::scheduled, belowID);
toBelow << Value;
}
}
@ -208,13 +212,13 @@ void Pstream::combineScatter(const List<Pstream::commsStruct>& comms, T& Value)
template <class T>
void Pstream::combineScatter(T& Value)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
combineScatter(Pstream::linearCommunication(), Value);
combineScatter(UPstream::linearCommunication(), Value);
}
else
{
combineScatter(Pstream::treeCommunication(), Value);
combineScatter(UPstream::treeCommunication(), Value);
}
}
@ -226,15 +230,15 @@ void Pstream::combineScatter(T& Value)
template <class T, class CombineOp>
void Pstream::listCombineGather
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
List<T>& Values,
const CombineOp& cop
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Receive from my downstairs neighbours
forAll(myComm.below(), belowI)
@ -245,9 +249,9 @@ void Pstream::listCombineGather
{
List<T> receivedValues(Values.size());
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
belowID,
reinterpret_cast<char*>(receivedValues.begin()),
receivedValues.byteSize()
@ -266,7 +270,7 @@ void Pstream::listCombineGather
}
else
{
IPstream fromBelow(Pstream::scheduled, belowID);
IPstream fromBelow(UPstream::scheduled, belowID);
List<T> receivedValues(fromBelow);
if (debug & 2)
@ -293,9 +297,9 @@ void Pstream::listCombineGather
if (contiguous<T>())
{
OPstream::write
UOPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<const char*>(Values.begin()),
Values.byteSize()
@ -303,7 +307,7 @@ void Pstream::listCombineGather
}
else
{
OPstream toAbove(Pstream::scheduled, myComm.above());
OPstream toAbove(UPstream::scheduled, myComm.above());
toAbove << Values;
}
}
@ -314,13 +318,13 @@ void Pstream::listCombineGather
template <class T, class CombineOp>
void Pstream::listCombineGather(List<T>& Values, const CombineOp& cop)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
listCombineGather(Pstream::linearCommunication(), Values, cop);
listCombineGather(UPstream::linearCommunication(), Values, cop);
}
else
{
listCombineGather(Pstream::treeCommunication(), Values, cop);
listCombineGather(UPstream::treeCommunication(), Values, cop);
}
}
@ -328,23 +332,23 @@ void Pstream::listCombineGather(List<T>& Values, const CombineOp& cop)
template <class T>
void Pstream::listCombineScatter
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
List<T>& Values
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
const UPstream::commsStruct& myComm = comms[UPstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
if (contiguous<T>())
{
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<char*>(Values.begin()),
Values.byteSize()
@ -352,7 +356,7 @@ void Pstream::listCombineScatter
}
else
{
IPstream fromAbove(Pstream::scheduled, myComm.above());
IPstream fromAbove(UPstream::scheduled, myComm.above());
fromAbove >> Values;
}
@ -375,9 +379,9 @@ void Pstream::listCombineScatter
if (contiguous<T>())
{
OPstream::write
UOPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
belowID,
reinterpret_cast<const char*>(Values.begin()),
Values.byteSize()
@ -385,7 +389,7 @@ void Pstream::listCombineScatter
}
else
{
OPstream toBelow(Pstream::scheduled, belowID);
OPstream toBelow(UPstream::scheduled, belowID);
toBelow << Values;
}
}
@ -396,13 +400,13 @@ void Pstream::listCombineScatter
template <class T>
void Pstream::listCombineScatter(List<T>& Values)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
listCombineScatter(Pstream::linearCommunication(), Values);
listCombineScatter(UPstream::linearCommunication(), Values);
}
else
{
listCombineScatter(Pstream::treeCommunication(), Values);
listCombineScatter(UPstream::treeCommunication(), Values);
}
}
@ -416,22 +420,22 @@ void Pstream::listCombineScatter(List<T>& Values)
template <class Container, class CombineOp>
void Pstream::mapCombineGather
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
Container& Values,
const CombineOp& cop
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Receive from my downstairs neighbours
forAll(myComm.below(), belowI)
{
label belowID = myComm.below()[belowI];
IPstream fromBelow(Pstream::scheduled, belowID);
IPstream fromBelow(UPstream::scheduled, belowID);
Container receivedValues(fromBelow);
if (debug & 2)
@ -471,7 +475,7 @@ void Pstream::mapCombineGather
<< " data:" << Values << endl;
}
OPstream toAbove(Pstream::scheduled, myComm.above());
OPstream toAbove(UPstream::scheduled, myComm.above());
toAbove << Values;
}
}
@ -481,13 +485,13 @@ void Pstream::mapCombineGather
template <class Container, class CombineOp>
void Pstream::mapCombineGather(Container& Values, const CombineOp& cop)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
mapCombineGather(Pstream::linearCommunication(), Values, cop);
mapCombineGather(UPstream::linearCommunication(), Values, cop);
}
else
{
mapCombineGather(Pstream::treeCommunication(), Values, cop);
mapCombineGather(UPstream::treeCommunication(), Values, cop);
}
}
@ -495,19 +499,19 @@ void Pstream::mapCombineGather(Container& Values, const CombineOp& cop)
template <class Container>
void Pstream::mapCombineScatter
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
Container& Values
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
const UPstream::commsStruct& myComm = comms[UPstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
IPstream fromAbove(Pstream::scheduled, myComm.above());
IPstream fromAbove(UPstream::scheduled, myComm.above());
fromAbove >> Values;
if (debug & 2)
@ -527,7 +531,7 @@ void Pstream::mapCombineScatter
Pout<< " sending to " << belowID << " data:" << Values << endl;
}
OPstream toBelow(Pstream::scheduled, belowID);
OPstream toBelow(UPstream::scheduled, belowID);
toBelow << Values;
}
}
@ -537,19 +541,17 @@ void Pstream::mapCombineScatter
template <class Container>
void Pstream::mapCombineScatter(Container& Values)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
mapCombineScatter(Pstream::linearCommunication(), Values);
mapCombineScatter(UPstream::linearCommunication(), Values);
}
else
{
mapCombineScatter(Pstream::treeCommunication(), Values);
mapCombineScatter(UPstream::treeCommunication(), Values);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -0,0 +1,160 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Exchange data.
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#include "contiguous.H"
#include "PstreamCombineReduceOps.H"
#include "UPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//template <template<class> class ListType, class T>
template <class Container, class T>
void Pstream::exchange
(
const List<Container >& sendBufs,
List<Container >& recvBufs,
labelListList& sizes,
const int tag,
const bool block
)
{
if (UPstream::parRun())
{
if (!contiguous<T>())
{
FatalErrorIn
(
"Pstream::exchange(..)"
) << "Continuous data only." << Foam::abort(FatalError);
}
if (sendBufs.size() != UPstream::nProcs())
{
FatalErrorIn
(
"Pstream::exchange(..)"
) << "Size of list:" << sendBufs.size()
<< " does not equal the number of processors:"
<< UPstream::nProcs()
<< Foam::abort(FatalError);
}
sizes.setSize(UPstream::nProcs());
labelList& nsTransPs = sizes[UPstream::myProcNo()];
nsTransPs.setSize(UPstream::nProcs());
forAll(sendBufs, procI)
{
nsTransPs[procI] = sendBufs[procI].size();
}
// Send sizes across.
int oldTag = UPstream::msgType();
UPstream::msgType() = tag;
combineReduce(sizes, UPstream::listEq());
UPstream::msgType() = oldTag;
// Set up receives
// ~~~~~~~~~~~~~~~
recvBufs.setSize(sendBufs.size());
forAll(sizes, procI)
{
label nRecv = sizes[procI][UPstream::myProcNo()];
if (procI != Pstream::myProcNo() && nRecv > 0)
{
recvBufs[procI].setSize(nRecv);
UIPstream::read
(
UPstream::nonBlocking,
procI,
reinterpret_cast<char*>(recvBufs[procI].begin()),
nRecv*sizeof(T),
tag
);
}
}
// Set up sends
// ~~~~~~~~~~~~
forAll(sendBufs, procI)
{
if (procI != Pstream::myProcNo() && sendBufs[procI].size() > 0)
{
if
(
!UOPstream::write
(
UPstream::nonBlocking,
procI,
reinterpret_cast<const char*>(sendBufs[procI].begin()),
sendBufs[procI].size()*sizeof(T),
tag
)
)
{
FatalErrorIn("Pstream::exchange(..)")
<< "Cannot send outgoing message. "
<< "to:" << procI << " nBytes:"
<< label(sendBufs[procI].size()*sizeof(T))
<< Foam::abort(FatalError);
}
}
}
// Wait for all to finish
// ~~~~~~~~~~~~~~~~~~~~~~
if (block)
{
Pstream::waitRequests();
}
}
// Do myself
recvBufs[Pstream::myProcNo()] = sendBufs[Pstream::myProcNo()];
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -30,7 +30,9 @@ Description
\*---------------------------------------------------------------------------*/
#include "UOPstream.H"
#include "OPstream.H"
#include "UIPstream.H"
#include "IPstream.H"
#include "contiguous.H"
@ -44,15 +46,15 @@ namespace Foam
template <class T, class BinaryOp>
void Pstream::gather
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
T& Value,
const BinaryOp& bop
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Receive from my downstairs neighbours
forAll(myComm.below(), belowI)
@ -61,9 +63,9 @@ void Pstream::gather
if (contiguous<T>())
{
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
myComm.below()[belowI],
reinterpret_cast<char*>(&value),
sizeof(T)
@ -71,7 +73,7 @@ void Pstream::gather
}
else
{
IPstream fromBelow(Pstream::scheduled, myComm.below()[belowI]);
IPstream fromBelow(UPstream::scheduled, myComm.below()[belowI]);
fromBelow >> value;
}
@ -83,9 +85,9 @@ void Pstream::gather
{
if (contiguous<T>())
{
OPstream::write
UOPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<const char*>(&Value),
sizeof(T)
@ -93,7 +95,7 @@ void Pstream::gather
}
else
{
OPstream toAbove(Pstream::scheduled, myComm.above());
OPstream toAbove(UPstream::scheduled, myComm.above());
toAbove << Value;
}
}
@ -104,33 +106,33 @@ void Pstream::gather
template <class T, class BinaryOp>
void Pstream::gather(T& Value, const BinaryOp& bop)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
gather(Pstream::linearCommunication(), Value, bop);
gather(UPstream::linearCommunication(), Value, bop);
}
else
{
gather(Pstream::treeCommunication(), Value, bop);
gather(UPstream::treeCommunication(), Value, bop);
}
}
template <class T>
void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
void Pstream::scatter(const List<UPstream::commsStruct>& comms, T& Value)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
if (contiguous<T>())
{
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<char*>(&Value),
sizeof(T)
@ -138,7 +140,7 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
}
else
{
IPstream fromAbove(Pstream::scheduled, myComm.above());
IPstream fromAbove(UPstream::scheduled, myComm.above());
fromAbove >> Value;
}
}
@ -148,9 +150,9 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
{
if (contiguous<T>())
{
OPstream::write
UOPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
myComm.below()[belowI],
reinterpret_cast<const char*>(&Value),
sizeof(T)
@ -158,7 +160,7 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
}
else
{
OPstream toBelow(Pstream::scheduled,myComm.below()[belowI]);
OPstream toBelow(UPstream::scheduled,myComm.below()[belowI]);
toBelow << Value;
}
}
@ -169,13 +171,13 @@ void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
template <class T>
void Pstream::scatter(T& Value)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
scatter(Pstream::linearCommunication(), Value);
scatter(UPstream::linearCommunication(), Value);
}
else
{
scatter(Pstream::treeCommunication(), Value);
scatter(UPstream::treeCommunication(), Value);
}
}

View File

@ -27,7 +27,7 @@ Description
communication schedule (usually linear-to-master or tree-to-master).
The gathered data will be a list with element procID the data from processor
procID. Before calling every processor should insert its value into
Values[Pstream::myProcNo()].
Values[UPstream::myProcNo()].
Note: after gather every processor only knows its own data and that of the
processors below it. Only the 'master' of the communication schedule holds
a fully filled List. Use scatter to distribute the data.
@ -48,26 +48,26 @@ namespace Foam
template <class T>
void Pstream::gatherList
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
List<T>& Values
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
if (Values.size() != Pstream::nProcs())
if (Values.size() != UPstream::nProcs())
{
FatalErrorIn
(
"Pstream::gatherList(const List<Pstream::commsStruct>&"
"UPstream::gatherList(const List<UPstream::commsStruct>&"
", List<T>)"
) << "Size of list:" << Values.size()
<< " does not equal the number of processors:"
<< Pstream::nProcs()
<< UPstream::nProcs()
<< Foam::abort(FatalError);
}
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Receive from my downstairs neighbours
forAll(myComm.below(), belowI)
@ -79,9 +79,9 @@ void Pstream::gatherList
{
List<T> receivedValues(belowLeaves.size() + 1);
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
belowID,
reinterpret_cast<char*>(receivedValues.begin()),
receivedValues.byteSize()
@ -96,7 +96,7 @@ void Pstream::gatherList
}
else
{
IPstream fromBelow(Pstream::scheduled, belowID);
IPstream fromBelow(UPstream::scheduled, belowID);
fromBelow >> Values[belowID];
if (debug & 2)
@ -132,14 +132,14 @@ void Pstream::gatherList
if (debug & 2)
{
Pout<< " sending to " << myComm.above()
<< " data from me:" << Pstream::myProcNo()
<< " data:" << Values[Pstream::myProcNo()] << endl;
<< " data from me:" << UPstream::myProcNo()
<< " data:" << Values[UPstream::myProcNo()] << endl;
}
if (contiguous<T>())
{
List<T> sendingValues(belowLeaves.size() + 1);
sendingValues[0] = Values[Pstream::myProcNo()];
sendingValues[0] = Values[UPstream::myProcNo()];
forAll(belowLeaves, leafI)
{
@ -148,7 +148,7 @@ void Pstream::gatherList
OPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<const char*>(sendingValues.begin()),
sendingValues.byteSize()
@ -156,8 +156,8 @@ void Pstream::gatherList
}
else
{
OPstream toAbove(Pstream::scheduled, myComm.above());
toAbove << Values[Pstream::myProcNo()];
OPstream toAbove(UPstream::scheduled, myComm.above());
toAbove << Values[UPstream::myProcNo()];
forAll(belowLeaves, leafI)
{
@ -180,13 +180,13 @@ void Pstream::gatherList
template <class T>
void Pstream::gatherList(List<T>& Values)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
gatherList(Pstream::linearCommunication(), Values);
gatherList(UPstream::linearCommunication(), Values);
}
else
{
gatherList(Pstream::treeCommunication(), Values);
gatherList(UPstream::treeCommunication(), Values);
}
}
@ -194,26 +194,26 @@ void Pstream::gatherList(List<T>& Values)
template <class T>
void Pstream::scatterList
(
const List<Pstream::commsStruct>& comms,
const List<UPstream::commsStruct>& comms,
List<T>& Values
)
{
if (Pstream::parRun())
if (UPstream::parRun())
{
if (Values.size() != Pstream::nProcs())
if (Values.size() != UPstream::nProcs())
{
FatalErrorIn
(
"Pstream::scatterList(const List<Pstream::commsStruct>&"
"UPstream::scatterList(const List<UPstream::commsStruct>&"
", List<T>)"
) << "Size of list:" << Values.size()
<< " does not equal the number of processors:"
<< Pstream::nProcs()
<< UPstream::nProcs()
<< Foam::abort(FatalError);
}
// Get my communication order
const commsStruct& myComm = comms[Pstream::myProcNo()];
const commsStruct& myComm = comms[UPstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
@ -224,9 +224,9 @@ void Pstream::scatterList
{
List<T> receivedValues(notBelowLeaves.size());
IPstream::read
UIPstream::read
(
Pstream::scheduled,
UPstream::scheduled,
myComm.above(),
reinterpret_cast<char*>(receivedValues.begin()),
receivedValues.byteSize()
@ -239,7 +239,7 @@ void Pstream::scatterList
}
else
{
IPstream fromAbove(Pstream::scheduled, myComm.above());
IPstream fromAbove(UPstream::scheduled, myComm.above());
forAll(notBelowLeaves, leafI)
{
@ -273,7 +273,7 @@ void Pstream::scatterList
OPstream::write
(
Pstream::scheduled,
UPstream::scheduled,
belowID,
reinterpret_cast<const char*>(sendingValues.begin()),
sendingValues.byteSize()
@ -281,7 +281,7 @@ void Pstream::scatterList
}
else
{
OPstream toBelow(Pstream::scheduled, belowID);
OPstream toBelow(UPstream::scheduled, belowID);
// Send data destined for all other processors below belowID
forAll(notBelowLeaves, leafI)
@ -305,13 +305,13 @@ void Pstream::scatterList
template <class T>
void Pstream::scatterList(List<T>& Values)
{
if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
{
scatterList(Pstream::linearCommunication(), Values);
scatterList(UPstream::linearCommunication(), Values);
}
else
{
scatterList(Pstream::treeCommunication(), Values);
scatterList(UPstream::treeCommunication(), Values);
}
}

View File

@ -42,7 +42,7 @@ Foam::scalarRange::scalarRange()
{}
Foam::scalarRange::scalarRange(const scalar& lower, const scalar& upper)
Foam::scalarRange::scalarRange(const scalar lower, const scalar upper)
:
type_(RANGE),
value_(lower),
@ -123,7 +123,7 @@ Foam::scalar Foam::scalarRange::upper() const
}
bool Foam::scalarRange::selected(const scalar& value) const
bool Foam::scalarRange::selected(const scalar value) const
{
switch (type_)
{

View File

@ -92,7 +92,7 @@ public:
scalarRange();
//- Construct a Range
scalarRange(const scalar& lower, const scalar& upper);
scalarRange(const scalar lower, const scalar upper);
//- Construct from Istream.
// Since commas can be used as list delimiters,
@ -119,7 +119,7 @@ public:
scalar upper() const;
//- Return true if the value is within the range
bool selected(const scalar&) const;
bool selected(const scalar) const;
// Member Operators

View File

@ -57,7 +57,7 @@ Foam::scalarRanges::scalarRanges(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::scalarRanges::selected(const scalar& value) const
bool Foam::scalarRanges::selected(const scalar value) const
{
forAll(*this, i)
{

View File

@ -66,7 +66,7 @@ public:
// Member Functions
//- Return true if the given value is within the ranges
bool selected(const scalar&) const;
bool selected(const scalar) const;
//- Return the set of selected entries in the given list
// that are within the ranges

View File

@ -22,7 +22,7 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Namespace
InNamespace
Foam
Description
@ -35,8 +35,6 @@ Description
#include "mathematicalConstants.H"
using namespace Foam::constant::mathematical;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -45,15 +43,15 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Conversion from degrees to radians
inline scalar degToRad(const scalar& deg)
inline scalar degToRad(const scalar deg)
{
return (deg*pi/180.0);
return (deg * constant::mathematical::pi/180.0);
}
//- Conversion from radians to degrees
inline scalar radToDeg(const scalar& rad)
inline scalar radToDeg(const scalar rad)
{
return (rad*180.0/pi);
return (rad * 180.0/constant::mathematical::pi);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,236 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "uniformInterpolationTable.H"
#include "Time.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template <class Type>
void Foam::uniformInterpolationTable<Type>::checkTable() const
{
if (size() < 2)
{
FatalErrorIn("uniformInterpolationTable<Type>::checkTable()")
<< "Table " << name() << ": must have at least 2 values." << nl
<< "Table size = " << size() << nl
<< " min, interval width = " << x0_ << ", " << dx_ << nl
<< exit(FatalError);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template <class Type>
Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
(
const IOobject& io,
bool readFields
)
:
IOobject(io),
List<scalar>(2, 0.0),
x0_(0.0),
dx_(1.0),
log10_(false),
bound_(false)
{
if (readFields)
{
IOdictionary dict(io);
dict.lookup("data") >> *this;
dict.lookup("x0") >> x0_;
dict.lookup("dx") >> dx_;
dict.lookup("log10") >> log10_;
dict.lookup("bound") >> bound_;
}
checkTable();
}
template <class Type>
Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
(
const word& tableName,
const objectRegistry& db,
const dictionary& dict,
const bool initialiseOnly
)
:
IOobject
(
tableName,
db.time().constant(),
db,
IOobject::NO_READ,
IOobject::NO_WRITE,
false // if used in BCs, could be used by multiple patches
),
List<scalar>(2, 0.0),
x0_(readScalar(dict.lookup("x0"))),
dx_(readScalar(dict.lookup("dx"))),
log10_(dict.lookup("log10")),
bound_(dict.lookup("bound"))
{
if (initialiseOnly)
{
scalar xMax = readScalar(dict.lookup("xMax"));
label nIntervals = static_cast<label>(xMax - x0_)/dx_ + 1;
this->setSize(nIntervals);
}
else
{
dict.lookup("data") >> *this;
}
checkTable();
}
template <class Type>
Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
(
const uniformInterpolationTable& uit
)
:
IOobject(uit),
List<scalar>(uit),
x0_(uit.x0_),
dx_(uit.dx_),
log10_(uit.log10_),
bound_(uit.bound_)
{
checkTable();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template <class Type>
Foam::uniformInterpolationTable<Type>::~uniformInterpolationTable()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template <class Type>
Type Foam::uniformInterpolationTable<Type>::interpolate(scalar x) const
{
if (bound_)
{
x = max(min(xMax() - SMALL*dx_, x), x0_);
}
else
{
if (x < x0_)
{
FatalErrorIn
(
"uniformInterpolationTable<Type>::interpolate(scalar x)"
) << "Supplied value is less than minimum table value:" << nl
<< "xMin=" << x0_ << ", xMax=" << xMax() << ", x=" << x << nl
<< exit(FatalError);
}
if (x > xMax())
{
FatalErrorIn
(
"uniformInterpolationTable<Type>::interpolate(scalar x)"
) << "Supplied value is greater than maximum table value:" << nl
<< "xMin=" << x0_ << ", xMax=" << xMax() << ", x=" << x << nl
<< exit(FatalError);
}
}
label i = static_cast<label>((x - x0_)/dx_);
scalar xLo = x0_ + i*dx_;
Type fx = (x - xLo)/dx_*(operator[](i+1) - operator[](i)) + operator[](i);
if (debug)
{
Info<< "Table: " << name() << ", x=" << x
<< ", x_lo=" << xLo << ", x_hi=" << xLo + dx_
<< ", f(x_lo)=" << operator[](i) << ", f(x_hi)=" << operator[](i+1)
<< ", f(x)=" << fx << endl;
}
return fx;
}
template <class Type>
Type Foam::uniformInterpolationTable<Type>::interpolateLog10
(
scalar x
) const
{
if (log10_)
{
if (x > 0)
{
x = ::log10(x);
}
else if (bound_ && (x <= 0))
{
x = x0_;
}
else
{
FatalErrorIn
(
"uniformInterpolationTable<Type>::interpolateLog10(scalar x)"
) << "Table " << name() << nl
<< "Supplied value must be greater than 0 when in log10 mode"
<< nl << "x=" << x << nl << exit(FatalError);
}
}
return interpolate(x);
}
template <class Type>
void Foam::uniformInterpolationTable<Type>::write() const
{
IOdictionary dict(*this);
dict.add("data", static_cast<const List<scalar>&>(*this));
dict.add("x0", x0_);
dict.add("dx", dx_);
dict.add("log10", log10_);
dict.add("bound", bound_);
dict.regIOobject::write();
}
// ************************************************************************* //

View File

@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::uniformInterpolationTable
Description
Table with uniform interval in independant variable, with linear
interpolation
Example usage (scalar): values specified in a dictionary:
{
x0 0; // lower limit
dx 0.2; // fixed interval
log10 true; // take log(10) when interpolating?
data // list of dependent data values
(
7870 // value at x0
7870 // value at x0 + dx
...
7870 // value at x0 + n*dx
);
}
SourceFiles
uniformInterpolationTable.C
\*---------------------------------------------------------------------------*/
#ifndef uniformInterpolationTable_H
#define uniformInterpolationTable_H
#include "List.H"
#include "Switch.H"
#include "IOobject.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class uniformInterpolationTable Declaration
\*---------------------------------------------------------------------------*/
template <class Type>
class uniformInterpolationTable
:
public IOobject,
public List<Type>
{
// Private data
// Control parameetrs
//- Lower limit
scalar x0_;
//- Fixed interval
scalar dx_;
//- Flag to indicate that x data is given in log10(x) form
Switch log10_;
//- Bound x values
Switch bound_;
// Private Member Functions
//- Check that the table is valid
void checkTable() const;
//- Disallow default bitwise assignment
void operator=(const uniformInterpolationTable&);
public:
// Constructors
//- Construct from IOobject and readFields flag. Creates a null object
// if readFields = false
uniformInterpolationTable(const IOobject& io, const bool readFields);
//- Construct from name, objectRegistry and dictionary.
// If initialiseOnly flag is set, control parameters are read from
// the dictionary, but not the data table
uniformInterpolationTable
(
const word& tableName,
const objectRegistry& db,
const dictionary& dict,
const bool initialiseOnly = false
);
//- Construct as copy
uniformInterpolationTable(const uniformInterpolationTable& uit);
//- Destructor
~uniformInterpolationTable();
// Member Functions
// Access
//- Return the lower limit
inline scalar x0() const;
//- Return the fixed interval
inline scalar dx() const;
//- Return the log10(x) flag
inline const Switch& log10() const;
//- Return the bound flag
inline const Switch& bound() const;
// Edit
//- Return the lower limit
inline scalar& x0();
//- Return the fixed interval
inline scalar& dx();
//- Return the log10(x) flag
inline Switch& log10();
//- Return the bound flag
inline Switch& bound();
// Evaluation
//- Return the minimum x value
inline scalar xMin() const;
//- Return the maximum x value
inline scalar xMax() const;
//- Interpolate
Type interpolate(scalar x) const;
//- Interpolate - takes log10 flag into account
Type interpolateLog10(scalar x) const;
// Override ancestor size() function and [] operator
//- Return the size of the table
label size() const
{
return List<Type>::size();
}
//- Use List[] operator for read access
Type operator[](label x) const
{
return List<Type>::operator[](x);
}
//- Use List[] operator for write access
Type& operator[](label x)
{
return List<Type>::operator[](x);
}
// I-O
//- Write
void write() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "uniformInterpolationTableI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "uniformInterpolationTable.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -22,27 +22,75 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Prints out a description of the streams
\*---------------------------------------------------------------------------*/
#include "IPstream.H"
#include "OPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::IPstream::print(Ostream& os) const
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::x0() const
{
os << "Reading from processor " << fromProcNo_
<< " to processor " << myProcNo() << Foam::endl;
return x0_;
}
void Foam::OPstream::print(Ostream& os) const
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::dx() const
{
os << "Writing from processor " << toProcNo_
<< " to processor " << myProcNo() << Foam::endl;
return dx_;
}
template <class Type>
const Foam::Switch& Foam::uniformInterpolationTable<Type>::log10() const
{
return log10_;
}
template <class Type>
const Foam::Switch& Foam::uniformInterpolationTable<Type>::bound() const
{
return bound_;
}
template <class Type>
Foam::scalar& Foam::uniformInterpolationTable<Type>::x0()
{
return x0_;
}
template <class Type>
Foam::scalar& Foam::uniformInterpolationTable<Type>::dx()
{
return dx_;
}
template <class Type>
Foam::Switch& Foam::uniformInterpolationTable<Type>::log10()
{
return log10_;
}
template <class Type>
Foam::Switch& Foam::uniformInterpolationTable<Type>::bound()
{
return bound_;
}
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::xMin() const
{
return x0_;
}
template <class Type>
Foam::scalar Foam::uniformInterpolationTable<Type>::xMax() const
{
return x0_ + dx_*(size() - 1);
}

View File

@ -32,7 +32,20 @@ template<class Type>
Foam::simpleMatrix<Type>::simpleMatrix(const label mSize)
:
scalarSquareMatrix(mSize),
source_(mSize, pTraits<Type>::zero)
source_(mSize)
{}
template<class Type>
Foam::simpleMatrix<Type>::simpleMatrix
(
const label mSize,
const scalar coeffVal,
const Type& sourceVal
)
:
scalarSquareMatrix(mSize, mSize, coeffVal),
source_(mSize, sourceVal)
{}
@ -148,7 +161,11 @@ Foam::simpleMatrix<Type> Foam::operator-
template<class Type>
Foam::simpleMatrix<Type> Foam::operator*(const scalar s, const simpleMatrix<Type>& m)
Foam::simpleMatrix<Type> Foam::operator*
(
const scalar s,
const simpleMatrix<Type>& m
)
{
return simpleMatrix<Type>(s*m.matrix_, s*m.source_);
}
@ -157,7 +174,11 @@ Foam::simpleMatrix<Type> Foam::operator*(const scalar s, const simpleMatrix<Type
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Type>
Foam::Ostream& Foam::operator<<(Ostream& os, const simpleMatrix<Type>& m)
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const simpleMatrix<Type>& m
)
{
os << static_cast<const scalarSquareMatrix&>(m) << nl << m.source_;
return os;

View File

@ -26,7 +26,7 @@ Class
Foam::simpleMatrix
Description
Foam::simpleMatrix
A simple square matrix solver with scalar coefficients.
SourceFiles
simpleMatrix.C
@ -75,8 +75,12 @@ public:
// Constructors
//- Construct given size
// Note: this does not initialise the coefficients or the source.
simpleMatrix(const label);
//- Construct given size and initial values for coefficients and source
simpleMatrix(const label, const scalar, const Type&);
//- Construct from components
simpleMatrix(const scalarSquareMatrix&, const Field<Type>&);
@ -91,11 +95,13 @@ public:
// Access
//- Return access to the source
Field<Type>& source()
{
return source_;
}
//- Return const-access to the source
const Field<Type>& source() const
{
return source_;

View File

@ -60,6 +60,7 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
)
),
cache_(ITstream("cache", tokenList())()),
caching_(false),
relaxationFactors_(ITstream("relaxationFactors", tokenList())()),
defaultRelaxationFactor_(0),
solvers_(ITstream("solvers", tokenList())())
@ -150,12 +151,19 @@ Foam::label Foam::solution::upgradeSolverDict
bool Foam::solution::cache(const word& name) const
{
if (debug)
if (caching_)
{
Info<< "Find cache entry for " << name << endl;
}
if (debug)
{
Info<< "Cache: find entry for " << name << endl;
}
return cache_.found(name);
return cache_.found(name);
}
else
{
return false;
}
}
@ -248,6 +256,7 @@ bool Foam::solution::read()
if (dict.found("cache"))
{
cache_ = dict.subDict("cache");
caching_ = cache_.lookupOrDefault<Switch>("active", true);
}
if (dict.found("relaxationFactors"))

View File

@ -37,6 +37,7 @@ SourceFiles
#define solution_H
#include "IOdictionary.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -56,6 +57,9 @@ class solution
//- Dictionary of temporary fields to cache
dictionary cache_;
//- Switch for the caching mechanism
Switch caching_;
//- Dictionary of relaxation factors for all the fields
dictionary relaxationFactors_;

View File

@ -22,8 +22,6 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "tetCell.H"
@ -44,7 +42,7 @@ Foam::cellShape Foam::tetCell::tetCellShape() const
const cellModel& tet = *tetModelPtr_;
return cellShape(tet, *this);
return cellShape(tet, labelList(*this));
}

View File

@ -229,11 +229,7 @@ void processorPointPatch::initPatchPatchPoints()
// Send the patchPatchPoints to the neighbouring processor
OPstream toNeighbProc
(
Pstream::blocking,
neighbProcNo()
);
OPstream toNeighbProc(Pstream::blocking, neighbProcNo());
toNeighbProc
<< ppmp.size() // number of points for checking
@ -252,11 +248,7 @@ void processorPointPatch::initPatchPatchPoints()
void Foam::processorPointPatch::calcPatchPatchPoints()
{
// Get the patchPatchPoints from the neighbouring processor
IPstream fromNeighbProc
(
Pstream::blocking,
neighbProcNo()
);
IPstream fromNeighbProc(Pstream::blocking, neighbProcNo());
label nbrNPoints(readLabel(fromNeighbProc));
labelListList patchPatchPoints(fromNeighbProc);

View File

@ -30,7 +30,7 @@ License
Foam::globalIndex::globalIndex(const label localSize)
:
offsets_(Pstream::nProcs())
offsets_(Pstream::nProcs()+1)
{
labelList localSizes(Pstream::nProcs());
localSizes[Pstream::myProcNo()] = localSize;
@ -38,7 +38,8 @@ Foam::globalIndex::globalIndex(const label localSize)
Pstream::scatterList(localSizes); // just to balance out comms
label offset = 0;
forAll(offsets_, procI)
offsets_[0] = 0;
for (label procI = 0; procI < Pstream::nProcs(); procI++)
{
label oldOffset = offset;
offset += localSizes[procI];
@ -51,7 +52,7 @@ Foam::globalIndex::globalIndex(const label localSize)
<< "). Please recompile with larger datatype for label."
<< exit(FatalError);
}
offsets_[procI] = offset;
offsets_[procI+1] = offset;
}
}

View File

@ -64,7 +64,7 @@ class globalIndex
{
// Private data
//- Start off procI+1. (so like CompactListList)
//- Start of procI. Size is nProcs()+1. (so like CompactListList)
labelList offsets_;
@ -81,10 +81,6 @@ public:
// Member Functions
////- Start of procI+1 data
//inline const labelList& offsets() const;
// Queries relating to my processor
//- my local size

View File

@ -28,26 +28,15 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//inline const Foam::labelList& Foam::globalIndex::offsets() const
//{
// return offsets_;
//}
inline Foam::label Foam::globalIndex::offset(const label procI) const
{
return (procI == 0 ? 0 : offsets_[procI-1]);
return offsets_[procI];
}
inline Foam::label Foam::globalIndex::localSize(const label procI) const
{
return
(
procI == 0
? offsets_[procI]
: offsets_[procI] - offsets_[procI-1]
);
return offsets_[procI+1] - offsets_[procI];
}
@ -59,7 +48,7 @@ inline Foam::label Foam::globalIndex::localSize() const
inline Foam::label Foam::globalIndex::size() const
{
return offsets_[Pstream::nProcs()-1];
return offsets_[Pstream::nProcs()];
}
@ -69,7 +58,7 @@ inline Foam::label Foam::globalIndex::toGlobal
const label i
) const
{
return(procI == 0 ? i : i + offsets_[procI-1]);
return i + offsets_[procI];
}
@ -82,9 +71,7 @@ inline Foam::label Foam::globalIndex::toGlobal(const label i) const
//- Is on local processor
inline bool Foam::globalIndex::isLocal(const label procI, const label i) const
{
return
(i < offsets_[procI])
&& (i >= (procI == 0 ? 0 : offsets_[procI-1]));
return i >= offsets_[procI] && i < offsets_[procI+1];
}
@ -97,9 +84,9 @@ inline bool Foam::globalIndex::isLocal(const label i) const
inline Foam::label Foam::globalIndex::toLocal(const label procI, const label i)
const
{
label localI = (procI == 0 ? i : i - offsets_[procI-1]);
label localI = i - offsets_[procI];
if (localI < 0 || i >= offsets_[procI])
if (localI < 0 || i >= offsets_[procI+1])
{
FatalErrorIn("globalIndex::toLocal(const label, const label)")
<< "Global " << i << " does not belong on processor "
@ -118,9 +105,7 @@ inline Foam::label Foam::globalIndex::toLocal(const label i) const
inline Foam::label Foam::globalIndex::whichProcID(const label i) const
{
label index = findLower(offsets_, i+1);
if (index == Pstream::nProcs()-1)
if (i < 0 || i >= offsets_[Pstream::nProcs()])
{
FatalErrorIn("globalIndex::whichProcID(const label)")
<< "Global " << i << " does not belong on any processor."
@ -128,7 +113,7 @@ inline Foam::label Foam::globalIndex::whichProcID(const label i) const
<< abort(FatalError);
}
return index+1;
return findLower(offsets_, i+1);
}

View File

@ -27,7 +27,7 @@ License
#include "mapDistribute.H"
#include "commSchedule.H"
#include "HashSet.H"
#include "ListOps.H"
#include "globalIndex.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -124,7 +124,7 @@ Foam::List<Foam::labelPair> Foam::mapDistribute::schedule
);
// Processors involved in my schedule
return UIndirectList<labelPair>(allComms, mySchedule);
return List<labelPair>(UIndirectList<labelPair>(allComms, mySchedule));
//if (debug)
@ -257,6 +257,304 @@ Foam::mapDistribute::mapDistribute
}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelList& elements,
List<Map<label> >& compactMap
)
:
constructSize_(0),
schedulePtr_()
{
// 1. Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since
// these are always all needed.
compactMap.setSize(Pstream::nProcs());
{
// Count all (non-local) elements needed. Just for presizing map.
labelList nNonLocal(Pstream::nProcs(), 0);
forAll(elements, i)
{
label globalIndex = elements[i];
if (!globalNumbering.isLocal(globalIndex))
{
label procI = globalNumbering.whichProcID(globalIndex);
nNonLocal[procI]++;
}
}
forAll(compactMap, procI)
{
if (procI != Pstream::myProcNo())
{
compactMap[procI].resize(2*nNonLocal[procI]);
}
}
// Collect all (non-local) elements needed.
forAll(elements, i)
{
label globalIndex = elements[i];
if (!globalNumbering.isLocal(globalIndex))
{
label procI = globalNumbering.whichProcID(globalIndex);
label index = globalNumbering.toLocal(procI, globalIndex);
label nCompact = compactMap[procI].size();
compactMap[procI].insert(index, nCompact);
}
}
//// Sort remote elements needed (not really necessary)
//forAll(compactMap, procI)
//{
// if (procI != Pstream::myProcNo())
// {
// Map<label>& globalMap = compactMap[procI];
//
// SortableList<label> sorted(globalMap.toc().xfer());
//
// forAll(sorted, i)
// {
// Map<label>::iterator iter = globalMap.find(sorted[i]);
// iter() = i;
// }
// }
//}
}
// 2. The overall compact addressing is
// - myProcNo data first (uncompacted)
// - all other processors consecutively
labelList compactStart(Pstream::nProcs());
compactStart[Pstream::myProcNo()] = 0;
constructSize_ = globalNumbering.localSize();
forAll(compactStart, procI)
{
if (procI != Pstream::myProcNo())
{
compactStart[procI] = constructSize_;
constructSize_ += compactMap[procI].size();
}
}
// 3. Find out what to receive/send in compact addressing.
// What I want to receive is what others have to send
labelListList wantedRemoteElements(Pstream::nProcs());
// Compact addressing for received data
constructMap_.setSize(Pstream::nProcs());
forAll(compactMap, procI)
{
if (procI == Pstream::myProcNo())
{
// All my own elements are used
label nLocal = globalNumbering.localSize();
wantedRemoteElements[procI] = identity(nLocal);
constructMap_[procI] = identity(nLocal);
}
else
{
// Remote elements wanted from processor procI
labelList& remoteElem = wantedRemoteElements[procI];
labelList& localElem = constructMap_[procI];
remoteElem.setSize(compactMap[procI].size());
localElem.setSize(compactMap[procI].size());
label i = 0;
forAllIter(Map<label>, compactMap[procI], iter)
{
remoteElem[i] = iter.key();
label compactI = compactStart[procI]+iter();
localElem[i] = compactI;
iter() = compactI;
i++;
}
}
}
subMap_.setSize(Pstream::nProcs());
labelListList sendSizes;
Pstream::exchange<labelList, label>
(
wantedRemoteElements,
subMap_,
sendSizes
);
// Renumber elements
forAll(elements, i)
{
elements[i] = renumber(globalNumbering, compactMap, elements[i]);
}
}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelListList& cellCells,
List<Map<label> >& compactMap
)
:
constructSize_(0),
schedulePtr_()
{
// 1. Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since
// these are always all needed.
compactMap.setSize(Pstream::nProcs());
{
// Count all (non-local) elements needed. Just for presizing map.
labelList nNonLocal(Pstream::nProcs(), 0);
forAll(cellCells, cellI)
{
const labelList& cCells = cellCells[cellI];
forAll(cCells, i)
{
label globalIndex = cCells[i];
if (!globalNumbering.isLocal(globalIndex))
{
label procI = globalNumbering.whichProcID(globalIndex);
nNonLocal[procI]++;
}
}
}
forAll(compactMap, procI)
{
if (procI != Pstream::myProcNo())
{
compactMap[procI].resize(2*nNonLocal[procI]);
}
}
// Collect all (non-local) elements needed.
// Collect all (non-local) elements needed.
forAll(cellCells, cellI)
{
const labelList& cCells = cellCells[cellI];
forAll(cCells, i)
{
label globalIndex = cCells[i];
if (!globalNumbering.isLocal(globalIndex))
{
label procI = globalNumbering.whichProcID(globalIndex);
label index = globalNumbering.toLocal(procI, globalIndex);
label nCompact = compactMap[procI].size();
compactMap[procI].insert(index, nCompact);
}
}
}
//// Sort remote elements needed (not really necessary)
//forAll(compactMap, procI)
//{
// if (procI != Pstream::myProcNo())
// {
// Map<label>& globalMap = compactMap[procI];
//
// SortableList<label> sorted(globalMap.toc().xfer());
//
// forAll(sorted, i)
// {
// Map<label>::iterator iter = globalMap.find(sorted[i]);
// iter() = i;
// }
// }
//}
}
// 2. The overall compact addressing is
// - myProcNo data first (uncompacted)
// - all other processors consecutively
labelList compactStart(Pstream::nProcs());
compactStart[Pstream::myProcNo()] = 0;
constructSize_ = globalNumbering.localSize();
forAll(compactStart, procI)
{
if (procI != Pstream::myProcNo())
{
compactStart[procI] = constructSize_;
constructSize_ += compactMap[procI].size();
}
}
// 3. Find out what to receive/send in compact addressing.
// What I want to receive is what others have to send
labelListList wantedRemoteElements(Pstream::nProcs());
// Compact addressing for received data
constructMap_.setSize(Pstream::nProcs());
forAll(compactMap, procI)
{
if (procI == Pstream::myProcNo())
{
// All my own elements are used
label nLocal = globalNumbering.localSize();
wantedRemoteElements[procI] = identity(nLocal);
constructMap_[procI] = identity(nLocal);
}
else
{
// Remote elements wanted from processor procI
labelList& remoteElem = wantedRemoteElements[procI];
labelList& localElem = constructMap_[procI];
remoteElem.setSize(compactMap[procI].size());
localElem.setSize(compactMap[procI].size());
label i = 0;
forAllIter(Map<label>, compactMap[procI], iter)
{
remoteElem[i] = iter.key();
label compactI = compactStart[procI]+iter();
localElem[i] = compactI;
iter() = compactI;
i++;
}
}
}
subMap_.setSize(Pstream::nProcs());
labelListList sendSizes;
Pstream::exchange<labelList, label>
(
wantedRemoteElements,
subMap_,
sendSizes
);
// Renumber elements
forAll(cellCells, cellI)
{
labelList& cCells = cellCells[cellI];
forAll(cCells, i)
{
cCells[i] = renumber(globalNumbering, compactMap, cCells[i]);
}
}
}
Foam::mapDistribute::mapDistribute(const mapDistribute& map)
:
constructSize_(map.constructSize_),
@ -266,7 +564,27 @@ Foam::mapDistribute::mapDistribute(const mapDistribute& map)
{}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::label Foam::mapDistribute::renumber
(
const globalIndex& globalNumbering,
const List<Map<label> >& compactMap,
const label globalI
)
{
if (globalNumbering.isLocal(globalI))
{
return globalNumbering.toLocal(globalI);
}
else
{
label procI = globalNumbering.whichProcID(globalI);
label index = globalNumbering.toLocal(procI, globalI);
return compactMap[procI][index];
}
}
void Foam::mapDistribute::compact(const boolList& elemIsUsed)
{

View File

@ -39,6 +39,16 @@ Note:
Note2: number of items send on one processor have to equal the number
of items received on the other processor.
Constructors using compact numbering: all my own elements first
(whether used or not) followed by used-only remote elements.
So e.g 4 procs and on proc 1 the compact
table will first have all globalIndex.localSize() elements from proc1
followed by used-only elements of proc0, proc2, proc3.
The constructed mapDistribute sends the local elements from and
receives the remote elements into their compact position.
compactMap[procI] is the position of elements from procI in the compact
map. compactMap[myProcNo()] is empty since trivial addressing. The indices
into compactMap[procI] are local, not global, indices.
SourceFiles
mapDistribute.C
@ -52,6 +62,7 @@ SourceFiles
#include "labelPair.H"
#include "Pstream.H"
#include "boolList.H"
#include "Map.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -59,6 +70,7 @@ namespace Foam
{
class mapPolyMesh;
class globalIndex;
/*---------------------------------------------------------------------------*\
Class mapDistribute Declaration
@ -83,28 +95,6 @@ class mapDistribute
public:
// Public classes
//- combineReduce operator for lists. Used for counting.
class listEq
{
public:
template<class T>
void operator()(T& x, const T& y) const
{
forAll(y, i)
{
if (y[i].size())
{
x[i] = y[i];
}
}
}
};
// Constructors
//- Construct from components
@ -123,6 +113,27 @@ public:
const labelList& recvProcs
);
//- Construct from list of (possibly) remote elements in globalIndex
// numbering. Determines compact numbering (see above) and
// distribute map to get data into this ordering and renumbers the
// elements to be in compact numbering.
mapDistribute
(
const globalIndex&,
labelList& elements,
List<Map<label> >& compactMap
);
//- Special variant that works with the into sorted into bins
// according to local indices. E.g. think cellCells where
// cellCells[localCellI] is a list of global cells
mapDistribute
(
const globalIndex&,
labelListList& cellCells,
List<Map<label> >& compactMap
);
//- Construct copy
mapDistribute(const mapDistribute&);
@ -180,6 +191,15 @@ public:
// Other
//- Helper for construct from globalIndex. Renumbers element
// (in globalIndex numbering) into compact indices.
static label renumber
(
const globalIndex&,
const List<Map<label> >& compactMap,
const label globalElement
);
//- Compact maps. Gets per field a bool whether it is used (locally)
// and works out itself what this side and sender side can remove
// from maps.

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#include "PstreamBuffers.H"
#include "PstreamCombineReduceOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -185,17 +186,9 @@ void Foam::mapDistribute::distribute
{
if (!contiguous<T>())
{
// 1. convert to contiguous buffer
// 2. send buffer
// 3. receive buffer
// 4. read from buffer into List<T>
PstreamBuffers pBuffs(Pstream::nonBlocking);
List<List<char> > sendFields(Pstream::nProcs());
labelListList allNTrans(Pstream::nProcs());
labelList& nsTransPs = allNTrans[Pstream::myProcNo()];
nsTransPs.setSize(Pstream::nProcs(), 0);
// Stream data into sendField buffers
// Stream data into buffer
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& map = subMap[domain];
@ -203,66 +196,13 @@ void Foam::mapDistribute::distribute
if (domain != Pstream::myProcNo() && map.size())
{
// Put data into send buffer
OPstream toDomain(Pstream::nonBlocking, domain);
UOPstream toDomain(domain, pBuffs);
toDomain << UIndirectList<T>(field, map);
// Store the size
nsTransPs[domain] = toDomain.bufPosition();
// Transfer buffer out
sendFields[domain].transfer(toDomain.buf());
toDomain.bufPosition() = 0;
}
}
// Send sizes across
combineReduce(allNTrans, listEq());
// Start sending buffers
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& map = subMap[domain];
if (domain != Pstream::myProcNo() && map.size())
{
OPstream::write
(
Pstream::nonBlocking,
domain,
reinterpret_cast<const char*>
(
sendFields[domain].begin()
),
nsTransPs[domain]
);
}
}
// Set up receives from neighbours
PtrList<IPstream> fromSlave(Pstream::nProcs());
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& map = constructMap[domain];
if (domain != Pstream::myProcNo() && map.size())
{
// Start receiving
fromSlave.set
(
domain,
new IPstream
(
Pstream::nonBlocking,
domain,
allNTrans[domain][Pstream::myProcNo()]
)
);
}
}
// Start receiving
pBuffs.finishedSends();
{
// Set up 'send' to myself
@ -285,10 +225,6 @@ void Foam::mapDistribute::distribute
}
}
// Wait till all finished
Pstream::waitRequests();
// Consume
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
@ -296,7 +232,8 @@ void Foam::mapDistribute::distribute
if (domain != Pstream::myProcNo() && map.size())
{
List<T> recvField(fromSlave[domain]);
UIPstream str(domain, pBuffs);
List<T> recvField(str);
if (recvField.size() != map.size())
{
@ -322,9 +259,6 @@ void Foam::mapDistribute::distribute
{
field[map[i]] = recvField[i];
}
// Delete receive buffer
fromSlave.set(domain, NULL);
}
}
}
@ -618,17 +552,10 @@ void Foam::mapDistribute::distribute
{
if (!contiguous<T>())
{
// 1. convert to contiguous buffer
// 2. send buffer
// 3. receive buffer
// 4. read from buffer into List<T>
//XXXXXX
PstreamBuffers pBuffs(Pstream::nonBlocking);
List<List<char> > sendFields(Pstream::nProcs());
labelListList allNTrans(Pstream::nProcs());
labelList& nsTransPs = allNTrans[Pstream::myProcNo()];
nsTransPs.setSize(Pstream::nProcs());
// Stream data into sendField buffers
// Stream data into buffer
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& map = subMap[domain];
@ -636,65 +563,13 @@ void Foam::mapDistribute::distribute
if (domain != Pstream::myProcNo() && map.size())
{
// Put data into send buffer
OPstream toDomain(Pstream::nonBlocking, domain);
UOPstream toDomain(domain, pBuffs);
toDomain << UIndirectList<T>(field, map);
// Store the size
nsTransPs[domain] = toDomain.bufPosition();
// Transfer buffer out
sendFields[domain].transfer(toDomain.buf());
toDomain.bufPosition() = 0;
}
}
// Send sizes across
combineReduce(allNTrans, listEq());
// Start sending buffers
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& map = subMap[domain];
if (domain != Pstream::myProcNo() && map.size())
{
OPstream::write
(
Pstream::nonBlocking,
domain,
reinterpret_cast<const char*>
(
sendFields[domain].begin()
),
nsTransPs[domain]
);
}
}
// Set up receives from neighbours
PtrList<IPstream> fromSlave(Pstream::nProcs());
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
const labelList& map = constructMap[domain];
if (domain != Pstream::myProcNo() && map.size())
{
// Start receiving
fromSlave.set
(
domain,
new IPstream
(
Pstream::nonBlocking,
domain,
allNTrans[domain][Pstream::myProcNo()]
)
);
}
}
// Start receiving
pBuffs.finishedSends();
{
// Set up 'send' to myself
@ -715,7 +590,7 @@ void Foam::mapDistribute::distribute
// Wait till all finished
Pstream::waitRequests();
UPstream::waitRequests();
// Consume
for (label domain = 0; domain < Pstream::nProcs(); domain++)
@ -724,7 +599,8 @@ void Foam::mapDistribute::distribute
if (domain != Pstream::myProcNo() && map.size())
{
List<T> recvField(fromSlave[domain]);
UIPstream str(domain, pBuffs);
List<T> recvField(str);
if (recvField.size() != map.size())
{
@ -750,9 +626,6 @@ void Foam::mapDistribute::distribute
{
cop(field[map[i]], recvField[i]);
}
// Delete receive buffer
fromSlave.set(domain, NULL);
}
}
}
@ -796,7 +669,7 @@ void Foam::mapDistribute::distribute
if (domain != Pstream::myProcNo() && map.size())
{
recvFields[domain].setSize(map.size());
IPstream::read
UIPstream::read
(
Pstream::nonBlocking,
domain,

View File

@ -402,11 +402,7 @@ void Foam::syncTools::syncPointMap
{
// Send to master
{
OPstream toMaster
(
Pstream::blocking,
Pstream::masterNo()
);
OPstream toMaster(Pstream::blocking, Pstream::masterNo());
toMaster << sharedPointValues;
}
// Receive merged values

View File

@ -76,7 +76,7 @@ public:
{}
//- Construct from components
objectHit(const bool success, const label& obj)
objectHit(const bool success, const label obj)
:
hit_(success),
hitObject_(obj)
@ -111,7 +111,7 @@ public:
{
return ((a.hit_ == b.hit_) && (a.hitObject_ == b.hitObject_));
}
friend bool operator!=(const objectHit& a, const objectHit& b)
{
return (!(a == b));

View File

@ -107,7 +107,7 @@ public:
//- Incrementally hash a label.
// This will necessarily return a different value than the
// non-incremental version.
unsigned operator()(const label& p, unsigned seed) const
unsigned operator()(const label p, unsigned seed) const
{
return Hasher(&p, sizeof(label), seed);
}
@ -115,11 +115,10 @@ public:
//- Return the unsigned representation of a label.
// This helps if people have relied on the hash value corresponding to
// the natural order.
unsigned operator()(const label& p) const
unsigned operator()(const label p) const
{
return p;
}
};

View File

@ -47,8 +47,7 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// construct given seed
Random::Random(const label& seed)
Random::Random(const label seed)
{
if (seed > 1)
{

View File

@ -61,7 +61,7 @@ public:
// Constructors
//- Construct given seed
Random(const label&);
Random(const label);
// Member functions
@ -70,14 +70,19 @@ public:
//- scalar [0..1] (so including 0,1)
scalar scalar01();
//- vector with every component scalar01
vector vector01();
//- sphericalTensor with every component scalar01
sphericalTensor sphericalTensor01();
//- symmTensor with every component scalar01
symmTensor symmTensor01();
//- tensor with every component scalar01
tensor tensor01();
//- label [lower..upper]
label integer(const label lower, const label upper);

View File

@ -1,5 +1,5 @@
Pstream.C
IPread.C
OPwrite.C
UPstream.C
UIPread.C
UOPwrite.C
LIB = $(FOAM_LIBBIN)/dummy/libPstream

View File

@ -23,62 +23,66 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Read token and binary block from IPstream
Read from UIPstream
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "UIPstream.H"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
Foam::IPstream::IPstream
Foam::UIPstream::UIPstream
(
const commsTypes commsType,
const int fromProcNo,
const label bufSize,
DynamicList<char>& externalBuf,
const int tag,
streamFormat format,
versionNumber version
)
:
Pstream(commsType, bufSize),
UPstream(commsType),
Istream(format, version),
fromProcNo_(fromProcNo),
externalBuf_(externalBuf),
externalBufPosition_(0),
tag_(tag),
messageSize_(0)
{
notImplemented
(
"IPsream::IPstream"
"("
"const commsTypes,"
"const int fromProcNo,"
"const label bufSize,"
"streamFormat, versionNumber"
")"
);
notImplemented
(
"UIPstream::UIPstream"
"("
"const commsTypes,"
"const int fromProcNo,"
"DynamicList<char>&,"
"const int tag,"
"streamFormat, versionNumber"
")"
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int Foam::IPstream::read
Foam::label Foam::UIPstream::read
(
const commsTypes commsType,
const int fromProcNo,
char* buf,
const std::streamsize bufSize
const std::streamsize bufSize,
const int tag
)
{
notImplemented
(
"IPstream::read"
"UIPstream::read"
"("
"const commsTypes,"
"const int fromProcNo,"
"char* buf,"
"const label bufSize"
"const label bufSize,"
"const int tag"
")"
);

View File

@ -27,41 +27,32 @@ Description
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "OPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::OPstream::~OPstream()
{
notImplemented("OPstream::~OPstream()");
}
#include "UOPstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::OPstream::write
bool Foam::UOPstream::write
(
const commsTypes commsType,
const int toProcNo,
const char* buf,
const std::streamsize bufSize
const std::streamsize bufSize,
const int tag
)
{
notImplemented
(
"IPstream::write"
"("
"const commsTypes commsType,"
"const int fromProcNo,"
"char* buf,"
"const label bufSize"
")"
);
notImplemented
(
"UOPstream::write"
"("
"const commsTypes commsType,"
"const int fromProcNo,"
"char* buf,"
"const label bufSize,"
"const int tag"
")"
);
return false;
return false;
}

View File

@ -24,20 +24,18 @@ License
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#include "UPstream.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::Pstream::addValidParOptions(HashTable<string>& validParOptions)
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
{}
bool Foam::Pstream::init(int& argc, char**& argv)
bool Foam::UPstream::init(int& argc, char**& argv)
{
FatalErrorIn("Pstream::init(int& argc, char**& argv)")
FatalErrorIn("UPstream::init(int& argc, char**& argv)")
<< "Trying to use the dummy Pstream library." << nl
<< "This dummy library cannot be used in parallel mode"
<< Foam::exit(FatalError);
@ -46,15 +44,15 @@ bool Foam::Pstream::init(int& argc, char**& argv)
}
void Foam::Pstream::exit(int errnum)
void Foam::UPstream::exit(int errnum)
{
notImplemented("Pstream::exit(int errnum)");
notImplemented("UPstream::exit(int errnum)");
}
void Foam::Pstream::abort()
void Foam::UPstream::abort()
{
notImplemented("Pstream::abort()");
notImplemented("UPstream::abort()");
}
@ -63,13 +61,13 @@ void Foam::reduce(scalar&, const sumOp<scalar>&)
void Foam::Pstream::waitRequests()
void Foam::UPstream::waitRequests()
{}
bool Foam::Pstream::finishedRequest(const label i)
bool Foam::UPstream::finishedRequest(const label i)
{
notImplemented("Pstream::finishedRequest()");
notImplemented("UPstream::finishedRequest()");
return false;
}

View File

@ -1,6 +1,6 @@
OPwrite.C
IPread.C
Pstream.C
UOPwrite.C
UIPread.C
UPstream.C
PstreamGlobals.C
LIB = $(FOAM_MPI_LIBBIN)/libPstream

View File

@ -23,91 +23,161 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Read token and binary block from IPstream
Read from UIPstream
\*---------------------------------------------------------------------------*/
#include "mpi.h"
#include "IPstream.H"
#include "UIPstream.H"
#include "PstreamGlobals.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Outstanding non-blocking operations.
//! @cond fileScope
//Foam::DynamicList<MPI_Request> IPstream_outstandingRequests_;
//! @endcond fileScope
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
Foam::IPstream::IPstream
Foam::UIPstream::UIPstream
(
const commsTypes commsType,
const int fromProcNo,
const label bufSize,
DynamicList<char>& externalBuf,
const int tag,
streamFormat format,
versionNumber version
)
:
Pstream(commsType, bufSize),
UPstream(commsType),
Istream(format, version),
fromProcNo_(fromProcNo),
externalBuf_(externalBuf),
externalBufPosition_(0),
tag_(tag),
messageSize_(0)
{
setOpened();
setGood();
MPI_Status status;
// Cannot use buf_.size() since appends a few bytes extra
label realBufSize = bufSize;
// If the buffer size is not specified, probe the incomming message
// and set it
if (!bufSize)
if (commsType == UPstream::nonBlocking)
{
if (commsType == nonBlocking)
// Message is already received into externalBuf
}
else
{
MPI_Status status;
label wantedSize = externalBuf_.capacity();
// If the buffer size is not specified, probe the incomming message
// and set it
if (!wantedSize)
{
MPI_Probe(procID(fromProcNo_), tag_, MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
externalBuf_.setCapacity(messageSize_);
wantedSize = messageSize_;
}
messageSize_ = UIPstream::read
(
commsType,
fromProcNo_,
externalBuf_.begin(),
wantedSize,
tag_
);
// Set addressed size. Leave actual allocated memory intact.
externalBuf_.setSize(messageSize_);
if (!messageSize_)
{
FatalErrorIn
(
"IPstream::IPstream(const commsTypes, const int, "
"const label, streamFormat, versionNumber)"
) << "Can use nonBlocking mode only with pre-allocated buffers"
"UIPstream::UIPstream(const commsTypes, const int, "
"DynamicList<char>&, streamFormat, versionNumber)"
) << "read failed"
<< Foam::abort(FatalError);
}
}
}
MPI_Probe(procID(fromProcNo_), msgType(), MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
buf_.setSize(messageSize_);
realBufSize = buf_.size();
Foam::UIPstream::UIPstream(const int fromProcNo, PstreamBuffers& buffers)
:
UPstream(buffers.commsType_),
Istream(buffers.format_, buffers.version_),
fromProcNo_(fromProcNo),
externalBuf_(buffers.recvBuf_[fromProcNo]),
externalBufPosition_(0),
tag_(buffers.tag_),
messageSize_(0)
{
if (commsType() != UPstream::scheduled && !buffers.finishedSendsCalled_)
{
FatalErrorIn("UIPstream::UIPstream(const int, PstreamBuffers&)")
<< "PstreamBuffers::finishedSends() never called." << endl
<< "Please call PstreamBuffers::finishedSends() after doing"
<< " all your sends (using UOPstream) and before doing any"
<< " receives (using UIPstream)" << Foam::exit(FatalError);
}
messageSize_ = read(commsType, fromProcNo_, buf_.begin(), realBufSize);
setOpened();
setGood();
if (!messageSize_)
if (commsType() == UPstream::nonBlocking)
{
FatalErrorIn
// Message is already received into externalBuf
}
else
{
MPI_Status status;
label wantedSize = externalBuf_.capacity();
// If the buffer size is not specified, probe the incomming message
// and set it
if (!wantedSize)
{
MPI_Probe(procID(fromProcNo_), tag_, MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_BYTE, &messageSize_);
externalBuf_.setCapacity(messageSize_);
wantedSize = messageSize_;
}
messageSize_ = UIPstream::read
(
"IPstream::IPstream(const commsTypes, const int, "
"const label, streamFormat, versionNumber)"
) << "read failed"
<< Foam::abort(FatalError);
commsType(),
fromProcNo_,
externalBuf_.begin(),
wantedSize,
tag_
);
// Set addressed size. Leave actual allocated memory intact.
externalBuf_.setSize(messageSize_);
if (!messageSize_)
{
FatalErrorIn
(
"UIPstream::UIPstream(const int, PstreamBuffers&)"
) << "read failed"
<< Foam::abort(FatalError);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::IPstream::read
Foam::label Foam::UIPstream::read
(
const commsTypes commsType,
const int fromProcNo,
char* buf,
const std::streamsize bufSize
const std::streamsize bufSize,
const int tag
)
{
if (commsType == blocking || commsType == scheduled)
@ -122,7 +192,7 @@ Foam::label Foam::IPstream::read
bufSize,
MPI_PACKED,
procID(fromProcNo),
msgType(),
tag,
MPI_COMM_WORLD,
&status
)
@ -130,7 +200,7 @@ Foam::label Foam::IPstream::read
{
FatalErrorIn
(
"IPstream::read"
"UIPstream::read"
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
) << "MPI_Recv cannot receive incomming message"
<< Foam::abort(FatalError);
@ -148,7 +218,7 @@ Foam::label Foam::IPstream::read
{
FatalErrorIn
(
"IPstream::read"
"UIPstream::read"
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
) << "buffer (" << label(bufSize)
<< ") not large enough for incomming message ("
@ -170,7 +240,7 @@ Foam::label Foam::IPstream::read
bufSize,
MPI_PACKED,
procID(fromProcNo),
msgType(),
tag,
MPI_COMM_WORLD,
&request
)
@ -178,7 +248,7 @@ Foam::label Foam::IPstream::read
{
FatalErrorIn
(
"IPstream::read"
"UIPstream::read"
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
) << "MPI_Recv cannot start non-blocking receive"
<< Foam::abort(FatalError);
@ -195,7 +265,7 @@ Foam::label Foam::IPstream::read
{
FatalErrorIn
(
"IPstream::read"
"UIPstream::read"
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
) << "Unsupported communications type " << commsType
<< Foam::abort(FatalError);
@ -205,6 +275,4 @@ Foam::label Foam::IPstream::read
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -29,54 +29,18 @@ Description
#include "mpi.h"
#include "OPstream.H"
#include "UOPstream.H"
#include "PstreamGlobals.H"
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::OPstream::~OPstream()
{
if (commsType_ == nonBlocking)
{
// alloc nonBlocking only if empty buffer. This denotes the buffer
// having been transfered out.
if (bufPosition_ > 0)
{
FatalErrorIn("OPstream::~OPstream()")
<< "OPstream contains buffer so cannot be used with nonBlocking"
<< " since destructor would destroy buffer whilst possibly"
<< " still sending." << Foam::abort(FatalError);
}
}
else
{
if
(
!write
(
commsType_,
toProcNo_,
buf_.begin(),
bufPosition_
)
)
{
FatalErrorIn("OPstream::~OPstream()")
<< "MPI cannot send outgoing message"
<< Foam::abort(FatalError);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::OPstream::write
bool Foam::UOPstream::write
(
const commsTypes commsType,
const int toProcNo,
const char* buf,
const std::streamsize bufSize
const std::streamsize bufSize,
const int tag
)
{
bool transferFailed = true;
@ -89,7 +53,7 @@ bool Foam::OPstream::write
bufSize,
MPI_PACKED,
procID(toProcNo),
msgType(),
tag,
MPI_COMM_WORLD
);
}
@ -101,7 +65,7 @@ bool Foam::OPstream::write
bufSize,
MPI_PACKED,
procID(toProcNo),
msgType(),
tag,
MPI_COMM_WORLD
);
}
@ -115,7 +79,7 @@ bool Foam::OPstream::write
bufSize,
MPI_PACKED,
procID(toProcNo),
msgType(),
tag,
MPI_COMM_WORLD,
&request
);
@ -126,8 +90,9 @@ bool Foam::OPstream::write
{
FatalErrorIn
(
"OPstream::write"
"(const int fromProcNo, char* buf, std::streamsize bufSize)"
"UOPstream::write"
"(const int fromProcNo, char* buf, std::streamsize bufSize"
", const int)"
) << "Unsupported communications type " << commsType
<< Foam::abort(FatalError);
}

View File

@ -26,7 +26,7 @@ License
#include "mpi.h"
#include "Pstream.H"
#include "UPstream.H"
#include "PstreamReduceOps.H"
#include "OSspecific.H"
#include "PstreamGlobals.H"
@ -50,7 +50,7 @@ License
// valid parallel options vary between implementations, but flag common ones.
// if they are not removed by MPI_Init(), the subsequent argument processing
// will notice that they are wrong
void Foam::Pstream::addValidParOptions(HashTable<string>& validParOptions)
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
{
validParOptions.insert("np", "");
validParOptions.insert("p4pg", "PI file");
@ -62,7 +62,7 @@ void Foam::Pstream::addValidParOptions(HashTable<string>& validParOptions)
}
bool Foam::Pstream::init(int& argc, char**& argv)
bool Foam::UPstream::init(int& argc, char**& argv)
{
MPI_Init(&argc, &argv);
@ -72,8 +72,8 @@ bool Foam::Pstream::init(int& argc, char**& argv)
if (numprocs <= 1)
{
FatalErrorIn("Pstream::init(int& argc, char**& argv)")
<< "bool Pstream::init(int& argc, char**& argv) : "
FatalErrorIn("UPstream::init(int& argc, char**& argv)")
<< "bool IPstream::init(int& argc, char**& argv) : "
"attempt to run parallel on 1 processor"
<< Foam::abort(FatalError);
}
@ -101,8 +101,8 @@ bool Foam::Pstream::init(int& argc, char**& argv)
}
else
{
FatalErrorIn("Pstream::init(int& argc, char**& argv)")
<< "Pstream::init(int& argc, char**& argv) : "
FatalErrorIn("UPstream::init(int& argc, char**& argv)")
<< "UPstream::init(int& argc, char**& argv) : "
<< "environment variable MPI_BUFFER_SIZE not defined"
<< Foam::abort(FatalError);
}
@ -122,7 +122,7 @@ bool Foam::Pstream::init(int& argc, char**& argv)
}
void Foam::Pstream::exit(int errnum)
void Foam::UPstream::exit(int errnum)
{
# ifndef SGIMPI
int size;
@ -136,10 +136,10 @@ void Foam::Pstream::exit(int errnum)
label n = PstreamGlobals::outstandingRequests_.size();
PstreamGlobals::outstandingRequests_.clear();
WarningIn("Pstream::exit(int)")
WarningIn("UPstream::exit(int)")
<< "There are still " << n << " outstanding MPI_Requests." << endl
<< "This means that your code exited before doing a"
<< " Pstream::waitRequests()." << endl
<< " UPstream::waitRequests()." << endl
<< "This should not happen for a normal code exit."
<< endl;
}
@ -156,7 +156,7 @@ void Foam::Pstream::exit(int errnum)
}
void Foam::Pstream::abort()
void Foam::UPstream::abort()
{
MPI_Abort(MPI_COMM_WORLD, 1);
}
@ -164,19 +164,19 @@ void Foam::Pstream::abort()
void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
{
if (!Pstream::parRun())
if (!UPstream::parRun())
{
return;
}
if (Pstream::nProcs() <= Pstream::nProcsSimpleSum)
if (UPstream::nProcs() <= UPstream::nProcsSimpleSum)
{
if (Pstream::master())
if (UPstream::master())
{
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
int slave=UPstream::firstSlave();
slave<=UPstream::lastSlave();
slave++
)
{
@ -189,8 +189,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&value,
1,
MPI_SCALAR,
Pstream::procID(slave),
Pstream::msgType(),
UPstream::procID(slave),
UPstream::msgType(),
MPI_COMM_WORLD,
MPI_STATUS_IGNORE
)
@ -215,8 +215,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&Value,
1,
MPI_SCALAR,
Pstream::procID(Pstream::masterNo()),
Pstream::msgType(),
UPstream::procID(UPstream::masterNo()),
UPstream::msgType(),
MPI_COMM_WORLD
)
)
@ -230,12 +230,12 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
}
if (Pstream::master())
if (UPstream::master())
{
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
int slave=UPstream::firstSlave();
slave<=UPstream::lastSlave();
slave++
)
{
@ -246,8 +246,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&Value,
1,
MPI_SCALAR,
Pstream::procID(slave),
Pstream::msgType(),
UPstream::procID(slave),
UPstream::msgType(),
MPI_COMM_WORLD
)
)
@ -269,8 +269,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&Value,
1,
MPI_SCALAR,
Pstream::procID(Pstream::masterNo()),
Pstream::msgType(),
UPstream::procID(UPstream::masterNo()),
UPstream::msgType(),
MPI_COMM_WORLD,
MPI_STATUS_IGNORE
)
@ -291,8 +291,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
Value = sum;
/*
int myProcNo = Pstream::myProcNo();
int nProcs = Pstream::nProcs();
int myProcNo = UPstream::myProcNo();
int nProcs = UPstream::nProcs();
//
// receive from children
@ -321,8 +321,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&value,
1,
MPI_SCALAR,
Pstream::procID(childProcId),
Pstream::msgType(),
UPstream::procID(childProcId),
UPstream::msgType(),
MPI_COMM_WORLD,
MPI_STATUS_IGNORE
)
@ -346,7 +346,7 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
//
// send and receive from parent
//
if (!Pstream::master())
if (!UPstream::master())
{
int parentId = myProcNo - (myProcNo % thisLevelOffset);
@ -357,8 +357,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&Value,
1,
MPI_SCALAR,
Pstream::procID(parentId),
Pstream::msgType(),
UPstream::procID(parentId),
UPstream::msgType(),
MPI_COMM_WORLD
)
)
@ -377,8 +377,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&Value,
1,
MPI_SCALAR,
Pstream::procID(parentId),
Pstream::msgType(),
UPstream::procID(parentId),
UPstream::msgType(),
MPI_COMM_WORLD,
MPI_STATUS_IGNORE
)
@ -413,8 +413,8 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
&Value,
1,
MPI_SCALAR,
Pstream::procID(childProcId),
Pstream::msgType(),
UPstream::procID(childProcId),
UPstream::msgType(),
MPI_COMM_WORLD
)
)
@ -436,7 +436,7 @@ void Foam::reduce(scalar& Value, const sumOp<scalar>& bop)
}
void Foam::Pstream::waitRequests()
void Foam::UPstream::waitRequests()
{
if (PstreamGlobals::outstandingRequests_.size())
{
@ -452,7 +452,7 @@ void Foam::Pstream::waitRequests()
{
FatalErrorIn
(
"Pstream::waitRequests()"
"UPstream::waitRequests()"
) << "MPI_Waitall returned with error" << Foam::endl;
}
@ -461,13 +461,13 @@ void Foam::Pstream::waitRequests()
}
bool Foam::Pstream::finishedRequest(const label i)
bool Foam::UPstream::finishedRequest(const label i)
{
if (i >= PstreamGlobals::outstandingRequests_.size())
{
FatalErrorIn
(
"Pstream::finishedRequest(const label)"
"UPstream::finishedRequest(const label)"
) << "There are " << PstreamGlobals::outstandingRequests_.size()
<< " outstanding send requests and you are asking for i=" << i
<< nl

View File

@ -74,7 +74,7 @@ bool Foam::ensightFile::allowUndef(bool value)
}
Foam::scalar Foam::ensightFile::undefValue(const scalar& value)
Foam::scalar Foam::ensightFile::undefValue(const scalar value)
{
// enable its use too
allowUndef_ = true;
@ -133,7 +133,7 @@ Foam::Ostream& Foam::ensightFile::write(const string& value)
}
Foam::Ostream& Foam::ensightFile::write(const label& value)
Foam::Ostream& Foam::ensightFile::write(const label value)
{
if (format() == IOstream::BINARY)
{
@ -157,7 +157,7 @@ Foam::Ostream& Foam::ensightFile::write(const label& value)
Foam::Ostream& Foam::ensightFile::write
(
const label& value,
const label value,
const label fieldWidth
)
{
@ -181,7 +181,7 @@ Foam::Ostream& Foam::ensightFile::write
}
Foam::Ostream& Foam::ensightFile::write(const scalar& value)
Foam::Ostream& Foam::ensightFile::write(const scalar value)
{
if (format() == IOstream::BINARY)
{

View File

@ -103,7 +103,7 @@ public:
//- Assign the value to represent undef in the results
// Returns the previous value
// NB: do not use values larger than floatScalarVGREAT
static scalar undefValue(const scalar&);
static scalar undefValue(const scalar);
// Output
@ -124,13 +124,13 @@ public:
Ostream& write(const string& value);
//- write integer as "%10d" or as binary
Ostream& write(const label& value);
Ostream& write(const label value);
//- write integer with specified width or as binary
Ostream& write(const label& value, const label fieldWidth);
Ostream& write(const label value, const label fieldWidth);
//- write float as "%12.5e" or as binary
Ostream& write(const scalar& value);
Ostream& write(const scalar value);
//- Add carriage return to ascii stream
void newline();

View File

@ -22,8 +22,6 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "cellTable.H"
@ -81,7 +79,7 @@ void Foam::cellTable::addDefaults()
void Foam::cellTable::setEntry
(
const label& id,
const label id,
const word& keyWord,
const word& value
)
@ -192,7 +190,7 @@ Foam::Map<Foam::word> Foam::cellTable::names
}
Foam::word Foam::cellTable::name(const label& id) const
Foam::word Foam::cellTable::name(const label id) const
{
word theName("cellTable_" + Foam::name(id));
@ -289,19 +287,19 @@ Foam::Map<Foam::word> Foam::cellTable::shells() const
void Foam::cellTable::setMaterial(const label& id, const word& matlType)
void Foam::cellTable::setMaterial(const label id, const word& matlType)
{
setEntry(id, "MaterialType", matlType);
}
void Foam::cellTable::setName(const label& id, const word& name)
void Foam::cellTable::setName(const label id, const word& name)
{
setEntry(id, "Label", name);
}
void Foam::cellTable::setName(const label& id)
void Foam::cellTable::setName(const label id)
{
iterator iter = find(id);

View File

@ -96,7 +96,7 @@ class cellTable
//- Add required entries - MaterialType
void addDefaults();
void setEntry(const label& id, const word& keyWord, const word& value);
void setEntry(const label id, const word& keyWord, const word& value);
//- Disallow default bitwise copy construct
cellTable(const cellTable&);
@ -133,7 +133,7 @@ public:
//- Return the name corresponding to id
// returns cellTable_ID if not otherwise defined
word name(const label& id) const;
word name(const label id) const;
//- Return a Map of (id => name)
Map<word> names() const;
@ -157,13 +157,13 @@ public:
Map<word> materialTypes() const;
//- Assign material Type
void setMaterial(const label&, const word&);
void setMaterial(const label, const word&);
//- Assign name
void setName(const label&, const word&);
void setName(const label, const word&);
//- Assign default name if not already set
void setName(const label&);
void setName(const label);
//- Read constant/cellTable
void readDict

View File

@ -182,7 +182,7 @@ public:
virtual bool writeSurface
(
const fileName& timeName = fileName::null,
const bool& triangulate = false
const bool triangulate = false
) const
{
return false;

View File

@ -530,7 +530,7 @@ bool Foam::meshWriters::STARCD::write(const fileName& meshName) const
bool Foam::meshWriters::STARCD::writeSurface
(
const fileName& meshName,
const bool& triangulate
const bool triangulate
) const
{
fileName baseName(meshName);

View File

@ -135,7 +135,7 @@ public:
virtual bool writeSurface
(
const fileName& meshName = fileName::null,
const bool& triangulate = false
const bool triangulate = false
) const;
};

View File

@ -1536,7 +1536,7 @@ void Foam::faceCoupleInfo::perfectPointMatch
FatalErrorIn
(
"faceCoupleInfo::perfectPointMatch"
"(const scalar&, const bool)"
"(const scalar, const bool)"
) << "Did not match all of the master faces to the slave faces"
<< endl
<< "This usually means that the slave patch and master patch"
@ -1761,10 +1761,13 @@ void Foam::faceCoupleInfo::subDivisionMatch
writeOBJ
(
"errorEdges.obj",
UIndirectList<edge>
edgeList
(
cutFaces().edges(),
cutFaces().pointEdges()[cutPointI]
UIndirectList<edge>
(
cutFaces().edges(),
cutFaces().pointEdges()[cutPointI]
)
),
cutFaces().localPoints(),
false

View File

@ -110,7 +110,7 @@ Foam::labelListList Foam::addPatchCellLayer::calcGlobalEdgeFaces
);
// Extract pp part
return UIndirectList<labelList>(globalEdgeFaces, meshEdges);
return labelListList(UIndirectList<labelList>(globalEdgeFaces, meshEdges));
}

View File

@ -55,9 +55,9 @@ namespace Foam
class ifEqEqOp
{
public:
void operator()(label& x, const label& y) const
void operator()(label& x, const label y) const
{
x = (x==y) ? x : value;
x = (x == y) ? x : value;
}
};
}

View File

@ -39,6 +39,7 @@ License
#include "objectMap.H"
#include "processorPolyPatch.H"
#include "fvMesh.H"
#include "CompactListList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -488,9 +489,6 @@ void Foam::polyTopoChange::makeCellCells
// Neighbours per cell
labelList nNbrs(cellMap_.size(), 0);
// Overall number of cellCells
label nCellCells = 0;
// 1. Count neighbours (through internal faces) per cell
for (label faceI = 0; faceI < nActiveFaces; faceI++)
@ -499,22 +497,12 @@ void Foam::polyTopoChange::makeCellCells
{
nNbrs[faceOwner_[faceI]]++;
nNbrs[faceNeighbour_[faceI]]++;
nCellCells += 2;
}
}
cellCells.setSize(cellMap_.size(), nCellCells);
// 2. Construct csr
cellCells.setSize(nNbrs);
// 2. Calculate offsets
labelList& offsets = cellCells.offsets();
label sumSize = 0;
forAll(nNbrs, cellI)
{
sumSize += nNbrs[cellI];
offsets[cellI] = sumSize;
}
// 3. Fill faces per cell
@ -543,8 +531,6 @@ Foam::label Foam::polyTopoChange::getCellOrder
labelList& oldToNew
) const
{
const labelList& offsets = cellCellAddressing.offsets();
labelList newOrder(cellCellAddressing.size());
// Fifo buffer for string of cells
@ -560,7 +546,7 @@ Foam::label Foam::polyTopoChange::getCellOrder
forAll (visited, cellI)
{
// find the first non-removed cell that has not been visited yet
if (!cellRemoved(cellI) && visited.get(cellI) == 0)
if (!cellRemoved(cellI) && visited[cellI] == 0)
{
// use this cell as a start
nextCell.append(cellI);
@ -574,23 +560,22 @@ Foam::label Foam::polyTopoChange::getCellOrder
{
label currentCell = nextCell.removeHead();
if (visited.get(currentCell) == 0)
if (visited[currentCell] == 0)
{
visited.set(currentCell, 1);
visited[currentCell] = 1;
// add into cellOrder
newOrder[cellInOrder] = currentCell;
cellInOrder++;
// find if the neighbours have been visited
label i0 = (currentCell == 0 ? 0 : offsets[currentCell-1]);
label i1 = offsets[currentCell];
const UList<label> cCells = cellCellAddressing[currentCell];
for (label i = i0; i < i1; i++)
forAll(cCells, i)
{
label nbr = cellCellAddressing.m()[i];
label nbr = cCells[i];
if (!cellRemoved(nbr) && visited.get(nbr) == 0)
if (!cellRemoved(nbr) && visited[nbr] == 0)
{
// not visited, add to the list
nextCell.append(nbr);

View File

@ -64,18 +64,12 @@ SourceFiles
#ifndef polyTopoChange_H
#define polyTopoChange_H
#include "autoPtr.H"
#include "DynamicList.H"
#include "labelList.H"
#include "IOobject.H"
#include "typeInfo.H"
#include "pointField.H"
#include "PtrList.H"
#include "cellList.H"
#include "Map.H"
#include "HashSet.H"
#include "mapPolyMesh.H"
#include "CompactListList.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -95,6 +89,8 @@ class polyPatch;
class dictionary;
class topoAction;
class objectMap;
class IOobject;
template<class T, class Container> class CompactListList;
/*---------------------------------------------------------------------------*\
Class polyTopoChange Declaration
@ -273,11 +269,15 @@ class polyTopoChange
void makeCellCells
(
const label nActiveFaces,
CompactListList<label>& cellCells
CompactListList<label, labelList>& cellCells
) const;
//- Cell ordering (bandCompression). Returns number of remaining cells.
label getCellOrder(const CompactListList<label>&, labelList&) const;
label getCellOrder
(
const CompactListList<label, labelList>&,
labelList&
) const;
//- Do upper-triangular ordering and patch ordering.
void getFaceOrder

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "face.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -33,7 +33,7 @@ License
#include "ListListOps.H"
#include "OFstream.H"
#include "IFstream.H"
#include "unitConversion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -31,8 +31,6 @@ License
#include "meshTools.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::primitiveEdgeMesh::calcPointEdges() const
@ -217,7 +215,7 @@ void Foam::primitiveEdgeMesh::mergePoints(const scalar mergeDist)
}
// Compact using a hashtable and commutative hash of edge.
StaticHashTable<label, edge, Hash<edge> > edgeToLabel
HashTable<label, edge, Hash<edge> > edgeToLabel
(
2*edges_.size()
);
@ -241,7 +239,7 @@ void Foam::primitiveEdgeMesh::mergePoints(const scalar mergeDist)
for
(
StaticHashTable<label, edge, Hash<edge> >::const_iterator iter =
HashTable<label, edge, Hash<edge> >::const_iterator iter =
edgeToLabel.begin();
iter != edgeToLabel.end();
++iter

View File

@ -285,6 +285,7 @@ $(divSchemes)/gaussDivScheme/gaussDivSchemes.C
gradSchemes = finiteVolume/gradSchemes
$(gradSchemes)/gradScheme/gradSchemes.C
$(gradSchemes)/gaussGrad/gaussGrads.C
$(gradSchemes)/leastSquaresGrad/leastSquaresVectors.C
$(gradSchemes)/leastSquaresGrad/leastSquaresGrads.C
$(gradSchemes)/extendedLeastSquaresGrad/extendedLeastSquaresVectors.C

View File

@ -273,7 +273,7 @@ public:
}
//- Return porosity
const scalar& porosity() const
scalar porosity() const
{
return porosity_;
}

View File

@ -26,8 +26,6 @@ License
#include "processorFvPatchField.H"
#include "processorFvPatch.H"
#include "IPstream.H"
#include "OPstream.H"
#include "demandDrivenData.H"
#include "transformField.H"

View File

@ -149,7 +149,7 @@ public:
}
//- Return the rotational speed
const scalar& omega() const
scalar omega() const
{
return omega_;
}

View File

@ -177,7 +177,7 @@ public:
virtual tmp<fvMatrix<Type> > fvmDiv
(
const surfaceScalarField&,
GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>&
) const = 0;
virtual tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDiv

View File

@ -69,7 +69,7 @@ tmp<fvMatrix<Type> >
gaussConvectionScheme<Type>::fvmDiv
(
const surfaceScalarField& faceFlux,
GeometricField<Type, fvPatchField, volMesh>& vf
const GeometricField<Type, fvPatchField, volMesh>& vf
) const
{
tmp<surfaceScalarField> tweights = tinterpScheme_().weights(vf);
@ -89,9 +89,9 @@ gaussConvectionScheme<Type>::fvmDiv
fvm.upper() = fvm.lower() + faceFlux.internalField();
fvm.negSumDiag();
forAll(fvm.psi().boundaryField(), patchI)
forAll(vf.boundaryField(), patchI)
{
const fvPatchField<Type>& psf = fvm.psi().boundaryField()[patchI];
const fvPatchField<Type>& psf = vf.boundaryField()[patchI];
const fvsPatchScalarField& patchFlux = faceFlux.boundaryField()[patchI];
const fvsPatchScalarField& pw = weights.boundaryField()[patchI];

View File

@ -124,7 +124,7 @@ public:
tmp<fvMatrix<Type> > fvmDiv
(
const surfaceScalarField&,
GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>&
) const;
tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDiv

View File

@ -22,8 +22,6 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "multivariateGaussConvectionScheme.H"
@ -81,7 +79,7 @@ tmp<fvMatrix<Type> >
multivariateGaussConvectionScheme<Type>::fvmDiv
(
const surfaceScalarField& faceFlux,
GeometricField<Type, fvPatchField, volMesh>& vf
const GeometricField<Type, fvPatchField, volMesh>& vf
) const
{
return gaussConvectionScheme<Type>

View File

@ -114,7 +114,7 @@ public:
tmp<fvMatrix<Type> > fvmDiv
(
const surfaceScalarField&,
GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>&
) const;
tmp<GeometricField<Type, fvPatchField, volMesh> > fvcDiv

View File

@ -21,7 +21,7 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "EulerD2dt2Scheme.H"
@ -181,7 +181,7 @@ EulerD2dt2Scheme<Type>::fvcD2dt2
coefft
*(rho.boundaryField() + rho.oldTime().boundaryField())
*vf.boundaryField()
- (
coefft
*(
@ -232,7 +232,7 @@ template<class Type>
tmp<fvMatrix<Type> >
EulerD2dt2Scheme<Type>::fvmD2dt2
(
GeometricField<Type, fvPatchField, volMesh>& vf
const GeometricField<Type, fvPatchField, volMesh>& vf
)
{
tmp<fvMatrix<Type> > tfvm
@ -292,7 +292,7 @@ tmp<fvMatrix<Type> >
EulerD2dt2Scheme<Type>::fvmD2dt2
(
const dimensionedScalar& rho,
GeometricField<Type, fvPatchField, volMesh>& vf
const GeometricField<Type, fvPatchField, volMesh>& vf
)
{
tmp<fvMatrix<Type> > tfvm
@ -353,7 +353,7 @@ tmp<fvMatrix<Type> >
EulerD2dt2Scheme<Type>::fvmD2dt2
(
const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& vf
const GeometricField<Type, fvPatchField, volMesh>& vf
)
{
tmp<fvMatrix<Type> > tfvm

Some files were not shown because too many files have changed in this diff Show More