All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graph.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 
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
150  const string& title() const
151  {
152  return title_;
153  }
155  const string& xName() const
156  {
157  return xName_;
158  }
160  const string& yName() const
161  {
162  return yName_;
163  }
164 
166  const scalarField& x() const
167  {
168  return x_;
169  }
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 // ************************************************************************* //
friend Ostream & operator<<(Ostream &, const graph &)
Ostream Operator.
A class for handling file names.
Definition: fileName.H:79
void write(Ostream &, const word &format) const
Write graph to stream in given format.
Definition: graph.C:221
const scalarField & y() const
Definition: graph.C:137
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
word format(conversionProperties.lookup("format"))
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
void writeTable(Ostream &) const
Write out graph data as a simple table.
Definition: graph.C:206
Abstract base class for a graph writer.
Definition: graph.H:184
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Class to create, store and output qgraph files.
Definition: graph.H:58
friend Istream & operator>>(Istream &, HashPtrTable< curve, word, string::hash > &)
const dimensionedScalar & b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
A class for handling words, derived from string.
Definition: word.H:59
bool operator!=(const HashTable< T, Key, Hash > &) const
The opposite of the equality operation. Takes linear time.
Definition: HashTable.C:635
const string & xName() const
Definition: graph.H:154
graph(const string &title, const string &xName, const string &yName, const scalarField &x)
Construct from title and labels (no curves)
Definition: graph.C:79
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:70
static word wordify(const string &sname)
Helper function to convert string name into appropriate word.
Definition: graph.C:44
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
bool operator==(const HashTable< T, Key, Hash > &) const
Equality. Hash tables are equal if the keys and values are equal.
Definition: HashTable.C:609
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
Ostream & operator<<(Ostream &, const ensightPart &)
#define declareRunTimeSelectionTable(autoPtr, baseType, argNames, argList, parList)
Declare a run-time selection.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const string & yName() const
Definition: graph.H:159
const string & title() const
Definition: graph.H:149
const scalarField & x() const
Definition: graph.H:165
Namespace for OpenFOAM.
fileName path(UMean.rootPath()/UMean.caseName()/functionObjects::writeFile::outputPrefix/"graphs"/UMean.instance())