OpenFOAM logo
Open Source CFD Toolkit

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