initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / boundBox / boundBox.C
blob15de6f2cf7f5b575e98e3a5e8c697188c9b6f4b3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "boundBox.H"
28 #include "PstreamReduceOps.H"
29 #include "tmp.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 const Foam::scalar Foam::boundBox::great(VGREAT);
35 const Foam::boundBox Foam::boundBox::greatBox
37     point(-VGREAT, -VGREAT, -VGREAT),
38     point(VGREAT, VGREAT, VGREAT)
42 const Foam::boundBox Foam::boundBox::invertedBox
44     point(VGREAT, VGREAT, VGREAT),
45     point(-VGREAT, -VGREAT, -VGREAT)
49 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
51 void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
53     if (points.empty())
54     {
55         min_ = point::zero;
56         max_ = point::zero;
58         if (doReduce && Pstream::parRun())
59         {
60             // Use values that get overwritten by reduce minOp, maxOp below
61             min_ = point(VGREAT, VGREAT, VGREAT);
62             max_ = point(-VGREAT, -VGREAT, -VGREAT);
63         }
64     }
65     else
66     {
67         min_ = points[0];
68         max_ = points[0];
70         for (label i = 1; i < points.size(); i++)
71         {
72             min_ = ::Foam::min(min_, points[i]);
73             max_ = ::Foam::max(max_, points[i]);
74         }
75     }
77     // Reduce parallel information
78     if (doReduce)
79     {
80         reduce(min_, minOp<point>());
81         reduce(max_, maxOp<point>());
82     }
86 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
88 Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
90     min_(point::zero),
91     max_(point::zero)
93     calculate(points, doReduce);
97 Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
99     min_(point::zero),
100     max_(point::zero)
102     calculate(points(), doReduce);
103     points.clear();
107 Foam::boundBox::boundBox(Istream& is)
109     operator>>(is, *this);
113 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
115 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
117     if (os.format() == IOstream::ASCII)
118     {
119         os << bb.min_ << token::SPACE << bb.max_;
120     }
121     else
122     {
123         os.write
124         (
125             reinterpret_cast<const char*>(&bb.min_),
126             sizeof(boundBox)
127         );
128     }
130     // Check state of Ostream
131     os.check("Ostream& operator<<(Ostream&, const boundBox&)");
132     return os;
136 Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
138     if (is.format() == IOstream::ASCII)
139     {
140         return is >> bb.min_ >> bb.max_;
141     }
142     else
143     {
144         is.read
145         (
146             reinterpret_cast<char*>(&bb.min_),
147             sizeof(boundBox)
148         );
149     }
151     // Check state of Istream
152     is.check("Istream& operator>>(Istream&, boundBox&)");
153     return is;
156 // ************************************************************************* //