extrudeMesh improvements

This commit is contained in:
mattijs
2009-06-16 16:44:35 +01:00
parent 72d8456951
commit e92d84b7a9
8 changed files with 663 additions and 83 deletions

View File

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "DynamicField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
template<class Type>
const char* const DynamicField<Type>::typeName("DynamicField");
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
DynamicField<Type>::DynamicField(Istream& is)
:
Field<Type>(is),
capacity_(Field<Type>::size())
{}
template<class Type>
tmp<DynamicField<Type> > DynamicField<Type>::clone() const
{
return tmp<DynamicField<Type> >(new DynamicField<Type>(*this));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void DynamicField<Type>::setSize(const label nElem)
{
// allocate more capacity?
if (nElem > capacity_)
{
capacity_ = max(nElem, label(1 + capacity_*2));
Field<Type>::setSize(capacity_);
}
// adjust addressed size
Field<Type>::size(nElem);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operator * * * * * * * * * * * * * //
template<class Type>
Ostream& operator<<(Ostream& os, const DynamicField<Type>& f)
{
os << static_cast<const Field<Type>&>(f);
return os;
}
template<class Type>
Ostream& operator<<(Ostream& os, const tmp<DynamicField<Type> >& tf)
{
os << tf();
tf.clear();
return os;
}
template<class Type>
Istream& operator>>(Istream& is, DynamicField<Type>& lst)
{
is >> static_cast<Field<Type>&>(lst);
lst.capacity_ = lst.Field<Type>::size();
return is;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,227 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::DynamicField
Description
Dynamically sized Field. WIP.
SourceFiles
DynamicField.C
\*---------------------------------------------------------------------------*/
#ifndef DynamicField_H
#define DynamicField_H
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class Type>
class DynamicField;
template<class Type>
Ostream& operator<<(Ostream&, const DynamicField<Type>&);
template<class Type>
Ostream& operator<<(Ostream&, const tmp<DynamicField<Type> >&);
template<class Type>
Istream& operator>>(Istream&, DynamicField<Type>&);
/*---------------------------------------------------------------------------*\
Class DynamicField Declaration
\*---------------------------------------------------------------------------*/
#include "CintDefs.H"
template<class Type>
class DynamicField
:
public Field<Type> //private Field<Type>
{
// Private data
//- The capacity (allocated size) of the underlying field.
label capacity_;
//- Construct given size and initial value
DynamicField(const label, const Type&);
//- Construct as copy of tmp<DynamicField>
# ifdef ConstructFromTmp
DynamicField(const tmp<DynamicField<Type> >&);
# endif
//- Construct from a dictionary entry
DynamicField(const word&, const dictionary&, const label);
public:
// Static data members
static const char* const typeName;
// Static Member Functions
//- Return a null field
inline static const DynamicField<Type>& null()
{
return *reinterpret_cast< DynamicField<Type>* >(0);
}
// Constructors
//- Construct null
// Used for temporary fields which are initialised after construction
DynamicField();
//- Construct given size
// Used for temporary fields which are initialised after construction
explicit inline DynamicField(const label);
//- Construct as copy of a UList\<Type\>
explicit inline DynamicField(const UList<Type>&);
//- Construct by transferring the List contents
explicit inline DynamicField(const Xfer<List<Type> >&);
//- Construct by 1 to 1 mapping from the given field
inline DynamicField
(
const UList<Type>& mapF,
const labelList& mapAddressing
);
//- Construct by interpolative mapping from the given field
inline DynamicField
(
const UList<Type>& mapF,
const labelListList& mapAddressing,
const scalarListList& weights
);
//- Construct by mapping from the given field
inline DynamicField
(
const UList<Type>& mapF,
const FieldMapper& map
);
//- Construct as copy
inline DynamicField(const DynamicField<Type>&);
//- Construct as copy or re-use as specified.
inline DynamicField(DynamicField<Type>&, bool reUse);
//- Construct by transferring the Field contents
inline DynamicField(const Xfer<DynamicField<Type> >&);
//- Construct from Istream
inline DynamicField(Istream&);
//- Clone
tmp<DynamicField<Type> > clone() const;
// Member Functions
//- Size of the underlying storage.
inline label capacity() const;
//- Append an element at the end of the list
inline void append(const Type&);
//- Alter the addressed list size.
// New space will be allocated if required.
// Use this to resize the list prior to using the operator[] for
// setting values (as per List usage).
void setSize(const label nElem);
// Member operators
inline void operator=(const DynamicField<Type>&);
inline void operator=(const UList<Type>&);
inline void operator=(const tmp<DynamicField<Type> >&);
//- Return element of Field.
inline Type& operator[](const label i);
//- Return element of constant Field.
inline const Type& operator[](const label) const;
// IOstream operators
friend Ostream& operator<<
#ifndef __CINT__
<Type>
#endif
(Ostream&, const DynamicField<Type>&);
friend Ostream& operator<<
#ifndef __CINT__
<Type>
#endif
(Ostream&, const tmp<DynamicField<Type> >&);
friend Istream& operator>>
#ifndef __CINT__
<Type>
#endif
(Istream&, DynamicField<Type>&);
};
#include "CintUndefs.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "DynamicFieldI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "DynamicField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "DynamicField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
DynamicField<Type>::DynamicField()
:
Field<Type>(),
capacity_(0)
{}
template<class Type>
DynamicField<Type>::DynamicField(const label size)
:
Field<Type>(size),
capacity_(Field<Type>::size())
{
Field<Type>::size(0);
}
template<class Type>
inline Foam::DynamicField<Type>::DynamicField
(
const UList<Type>& lst
)
:
Field<Type>(lst),
capacity_(Field<Type>::size())
{}
template<class Type>
inline Foam::DynamicField<Type>::DynamicField
(
const Xfer<List<Type> >& lst
)
:
Field<Type>(lst),
capacity_(Field<Type>::size())
{}
template<class Type>
DynamicField<Type>::DynamicField
(
const UList<Type>& mapF,
const labelList& mapAddressing
)
:
Field<Type>(mapF, mapAddressing),
capacity_(Field<Type>::size())
{}
template<class Type>
DynamicField<Type>::DynamicField
(
const UList<Type>& mapF,
const labelListList& mapAddressing,
const scalarListList& weights
)
:
Field<Type>(mapF, mapAddressing, weights),
capacity_(Field<Type>::size())
{}
//- Construct by mapping from the given field
template<class Type>
DynamicField<Type>::DynamicField
(
const UList<Type>& mapF,
const FieldMapper& map
)
:
DynamicField<Type>(mapF, map),
capacity_(Field<Type>::size())
{}
template<class Type>
DynamicField<Type>::DynamicField(const DynamicField<Type>& f)
:
Field<Type>(f),
capacity_(Field<Type>::size())
{}
template<class Type>
DynamicField<Type>::DynamicField(DynamicField<Type>& f, bool reUse)
:
Field<Type>(f, reUse),
capacity_(Field<Type>::size())
{}
template<class Type>
DynamicField<Type>::DynamicField(const Xfer<DynamicField<Type> >& f)
:
Field<Type>(f),
capacity_(Field<Type>::size())
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::label DynamicField<Type>::capacity() const
{
return capacity_;
}
template<class Type>
void DynamicField<Type>::append(const Type& t)
{
label elemI = Field<Type>::size();
setSize(elemI + 1);
this->operator[](elemI) = t;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
void DynamicField<Type>::operator=(const DynamicField<Type>& rhs)
{
if (this == &rhs)
{
FatalErrorIn("DynamicField<Type>::operator=(const DynamicField<Type>&)")
<< "attempted assignment to self"
<< abort(FatalError);
}
Field<Type>::operator=(rhs);
capacity_ = Field<Type>::size();
}
template<class Type>
void DynamicField<Type>::operator=(const UList<Type>& rhs)
{
Field<Type>::operator=(rhs);
capacity_ = Field<Type>::size();
}
template<class Type>
void DynamicField<Type>::operator=(const tmp<DynamicField>& rhs)
{
if (this == &(rhs()))
{
FatalErrorIn("DynamicField<Type>::operator=(const tmp<DynamicField>&)")
<< "attempted assignment to self"
<< abort(FatalError);
}
// This is dodgy stuff, don't try it at home.
DynamicField* fieldPtr = rhs.ptr();
List<Type>::transfer(*fieldPtr);
delete fieldPtr;
capacity_ = Field<Type>::size();
}
template<class Type>
Type& DynamicField<Type>::operator[](const label i)
{
return Field<Type>::operator[](i);
}
template<class Type>
const Type& DynamicField<Type>::operator[](const label i) const
{
return Field<Type>::operator[](i);
}
// * * * * * * * * * * * * * * * IOstream Operator * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //