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) 2011-2013 OpenFOAM Foundation
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 "string.H"
39 #include "point.H"
40 #include "HashPtrTable.H"
41 #include "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 
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 
171  scalarField& x()
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
225  writer()
226  {}
227 
228 
229  //- Destructor
230  virtual ~writer()
231  {}
232 
233 
234  // Member Functions
235 
236  // Access
237 
238  //- Return the appropriate fileName extension
239  // for this graph format
240  virtual const word& ext() const = 0;
241 
242 
243  // Write
244 
245  //- Write graph in appropriate format
246  virtual void write(const graph&, Ostream&) const = 0;
247  };
248 
249  //- Write out graph data as a simple table
250  void writeTable(Ostream&) const;
251 
252  //- Write graph to stream in given format
253  void write(Ostream&, const word& format) const;
254 
255  //- Write graph to file in given path-name and format
256  void write(const fileName& pName, const word& format) const;
257 
258  //- Write graph to file in given path, name and format
259  void write
260  (
261  const fileName& path,
262  const word& name,
263  const word& format
264  ) const;
265 
266  //- Helper function to convert string name into appropriate word
267  static word wordify(const string& sname);
268 
269 
270  // Friend operators
271 
272  //- Ostream Operator
273  friend Ostream& operator<<(Ostream&, const graph&);
274 };
275 
276 
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 
279 } // End namespace Foam
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
Foam::graph::writer::ext
virtual const word & ext() const =0
Return the appropriate fileName extension.
Foam::graph::xName
const string & xName() const
Definition: graph.H:154
Foam::graph::title
const string & title() const
Definition: graph.H:149
format
word format(conversionProperties.lookup("format"))
Foam::graph
Class to create, store and output qgraph files.
Definition: graph.H:58
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::graph::wordify
static word wordify(const string &sname)
Helper function to convert string name into appropriate word.
Definition: graph.C:44
Foam::graph::title_
string title_
Definition: graph.H:64
point.H
Foam::graph::xy::operator>>
friend Istream & operator>>(Istream &is, xy &xyd)
Definition: graph.H:90
Foam::graph::graph
graph(const string &title, const string &xName, const string &yName, const scalarField &x)
Construct from title and labels (no curves)
Definition: graph.C:79
Foam::graph::y
const scalarField & y() const
Definition: graph.C:137
string.H
Foam::graph::writer
Abstract base class for a graph writer.
Definition: graph.H:184
Foam::graph::x
const scalarField & x() const
Definition: graph.H:165
Foam::graph::xy::x_
scalar x_
Definition: graph.H:73
Foam::graph::readCurves
void readCurves(Istream &)
Definition: graph.C:55
Foam::graph::xy::xy
xy()
Definition: graph.H:75
Foam::graph::writeTable
void writeTable(Ostream &) const
Write out graph data as a simple table.
Definition: graph.C:206
Foam::graph::writer::~writer
virtual ~writer()
Destructor.
Definition: graph.H:229
Foam::graph::xy::operator!=
friend bool operator!=(const xy &a, const xy &b)
Definition: graph.H:85
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::graph::xName_
string xName_
Definition: graph.H:65
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::graph::write
void write(Ostream &, const word &format) const
Write graph to stream in given format.
Definition: graph.C:221
Foam::graph::xy::operator<<
friend Ostream & operator<<(Ostream &os, const xy &xyd)
Definition: graph.H:96
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::graph::writer::writer
writer()
Construct null.
Definition: graph.H:224
Foam::graph::yName_
string yName_
Definition: graph.H:66
Foam::graph::writer::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, writer, word,(),())
Declare run-time constructor selection table.
Foam::graph::writer::New
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: graph.C:164
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::graph::writer::TypeName
TypeName("writer")
Runtime type information.
Foam::graph::writer::writeXY
void writeXY(const scalarField &x, const scalarField &y, Ostream &) const
Definition: graph.C:193
HashPtrTable.H
Foam::graph::xy
Definition: graph.H:71
path
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Foam::graph::xy::y_
scalar y_
Definition: graph.H:73
Foam::graph::yName
const string & yName() const
Definition: graph.H:159
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::graph::x_
scalarField x_
Definition: graph.H:68
Foam::graph::x
scalarField & x()
Definition: graph.H:170
curve.H
Foam::equal
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:78
Foam::graph::operator<<
friend Ostream & operator<<(Ostream &, const graph &)
Ostream Operator.
Foam::graph::writer::write
virtual void write(const graph &, Ostream &) const =0
Write graph in appropriate format.
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::graph::xy::operator==
friend bool operator==(const xy &a, const xy &b)
Definition: graph.H:80