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

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