Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / matrices / blockLduMatrix / BlockLduMatrix / BlockConstraint / BlockConstraint.C
blobbe3dfc44e58bd008b3dc3315b66b8fb72dee3efb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     A storage mechanism which allows setting of the fixed value and
26     consequently recovering the equation for a single row of the matrix as
27     well as the source. The equation is taken out of the matrix using a
28     variant of compact matrix storage mechanism.
30 Author
31     Hrvoje Jasak, Wikki Ltd.  All rights reserved.
33 \*---------------------------------------------------------------------------*/
35 #include "error.H"
37 #include "BlockConstraint.H"
38 #include "demandDrivenData.H"
39 #include "BlockLduMatrix.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 // Construct from components
49 template<class Type>
50 BlockConstraint<Type>::BlockConstraint
52     const label row,
53     const Type value,
54     const Type& fixedCmpts
57     rowID_(row),
58     value_(value),
59     fixedComponents_(fixedCmpts),
60     matrixCoeffsSet_(false),
61     diagCoeff_(),
62     upperCoeffsOwnerPtr_(NULL),
63     upperCoeffsNeighbourPtr_(NULL),
64     lowerCoeffsOwnerPtr_(NULL),
65     lowerCoeffsNeighbourPtr_(NULL)
69 // Construct as copy
70 template<class Type>
71 BlockConstraint<Type>::BlockConstraint(const BlockConstraint& e)
73     rowID_(e.rowID_),
74     value_(e.value_),
75     fixedComponents_(e.fixedComponents_),
76     matrixCoeffsSet_(false),
77     upperCoeffsOwnerPtr_(NULL),
78     upperCoeffsNeighbourPtr_(NULL),
79     lowerCoeffsOwnerPtr_(NULL),
80     lowerCoeffsNeighbourPtr_(NULL)
84 // Construct from Istream
85 template<class Type>
86 BlockConstraint<Type>::BlockConstraint(Istream& is)
88     rowID_(readLabel(is)),
89     value_(pTraits<Type>(is)),
90     fixedComponents_(pTraits<Type>(is)),
91     matrixCoeffsSet_(false),
92     upperCoeffsOwnerPtr_(NULL),
93     upperCoeffsNeighbourPtr_(NULL),
94     lowerCoeffsOwnerPtr_(NULL),
95     lowerCoeffsNeighbourPtr_(NULL)
99 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
101 template<class Type>
102 BlockConstraint<Type>::~BlockConstraint()
104     deleteDemandDrivenData(upperCoeffsOwnerPtr_);
105     deleteDemandDrivenData(upperCoeffsNeighbourPtr_);
107     deleteDemandDrivenData(lowerCoeffsOwnerPtr_);
108     deleteDemandDrivenData(lowerCoeffsNeighbourPtr_);
112 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
114 template<class Type>
115 const BlockCoeff<Type>& BlockConstraint<Type>::diagCoeff() const
117     if (matrixCoeffsSet_)
118     {
119         FatalErrorIn
120         (
121             "const BlockCoeff<Type>& BlockConstraint<Type>::diagCoeff() const"
122         )   << "matrix coefficients not set"
123             << abort(FatalError);
124     }
126     return diagCoeff_;
130 template<class Type>
131 const Type& BlockConstraint<Type>::b() const
133     if (matrixCoeffsSet_)
134     {
135         FatalErrorIn
136         (
137             "Type BlockConstraint<Type>::b() const"
138         )   << "matrix coefficients not set"
139             << abort(FatalError);
140     }
142     return b_;
146 template<class Type>
147 const CoeffField<Type>& BlockConstraint<Type>::upperCoeffsOwner() const
149     if (!upperCoeffsOwnerPtr_ || !matrixCoeffsSet_)
150     {
151         FatalErrorIn
152         (
153             "const CoeffField<Type>& BlockConstraint<Type>::"
154             "upperCoeffsOwner() const"
155         )   << "upper matrix coefficients not set"
156             << abort(FatalError);
157     }
159     return *upperCoeffsOwnerPtr_;
163 template<class Type>
164 const CoeffField<Type>& BlockConstraint<Type>::upperCoeffsNeighbour() const
166     if (!upperCoeffsNeighbourPtr_ || !matrixCoeffsSet_)
167     {
168         FatalErrorIn
169         (
170             "const CoeffField<Type>& BlockConstraint<Type>::"
171             "upperCoeffsNeighbour() const"
172         )   << "upper matrix coefficients not set"
173             << abort(FatalError);
174     }
176     return *upperCoeffsNeighbourPtr_;
180 template<class Type>
181 const CoeffField<Type>& BlockConstraint<Type>::lowerCoeffsOwner() const
183     if (!lowerCoeffsOwnerPtr_ || !matrixCoeffsSet_)
184     {
185         FatalErrorIn
186         (
187             "const CoeffField<Type>& BlockConstraint<Type>::"
188             "lowerCoeffsOwner() const"
189         )   << "lower matrix coefficients not set"
190             << abort(FatalError);
191     }
193     return *lowerCoeffsOwnerPtr_;
197 template<class Type>
198 const CoeffField<Type>& BlockConstraint<Type>::lowerCoeffsNeighbour() const
200     if (!lowerCoeffsNeighbourPtr_ || !matrixCoeffsSet_)
201     {
202         FatalErrorIn
203         (
204             "const CoeffField<Type>& BlockConstraint<Type>::"
205             "lowerCoeffsNeighbour() const"
206         )   << "lower matrix coefficients not set"
207             << abort(FatalError);
208     }
210     return *lowerCoeffsNeighbourPtr_;
214 template<class Type>
215 void BlockConstraint<Type>::combine
217     const BlockConstraint<Type>& e
220     for
221     (
222         direction cmptI = 0;
223         cmptI < pTraits<Type>::nComponents;
224         cmptI++
225     )
226     {
227         if
228         (
229             e.fixedComponents_.component(cmptI)
230           > fixedComponents_.component(cmptI)
231         )
232         {
233             fixedComponents_.component(cmptI) =
234                 e.fixedComponents_.component(cmptI);
236             value_.replace(cmptI, e.value_.component(cmptI));
237         }
238     }
242 template<class Type>
243 void BlockConstraint<Type>::clearMatrix()
245     matrixCoeffsSet_ = false;
247     diagCoeff_.clear();
249     b_ = pTraits<Type>::zero;
251     deleteDemandDrivenData(upperCoeffsOwnerPtr_);
252     deleteDemandDrivenData(upperCoeffsNeighbourPtr_);
254     deleteDemandDrivenData(lowerCoeffsOwnerPtr_);
255     deleteDemandDrivenData(lowerCoeffsNeighbourPtr_);
259 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
261 template<class Type>
262 void BlockConstraint<Type>::operator=
264     const BlockConstraint<Type>& rhs
267     // Check for assignment to self
268     if (this == &rhs)
269     {
270         FatalErrorIn
271         (
272             "BlockConstraint::operator=(const BlockConstraint&)"
273         )   << "attempted assignment to self"
274             << abort(FatalError);
275     }
277     rowID_ = rhs.rowID_;
279     value_ = rhs.value_;
281     fixedComponents_ = rhs.fixedComponents_;
283     clearMatrix();
287 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
289 template<class Type>
290 Ostream& operator<<(Ostream& os, const BlockConstraint<Type>& e)
292     os  << e.rowID_ << nl
293         << e.value_ << nl
294         << e.fixedComponents_ << nl;
296     os.check("Ostream& operator<<(Ostream&, BlockConstraint<Type>&");
298     return os;
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 } // End namespace Foam
306 // ************************************************************************* //