OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

boundBox.C

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-2009 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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "boundBox.H"
00028 #include "PstreamReduceOps.H"
00029 #include "tmp.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 const Foam::scalar Foam::boundBox::great(VGREAT);
00034 
00035 const Foam::boundBox Foam::boundBox::greatBox
00036 (
00037     point(-VGREAT, -VGREAT, -VGREAT),
00038     point(VGREAT, VGREAT, VGREAT)
00039 );
00040 
00041 
00042 const Foam::boundBox Foam::boundBox::invertedBox
00043 (
00044     point(VGREAT, VGREAT, VGREAT),
00045     point(-VGREAT, -VGREAT, -VGREAT)
00046 );
00047 
00048 
00049 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00050 
00051 void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
00052 {
00053     if (points.empty())
00054     {
00055         min_ = point::zero;
00056         max_ = point::zero;
00057 
00058         if (doReduce && Pstream::parRun())
00059         {
00060             // Use values that get overwritten by reduce minOp, maxOp below
00061             min_ = point(VGREAT, VGREAT, VGREAT);
00062             max_ = point(-VGREAT, -VGREAT, -VGREAT);
00063         }
00064     }
00065     else
00066     {
00067         min_ = points[0];
00068         max_ = points[0];
00069 
00070         for (label i = 1; i < points.size(); i++)
00071         {
00072             min_ = ::Foam::min(min_, points[i]);
00073             max_ = ::Foam::max(max_, points[i]);
00074         }
00075     }
00076 
00077     // Reduce parallel information
00078     if (doReduce)
00079     {
00080         reduce(min_, minOp<point>());
00081         reduce(max_, maxOp<point>());
00082     }
00083 }
00084 
00085 
00086 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00087 
00088 Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
00089 :
00090     min_(point::zero),
00091     max_(point::zero)
00092 {
00093     calculate(points, doReduce);
00094 }
00095 
00096 
00097 Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
00098 :
00099     min_(point::zero),
00100     max_(point::zero)
00101 {
00102     calculate(points(), doReduce);
00103     points.clear();
00104 }
00105 
00106 
00107 Foam::boundBox::boundBox(Istream& is)
00108 {
00109     operator>>(is, *this);
00110 }
00111 
00112 
00113 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00114 
00115 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
00116 {
00117     if (os.format() == IOstream::ASCII)
00118     {
00119         os << bb.min_ << token::SPACE << bb.max_;
00120     }
00121     else
00122     {
00123         os.write
00124         (
00125             reinterpret_cast<const char*>(&bb.min_),
00126             sizeof(boundBox)
00127         );
00128     }
00129 
00130     // Check state of Ostream
00131     os.check("Ostream& operator<<(Ostream&, const boundBox&)");
00132     return os;
00133 }
00134 
00135 
00136 Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
00137 {
00138     if (is.format() == IOstream::ASCII)
00139     {
00140         return is >> bb.min_ >> bb.max_;
00141     }
00142     else
00143     {
00144         is.read
00145         (
00146             reinterpret_cast<char*>(&bb.min_),
00147             sizeof(boundBox)
00148         );
00149     }
00150 
00151     // Check state of Istream
00152     is.check("Istream& operator>>(Istream&, boundBox&)");
00153     return is;
00154 }
00155 
00156 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd