FreeFOAM The Cross-Platform CFD Toolkit
graph.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::graph
26 
27 Description
28  Class to create, store and output qgraph files.
29 
30 SourceFiles
31  graph.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef graph_H
36 #define graph_H
37 
38 #include <OpenFOAM/string.H>
39 #include <OpenFOAM/point.H>
40 #include <OpenFOAM/HashPtrTable.H>
41 #include <OpenFOAM/curve.H>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of friend functions and operators
49 
50 class graph;
51 
52 Ostream& operator<<(Ostream&, const graph&);
53 
54 
55 /*---------------------------------------------------------------------------*\
56  Class graph Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class graph
60 :
61  public HashPtrTable<curve>
62 {
63  // private data
64 
65  string title_;
66  string xName_;
67  string yName_;
68 
69  scalarField x_;
70 
71 
72  struct xy
73  {
74  scalar x_, y_;
75 
76  xy()
77  {}
78 
79  // Friend Operators
80 
81  friend bool operator==(const xy& a, const xy& b)
82  {
83  return equal(a.x_, b.x_) && equal(a.y_, b.y_);
84  }
85 
86  friend bool operator!=(const xy& a, const xy& b)
87  {
88  return !(a == b);
89  }
90 
91  friend Istream& operator>>(Istream& is, xy& xyd)
92  {
93  is >> xyd.x_ >> xyd.y_;
94  return is;
95  }
96 
97  friend Ostream& operator<<(Ostream& os, const xy& xyd)
98  {
99  os << xyd.x_ << ' ' << xyd.y_;
100  return os;
101  }
102  };
103 
104 
105  // private member functions
106 
107  void readCurves(Istream&);
108 
109 
110 public:
111 
112  // Constructors
113 
114  //- Construct from title and labels (no curves)
115  graph
116  (
117  const string& title,
118  const string& xName,
119  const string& yName,
120  const scalarField& x
121  );
122 
123  //- Construct from title, labels and y data for 1 curve
124  graph
125  (
126  const string& title,
127  const string& xName,
128  const string& yName,
129  const scalarField& x,
130  const scalarField& y
131  );
132 
133  //- Construct from Istream given title and labels
134  graph
135  (
136  const string& title,
137  const string& xName,
138  const string& yName,
139  Istream& is
140  );
141 
142  //- Construct from Istream
143  graph(Istream& is);
144 
145 
146  // Member functions
147 
148  // Access
149 
150  const string& title() const
151  {
152  return title_;
153  }
154 
155  const string& xName() const
156  {
157  return xName_;
158  }
159 
160  const string& yName() const
161  {
162  return yName_;
163  }
164 
165 
166  const scalarField& x() const
167  {
168  return x_;
169  }
170 
172  {
173  return x_;
174  }
175 
176 
177  const scalarField& y() const;
178 
179  scalarField& y();
180 
181 
182  // Write
183 
184  //- Abstract base class for a graph writer
185  class writer
186  {
187 
188  protected:
189 
190  void writeXY
191  (
192  const scalarField& x,
193  const scalarField& y,
194  Ostream&
195  ) const;
196 
197  public:
198 
199  //- Runtime type information
200  TypeName("writer");
201 
202  //- Declare run-time constructor selection table
204  (
205  autoPtr,
206  writer,
207  word,
208  (),
209  ()
210  );
211 
212 
213  // Selectors
214 
215  //- Return a reference to the selected writer
216  static autoPtr<writer> New
217  (
218  const word& writeFormat
219  );
220 
221 
222  // Constructors
223 
224  //- Construct null
226  {}
227 
228 
229  // Destructor
230 
231  virtual ~writer()
232  {}
233 
234 
235  // Member Functions
236 
237  // Access
238 
239  //- Return the appropriate fileName extension
240  // for this graph format
241  virtual const word& ext() const = 0;
242 
243 
244  // Write
245 
246  //- Write graph in appropriate format
247  virtual void write(const graph&, Ostream&) const = 0;
248  };
249 
250  //- Write out graph data as a simple table
251  void writeTable(Ostream&) const;
252 
253  //- Write graph to stream in given format
254  void write(Ostream&, const word& format) const;
255 
256  //- Write graph to file in given format
257  void write(const fileName& fName, const word& format) const;
258 
259 
260  // Friend operators
261 
262  //- Ostream Operator
263  friend Ostream& operator<<(Ostream&, const graph&);
264 };
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************ vim: set sw=4 sts=4 et: ************************ //