BlockMatrixAgglomeration
[foam-extend-3.0.git] / src / foam / meshes / boundBox / boundBox.C
blob9756f6e16a709534cac082183ee44947535206ae
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
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 \*---------------------------------------------------------------------------*/
26 #include "boundBox.H"
27 #include "PstreamReduceOps.H"
28 #include "tmp.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 const Foam::scalar Foam::boundBox::great(VGREAT);
34 const Foam::boundBox Foam::boundBox::greatBox
36     point(-VGREAT, -VGREAT, -VGREAT),
37     point(VGREAT, VGREAT, VGREAT)
41 const Foam::boundBox Foam::boundBox::invertedBox
43     point(VGREAT, VGREAT, VGREAT),
44     point(-VGREAT, -VGREAT, -VGREAT)
48 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
50 void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
52     if (points.empty())
53     {
54         min_ = point::zero;
55         max_ = point::zero;
57         if (doReduce && Pstream::parRun())
58         {
59             // Use values that get overwritten by reduce minOp, maxOp below
60             min_ = point(VGREAT, VGREAT, VGREAT);
61             max_ = point(-VGREAT, -VGREAT, -VGREAT);
62         }
63     }
64     else
65     {
66         min_ = points[0];
67         max_ = points[0];
69         forAll(points, i)
70         {
71             min_ = ::Foam::min(min_, points[i]);
72             max_ = ::Foam::max(max_, points[i]);
73         }
74     }
76     // Reduce parallel information
77     if (doReduce)
78     {
79         reduce(min_, minOp<point>());
80         reduce(max_, maxOp<point>());
81     }
85 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
87 Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
89     min_(point::zero),
90     max_(point::zero)
92     calculate(points, doReduce);
96 Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
98     min_(point::zero),
99     max_(point::zero)
101     calculate(points(), doReduce);
102     points.clear();
106 Foam::boundBox::boundBox(Istream& is)
108     operator>>(is, *this);
112 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
114 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
116     if (os.format() == IOstream::ASCII)
117     {
118         os << bb.min_ << token::SPACE << bb.max_;
119     }
120     else
121     {
122         os.write
123         (
124             reinterpret_cast<const char*>(&bb.min_),
125             sizeof(boundBox)
126         );
127     }
129     // Check state of Ostream
130     os.check("Ostream& operator<<(Ostream&, const boundBox&)");
131     return os;
135 Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
137     if (is.format() == IOstream::ASCII)
138     {
139         return is >> bb.min_ >> bb.max_;
140     }
141     else
142     {
143         is.read
144         (
145             reinterpret_cast<char*>(&bb.min_),
146             sizeof(boundBox)
147         );
148     }
150     // Check state of Istream
151     is.check("Istream& operator>>(Istream&, boundBox&)");
152     return is;
155 // ************************************************************************* //