merge from master

This commit is contained in:
mattijs 2008-10-21 15:04:18 +01:00
parent 4c5ebb4cb1
commit 3efb4ebe20
44 changed files with 589 additions and 225 deletions

View File

@ -43,20 +43,58 @@ int main(int argc, char *argv[])
ldl[0](3) = 3;
ldl[0](1) = 1;
ldl[1](0) = 1;
ldl[1](1) = 2;
ldl[0].setSize(5); // increase allocated size
ldl[1].setSize(10); // increase allocated size
ldl[1](2) = 2;
ldl[1] = 3;
Info<< ldl[1];
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
}
Info<< endl;
List<List<label> > ll(2);
ll[0].transfer(ldl[0].shrink());
ll[0].transfer(ldl[0]);
ll[1].transfer(ldl[1].shrink());
Info<< ll << endl;
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
}
Info<< endl;
Info<< "<ll>" << ll << "</ll>" << nl << endl;
// test the transfer between DynamicLists
DynamicList<label, 1, 0> dlA;
DynamicList<label, 1, 0> dlB;
for (label i = 0; i < 5; i++)
{
dlA.append(i);
}
dlA.setSize(10);
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
dlB.transfer(dlA);
// provokes memory error if previous transfer did not maintain
// the correct allocated space
dlB[6] = 6;
Info<< "Transferred to dlB" << endl;
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl;
Info << "\nEnd\n" << endl;
return 0;
}

View File

@ -52,34 +52,48 @@ int main(int argc, char *argv[])
Info<< "lstA: " << lstA << endl;
Info<< "lstC: " << lstC << endl;
xfer<List<label> > xA(lstA, true);
xfer<List<label> > xA = xferMove(lstA);
xfer<List<label> > xB;
// List<label> lstB( xferTmp(List<label>, lstC) );
// List<label> lstB( xfer<List<label> >(lstC) );
List<label> lstB( xA );
Info<< "xA: " << *xA << endl;
Info<< "xB: " << *xB << endl;
Info<< "xA: " << xA() << endl;
Info<< "xB: " << xB() << endl;
Info<< "lstA: " << lstA << endl;
Info<< "lstB: " << lstB << endl;
Info<< "lstC: " << lstC << endl;
xA = lstB;
Info<< "xA: " << *xA << endl;
Info<< "xB: " << *xB << endl;
Info<< "xA: " << xA() << endl;
Info<< "xB: " << xB() << endl;
Info<< "lstA: " << lstA << endl;
Info<< "lstB: " << lstB << endl;
Info<< "lstC: " << lstC << endl;
xB = xA;
List<label> lstD(xferCopy(lstC));
List<label> lstE(xferMove(lstC));
// this must be empty
List<label> lstF = xferCopy(lstC);
Info<< "xA: " << *xA << endl;
Info<< "xB: " << *xB << endl;
Info<< "xA: " << xA() << endl;
Info<< "xB: " << xB() << endl;
Info<< "lstA: " << lstA << endl;
Info<< "lstB: " << lstB << endl;
Info<< "lstC: " << lstC << endl;
Info<< "lstD: " << lstD << endl;
Info<< "lstE: " << lstE << endl;
Info<< "lstF: " << lstF << endl;
Info<< "xB size: " << xB->size() << endl;
// clear the underlying List
xB->clear();
Info<< "xB size: " << xB->size() << endl;
return 0;
}

View File

@ -121,7 +121,7 @@ unset MPI_ARCH_PATH
switch ("$WM_MPLIB")
case OPENMPI:
set mpi_version=openmpi-1.2.6
set mpi_version=openmpi-1.2.8
setenv MPI_HOME $WM_THIRD_PARTY_DIR/$mpi_version
setenv MPI_ARCH_PATH $MPI_HOME/platforms/$WM_OPTIONS

View File

@ -151,7 +151,7 @@ unset MPI_ARCH_PATH
case "$WM_MPLIB" in
OPENMPI)
mpi_version=openmpi-1.2.6
mpi_version=openmpi-1.2.8
export MPI_HOME=$WM_THIRD_PARTY_DIR/$mpi_version
export MPI_ARCH_PATH=$MPI_HOME/platforms/$WM_OPTIONS

View File

@ -93,7 +93,7 @@ HashTable<T, Key, Hash>::HashTable(const xfer<HashTable<T, Key, Hash> >& ht)
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
{
transfer(*ht);
transfer(ht());
}

View File

@ -90,7 +90,7 @@ StaticHashTable<T, Key, Hash>::StaticHashTable
endIter_(*this, 0, 0),
endConstIter_(*this, 0, 0)
{
transfer(*ht);
transfer(ht());
}

View File

@ -95,7 +95,7 @@ CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
template<class T>
CompactListList<T>::CompactListList(const xfer<CompactListList<T> >& lst)
{
transfer(*lst);
transfer(lst());
}
template<class T>

View File

@ -115,39 +115,36 @@ public:
// Access
//- Size of the underlying storage.
inline label allocSize() const;
//- Size of the underlying storage.
inline label allocSize() const;
// Edit
//- Alter the list size.
// When the new size is greater than the addressed list size, the
// allocated list sizes is adjusted and the
// addressed size does not change.
// Otherwise the addressed list size is just reduced and the
// allocated size does not change.
inline void setSize(const label);
//- Alter the list size.
// When the new size is greater than the addressed list size, the
// allocated list sizes is adjusted and the
// addressed size does not change.
// Otherwise the addressed list size is just reduced and the
// allocated size does not change.
inline void setSize(const label);
//- Clear the list, i.e. set the size to zero.
// Allocated size does not change
inline void clear();
//- Clear the list, i.e. set the size to zero.
// Allocated size does not change
inline void clear();
//- Clear the list and delete storage.
inline void clearStorage();
//- Clear the list and delete storage.
inline void clearStorage();
//- Shrink the List<T> to the number of elements used
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
//- Shrink the allocated space to the number of elements used.
// Returns a reference to the DynamicList.
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
//- Transfer the contents of the argument List into this List
// and annull the argument list. Is same as List::transfer except
// checks that you're not changing the underlying list to something
// smaller than allocSize_.
inline void transfer(List<T>&);
//- Transfer contents of the argument List into this DynamicList
inline void transfer(List<T>&);
//- Transfer the contents of the argument DynamicList into this
// DynamicList and annull the argument list.
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
//- Transfer contents of the argument DynamicList into this DynamicList
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
// Member Operators
@ -158,8 +155,7 @@ public:
//- Remove and return the top element
inline T remove();
//- Return non-const access to an element,
// resizing the list if necessary
//- Return non-const access to an element, resizing list if necessary
inline T& operator()(const label);
//- Assignment of all addressed entries to the given value

View File

@ -26,7 +26,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct null
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
:
@ -37,7 +36,6 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
}
//- Construct given size
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
@ -51,15 +49,14 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
}
//- Construct given size
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
const UList<T>& s
const UList<T>& lst
)
:
List<T>(s),
allocSize_(s.size())
List<T>(lst),
allocSize_(lst.size())
{}
@ -114,31 +111,24 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink()
{
allocSize_ = List<T>::size();
List<T>::setSize(allocSize_);
if (allocSize_ > List<T>::size())
{
allocSize_ = List<T>::size();
// force re-allocation/copying in List<T>::setSize() by temporarily
// faking a larger list size that will be truncated
List<T>::size(allocSize_+1);
List<T>::setSize(allocSize_);
}
return *this;
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& l)
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& lst)
{
if (l.size() < List<T>::size())
{
FatalErrorIn
(
"void DynamicList<T, SizeInc, SizeMult"
", SizeDiv>::transfer(List<T>&)"
) << "Cannot replace the underlying storage of this DynamicList"
<< " of which " << List<T>::size() << " elements are used" << nl
<< "with a List of size " << l.size() << abort(FatalError);
}
else
{
allocSize_ = l.size();
List<T>::transfer(l); // take over storage
}
allocSize_ = lst.size();
List<T>::transfer(lst); // take over storage, clear addressing for lst.
}
@ -146,11 +136,14 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
(
DynamicList<T, SizeInc, SizeMult, SizeDiv>& l
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
)
{
allocSize_ = l.allocSize();
List<T>::transfer(l); // take over storage. Null l.
// take over storage as-is (without shrink), clear addressing for lst.
allocSize_ = lst.allocSize_;
lst.allocSize_ = 0;
List<T>::transfer(static_cast<List<T>&>(lst));
}
@ -240,10 +233,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
(
const List<T>& l
const List<T>& lst
)
{
List<T>::operator=(l);
// make the entire storage available for the copy operation:
List<T>::size(allocSize_);
List<T>::operator=(lst);
allocSize_ = List<T>::size();
}

View File

@ -129,7 +129,7 @@ Foam::List<T>::List(const List<T>& a)
template<class T>
Foam::List<T>::List(const xfer<List<T> >& lst)
{
transfer(*lst);
transfer(lst());
}
@ -430,6 +430,9 @@ template<class T>
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void Foam::List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a)
{
// shrink the allocated space to the number of elements used
a.shrink();
if (this->v_) delete[] this->v_;
this->size_ = a.size_;
this->v_ = a.v_;

View File

@ -57,7 +57,7 @@ PackedList<nBits>::PackedList(const PackedList<nBits>& PList)
template<int nBits>
PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
{
transfer(*lst);
transfer(lst());
}

View File

@ -74,7 +74,7 @@ Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg)
template<class T>
Foam::PtrList<T>::PtrList(const xfer<PtrList<T> >& lst)
{
transfer(*lst);
transfer(lst());
}

View File

@ -45,9 +45,9 @@ template <class Type>
Foam::SortableList<Type>::SortableList(const xfer<List<Type> >& values)
:
List<Type>(),
indices_((*values).size())
indices_(values->size())
{
List<Type>::transfer(*values);
List<Type>::transfer(values());
sort();
}

View File

@ -45,7 +45,7 @@ void Foam::UList<T>::assign(const UList<T>& a)
{
if (a.size_ != this->size_)
{
FatalErrorIn("UList<T>::operator=(const UList<T>&)")
FatalErrorIn("UList<T>::assign(const UList<T>&)")
<< "ULists have different sizes: "
<< this->size_ << " " << a.size_
<< abort(FatalError);

View File

@ -53,7 +53,7 @@ UPtrList<T>::UPtrList(const label s)
template<class T>
UPtrList<T>::UPtrList(const xfer<UPtrList<T> >& lst)
{
transfer(*lst);
transfer(lst());
}

View File

@ -87,6 +87,25 @@ Foam::IOField<Type>::IOField(const IOobject& io, const Field<Type>& f)
}
template<class Type>
Foam::IOField<Type>::IOField(const IOobject& io, const xfer<Field<Type> >& f)
:
regIOobject(io)
{
Field<Type>::transfer(f());
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class Type>

View File

@ -65,11 +65,14 @@ public:
//- Construct from IOobject
IOField(const IOobject&);
//- Construct from IOobject and size (does not set values)
IOField(const IOobject&, const label size);
//- Construct from components
IOField(const IOobject&, const Field<Type>&);
//- Construct from IOobject and size (does not set values)
IOField(const IOobject&, const label size);
//- Construct by transferring the Field contents
IOField(const IOobject&, const xfer<Field<Type> >&);
// Destructor

View File

@ -87,6 +87,25 @@ Foam::IOList<T>::IOList(const IOobject& io, const List<T>& list)
}
template<class T>
Foam::IOList<T>::IOList(const IOobject& io, const xfer<List<T> >& list)
:
regIOobject(io)
{
List<T>::transfer(list());
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class T>

View File

@ -72,6 +72,9 @@ public:
//- Construct from IOobject and a List
IOList(const IOobject&, const List<T>&);
//- Construct by transferring the List contents
IOList(const IOobject&, const xfer<List<T> >&);
// Destructor

View File

@ -86,6 +86,25 @@ Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& map)
}
template<class T>
Foam::IOMap<T>::IOMap(const IOobject& io, const xfer<Map<T> >& map)
:
regIOobject(io)
{
Map<T>::transfer(map());
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class T>

View File

@ -66,11 +66,14 @@ public:
//- Construct from IOobject
IOMap(const IOobject&);
//- Construct from IOobject and size of Map
IOMap(const IOobject&, const label);
//- Construct from IOobject and a Map
IOMap(const IOobject&, const Map<T>&);
//- Construct from IOobject and size of Map
IOMap(const IOobject&, const label);
//- Construct by transferring the Map contents
IOMap(const IOobject&, const xfer<Map<T> >&);
// Destructor

View File

@ -84,6 +84,25 @@ Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const PtrList<T>& list)
}
template<class T>
Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const xfer<PtrList<T> >& list)
:
regIOobject(io)
{
PtrList<T>::transfer(list());
if
(
io.readOpt() == IOobject::MUST_READ
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
PtrList<T>::read(readStream(typeName), INew<T>());
close();
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class T>

View File

@ -73,6 +73,9 @@ public:
//- Construct from IOobject and a PtrList
IOPtrList(const IOobject&, const PtrList<T>&);
//- Construct by transferring the PtrList contents
IOPtrList(const IOobject&, const xfer<PtrList<T> >&);
// Destructor

View File

@ -138,6 +138,19 @@ DimensionedField<Type, GeoMesh>::DimensionedField
{}
template<class Type, class GeoMesh>
DimensionedField<Type, GeoMesh>::DimensionedField
(
const xfer<DimensionedField<Type, GeoMesh> >& df
)
:
regIOobject(df(), true),
Field<Type>(df),
mesh_(df->mesh_),
dimensions_(df->dimensions_)
{}
#ifdef ConstructFromTmp
template<class Type, class GeoMesh>
DimensionedField<Type, GeoMesh>::DimensionedField
@ -202,6 +215,20 @@ DimensionedField<Type, GeoMesh>::DimensionedField
{}
template<class Type, class GeoMesh>
DimensionedField<Type, GeoMesh>::DimensionedField
(
const word& newName,
const xfer<DimensionedField<Type, GeoMesh> >& df
)
:
regIOobject(IOobject(newName, df->time().timeName(), df->db())),
Field<Type>(df),
mesh_(df->mesh_),
dimensions_(df->dimensions_)
{}
#ifdef ConstructFromTmp
template<class Type, class GeoMesh>
DimensionedField<Type, GeoMesh>::DimensionedField
@ -248,7 +275,7 @@ DimensionedField<Type, GeoMesh>::~DimensionedField()
template<class Type, class GeoMesh>
const DimensionedField<Type, GeoMesh>& DimensionedField<Type, GeoMesh>::null()
{
DimensionedField<Type, GeoMesh>* nullPtr =
DimensionedField<Type, GeoMesh>* nullPtr =
reinterpret_cast<DimensionedField<Type, GeoMesh>*>(NULL);
return *nullPtr;
}
@ -258,8 +285,8 @@ template<class Type, class GeoMesh>
tmp
<
DimensionedField
<typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
>
<typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
>
DimensionedField<Type, GeoMesh>::component
(
const direction d
@ -315,7 +342,7 @@ void DimensionedField<Type, GeoMesh>::replace
template<class Type, class GeoMesh>
tmp<DimensionedField<Type, GeoMesh> >
tmp<DimensionedField<Type, GeoMesh> >
DimensionedField<Type, GeoMesh>::T() const
{
tmp<DimensionedField<Type, GeoMesh> > result

View File

@ -49,7 +49,7 @@ namespace Foam
{
// Forward declaration of friend functions and operators
template<class Type, class GeoMesh> class DimensionedField;
template<class Type, class GeoMesh> Ostream& operator<<
@ -156,6 +156,12 @@ public:
bool reUse
);
//- Construct by transferring the DimensionedField
DimensionedField
(
const xfer<DimensionedField<Type, GeoMesh> >&
);
//- Construct as copy of tmp<DimensionedField> deleting argument
# ifdef ConstructFromTmp
DimensionedField
@ -186,6 +192,13 @@ public:
bool reUse
);
//- Construct by transferring the DimensionedField with a new name
DimensionedField
(
const word& newName,
const xfer<DimensionedField<Type, GeoMesh> >&
);
//- Construct as copy resetting name
# ifdef ConstructFromTmp
DimensionedField

View File

@ -37,6 +37,7 @@ SourceFiles
#define FieldField_H
#include "tmp.H"
#include "xfer.H"
#include "PtrList.H"
#include "scalar.H"
#include "direction.H"

View File

@ -155,6 +155,13 @@ Field<Type>::Field(Field<Type>& f, bool reUse)
{}
template<class Type>
Field<Type>::Field(const xfer<Field<Type> >& f)
:
List<Type>(f)
{}
template<class Type>
Field<Type>::Field(const typename Field<Type>::subField& sf)
:
@ -568,6 +575,20 @@ void Field<Type>::replace
}
template<class Type>
void Field<Type>::transfer(Field<Type>& f)
{
List<Type>::transfer(f);
}
template<class Type>
void Field<Type>::transfer(List<Type>& lst)
{
List<Type>::transfer(lst);
}
template<class Type>
tmp<Field<Type> > Field<Type>::T() const
{

View File

@ -43,6 +43,7 @@ SourceFiles
#define Field_H
#include "tmp.H"
#include "xfer.H"
#include "direction.H"
#include "VectorSpace.H"
#include "scalarList.H"
@ -164,6 +165,9 @@ public:
//- Construct as copy or re-use as specified.
Field(Field<Type>&, bool reUse);
//- Construct by transferring the Field contents
Field(const xfer<Field<Type> >&);
//- Construct as copy of subField
Field(const typename Field<Type>::subField&);
@ -293,6 +297,12 @@ public:
//- Replace a component field of the field
void replace(const direction, const cmptType&);
//- Transfer the contents of the argument Field into this Field
void transfer(Field<Type>&);
//- Transfer the contents of the argument List into this Field
void transfer(List<Type>&);
//- Return the field transpose (only defined for second rank tensors)
tmp<Field<Type> > T() const;

View File

@ -30,7 +30,7 @@ Description
of objects of type \<T\>.
Since it is decided upon construction of the xfer object whether the
parameter is to be copied or transferred, the contents of resulting
parameter is to be copied or transferred, the contents of the resulting
object can be transferred unconditionally.
This greatly simplifies defining the constructors for other classes
@ -39,10 +39,6 @@ Description
The wrapped object of type \<T\> must implement a transfer() method and
an operator=() copy method.
Note
The macros xferCopy(T,arg) and xferMove(T,arg) can be used as
workarounds for passing temporaries to copy-constructors.
SourceFiles
xferI.H
@ -56,6 +52,9 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
template<class T> class tmp;
/*---------------------------------------------------------------------------*\
Class xfer Declaration
\*---------------------------------------------------------------------------*/
@ -97,52 +96,65 @@ public:
//- Transfer the contents into the object
inline void operator=(const xfer<T>&);
//- Return a non-const reference to const object
// @sa xferCopy, xferMove macros alternatives for copy-constructors
inline const xfer<T>& operator()() const;
//- Reference to the underlying datatype
inline T& operator*() const;
inline T& operator()() const;
//- Pointer to the underlying datatype
inline T* operator->() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
/**
* @def xferCopy(T,arg)
* @fn template<class T> xferCopy(const T&)
* Construct by copying the contents of the @a arg
* and return a const reference to an xfer of type \<T\>
*
* Useful for constructors where the argument is temporary.
* This is a workaround for a template resolution issue.
*
* @sa xferMove and Foam::xfer
* @sa xferMove, xferTmp and Foam::xfer
*/
#define xferCopy(T,arg) \
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg)()))
template<class T>
Foam::xfer<T> xferCopy(const T& t)
{
return Foam::xfer<T>(t);
}
/**
* @def xferMove(T,arg)
* @fn template<class T> xferMove(T&)
* Construct by transferring the contents of the @a arg
* and return a const reference to an xfer of type \<T\>
*
* Useful for constructors where the argument is temporary.
* This is a workaround for a template resolution issue.
*
* @par Example Use
* @code
* List<label> a;
* ...
* List<label> b(xferMove(List<label>, a));
* List<label> b(xferMove(a));
* @endcode
*
* @sa xferCopy and Foam::xfer
* @sa xferCopy, xferTmp and Foam::xfer
*/
#define xferMove(T,arg) \
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg, true)()))
template<class T>
Foam::xfer<T> xferMove(T& t)
{
return Foam::xfer<T>(t, true);
}
/**
* @fn template<class T> xferTmp(tmp<T>&)
* Construct by transferring the contents of the @a arg
*
* @sa xferCopy, xferMove and Foam::xfer
*/
template<class T>
Foam::xfer<T> xferTmp(Foam::tmp<T>& tt)
{
return Foam::xfer<T>(tt(), tt.isTmp());
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -98,16 +98,16 @@ inline void Foam::xfer<T>::operator=(const xfer<T>& t)
template<class T>
inline const Foam::xfer<T>& Foam::xfer<T>::operator()() const
{
return *this;
}
template<class T>
inline T& Foam::xfer<T>::operator*() const
inline T& Foam::xfer<T>::operator()() const
{
return *ptr_;
}
template<class T>
inline T* Foam::xfer<T>::operator->() const
{
return ptr_;
}
// ************************************************************************* //

View File

@ -65,11 +65,11 @@ const Type& Foam::MeshObject<Mesh, Type>::New
template<class Mesh, class Type>
template<class Data>
template<class Data1>
const Type& Foam::MeshObject<Mesh, Type>::New
(
const Mesh& mesh,
const Data& d
const Data1& d
)
{
if (!mesh.db().objectRegistry::foundObject<Type>(Type::typeName))
@ -103,6 +103,49 @@ const Type& Foam::MeshObject<Mesh, Type>::New
}
template<class Mesh, class Type>
template<class Data1, class Data2, class Data3>
const Type& Foam::MeshObject<Mesh, Type>::New
(
const Mesh& mesh,
const Data1& d1,
const Data2& d2,
const Data3& d3
)
{
if (!mesh.db().objectRegistry::foundObject<Type>(Type::typeName))
{
return store(new Type(mesh, d1, d2, d3));
}
else
{
return mesh.db().objectRegistry::lookupObject<Type>(Type::typeName);
}
}
template<class Mesh, class Type>
template<class Data1, class Data2, class Data3, class Data4>
const Type& Foam::MeshObject<Mesh, Type>::New
(
const Mesh& mesh,
const Data1& d1,
const Data2& d2,
const Data3& d3,
const Data4& d4
)
{
if (!mesh.db().objectRegistry::foundObject<Type>(Type::typeName))
{
return store(new Type(mesh, d3, d4));
}
else
{
return mesh.db().objectRegistry::lookupObject<Type>(Type::typeName);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
template<class Mesh, class Type>

View File

@ -69,11 +69,39 @@ public:
static const Type& New(const Mesh& mesh);
template<class Data>
static const Type& New(const Mesh& mesh, const Data& d);
template<class Data1>
static const Type& New
(
const Mesh& mesh,
const Data1& d
);
template<class Data1, class Data2>
static const Type& New(const Mesh& mesh, const Data1&, const Data2&);
static const Type& New
(
const Mesh& mesh,
const Data1&,
const Data2&
);
template<class Data1, class Data2, class Data3>
static const Type& New
(
const Mesh& mesh,
const Data1&,
const Data2&,
const Data3&
);
template<class Data1, class Data2, class Data3, class Data4>
static const Type& New
(
const Mesh& mesh,
const Data1&,
const Data2&,
const Data3&,
const Data4&
);
// Destructor

View File

@ -170,6 +170,9 @@ private:
//- Initialise the polyMesh from the given set of cells
void initMesh(cellList& c);
//- Initialise the polyMesh from the given set of cells
void initMesh(const xfer<cellList>& c);
//- Calculate the valid directions in the mesh from the boundaries
void calcDirections() const;
@ -226,6 +229,18 @@ public:
const bool syncPar = true
);
//- Construct without boundary from components.
// Boundary is added using addPatches() member function
polyMesh
(
const IOobject& io,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<labelList>& owner,
const xfer<labelList>& neighbour,
const bool syncPar = true
);
//- Construct without boundary with cells rather than owner/neighbour.
// Boundary is added using addPatches() member function
polyMesh
@ -237,6 +252,17 @@ public:
const bool syncPar = true
);
//- Construct without boundary with cells rather than owner/neighbour.
// Boundary is added using addPatches() member function
polyMesh
(
const IOobject& io,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<cellList>& cells,
const bool syncPar = true
);
//- Construct from cell shapes
polyMesh
(
@ -444,6 +470,23 @@ public:
const bool validBoundary = true
);
//- Reset mesh primitive data. Assumes all patch info correct
// (so does e.g. parallel communication). If not use
// validBoundary=false
// (still assumes patchStarts[0] = nInternalFaces and last
// patch ends at nActiveFaces) and change patches with addPatches.
void resetPrimitives
(
const label nUsedFaces,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<labelList>& owner,
const xfer<labelList>& neighbour,
const labelList& patchSizes,
const labelList& patchStarts,
const bool validBoundary = true
);
// Storage management

View File

@ -155,4 +155,10 @@ void Foam::polyMesh::initMesh(cellList& c)
}
void Foam::polyMesh::initMesh(const xfer<cellList>& clst)
{
initMesh(clst());
}
// ************************************************************************* //

View File

@ -29,16 +29,15 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(primitiveMesh, 0);
defineTypeNameAndDebug(primitiveMesh, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
primitiveMesh::primitiveMesh()
Foam::primitiveMesh::primitiveMesh()
:
nInternalPoints_(0), // note: points are considered ordered on empty mesh
nPoints_(0),
@ -76,8 +75,8 @@ primitiveMesh::primitiveMesh()
// Construct from components
// WARNING: ASSUMES CORRECT ORDERING OF DATA.
primitiveMesh::primitiveMesh
// WARNING: ASSUMES CORRECT ORDERING OF DATA.
Foam::primitiveMesh::primitiveMesh
(
const label nPoints,
const label nInternalFaces,
@ -114,14 +113,12 @@ primitiveMesh::primitiveMesh
faceCentresPtr_(NULL),
cellVolumesPtr_(NULL),
faceAreasPtr_(NULL)
{
}
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
primitiveMesh::~primitiveMesh()
Foam::primitiveMesh::~primitiveMesh()
{
clearOut();
}
@ -129,7 +126,7 @@ primitiveMesh::~primitiveMesh()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool primitiveMesh::calcPointOrder
bool Foam::primitiveMesh::calcPointOrder
(
label& nInternalPoints,
labelList& oldToNew,
@ -208,7 +205,7 @@ bool primitiveMesh::calcPointOrder
}
void primitiveMesh::reset
void Foam::primitiveMesh::reset
(
const label nPoints,
const label nInternalFaces,
@ -264,13 +261,13 @@ void primitiveMesh::reset
}
void primitiveMesh::reset
void Foam::primitiveMesh::reset
(
const label nPoints,
const label nInternalFaces,
const label nFaces,
const label nCells,
cellList& c
cellList& clst
)
{
reset
@ -281,11 +278,32 @@ void primitiveMesh::reset
nCells
);
cfPtr_ = new cellList(c, true);
cfPtr_ = new cellList(clst, true);
}
tmp<scalarField> primitiveMesh::movePoints
void Foam::primitiveMesh::reset
(
const label nPoints,
const label nInternalFaces,
const label nFaces,
const label nCells,
const xfer<cellList>& clst
)
{
reset
(
nPoints,
nInternalFaces,
nFaces,
nCells
);
cfPtr_ = new cellList(clst);
}
Foam::tmp<Foam::scalarField> Foam::primitiveMesh::movePoints
(
const pointField& newPoints,
const pointField& oldPoints
@ -320,7 +338,7 @@ tmp<scalarField> primitiveMesh::movePoints
}
const cellShapeList& primitiveMesh::cellShapes() const
const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
{
if (!cellShapesPtr_)
{
@ -331,8 +349,4 @@ const cellShapeList& primitiveMesh::cellShapes() const
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -375,6 +375,17 @@ public:
);
//- Reset this primitiveMesh given the primitive array sizes and cells
void reset
(
const label nPoints,
const label nInternalFaces,
const label nFaces,
const label nCells,
const xfer<cellList>& cells
);
// Access
// Mesh size parameters

View File

@ -30,9 +30,6 @@ Description
#include "meshReader.H"
// for transition - in case someone really relied on the old behaviour
#undef LEAVE_UNUSED_POINTS
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::meshReader::calcPointCells() const
@ -46,7 +43,7 @@ void Foam::meshReader::calcPointCells() const
<< abort(FatalError);
}
label nPoints = points().size();
label nPoints = points_.size();
pointCellsPtr_ = new labelListList(nPoints);
labelListList& ptCells = *pointCellsPtr_;
@ -132,19 +129,15 @@ void Foam::meshReader::calcPointCells() const
// report unused points
if (nPoints > pointI)
{
#ifdef LEAVE_UNUSED_POINTS
FatalErrorIn("meshReader::calcPointCells() const")
<< "mesh has " << (nPoints - pointI)
<< " points that were declared but not used" << endl;
#else
Info<< "removing " << (nPoints - pointI) << " unused points" << endl;
nPoints = pointI;
// adjust points and truncate
inplaceReorder(oldToNew, points());
points().setSize(nPoints);
// adjust points and truncate - bend const-ness
pointField& adjustedPoints = const_cast<pointField&>(points_);
inplaceReorder(oldToNew, adjustedPoints);
adjustedPoints.setSize(nPoints);
// adjust pointCells and truncate
inplaceReorder(oldToNew, ptCells);
@ -162,7 +155,6 @@ void Foam::meshReader::calcPointCells() const
inplaceRenumber(oldToNew, faces[i]);
}
}
#endif
}
}

View File

@ -142,7 +142,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
"constant",
registry
),
points(),
points_,
meshFaces_,
cellPolys_
)

View File

@ -291,13 +291,6 @@ protected:
//- Subclasses are required to supply this information
virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
//- Return mesh points
pointField& points() const
{
return const_cast<pointField&>(points_);
}
public:
// Static Members

View File

@ -180,6 +180,18 @@ public:
const bool syncPar = true
);
//- Construct from components without boundary.
// Boundary is added using addFvPatches() member function
fvMesh
(
const IOobject& io,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<labelList>& allOwner,
const xfer<labelList>& allNeighbour,
const bool syncPar = true
);
//- Construct from components with cells rather than owner
// and neighbourwithout boundary.
// Boundary is added using addPatches() member function
@ -192,6 +204,18 @@ public:
const bool syncPar = true
);
//- Construct from components with cells rather than owner
// and neighbourwithout boundary.
// Boundary is added using addPatches() member function
fvMesh
(
const IOobject& io,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<cellList>& cells,
const bool syncPar = true
);
// Destructor
@ -295,7 +319,7 @@ public:
virtual void updateMesh(const mapPolyMesh& mpm);
//- Move points, returns volumes swept by faces in motion
virtual tmp<scalarField> movePoints(const vectorField&);
virtual tmp<scalarField> movePoints(const pointField&);
//- Map all fields in time using given map.
virtual void mapFields(const mapPolyMesh& mpm);

View File

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
quadraticFit
Foam::quadraticFit
Description
Quadratic fit interpolation scheme which applies an explicit correction to
@ -56,8 +56,16 @@ class quadraticFit
public linear<Type>
{
// Private Data
//- Factor the fit is allowed to deviate from linear.
// This limits the amount of high-order correction and increases
// stability on bad meshes
const scalar linearLimitFactor_;
//- Weights for central stencil
const scalar centralWeight_;
// Private Member Functions
//- Disallow default bitwise copy construct
@ -79,6 +87,7 @@ public:
quadraticFit(const fvMesh& mesh, Istream& is)
:
linear<Type>(mesh),
linearLimitFactor_(readScalar(is)),
centralWeight_(readScalar(is))
{}
@ -92,6 +101,7 @@ public:
)
:
linear<Type>(mesh),
linearLimitFactor_(readScalar(is)),
centralWeight_(readScalar(is))
{}
@ -123,6 +133,7 @@ public:
(
mesh,
stencil,
linearLimitFactor_,
centralWeight_
);

View File

@ -41,16 +41,16 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
static int count = 0;
Foam::quadraticFitData::quadraticFitData
(
const fvMesh& mesh,
const extendedCentredStencil& stencil,
const scalar linearLimitFactor,
const scalar cWeight
)
:
MeshObject<fvMesh, quadraticFitData>(mesh),
linearLimitFactor_(linearLimitFactor),
centralWeight_(cWeight),
# ifdef SPHERICAL_GEOMETRY
dim_(2),
@ -61,7 +61,7 @@ Foam::quadraticFitData::quadraticFitData
(
dim_ == 1 ? 3 :
dim_ == 2 ? 6 :
dim_ == 3 ? 9 : 0
dim_ == 3 ? 7 : 0
),
fit_(mesh.nInternalFaces())
{
@ -116,8 +116,6 @@ Foam::quadraticFitData::quadraticFitData
interpPolySize[faci] = calcFit(stencilPoints[faci], faci);
}
Pout<< "count = " << count << endl;
if (debug)
{
Info<< "quadraticFitData::quadraticFitData() :"
@ -243,14 +241,14 @@ Foam::label Foam::quadraticFitData::calcFit
{
B[ip][is++] = wts[ip]*py;
B[ip][is++] = wts[ip]*px*py;
B[ip][is++] = wts[ip]*sqr(py);
//B[ip][is++] = wts[ip]*sqr(py);
}
if (dim_ == 3)
{
B[ip][is++] = wts[ip]*pz;
B[ip][is++] = wts[ip]*px*pz;
//B[ip][is++] = wts[ip]*py*pz;
B[ip][is++] = wts[ip]*sqr(pz);
//B[ip][is++] = wts[ip]*sqr(pz);
}
}
@ -274,15 +272,15 @@ Foam::label Foam::quadraticFitData::calcFit
//goodFit = (fit0 > 0 && fit1 > 0);
goodFit =
(mag(fit0 - w[faci])/w[faci] < 0.15)
&& (mag(fit1 - (1 - w[faci]))/(1 - w[faci]) < 0.15);
(mag(fit0 - w[faci])/w[faci] < linearLimitFactor_)
&& (mag(fit1 - (1 - w[faci]))/(1 - w[faci]) < linearLimitFactor_);
//scalar w0Err = fit0/w[faci];
//scalar w1Err = fit1/(1 - w[faci]);
//goodFit =
// (w0Err > 0.5 && w0Err < 1.5)
// && (w1Err > 0.5 && w1Err < 1.5);
// (w0Err > linearLimitFactor_ && w0Err < (1 + linearLimitFactor_))
// && (w1Err > linearLimitFactor_ && w1Err < (1 + linearLimitFactor_));
if (goodFit)
{
@ -324,13 +322,6 @@ Foam::label Foam::quadraticFitData::calcFit
if (goodFit)
{
if ((mag(fit_[faci][0] - w[faci])/w[faci] < 0.15)
&& (mag(fit_[faci][1] - (1 - w[faci]))/(1 - w[faci]) < 0.15))
{
count++;
//Pout<< "fit " << mag(fit_[faci][0] - w[faci])/w[faci] << " " << mag(fit_[faci][1] - (1 - w[faci]))/(1 - w[faci]) << endl;
}
// scalar limiter =
// max
// (
@ -358,6 +349,7 @@ Foam::label Foam::quadraticFitData::calcFit
Pout<< "Could not fit face " << faci
<< " " << fit_[faci][0] << " " << w[faci]
<< " " << fit_[faci][1] << " " << 1 - w[faci]<< endl;
fit_[faci] = 0;
}

View File

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
quadraticFitData
Foam::quadraticFitData
Description
Data for the quadratic fit correction interpolation scheme
@ -56,13 +56,18 @@ class quadraticFitData
{
// Private data
//- weights for central stencil
//- Factor the fit is allowed to deviate from linear.
// This limits the amount of high-order correction and increases
// stability on bad meshes
const scalar linearLimitFactor_;
//- Weights for central stencil
const scalar centralWeight_;
//- dimensionality of the geometry
//- Dimensionality of the geometry
const label dim_;
//- minimum stencil size
//- Minimum stencil size
const label minSize_;
//- For each cell in the mesh store the values which multiply the
@ -96,19 +101,18 @@ public:
(
const fvMesh& mesh,
const extendedCentredStencil& stencil,
scalar cWeightDim
const scalar linearLimitFactor,
const scalar centralWeight
);
// Destructor
virtual ~quadraticFitData()
{}
//- Destructor
virtual ~quadraticFitData()
{}
// Member functions
//- Return reference to fit coefficients
const List<scalarList>& fit() const
{

View File

@ -163,18 +163,6 @@ colourPipe()
}
#
# prefix message with [HOSTNAME]
#
prefixPipe()
{
while read line
do
echo "[$@] $line"
done
}
colourIndex=0
while :
@ -202,19 +190,15 @@ do
if [ "$host" = "$HOST" ]; then
eval $* 2>&1 | colourPipe "$colour"
elif [ -n "$JOB_ID" ]; then
qrsh -inherit -v PWD $host "$rcmd"
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe "$colour"
fi
retval=$?
else
if [ "$host" = "$HOST" ]; then
eval $* 2>&1 | prefixPipe "$host"
elif [ -n "$JOB_ID" ]; then
qrsh -inherit -v PWD $host "$rcmd" | prefixPipe "$host"
eval $* 2>&1
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | prefixPipe "$host"
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1
fi
retval=$?
fi