FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

graph.H

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::graph
00026 
00027 Description
00028     Class to create, store and output qgraph files.
00029 
00030 SourceFiles
00031     graph.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef graph_H
00036 #define graph_H
00037 
00038 #include <OpenFOAM/string.H>
00039 #include <OpenFOAM/point.H>
00040 #include <OpenFOAM/HashPtrTable.H>
00041 #include <OpenFOAM/curve.H>
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 // Forward declaration of friend functions and operators
00049 
00050 class graph;
00051 
00052 Ostream& operator<<(Ostream&, const graph&);
00053 
00054 
00055 /*---------------------------------------------------------------------------*\
00056                            Class graph Declaration
00057 \*---------------------------------------------------------------------------*/
00058 
00059 class graph
00060 :
00061     public HashPtrTable<curve>
00062 {
00063     // private data
00064 
00065         string title_;
00066         string xName_;
00067         string yName_;
00068 
00069         scalarField x_;
00070 
00071 
00072         struct xy
00073         {
00074             scalar x_, y_;
00075 
00076             xy()
00077             {}
00078 
00079         // Friend Operators
00080 
00081             friend bool operator==(const xy& a, const xy& b)
00082             {
00083                 return equal(a.x_, b.x_) && equal(a.y_, b.y_);
00084             }
00085 
00086             friend bool operator!=(const xy& a, const xy& b)
00087             {
00088                 return !(a == b);
00089             }
00090 
00091             friend Istream& operator>>(Istream& is, xy& xyd)
00092             {
00093                 is >> xyd.x_ >> xyd.y_;
00094                 return is;
00095             }
00096 
00097             friend Ostream& operator<<(Ostream& os, const xy& xyd)
00098             {
00099                 os << xyd.x_ << ' ' << xyd.y_;
00100                 return os;
00101             }
00102         };
00103 
00104 
00105     // private member functions
00106 
00107         void readCurves(Istream&);
00108 
00109 
00110 public:
00111 
00112     // Constructors
00113 
00114         //- Construct from title and labels (no curves)
00115         graph
00116         (
00117             const string& title,
00118             const string& xName,
00119             const string& yName,
00120             const scalarField& x
00121         );
00122 
00123         //- Construct from title, labels and y data for 1 curve
00124         graph
00125         (
00126             const string& title,
00127             const string& xName,
00128             const string& yName,
00129             const scalarField& x,
00130             const scalarField& y
00131         );
00132 
00133         //- Construct from Istream given title and labels
00134         graph
00135         (
00136             const string& title,
00137             const string& xName,
00138             const string& yName,
00139             Istream& is
00140         );
00141 
00142         //- Construct from Istream
00143         graph(Istream& is);
00144 
00145 
00146     // Member functions
00147 
00148         // Access
00149 
00150             const string& title() const
00151             {
00152                 return title_;
00153             }
00154 
00155             const string& xName() const
00156             {
00157                 return xName_;
00158             }
00159 
00160             const string& yName() const
00161             {
00162                 return yName_;
00163             }
00164 
00165 
00166             const scalarField& x() const
00167             {
00168                 return x_;
00169             }
00170 
00171             scalarField& x()
00172             {
00173                 return x_;
00174             }
00175 
00176 
00177             const scalarField& y() const;
00178 
00179             scalarField& y();
00180 
00181 
00182         // Write
00183 
00184             //- Abstract base class for a graph writer
00185             class writer
00186             {
00187 
00188             protected:
00189 
00190                 void writeXY
00191                 (
00192                     const scalarField& x,
00193                     const scalarField& y,
00194                     Ostream&
00195                 ) const;
00196 
00197             public:
00198 
00199                 //- Runtime type information
00200                 TypeName("writer");
00201 
00202                 //- Declare run-time constructor selection table
00203                 declareRunTimeSelectionTable
00204                 (
00205                     autoPtr,
00206                     writer,
00207                     word,
00208                     (),
00209                     ()
00210                 );
00211                 
00212 
00213                 // Selectors
00214                 
00215                     //- Return a reference to the selected writer
00216                     static autoPtr<writer> New
00217                     (
00218                         const word& writeFormat
00219                     );
00220                 
00221 
00222                 // Constructors
00223 
00224                     //- Construct null
00225                     writer()
00226                     {}
00227 
00228 
00229                 // Destructor
00230 
00231                     virtual ~writer()
00232                     {}
00233 
00234 
00235                 // Member Functions
00236 
00237                     // Access
00238 
00239                         //- Return the appropriate fileName extension
00240                         //  for this graph format
00241                         virtual const word& ext() const = 0;
00242 
00243 
00244                     // Write
00245 
00246                         //- Write graph in appropriate format
00247                         virtual void write(const graph&, Ostream&) const = 0;
00248             };
00249 
00250             //- Write out graph data as a simple table
00251             void writeTable(Ostream&) const;
00252 
00253             //- Write graph to stream in given format
00254             void write(Ostream&, const word& format) const;
00255 
00256             //- Write graph to file in given format
00257             void write(const fileName& fName, const word& format) const;
00258 
00259 
00260     // Friend operators
00261 
00262         //- Ostream Operator
00263         friend Ostream& operator<<(Ostream&, const graph&);
00264 };
00265 
00266 
00267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00268 
00269 } // End namespace Foam
00270 
00271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00272 
00273 #endif
00274 
00275 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines