1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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/>.
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.
31 Hrvoje Jasak, Wikki Ltd. All rights reserved.
33 \*---------------------------------------------------------------------------*/
37 #include "BlockConstraint.H"
38 #include "demandDrivenData.H"
39 #include "BlockLduMatrix.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 // Construct from components
50 BlockConstraint<Type>::BlockConstraint
54 const Type& fixedCmpts
59 fixedComponents_(fixedCmpts),
60 matrixCoeffsSet_(false),
62 upperCoeffsOwnerPtr_(NULL),
63 upperCoeffsNeighbourPtr_(NULL),
64 lowerCoeffsOwnerPtr_(NULL),
65 lowerCoeffsNeighbourPtr_(NULL)
71 BlockConstraint<Type>::BlockConstraint(const BlockConstraint& e)
75 fixedComponents_(e.fixedComponents_),
76 matrixCoeffsSet_(false),
77 upperCoeffsOwnerPtr_(NULL),
78 upperCoeffsNeighbourPtr_(NULL),
79 lowerCoeffsOwnerPtr_(NULL),
80 lowerCoeffsNeighbourPtr_(NULL)
84 // Construct from Istream
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 * * * * * * * * * * * * * * * //
102 BlockConstraint<Type>::~BlockConstraint()
104 deleteDemandDrivenData(upperCoeffsOwnerPtr_);
105 deleteDemandDrivenData(upperCoeffsNeighbourPtr_);
107 deleteDemandDrivenData(lowerCoeffsOwnerPtr_);
108 deleteDemandDrivenData(lowerCoeffsNeighbourPtr_);
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 const BlockCoeff<Type>& BlockConstraint<Type>::diagCoeff() const
117 if (matrixCoeffsSet_)
121 "const BlockCoeff<Type>& BlockConstraint<Type>::diagCoeff() const"
122 ) << "matrix coefficients not set"
123 << abort(FatalError);
131 const Type& BlockConstraint<Type>::b() const
133 if (matrixCoeffsSet_)
137 "Type BlockConstraint<Type>::b() const"
138 ) << "matrix coefficients not set"
139 << abort(FatalError);
147 const CoeffField<Type>& BlockConstraint<Type>::upperCoeffsOwner() const
149 if (!upperCoeffsOwnerPtr_ || !matrixCoeffsSet_)
153 "const CoeffField<Type>& BlockConstraint<Type>::"
154 "upperCoeffsOwner() const"
155 ) << "upper matrix coefficients not set"
156 << abort(FatalError);
159 return *upperCoeffsOwnerPtr_;
164 const CoeffField<Type>& BlockConstraint<Type>::upperCoeffsNeighbour() const
166 if (!upperCoeffsNeighbourPtr_ || !matrixCoeffsSet_)
170 "const CoeffField<Type>& BlockConstraint<Type>::"
171 "upperCoeffsNeighbour() const"
172 ) << "upper matrix coefficients not set"
173 << abort(FatalError);
176 return *upperCoeffsNeighbourPtr_;
181 const CoeffField<Type>& BlockConstraint<Type>::lowerCoeffsOwner() const
183 if (!lowerCoeffsOwnerPtr_ || !matrixCoeffsSet_)
187 "const CoeffField<Type>& BlockConstraint<Type>::"
188 "lowerCoeffsOwner() const"
189 ) << "lower matrix coefficients not set"
190 << abort(FatalError);
193 return *lowerCoeffsOwnerPtr_;
198 const CoeffField<Type>& BlockConstraint<Type>::lowerCoeffsNeighbour() const
200 if (!lowerCoeffsNeighbourPtr_ || !matrixCoeffsSet_)
204 "const CoeffField<Type>& BlockConstraint<Type>::"
205 "lowerCoeffsNeighbour() const"
206 ) << "lower matrix coefficients not set"
207 << abort(FatalError);
210 return *lowerCoeffsNeighbourPtr_;
215 void BlockConstraint<Type>::combine
217 const BlockConstraint<Type>& e
223 cmptI < pTraits<Type>::nComponents;
229 e.fixedComponents_.component(cmptI)
230 > fixedComponents_.component(cmptI)
233 fixedComponents_.component(cmptI) =
234 e.fixedComponents_.component(cmptI);
236 value_.replace(cmptI, e.value_.component(cmptI));
243 void BlockConstraint<Type>::clearMatrix()
245 matrixCoeffsSet_ = false;
249 b_ = pTraits<Type>::zero;
251 deleteDemandDrivenData(upperCoeffsOwnerPtr_);
252 deleteDemandDrivenData(upperCoeffsNeighbourPtr_);
254 deleteDemandDrivenData(lowerCoeffsOwnerPtr_);
255 deleteDemandDrivenData(lowerCoeffsNeighbourPtr_);
259 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
262 void BlockConstraint<Type>::operator=
264 const BlockConstraint<Type>& rhs
267 // Check for assignment to self
272 "BlockConstraint::operator=(const BlockConstraint&)"
273 ) << "attempted assignment to self"
274 << abort(FatalError);
281 fixedComponents_ = rhs.fixedComponents_;
287 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
290 Ostream& operator<<(Ostream& os, const BlockConstraint<Type>& e)
294 << e.fixedComponents_ << nl;
296 os.check("Ostream& operator<<(Ostream&, BlockConstraint<Type>&");
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 } // End namespace Foam
306 // ************************************************************************* //