OpenFOAM logo
Open Source CFD Toolkit

constraint.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     constraint
00027 
00028 Description
00029     A storage mechanism which allows setting of the fixed value and
00030     consequently recovering the equation for a single row of the matrix as
00031     well as the source. The equation is taken out of the matrix using a
00032     variant of compact matrix storage mechanism.
00033 
00034 SourceFiles
00035     constraint.C
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef constraint_H
00040 #define constraint_H
00041 
00042 #include "labelList.H"
00043 #include "scalarField.H"
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 template<class Type>
00051 class constraint;
00052 
00053 template<class Type>
00054 Ostream& operator<<(Ostream&, const constraint<Type>&);
00055 
00056 
00057 /*---------------------------------------------------------------------------*\
00058                         Class constraint Declaration
00059 \*---------------------------------------------------------------------------*/
00060 
00061 template<class Type>
00062 class constraint
00063 {
00064     // Private data
00065 
00066         //- Matrix row ID
00067         label rowID_;
00068 
00069         //- Fixed value
00070         Type value_;
00071 
00072         //- Fixed components (0-1) 1 = fixed, 0 = free
00073         Type fixedComponents_;
00074 
00075         //- Are matrix coefficients set?
00076         bool matrixCoeffsSet_;
00077 
00078         //- Diagonal coefficient
00079         scalar diagCoeff_;
00080 
00081         //- Source
00082         Type source_;
00083 
00084         //- Upper coefficients
00085         scalarField* upperCoeffsOwnerPtr_;
00086 
00087         scalarField* upperCoeffsNeighbourPtr_;
00088 
00089         //- Lower coefficients
00090         scalarField* lowerCoeffsOwnerPtr_;
00091 
00092         scalarField* lowerCoeffsNeighbourPtr_;
00093 
00094     // Private Member Functions
00095 
00096         //- Return scalar component of value. Used to simplify templating
00097         scalar componentOfValue(const Type&, const direction) const;
00098 
00099 
00100 public:
00101 
00102 
00103     // Constructors
00104 
00105         //- Construct from components
00106         constraint
00107         (
00108             const label row,
00109             const Type value,
00110             const Type& fixedCmpts = pTraits<Type>::one
00111         );
00112 
00113         //- Construct from matrix and other components
00114         template<template<class> class Matrix>
00115         constraint
00116         (
00117             const Matrix<Type>&,
00118             const label row,
00119             const Type value,
00120             const Type& fixedCmpts = pTraits<Type>::one
00121         );
00122 
00123         //- Construct as copy
00124         constraint(const constraint&);
00125 
00126         //- Construct from Istream
00127         constraint(Istream&);
00128 
00129 
00130     // Destructor
00131 
00132         ~constraint();
00133 
00134 
00135     // Member Functions
00136 
00137         //- Return matrix row ID
00138         label rowID() const
00139         {
00140             return rowID_;
00141         }
00142 
00143         //- Return fixed value
00144         Type value() const
00145         {
00146             return value_;
00147         }
00148 
00149         //- Return map of fixed components
00150         const Type& fixedComponents() const
00151         {
00152             return fixedComponents_;
00153         }
00154 
00155         //- Return diagonal coefficient
00156         scalar diagCoeff() const;
00157 
00158         //- Return source
00159         Type source() const;
00160 
00161         //- Return off-diagonal coefficients
00162         const scalarField& upperCoeffsOwner() const;
00163 
00164         const scalarField& upperCoeffsNeighbour() const;
00165 
00166         const scalarField& lowerCoeffsOwner() const;
00167 
00168         const scalarField& lowerCoeffsNeighbour() const;
00169 
00170         //- Combine with existing equation
00171         void combine(const constraint&);
00172 
00173         //- Set matrix coefficients
00174         template<template<class> class Matrix>
00175         void setMatrix(const Matrix<Type>&);
00176 
00177 
00178         //- Eliminate equation
00179         template<template<class> class Matrix>
00180         static void eliminateEquation(Matrix<Type>&, const label, const Type&);
00181 
00182         //- Eliminate equation
00183         template<template<class> class Matrix>
00184         void eliminateEquation(Matrix<Type>&) const;
00185 
00186         //- Eliminate component equation with given direction and
00187         //  component source
00188         template<template<class> class Matrix>
00189         void eliminateEquation
00190         (
00191             Matrix<Type>&,
00192             const direction,
00193             scalarField&
00194         ) const;
00195 
00196 
00197         //- Set source in eliminated equation
00198         template<template<class> class Matrix>
00199         static void setSource(Matrix<Type>&, const label, const Type&);
00200 
00201         //- Set source in eliminated equation
00202         template<template<class> class Matrix>
00203         void setSource(Matrix<Type>&) const;
00204 
00205         //- Set source and diagonal in eliminated equation
00206         template<template<class> class Matrix>
00207         void setSourceDiag
00208         (
00209             Matrix<Type>&,
00210             const direction,
00211             scalarField& psiCmpt,
00212             scalarField& sourceCmpt
00213         ) const;
00214 
00215 
00216         //- Reconstruct matrix coefficients
00217         template<template<class> class Matrix>
00218         void reconstructMatrix(Matrix<Type>&) const;
00219 
00220         //- Clear matrix coefficients
00221         void clearMatrix();
00222 
00223 
00224     // Member Operators
00225 
00226         void operator=(const constraint<Type>&);
00227 
00228 
00229     // Ostream Operator
00230 
00231         friend Ostream& operator<< <Type>
00232         (
00233             Ostream&,
00234             const constraint<Type>&
00235         );
00236 };
00237 
00238 
00239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00240 
00241 } // End namespace Foam
00242 
00243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00244 
00245 #ifdef NoRepository
00246 #    include "constraint.C"
00247 #    include "constraintTools.C"
00248 #endif
00249 
00250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00251 
00252 #include "scalarConstraint.H"
00253 
00254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00255 
00256 #endif
00257 
00258 // ************************************************************************* //
For further information go to www.openfoam.org