Add CoeffField and blockLduMatrix to OpenFOAM library

This commit is contained in:
Ivor Clifford 2010-10-14 17:15:53 -04:00
parent b7eaf44c61
commit 781878cd02
141 changed files with 24856 additions and 0 deletions

View file

@ -578,4 +578,55 @@ $(writers)/gnuplotGraph/gnuplotGraph.C
$(writers)/xmgrGraph/xmgrGraph.C
$(writers)/jplotGraph/jplotGraph.C
//- Block Matrix Additions
//- I. Clifford 03-12-2009
primitives/BlockCoeff/blockCoeffBase.C
primitives/BlockCoeff/scalarBlockCoeff.C
primitives/BlockCoeff/sphericalTensorBlockCoeff.C
primitives/BlockCoeff/symmTensorBlockCoeff.C
primitives/BlockCoeff/tensorBlockCoeff.C
fields/expandContract/expandTensorField.C
fields/CoeffField/scalarCoeffField.C
// fields/CoeffField/sphericalTensorCoeffField.C
// fields/CoeffField/symmTensorCoeffField.C
fields/CoeffField/tensorCoeffField.C
matrices/blockLduMatrix/BlockLduMatrix/blockLduMatrices.C
matrices/blockLduMatrix/BlockLduMatrix/scalarBlockLduMatrix.C
// matrices/blockLduMatrix/BlockLduMatrix/sphericalTensorBlockLduMatrix.C
// matrices/blockLduMatrix/BlockLduMatrix/symmTensorBlockLduMatrix.C
matrices/blockLduMatrix/BlockLduMatrix/tensorBlockLduMatrix.C
matrices/blockLduMatrix/BlockLduMatrix/BlockConstraint/scalarBlockConstraint.C
matrices/blockLduMatrix/BlockLduPrecons/BlockLduPrecon/blockLduPrecons.C
matrices/blockLduMatrix/BlockLduPrecons/BlockNoPrecon/blockNoPrecons.C
matrices/blockLduMatrix/BlockLduPrecons/BlockDiagonalPrecon/scalarBlockDiagonalPrecon.C
matrices/blockLduMatrix/BlockLduPrecons/BlockDiagonalPrecon/tensorBlockDiagonalPrecon.C
matrices/blockLduMatrix/BlockLduPrecons/BlockDiagonalPrecon/blockDiagonalPrecons.C
matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/scalarBlockGaussSeidelPrecon.C
matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/tensorBlockGaussSeidelPrecon.C
matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/blockGaussSeidelPrecons.C
matrices/blockLduMatrix/BlockLduPrecons/BlockCholeskyPrecon/scalarBlockCholeskyPrecon.C
matrices/blockLduMatrix/BlockLduPrecons/BlockCholeskyPrecon/tensorBlockCholeskyPrecon.C
matrices/blockLduMatrix/BlockLduPrecons/BlockCholeskyPrecon/blockCholeskyPrecons.C
matrices/blockLduMatrix/BlockLduSmoothers/BlockLduSmoother/blockLduSmoothers.C
// matrices/blockLduMatrix/BlockLduSmoothers/BlockGaussSeidelSmoother/blockGaussSeidelSmoothers.C
matrices/blockLduMatrix/BlockLduSmoothers/BlockILUSmoother/blockILUSmoothers.C
matrices/blockLduMatrix/BlockLduSolvers/BlockLduSolver/blockLduSolvers.C
matrices/blockLduMatrix/BlockLduSolvers/BlockDiagonal/blockDiagonalSolvers.C
// matrices/blockLduMatrix/BlockLduSolvers/Segregated/segregatedSolvers.C
matrices/blockLduMatrix/BlockLduSolvers/BlockGaussSeidel/blockGaussSeidelSolvers.C
matrices/blockLduMatrix/BlockLduSolvers/BlockCG/blockCGSolvers.C
matrices/blockLduMatrix/BlockLduSolvers/BlockBiCGStab/blockBiCGStabSolvers.C
matrices/blockLduMatrix/BlockLduSolvers/BlockGMRES/blockGMRESSolvers.C
matrices/blockLduMatrix/BlockLduMatrix/BlockLduInterface/BlockLduInterfaceFields.C
LIB = $(FOAM_LIBBIN)/libOpenFOAM

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,336 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
CoeffField<T>
Description
Generic coefficient field type. Used in BlockLduMatrix. HJ, 2/Apr/2005
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
CoeffField.C
\*---------------------------------------------------------------------------*/
#ifndef CoeffField_H
#define CoeffField_H
#include "VectorSpace.H"
#include "primitiveFields.H"
#include "blockCoeffs.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * Forward declaration of template friend fuctions * * * * * * * //
template<class Type>
class CoeffField;
template<class Type>
Ostream& operator<<(Ostream&, const CoeffField<Type>&);
template<class Type>
Ostream& operator<<(Ostream&, const tmp<CoeffField<Type> >&);
/*---------------------------------------------------------------------------*\
Class CoeffField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class CoeffField
:
public refCount
{
public:
// Public data types
//- Component type
typedef typename BlockCoeff<Type>::scalarType scalarType;
typedef typename BlockCoeff<Type>::linearType linearType;
typedef typename BlockCoeff<Type>::squareType squareType;
//- Field type
typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
typedef typename BlockCoeff<Type>::squareTypeField squareTypeField;
private:
// Private data
//- Scalar coefficient
mutable scalarTypeField* scalarCoeffPtr_;
//- Linear coefficient
mutable linearTypeField* linearCoeffPtr_;
//- Square coefficient
mutable squareTypeField* squareCoeffPtr_;
//- Number of elements
label size_;
// Private Member Functions
//- Check size for arithmetic operations: resizing is not allowed!
template<class Type2>
inline void checkSize(const UList<Type2>&) const;
//- Promote to scalar
scalarTypeField& toScalar();
//- Promote to linear
linearTypeField& toLinear();
//- Promote to square
squareTypeField& toSquare();
public:
// Static data members
static const char* const typeName;
// Constructors
//- Construct given size
explicit CoeffField(const label);
//- Construct as copy
CoeffField(const CoeffField<Type>&);
//- Construct from Istream
explicit CoeffField(Istream&);
//- Clone
tmp<CoeffField<Type> > clone() const;
// Destructor
~CoeffField();
//- Clear data
void clear();
// Member functions
//- Return size
inline label size() const;
//- Return active type
blockCoeffBase::activeLevel activeType() const;
//- Check pointers: only one type should be active (debug only)
void checkActive() const;
//- Negate this field
void negate();
//- Return the field transpose
tmp<CoeffField<Type> > transpose() const;
// Return as typed. Fails when asked for the incorrect type
//- Return as scalar field
const scalarTypeField& asScalar() const;
//- Return as linear field
const linearTypeField& asLinear() const;
//- Return as square field
const squareTypeField& asSquare() const;
// Return as typed. Fails when asked for demotion
//- Return as scalar field
scalarTypeField& asScalar();
//- Return as linear field
linearTypeField& asLinear();
//- Return as square field
squareTypeField& asSquare();
//- Return component
tmp<scalarTypeField> component(const direction) const;
//- Return coefficient as block
BlockCoeff<Type> getCoeff(const label index) const;
//- Set coefficient from a block
void setCoeff(const label index, const BlockCoeff<Type>& coeff);
// Subset operations
//- Get subset with offset and size and store in given field
void getSubset
(
CoeffField<Type>& f,
const label start,
const label size
) const;
//- Get subset with addressing and store in given field
void getSubset
(
CoeffField<Type>& f,
const labelList& addr
) const;
//- Set subset with offset and size from given field
void setSubset
(
const CoeffField<Type>& f,
const label start,
const label size
);
//- Get subset with addressing and store in target field
void setSubset
(
const CoeffField<Type>& f,
const labelList& addr
);
//- Zero out subset with offset and size
void zeroOutSubset
(
const label start,
const label size
);
//- Zero out subset with addressing
void zeroOutSubset
(
const labelList& addr
);
//- Add subset with addressing to field
void addSubset
(
const CoeffField<Type>& f,
const labelList& addr
);
//- Subtract subset with addressing to field
void subtractSubset
(
const CoeffField<Type>& f,
const labelList& addr
);
// Member operators
void operator=(const CoeffField<Type>&);
void operator=(const tmp<CoeffField<Type> >&);
void operator=(const scalarTypeField&);
void operator=(const tmp<scalarTypeField>&);
void operator=(const linearTypeField&);
void operator=(const tmp<linearTypeField>&);
void operator=(const squareTypeField&);
void operator=(const tmp<squareTypeField>&);
void operator+=(const CoeffField<Type>&);
void operator+=(const tmp<CoeffField<Type> >&);
void operator+=(const scalarTypeField&);
void operator+=(const tmp<scalarTypeField>&);
void operator+=(const linearTypeField&);
void operator+=(const tmp<linearTypeField>&);
void operator+=(const squareTypeField&);
void operator+=(const tmp<squareTypeField>&);
void operator-=(const CoeffField<Type>&);
void operator-=(const tmp<CoeffField<Type> >&);
void operator-=(const scalarTypeField&);
void operator-=(const tmp<scalarTypeField>&);
void operator-=(const linearTypeField&);
void operator-=(const tmp<linearTypeField>&);
void operator-=(const squareTypeField&);
void operator-=(const tmp<squareTypeField>&);
void operator*=(const UList<scalar>&);
void operator*=(const tmp<Field<scalar> >&);
void operator*=(const scalar&);
void operator/=(const UList<scalar>&);
void operator/=(const tmp<Field<scalar> >&);
void operator/=(const scalar&);
tmp<CoeffField<Type> > operator-();
// IOstream operators
friend Ostream& operator<< <Type>
(
Ostream&,
const CoeffField<Type>&
);
friend Ostream& operator<< <Type>
(
Ostream&,
const tmp<CoeffField<Type> >&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "CoeffFieldFunctions.H"
#ifdef NoRepository
# include "CoeffField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,342 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "BlockCoeff.H"
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
template<class Type>
Foam::tmp<Foam::CoeffField<Type> > Foam::inv(const CoeffField<Type>& f)
{
// The inverse of a linear coefficient type is currently done "by
// hand". The need for this will disappear once the diagonal tensor
// type is introduced. HJ, 24/May/2005
typedef typename CoeffField<Type>::linearTypeField fieldType;
typedef typename CoeffField<Type>::linearType valueType;
// Create result
tmp<CoeffField<Type> > tresult(new CoeffField<Type>(f.size()));
CoeffField<Type>& result = tresult();
if (f.activeType() == blockCoeffBase::SCALAR)
{
result = 1.0/f.asScalar();
}
else if (f.activeType() == blockCoeffBase::LINEAR)
{
const fieldType& lf = f.asLinear();
fieldType inverse =
cmptDivide
(
fieldType(lf.size(), pTraits<valueType>::one),
lf
);
result = inverse;
}
else if (f.activeType() == blockCoeffBase::SQUARE)
{
result = inv(f.asSquare());
}
return tresult;
}
template<class Type>
void Foam::multiply
(
Field<Type>& f,
const CoeffField<Type>& f1,
const Type& f2
)
{
if (f1.activeType() == blockCoeffBase::SCALAR)
{
f = f1.asScalar()*f2;
}
else if (f1.activeType() == blockCoeffBase::LINEAR)
{
f = cmptMultiply(f1.asLinear(), f2);
}
else if (f1.activeType() == blockCoeffBase::SQUARE)
{
f = f1.asSquare() & f2;
}
}
template<class Type>
void Foam::multiply
(
Field<Type>& f,
const CoeffField<Type>& f1,
const Field<Type>& f2
)
{
if (f1.activeType() == blockCoeffBase::SCALAR)
{
f = f1.asScalar()*f2;
}
else if (f1.activeType() == blockCoeffBase::LINEAR)
{
f = cmptMultiply(f1.asLinear(), f2);
}
else if (f1.activeType() == blockCoeffBase::SQUARE)
{
f = f1.asSquare() & f2;
}
}
template<class Type>
void Foam::multiply
(
Field<Type>& f,
const Field<Type>& f1,
const CoeffField<Type>& f2
)
{
if (f2.activeType() == blockCoeffBase::SCALAR)
{
f = f1*f2.asScalar();
}
else if (f2.activeType() == blockCoeffBase::LINEAR)
{
f = cmptMultiply(f1, f2.asLinear());
}
else if (f2.activeType() == blockCoeffBase::SQUARE)
{
f = f1 & f2.asSquare();
}
}
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
#define UNARY_OPERATOR(op, opFunc) \
\
template<class Type> \
void Foam::opFunc \
( \
CoeffField<Type>& f, \
const CoeffField<Type>& f1 \
) \
{ \
typedef CoeffField<Type> TypeCoeffField; \
\
typedef typename TypeCoeffField::scalarTypeField scalarTypeField; \
typedef typename TypeCoeffField::linearTypeField linearTypeField; \
typedef typename TypeCoeffField::squareTypeField squareTypeField; \
\
if (f.activeType() == blockCoeffBase::SCALAR) \
{ \
scalarTypeField sf = f1.asScalar(); \
sf.opFunc(); \
f = sf; \
} \
else if (f.activeType() == blockCoeffBase::LINEAR) \
{ \
linearTypeField sf = f1.asLinear(); \
sf.opFunc(); \
f = sf; \
} \
else if (f.activeType() == blockCoeffBase::SQUARE) \
{ \
squareTypeField sf = f1.asSquare(); \
sf.opFunc(); \
f = sf; \
} \
} \
\
template<class Type> \
Foam::tmp<Foam::CoeffField<Type> > Foam::operator op \
( \
const CoeffField<Type>& f1 \
) \
{ \
tmp<CoeffField<Type> > tf(new CoeffField<Type>(f1.size())); \
opFunc(tf(), f1); \
return tf; \
} \
\
template<class Type> \
Foam::tmp<Foam::CoeffField<Type> > Foam::operator op \
( \
const tmp<CoeffField<Type> >& tf1 \
) \
{ \
tmp<CoeffField<Type> > tf(tf1.ptr()); \
opFunc(tf(), tf()); \
return tf; \
}
UNARY_OPERATOR(-, negate)
#undef UNARY_OPERATOR
#define BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
\
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const CoeffField<Type1>& f1, \
const Type2& f2 \
) \
{ \
tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
opFunc(tf(), f1, f2); \
return tf; \
} \
\
\
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const CoeffField<Type1>& f1, \
const Field<Type2>& f2 \
) \
{ \
tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
opFunc(tf(), f1, f2); \
return tf; \
} \
\
\
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const Field<Type2>& f1, \
const CoeffField<Type1>& f2 \
) \
{ \
tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
opFunc(tf(), f1, f2); \
return tf; \
}
#define BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const CoeffField<Type1>& f1, \
const tmp<Field<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf(tf2.ptr()); \
opFunc(tf(), f1, tf()); \
return tf; \
}
#define BINARY_OPERATOR_FT(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const Field<Type1>& f1, \
const tmp<CoeffField<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf = f1 op tf2(); \
tf2.clear(); \
return tf; \
}
#define BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<CoeffField<Type1> >& tf1, \
const Field<Type2>& f2 \
) \
{ \
tmp<Field<Type> > tf(tf1.ptr()); \
opFunc(tf(), tf(), f2); \
return tf; \
}
#define BINARY_OPERATOR_TF(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<CoeffField<Type1> >& tf1, \
const Field<Type2>& f2 \
) \
{ \
tmp<Field<Type> > tf = tf1() op f2; \
tf1.clear(); \
return tf; \
}
#define BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<CoeffField<Type1> >& tf1, \
const tmp<Field<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf(tf1.ptr()); \
opFunc(tf(), tf(), tf2()); \
tf2.clear(); \
return tf; \
}
#define BINARY_OPERATOR_TTR(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<Field<Type1> >& tf1, \
const tmp<CoeffField<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf(tf2.ptr()); \
opFunc(tf(), tf1(), tf()); \
tf1.clear(); \
return tf; \
}
#define BINARY_OPERATOR_R(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc)
BINARY_OPERATOR_R(Type, Type, *, multiply)
#undef BINARY_OPERATOR_R
#undef BINARY_OPERATOR_FF
#undef BINARY_OPERATOR_FTR
#undef BINARY_OPERATOR_TF
#undef BINARY_OPERATOR_TTR
#undef BINARY_OPERATOR_FT
#undef BINARY_OPERATOR_TRF
#undef BINARY_OPERATOR_TRT
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -0,0 +1,197 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Generic coefficient field type.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
template<class Type>
tmp<CoeffField<Type> > inv(const CoeffField<Type>& f);
template<class Type>
void multiply
(
Field<Type>& f,
const CoeffField<Type>& f1,
const Type& f2
);
template<class Type>
void multiply
(
Field<Type>& f,
const CoeffField<Type>& f1,
const Field<Type>& f2
);
template<class Type>
void multiply
(
Field<Type>& f,
const Field<Type>& f1,
const CoeffField<Type>& f2
);
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
#define UNARY_OPERATOR(op, opFunc) \
\
template<class Type> \
void opFunc \
( \
CoeffField<Type>& f, \
const CoeffField<Type>& f1 \
); \
\
template<class Type> \
tmp<CoeffField<Type> > operator op \
( \
const CoeffField<Type>& f1 \
); \
\
template<class Type> \
tmp<CoeffField<Type> > operator op \
( \
const tmp<CoeffField<Type> >& tf1 \
);
UNARY_OPERATOR(-, negate)
#undef UNARY_OPERATOR
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
#define BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
\
template<class Type> \
tmp<Field<Type> > operator op \
( \
const CoeffField<Type1>& f1, \
const Type2& f2 \
); \
\
\
template<class Type> \
tmp<Field<Type> > operator op \
( \
const CoeffField<Type1>& f1, \
const Field<Type2>& f2 \
); \
\
\
template<class Type> \
tmp<Field<Type> > operator op \
( \
const Field<Type2>& f1, \
const CoeffField<Type1>& f2 \
);
#define BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const CoeffField<Type1>& f1, \
const tmp<Field<Type2> >& tf2 \
);
#define BINARY_OPERATOR_FT(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const Field<Type1>& f1, \
const tmp<CoeffField<Type2> >& tf2 \
);
#define BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<Field<Type1> >& tf1, \
const CoeffField<Type2>& f2 \
);
#define BINARY_OPERATOR_TF(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<CoeffField<Type1> >& tf1, \
const Field<Type2>& f2 \
);
#define BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<CoeffField<Type1> >& tf1, \
const tmp<Field<Type2> >& tf2 \
);
#define BINARY_OPERATOR_TTR(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<Field<Type1> >& tf1, \
const tmp<CoeffField<Type2> >& tf2 \
);
#define BINARY_OPERATOR_R(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc)
BINARY_OPERATOR_R(Type, Type, *, multiply)
#undef BINARY_OPERATOR_R
#undef BINARY_OPERATOR_FF
#undef BINARY_OPERATOR_FTR
#undef BINARY_OPERATOR_TF
#undef BINARY_OPERATOR_TTR
#undef BINARY_OPERATOR_FT
#undef BINARY_OPERATOR_TRF
#undef BINARY_OPERATOR_TRT
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,310 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
DecoupledCoeffField<T>
Description
Generic coefficient field type. Used in BlockLduMatrix. HJ, 2/Apr/2005
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
DecoupledCoeffField.C
\*---------------------------------------------------------------------------*/
#ifndef DecoupledCoeffField_H
#define DecoupledCoeffField_H
#include "VectorSpace.H"
#include "primitiveFields.H"
#include "blockCoeffs.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * Forward declaration of template friend fuctions * * * * * * * //
template<class Type>
class DecoupledCoeffField;
template<class Type>
Ostream& operator<<(Ostream&, const DecoupledCoeffField<Type>&);
template<class Type>
Ostream& operator<<(Ostream&, const tmp<DecoupledCoeffField<Type> >&);
/*---------------------------------------------------------------------------*\
Class DecoupledCoeffField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class DecoupledCoeffField
:
public refCount
{
public:
// Public data types
//- Component type
typedef typename BlockCoeff<Type>::scalarType scalarType;
typedef typename BlockCoeff<Type>::linearType linearType;
//- Field type
typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
private:
// Private data
//- Scalar coefficient
mutable scalarTypeField* scalarCoeffPtr_;
//- Linear coefficient
mutable linearTypeField* linearCoeffPtr_;
//- Number of elements
label size_;
// Private Member Functions
//- Check size for arithmetic operations: resizing is not allowed!
template<class Type2>
inline void checkSize(const UList<Type2>&) const;
//- Promote to scalar
scalarTypeField& toScalar();
//- Promote to linear
linearTypeField& toLinear();
public:
// Static data members
static const char* const typeName;
// Constructors
//- Construct given size
explicit DecoupledCoeffField(const label);
//- Construct as copy
DecoupledCoeffField(const DecoupledCoeffField<Type>&);
//- Construct from Istream
explicit DecoupledCoeffField(Istream&);
//- Clone
tmp<DecoupledCoeffField<Type> > clone() const;
// Destructor
~DecoupledCoeffField();
//- Clear data
void clear();
// Member functions
//- Return size
inline label size() const;
//- Return active type
blockCoeffBase::activeLevel activeType() const;
//- Check pointers: only one type should be active (debug only)
void checkActive() const;
//- Negate this field
void negate();
//- Return the field transpose
tmp<DecoupledCoeffField<Type> > transpose() const;
// Return as typed. Fails when asked for the incorrect type
//- Return as scalar field
const scalarTypeField& asScalar() const;
//- Return as linear field
const linearTypeField& asLinear() const;
// Return as typed. Fails when asked for demotion
//- Return as scalar field
scalarTypeField& asScalar();
//- Return as linear field
linearTypeField& asLinear();
//- Return component
tmp<scalarTypeField> component(const direction) const;
//- Return coefficient as block
BlockCoeff<Type> getCoeff(const label index) const;
//- Set coefficient from a block
void setCoeff(const label index, const BlockCoeff<Type>& coeff);
// Subset operations
//- Get subset with offset and size and store in given field
void getSubset
(
DecoupledCoeffField<Type>& f,
const label start,
const label size
) const;
//- Get subset with addressing and store in given field
void getSubset
(
DecoupledCoeffField<Type>& f,
const labelList& addr
) const;
//- Set subset with offset and size from given field
void setSubset
(
const DecoupledCoeffField<Type>& f,
const label start,
const label size
);
//- Get subset with addressing and store in target field
void setSubset
(
const DecoupledCoeffField<Type>& f,
const labelList& addr
);
//- Zero out subset with offset and size
void zeroOutSubset
(
const label start,
const label size
);
//- Zero out subset with addressing
void zeroOutSubset
(
const labelList& addr
);
//- Add subset with addressing to field
void addSubset
(
const DecoupledCoeffField<Type>& f,
const labelList& addr
);
// Member operators
void operator=(const DecoupledCoeffField<Type>&);
void operator=(const tmp<DecoupledCoeffField<Type> >&);
void operator=(const scalarTypeField&);
void operator=(const tmp<scalarTypeField>&);
void operator=(const linearTypeField&);
void operator=(const tmp<linearTypeField>&);
void operator+=(const DecoupledCoeffField<Type>&);
void operator+=(const tmp<DecoupledCoeffField<Type> >&);
void operator+=(const scalarTypeField&);
void operator+=(const tmp<scalarTypeField>&);
void operator+=(const linearTypeField&);
void operator+=(const tmp<linearTypeField>&);
void operator-=(const DecoupledCoeffField<Type>&);
void operator-=(const tmp<DecoupledCoeffField<Type> >&);
void operator-=(const scalarTypeField&);
void operator-=(const tmp<scalarTypeField>&);
void operator-=(const linearTypeField&);
void operator-=(const tmp<linearTypeField>&);
void operator*=(const UList<scalar>&);
void operator*=(const tmp<Field<scalar> >&);
void operator*=(const scalar&);
void operator/=(const UList<scalar>&);
void operator/=(const tmp<Field<scalar> >&);
void operator/=(const scalar&);
// IOstream operators
friend Ostream& operator<< <Type>
(
Ostream&,
const DecoupledCoeffField<Type>&
);
friend Ostream& operator<< <Type>
(
Ostream&,
const tmp<DecoupledCoeffField<Type> >&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "DecoupledCoeffFieldFunctions.H"
#ifdef NoRepository
# include "DecoupledCoeffField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,328 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "BlockCoeff.H"
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
template<class Type>
Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::inv
(
const DecoupledCoeffField<Type>& f
)
{
// The inverse of a linear coefficient type is currently done "by
// hand". The need for this will disappear once the diagonal tensor
// type is introduced. HJ, 24/May/2005
typedef typename DecoupledCoeffField<Type>::linearTypeField fieldType;
typedef typename DecoupledCoeffField<Type>::linearType valueType;
// Create result
tmp<DecoupledCoeffField<Type> > tresult
(
new DecoupledCoeffField<Type>(f.size())
);
DecoupledCoeffField<Type>& result = tresult();
if (f.activeType() == blockCoeffBase::SCALAR)
{
result = 1.0/f.asScalar();
}
else if (f.activeType() == blockCoeffBase::LINEAR)
{
const fieldType& lf = f.asLinear();
fieldType inverse =
cmptDivide
(
fieldType(lf.size(), pTraits<valueType>::one),
lf
);
result = inverse;
}
return tresult;
}
template<class Type>
void Foam::multiply
(
Field<Type>& f,
const DecoupledCoeffField<Type>& f1,
const Type& f2
)
{
if (f1.activeType() == blockCoeffBase::SCALAR)
{
f = f1.asScalar()*f2;
}
else if (f1.activeType() == blockCoeffBase::LINEAR)
{
f = cmptMultiply(f1.asLinear(), f2);
}
}
template<class Type>
void Foam::multiply
(
Field<Type>& f,
const DecoupledCoeffField<Type>& f1,
const Field<Type>& f2
)
{
if (f1.activeType() == blockCoeffBase::SCALAR)
{
f = f1.asScalar()*f2;
}
else if (f1.activeType() == blockCoeffBase::LINEAR)
{
f = cmptMultiply(f1.asLinear(), f2);
}
}
template<class Type>
void Foam::multiply
(
Field<Type>& f,
const Field<Type>& f1,
const DecoupledCoeffField<Type>& f2
)
{
if (f2.activeType() == blockCoeffBase::SCALAR)
{
f = f1*f2.asScalar();
}
else if (f2.activeType() == blockCoeffBase::LINEAR)
{
f = cmptMultiply(f1, f2.asLinear());
}
}
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
#define UNARY_OPERATOR(op, opFunc) \
\
template<class Type> \
void Foam::opFunc \
( \
DecoupledCoeffField<Type>& f, \
const DecoupledCoeffField<Type>& f1 \
) \
{ \
typedef DecoupledCoeffField<Type> TypeDecoupledCoeffField; \
\
typedef typename TypeDecoupledCoeffField::scalarTypeField scalarTypeField;\
typedef typename TypeDecoupledCoeffField::linearTypeField linearTypeField;\
\
if (f.activeType() == blockCoeffBase::SCALAR) \
{ \
scalarTypeField sf = f1.asScalar(); \
sf.opFunc(); \
f = sf; \
} \
else if (f.activeType() == blockCoeffBase::LINEAR) \
{ \
linearTypeField sf = f1.asLinear(); \
sf.opFunc(); \
f = sf; \
} \
} \
\
template<class Type> \
Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::operator op \
( \
const DecoupledCoeffField<Type>& f1 \
) \
{ \
tmp<DecoupledCoeffField<Type> > tf \
( \
new DecoupledCoeffField<Type>(f1.size()) \
); \
opFunc(tf(), f1); \
return tf; \
} \
\
template<class Type> \
Foam::tmp<Foam::DecoupledCoeffField<Type> > Foam::operator op \
( \
const tmp<DecoupledCoeffField<Type> >& tf1 \
) \
{ \
tmp<DecoupledCoeffField<Type> > tf(tf1.ptr()); \
opFunc(tf(), tf()); \
return tf; \
}
UNARY_OPERATOR(-, negate)
#undef UNARY_OPERATOR
#define BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
\
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const DecoupledCoeffField<Type1>& f1, \
const Type2& f2 \
) \
{ \
tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
opFunc(tf(), f1, f2); \
return tf; \
} \
\
\
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const DecoupledCoeffField<Type1>& f1, \
const Field<Type2>& f2 \
) \
{ \
tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
opFunc(tf(), f1, f2); \
return tf; \
} \
\
\
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const Field<Type2>& f1, \
const DecoupledCoeffField<Type1>& f2 \
) \
{ \
tmp<Field<Type> > tf(new Field<Type>(f1.size())); \
opFunc(tf(), f1, f2); \
return tf; \
}
#define BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const DecoupledCoeffField<Type1>& f1, \
const tmp<Field<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf(tf2.ptr()); \
opFunc(tf(), f1, tf()); \
return tf; \
}
#define BINARY_OPERATOR_FT(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const Field<Type1>& f1, \
const tmp<DecoupledCoeffField<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf = f1 op tf2(); \
tf2.clear(); \
return tf; \
}
#define BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<DecoupledCoeffField<Type1> >& tf1, \
const Field<Type2>& f2 \
) \
{ \
tmp<Field<Type> > tf(tf1.ptr()); \
opFunc(tf(), tf(), f2); \
return tf; \
}
#define BINARY_OPERATOR_TF(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<DecoupledCoeffField<Type1> >& tf1, \
const Field<Type2>& f2 \
) \
{ \
tmp<Field<Type> > tf = tf1() op f2; \
tf1.clear(); \
return tf; \
}
#define BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<DecoupledCoeffField<Type1> >& tf1, \
const tmp<Field<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf(tf1.ptr()); \
opFunc(tf(), tf(), tf2()); \
tf2.clear(); \
return tf; \
}
#define BINARY_OPERATOR_TTR(Type1, Type2, op, opFunc) \
template<class Type> \
Foam::tmp<Foam::Field<Type> > Foam::operator op \
( \
const tmp<Field<Type1> >& tf1, \
const tmp<DecoupledCoeffField<Type2> >& tf2 \
) \
{ \
tmp<Field<Type> > tf(tf2.ptr()); \
opFunc(tf(), tf1(), tf()); \
tf1.clear(); \
return tf; \
}
#define BINARY_OPERATOR_R(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc)
BINARY_OPERATOR_R(Type, Type, *, multiply)
#undef BINARY_OPERATOR_R
#undef BINARY_OPERATOR_FF
#undef BINARY_OPERATOR_FTR
#undef BINARY_OPERATOR_TF
#undef BINARY_OPERATOR_TTR
#undef BINARY_OPERATOR_FT
#undef BINARY_OPERATOR_TRF
#undef BINARY_OPERATOR_TRT
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -0,0 +1,197 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Generic coefficient field type.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
template<class Type>
tmp<DecoupledCoeffField<Type> > inv(const DecoupledCoeffField<Type>& f);
template<class Type>
void multiply
(
Field<Type>& f,
const DecoupledCoeffField<Type>& f1,
const Type& f2
);
template<class Type>
void multiply
(
Field<Type>& f,
const DecoupledCoeffField<Type>& f1,
const Field<Type>& f2
);
template<class Type>
void multiply
(
Field<Type>& f,
const Field<Type>& f1,
const DecoupledCoeffField<Type>& f2
);
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
#define UNARY_OPERATOR(op, opFunc) \
\
template<class Type> \
void opFunc \
( \
DecoupledCoeffField<Type>& f, \
const DecoupledCoeffField<Type>& f1 \
); \
\
template<class Type> \
tmp<DecoupledCoeffField<Type> > operator op \
( \
const DecoupledCoeffField<Type>& f1 \
); \
\
template<class Type> \
tmp<DecoupledCoeffField<Type> > operator op \
( \
const tmp<DecoupledCoeffField<Type> >& tf1 \
);
UNARY_OPERATOR(-, negate)
#undef UNARY_OPERATOR
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
#define BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
\
template<class Type> \
tmp<Field<Type> > operator op \
( \
const DecoupledCoeffField<Type1>& f1, \
const Type2& f2 \
); \
\
\
template<class Type> \
tmp<Field<Type> > operator op \
( \
const DecoupledCoeffField<Type1>& f1, \
const Field<Type2>& f2 \
); \
\
\
template<class Type> \
tmp<Field<Type> > operator op \
( \
const Field<Type2>& f1, \
const DecoupledCoeffField<Type1>& f2 \
);
#define BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const DecoupledCoeffField<Type1>& f1, \
const tmp<Field<Type2> >& tf2 \
);
#define BINARY_OPERATOR_FT(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const Field<Type1>& f1, \
const tmp<DecoupledCoeffField<Type2> >& tf2 \
);
#define BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<Field<Type1> >& tf1, \
const DecoupledCoeffField<Type2>& f2 \
);
#define BINARY_OPERATOR_TF(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<DecoupledCoeffField<Type1> >& tf1, \
const Field<Type2>& f2 \
);
#define BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<DecoupledCoeffField<Type1> >& tf1, \
const tmp<Field<Type2> >& tf2 \
);
#define BINARY_OPERATOR_TTR(Type1, Type2, op, opFunc) \
template<class Type> \
tmp<Field<Type> > operator op \
( \
const tmp<Field<Type1> >& tf1, \
const tmp<DecoupledCoeffFieldy<Type2> >& tf2 \
);
#define BINARY_OPERATOR_R(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_FTR(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRF(Type1, Type2, op, opFunc) \
BINARY_OPERATOR_TRT(Type1, Type2, op, opFunc)
BINARY_OPERATOR_R(Type, Type, *, multiply)
#undef BINARY_OPERATOR_R
#undef BINARY_OPERATOR_FF
#undef BINARY_OPERATOR_FTR
#undef BINARY_OPERATOR_TF
#undef BINARY_OPERATOR_TTR
#undef BINARY_OPERATOR_FT
#undef BINARY_OPERATOR_TRF
#undef BINARY_OPERATOR_TRT
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
coeffFields
Description
Typedefs for coefficient field
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef coeffFields_H
#define coeffFields_H
#include "scalarCoeffField.H"
#include "sphericalTensorCoeffField.H"
#include "symmTensorCoeffField.H"
#include "tensorCoeffField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef CoeffField<scalar> scalarCoeffField;
typedef CoeffField<vector> vectorCoeffField;
typedef CoeffField<sphericalTensor> sphericalTensorCoeffField;
typedef CoeffField<symmTensor> symmTensorCoeffField;
typedef CoeffField<tensor> tensorCoeffField;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,383 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
scalarCoeffField
Description
\*---------------------------------------------------------------------------*/
#include "scalarCoeffField.H"
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
const char* const Foam::CoeffField<Foam::scalar>::typeName("CoeffField");
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::blockCoeffBase::activeLevel
Foam::CoeffField<Foam::scalar>::activeType() const
{
return blockCoeffBase::SCALAR;
}
Foam::tmp<Foam::CoeffField<Foam::scalar> >
Foam::CoeffField<Foam::scalar>::transpose() const
{
return tmp<CoeffField<scalar> >(new CoeffField<scalar>(*this));
}
const Foam::scalarField&
Foam::CoeffField<Foam::scalar>::asScalar() const
{
return *this;
}
Foam::scalarField&
Foam::CoeffField<Foam::scalar>::asScalar()
{
return *this;
}
const Foam::scalarField&
Foam::CoeffField<Foam::scalar>::asLinear() const
{
return *this;
}
Foam::scalarField&
Foam::CoeffField<Foam::scalar>::asLinear()
{
return *this;
}
Foam::BlockCoeff<Foam::scalar>
Foam::CoeffField<Foam::scalar>::getCoeff(const label index) const
{
BlockCoeff<scalar> result;
result.asScalar() = (operator[](index));
return result;
}
void Foam::CoeffField<Foam::scalar>::setCoeff
(
const label index,
const BlockCoeff<scalar>& coeff
)
{
operator[](index) = coeff.asScalar();
}
void Foam::CoeffField<Foam::scalar>::getSubset
(
CoeffField<scalar>& f,
const label start,
const label size
) const
{
// Check sizes
if (f.size() != size)
{
FatalErrorIn
(
"void Foam::CoeffField<Foam::scalar>::getSubset\n"
"(\n"
" CoeffField<scalar>& f,\n"
" const label start,\n"
" const label size\n"
") const"
) << "Incompatible sizes: " << f.size() << " and " << size
<< abort(FatalError);
}
const scalarField& localF = *this;
forAll (f, fI)
{
f[fI] = localF[start + fI];
}
}
void Foam::CoeffField<Foam::scalar>::getSubset
(
CoeffField<scalar>& f,
const labelList& addr
) const
{
// Check sizes
if (f.size() != addr.size())
{
FatalErrorIn
(
"void Foam::CoeffField<Foam::scalar>::getSubset\n"
"(\n"
" CoeffField<scalar>& f,\n"
" const labelList addr\n"
") const"
) << "Incompatible sizes: " << f.size() << " and " << addr.size()
<< abort(FatalError);
}
const scalarField& localF = *this;
forAll (f, fI)
{
f[fI] = localF[addr[fI]];
}
}
void Foam::CoeffField<Foam::scalar>::setSubset
(
const CoeffField<scalar>& f,
const label start,
const label size
)
{
// Check sizes
if (f.size() != size)
{
FatalErrorIn
(
"void Foam::CoeffField<Foam::scalar>::setSubset\n"
"(\n"
" const CoeffField<scalar>& f,\n"
" const label start,\n"
" const label size\n"
")"
) << "Incompatible sizes: " << f.size() << " and " << size
<< abort(FatalError);
}
scalarField& localF = *this;
forAll (f, fI)
{
localF[start + fI] = f[fI];
}
}
void Foam::CoeffField<Foam::scalar>::setSubset
(
const CoeffField<scalar>& f,
const labelList& addr
)
{
// Check sizes
if (f.size() != addr.size())
{
FatalErrorIn
(
"void Foam::CoeffField<Foam::scalar>::setSubset\n"
"(\n"
" const CoeffField<scalar>& f,\n"
" const labelList addr\n"
")"
) << "Incompatible sizes: " << f.size() << " and " << addr.size()
<< abort(FatalError);
}
scalarField& localF = this->asScalar();
forAll (f, fI)
{
localF[addr[fI]] = f[fI];
}
}
void Foam::CoeffField<Foam::scalar>::zeroOutSubset
(
const label start,
const label size
)
{
scalarField& localF = *this;
for (label ffI = 0; ffI < size; ffI++)
{
localF[start + ffI] = pTraits<scalar>::zero;
}
}
void Foam::CoeffField<Foam::scalar>::zeroOutSubset
(
const labelList& addr
)
{
scalarField& localF = *this;
forAll (addr, ffI)
{
localF[addr[ffI]] = pTraits<scalar>::zero;
}
}
void Foam::CoeffField<Foam::scalar>::addSubset
(
const CoeffField<scalar>& f,
const labelList& addr
)
{
// Check sizes
if (f.size() != addr.size())
{
FatalErrorIn
(
"void Foam::CoeffField<Foam::scalar>::addSubset\n"
"(\n"
" const CoeffField<scalar>& f,\n"
" const labelList addr\n"
")"
) << "Incompatible sizes: " << f.size() << " and " << addr.size()
<< abort(FatalError);
}
scalarField& localF = this->asScalar();
forAll (f, fI)
{
localF[addr[fI]] += f[fI];
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::CoeffField<Foam::scalar>::operator=(const scalarField& f)
{
scalarField::operator=(f);
}
void Foam::CoeffField<Foam::scalar>::operator=(const tmp<scalarField>& tf)
{
scalarField::operator=(tf);
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const CoeffField<scalar>& f)
{
os << static_cast<const scalarField&>(f);
return os;
}
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const tmp<CoeffField<scalar> >& tf
)
{
os << tf();
tf.clear();
return os;
}
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
template<>
Foam::tmp<Foam::CoeffField<Foam::scalar> >
Foam::inv(const CoeffField<scalar>& f)
{
tmp<CoeffField<scalar> > tresult(new CoeffField<scalar>(f.size()));
scalarField& result = tresult();
result = 1.0/f;
return tresult;
}
template<>
void Foam::negate
(
CoeffField<scalar>& f,
const CoeffField<scalar>& f1
)
{
f = f1;
f.negate();
}
template<>
void Foam::multiply
(
scalarField& f,
const CoeffField<scalar>& f1,
const scalar& f2
)
{
const scalarField& sf = f1;
f = sf*f2;
}
template<>
void Foam::multiply
(
scalarField& f,
const CoeffField<scalar>& f1,
const scalarField& f2
)
{
const scalarField& sf = f1;
f = sf*f2;
}
template<>
void Foam::multiply
(
scalarField& f,
const scalarField& f1,
const CoeffField<scalar>& f2
)
{
const scalarField& sf = f2;
f = f1*sf;
}
// ************************************************************************* //

View file

@ -0,0 +1,245 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
CoeffField<T>
Description
Template specialisation for scalar coefficients
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
tensorCoeffField.C
\*---------------------------------------------------------------------------*/
#ifndef scalarCoeffField_H
#define scalarCoeffField_H
#include "CoeffField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
class CoeffField<scalar>
:
public scalarField
{
public:
// Public data types
//- Component type
typedef scalar scalarType;
typedef scalar linearType;
//- Field type
typedef scalarField scalarTypeField;
typedef scalarField linearTypeField;
// Static data members
static const char* const typeName;
// Constructors
//- Construct given size
explicit CoeffField<scalar>(const label size)
:
scalarField(size, pTraits<scalar>::zero)
{}
//- Construct as copy
CoeffField(const CoeffField<scalar>& f)
:
scalarField(f)
{}
//- Construct from Istream
CoeffField(Istream& is)
:
scalarField(is)
{}
// Member functions
//- Return active type
blockCoeffBase::activeLevel activeType() const;
//- Return the field transpose
tmp<CoeffField<scalar> > transpose() const;
// Return as typed. Fails when asked for the incorrect type
//- Return as scalar field
const scalarField& asScalar() const;
scalarField& asScalar();
//- Return as linear field. Equal to scalar field
const scalarField& asLinear() const;
scalarField& asLinear();
//- Return coefficient as a block
BlockCoeff<scalar> getCoeff(const label index) const;
//- Set coefficient from a block
void setCoeff(const label index, const BlockCoeff<scalar>& coeff);
// Subset operations
//- Get subset with offset and size and store in given field
void getSubset
(
CoeffField<scalar>& f,
const label start,
const label size
) const;
//- Get subset with addressing and store in given field
void getSubset
(
CoeffField<scalar>& f,
const labelList& addr
) const;
//- Set subset with offset and size from given field
void setSubset
(
const CoeffField<scalar>& f,
const label start,
const label size
);
//- Get subset with addressing and store in target field
void setSubset
(
const CoeffField<scalar>& f,
const labelList& addr
);
//- Zero out subset with offset and size
void zeroOutSubset
(
const label start,
const label size
);
//- Zero out subset with addressing
void zeroOutSubset
(
const labelList& addr
);
//- Add subset with addressing to field
void addSubset
(
const CoeffField<scalar>& f,
const labelList& addr
);
// Member operators
void operator=(const scalarField&);
void operator=(const tmp<scalarField>&);
// IOstream operators
friend Ostream& operator<<
(
Ostream&,
const CoeffField<scalar>&
);
friend Ostream& operator<<
(
Ostream&,
const tmp<CoeffField<scalar> >&
);
};
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
template<>
tmp<CoeffField<scalar> > inv(const CoeffField<scalar>& f);
template<>
void negate
(
CoeffField<scalar>& f,
const CoeffField<scalar>& f1
);
template<>
void multiply
(
scalarField& f,
const CoeffField<scalar>& f1,
const scalar& f2
);
template<>
void multiply
(
scalarField& f,
const CoeffField<scalar>& f1,
const scalarField& f2
);
template<>
void multiply
(
scalarField& f,
const scalarField& f1,
const CoeffField<scalar>& f2
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "sphericalTensorCoeffField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::CoeffField<Foam::sphericalTensor>::CoeffField(const label size)
:
DecoupledCoeffField<sphericalTensor>(size)
{}
Foam::CoeffField<Foam::sphericalTensor>::CoeffField
(
const CoeffField<sphericalTensor>& f
)
:
DecoupledCoeffField<sphericalTensor>(f)
{}
Foam::CoeffField<Foam::sphericalTensor>::CoeffField
(
const DecoupledCoeffField<sphericalTensor>& f
)
:
DecoupledCoeffField<sphericalTensor>(f)
{}
Foam::CoeffField<Foam::sphericalTensor>::CoeffField
(
const tmp<DecoupledCoeffField<sphericalTensor> >& tf
)
:
DecoupledCoeffField<sphericalTensor>(tf())
{}
Foam::CoeffField<Foam::sphericalTensor>::CoeffField(Istream& is)
:
DecoupledCoeffField<sphericalTensor>(is)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::CoeffField<Foam::sphericalTensor>::operator=
(
const CoeffField<sphericalTensor>& f
)
{
DecoupledCoeffField<sphericalTensor>::operator=(f);
}
void Foam::CoeffField<Foam::sphericalTensor>::operator=
(
const tmp<CoeffField<sphericalTensor> >& f
)
{
DecoupledCoeffField<sphericalTensor>::operator=(f);
}
void Foam::CoeffField<Foam::sphericalTensor>::operator=
(
const CoeffField<sphericalTensor>::scalarTypeField& f
)
{
DecoupledCoeffField<sphericalTensor>::operator=(f);
}
void Foam::CoeffField<Foam::sphericalTensor>::operator=
(
const tmp<CoeffField<sphericalTensor>::scalarTypeField>& f
)
{
DecoupledCoeffField<sphericalTensor>::operator=(f);
}
void Foam::CoeffField<Foam::sphericalTensor>::operator=
(
const CoeffField<sphericalTensor>::linearTypeField& f
)
{
DecoupledCoeffField<sphericalTensor>::operator=(f);
}
void Foam::CoeffField<Foam::sphericalTensor>::operator=
(
const tmp<CoeffField<sphericalTensor>::linearTypeField>& f
)
{
DecoupledCoeffField<sphericalTensor>::operator=(f);
}
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
Foam::tmp<Foam::CoeffField<Foam::sphericalTensor> > Foam::inv
(
const CoeffField<sphericalTensor>& f
)
{
const DecoupledCoeffField<sphericalTensor>& df = f;
return tmp<CoeffField<sphericalTensor> >
(
new CoeffField<sphericalTensor>(inv(df)())
);
}
// ************************************************************************* //

View file

@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
CoeffField<T>
Description
Template specialisation for sphericalTensor coefficients
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
sphericalTensorCoeffField.C
\*---------------------------------------------------------------------------*/
#ifndef sphericalTensorCoeffField_H
#define sphericalTensorCoeffField_H
#include "CoeffField.H"
#include "DecoupledCoeffField.H"
#include "sphericalTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
class CoeffField<sphericalTensor>
:
public DecoupledCoeffField<sphericalTensor>
{
public:
// Constructors
//- Construct given size
explicit CoeffField(const label);
//- Construct as copy
CoeffField(const CoeffField<sphericalTensor>&);
//- Construct as copy of base
explicit CoeffField(const DecoupledCoeffField<sphericalTensor>&);
//- Construct as copy of base
explicit CoeffField(const tmp<DecoupledCoeffField<sphericalTensor> >&);
//- Construct from Istream
explicit CoeffField(Istream&);
// Member operators
void operator=(const CoeffField<sphericalTensor>&);
void operator=(const tmp<CoeffField<sphericalTensor> >&);
void operator=(const scalarTypeField&);
void operator=(const tmp<scalarTypeField>&);
void operator=(const linearTypeField&);
void operator=(const tmp<linearTypeField>&);
};
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
tmp<CoeffField<sphericalTensor> > inv(const CoeffField<sphericalTensor>& f);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "symmTensorCoeffField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::CoeffField<Foam::symmTensor>::CoeffField(const label size)
:
DecoupledCoeffField<symmTensor>(size)
{}
Foam::CoeffField<Foam::symmTensor>::CoeffField
(
const CoeffField<symmTensor>& f
)
:
DecoupledCoeffField<symmTensor>(f)
{}
Foam::CoeffField<Foam::symmTensor>::CoeffField
(
const DecoupledCoeffField<symmTensor>& f
)
:
DecoupledCoeffField<symmTensor>(f)
{}
Foam::CoeffField<Foam::symmTensor>::CoeffField
(
const tmp<DecoupledCoeffField<symmTensor> >& tf
)
:
DecoupledCoeffField<symmTensor>(tf())
{}
Foam::CoeffField<Foam::symmTensor>::CoeffField(Istream& is)
:
DecoupledCoeffField<symmTensor>(is)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::CoeffField<Foam::symmTensor>::operator=
(
const CoeffField<symmTensor>& f
)
{
DecoupledCoeffField<symmTensor>::operator=(f);
}
void Foam::CoeffField<Foam::symmTensor>::operator=
(
const tmp<CoeffField<symmTensor> >& f
)
{
DecoupledCoeffField<symmTensor>::operator=(f);
}
void Foam::CoeffField<Foam::symmTensor>::operator=
(
const CoeffField<symmTensor>::scalarTypeField& f
)
{
DecoupledCoeffField<symmTensor>::operator=(f);
}
void Foam::CoeffField<Foam::symmTensor>::operator=
(
const tmp<CoeffField<symmTensor>::scalarTypeField>& f
)
{
DecoupledCoeffField<symmTensor>::operator=(f);
}
void Foam::CoeffField<Foam::symmTensor>::operator=
(
const CoeffField<symmTensor>::linearTypeField& f
)
{
DecoupledCoeffField<symmTensor>::operator=(f);
}
void Foam::CoeffField<Foam::symmTensor>::operator=
(
const tmp<CoeffField<symmTensor>::linearTypeField>& f
)
{
DecoupledCoeffField<symmTensor>::operator=(f);
}
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
Foam::tmp<Foam::CoeffField<Foam::symmTensor> > Foam::inv
(
const CoeffField<symmTensor>& f
)
{
const DecoupledCoeffField<symmTensor>& df = f;
return tmp<CoeffField<symmTensor> >
(
new CoeffField<symmTensor>(inv(df)())
);
}
// ************************************************************************* //

View file

@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
CoeffField<T>
Description
Template specialisation for symmTensor coefficients
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
symmTensorCoeffField.C
\*---------------------------------------------------------------------------*/
#ifndef symmTensorCoeffField_H
#define symmTensorCoeffField_H
#include "CoeffField.H"
#include "DecoupledCoeffField.H"
#include "symmTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
class CoeffField<symmTensor>
:
public DecoupledCoeffField<symmTensor>
{
public:
// Constructors
//- Construct given size
explicit CoeffField(const label);
//- Construct as copy
CoeffField(const CoeffField<symmTensor>&);
//- Construct as copy of base
explicit CoeffField(const DecoupledCoeffField<symmTensor>&);
//- Construct as copy of base
explicit CoeffField(const tmp<DecoupledCoeffField<symmTensor> >&);
//- Construct from Istream
explicit CoeffField(Istream&);
// Member operators
void operator=(const CoeffField<symmTensor>&);
void operator=(const tmp<CoeffField<symmTensor> >&);
void operator=(const scalarTypeField&);
void operator=(const tmp<scalarTypeField>&);
void operator=(const linearTypeField&);
void operator=(const tmp<linearTypeField>&);
};
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
tmp<CoeffField<symmTensor> > inv(const CoeffField<symmTensor>& f);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "tensorCoeffField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::CoeffField<Foam::tensor>::CoeffField(const label size)
:
DecoupledCoeffField<tensor>(size)
{}
Foam::CoeffField<Foam::tensor>::CoeffField(const CoeffField<tensor>& f)
:
DecoupledCoeffField<tensor>(f)
{}
Foam::CoeffField<Foam::tensor>::CoeffField(const DecoupledCoeffField<tensor>& f)
:
DecoupledCoeffField<tensor>(f)
{}
Foam::CoeffField<Foam::tensor>::CoeffField
(
const tmp<DecoupledCoeffField<tensor> >& tf
)
:
DecoupledCoeffField<tensor>(tf())
{}
Foam::CoeffField<Foam::tensor>::CoeffField(Istream& is)
:
DecoupledCoeffField<tensor>(is)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::CoeffField<Foam::tensor>::operator=(const CoeffField<tensor>& f)
{
DecoupledCoeffField<tensor>::operator=(f);
}
void Foam::CoeffField<Foam::tensor>::operator=
(
const tmp<CoeffField<tensor> >& f
)
{
DecoupledCoeffField<tensor>::operator=(f);
}
void Foam::CoeffField<Foam::tensor>::operator=
(
const CoeffField<tensor>::scalarTypeField& f
)
{
DecoupledCoeffField<tensor>::operator=(f);
}
void Foam::CoeffField<Foam::tensor>::operator=
(
const tmp<CoeffField<tensor>::scalarTypeField>& f
)
{
DecoupledCoeffField<tensor>::operator=(f);
}
void Foam::CoeffField<Foam::tensor>::operator=
(
const CoeffField<tensor>::linearTypeField& f
)
{
DecoupledCoeffField<tensor>::operator=(f);
}
void Foam::CoeffField<Foam::tensor>::operator=
(
const tmp<CoeffField<tensor>::linearTypeField>& f
)
{
DecoupledCoeffField<tensor>::operator=(f);
}
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
Foam::tmp<Foam::CoeffField<Foam::tensor> > Foam::inv
(
const CoeffField<tensor>& f
)
{
const DecoupledCoeffField<tensor>& df = f;
return tmp<CoeffField<tensor> >(new CoeffField<tensor>(inv(df)()));
}
// ************************************************************************* //

View file

@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
CoeffField<T>
Description
Template specialisation for tensor coefficients
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
tensorCoeffField.C
\*---------------------------------------------------------------------------*/
#ifndef tensorCoeffField_H
#define tensorCoeffField_H
#include "CoeffField.H"
#include "DecoupledCoeffField.H"
#include "tensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
class CoeffField<tensor>
:
public DecoupledCoeffField<tensor>
{
public:
// Constructors
//- Construct given size
explicit CoeffField(const label);
//- Construct as copy
CoeffField(const CoeffField<tensor>&);
//- Construct as copy of base
explicit CoeffField(const DecoupledCoeffField<tensor>&);
//- Construct as copy of base
explicit CoeffField(const tmp<DecoupledCoeffField<tensor> >&);
//- Construct from Istream
explicit CoeffField(Istream&);
// Member operators
void operator=(const CoeffField<tensor>&);
void operator=(const tmp<CoeffField<tensor> >&);
void operator=(const scalarTypeField&);
void operator=(const tmp<scalarTypeField>&);
void operator=(const linearTypeField&);
void operator=(const tmp<linearTypeField>&);
};
/* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
tmp<CoeffField<tensor> > inv(const CoeffField<tensor>& f);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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
Global functions for expansion and contraction of tensor field
to diagonal type
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#include "tensorField.H"
#include "expandTensor.H"
#define TEMPLATE
#include "FieldFunctionsM.C"
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void contractScalar(Field<scalar>& res, const UList<tensor>& f)
{
forAll (res, i)
{
contractScalar(res[i], f[i]);
}
}
void contractLinear(Field<vector>& res, const UList<tensor>& f)
{
forAll (res, i)
{
contractLinear(res[i], f[i]);
}
}
void expandScalar(Field<vector>& res, const UList<scalar>& f)
{
forAll (res, i)
{
expandScalar(res[i], f[i]);
}
}
void expandScalar(Field<tensor>& res, const UList<scalar>& f)
{
forAll (res, i)
{
expandScalar(res[i], f[i]);
}
}
void expandLinear(Field<tensor>& res, const UList<vector>& f)
{
forAll (res, i)
{
expandLinear(res[i], f[i]);
}
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "undefFieldFunctionsM.H"
// ************************************************************************* //

View file

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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
Global functions for expansion and contraction of tensor field
to diagonal type
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
expandTensorField.C
\*---------------------------------------------------------------------------*/
#ifndef expandTensorField_H
#define expandTensorField_H
#include "tensorField.H"
#define TEMPLATE
#include "FieldFunctionsM.H"
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void contractScalar(Field<scalar>& res, const UList<tensor>& f);
void contractLinear(Field<vector>& res, const UList<tensor>& f);
void expandScalar(Field<vector>& res, const UList<scalar>& f);
void expandScalar(Field<tensor>& res, const UList<scalar>& f);
void expandLinear(Field<tensor>& res, const UList<vector>& f);
} // End namespace Foam
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "undefFieldFunctionsM.H"
// ************************************************************************* //

View file

@ -0,0 +1,307 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
A storage mechanism which allows setting of the fixed value and
consequently recovering the equation for a single row of the matrix as
well as the source. The equation is taken out of the matrix using a
variant of compact matrix storage mechanism.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockConstraint.H"
#include "demandDrivenData.H"
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
template<class Type>
BlockConstraint<Type>::BlockConstraint
(
const label row,
const Type value,
const Type& fixedCmpts
)
:
rowID_(row),
value_(value),
fixedComponents_(fixedCmpts),
matrixCoeffsSet_(false),
diagCoeff_(),
upperCoeffsOwnerPtr_(NULL),
upperCoeffsNeighbourPtr_(NULL),
lowerCoeffsOwnerPtr_(NULL),
lowerCoeffsNeighbourPtr_(NULL)
{}
// Construct as copy
template<class Type>
BlockConstraint<Type>::BlockConstraint(const BlockConstraint& e)
:
rowID_(e.rowID_),
value_(e.value_),
fixedComponents_(e.fixedComponents_),
matrixCoeffsSet_(false),
upperCoeffsOwnerPtr_(NULL),
upperCoeffsNeighbourPtr_(NULL),
lowerCoeffsOwnerPtr_(NULL),
lowerCoeffsNeighbourPtr_(NULL)
{}
// Construct from Istream
template<class Type>
BlockConstraint<Type>::BlockConstraint(Istream& is)
:
rowID_(is),
value_(is),
fixedComponents_(is),
matrixCoeffsSet_(false),
upperCoeffsOwnerPtr_(NULL),
upperCoeffsNeighbourPtr_(NULL),
lowerCoeffsOwnerPtr_(NULL),
lowerCoeffsNeighbourPtr_(NULL)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
BlockConstraint<Type>::~BlockConstraint()
{
deleteDemandDrivenData(upperCoeffsOwnerPtr_);
deleteDemandDrivenData(upperCoeffsNeighbourPtr_);
deleteDemandDrivenData(lowerCoeffsOwnerPtr_);
deleteDemandDrivenData(lowerCoeffsNeighbourPtr_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const BlockCoeff<Type>& BlockConstraint<Type>::diagCoeff() const
{
if (matrixCoeffsSet_)
{
FatalErrorIn
(
"const BlockCoeff<Type>& BlockConstraint<Type>::diagCoeff() const"
) << "matrix coefficients not set"
<< abort(FatalError);
}
return diagCoeff_;
}
template<class Type>
const Type& BlockConstraint<Type>::b() const
{
if (matrixCoeffsSet_)
{
FatalErrorIn
(
"Type BlockConstraint<Type>::b() const"
) << "matrix coefficients not set"
<< abort(FatalError);
}
return b_;
}
template<class Type>
const CoeffField<Type>& BlockConstraint<Type>::upperCoeffsOwner() const
{
if (!upperCoeffsOwnerPtr_ || !matrixCoeffsSet_)
{
FatalErrorIn
(
"const CoeffField<Type>& BlockConstraint<Type>::"
"upperCoeffsOwner() const"
) << "upper matrix coefficients not set"
<< abort(FatalError);
}
return *upperCoeffsOwnerPtr_;
}
template<class Type>
const CoeffField<Type>& BlockConstraint<Type>::upperCoeffsNeighbour() const
{
if (!upperCoeffsNeighbourPtr_ || !matrixCoeffsSet_)
{
FatalErrorIn
(
"const CoeffField<Type>& BlockConstraint<Type>::"
"upperCoeffsNeighbour() const"
) << "upper matrix coefficients not set"
<< abort(FatalError);
}
return *upperCoeffsNeighbourPtr_;
}
template<class Type>
const CoeffField<Type>& BlockConstraint<Type>::lowerCoeffsOwner() const
{
if (!lowerCoeffsOwnerPtr_ || !matrixCoeffsSet_)
{
FatalErrorIn
(
"const CoeffField<Type>& BlockConstraint<Type>::"
"lowerCoeffsOwner() const"
) << "lower matrix coefficients not set"
<< abort(FatalError);
}
return *lowerCoeffsOwnerPtr_;
}
template<class Type>
const CoeffField<Type>& BlockConstraint<Type>::lowerCoeffsNeighbour() const
{
if (!lowerCoeffsNeighbourPtr_ || !matrixCoeffsSet_)
{
FatalErrorIn
(
"const CoeffField<Type>& BlockConstraint<Type>::"
"lowerCoeffsNeighbour() const"
) << "lower matrix coefficients not set"
<< abort(FatalError);
}
return *lowerCoeffsNeighbourPtr_;
}
template<class Type>
void BlockConstraint<Type>::combine
(
const BlockConstraint<Type>& e
)
{
for
(
direction cmptI = 0;
cmptI < pTraits<Type>::nComponents;
cmptI++
)
{
if
(
e.fixedComponents_.component(cmptI)
> fixedComponents_.component(cmptI)
)
{
fixedComponents_.component(cmptI) =
e.fixedComponents_.component(cmptI);
value_.replace(cmptI, e.value_.component(cmptI));
}
}
}
template<class Type>
void BlockConstraint<Type>::clearMatrix()
{
matrixCoeffsSet_ = false;
diagCoeff_.clear();
b_ = pTraits<Type>::zero;
deleteDemandDrivenData(upperCoeffsOwnerPtr_);
deleteDemandDrivenData(upperCoeffsNeighbourPtr_);
deleteDemandDrivenData(lowerCoeffsOwnerPtr_);
deleteDemandDrivenData(lowerCoeffsNeighbourPtr_);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
void BlockConstraint<Type>::operator=
(
const BlockConstraint<Type>& rhs
)
{
// Check for assignment to self
if (this == &rhs)
{
FatalErrorIn
(
"BlockConstraint::operator=(const BlockConstraint&)"
) << "attempted assignment to self"
<< abort(FatalError);
}
rowID_ = rhs.rowID_;
value_ = rhs.value_;
fixedComponents_ = rhs.fixedComponents_;
clearMatrix();
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Type>
Ostream& operator<<(Ostream& os, const BlockConstraint<Type>& e)
{
os << e.rowID_ << nl
<< e.value_ << nl
<< e.fixedComponents_ << nl;
os.check("Ostream& operator<<(Ostream&, BlockConstraint<Type>&");
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,231 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockConstraint
Description
A storage mechanism which allows setting of the fixed value and
consequently recovering the equation for a single row of the matrix as
well as the b. The equation is taken out of the matrix using a
variant of compact matrix storage mechanism.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
BlockConstraint.C
\*---------------------------------------------------------------------------*/
#ifndef BlockConstraint_H
#define BlockConstraint_H
#include "BlockCoeff.H"
#include "coeffFields.H"
#include "blockLduMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class BlockConstraint;
template<class Type>
Ostream& operator<<(Ostream&, const BlockConstraint<Type>&);
/*---------------------------------------------------------------------------*\
Class BlockConstraint Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockConstraint
{
// Public data types
typedef CoeffField<Type> TypeCoeffField;
typedef Field<Type> TypeField;
// Private data
//- Matrix row ID
label rowID_;
//- Fixed value
Type value_;
//- Fixed components (0-1) 1 = fixed, 0 = free
Type fixedComponents_;
//- Are matrix coefficients set?
bool matrixCoeffsSet_;
//- Diagonal coefficient
BlockCoeff<Type> diagCoeff_;
//- Right-hand side
Type b_;
//- Upper coefficients, owner side
TypeCoeffField* upperCoeffsOwnerPtr_;
//- Upper coefficients, neighbour side
TypeCoeffField* upperCoeffsNeighbourPtr_;
//- Lower coefficients, owner side
TypeCoeffField* lowerCoeffsOwnerPtr_;
//- Lower coefficients, neighbour side
TypeCoeffField* lowerCoeffsNeighbourPtr_;
public:
// Constructors
//- Construct from components
BlockConstraint
(
const label row,
const Type value,
const Type& fixedCmpts = pTraits<Type>::one
);
//- Construct as copy
BlockConstraint(const BlockConstraint&);
//- Construct from Istream
BlockConstraint(Istream&);
// Destructor
~BlockConstraint();
// Member Functions
//- Return matrix row ID
label rowID() const
{
return rowID_;
}
//- Return fixed value
Type value() const
{
return value_;
}
//- Return map of fixed components
const Type& fixedComponents() const
{
return fixedComponents_;
}
//- Return diagonal coefficient
const BlockCoeff<Type>& diagCoeff() const;
//- Return right-hand side
const Type& b() const;
//- Return off-diagonal coefficients
const TypeCoeffField& upperCoeffsOwner() const;
const TypeCoeffField& upperCoeffsNeighbour() const;
const TypeCoeffField& lowerCoeffsOwner() const;
const TypeCoeffField& lowerCoeffsNeighbour() const;
//- Combine with existing equation
void combine(const BlockConstraint<Type>&);
//- Set matrix coefficients
void setMatrix
(
const BlockLduMatrix<Type>& matrix,
const TypeField& x,
const TypeField& b
);
//- Eliminate equation
void eliminateEquation
(
BlockLduMatrix<Type>& matrix,
TypeField& b
) const;
//- Set x, b and diagonal in eliminated equation
void setSourceDiag
(
BlockLduMatrix<Type>&,
Field<Type>& x,
Field<Type>& b
) const;
//- Reconstruct matrix coefficients
void reconstructMatrix(BlockLduMatrix<Type>&) const;
//- Clear matrix coefficients
void clearMatrix();
// Member Operators
void operator=(const BlockConstraint<Type>&);
// Ostream Operator
friend Ostream& operator<< <Type>
(
Ostream&,
const BlockConstraint<Type>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockConstraint.C"
# include "BlockConstraintTools.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,345 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
A storage mechanism which allows setting of the fixed value and
consequently recovering the equation for a single row of the matrix as
well as b. The equation is taken out of the matrix using a
variant of compact matrix storage mechanism.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockConstraint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void BlockConstraint<Type>::setMatrix
(
const BlockLduMatrix<Type>& matrix,
const TypeField& x,
const TypeField& b
)
{
if (matrixCoeffsSet_)
{
FatalErrorIn
(
"void BlockConstraint<Type>::setMatrix\n"
"(\n"
" const BlockLduMatrix<Type>& matrix,\n"
" const TypeField& x,\n"
" const TypeField& b\n"
")"
) << "matrix coefficients already set"
<< abort(FatalError);
}
matrixCoeffsSet_ = true;
if (matrix.thereIsDiag())
{
diagCoeff_ = matrix.diag().getCoeff(rowID_);
}
b_ = b[rowID_];
const label startFaceOwn =
matrix.lduAddr().ownerStartAddr()[rowID_];
const label endFaceOwn =
matrix.lduAddr().ownerStartAddr()[rowID_ + 1];
const label ownSize = endFaceOwn - startFaceOwn;
const label startFaceNbr =
matrix.lduAddr().losortStartAddr()[rowID_];
const label endFaceNbr =
matrix.lduAddr().losortStartAddr()[rowID_ + 1];
const label nbrSize = endFaceNbr - startFaceNbr;
const unallocLabelList& losort = matrix.lduAddr().losortAddr();
// Create losort addressing
labelList losortAddr(nbrSize);
forAll (losortAddr, laI)
{
losortAddr[laI] = losort[startFaceNbr + laI];
}
if (matrix.thereIsUpper())
{
// Get the upper coefficients
const TypeCoeffField& matrixUpper = matrix.upper();
// owner side
upperCoeffsOwnerPtr_ = new TypeCoeffField(ownSize);
TypeCoeffField& uOwn = *upperCoeffsOwnerPtr_;
matrixUpper.getSubset(uOwn, startFaceOwn, ownSize);
// neighbour side
upperCoeffsNeighbourPtr_ = new TypeCoeffField(nbrSize);
TypeCoeffField& uNbr = *upperCoeffsNeighbourPtr_;
matrixUpper.getSubset(uNbr, losortAddr);
}
if (matrix.thereIsLower())
{
// Get the lower coefficients
const TypeCoeffField& matrixLower = matrix.lower();
// owner side
lowerCoeffsOwnerPtr_ = new TypeCoeffField(ownSize);
TypeCoeffField& lOwn = *lowerCoeffsOwnerPtr_;
matrixLower.getSubset(lOwn, startFaceOwn, ownSize);
// neighbour side
lowerCoeffsNeighbourPtr_ = new TypeCoeffField(nbrSize);
TypeCoeffField& lNbr = *lowerCoeffsNeighbourPtr_;
matrixLower.getSubset(lNbr, losortAddr);
}
}
template<class Type>
void BlockConstraint<Type>::eliminateEquation
(
BlockLduMatrix<Type>& matrix,
TypeField& b
) const
{
const label startFaceOwn =
matrix.lduAddr().ownerStartAddr()[rowID_];
const label endFaceOwn =
matrix.lduAddr().ownerStartAddr()[rowID_ + 1];
const label ownSize = endFaceOwn - startFaceOwn;
const label startFaceNbr =
matrix.lduAddr().losortStartAddr()[rowID_];
const label endFaceNbr =
matrix.lduAddr().losortStartAddr()[rowID_ + 1];
const label nbrSize = endFaceNbr - startFaceNbr;
const unallocLabelList& owner = matrix.lduAddr().lowerAddr();
const unallocLabelList& neighbour = matrix.lduAddr().upperAddr();
const unallocLabelList& losort = matrix.lduAddr().losortAddr();
// Create losort addressing
labelList losortAddr(nbrSize);
forAll (losortAddr, laI)
{
losortAddr[laI] = losort[startFaceNbr + laI];
}
typename BlockCoeff<Type>::multiply mult;
// My index = rowID_
if (matrix.symmetric())
{
TypeField bOwn;
TypeField bNbr;
TypeCoeffField& upperLower = matrix.upper();
upperLower.zeroOutSubset(startFaceOwn, ownSize);
upperLower.zeroOutSubset(losortAddr);
bOwn = upperCoeffsOwner()*value_;
bNbr = upperCoeffsNeighbour()*value_;
// owner side
forAll (bOwn, soI)
{
// add contribution to b of the neighbour (I am the owner)
b[neighbour[startFaceOwn + soI]] -= bOwn[soI];
}
// neighbour side
forAll (bNbr, snI)
{
// add contribution to b of owner (I am the neighbour)
b[owner[losort[startFaceNbr + snI]]] -= bNbr[snI];
}
}
else if (matrix.asymmetric())
{
// Do upper
TypeCoeffField& matrixUpper = matrix.upper();
matrixUpper.zeroOutSubset(startFaceOwn, ownSize);
TypeField bOwn = lowerCoeffsOwner()*value_;
// Do lower
TypeCoeffField& matrixLower = matrix.lower();
matrixLower.zeroOutSubset(losortAddr);
TypeField bNbr = upperCoeffsNeighbour()*value_;
// owner side
forAll (bOwn, soI)
{
// add contribution to b of the neighbour (I am the owner)
b[neighbour[startFaceOwn + soI]] -= bOwn[soI];
}
// neighbour side
forAll (bNbr, snI)
{
// add contribution to b of owner (I am the neighbour)
b[owner[losort[startFaceNbr + snI]]] -= bNbr[snI];
}
}
}
template<class Type>
void BlockConstraint<Type>::setSourceDiag
(
BlockLduMatrix<Type>& matrix,
Field<Type>& x,
Field<Type>& b
) const
{
const Type& fc = fixedComponents();
typename BlockCoeff<Type>::multiply mult;
if (mag(fc) > SMALL)
{
b[rowID()] =
cmptMultiply
(
fc,
mult(matrix.diag().getCoeff(rowID()), value())
);
// set the solution to the right value as well
x[rowID()] = cmptMultiply(fc, value());
}
}
template<class Type>
void BlockConstraint<Type>::reconstructMatrix
(
BlockLduMatrix<Type>& matrix
) const
{
if (!matrixCoeffsSet_)
{
FatalErrorIn
(
"void BlockConstraint<Type>::reconstructMatrix("
"BlockLduMatrix<Type>& matrix)"
) << "matrix coefficients not set"
<< abort(FatalError);
}
if (matrix.thereIsDiag())
{
matrix.diag().setCoeff(rowID_, diagCoeff_);
}
const label startFaceOwn =
matrix.lduAddr().ownerStartAddr()[rowID_];
const label endFaceOwn =
matrix.lduAddr().ownerStartAddr()[rowID_ + 1];
const label ownSize = endFaceOwn - startFaceOwn;
const label startFaceNbr =
matrix.lduAddr().losortStartAddr()[rowID_];
const label endFaceNbr =
matrix.lduAddr().losortStartAddr()[rowID_ + 1];
const label nbrSize = endFaceNbr - startFaceNbr;
const unallocLabelList& losort = matrix.lduAddr().losortAddr();
// Create losort addressing
labelList losortAddr(nbrSize);
forAll (losortAddr, laI)
{
losortAddr[laI] = losort[startFaceNbr + laI];
}
if (matrix.thereIsUpper())
{
// Get the upper coefficients
TypeCoeffField& matrixUpper = matrix.upper();
// owner side
const TypeCoeffField& uOwn = upperCoeffsOwner();
matrixUpper.setSubset(uOwn, startFaceOwn, ownSize);
// neighbour side
const TypeCoeffField& uNbr = upperCoeffsNeighbour();
matrixUpper.setSubset(uNbr, losortAddr);
}
if (matrix.thereIsLower())
{
// Get the lower coefficients
TypeCoeffField& matrixLower = matrix.lower();
// owner side
const TypeCoeffField& lOwn = lowerCoeffsOwner();
matrixLower.setSubset(lOwn, startFaceOwn, ownSize);
// neighbour side
const TypeCoeffField& lNbr = lowerCoeffsNeighbour();
matrixLower.setSubset(lNbr, losortAddr);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
blockConstraints
Description
A storage mechanism which allows setting of the fixed value and
consequently recovering the equation for a single row of the matrix as
well as the source. The equation is taken out of the matrix using a
variant of compact matrix storage mechanism.
File to include template specialisation for scalar
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef blockConstraints_H
#define blockConstraints_H
#include "scalarBlockConstraint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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 "scalarBlockConstraint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<>
void BlockConstraint<scalar>::combine
(
const BlockConstraint<scalar>& e
)
{
if (e.fixedComponents_ > fixedComponents_)
{
fixedComponents_ = e.fixedComponents_;
value_ = e.value_;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
scalarBlockConstraint
Description
Template specialisation for scalar block constraint
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
scalarBlockConstraint.C
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockConstraint_H
#define scalarBlockConstraint_H
#include "BlockConstraint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<>
void BlockConstraint<scalar>::combine
(
const BlockConstraint<scalar>& e
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,116 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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
BlockLduInterface
Description
An abstract base class for implicitly-coupled interface fields
e.g. processor and cyclic patch fields.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
BlockLduInterface.C
\*---------------------------------------------------------------------------*/
#ifndef BlockLduInterface_H
#define BlockLduInterface_H
#include "primitiveFieldsFwd.H"
#include "FieldField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
class BlockLduMatrix;
/*---------------------------------------------------------------------------*\
Class BlockLduInterface Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockLduInterface
{
// Private Member Functions
//- Disallow default bitwise copy construct
BlockLduInterface(const BlockLduInterface&);
//- Disallow default bitwise assignment
void operator=(const BlockLduInterface&);
public:
//- Runtime type information
TypeName("BlockLduInterface");
// Destructor
virtual ~BlockLduInterface()
{}
// Member Functions
// Coupled interface matrix update
//- Initialise matrix update
virtual void initMatrixUpdate
(
const BlockLduMatrix<Type>& matrix,
Field<Type>& Ax,
const Field<Type>& x
) const
{}
//- Update result based on interface functionality
virtual void updateMatrix
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& coeffs,
Field<Type>& Ax,
const Field<Type>& x
) const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration |
\ / A nd | Copyright held by original author
\/ 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
BlockLduInterfaceField
Description
Abstract base class for interface fields with block coefficients
Author
Ivor Clifford, ivor.clifford@gmail.com
SourceFiles
BlockLduInterfaceField.C
\*---------------------------------------------------------------------------*/
#ifndef BlockLduInterfaceField_H
#define BlockLduInterfaceField_H
#include "lduInterfaceField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
class BlockLduMatrix;
template<class Type>
class CoeffField;
/*---------------------------------------------------------------------------*\
Class BlockLduInterfaceField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockLduInterfaceField
:
public lduInterfaceField
{
// Private Member Functions
//- Disallow default bitwise copy construct
BlockLduInterfaceField(const BlockLduInterfaceField&);
//- Disallow default bitwise assignment
void operator=(const BlockLduInterfaceField&);
public:
//- Runtime Type information
TypeName("BlockLduInterfaceField");
// Constructors
//- Construct given coupled patch
BlockLduInterfaceField(const lduInterface& patch)
:
lduInterfaceField(patch)
{}
// Destructor
virtual ~BlockLduInterfaceField()
{}
// Member Functions
// Coupled interface matrix update
//- Initialise neighbour matrix update
virtual void initInterfaceMatrixUpdate
(
const Field<Type>&,
Field<Type>&,
const BlockLduMatrix<Type>&,
const CoeffField<Type>&,
const Pstream::commsTypes commsType
) const
{}
//- Update result field based on interface functionality
virtual void updateInterfaceMatrix
(
const Field<Type>&,
Field<Type>&,
const BlockLduMatrix<Type>&,
const CoeffField<Type>&,
const Pstream::commsTypes commsType
) const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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
BlockLduInterfaceFieldPtrsList
Description
List of coupled interface fields to be used in coupling.
Templated typedef workaround.
Author
Ivor Clifford, ivor.clifford@gmail.com
\*---------------------------------------------------------------------------*/
#ifndef BlockLduInterfaceFieldPtrsList_H
#define BlockLduInterfaceFieldPtrsList_H
#include "BlockLduInterfaceField.H"
#include "UPtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class T>
struct BlockLduInterfaceFieldPtrsList
{
typedef UPtrList<const BlockLduInterfaceField<T> > Type;
};
template<class T>
struct BlockLduInterfaceFieldPtrsListList
{
typedef List<typename BlockLduInterfaceFieldPtrsList<T>::Type> Type;
};
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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
BlockLduInterfaceField
Description
Abstract base class for interface fields with block coefficients
Author
Ivor Clifford, ivor.clifford@gmail.com
\*----------------------------------------------------------------------------*/
#include "BlockLduInterfaceField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTemplateTypeNameAndDebug(BlockLduInterfaceField<scalar>, 0);
defineTemplateTypeNameAndDebug(BlockLduInterfaceField<vector>, 0);
defineTemplateTypeNameAndDebug(BlockLduInterfaceField<tensor>, 0);
defineTemplateTypeNameAndDebug(BlockLduInterfaceField<sphericalTensor>, 0);
defineTemplateTypeNameAndDebug(BlockLduInterfaceField<symmTensor>, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,361 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
BlockLduMatrix is a general matrix class in which the coefficients are
stored as three arrays, one for the upper triangle, one for the
lower triangle and a third for the diagonal. Addressing object must
be supplied for the upper and lower triangles.
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockLduMatrix.H"
#include "IOstreams.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Type>
const Foam::label Foam::BlockLduMatrix<Type>::fixFillIn
(
debug::optimisationSwitch("matrixConstraintFillIn", 4)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::BlockLduMatrix<Type>::BlockLduMatrix(const lduMesh& ldu)
:
lduMesh_(ldu),
diagPtr_(NULL),
upperPtr_(NULL),
lowerPtr_(NULL),
fixedEqns_(ldu.lduAddr().size()/fixFillIn)
{}
template<class Type>
Foam::BlockLduMatrix<Type>::BlockLduMatrix(const BlockLduMatrix<Type>& A)
:
refCount(),
lduMesh_(A.lduMesh_),
diagPtr_(NULL),
upperPtr_(NULL),
lowerPtr_(NULL),
fixedEqns_(A.fixedEqns_)
{
if (A.diagPtr_)
{
diagPtr_ = new TypeCoeffField(*(A.diagPtr_));
}
if (A.upperPtr_)
{
upperPtr_ = new TypeCoeffField(*(A.upperPtr_));
}
if (A.lowerPtr_)
{
lowerPtr_ = new TypeCoeffField(*(A.lowerPtr_));
}
}
template<class Type>
Foam::BlockLduMatrix<Type>::BlockLduMatrix(BlockLduMatrix<Type>& A, bool reUse)
:
refCount(),
lduMesh_(A.lduMesh_),
diagPtr_(NULL),
upperPtr_(NULL),
lowerPtr_(NULL),
fixedEqns_(A.fixedEqns_)
{
if (reUse)
{
if (A.lowerPtr_)
{
lowerPtr_ = A.lowerPtr_;
A.lowerPtr_ = NULL;
}
if (A.diagPtr_)
{
diagPtr_ = A.diagPtr_;
A.diagPtr_ = NULL;
}
if (A.upperPtr_)
{
upperPtr_ = A.upperPtr_;
A.upperPtr_ = NULL;
}
}
else
{
if (A.diagPtr_)
{
diagPtr_ = new TypeCoeffField(*(A.diagPtr_));
}
if (A.upperPtr_)
{
upperPtr_ = new TypeCoeffField(*(A.upperPtr_));
}
if (A.lowerPtr_)
{
lowerPtr_ = new TypeCoeffField(*(A.lowerPtr_));
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::BlockLduMatrix<Type>::~BlockLduMatrix()
{
deleteDemandDrivenData(diagPtr_);
deleteDemandDrivenData(upperPtr_);
deleteDemandDrivenData(lowerPtr_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
typename Foam::BlockLduMatrix<Type>::TypeCoeffField&
Foam::BlockLduMatrix<Type>::diag()
{
if (!diagPtr_)
{
diagPtr_ = new TypeCoeffField(lduAddr().size());
}
return *diagPtr_;
}
template<class Type>
const typename Foam::BlockLduMatrix<Type>::TypeCoeffField&
Foam::BlockLduMatrix<Type>::diag() const
{
if (!diagPtr_)
{
FatalErrorIn
(
"const TypeCoeffField& BlockLduMatrix<Type>::diag() const"
) << "diagPtr_ unallocated"
<< abort(FatalError);
}
return *diagPtr_;
}
template<class Type>
typename Foam::BlockLduMatrix<Type>::TypeCoeffField&
Foam::BlockLduMatrix<Type>::upper()
{
if (!upperPtr_)
{
upperPtr_ = new TypeCoeffField(lduAddr().lowerAddr().size());
}
return *upperPtr_;
}
template<class Type>
const typename Foam::BlockLduMatrix<Type>::TypeCoeffField&
Foam::BlockLduMatrix<Type>::upper() const
{
if (!upperPtr_)
{
FatalErrorIn
(
"const TypeCoeffField& BlockLduMatrix<Type>::upper() const"
) << "upperPtr_ unallocated"
<< abort(FatalError);
}
return *upperPtr_;
}
template<class Type>
typename Foam::BlockLduMatrix<Type>::TypeCoeffField&
Foam::BlockLduMatrix<Type>::lower()
{
if (!lowerPtr_)
{
if (upperPtr_)
{
Info << "Manufacturing lower from upper transpose" << endl;
lowerPtr_ = new TypeCoeffField(upperPtr_->transpose());
}
else
{
lowerPtr_ = new TypeCoeffField(lduAddr().lowerAddr().size());
}
}
return *lowerPtr_;
}
template<class Type>
const typename Foam::BlockLduMatrix<Type>::TypeCoeffField&
Foam::BlockLduMatrix<Type>::lower() const
{
if (!lowerPtr_)
{
FatalErrorIn
(
"const TypeCoeffField& BlockLduMatrix<Type>::lower() const"
) << "lowerPtr_ unallocated"
<< abort(FatalError);
}
return *lowerPtr_;
}
template<class Type>
bool Foam::BlockLduMatrix<Type>::empty() const
{
return (!diagPtr_ && !lowerPtr_ && !upperPtr_);
}
template<class Type>
bool Foam::BlockLduMatrix<Type>::diagonal() const
{
return (diagPtr_ && !lowerPtr_ && !upperPtr_);
}
template<class Type>
bool Foam::BlockLduMatrix<Type>::symmetric() const
{
if (lowerPtr_ && !upperPtr_)
{
FatalErrorIn
(
"bool BlockLduMatrix<Type>::symmetric() const"
) << "Matrix assembly error: symmetric matrix but only lower "
<< "triangle is allocated. This is not allowed."
<< abort(FatalError);
}
return (diagPtr_ && (!lowerPtr_ && upperPtr_));
}
template<class Type>
bool Foam::BlockLduMatrix<Type>::asymmetric() const
{
return (diagPtr_ && lowerPtr_ && upperPtr_);
}
template<class Type>
bool Foam::BlockLduMatrix<Type>::componentCoupled() const
{
// Return true if the matrix coefficient couple the components
if (thereIsDiag())
{
if (diag().activeType() == blockCoeffBase::SQUARE)
{
return true;
}
}
if (thereIsUpper())
{
if (upper().activeType() == blockCoeffBase::SQUARE)
{
return true;
}
}
if (thereIsLower())
{
if (lower().activeType() == blockCoeffBase::SQUARE)
{
return true;
}
}
return false;
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template<class Type>
Foam::Ostream& Foam::operator<<(Ostream& os, const BlockLduMatrix<Type>& ldum)
{
if (ldum.diagPtr_)
{
os.writeKeyword("diagonal") << *ldum.diagPtr_ << token::END_STATEMENT << nl;
}
else
{
// Dummy write for consistency
os.writeKeyword("diagonal") << typename BlockLduMatrix<Type>::TypeCoeffField
(ldum.lduAddr().size()) << token::END_STATEMENT << nl;
}
if (ldum.upperPtr_)
{
os.writeKeyword("upper") << *ldum.upperPtr_ << token::END_STATEMENT << nl;
}
else
{
// Dummy write for consistency
os.writeKeyword("upper") << typename BlockLduMatrix<Type>::TypeCoeffField
(ldum.lduAddr().lowerAddr().size()) << token::END_STATEMENT << nl;
}
if (ldum.lowerPtr_)
{
os.writeKeyword("lower") << *ldum.lowerPtr_ << token::END_STATEMENT << nl;
}
else
{
// Dummy write for consistency
os.writeKeyword("lower") << typename BlockLduMatrix<Type>::TypeCoeffField
(ldum.lduAddr().lowerAddr().size()) << token::END_STATEMENT << nl;
}
os.check("Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&");
return os;
}
// ************************************************************************* //

View file

@ -0,0 +1,456 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduMatrix
Description
BlockLduMatrix is a general matrix class in which the coefficients are
stored as three arrays, one for the upper triangle, one for the
lower triangle and a third for the diagonal. Addressing object must
be supplied for the upper and lower triangles.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
BlockLduMatrix.C
BlockLduMatrixOperations.C
BlockLduMatrixUpdateInterfaces.C
BlockLduMatrixATmul.C
BlockLduMatrixHOps.C
BlockLduMatrixDecouple.C
BlockLduMatrixDecoupledHOps.C
\*---------------------------------------------------------------------------*/
#ifndef BlockLduMatrix_H
#define BlockLduMatrix_H
#include "coeffFields.H"
#include "FieldField.H"
#include "lduMesh.H"
#include "BlockLduInterfaceFieldPtrsList.H"
#include "Map.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * Forward declaration of template friend fuctions * * * * * * * //
template<class Type>
class BlockLduMatrix;
template<class Type>
Ostream& operator<<(Ostream&, const BlockLduMatrix<Type>&);
template<class Type>
class BlockConstraint;
/*---------------------------------------------------------------------------*\
Class BlockLduMatrix Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockLduMatrix
:
public refCount
{
public:
// Public data types
typedef CoeffField<Type> TypeCoeffField;
typedef Field<Type> TypeField;
typedef BlockConstraint<Type> ConstraintType;
private:
// Private data
// LDU mesh reference
const lduMesh& lduMesh_;
// Block matrix elements (excluding interfaces)
//- Diagonal coefficients
CoeffField<Type>* diagPtr_;
//- Upper triangle coefficients. Also used for symmetric matrix
CoeffField<Type>* upperPtr_;
//- Lower triangle coefficients
CoeffField<Type> *lowerPtr_;
// Constraints
//- Equation triangle map
mutable Map<ConstraintType> fixedEqns_;
// Private static data
//- Matrix constraint fill-in
// Equals to the estimated fraction of fixed nodes in the matrix
static const label fixFillIn;
// Private member functions
// Decoupled versions of nmatrix operations
//- Sum off-diagonal coefficients and add to diagonal,
// decoupled version
void decoupledSumDiag();
//- Sum negative off-diagonal coefficients and add to diagonal,
// decoupled version
void decoupledNegSumDiag();
//- Check matrix for diagonal dominance, decoupled version
void decoupledCheck() const;
//- Relax matrix, decoupled version
void decoupledRelax
(
const TypeField& x,
TypeField& b,
const scalar alpha
);
//- Matrix scaling with scalar field, decoupled version
void decoupledMultEqOp(const scalarField& sf);
//- Matrix multiplication without coupled interface update,
// decoupled version
void decoupledAmulCore
(
TypeField& Ax,
const TypeField& x
) const;
//- Matrix transpose multiplication without coupled interface update
// decoupled version
void decoupledTmulCore
(
TypeField& Tx,
const TypeField& x
) const;
//- Return L-U vector-matrix multiplication in row-form,
// decoupled version
tmp<TypeField> decoupledH(const TypeField& x) const;
//- Return L-U vector-matrix multiplication in off-diagonal form,
// decoupled version
tmp<TypeField> decoupledFaceH(const TypeField& x) const;
protected:
// Access to constraints
//- Return constraint map
const Map<ConstraintType>& fixedEqns() const
{
return fixedEqns_;
}
//- Return access constraint map
Map<ConstraintType>& fixedEqns()
{
return fixedEqns_;
}
public:
//- Runtime type information
TypeName("BlockLduMatrix");
// Constructors
//- Construct given addressing
explicit BlockLduMatrix(const lduMesh&);
//- Construct as copy
BlockLduMatrix(const BlockLduMatrix<Type>&);
//- Construct as copy or re-use as specified.
BlockLduMatrix(BlockLduMatrix<Type>&, bool reUse);
// Destructor
virtual ~BlockLduMatrix();
// Member functions
// Access to addressing
//- Return the LDU mesh from which the addressing is obtained
const lduMesh& mesh() const
{
return lduMesh_;
}
//- Return the LDU addressing
const lduAddressing& lduAddr() const
{
return lduMesh_.lduAddr();
}
//- Return the patch evaluation schedule
const lduSchedule& patchSchedule() const
{
return lduAddr().patchSchedule();
}
// Access to coefficients
//- Return access to diagonal coefficients
TypeCoeffField& diag();
//- Return diagonal coefficients
const TypeCoeffField& diag() const;
//- Return access to upper coefficients
// Also used for symmetric matrices
TypeCoeffField& upper();
//- Return upper coefficients
// Also used for symmetric matrices
const TypeCoeffField& upper() const;
//- Return access to lower coefficients
TypeCoeffField& lower();
//- Return lower coefficients
const TypeCoeffField& lower() const;
// Matrix structure
//- Return true if there is a diagonal
bool thereIsDiag() const
{
return (diagPtr_);
}
//- Return true if upper triangle is allocated
bool thereIsUpper() const
{
return (upperPtr_);
}
//- Return true if lower triangle is allocated
bool thereIsLower() const
{
return (lowerPtr_);
}
//- Return true if matrix is empty
bool empty() const;
//- Return true if matrix is diagonal-only
bool diagonal() const;
//- Return true if matrix is symmetric
bool symmetric() const;
//- Return true if matrix is asymmetric
bool asymmetric() const;
//- Return true if matrix is component-coupled
bool componentCoupled() const;
// Operations
//- Sum off-diagonal coefficients and add to diagonal
void sumDiag();
//- Sum negative off-diagonal coefficients and add to diagonal
void negSumDiag();
//- Check matrix for diagonal dominance
void check() const;
//- Relax matrix
void relax
(
const TypeField& x,
TypeField& b,
const scalar alpha
);
//- Matrix multiplication
void Amul
(
TypeField& Ax,
const TypeField& x,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces
) const;
//- Matrix multiplication without coupled interface update
void AmulCore
(
TypeField& Ax,
const TypeField& x
) const;
//- Matrix transpose multiplication
void Tmul
(
TypeField& Ax,
const TypeField& x,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces
) const;
//- Matrix transpose multiplication without coupled interface update
void TmulCore
(
TypeField& Ax,
const TypeField& x
) const;
//- Return decoupled b
void segregateB
(
TypeField& sMul,
const TypeField& x
) const;
// Coupled interface functionality
//- Initialise the update of coupled interfaces
// for Amul operations
void initInterfaces
(
const FieldField<CoeffField, Type>& interfaceCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
TypeField& result,
const TypeField& psi
) const;
//- Update coupled interfaces
void updateInterfaces
(
const FieldField<CoeffField, Type>& interfaceCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
TypeField& result,
const TypeField& psi
) const;
// Constraint manipulation
//- Set constrained value in a prescribed point
void setValue
(
const label eqnIndex,
const Type& value
);
// Residual calculation
//- Calculate residual
tmp<TypeField> residual
(
const TypeField& x
) const;
tmp<TypeField> residual
(
const TypeField& x,
const TypeField& b
) const;
// H-operations
//- Return L-U vector-matrix multiplication in row-form
tmp<TypeField> H(const TypeField&) const;
//- Return L-U vector-matrix multiplication in off-diagonal form
tmp<TypeField> faceH(const TypeField&) const;
// Member operators
void operator=(const BlockLduMatrix<Type>&);
void negate();
void operator+=(const BlockLduMatrix<Type>&);
void operator-=(const BlockLduMatrix<Type>&);
void operator*=(const scalarField&);
void operator*=(const scalar);
// Ostream operator
friend Ostream& operator<< <Type>
(
Ostream&,
const BlockLduMatrix<Type>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockLduMatrix.C"
# include "BlockLduMatrixOperations.C"
# include "BlockLduMatrixUpdateInterfaces.C"
# include "BlockLduMatrixATmul.C"
# include "BlockLduMatrixHOps.C"
# include "BlockLduMatrixDecouple.C"
# include "BlockLduMatrixDecoupledHOps.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,414 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Vector-matrix multiplication operations for a block matrix
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::BlockLduMatrix<Type>::Amul
(
TypeField& Ax,
const TypeField& x,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces
) const
{
Ax = pTraits<Type>::zero;
// Initialise the update of coupled interfaces
initInterfaces(boundaryCoeffs, interfaces, Ax, x);
AmulCore(Ax, x);
// Update coupled interfaces
updateInterfaces(boundaryCoeffs, interfaces, Ax, x);
}
template<class Type>
void Foam::BlockLduMatrix<Type>::AmulCore
(
TypeField& Ax,
const TypeField& x
) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
typedef typename TypeCoeffField::squareTypeField squareTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
const TypeCoeffField& Diag = this->diag();
const TypeCoeffField& Upper = this->upper();
// Diagonal multiplication, no indirection
multiply(Ax, Diag, x);
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// Use transpose upper coefficient
Ax[u[coeffI]] +=
mult(activeUpper[coeffI].T(), x[l[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeLower = Lower.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeLower[coeffI], x[l[coeffI]]);
}
}
}
// Upper multiplication
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::Tmul
(
TypeField& Ax,
const TypeField& x,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces
) const
{
Ax = pTraits<Type>::zero;
// Initialise the update of coupled interfaces
initInterfaces(boundaryCoeffs, interfaces, Ax, x);
TmulCore(Ax, x);
// Update coupled interfaces
updateInterfaces(boundaryCoeffs, interfaces, Ax, x);
}
template<class Type>
void Foam::BlockLduMatrix<Type>::TmulCore
(
TypeField& Tx,
const TypeField& x
) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
typedef typename TypeCoeffField::squareTypeField squareTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
const TypeCoeffField& Diag = this->diag();
const TypeCoeffField& Upper = this->upper();
// Diagonal multiplication, no indirection
multiply(Tx, Diag, x);
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Upper multiplication
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// Use transpose upper coefficient
Tx[l[coeffI]] +=
mult(activeUpper[coeffI].T(), x[u[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeLower[coeffI], x[u[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeLower[coeffI], x[u[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeLower = Lower.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeLower[coeffI], x[u[coeffI]]);
}
}
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::segregateB
(
TypeField& sMul,
const TypeField& x
) const
{
typedef typename TypeCoeffField::linearType linearType;
typedef typename TypeCoeffField::squareType squareType;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
typedef typename TypeCoeffField::squareTypeField squareTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
// Diagonal multiplication
if (thereIsDiag())
{
if (diag().activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeDiag = this->diag().asSquare();
linearTypeField lf(activeDiag.size());
squareTypeField sf(activeDiag.size());
// Expand and contract
contractLinear(lf, activeDiag);
expandLinear(sf, lf);
sMul -= (activeDiag - sf) & x;
}
}
// Lower multiplication
if (thereIsLower())
{
if (lower().activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeLower = this->lower().asSquare();
// Auxiliary variables used in expand/contract
linearType lt;
squareType st;
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
contractLinear(lt, activeLower[coeffI]);
expandLinear(st, lt);
sMul[u[coeffI]] -= (activeLower[coeffI] - st) & x[l[coeffI]];
}
}
}
// Upper multiplication
if (thereIsUpper())
{
if (upper().activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = this->upper().asSquare();
// Auxiliary variables used in expand/contract
linearType lt;
squareType st;
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
contractLinear(lt, activeUpper[coeffI]);
expandLinear(st, lt);
sMul[l[coeffI]] -= (activeUpper[coeffI] - st) & x[u[coeffI]];
}
// If the matrix is symmetric, the lower triangular product
// is also needed
if (symmetric())
{
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// Use transpose upper coefficient
contractLinear(lt, activeUpper[coeffI]);
expandLinear(st, lt);
sMul[u[coeffI]] -=
(activeUpper[coeffI].T() - st) & x[l[coeffI]];
}
}
}
}
}
// ************************************************************************* //

View file

@ -0,0 +1,797 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Vector-matrix multiplication operations for a block matrix
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledSumDiag()
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
TypeCoeffField& Diag = this->diag();
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (this->symmetric())
{
// Symmetric matrix: re-use upper for lower coefficients
const TypeCoeffField& Upper =
const_cast<const BlockLduMatrix<Type>&>(*this).upper();
if
(
Upper.activeType() == blockCoeffBase::LINEAR
|| Diag.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiag = Diag.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] += activeUpper[coeffI];
activeDiag[u[coeffI]] += activeUpper[coeffI];
}
}
else if
(
Upper.activeType() == blockCoeffBase::SCALAR
|| Diag.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiag = Diag.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] += activeUpper[coeffI];
activeDiag[u[coeffI]] += activeUpper[coeffI];
}
}
}
else if (this->asymmetric())
{
// Full asymmetric matrix
const TypeCoeffField& Lower =
const_cast<const BlockLduMatrix<Type>&>(*this).lower();
const TypeCoeffField& Upper =
const_cast<const BlockLduMatrix<Type>&>(*this).upper();
if
(
Lower.activeType() == blockCoeffBase::LINEAR
|| Upper.activeType() == blockCoeffBase::LINEAR
|| Diag.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeLower = Lower.asLinear();
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiag = Diag.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] += activeLower[coeffI];
activeDiag[u[coeffI]] += activeUpper[coeffI];
}
}
else if
(
Lower.activeType() == blockCoeffBase::SCALAR
|| Upper.activeType() == blockCoeffBase::SCALAR
|| Diag.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeLower = Lower.asScalar();
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiag = Diag.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] += activeLower[coeffI];
activeDiag[u[coeffI]] += activeUpper[coeffI];
}
}
}
else
{
FatalErrorIn("void BlockLduMatrix<Type>::decoupledSumDiag()")
<< "No off-diagonal available"
<< abort(FatalError);
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledNegSumDiag()
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
TypeCoeffField& Diag = this->diag();
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (this->symmetric())
{
// Symmetric matrix: re-use upper for lower coefficients
const TypeCoeffField& Upper =
const_cast<const BlockLduMatrix<Type>&>(*this).upper();
if
(
Upper.activeType() == blockCoeffBase::LINEAR
|| Diag.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiag = Diag.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] -= activeUpper[coeffI];
activeDiag[u[coeffI]] -= activeUpper[coeffI];
}
}
else if
(
Upper.activeType() == blockCoeffBase::SCALAR
|| Diag.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiag = Diag.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] -= activeUpper[coeffI];
activeDiag[u[coeffI]] -= activeUpper[coeffI];
}
}
}
else if (this->asymmetric())
{
// Full asymmetric matrix
const TypeCoeffField& Lower =
const_cast<const BlockLduMatrix<Type>&>(*this).lower();
const TypeCoeffField& Upper =
const_cast<const BlockLduMatrix<Type>&>(*this).upper();
if
(
Lower.activeType() == blockCoeffBase::LINEAR
|| Upper.activeType() == blockCoeffBase::LINEAR
|| Diag.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeLower = Lower.asLinear();
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiag = Diag.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] -= activeLower[coeffI];
activeDiag[u[coeffI]] -= activeUpper[coeffI];
}
}
else if
(
Lower.activeType() == blockCoeffBase::SCALAR
|| Upper.activeType() == blockCoeffBase::SCALAR
|| Diag.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeLower = Lower.asScalar();
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiag = Diag.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] -= activeLower[coeffI];
activeDiag[u[coeffI]] -= activeUpper[coeffI];
}
}
}
else
{
FatalErrorIn("void BlockLduMatrix<Type>::decoupledNegSumDiag()")
<< "No off-diagonal available"
<< abort(FatalError);
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledCheck() const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
// Copy the diagonal
TypeCoeffField DiagCopy(this->diag().size());
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (this->symmetric())
{
// Symmetric matrix: re-use upper for lower coefficients
const TypeCoeffField& Upper = this->upper();
if
(
Upper.activeType() == blockCoeffBase::LINEAR
|| DiagCopy.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiagCopy = DiagCopy.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiagCopy[l[coeffI]] += activeUpper[coeffI];
activeDiagCopy[u[coeffI]] += activeUpper[coeffI];
}
Info<< "void BlockLduMatrix<Type>::decoupledCheck() const : "
<< "Symmetric matrix: raw matrix difference: "
<< sum(mag(activeDiagCopy))
<< " scaled: "
<< sum(mag(activeDiagCopy))/sum(mag(this->diag().asLinear()))
<< endl;
}
else if
(
Upper.activeType() == blockCoeffBase::SCALAR
|| DiagCopy.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiagCopy = DiagCopy.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiagCopy[l[coeffI]] += activeUpper[coeffI];
activeDiagCopy[u[coeffI]] += activeUpper[coeffI];
}
Info<< "void BlockLduMatrix<Type>::decoupledCheck() const : "
<< "Symmetric matrix: raw matrix difference: "
<< sum(mag(activeDiagCopy))
<< " scaled: "
<< sum(mag(activeDiagCopy))/sum(mag(this->diag().asScalar()))
<< endl;
}
}
else if (this->asymmetric())
{
// Full asymmetric matrix
const TypeCoeffField& Lower = this->lower();
const TypeCoeffField& Upper = this->upper();
if
(
Lower.activeType() == blockCoeffBase::LINEAR
|| Upper.activeType() == blockCoeffBase::LINEAR
|| DiagCopy.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeLower = Lower.asLinear();
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiagCopy = DiagCopy.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiagCopy[l[coeffI]] += activeLower[coeffI];
activeDiagCopy[u[coeffI]] += activeUpper[coeffI];
}
Info<< "void BlockLduMatrix<Type>::decoupledCheck() const : "
<< "Asymmetric matrix: raw matrix difference: "
<< sum(mag(activeDiagCopy))
<< " scaled: "
<< sum(mag(activeDiagCopy))/sum(mag(this->diag().asLinear()))
<< endl;
}
else if
(
Lower.activeType() == blockCoeffBase::SCALAR
|| Upper.activeType() == blockCoeffBase::SCALAR
|| DiagCopy.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeLower = Lower.asScalar();
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiagCopy = DiagCopy.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiagCopy[l[coeffI]] += activeLower[coeffI];
activeDiagCopy[u[coeffI]] += activeUpper[coeffI];
}
Info<< "void BlockLduMatrix<Type>::decoupledCheck() const : "
<< "Asymmetric matrix: raw matrix difference: "
<< sum(mag(activeDiagCopy))
<< " scaled: "
<< sum(mag(activeDiagCopy))/sum(mag(this->diag().asScalar()))
<< endl;
}
}
else
{
Info<< "void BlockLduMatrix<Type>::decoupledCheck() const : "
<< "Diagonal matrix" << endl;
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledRelax
(
const TypeField& x,
TypeField& b,
const scalar alpha
)
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
//HJ Missing code: add coupling coefficients to under-relaxation
// HJ, 21/Feb/2008
if (alpha <= 0)
{
return;
}
TypeCoeffField& Diag = this->diag();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (this->symmetric())
{
// Symmetric matrix: re-use upper for lower coefficients
const TypeCoeffField& Upper =
const_cast<const BlockLduMatrix<Type>&>(*this).upper();
if
(
Upper.activeType() == blockCoeffBase::LINEAR
|| Diag.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiag = Diag.asLinear();
// Make a copy of diagonal before relaxation
linearTypeField activeDiagOld = activeDiag;
linearTypeField sumOff
(
activeDiag.size(),
pTraits<typename TypeCoeffField::linearType>::zero
);
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
sumOff[u[coeffI]] += cmptMag(activeUpper[coeffI]);
sumOff[l[coeffI]] += cmptMag(activeUpper[coeffI]);
}
activeDiag = max(activeDiag, sumOff);
activeDiag *= 1.0/alpha;
// Add the relaxation contribution to b
forAll (b, i)
{
b[i] += mult(activeDiag[i] - activeDiagOld[i], x[i]);
}
}
else if
(
Upper.activeType() == blockCoeffBase::SCALAR
|| Diag.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiag = Diag.asScalar();
// Make a copy of diagonal before relaxation
scalarTypeField activeDiagOld = activeDiag;
scalarTypeField sumOff
(
activeDiag.size(),
pTraits<typename TypeCoeffField::scalarType>::zero
);
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
sumOff[u[coeffI]] += mag(activeUpper[coeffI]);
sumOff[l[coeffI]] += mag(activeUpper[coeffI]);
}
activeDiag = max(activeDiag, sumOff);
activeDiag *= 1.0/alpha;
// Add the relaxation contribution to b
forAll (b, i)
{
b[i] += mult(activeDiag[i] - activeDiagOld[i], x[i]);
}
}
}
else if (this->asymmetric())
{
// Full asymmetric matrix
const TypeCoeffField& Lower =
const_cast<const BlockLduMatrix<Type>&>(*this).lower();
const TypeCoeffField& Upper =
const_cast<const BlockLduMatrix<Type>&>(*this).upper();
if
(
Lower.activeType() == blockCoeffBase::LINEAR
|| Upper.activeType() == blockCoeffBase::LINEAR
|| Diag.activeType() == blockCoeffBase::LINEAR
)
{
const linearTypeField& activeLower = Lower.asLinear();
const linearTypeField& activeUpper = Upper.asLinear();
linearTypeField& activeDiag = Diag.asLinear();
linearTypeField sumOff
(
activeDiag.size(),
pTraits<typename TypeCoeffField::linearType>::zero
);
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
sumOff[u[coeffI]] += cmptMag(activeLower[coeffI]);
sumOff[l[coeffI]] += cmptMag(activeUpper[coeffI]);
}
activeDiag = max(activeDiag, sumOff);
activeDiag *= 1.0/alpha;
}
else if
(
Lower.activeType() == blockCoeffBase::SCALAR
|| Upper.activeType() == blockCoeffBase::SCALAR
|| Diag.activeType() == blockCoeffBase::SCALAR
)
{
const scalarTypeField& activeLower = Lower.asScalar();
const scalarTypeField& activeUpper = Upper.asScalar();
scalarTypeField& activeDiag = Diag.asScalar();
// Make a copy of diagonal before relaxation
scalarTypeField activeDiagOld = activeDiag;
scalarTypeField sumOff
(
activeDiag.size(),
pTraits<typename TypeCoeffField::scalarType>::zero
);
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
sumOff[u[coeffI]] += mag(activeLower[coeffI]);
sumOff[l[coeffI]] += mag(activeUpper[coeffI]);
}
activeDiag = max(activeDiag, sumOff);
activeDiag *= 1.0/alpha;
forAll (b, i)
{
b[i] += (activeDiag[i] - activeDiagOld[i])*x[i];
}
}
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledMultEqOp(const scalarField& sf)
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
if (diagPtr_)
{
*diagPtr_ *= sf;
}
if (upperPtr_)
{
TypeCoeffField& Upper = *upperPtr_;
const unallocLabelList& l = lduAddr().lowerAddr();
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeUpper[coeffI] *= sf[l[coeffI]];
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeUpper[coeffI] *= sf[l[coeffI]];
}
}
}
if (lowerPtr_)
{
TypeCoeffField& Lower = *lowerPtr_;
const unallocLabelList& u = lduAddr().upperAddr();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
activeLower[coeffI] *= sf[u[coeffI]];
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
activeLower[coeffI] *= sf[u[coeffI]];
}
}
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledAmulCore
(
TypeField& Ax,
const TypeField& x
) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
// In order to do automatic multiplication, diagonal needs to be recognised
// as a decoupled coeff field. HJ, 19/Feb/2008
// const TypeCoeffField& Diag = this->diag();
const DecoupledCoeffField<Type>& Diag = this->diag();
const TypeCoeffField& Upper = this->upper();
// Diagonal multiplication, no indirection
multiply(Ax, Diag, x);
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[u[coeffI]] += mult(activeLower[coeffI], x[l[coeffI]]);
}
}
}
// Upper multiplication
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Ax[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::decoupledTmulCore
(
TypeField& Tx,
const TypeField& x
) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
// In order to do automatic multiplication, diagonal needs to be recognised
// as a decoupled coeff field. HJ, 19/Feb/2008
const DecoupledCoeffField<Type>& Diag = this->diag();
const TypeCoeffField& Upper = this->upper();
// Diagonal multiplication, no indirection
multiply(Tx, Diag, x);
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Upper multiplication
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[u[coeffI]] += mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeLower[coeffI], x[u[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
Tx[l[coeffI]] += mult(activeLower[coeffI], x[u[coeffI]]);
}
}
}
}
// ************************************************************************* //

View file

@ -0,0 +1,213 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Vector-matrix multiplication operations for a block matrix
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::Field<Type> >
Foam::BlockLduMatrix<Type>::decoupledH(const Field<Type>& x) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
// Create result
tmp<Field<Type> > tresult
(
new Field<Type>(lduAddr().size(), pTraits<Type>::zero)
);
Field<Type>& result = tresult();
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
const TypeCoeffField& Upper = this->upper();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
}
}
}
// Upper multiplication
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
return tresult;
}
template<class Type>
Foam::tmp<Foam::Field<Type> >
Foam::BlockLduMatrix<Type>::decoupledFaceH(const Field<Type>& x) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
// Create result
tmp<Field<Type> > tresult(new Field<Type>(u.size(), pTraits<Type>::zero));
Field<Type>& result = tresult();
const TypeCoeffField& Upper = this->upper();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// This can be optimised with a subtraction.
// Currently not done for clarity. HJ, 31/Oct/2007
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// This can be optimised with a subtraction.
// Currently not done for clarity. HJ, 31/Oct/2007
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeLower[coeffI], x[l[coeffI]]);
}
}
}
return tresult;
}
// ************************************************************************* //

View file

@ -0,0 +1,273 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Vector-matrix multiplication operations for a block matrix
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::Field<Type> >
Foam::BlockLduMatrix<Type>::H(const Field<Type>& x) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
typedef typename TypeCoeffField::squareTypeField squareTypeField;
// Create result
tmp<Field<Type> > tresult
(
new Field<Type>(lduAddr().size(), pTraits<Type>::zero)
);
Field<Type>& result = tresult();
if (this->thereIsUpper())
{
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
const TypeCoeffField& Upper = this->upper();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// Use transpose upper coefficient
result[u[coeffI]] -=
mult(activeUpper[coeffI].T(), x[l[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeLower = Lower.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[u[coeffI]] -= mult(activeLower[coeffI], x[l[coeffI]]);
}
}
}
// Upper multiplication
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[l[coeffI]] -= mult(activeUpper[coeffI], x[u[coeffI]]);
}
}
}
return tresult;
}
template<class Type>
Foam::tmp<Foam::Field<Type> >
Foam::BlockLduMatrix<Type>::faceH(const Field<Type>& x) const
{
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
typedef typename TypeCoeffField::squareTypeField squareTypeField;
const unallocLabelList& u = lduAddr().upperAddr();
const unallocLabelList& l = lduAddr().lowerAddr();
// Create result
tmp<Field<Type> > tresult(new Field<Type>(u.size(), pTraits<Type>::zero));
Field<Type>& result = tresult();
if (this->thereIsUpper())
{
const TypeCoeffField& Upper = this->upper();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
// Lower multiplication
if (symmetric())
{
if (Upper.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// This can be optimised with a subtraction.
// Currently not done for clarity. HJ, 31/Oct/2007
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// This can be optimised with a subtraction.
// Currently not done for clarity. HJ, 31/Oct/2007
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeUpper[coeffI], x[l[coeffI]]);
}
}
else if (Upper.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
// Use transpose upper coefficient
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeUpper[coeffI].T(), x[l[coeffI]]);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& Lower = this->lower();
if (Lower.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeUpper = Upper.asScalar();
const scalarTypeField& activeLower = Lower.asScalar();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeUpper = Upper.asLinear();
const linearTypeField& activeLower = Lower.asLinear();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeLower[coeffI], x[l[coeffI]]);
}
}
else if (Lower.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeUpper = Upper.asSquare();
const squareTypeField& activeLower = Lower.asSquare();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
result[coeffI] =
mult(activeUpper[coeffI], x[u[coeffI]])
- mult(activeLower[coeffI], x[l[coeffI]]);
}
}
}
}
return tresult;
}
// ************************************************************************* //

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,204 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Update of block interfaces
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::BlockLduMatrix<Type>::initInterfaces
(
const FieldField<CoeffField, Type>& interfaceCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
TypeField& result,
const TypeField& psi
) const
{
if
(
Pstream::defaultCommsType == Pstream::blocking
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
forAll (interfaces, interfaceI)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].initInterfaceMatrixUpdate
(
psi,
result,
*this,
interfaceCoeffs[interfaceI],
Pstream::defaultCommsType
);
}
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
{
const lduSchedule& patchSchedule = this->patchSchedule();
// Loop over the "global" patches are on the list of interfaces but
// beyond the end of the schedule which only handles "normal" patches
for
(
label interfaceI=patchSchedule.size()/2;
interfaceI<interfaces.size();
interfaceI++
)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].initInterfaceMatrixUpdate
(
psi,
result,
*this,
interfaceCoeffs[interfaceI],
Pstream::blocking
);
}
}
}
else
{
FatalErrorIn("BlockLduMatrix<Type>::initMatrixInterfaces")
<< "Unsuported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType]
<< exit(FatalError);
}
}
template<class Type>
void Foam::BlockLduMatrix<Type>::updateInterfaces
(
const FieldField<CoeffField, Type>& interfaceCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
TypeField& result,
const TypeField& psi
) const
{
if
(
Pstream::defaultCommsType == Pstream::blocking
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
// Block until all sends/receives have been finished
if (Pstream::defaultCommsType == Pstream::nonBlocking)
{
IPstream::waitRequests();
OPstream::waitRequests();
}
forAll (interfaces, interfaceI)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].updateInterfaceMatrix
(
psi,
result,
*this,
interfaceCoeffs[interfaceI],
Pstream::defaultCommsType
);
}
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
{
const lduSchedule& patchSchedule = this->patchSchedule();
// Loop over all the "normal" interfaces relating to standard patches
forAll (patchSchedule, i)
{
label interfaceI = patchSchedule[i].patch;
if (interfaces.set(interfaceI))
{
if (patchSchedule[i].init)
{
interfaces[interfaceI].initInterfaceMatrixUpdate
(
psi,
result,
*this,
interfaceCoeffs[interfaceI],
Pstream::scheduled
);
}
else
{
interfaces[interfaceI].updateInterfaceMatrix
(
psi,
result,
*this,
interfaceCoeffs[interfaceI],
Pstream::scheduled
);
}
}
}
// Loop over the "global" patches are on the list of interfaces but
// beyond the end of the schedule which only handles "normal" patches
for
(
label interfaceI=patchSchedule.size()/2;
interfaceI<interfaces.size();
interfaceI++
)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].updateInterfaceMatrix
(
psi,
result,
*this,
interfaceCoeffs[interfaceI],
Pstream::blocking
);
}
}
}
else
{
FatalErrorIn("BlockLduMatrix<Type>::updateMatrixInterfaces")
<< "Unsuported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType]
<< exit(FatalError);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Block matrix member static data members
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineNamedTemplateTypeNameAndDebug(blockScalarMatrix, 0);
defineNamedTemplateTypeNameAndDebug(blockVectorMatrix, 0);
defineNamedTemplateTypeNameAndDebug(blockSphericalTensorMatrix, 0);
defineNamedTemplateTypeNameAndDebug(blockSymmTensorMatrix, 0);
defineNamedTemplateTypeNameAndDebug(blockTensorMatrix, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,68 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduMatrix
Description
Typedefs for block matrices
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef blockLduMatrices_H
#define blockLduMatrices_H
#include "scalarBlockLduMatrix.H"
#include "sphericalTensorBlockLduMatrix.H"
#include "symmTensorBlockLduMatrix.H"
#include "tensorBlockLduMatrix.H"
#include "Map.H"
#include "blockConstraints.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockLduMatrix<scalar> blockScalarMatrix;
typedef BlockLduMatrix<vector> blockVectorMatrix;
typedef BlockLduMatrix<sphericalTensor> blockSphericalTensorMatrix;
typedef BlockLduMatrix<symmTensor> blockSymmTensorMatrix;
typedef BlockLduMatrix<tensor> blockTensorMatrix;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,423 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void BlockLduMatrix<scalar>::sumDiag()
{
scalarField& activeDiag = this->diag();
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (symmetric())
{
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] += activeUpper[coeffI];
activeDiag[u[coeffI]] += activeUpper[coeffI];
}
}
else if (asymmetric())
{
const scalarField& activeLower = this->lower();
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] += activeLower[coeffI];
activeDiag[u[coeffI]] += activeUpper[coeffI];
}
}
else
{
FatalErrorIn("void BlockLduMatrix<scalar>::sumDiag()")
<< "No off-diagonal available"
<< abort(FatalError);
}
}
template<>
void BlockLduMatrix<scalar>::negSumDiag()
{
scalarField& activeDiag = this->diag();
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (symmetric())
{
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] -= activeUpper[coeffI];
activeDiag[u[coeffI]] -= activeUpper[coeffI];
}
}
else if (asymmetric())
{
const scalarField& activeLower = this->lower();
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiag[l[coeffI]] -= activeLower[coeffI];
activeDiag[u[coeffI]] -= activeUpper[coeffI];
}
}
else
{
FatalErrorIn("void BlockLduMatrix<scalar>::negSumDiag()")
<< "No off-diagonal available"
<< abort(FatalError);
}
}
template<>
void BlockLduMatrix<scalar>::check() const
{
// Copy the diagonal
scalarField activeDiagCopy = this->diag();
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
if (symmetric())
{
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiagCopy[l[coeffI]] -= activeUpper[coeffI];
activeDiagCopy[u[coeffI]] -= activeUpper[coeffI];
}
Info<< "void BlockLduMatrix<scalar>::check() const : "
<< "Symmetric matrix: raw matrix difference: "
<< sum(mag(activeDiagCopy))
<< " scaled: "
<< sum(mag(activeDiagCopy))/sum(mag(this->diag()))
<< endl;
}
else if (asymmetric())
{
const scalarField& activeLower = this->lower();
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeDiagCopy[l[coeffI]] -= activeLower[coeffI];
activeDiagCopy[u[coeffI]] -= activeUpper[coeffI];
}
Info<< "void BlockLduMatrix<scalar>::check() const : "
<< "Asymmetric matrix: raw matrix difference: "
<< sum(mag(activeDiagCopy))
<< " scaled: "
<< sum(mag(activeDiagCopy))/sum(mag(this->diag()))
<< endl;
}
else
{
Info<< "void BlockLduMatrix<scalar>::check() const : "
<< "Diagonal matrix" << endl;
}
}
template<>
void BlockLduMatrix<scalar>::relax
(
const scalarField& x,
scalarField& b,
const scalar alpha
)
{
scalarField& activeDiag = this->diag();
scalarField activeDiagOld = this->diag();
const unallocLabelList& l = lduAddr().lowerAddr();
const unallocLabelList& u = lduAddr().upperAddr();
scalarField sumOff(activeDiag.size(), 0.0);
if (symmetric())
{
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
sumOff[u[coeffI]] += mag(activeUpper[coeffI]);
sumOff[l[coeffI]] += mag(activeUpper[coeffI]);
}
}
else if (asymmetric())
{
const scalarField& activeLower = this->lower();
const scalarField& activeUpper = this->upper();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
sumOff[u[coeffI]] += mag(activeLower[coeffI]);
sumOff[l[coeffI]] += mag(activeUpper[coeffI]);
}
}
activeDiag = max(activeDiag, sumOff);
activeDiag *= 1.0/alpha;
// Add the relaxation contribution to b
b += (activeDiag - activeDiagOld)*x;
}
template<>
void BlockLduMatrix<scalar>::operator*=(const scalarField& sf)
{
if (diagPtr_)
{
*diagPtr_ *= sf;
}
if (upperPtr_)
{
scalarField& activeUpper = *upperPtr_;
const unallocLabelList& l = lduAddr().lowerAddr();
for (register label coeffI = 0; coeffI < l.size(); coeffI++)
{
activeUpper[coeffI] *= sf[l[coeffI]];
}
}
if (lowerPtr_)
{
scalarField& activeLower = *lowerPtr_;
const unallocLabelList& u = lduAddr().upperAddr();
for (register label coeffI = 0; coeffI < u.size(); coeffI++)
{
activeLower[coeffI] *= sf[u[coeffI]];
}
}
}
template<>
void BlockLduMatrix<scalar>::AmulCore
(
scalarField& Ax,
const scalarField& x
) const
{
const scalarField& Diag = diag();
for (register label rowI = 0; rowI < x.size(); rowI++)
{
Ax[rowI] = Diag[rowI]*x[rowI];
}
// Note: pointer looping
const label* const __restrict__ U = lduAddr().upperAddr().begin();
const label* const __restrict__ L = lduAddr().lowerAddr().begin();
if (symmetric())
{
const scalar* const __restrict__ Upper = upper().begin();
const scalar* const __restrict__ X = x.begin();
scalar* __restrict__ AX = Ax.begin();
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
AX[U[coeffI]] += Upper[coeffI]*X[L[coeffI]];
AX[L[coeffI]] += Upper[coeffI]*X[U[coeffI]];
}
}
else if (asymmetric())
{
const scalar* const __restrict__ Lower = lower().begin();
const scalar* const __restrict__ Upper = upper().begin();
const scalar* const __restrict__ X = x.begin();
scalar* __restrict__ AX = Ax.begin();
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
AX[U[coeffI]] += Lower[coeffI]*X[L[coeffI]];
AX[L[coeffI]] += Upper[coeffI]*X[U[coeffI]];
}
}
}
template<>
void BlockLduMatrix<scalar>::TmulCore
(
scalarField& Tx,
const scalarField& x
) const
{
const scalarField& Diag = diag();
for (register label rowI = 0; rowI < x.size(); rowI++)
{
Tx[rowI] = Diag[rowI]*x[rowI];
}
// Note: pointer looping
const label* const __restrict__ U = lduAddr().upperAddr().begin();
const label* const __restrict__ L = lduAddr().lowerAddr().begin();
if (symmetric())
{
const scalar* const __restrict__ Upper = upper().begin();
const scalar* const __restrict__ X = x.begin();
scalar* __restrict__ TX = Tx.begin();
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
TX[U[coeffI]] += Upper[coeffI]*X[L[coeffI]];
TX[L[coeffI]] += Upper[coeffI]*X[U[coeffI]];
}
}
else if (asymmetric())
{
const scalar* const __restrict__ Lower = lower().begin();
const scalar* const __restrict__ Upper = upper().begin();
const scalar* const __restrict__ X = x.begin();
scalar* __restrict__ TX = Tx.begin();
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
TX[U[coeffI]] += Upper[coeffI]*X[L[coeffI]];
TX[L[coeffI]] += Lower[coeffI]*X[U[coeffI]];
}
}
}
template<>
void BlockLduMatrix<scalar>::segregateB
(
scalarField&,
const scalarField&
) const
{
FatalErrorIn
(
"void BlockLduMatrix<scalar>::segregateB\n"
"(\n"
" scalarField&,\n"
" const scalarField&\n"
") const"
) << "Requested decoupling of scalar matrix - never coupled"
<< abort(FatalError);
}
template<>
tmp<scalarField> BlockLduMatrix<scalar>::H(const scalarField& x) const
{
tmp<scalarField> tresult(new scalarField(lduAddr().size(), 0));
scalarField& result = tresult();
if (thereIsUpper() || thereIsLower())
{
// Note: pointer looping
const label* const __restrict__ U = lduAddr().upperAddr().begin();
const label* const __restrict__ L = lduAddr().lowerAddr().begin();
const scalar* const __restrict__ Lower = lower().begin();
const scalar* const __restrict__ Upper = upper().begin();
const scalar* const __restrict__ X = x.begin();
scalar* __restrict__ R = result.begin();
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
R[U[coeffI]] -= Upper[coeffI]*X[U[coeffI]];
}
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
R[L[coeffI]] -= Lower[coeffI]*X[L[coeffI]];
}
}
return tresult;
}
template<>
tmp<scalarField> BlockLduMatrix<scalar>::faceH(const scalarField& x) const
{
tmp<scalarField> tresult(new scalarField(lduAddr().upperAddr().size(), 0));
scalarField& result = tresult();
if (thereIsUpper() || thereIsLower())
{
// Note: pointer looping
const label* const __restrict__ U = lduAddr().upperAddr().begin();
const label* const __restrict__ L = lduAddr().lowerAddr().begin();
const scalar* const __restrict__ Lower = lower().begin();
const scalar* const __restrict__ Upper = upper().begin();
const scalar* const __restrict__ X = x.begin();
scalar* __restrict__ R = result.begin();
for (register label coeffI = 0; coeffI < upper().size(); coeffI++)
{
R[coeffI] = Upper[coeffI]*X[U[coeffI]] - Lower[coeffI]*X[L[coeffI]];
}
}
return tresult;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduMatrix
Description
Template specialisation for scalar block matrix
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
scalarBlockLduMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockLduMatrix_H
#define scalarBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void BlockLduMatrix<scalar>::sumDiag();
template<>
void BlockLduMatrix<scalar>::negSumDiag();
template<>
void BlockLduMatrix<scalar>::check() const;
template<>
void BlockLduMatrix<scalar>::relax
(
const scalarField& x,
scalarField& b,
const scalar alpha
);
template<>
void BlockLduMatrix<scalar>::operator*=(const scalarField& sf);
template<>
void BlockLduMatrix<scalar>::AmulCore
(
scalarField& mul,
const scalarField& x
) const;
template<>
void BlockLduMatrix<scalar>::TmulCore
(
scalarField& mul,
const scalarField& x
) const;
template<>
void BlockLduMatrix<scalar>::segregateB
(
scalarField& mul,
const scalarField& x
) const;
template<>
tmp<scalarField> BlockLduMatrix<scalar>::H(const scalarField& x) const;
template<>
tmp<scalarField> BlockLduMatrix<scalar>::faceH(const scalarField& x) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,206 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Update of block interfaces
\*---------------------------------------------------------------------------*/
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// TODO - This code is currently not called so we have specialized
// initInterfaceMatrixUpdate in processorFvPatchScalarfield. This needs to be fixed
template<>
void Foam::BlockLduMatrix<scalar>::initInterfaces
(
const FieldField<CoeffField, scalar>& coupleCoeffs,
scalarField& result,
const scalarField& psi
) const
{
if
(
Pstream::defaultCommsType == Pstream::blocking
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
forAll (interfaces, interfaceI)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].initInterfaceMatrixUpdate
(
psi,
result,
*this,
coupleCoeffs[interfaceI].asScalar(),
Pstream::defaultCommsType
);
}
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
{
const lduSchedule& patchSchedule = this->patchSchedule();
// Loop over the "global" patches are on the list of interfaces but
// beyond the end of the schedule which only handles "normal" patches
for
(
label interfaceI=patchSchedule.size()/2;
interfaceI<interfaces.size();
interfaceI++
)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].initInterfaceMatrixUpdate
(
psi,
result,
*this,
coupleCoeffs[interfaceI].asScalar(),
Pstream::blocking
);
}
}
}
else
{
FatalErrorIn("BlockLduMatrix<scalar>::initMatrixInterfaces")
<< "Unsuported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType]
<< exit(FatalError);
}
}
template<>
void Foam::BlockLduMatrix<scalar>::updateInterfaces
(
const FieldField<CoeffField, scalar>& coupleCoeffs,
scalarField& result,
const scalarField& psi
) const
{
if
(
Pstream::defaultCommsType == Pstream::blocking
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
// Block until all sends/receives have been finished
if (Pstream::defaultCommsType == Pstream::nonBlocking)
{
IPstream::waitRequests();
OPstream::waitRequests();
}
forAll (interfaces, interfaceI)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].updateInterfaceMatrix
(
psi,
result,
*this,
coupleCoeffs[interfaceI].asScalar(),
Pstream::defaultCommsType
);
}
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
{
const lduSchedule& patchSchedule = this->patchSchedule();
// Loop over all the "normal" interfaces relating to standard patches
forAll (patchSchedule, i)
{
label interfaceI = patchSchedule[i].patch;
if (interfaces.set(interfaceI))
{
if (patchSchedule[i].init)
{
interfaces[interfaceI].initInterfaceMatrixUpdate
(
psi,
result,
*this,
coupleCoeffs[interfaceI].asScalar(),
Pstream::scheduled
);
}
else
{
interfaces[interfaceI].updateInterfaceMatrix
(
psi,
result,
*this,
coupleCoeffs[interfaceI].asScalar(),
Pstream::scheduled
);
}
}
}
// Loop over the "global" patches are on the list of interfaces but
// beyond the end of the schedule which only handles "normal" patches
for
(
label interfaceI=patchSchedule.size()/2;
interfaceI<interfaces.size();
interfaceI++
)
{
if (interfaces.set(interfaceI))
{
interfaces[interfaceI].updateInterfaceMatrix
(
psi,
result,
*this,
coupleCoeffs[interfaceI].asScalar(),
Pstream::blocking
);
}
}
}
else
{
FatalErrorIn("BlockLduMatrix<scalar>::updateMatrixInterfaces")
<< "Unsuported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType]
<< exit(FatalError);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,159 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#ifndef sphericalTensorBlockLduMatrix_H
#define sphericalTensorBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::sumDiag()
{
// Decoupled version
this->decoupledSumDiag();
}
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::negSumDiag()
{
// Decoupled version
this->decoupledNegSumDiag();
}
template<>
void Foam::BlockLduMatrix<sphericalTensor>::check() const
{
// Decoupled version
this->decoupledCheck();
}
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::relax
(
const sphericalTensorField& x,
sphericalTensorField& b,
const scalar alpha
)
{
// Decoupled version
this->decoupledRelax(x, b, alpha);
}
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::operator*=
(
const scalarField& sf
)
{
// Decoupled version
this->decoupledMultEqOp(sf);
}
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::AmulCore
(
sphericalTensorField& Ax,
const sphericalTensorField& x
) const
{
decoupledAmulCore(Ax, x);
}
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::TmulCore
(
sphericalTensorField& Tx,
const sphericalTensorField& x
) const
{
// Decoupled version
decoupledTmulCore(Tx, x);
}
template<>
void Foam::BlockLduMatrix<Foam::sphericalTensor>::segregateB
(
sphericalTensorField&,
const sphericalTensorField&
) const
{
FatalErrorIn
(
"void Foam::BlockLduMatrix<sphericalTensor>::segregateB\n"
"(\n"
" sphericalTensorField&,\n"
" const sphericalTensorField&\n"
") const"
) << "Requested decoupling of sphericalTensor matrix - never coupled"
<< abort(FatalError);
}
template<>
Foam::tmp<Foam::sphericalTensorField>
Foam::BlockLduMatrix<Foam::sphericalTensor>::H
(
const sphericalTensorField& x
) const
{
// Decoupled version
return decoupledH(x);
}
template<>
Foam::tmp<Foam::sphericalTensorField>
Foam::BlockLduMatrix<Foam::sphericalTensor>::faceH
(
const sphericalTensorField& x
) const
{
// Decoupled version
return decoupledFaceH(x);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduMatrix
Description
Template specialisation for sphericalTensor block matrix
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
sphericalTensorBlockLduMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef sphericalTensorBlockLduMatrix_H
#define sphericalTensorBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void BlockLduMatrix<sphericalTensor>::sumDiag();
template<>
void BlockLduMatrix<sphericalTensor>::negSumDiag();
template<>
void BlockLduMatrix<sphericalTensor>::check() const;
template<>
void BlockLduMatrix<sphericalTensor>::relax
(
const sphericalTensorField& x,
sphericalTensorField& b,
const scalar alpha
);
template<>
void BlockLduMatrix<sphericalTensor>::operator*=(const scalarField& sf);
template<>
void BlockLduMatrix<sphericalTensor>::AmulCore
(
sphericalTensorField& mul,
const sphericalTensorField& x
) const;
template<>
void BlockLduMatrix<sphericalTensor>::TmulCore
(
sphericalTensorField& mul,
const sphericalTensorField& x
) const;
template<>
void BlockLduMatrix<sphericalTensor>::segregateB
(
sphericalTensorField& mul,
const sphericalTensorField& x
) const;
template<>
tmp<sphericalTensorField>
BlockLduMatrix<sphericalTensor>::H(const sphericalTensorField& x) const;
template<>
tmp<sphericalTensorField>
BlockLduMatrix<sphericalTensor>::faceH(const sphericalTensorField& x) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,150 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#ifndef symmTensorBlockLduMatrix_H
#define symmTensorBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::sumDiag()
{
// Decoupled version
this->decoupledSumDiag();
}
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::negSumDiag()
{
// Decoupled version
this->decoupledNegSumDiag();
}
template<>
void Foam::BlockLduMatrix<symmTensor>::check() const
{
// Decoupled version
this->decoupledCheck();
}
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::relax
(
const symmTensorField& x,
symmTensorField& b,
const scalar alpha
)
{
// Decoupled version
this->decoupledRelax(x, b, alpha);
}
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::operator*=(const scalarField& sf)
{
// Decoupled version
this->decoupledMultEqOp(sf);
}
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::AmulCore
(
symmTensorField& Ax,
const symmTensorField& x
) const
{
decoupledAmulCore(Ax, x);
}
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::TmulCore
(
symmTensorField& Tx,
const symmTensorField& x
) const
{
// Decoupled version
decoupledTmulCore(Tx, x);
}
template<>
void Foam::BlockLduMatrix<Foam::symmTensor>::segregateB
(
symmTensorField&,
const symmTensorField&
) const
{
FatalErrorIn
(
"void Foam::BlockLduMatrix<symmTensor>::segregateB\n"
"(\n"
" symmTensorField&,\n"
" const symmTensorField&\n"
") const"
) << "Requested decoupling of symmTensor matrix - never coupled"
<< abort(FatalError);
}
template<>
Foam::tmp<Foam::symmTensorField>
Foam::BlockLduMatrix<Foam::symmTensor>::H(const symmTensorField& x) const
{
// Decoupled version
return decoupledH(x);
}
template<>
Foam::tmp<Foam::symmTensorField>
Foam::BlockLduMatrix<Foam::symmTensor>::faceH(const symmTensorField& x) const
{
// Decoupled version
return decoupledFaceH(x);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduMatrix
Description
Template specialisation for symmTensor block matrix
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
symmTensorBlockLduMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef symmTensorBlockLduMatrix_H
#define symmTensorBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void BlockLduMatrix<symmTensor>::sumDiag();
template<>
void BlockLduMatrix<symmTensor>::negSumDiag();
template<>
void BlockLduMatrix<symmTensor>::check() const;
template<>
void BlockLduMatrix<symmTensor>::relax
(
const symmTensorField& x,
symmTensorField& b,
const scalar alpha
);
template<>
void BlockLduMatrix<symmTensor>::operator*=(const scalarField& sf);
template<>
void BlockLduMatrix<symmTensor>::AmulCore
(
symmTensorField& mul,
const symmTensorField& x
) const;
template<>
void BlockLduMatrix<symmTensor>::TmulCore
(
symmTensorField& mul,
const symmTensorField& x
) const;
template<>
void BlockLduMatrix<symmTensor>::segregateB
(
symmTensorField& mul,
const symmTensorField& x
) const;
template<>
tmp<symmTensorField>
BlockLduMatrix<symmTensor>::H(const symmTensorField& x) const;
template<>
tmp<symmTensorField>
BlockLduMatrix<symmTensor>::faceH(const symmTensorField& x) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,150 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockLduMatrix_H
#define tensorBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockLduMatrix<Foam::tensor>::sumDiag()
{
// Decoupled version
this->decoupledSumDiag();
}
template<>
void Foam::BlockLduMatrix<Foam::tensor>::negSumDiag()
{
// Decoupled version
this->decoupledNegSumDiag();
}
template<>
void Foam::BlockLduMatrix<tensor>::check() const
{
// Decoupled version
this->decoupledCheck();
}
template<>
void Foam::BlockLduMatrix<Foam::tensor>::relax
(
const tensorField& x,
tensorField& b,
const scalar alpha
)
{
// Decoupled version
this->decoupledRelax(x, b, alpha);
}
template<>
void Foam::BlockLduMatrix<Foam::tensor>::operator*=(const scalarField& sf)
{
// Decoupled version
this->decoupledMultEqOp(sf);
}
template<>
void Foam::BlockLduMatrix<Foam::tensor>::AmulCore
(
tensorField& Ax,
const tensorField& x
) const
{
decoupledAmulCore(Ax, x);
}
template<>
void Foam::BlockLduMatrix<Foam::tensor>::TmulCore
(
tensorField& Tx,
const tensorField& x
) const
{
// Decoupled version
decoupledTmulCore(Tx, x);
}
template<>
void Foam::BlockLduMatrix<Foam::tensor>::segregateB
(
tensorField&,
const tensorField&
) const
{
FatalErrorIn
(
"void Foam::BlockLduMatrix<tensor>::segregateB\n"
"(\n"
" tensorField&,\n"
" const tensorField&\n"
") const"
) << "Requested decoupling of tensor matrix - never coupled"
<< abort(FatalError);
}
template<>
Foam::tmp<Foam::tensorField>
Foam::BlockLduMatrix<Foam::tensor>::H(const tensorField& x) const
{
// Decoupled version
return decoupledH(x);
}
template<>
Foam::tmp<Foam::tensorField>
Foam::BlockLduMatrix<Foam::tensor>::faceH(const tensorField& x) const
{
// Decoupled version
return decoupledFaceH(x);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduMatrix
Description
Template specialisation for tensor block matrix
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
tensorBlockLduMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockLduMatrix_H
#define tensorBlockLduMatrix_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void BlockLduMatrix<tensor>::sumDiag();
template<>
void BlockLduMatrix<tensor>::negSumDiag();
template<>
void BlockLduMatrix<tensor>::check() const;
template<>
void BlockLduMatrix<tensor>::relax
(
const tensorField& x,
tensorField& b,
const scalar alpha
);
template<>
void BlockLduMatrix<tensor>::operator*=(const scalarField& sf);
template<>
void BlockLduMatrix<tensor>::AmulCore
(
tensorField& mul,
const tensorField& x
) const;
template<>
void BlockLduMatrix<tensor>::TmulCore
(
tensorField& mul,
const tensorField& x
) const;
template<>
void BlockLduMatrix<tensor>::segregateB
(
tensorField& mul,
const tensorField& x
) const;
template<>
tmp<tensorField> BlockLduMatrix<tensor>::H(const tensorField& x) const;
template<>
tmp<tensorField> BlockLduMatrix<tensor>::faceH(const tensorField& x) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,927 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockCholeskyPrecon.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::BlockCholeskyPrecon<Type>::calcPreconDiag()
{
typedef CoeffField<Type> TypeCoeffField;
// Note: Assuming lower and upper triangle have the same active type
if (this->matrix_.symmetric())
{
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
UpperCoeff.asLinear()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Transpose multiplication
diagMultiplyCoeffT
(
preconDiag_.asSquare(),
UpperCoeff.asSquare()
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asLinear(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
UpperCoeff.asLinear()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Transpose multiplication
diagMultiplyCoeffT
(
preconDiag_.asSquare(),
UpperCoeff.asSquare()
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asSquare(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asSquare(),
UpperCoeff.asLinear()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Transpose multiplication
diagMultiplyCoeffT
(
preconDiag_.asSquare(),
UpperCoeff.asSquare()
);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
diagMultiply
(
preconDiag_.asSquare(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare()
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
diagMultiply
(
preconDiag_.asSquare(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare()
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asSquare(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asSquare(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
diagMultiply
(
preconDiag_.asSquare(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare()
);
}
}
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::diagMultiply
(
Field<DiagType>& dDiag,
const Field<ULType>& upper
)
{
// Precondition the diagonal
// Get addressing
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll (upper, coeffI)
{
dDiag[upperAddr[coeffI]] -=
mult.tripleProduct
(
upper[coeffI],
dDiag[lowerAddr[coeffI]],
upper[coeffI]
);
}
// Invert the diagonal for future use
forAll (dDiag, i)
{
dDiag[i] = mult.inverse(dDiag[i]);
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::diagMultiplyCoeffT
(
Field<DiagType>& dDiag,
const Field<ULType>& upper
)
{
// Precondition the diagonal
// Get addressing
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll (upper, coeffI)
{
dDiag[upperAddr[coeffI]] -=
mult.tripleProduct
(
upper[coeffI].T(), // Upper coefficient transposed
dDiag[lowerAddr[coeffI]],
upper[coeffI]
);
}
// Invert the diagonal for future use
forAll (dDiag, i)
{
dDiag[i] = mult.inverse(dDiag[i]);
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::diagMultiply
(
Field<DiagType>& dDiag,
const Field<ULType>& lower,
const Field<ULType>& upper
)
{
// Precondition the diagonal
// Get addressing
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll (upper, coeffI)
{
dDiag[upperAddr[coeffI]] -=
mult.tripleProduct
(
lower[coeffI],
dDiag[lowerAddr[coeffI]],
upper[coeffI]
);
}
// Invert the diagonal for future use
forAll (dDiag, i)
{
dDiag[i] = mult.inverse(dDiag[i]);
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::ILUmultiply
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& upper,
const Field<Type>& b
) const
{
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll(x, i)
{
x[i] = mult(dDiag[i], b[i]);
}
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
forAll (upper, coeffI)
{
x[upperAddr[coeffI]] -=
mult
(
dDiag[upperAddr[coeffI]],
mult(upper[coeffI], x[lowerAddr[coeffI]])
);
}
forAllReverse (upper, coeffI)
{
x[lowerAddr[coeffI]] -=
mult
(
dDiag[lowerAddr[coeffI]],
mult(upper[coeffI], x[upperAddr[coeffI]])
);
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::ILUmultiplyCoeffT
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& upper,
const Field<Type>& b
) const
{
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll(x, i)
{
x[i] = mult(dDiag[i], b[i]);
}
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
forAll (upper, coeffI)
{
x[upperAddr[coeffI]] -=
mult
(
dDiag[upperAddr[coeffI]],
mult(upper[coeffI].T(), x[lowerAddr[coeffI]])
);
}
forAllReverse (upper, coeffI)
{
x[lowerAddr[coeffI]] -=
mult
(
dDiag[lowerAddr[coeffI]],
mult(upper[coeffI], x[upperAddr[coeffI]])
);
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::ILUmultiply
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& lower,
const Field<ULType>& upper,
const Field<Type>& b
) const
{
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll(x, i)
{
x[i] = mult(dDiag[i], b[i]);
}
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
const unallocLabelList& losortAddr = this->matrix_.lduAddr().losortAddr();
register label losortCoeff;
forAll (lower, coeffI)
{
losortCoeff = losortAddr[coeffI];
x[upperAddr[losortCoeff]] -=
mult
(
dDiag[upperAddr[losortCoeff]],
mult(lower[losortCoeff], x[lowerAddr[losortCoeff]])
);
}
forAllReverse (upper, coeffI)
{
x[lowerAddr[coeffI]] -=
mult
(
dDiag[lowerAddr[coeffI]],
mult(upper[coeffI], x[upperAddr[coeffI]])
);
}
}
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockCholeskyPrecon<Type>::ILUmultiplyTranspose
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& lower,
const Field<ULType>& upper,
const Field<Type>& b
) const
{
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
forAll(x, i)
{
x[i] = mult(dDiag[i], b[i]);
}
const unallocLabelList& upperAddr = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = this->matrix_.lduAddr().lowerAddr();
const unallocLabelList& losortAddr = this->matrix_.lduAddr().losortAddr();
register label losortCoeff;
//HJ Not sure if the coefficient itself needs to be transposed.
// HJ, 30/Oct/2007
forAll (lower, coeffI)
{
x[upperAddr[coeffI]] -=
mult
(
dDiag[upperAddr[coeffI]],
mult(upper[coeffI], x[lowerAddr[coeffI]])
);
}
forAllReverse (upper, coeffI)
{
losortCoeff = losortAddr[coeffI];
x[lowerAddr[losortCoeff]] -=
mult
(
dDiag[lowerAddr[losortCoeff]],
mult(lower[losortCoeff], x[upperAddr[losortCoeff]])
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::BlockCholeskyPrecon<Type>::BlockCholeskyPrecon
(
const BlockLduMatrix<Type>& matrix
)
:
BlockLduPrecon<Type>(matrix),
preconDiag_(matrix.diag())
{
calcPreconDiag();
}
template<class Type>
Foam::BlockCholeskyPrecon<Type>::BlockCholeskyPrecon
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
)
:
BlockLduPrecon<Type>(matrix),
preconDiag_(matrix.diag())
{
calcPreconDiag();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::BlockCholeskyPrecon<Type>::~BlockCholeskyPrecon()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::BlockCholeskyPrecon<Type>::precondition
(
Field<Type>& x,
const Field<Type>& b
) const
{
typedef CoeffField<Type> TypeCoeffField;
// Note: Assuming lower and upper triangle have the same active type
if (this->matrix_.symmetric())
{
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Multiplication using transposed upper square coefficient
ILUmultiplyCoeffT
(
x,
preconDiag_.asScalar(),
UpperCoeff.asSquare(),
b
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Multiplication using transposed upper square coefficient
ILUmultiplyCoeffT
(
x,
preconDiag_.asLinear(),
UpperCoeff.asSquare(),
b
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asSquare(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asSquare(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Multiplication using transposed upper square coefficient
ILUmultiplyCoeffT
(
x,
preconDiag_.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asSquare(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asSquare(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
ILUmultiply
(
x,
preconDiag_.asSquare(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
}
}
template<class Type>
void Foam::BlockCholeskyPrecon<Type>::preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
typedef CoeffField<Type> TypeCoeffField;
// Note: Assuming lower and upper triangle have the same active type
if (this->matrix_.symmetric())
{
precondition(xT, bT);
}
else // Asymmetric matrix
{
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asScalar(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asScalar(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
bT
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asLinear(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
bT
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asSquare(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asSquare(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asSquare(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
bT
);
}
}
}
}
// ************************************************************************* //

View file

@ -0,0 +1,226 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockCholeskyPrecon
Description
Incomplete Cholesky preconditioning with no fill-in.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
BlockCholeskyPrecon.C
BlockCholeskyPreconDecoupled.C
\*---------------------------------------------------------------------------*/
#ifndef BlockCholeskyPrecon_H
#define BlockCholeskyPrecon_H
#include "BlockLduPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockCholeskyPrecon Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockCholeskyPrecon
:
public BlockLduPrecon<Type>
{
// Private Data
//- Preconditioned diagonal
mutable CoeffField<Type> preconDiag_;
// Private Member Functions
//- Disallow default bitwise copy construct
BlockCholeskyPrecon(const BlockCholeskyPrecon&);
//- Disallow default bitwise assignment
void operator=(const BlockCholeskyPrecon&);
//- Precondition the diagonal
void calcPreconDiag();
// Diagonal multiplication, symmetric matrix
template<class DiagType, class ULType>
void diagMultiply
(
Field<DiagType>& dDiag,
const Field<ULType>& upper
);
//- Diagonal multiplication with transpose upper square coeff
// for the symmetric matrix
template<class DiagType, class ULType>
void diagMultiplyCoeffT
(
Field<DiagType>& dDiag,
const Field<ULType>& upper
);
//- Diagonal multiplication, asymmetric matrix
template<class DiagType, class ULType>
void diagMultiply
(
Field<DiagType>& dDiag,
const Field<ULType>& lower,
const Field<ULType>& upper
);
//- ILU multiplication, symmetric matrix
template<class DiagType, class ULType>
void ILUmultiply
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& upper,
const Field<Type>& b
) const;
//- ILU multiplication, with transpose upper square coeff
// for a symmetric matrix
template<class DiagType, class ULType>
void ILUmultiplyCoeffT
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& upper,
const Field<Type>& b
) const;
//- ILU multiplication, asymmetric matrix
template<class DiagType, class ULType>
void ILUmultiply
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& lower,
const Field<ULType>& upper,
const Field<Type>& b
) const;
//- ILU multiplication transposed asymmetric matrix
template<class DiagType, class ULType>
void ILUmultiplyTranspose
(
Field<Type>& x,
const Field<DiagType>& dDiag,
const Field<ULType>& lower,
const Field<ULType>& upper,
const Field<Type>& b
) const;
// Decoupled operations, used in template specialisation
//- Precondition the diagonal, decoupled version
void calcDecoupledPreconDiag();
//- Execute preconditioning, decoupled version
void decoupledPrecondition
(
Field<Type>& x,
const Field<Type>& b
) const;
//- Execute preconditioning with matrix transpose, decoupled version
void decoupledPreconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const;
public:
//- Runtime type information
TypeName("Cholesky");
// Constructors
//- Construct from matrix for smoother use
BlockCholeskyPrecon
(
const BlockLduMatrix<Type>& matrix
);
//- Construct from components
BlockCholeskyPrecon
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
);
// Destructor
virtual ~BlockCholeskyPrecon();
// Member Functions
//- Execute preconditioning
virtual void precondition
(
Field<Type>& x,
const Field<Type>& b
) const;
//- Execute preconditioning with matrix transpose
virtual void preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockCholeskyPrecon.C"
# include "BlockCholeskyPreconDecoupled.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,328 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockCholeskyPrecon.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::BlockCholeskyPrecon<Type>::calcDecoupledPreconDiag()
{
typedef CoeffField<Type> TypeCoeffField;
// Note: Assuming lower and upper triangle have the same active type
if (this->matrix_.symmetric())
{
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
UpperCoeff.asLinear()
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asLinear(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
UpperCoeff.asLinear()
);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear()
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
diagMultiply
(
preconDiag_.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar()
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
diagMultiply
(
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear()
);
}
}
}
}
template<class Type>
void Foam::BlockCholeskyPrecon<Type>::decoupledPrecondition
(
Field<Type>& x,
const Field<Type>& b
) const
{
typedef CoeffField<Type> TypeCoeffField;
// Note: Assuming lower and upper triangle have the same active type
if (this->matrix_.symmetric())
{
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
UpperCoeff.asLinear(),
b
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
UpperCoeff.asLinear(),
b
);
}
}
}
else // Asymmetric matrix
{
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asScalar(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiply
(
x,
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
}
}
}
template<class Type>
void Foam::BlockCholeskyPrecon<Type>::decoupledPreconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
typedef CoeffField<Type> TypeCoeffField;
// Note: Assuming lower and upper triangle have the same active type
if (this->matrix_.symmetric())
{
precondition(xT, bT);
}
else // Asymmetric matrix
{
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
if (preconDiag_.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asScalar(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
bT
);
}
}
else if (preconDiag_.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
ILUmultiplyTranspose
(
xT,
preconDiag_.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
bT
);
}
}
}
}
// ************************************************************************* //

View file

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockLduPrecons.H"
#include "blockCholeskyPrecons.H"
#include "addToRunTimeSelectionTable.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockPrecons(blockCholeskyPrecon);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockCholeskyPrecon
Description
Typedefs for Incomplete Cholesky preconditioning with no fill-in.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockCholeskyPrecons.C
\*---------------------------------------------------------------------------*/
#ifndef blockCholeskyPrecons_H
#define blockCholeskyPrecons_H
#include "scalarBlockCholeskyPrecon.H"
#include "tensorBlockCholeskyPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockCholeskyPrecon<scalar> blockCholeskyPreconScalar;
typedef BlockCholeskyPrecon<vector> blockCholeskyPreconVector;
typedef BlockCholeskyPrecon<tensor> blockCholeskyPreconTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,200 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockCholeskyPrecon_H
#define scalarBlockCholeskyPrecon_H
#include "BlockCholeskyPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockCholeskyPrecon<scalar>::calcPreconDiag()
{
// Precondition the diagonal
if (matrix_.symmetric())
{
const unallocLabelList& upperAddr = matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = matrix_.lduAddr().lowerAddr();
// Get off-diagonal matrix coefficients
const scalarField& upper = matrix_.upper();
forAll (upper, coeffI)
{
preconDiag_[upperAddr[coeffI]] -=
sqr(upper[coeffI])/preconDiag_[lowerAddr[coeffI]];
}
}
else if (matrix_.asymmetric())
{
const unallocLabelList& upperAddr = matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = matrix_.lduAddr().lowerAddr();
// Get off-diagonal matrix coefficients
const scalarField& upper = matrix_.upper();
const scalarField& lower = matrix_.lower();
forAll (upper, coeffI)
{
preconDiag_[upperAddr[coeffI]] -=
upper[coeffI]*lower[coeffI]/preconDiag_[lowerAddr[coeffI]];
}
}
// Invert the diagonal for future use
forAll (preconDiag_, i)
{
preconDiag_[i] = 1.0/preconDiag_[i];
}
}
template<>
void Foam::BlockCholeskyPrecon<scalar>::precondition
(
scalarField& x,
const scalarField& b
) const
{
forAll(x, i)
{
x[i] = b[i]*preconDiag_[i];
}
if (matrix_.symmetric())
{
const unallocLabelList& upperAddr = matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = matrix_.lduAddr().lowerAddr();
// Get off-diagonal matrix coefficients
const scalarField& upper = matrix_.upper();
forAll (upper, coeffI)
{
x[upperAddr[coeffI]] -=
preconDiag_[upperAddr[coeffI]]*
upper[coeffI]*x[lowerAddr[coeffI]];
}
forAllReverse (upper, coeffI)
{
x[lowerAddr[coeffI]] -=
preconDiag_[lowerAddr[coeffI]]*
upper[coeffI]*x[upperAddr[coeffI]];
}
}
else if (matrix_.asymmetric())
{
const unallocLabelList& upperAddr = matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = matrix_.lduAddr().lowerAddr();
const unallocLabelList& losortAddr = matrix_.lduAddr().losortAddr();
// Get off-diagonal matrix coefficients
const scalarField& upper = matrix_.upper();
const scalarField& lower = matrix_.lower();
label losortCoeff;
forAll (lower, coeffI)
{
losortCoeff = losortAddr[coeffI];
x[upperAddr[losortCoeff]] -=
preconDiag_[upperAddr[losortCoeff]]*
lower[losortCoeff]*x[lowerAddr[losortCoeff]];
}
forAllReverse (upper, coeffI)
{
x[lowerAddr[coeffI]] -=
preconDiag_[lowerAddr[coeffI]]*
upper[coeffI]*x[upperAddr[coeffI]];
}
}
}
template<>
void Foam::BlockCholeskyPrecon<scalar>::preconditionT
(
scalarField& xT,
const scalarField& bT
) const
{
if (matrix_.symmetric())
{
precondition(xT, bT);
}
forAll(xT, i)
{
xT[i] = bT[i]*preconDiag_[i];
}
if (matrix_.asymmetric())
{
const unallocLabelList& upperAddr = matrix_.lduAddr().upperAddr();
const unallocLabelList& lowerAddr = matrix_.lduAddr().lowerAddr();
const unallocLabelList& losortAddr = matrix_.lduAddr().losortAddr();
// Get off-diagonal matrix coefficients
const scalarField& upper = matrix_.upper();
const scalarField& lower = matrix_.lower();
label losortCoeff;
forAll (lower, coeffI)
{
xT[upperAddr[coeffI]] -=
preconDiag_[upperAddr[coeffI]]*
upper[coeffI]*xT[lowerAddr[coeffI]];
}
forAllReverse (upper, coeffI)
{
losortCoeff = losortAddr[coeffI];
xT[lowerAddr[losortCoeff]] -=
preconDiag_[lowerAddr[losortCoeff]]*
lower[losortCoeff]*xT[upperAddr[losortCoeff]];
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockCholeskyPrecon
Description
Template specialisation for scalar block Cholesky preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
scalarBlockCholeskyPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockCholeskyPrecon_H
#define scalarBlockCholeskyPrecon_H
#include "BlockCholeskyPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockCholeskyPrecon<scalar>::calcPreconDiag();
template<>
void Foam::BlockCholeskyPrecon<scalar>::precondition
(
scalarField& x,
const scalarField& b
) const;
template<>
void Foam::BlockCholeskyPrecon<scalar>::preconditionT
(
scalarField& xT,
const scalarField& bT
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,77 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockCholeskyPrecon_H
#define tensorBlockCholeskyPrecon_H
#include "BlockCholeskyPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockCholeskyPrecon<tensor>::calcPreconDiag()
{
// Decoupled version
calcDecoupledPreconDiag();
}
template<>
void Foam::BlockCholeskyPrecon<tensor>::precondition
(
tensorField& x,
const tensorField& b
) const
{
// Decoupled version
decoupledPrecondition(x, b);
}
template<>
void Foam::BlockCholeskyPrecon<tensor>::preconditionT
(
tensorField& xT,
const tensorField& bT
) const
{
// Decoupled version
decoupledPreconditionT(xT, bT);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockCholeskyPrecon
Description
Template specialisation for tensor block Cholesky preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
tensorBlockCholeskyPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockCholeskyPrecon_H
#define tensorBlockCholeskyPrecon_H
#include "BlockCholeskyPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockCholeskyPrecon<tensor>::calcPreconDiag();
template<>
void Foam::BlockCholeskyPrecon<tensor>::precondition
(
tensorField& x,
const tensorField& b
) const;
template<>
void Foam::BlockCholeskyPrecon<tensor>::preconditionT
(
tensorField& xT,
const tensorField& bT
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockDiagonalPrecon.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::BlockDiagonalPrecon<Type>::precondition
(
Field<Type>& x,
const Field<Type>& b
) const
{
typedef CoeffField<Type> TypeCoeffField;
typedef typename TypeCoeffField::scalarTypeField scalarTypeField;
typedef typename TypeCoeffField::linearTypeField linearTypeField;
typedef typename TypeCoeffField::squareTypeField squareTypeField;
const TypeCoeffField& diag = this->matrix_.diag();
if (diag.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeDiag = diag.asScalar();
forAll (x, i)
{
x[i] = b[i]/activeDiag[i];
}
}
else if (diag.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeDiag = diag.asLinear();
forAll (x, i)
{
x[i] = cmptDivide(b[i], activeDiag[i]);
}
}
else if (diag.activeType() == blockCoeffBase::SQUARE)
{
const squareTypeField& activeDiag = diag.asSquare();
forAll (x, i)
{
x[i] = (b[i] & inv(activeDiag[i]));
}
}
else
{
FatalErrorIn
(
"void BlockDiagonalPrecon<Type>:solve:\n"
"(\n"
" Field<Type>& x,\n"
" const Field<Type>& b\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,129 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockDiagonalPrecon
Description
Diagonal preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockDiagonalPrecons.C
scalarBlockDiagonalPrecon.C
tensorBlockDiagonalPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef BlockDiagonalPrecon_H
#define BlockDiagonalPrecon_H
#include "BlockLduPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockDiagonalPrecon Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockDiagonalPrecon
:
public BlockLduPrecon<Type>
{
// Private Member Functions
//- Disallow default bitwise copy construct
BlockDiagonalPrecon(const BlockDiagonalPrecon&);
//- Disallow default bitwise assignment
void operator=(const BlockDiagonalPrecon&);
public:
//- Runtime type information
TypeName("diagonal");
// Constructors
//- Construct from components
BlockDiagonalPrecon
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
)
:
BlockLduPrecon<Type>(matrix)
{}
// Destructor
virtual ~BlockDiagonalPrecon()
{}
// Member Functions
//- Execute preconditioning
virtual void precondition
(
Field<Type>& x,
const Field<Type>& b
) const;
//- Execute preconditioning on a transposed matrix
virtual void preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
return precondition(xT, bT);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockDiagonalPrecon.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockLduPrecons.H"
#include "blockDiagonalPrecons.H"
#include "addToRunTimeSelectionTable.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockPrecons(blockDiagonalPrecon);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockDiagonalPrecon
Description
Typedefs Diagonal preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockDiagonalPrecons.C
\*---------------------------------------------------------------------------*/
#ifndef blockDiagonalPrecons_H
#define blockDiagonalPrecons_H
#include "scalarBlockDiagonalPrecon.H"
#include "tensorBlockDiagonalPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockDiagonalPrecon<scalar> blockDiagonalPreconScalar;
typedef BlockDiagonalPrecon<vector> blockDiagonalPreconVector;
typedef BlockDiagonalPrecon<tensor> blockDiagonalPreconTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockDiagonalPrecon
Description
Template specialisation for scalar block diagonal preconditioning
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockDiagonalPrecon_H
#define scalarBlockDiagonalPrecon_H
#include "BlockDiagonalPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockDiagonalPrecon<scalar>::precondition
(
scalarField& x,
const scalarField& b
) const
{
const scalarField& diag = matrix_.diag();
forAll (x, i)
{
x[i] = b[i]/diag[i];
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockDiagonalPrecon
Description
Template specialisation for scalar block diagonal preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
scalarBlockDiagonalPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockDiagonalPrecon_H
#define scalarBlockDiagonalPrecon_H
#include "BlockDiagonalPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockDiagonalPrecon<scalar>::precondition
(
scalarField& x,
const scalarField& b
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockDiagonalPrecon
Description
Template specialisation for tensor block diagonal preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockDiagonalPrecon_H
#define tensorBlockDiagonalPrecon_H
#include "BlockDiagonalPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockDiagonalPrecon<tensor>::precondition
(
tensorField& x,
const tensorField& b
) const
{
typedef CoeffField<tensor> tensorCoeffField;
typedef tensorCoeffField::scalarTypeField scalarTypeField;
typedef tensorCoeffField::linearTypeField linearTypeField;
const tensorCoeffField& diag = matrix_.diag();
if (diag.activeType() == blockCoeffBase::SCALAR)
{
const scalarTypeField& activeDiag = diag.asScalar();
forAll (x, i)
{
x[i] = b[i]/activeDiag[i];
}
}
else if (diag.activeType() == blockCoeffBase::LINEAR)
{
const linearTypeField& activeDiag = diag.asLinear();
forAll (x, i)
{
x[i] = cmptDivide(b[i], activeDiag[i]);
}
}
else
{
FatalErrorIn
(
"void BlockDiagonalPrecon<tensor>::solve\n"
"(\n"
" tensorField& x,\n"
" const tensorField& b\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockDiagonalPrecon
Description
Template specialisation for tensor block diagonal preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
tensorBlockDiagonalPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockDiagonalPrecon_H
#define tensorBlockDiagonalPrecon_H
#include "BlockDiagonalPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockDiagonalPrecon<tensor>::precondition
(
tensorField& x,
const tensorField& b
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,689 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Gauss-Seidel sweep as a preconditioner.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Block sweep, symmetric matrix
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockGaussSeidelPrecon<Type>::BlockSweep
(
Field<Type>& x,
const Field<DiagType>& dD,
const Field<ULType>& upper,
const Field<Type>& b
) const
{
const unallocLabelList& u = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& ownStart = this->matrix_.lduAddr().ownerStartAddr();
const label nRows = ownStart.size() - 1;
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
for (label sweep = 0; sweep < nSweeps_; sweep++)
{
bPrime_ = b;
register label fStart, fEnd, curCoeff;
// Forward sweep
for (register label rowI = 0; rowI < nRows; rowI++)
{
Type& curX = x[rowI];
// Grab the accumulated neighbour side
curX = bPrime_[rowI];
// Start and end of this row
fStart = ownStart[rowI];
fEnd = ownStart[rowI + 1];
// Accumulate the owner product side
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
curX -= mult(upper[curCoeff], x[u[curCoeff]]);
}
// Finish current x
curX = mult(dD[rowI], curX);
// Distribute the neighbour side using current x
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
// lower = upper transposed
bPrime_[u[curCoeff]] -=
mult(mult.transpose(upper[curCoeff]), curX);
}
}
// Reverse sweep
for (register label rowI = nRows - 1; rowI >= 0; rowI--)
{
Type& curX = x[rowI];
// Grab the accumulated neighbour side
curX = bPrime_[rowI];
// Start and end of this row
fStart = ownStart[rowI];
fEnd = ownStart[rowI + 1];
// Accumulate the owner product side
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
curX -= mult(upper[curCoeff], x[u[curCoeff]]);
}
// Finish current x
curX = mult(dD[rowI], curX);
// Distribute the neighbour side using current x
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
// lower = upper transposed
bPrime_[u[curCoeff]] -=
mult(mult.transpose(upper[curCoeff]), curX);
}
}
}
}
// Block sweep, asymmetric matrix
template<class Type>
template<class DiagType, class ULType>
void Foam::BlockGaussSeidelPrecon<Type>::BlockSweep
(
Field<Type>& x,
const Field<DiagType>& dD,
const Field<ULType>& lower,
const Field<ULType>& upper,
const Field<Type>& b
) const
{
const unallocLabelList& u = this->matrix_.lduAddr().upperAddr();
const unallocLabelList& ownStart = this->matrix_.lduAddr().ownerStartAddr();
const label nRows = ownStart.size() - 1;
// Create multiplication function object
typename BlockCoeff<Type>::multiply mult;
for (label sweep = 0; sweep < nSweeps_; sweep++)
{
bPrime_ = b;
register label fStart, fEnd, curCoeff;
// Forward sweep
for (register label rowI = 0; rowI < nRows; rowI++)
{
Type& curX = x[rowI];
// Grab the accumulated neighbour side
curX = bPrime_[rowI];
// Start and end of this row
fStart = ownStart[rowI];
fEnd = ownStart[rowI + 1];
// Accumulate the owner product side
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
curX -= mult(upper[curCoeff], x[u[curCoeff]]);
}
// Finish current x
curX = mult(dD[rowI], curX);
// Distribute the neighbour side using current x
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
bPrime_[u[curCoeff]] -= mult(lower[curCoeff], curX);
}
}
// Reverse sweep
for (register label rowI = nRows - 1; rowI >= 0; rowI--)
{
Type& curX = x[rowI];
// Grab the accumulated neighbour side
curX = bPrime_[rowI];
// Start and end of this row
fStart = ownStart[rowI];
fEnd = ownStart[rowI + 1];
// Accumulate the owner product side
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
curX -= mult(upper[curCoeff], x[u[curCoeff]]);
}
// Finish current x
curX = mult(dD[rowI], curX);
// Distribute the neighbour side using current x
for (curCoeff = fStart; curCoeff < fEnd; curCoeff++)
{
bPrime_[u[curCoeff]] -= mult(lower[curCoeff], curX);
}
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::BlockGaussSeidelPrecon<Type>::precondition
(
Field<Type>& x,
const Field<Type>& b
) const
{
typedef CoeffField<Type> TypeCoeffField;
if (this->matrix_.diagonal())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
multiply(x, dDCoeff, b);
}
else if (this->matrix_.symmetric())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
// Note
// Gauss-Seidel loops need to be executed in the specific
// order with direct access to the coefficients which can be
// of morphed type. Under normal circumstances, the
// operations are not inter-leaved and the decision can be
// made at the beginning of the loop. Here, the order needs
// to be enforced without the per-element if-condition, which
// makes for ugly code. HJ, 19/May/2005
//Note: Assuming lower and upper triangle have the same active type
if (dDCoeff.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
UpperCoeff.asSquare(),
b
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
UpperCoeff.asSquare(),
b
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asSquare(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asSquare(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
BlockSweep
(
x,
dDCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::precondition\n"
"(\n"
" Field<Type>& x,\n"
" const Field<Type>& b\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
else if (this->matrix_.asymmetric())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
// Note
// Gauss-Seidel loops need to be executed in the specific
// order with direct access to the coefficients which can be
// of morphed type. Under normal circumstances, the
// operations are not inter-leaved and the decision can be
// made at the beginning of the loop. Here, the order needs
// to be enforced without the per-element if-condition, which
// makes for ugly code. HJ, 19/May/2005
//Note: Assuming lower and upper triangle have the same active type
if (dDCoeff.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asSquare(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asSquare(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
BlockSweep
(
x,
dDCoeff.asSquare(),
LowerCoeff.asSquare(),
UpperCoeff.asSquare(),
b
);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::precondition\n"
"(\n"
" Field<Type>& x,\n"
" const Field<Type>& b\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::precondition\n"
"(\n"
" Field<Type>& x,\n"
" const Field<Type>& b\n"
") const"
) << "cannot solve incomplete matrix, no diagonal"
<< abort(FatalError);
}
}
template<class Type>
void Foam::BlockGaussSeidelPrecon<Type>::preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
typedef CoeffField<Type> TypeCoeffField;
if (this->matrix_.diagonal())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
multiply(xT, dDCoeff, bT);
}
else if (this->matrix_.symmetric() || this->matrix_.asymmetric())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
// Note
// Gauss-Seidel loops need to be executed in the specific
// order with direct access to the coefficients which can be
// of morphed type. Under normal circumstances, the
// operations are not inter-leaved and the decision can be
// made at the beginning of the loop. Here, the order needs
// to be enforced without the per-element if-condition, which
// makes for ugly code. HJ, 19/May/2005
//Note: Assuming lower and upper triangle have the same active type
if (dDCoeff.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asScalar(),
UpperCoeff.asScalar(),
LowerCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asScalar(),
UpperCoeff.asLinear(),
LowerCoeff.asLinear(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asScalar(),
UpperCoeff.asSquare(),
LowerCoeff.asSquare(),
bT
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asLinear(),
UpperCoeff.asScalar(),
LowerCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asLinear(),
UpperCoeff.asLinear(),
LowerCoeff.asLinear(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asLinear(),
UpperCoeff.asSquare(),
LowerCoeff.asSquare(),
bT
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::SQUARE)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asSquare(),
UpperCoeff.asScalar(),
LowerCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asSquare(),
UpperCoeff.asLinear(),
LowerCoeff.asLinear(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::SQUARE)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asSquare(),
UpperCoeff.asSquare(),
LowerCoeff.asSquare(),
bT
);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::preconditionT\n"
"(\n"
" Field<Type>& xT,\n"
" const Field<Type>& bT\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::preconditionT\n"
"(\n"
" Field<Type>& xT,\n"
" const Field<Type>& bT\n"
") const"
) << "cannot solve incomplete matrix, no diagonal"
<< abort(FatalError);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,188 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockGaussSeidelPrecon
Description
Gauss-Seidel preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
BlockGaussSeidelPrecon.C
BlockGaussSeidelPrecon.C
BlockGaussSeidelPreconDecoupled.C
\*---------------------------------------------------------------------------*/
#ifndef BlockGaussSeidelPrecon_H
#define BlockGaussSeidelPrecon_H
#include "BlockLduPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockGaussSeidelPrecon Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockGaussSeidelPrecon
:
public BlockLduPrecon<Type>
{
// Private Data
//- Temporary space for solution intermediate
mutable Field<Type> bPrime_;
//- Number of sweeps
const label nSweeps_;
// Private Member Functions
//- Disallow default bitwise copy construct
BlockGaussSeidelPrecon(const BlockGaussSeidelPrecon&);
//- Disallow default bitwise assignment
void operator=(const BlockGaussSeidelPrecon&);
// Block Gauss-Seidel sweep, symetric matrix
template<class DiagType, class ULType>
void BlockSweep
(
Field<Type>& x,
const Field<DiagType>& dD,
const Field<ULType>& upper,
const Field<Type>& b
) const;
// Block Gauss-Seidel sweep, asymmetric matrix
template<class DiagType, class ULType>
void BlockSweep
(
Field<Type>& x,
const Field<DiagType>& dD,
const Field<ULType>& lower,
const Field<ULType>& upper,
const Field<Type>& b
) const;
// Decoupled operations, used in template specialisation
//- Execute preconditioning, decoupled version
void decoupledPrecondition
(
Field<Type>& x,
const Field<Type>& b
) const;
//- Execute preconditioning with matrix transpose, decoupled version
void decoupledPreconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const;
public:
//- Runtime type information
TypeName("GaussSeidel");
// Constructors
//- Construct from matrix for smoother use
BlockGaussSeidelPrecon
(
const BlockLduMatrix<Type>& matrix
)
:
BlockLduPrecon<Type>(matrix),
bPrime_(matrix.lduAddr().size()),
nSweeps_(1)
{}
//- Construct from components
BlockGaussSeidelPrecon
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
)
:
BlockLduPrecon<Type>(matrix),
bPrime_(matrix.lduAddr().size()),
nSweeps_(readLabel(dict.lookup("nSweeps")))
{}
// Destructor
virtual ~BlockGaussSeidelPrecon()
{}
// Member Functions
//- Execute preconditioning
virtual void precondition
(
Field<Type>& x,
const Field<Type>& b
) const;
//- Execute preconditioning with matrix transpose
virtual void preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockGaussSeidelPrecon.C"
# include "BlockGaussSeidelPreconDecoupled.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,264 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Gauss-Seidel sweep as a preconditioner. Decoupled version, used in template
specialisation.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#include "BlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::BlockGaussSeidelPrecon<Type>::decoupledPrecondition
(
Field<Type>& x,
const Field<Type>& b
) const
{
typedef DecoupledCoeffField<Type> TypeCoeffField;
if (this->matrix_.diagonal())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
multiply(x, dDCoeff, b);
}
else if (this->matrix_.symmetric() || this->matrix_.asymmetric())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
// Note
// Gauss-Seidel loops need to be executed in the specific
// order with direct access to the coefficients which can be
// of morphed type. Under normal circumstances, the
// operations are not inter-leaved and the decision can be
// made at the beginning of the loop. Here, the order needs
// to be enforced without the per-element if-condition, which
// makes for ugly code. HJ, 19/May/2005
//Note: Assuming lower and upper triangle have the same active type
if (dDCoeff.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asScalar(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
LowerCoeff.asScalar(),
UpperCoeff.asScalar(),
b
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
BlockSweep
(
x,
dDCoeff.asLinear(),
LowerCoeff.asLinear(),
UpperCoeff.asLinear(),
b
);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::precondition\n"
"(\n"
" Field<Type>& x,\n"
" const Field<Type>& b\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::precondition\n"
"(\n"
" Field<Type>& x,\n"
" const Field<Type>& b\n"
") const"
) << "cannot solve incomplete matrix, no diagonal"
<< abort(FatalError);
}
}
template<class Type>
void Foam::BlockGaussSeidelPrecon<Type>::decoupledPreconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
typedef DecoupledCoeffField<Type> TypeCoeffField;
if (this->matrix_.diagonal())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
multiply(xT, dDCoeff, bT);
}
else if (this->matrix_.symmetric() || this->matrix_.asymmetric())
{
TypeCoeffField dDCoeff = inv(this->matrix_.diag());
const TypeCoeffField& LowerCoeff = this->matrix_.lower();
const TypeCoeffField& UpperCoeff = this->matrix_.upper();
// Note
// Gauss-Seidel loops need to be executed in the specific
// order with direct access to the coefficients which can be
// of morphed type. Under normal circumstances, the
// operations are not inter-leaved and the decision can be
// made at the beginning of the loop. Here, the order needs
// to be enforced without the per-element if-condition, which
// makes for ugly code. HJ, 19/May/2005
//Note: Assuming lower and upper triangle have the same active type
if (dDCoeff.activeType() == blockCoeffBase::SCALAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asScalar(),
UpperCoeff.asScalar(),
LowerCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asScalar(),
UpperCoeff.asLinear(),
LowerCoeff.asLinear(),
bT
);
}
}
else if (dDCoeff.activeType() == blockCoeffBase::LINEAR)
{
if (UpperCoeff.activeType() == blockCoeffBase::SCALAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asLinear(),
UpperCoeff.asScalar(),
LowerCoeff.asScalar(),
bT
);
}
else if (UpperCoeff.activeType() == blockCoeffBase::LINEAR)
{
// Transpose multiplication - swap lower and upper coeff arrays
BlockSweep
(
xT,
dDCoeff.asLinear(),
UpperCoeff.asLinear(),
LowerCoeff.asLinear(),
bT
);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::preconditionT\n"
"(\n"
" Field<Type>& xT,\n"
" const Field<Type>& bT\n"
") const"
) << "Problem with coefficient type morphing."
<< abort(FatalError);
}
}
else
{
FatalErrorIn
(
"void BlockGaussSeidelPrecon<Type>::preconditionT\n"
"(\n"
" Field<Type>& xT,\n"
" const Field<Type>& bT\n"
") const"
) << "cannot solve incomplete matrix, no diagonal"
<< abort(FatalError);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Gauss-Seidel preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockLduPrecons.H"
#include "blockGaussSeidelPrecons.H"
#include "addToRunTimeSelectionTable.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockPrecons(blockGaussSeidelPrecon);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockGaussSeidelPrecon
Description
Typedefs for Gauss-Seidel preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockGaussSeidelPrecons.C
\*---------------------------------------------------------------------------*/
#ifndef blockGaussSeidelPrecons_H
#define blockGaussSeidelPrecons_H
#include "scalarBlockGaussSeidelPrecon.H"
#include "tensorBlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockGaussSeidelPrecon<scalar> blockGaussSeidelPreconScalar;
typedef BlockGaussSeidelPrecon<vector> blockGaussSeidelPreconVector;
typedef BlockGaussSeidelPrecon<tensor> blockGaussSeidelPreconTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,123 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockGaussSeidelPrecon
Description
Template specialisation for scalar block Gauss-Seidel preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockGaussSeidelPrecon_H
#define scalarBlockGaussSeidelPrecon_H
#include "BlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockGaussSeidelPrecon<scalar>::precondition
(
scalarField& x,
const scalarField& b
) const
{
if (matrix_.diagonal())
{
const scalarField& d = matrix_.diag();
forAll (x, i)
{
x[i] = b[i]/d[i];
}
}
else if (matrix_.symmetric() || matrix_.asymmetric())
{
scalarField dD = 1.0/matrix_.diag();
const scalarField& LowerCoeff = matrix_.lower();
const scalarField& UpperCoeff = matrix_.upper();
BlockSweep
(
x,
dD,
LowerCoeff,
UpperCoeff,
b
);
}
}
template<>
void Foam::BlockGaussSeidelPrecon<scalar>::preconditionT
(
scalarField& xT,
const scalarField& bT
) const
{
if (matrix_.diagonal())
{
const scalarField& d = matrix_.diag();
forAll (xT, i)
{
xT[i] = bT[i]/d[i];
}
}
else if (matrix_.symmetric() || matrix_.asymmetric())
{
scalarField dD = 1.0/matrix_.diag();
const scalarField& LowerCoeff = matrix_.lower();
const scalarField& UpperCoeff = matrix_.upper();
// Swap lower and upper coefficients, transposed matrix
BlockSweep
(
xT,
dD,
UpperCoeff,
LowerCoeff,
bT
);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockGaussSeidelPrecon
Description
Template specialisation for scalar block Gauss-Seidel preconditioning
SourceFiles
scalarBlockGaussSeidelPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef scalarBlockGaussSeidelPrecon_H
#define scalarBlockGaussSeidelPrecon_H
#include "BlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockGaussSeidelPrecon<scalar>::precondition
(
scalarField& x,
const scalarField& b
) const;
template<>
void Foam::BlockGaussSeidelPrecon<scalar>::preconditionT
(
scalarField& xT,
const scalarField& bT
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockGaussSeidelPrecon
Description
Template specialisation for tensor block Gauss-Seidel preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
tensorBlockGaussSeidelPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockGaussSeidelPrecon_H
#define tensorBlockGaussSeidelPrecon_H
#include "BlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockGaussSeidelPrecon<tensor>::precondition
(
tensorField& x,
const tensorField& b
) const
{
// Decoupled version
decoupledPrecondition(x, b);
}
template<>
void Foam::BlockGaussSeidelPrecon<tensor>::preconditionT
(
tensorField& xT,
const tensorField& bT
) const
{
// Decoupled version
decoupledPreconditionT(xT, bT);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockGaussSeidelPrecon
Description
Template specialisation for tensor block Gauss-Seidel preconditioning
SourceFiles
tensorBlockGaussSeidelPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef tensorBlockGaussSeidelPrecon_H
#define tensorBlockGaussSeidelPrecon_H
#include "BlockGaussSeidelPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::BlockGaussSeidelPrecon<tensor>::precondition
(
tensorField& x,
const tensorField& b
) const;
template<>
void Foam::BlockGaussSeidelPrecon<tensor>::preconditionT
(
tensorField& xT,
const tensorField& bT
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,174 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockLduPrecon
Description
Block LDU matrix preconditioner virtual base class
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
newBlockLduPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef BlockLduPrecon_H
#define BlockLduPrecon_H
#include "BlockLduMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockLduPrecon Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockLduPrecon
{
// Private Member Functions
//- Disallow default bitwise copy construct
BlockLduPrecon(const BlockLduPrecon&);
//- Disallow default bitwise assignment
void operator=(const BlockLduPrecon&);
protected:
// Protected data
//- Matrix reference
const BlockLduMatrix<Type>& matrix_;
public:
//- Runtime type information
TypeName("BlockLduPrecon");
// Declare run-time constructor selection tables
declareRunTimeSelectionTable
(
autoPtr,
BlockLduPrecon,
dictionary,
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
),
(
matrix,
dict
)
);
// Constructors
//- Construct from matrix
BlockLduPrecon(const BlockLduMatrix<Type>& matrix)
:
matrix_(matrix)
{}
// Selectors
//- Select given matrix and dictionary
static autoPtr<BlockLduPrecon<Type> > New
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
);
// Destructor
virtual ~BlockLduPrecon()
{}
// Member Functions
//- Execute preconditioning
virtual void precondition
(
Field<Type>& x,
const Field<Type>& b
) const = 0;
//- Execute preconditioning on a transposed matrix
virtual void preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
notImplemented
(
type() +"::preconditionT"
"(Field<Type>& xT, const Field<Type>& bT) const"
);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "newBlockLduPrecon.C"
#endif
#define makeBlockPrecon(PreconType, typePreconType) \
\
defineNamedTemplateTypeNameAndDebug(typePreconType, 0); \
\
addToRunTimeSelectionTable(PreconType, typePreconType, dictionary);
#define makeBlockPrecons(preconType) \
\
makeBlockPrecon(blockScalarPrecon, preconType##Scalar); \
makeBlockPrecon(blockVectorPrecon, preconType##Vector); \
makeBlockPrecon(blockTensorPrecon, preconType##Tensor);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,54 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Block precon member static data members
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
\*---------------------------------------------------------------------------*/
#include "blockLduPrecons.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineNamedTemplateTypeNameAndDebug(blockScalarPrecon, 0);
defineNamedTemplateTypeNameAndDebug(blockVectorPrecon, 0);
defineNamedTemplateTypeNameAndDebug(blockTensorPrecon, 0);
defineTemplateRunTimeSelectionTable(blockScalarPrecon, dictionary);
defineTemplateRunTimeSelectionTable(blockVectorPrecon, dictionary);
defineTemplateRunTimeSelectionTable(blockTensorPrecon, dictionary);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduPrecon
Description
Typedefs for block preconditioners
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
blockLduPrecons.C
\*---------------------------------------------------------------------------*/
#ifndef blockLduPrecons_H
#define blockLduPrecons_H
#include "BlockLduPrecon.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockLduPrecon<scalar> blockScalarPrecon;
typedef BlockLduPrecon<vector> blockVectorPrecon;
typedef BlockLduPrecon<tensor> blockTensorPrecon;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,90 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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 "BlockLduPrecon.H"
#include "blockNoPrecons.H"
template<class Type>
class BlockNoPrecon;
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::BlockLduPrecon<Type> > Foam::BlockLduPrecon<Type>::New
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
)
{
word preconName(dict.lookup("preconditioner"));
if (matrix.diagonal())
{
// No preconditioning for the diagonal matrix
return autoPtr<BlockLduPrecon<Type> >
(
new BlockNoPrecon<Type>
(
matrix,
dict
)
);
}
else
{
typename dictionaryConstructorTable::iterator constructorIter =
dictionaryConstructorTablePtr_->find(preconName);
if (constructorIter == dictionaryConstructorTablePtr_->end())
{
FatalIOErrorIn
(
"autoPtr<BlockLduPrecon> BlockLduPrecon::New\n"
"(\n"
" const BlockLduMatrix<Type>& matrix,\n"
" const dictionary& dict\n"
")",
dict
) << "Unknown matrix preconditioner " << preconName
<< endl << endl
<< "Valid matrix preconditioners are :" << endl
<< dictionaryConstructorTablePtr_->toc()
<< exit(FatalIOError);
}
return autoPtr<BlockLduPrecon<Type> >
(
constructorIter()
(
matrix,
dict
)
);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockNoPrecon
Description
No preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
BlockNoPrecon.C
\*---------------------------------------------------------------------------*/
#ifndef BlockNoPrecon_H
#define BlockNoPrecon_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class BlockLduPrecon;
/*---------------------------------------------------------------------------*\
Class BlockNoPrecon Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockNoPrecon
:
public BlockLduPrecon<Type>
{
// Private Member Functions
//- Disallow default bitwise copy construct
BlockNoPrecon(const BlockNoPrecon&);
//- Disallow default bitwise assignment
void operator=(const BlockNoPrecon&);
public:
//- Runtime type information
TypeName("none");
// Constructors
//- Construct from components
BlockNoPrecon
(
const BlockLduMatrix<Type>& matrix,
const dictionary& dict
)
:
BlockLduPrecon<Type>(matrix)
{}
// Destructor
virtual ~BlockNoPrecon()
{}
// Member Functions
//- Execute preconditioning
virtual void precondition
(
Field<Type>& x,
const Field<Type>& b
) const
{
x = b;
}
//- Execute preconditioning
virtual void preconditionT
(
Field<Type>& xT,
const Field<Type>& bT
) const
{
precondition(xT, bT);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockLduPrecons.H"
#include "addToRunTimeSelectionTable.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockPrecons(blockNoPrecon);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockNoPrecon
Description
Typedefs for no preconditioning
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockNoPrecons.C
\*---------------------------------------------------------------------------*/
#ifndef blockNoPrecons_H
#define blockNoPrecons_H
#include "BlockNoPrecon.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockNoPrecon<scalar> blockNoPreconScalar;
typedef BlockNoPrecon<vector> blockNoPreconVector;
typedef BlockNoPrecon<tensor> blockNoPreconTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,128 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockGaussSeidelSmoother
Description
Symmetric Gauss-Seidel smoother with prescribed number of smoothing sweeps
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockGaussSeidelSmoothers.C
\*---------------------------------------------------------------------------*/
#ifndef BlockGaussSeidelSmoother_H
#define BlockGaussSeidelSmoother_H
#include "BlockLduSmoother.H"
#include "blockGaussSeidelPrecons.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockGaussSeidelSmoother Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockGaussSeidelSmoother
:
public BlockLduSmoother<Type>
{
// Private Data
//- Gauss-Seidel preconditioner
BlockGaussSeidelPrecon<Type> gs_;
// Private Member Functions
//- Disallow default bitwise copy construct
BlockGaussSeidelSmoother(const BlockGaussSeidelSmoother&);
//- Disallow default bitwise assignment
void operator=(const BlockGaussSeidelSmoother&);
public:
//- Runtime type information
TypeName("GaussSeidel");
// Constructors
//- Construct from components
BlockGaussSeidelSmoother
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& dict
)
:
BlockLduSmoother<Type>(matrix, boundaryCoeffs, interfaces),
gs_(matrix)
{}
// Destructor
virtual ~BlockGaussSeidelSmoother()
{}
// Member Functions
//- Execute smoothing
virtual void smooth
(
Field<Type>& x,
const Field<Type>& b,
const label nSweeps
) const
{
for (label sweep = 0; sweep < nSweeps; sweep++)
{
gs_.precondition(x, b);
}
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Gauss-Seidel smoother
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockLduSmoothers.H"
#include "blockGaussSeidelSmoothers.H"
#include "addToRunTimeSelectionTable.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockSmoothers(blockGaussSeidelSmoother);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockGaussSeidelSmoother
Description
Typedefs for Gauss-Seidel smoother
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockGaussSeidelSmoothers.C
\*---------------------------------------------------------------------------*/
#ifndef blockGaussSeidelSmoothers_H
#define blockGaussSeidelSmoothers_H
#include "BlockGaussSeidelSmoother.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockGaussSeidelSmoother<scalar> blockGaussSeidelSmootherScalar;
typedef BlockGaussSeidelSmoother<vector> blockGaussSeidelSmootherVector;
typedef BlockGaussSeidelSmoother<tensor> blockGaussSeidelSmootherTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockILUSmoother
Description
Gauss-Seidel smoother
SourceFiles
blockILUSmoothers.C
\*---------------------------------------------------------------------------*/
#ifndef BlockILUSmoother_H
#define BlockILUSmoother_H
#include "BlockLduSmoother.H"
#include "blockCholeskyPrecons.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockILUSmoother Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockILUSmoother
:
public BlockLduSmoother<Type>
{
// Private Data
//- Cholesky preconditioner
BlockCholeskyPrecon<Type> precon_;
//- Correction array
mutable Field<Type> xCorr_;
//- Residual array
mutable Field<Type> residual_;
// Private Member Functions
//- Disallow default bitwise copy construct
BlockILUSmoother(const BlockILUSmoother&);
//- Disallow default bitwise assignment
void operator=(const BlockILUSmoother&);
public:
//- Runtime type information
TypeName("ILU");
// Constructors
//- Construct from components
BlockILUSmoother
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& dict
)
:
BlockLduSmoother<Type>(matrix, boundaryCoeffs, interfaces),
precon_(matrix),
xCorr_(matrix.lduAddr().size()),
residual_(matrix.lduAddr().size())
{}
// Destructor
virtual ~BlockILUSmoother()
{}
// Member Functions
//- Execute smoothing
virtual void smooth
(
Field<Type>& x,
const Field<Type>& b,
const label nSweeps
) const
{
for (label sweep = 0; sweep < nSweeps; sweep++)
{
// Calculate residual
this-> matrix_.Amul
(
residual_,
x,
BlockLduSmoother<Type>::boundaryCoeffs_,
BlockLduSmoother<Type>::interfaces_
);
// residual = b - Ax
forAll (b, i)
{
residual_[i] = b[i] - residual_[i];
}
precon_.precondition(xCorr_, residual_);
// Add correction to x
x += xCorr_;
}
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockLduSmoothers.H"
#include "blockILUSmoothers.H"
#include "addToRunTimeSelectionTable.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockSmoothers(blockILUSmoother);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockILUSmoother
Description
Typedefs for Incomplete Lower-Upper (ILU) smoother
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved.
SourceFiles
blockILUSmoothers.C
\*---------------------------------------------------------------------------*/
#ifndef blockILUSmoothers_H
#define blockILUSmoothers_H
#include "BlockILUSmoother.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockILUSmoother<scalar> blockILUSmootherScalar;
typedef BlockILUSmoother<vector> blockILUSmootherVector;
typedef BlockILUSmoother<tensor> blockILUSmootherTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,176 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockLduSmoother
Description
Block LDU matrix smoother virtual base class
SourceFiles
newBlockLduSmoother.C
\*---------------------------------------------------------------------------*/
#ifndef BlockLduSmoother_H
#define BlockLduSmoother_H
#include "blockLduMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockLduSmoother Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockLduSmoother
{
// Private Member Functions
//- Disallow default bitwise copy construct
BlockLduSmoother(const BlockLduSmoother&);
//- Disallow default bitwise assignment
void operator=(const BlockLduSmoother&);
protected:
// Protected data
//- Matrix reference
const BlockLduMatrix<Type>& matrix_;
//- Reference to boundary coefficients
const FieldField<CoeffField, Type>& boundaryCoeffs_;
//- Reference to interfaces
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces_;
public:
//- Runtime type information
TypeName("BlockLduSmoother");
// Declare run-time constructor selection tables
declareRunTimeSelectionTable
(
autoPtr,
BlockLduSmoother,
dictionary,
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& dict
),
(
matrix,
boundaryCoeffs,
interfaces,
dict
)
);
// Constructors
//- Construct from matrix
BlockLduSmoother
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces
)
:
matrix_(matrix),
boundaryCoeffs_(boundaryCoeffs),
interfaces_(interfaces)
{}
// Selectors
//- Select given matrix and dictionary
static autoPtr<BlockLduSmoother<Type> > New
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& dict
);
// Destructor
virtual ~BlockLduSmoother()
{}
// Member Functions
//- Execute smoothing
virtual void smooth
(
Field<Type>& x,
const Field<Type>& b,
const label nSweeps
) const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "newBlockLduSmoother.C"
#endif
#define makeBlockSmoother(SmootherType, typeSmootherType) \
\
defineNamedTemplateTypeNameAndDebug(typeSmootherType, 0); \
\
addToRunTimeSelectionTable(SmootherType, typeSmootherType, dictionary);
#define makeBlockSmoothers(smootherType) \
\
makeBlockSmoother(blockScalarSmoother, smootherType##Scalar); \
makeBlockSmoother(blockVectorSmoother, smootherType##Vector);
// makeBlockSmoother(blockTensorSmoother, smootherType##Tensor);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,52 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Block smoother member static data members
\*---------------------------------------------------------------------------*/
#include "blockLduSmoothers.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineNamedTemplateTypeNameAndDebug(blockScalarSmoother, 0);
defineNamedTemplateTypeNameAndDebug(blockVectorSmoother, 0);
// defineNamedTemplateTypeNameAndDebug(blockTensorSmoother, 0);
defineTemplateRunTimeSelectionTable(blockScalarSmoother, dictionary);
defineTemplateRunTimeSelectionTable(blockVectorSmoother, dictionary);
// defineTemplateRunTimeSelectionTable(blockTensorSmoother, dictionary);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockLduSmoother
Description
Typedefs for block LDU smoothers.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
blockLduSmoothers.C
\*---------------------------------------------------------------------------*/
#ifndef blockLduSmoothers_H
#define blockLduSmoothers_H
#include "BlockLduSmoother.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockLduSmoother<scalar> blockScalarSmoother;
typedef BlockLduSmoother<vector> blockVectorSmoother;
// typedef BlockLduSmoother<tensor> blockTensorSmoother;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,86 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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
BlockLduSmoother
Description
Block LDU matrix smoother virtual base class
\*----------------------------------------------------------------------------*/
#include "BlockLduSmoother.H"
template<class Type>
class BlockNoSmoother;
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::BlockLduSmoother<Type> > Foam::BlockLduSmoother<Type>::New
(
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& dict
)
{
word smootherName(dict.lookup("smoother"));
typename dictionaryConstructorTable::iterator constructorIter =
dictionaryConstructorTablePtr_->find(smootherName);
if (constructorIter == dictionaryConstructorTablePtr_->end())
{
FatalIOErrorIn
(
"autoPtr<BlockLduSmoother> BlockLduSmoother::New\n"
"(\n"
" const BlockLduMatrix<Type>& matrix,\n"
" const FieldField<CoeffField, Type>& boundaryCoeffs,\n"
" const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,\n"
" const dictionary& dict\n"
")",
dict
) << "Unknown matrix smoother " << smootherName
<< endl << endl
<< "Valid matrix smoothers are :" << endl
<< dictionaryConstructorTablePtr_->toc()
<< exit(FatalIOError);
}
return autoPtr<BlockLduSmoother<Type> >
(
constructorIter()
(
matrix,
boundaryCoeffs,
interfaces,
dict
)
);
}
// ************************************************************************* //

View file

@ -0,0 +1,194 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Preconditioned Bi-Conjugate Gradient stabilised solver.
\*---------------------------------------------------------------------------*/
#include "BlockBiCGStabSolver.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct from matrix and solver data stream
template<class Type>
Foam::BlockBiCGStabSolver<Type>::BlockBiCGStabSolver
(
const word& fieldName,
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& solverDict
)
:
BlockIterativeSolver<Type>
(
fieldName,
matrix,
boundaryCoeffs,
interfaces,
solverDict
),
preconPtr_
(
BlockLduPrecon<Type>::New
(
matrix,
this->dict().subDict("preconditioner")
)
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
typename Foam::BlockSolverPerformance<Type>
Foam::BlockBiCGStabSolver<Type>::solve
(
Field<Type>& x,
const Field<Type>& b
)
{
// Create local references to avoid the spread this-> ugliness
const BlockLduMatrix<Type>& matrix = this->matrix_;
// Prepare solver performance
BlockSolverPerformance<Type> solverPerf
(
typeName,
this->fieldName()
);
scalar norm = this->normFactor(x, b);
// Multiplication helper
typename BlockCoeff<Type>::multiply mult;
Field<Type> p(x.size());
// Calculate initial residual
matrix.Amul
(
p,
x,
BlockLduSolver<Type>::boundaryCoeffs_,
BlockLduSolver<Type>::interfaces_
);
Field<Type> r(b - p);
solverPerf.initialResidual() = gSum(cmptMag(r))/norm;
solverPerf.finalResidual() = solverPerf.initialResidual();
// Check convergence, solve if not converged
if (!solverPerf.checkConvergence(this->tolerance(), this->relTolerance()))
{
scalar rho = this->great_;
scalar rhoOld = rho;
scalar alpha = 0;
scalar omega = this->great_;
scalar beta;
p = pTraits<Type>::zero;
Field<Type> ph(x.size(), pTraits<Type>::zero);
Field<Type> v(x.size(), pTraits<Type>::zero);
Field<Type> s(x.size(), pTraits<Type>::zero);
Field<Type> sh(x.size(), pTraits<Type>::zero);
Field<Type> t(x.size(), pTraits<Type>::zero);
// Calculate transpose residual
Field<Type> rw(r);
do
{
rhoOld = rho;
// Update search directions
rho = gSumProd(rw, r);
beta = rho/rhoOld*(alpha/omega);
// Restart if breakdown occurs
if (rho == 0)
{
rw = r;
rho = gSumProd(rw, r);
alpha = 0;
omega = 0;
beta = 0;
}
forAll (p, i)
{
p[i] = r[i] + beta*p[i] - beta*omega*v[i];
}
preconPtr_->precondition(ph, p);
matrix.Amul
(
v,
ph,
BlockLduSolver<Type>::boundaryCoeffs_,
BlockLduSolver<Type>::interfaces_
);
alpha = rho/gSumProd(rw, v);
forAll (s, i)
{
s[i] = r[i] - alpha*v[i];
}
preconPtr_->preconditionT(sh, s);
matrix.Amul
(
t,
sh,
BlockLduSolver<Type>::boundaryCoeffs_,
BlockLduSolver<Type>::interfaces_
);
omega = gSumProd(t, s)/gSumProd(t, t);
forAll (x, i)
{
x[i] = x[i] + alpha*ph[i] + omega*sh[i];
}
forAll (r, i)
{
r[i] = s[i] - omega*t[i];
}
solverPerf.finalResidual() = gSum(cmptMag(r))/norm;
solverPerf.nIterations()++;
} while (!stop(solverPerf));
}
return solverPerf;
}
// ************************************************************************* //

View file

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockBiCGStabSolver
Description
Preconditioned Bi-Conjugate Gradient stabilised solver.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
BlockBiCGStabSolver.C
\*---------------------------------------------------------------------------*/
#ifndef BlockBiCGStabSolver_H
#define BlockBiCGStabSolver_H
#include "blockLduSolvers.H"
#include "BlockIterativeSolver.H"
#include "blockLduPrecons.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockBiCGStabSolver Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockBiCGStabSolver
:
public BlockIterativeSolver<Type>
{
// Private data
//- Preconditioner
autoPtr<BlockLduPrecon<Type> > preconPtr_;
// Private Member Functions
//- Disallow default bitwise copy construct
BlockBiCGStabSolver(const BlockBiCGStabSolver<Type>&);
//- Disallow default bitwise assignment
void operator=(const BlockBiCGStabSolver<Type>&);
public:
//- Runtime type information
TypeName("BiCGStab");
// Constructors
//- Construct from matrix components and solver data stream
BlockBiCGStabSolver
(
const word& fieldName,
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& solverDict
);
// Destructor
virtual ~BlockBiCGStabSolver()
{}
// Member Functions
//- Solve the matrix with this solver
virtual BlockSolverPerformance<Type> solve
(
Field<Type>& x,
const Field<Type>& b
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockBiCGStabSolver.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,54 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Preconditioned Bi-Conjugate Gradient stabilised solver.
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockBiCGStabSolvers.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockSolvers(blockBiCGStabSolver);
// BiCGStab as a symmetric solver: use where the diagonal coefficient block
// is assymetric. HJ, 24/Jan/2008
addSymSolverToBlockMatrix(blockBiCGStabSolver);
addAsymSolverToBlockMatrix(blockBiCGStabSolver);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockBiCGStabSolver
Description
Typedefs Preconditioned Bi-Conjugate Gradient stabilised solver.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
blockICBiCGStabSolvers.C
\*---------------------------------------------------------------------------*/
#ifndef blockBiCGStabSolvers_H
#define blockBiCGStabSolvers_H
#include "BlockBiCGStabSolver.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockBiCGStabSolver<scalar> blockBiCGStabSolverScalar;
typedef BlockBiCGStabSolver<vector> blockBiCGStabSolverVector;
typedef BlockBiCGStabSolver<tensor> blockBiCGStabSolverTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,170 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Preconditioned Conjugate Gradient solver.
\*---------------------------------------------------------------------------*/
#include "BlockCGSolver.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct from matrix and solver data stream
template<class Type>
Foam::BlockCGSolver<Type>::BlockCGSolver
(
const word& fieldName,
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& solverDict
)
:
BlockIterativeSolver<Type>
(
fieldName,
matrix,
boundaryCoeffs,
interfaces,
solverDict
),
preconPtr_
(
BlockLduPrecon<Type>::New
(
matrix,
this->dict().subDict("preconditioner")
)
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
typename Foam::BlockSolverPerformance<Type> Foam::BlockCGSolver<Type>::solve
(
Field<Type>& x,
const Field<Type>& b
)
{
// Create local references to avoid the spread this-> ugliness
const BlockLduMatrix<Type>& matrix = this->matrix_;
// Prepare solver performance
BlockSolverPerformance<Type> solverPerf
(
typeName,
this->fieldName()
);
scalar norm = this->normFactor(x, b);
// Multiplication helper
typename BlockCoeff<Type>::multiply mult;
Field<Type> wA(x.size());
// Calculate initial residual
matrix.Amul
(
wA,
x,
BlockLduSolver<Type>::boundaryCoeffs_,
BlockLduSolver<Type>::interfaces_
);
Field<Type> rA(b - wA);
solverPerf.initialResidual() = gSum(cmptMag(rA))/norm;
solverPerf.finalResidual() = solverPerf.initialResidual();
// Check convergence, solve if not converged
if (!solverPerf.checkConvergence(this->tolerance(), this->relTolerance()))
{
scalar rho = this->great_;
scalar rhoOld = rho;
scalar alpha, beta, wApA;
Field<Type> pA(x.size());
do
{
rhoOld = rho;
// Execute preconditioning
preconPtr_->precondition(wA, rA);
// Update search directions
rho = gSumProd(wA, rA);
beta = rho/rhoOld;
forAll (pA, i)
{
pA[i] = wA[i] + beta*pA[i];
}
// Update preconditioner residual
matrix.Amul
(
wA,
pA,
BlockLduSolver<Type>::boundaryCoeffs_,
BlockLduSolver<Type>::interfaces_
);
wApA = gSumProd(wA, pA);
// Check for singularity
if (solverPerf.checkSingularity(mag(wApA)/norm))
{
break;
}
// Update solution and raw residual
alpha = rho/wApA;
forAll (x, i)
{
x[i] += alpha*pA[i];
}
forAll (rA, i)
{
rA[i] -= alpha*wA[i];
}
solverPerf.finalResidual() = gSum(cmptMag(rA))/norm;
solverPerf.nIterations()++;
} while (!stop(solverPerf));
}
return solverPerf;
}
// ************************************************************************* //

View file

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockCGSolver
Description
Preconditioned Conjugate Gradient solver.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
BlockCGSolver.C
\*---------------------------------------------------------------------------*/
#ifndef BlockCGSolver_H
#define BlockCGSolver_H
#include "blockLduSolvers.H"
#include "BlockIterativeSolver.H"
#include "blockLduPrecons.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BlockCGSolver Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class BlockCGSolver
:
public BlockIterativeSolver<Type>
{
// Private data
//- Preconditioner
autoPtr<BlockLduPrecon<Type> > preconPtr_;
// Private Member Functions
//- Disallow default bitwise copy construct
BlockCGSolver(const BlockCGSolver<Type>&);
//- Disallow default bitwise assignment
void operator=(const BlockCGSolver<Type>&);
public:
//- Runtime type information
TypeName("CG");
// Constructors
//- Construct from matrix components and solver data stream
BlockCGSolver
(
const word& fieldName,
const BlockLduMatrix<Type>& matrix,
const FieldField<CoeffField, Type>& boundaryCoeffs,
const typename BlockLduInterfaceFieldPtrsList<Type>::Type& interfaces,
const dictionary& solverDict
);
// Destructor
virtual ~BlockCGSolver()
{}
// Member Functions
//- Solve the matrix with this solver
virtual BlockSolverPerformance<Type> solve
(
Field<Type>& x,
const Field<Type>& b
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BlockCGSolver.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
Preconditioned Conjugate Gradient solver.
\*---------------------------------------------------------------------------*/
#include "blockLduMatrices.H"
#include "blockCGSolvers.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeBlockSolvers(blockCGSolver);
addSymSolverToBlockMatrix(blockCGSolver);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
\\/ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Class
BlockCGSolver
Description
Typedefs for Preconditioned Conjugate Gradient solver.
Author
Hrvoje Jasak, Wikki Ltd. All rights reserved
SourceFiles
blockCGSolvers.C
\*---------------------------------------------------------------------------*/
#ifndef blockCGSolvers_H
#define blockCGSolvers_H
#include "BlockCGSolver.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef BlockCGSolver<scalar> blockCGSolverScalar;
typedef BlockCGSolver<vector> blockCGSolverVector;
typedef BlockCGSolver<tensor> blockCGSolverTensor;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

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