graphFunctionObject.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 | www.openfoam.com
6  \/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::functionObjects::graphFunctionObject
28 
29 Description
30  Accumulates function object result values and renders into a graph in
31  SVG format.
32 
33  Operands:
34  \table
35  Operand | Type | Location
36  input | Function object results | Memory; <!--
37  --> $FOAM_CASE/<time>/uniform/functionObjects/functionObjectProperties
38  output file | SVG | <!--
39  --> $FOAM_CASE/postProcessing/<functionObject>/<time>/<functionObject>.svg
40  \endtable
41 
42 Usage
43  Minimal example by using \c system/controlDict.functions to plot the
44  residuals from the \c solverInfo function object:
45 
46  \verbatim
47  residualGraph
48  {
49  // Mandatory entries
50  type graphFunctionObject;
51  libs (utilityFunctionObjects);
52 
53  functions
54  {
55  entry
56  {
57  // Mandatory entries
58  object <word>;
59  entry <word>;
60 
61  // Optional entries
62  title <string>;
63  colour <labelVector>;
64  dashes <labelList>;
65  }
66  line1
67  {
68  object solverInfo1;
69  entry Ux_initial;
70  }
71  line2
72  {
73  object solverInfo1;
74  entry p_initial;
75  }
76  }
77 
78  // Optional entries
79  xMin <scalar>;
80  xMax <scalar>;
81  yMin <scalar>;
82  yMax <scalar>;
83  xlabel <string>; // "Iteration";
84  ylabel <string>; // "log10(Initial residual)";
85  width <label>;
86  height <label>;
87  strokeWidth <label>;
88  logScaleX <bool>;
89  logScaleY <bool>;
90  drawGrid <bool>;
91 
92  // Inherited entries
93  ...
94  }
95  \endverbatim
96 
97  where the entries mean:
98  \table
99  Property | Description | Type | Reqd | Deflt
100  type | Type name: graphFunctionObject | word | yes | -
101  libs | Library name: utilityFunctionObjects | word | yes | -
102  functions | Dictionary of lines to draw | dictionary | yes | -
103  width | Output SVG width in pixel | label| no | 800
104  height | Output SVG height in pixel | label| no | 600
105  xMin | User defined minimum x axis limit | scalar | no | calculated
106  xMax | User defined maximum x axis limit | scalar | no | calculated
107  yMin | User defined minimum y axis limit | scalar | no | calculated
108  yMax | User defined maximum y axis limit | scalar | no | calculated
109  xLabel | X axis label | string | no | Iteration/Time
110  yLabel | Y axis label | string | no | Property
111  strokeWidth | Line stroke width in pixel | label | no | 2
112  logScaleX | Use log scale for x axis | bool | no | false
113  logScaleY | Use log scale for y axis | bool | no | false
114  drawGrid | Draw background grid | bool | no | true
115  \endtable
116 
117  The inherited entries are elaborated in:
118  - \link stateFunctionObject.H \endlink
119  - \link writeFile.H \endlink
120 
121  Each line corresponds to the history of function object result values, e.g.
122 
123  \verbatim
124  line1
125  {
126  object solverInfo1;
127  entry Ux_initial;
128  colour (255 0 0);
129  dashes (4 1);
130  title Ux;
131  }
132  \endverbatim
133 
134  where the entries mean:
135  \table
136  Property | Description | Type | Reqd | Deflt
137  object | Function object name | word | yes | -
138  entry | Function object result entry name | word | yes | -
139  colour | Line colour | label vector | no | auto
140  dashes | Line dash array | label vector | no | auto
141  title | Title | string | no | dict name
142  \endtable
143 
144 See also
145  - Foam::functionObjects::solverInfo
146 
147 SourceFiles
148  graphFunctionObject.C
149 
150 \*---------------------------------------------------------------------------*/
151 
152 #ifndef Foam_functionObjects_graphFunctionObject_H
153 #define Foam_functionObjects_graphFunctionObject_H
154 
155 #include "stateFunctionObject.H"
156 #include "writeFile.H"
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 namespace Foam
161 {
162 
163 namespace functionObjects
164 {
165 
166 /*---------------------------------------------------------------------------*\
167  Class graphFunctionObject Declaration
168 \*---------------------------------------------------------------------------*/
169 
170 class graphFunctionObject
171 :
172  public stateFunctionObject,
173  public writeFile
174 {
175  // Private Data
176 
177  //- List of default curve colours
178  static wordList defaultColours;
179 
180  //- Names of function objects
181  List<word> objects_;
182 
183  //- Function object entries
184  List<word> entries_;
185 
186  //- Line titles
187  List<string> titles_;
188 
189  //- Line colours - hex string
190  List<word> colours_;
191 
192  //- Line dash array
193  List<string> dashes_;
194 
195  //- Times
196  DynamicList<scalar> times_;
197 
198  //- Time vs. flattened values
199  DynamicList<DynamicList<scalar>> values_;
200 
201  //- Mapping from object to column index in values_
202  List<DynamicList<label>> objectToCol_;
203 
204  //- User-supplied minimum x value
205  scalar xMin_;
206 
207  //- User-supplied maximum x value
208  scalar xMax_;
209 
210  //- User-supplied minimum y value
211  scalar yMin_;
212 
213  //- User-supplied maximum y value
214  scalar yMax_;
215 
216  //- X axis label
217  const string xlabel_;
218 
219  //- Y axis label
220  const string ylabel_;
221 
222  //- Width in px
223  const label width_;
224 
225  //- Height in px
226  const label height_;
227 
228  //- Line width in px
229  const label strokeWidth_;
230 
231  //- Flag to use log scale on x-axis
232  bool logScaleX_;
233 
234  //- Flag to use log scale on y-axis
235  bool logScaleY_;
236 
237  //- Draw background grid
238  const bool drawGrid_;
239 
240 
241  // Private Functions
242 
243  //- Get the result value from the function object
244  // \returns true if the value was found
245  template<class Type>
246  bool getValue(const label objecti, label& valuei);
247 
248  //- Set axis min, max, tick
249  // \returns number of ticks
250  label setAxisProps
251  (
252  const bool logScale,
253  scalar& xmin,
254  scalar& xmax,
255  scalar& xtick
256  ) const;
257 
258  //- No copy construct
259  graphFunctionObject(const graphFunctionObject&) = delete;
260 
261  //- No copy assignment
262  void operator=(const graphFunctionObject&) = delete;
263 
264 
265 public:
266 
267  //- Runtime type information
268  TypeName("graphFunctionObject");
269 
270  //- Construct from Time and dictionary
271  graphFunctionObject
272  (
273  const word& name,
274  const Time& runTime,
275  const dictionary& dict
276  );
277 
278  //- Destructor
279  virtual ~graphFunctionObject() = default;
280 
281 
282  // Member Functions
283 
284  //- Execute
285  virtual bool execute();
286 
287  //- Write
288  virtual bool write();
289 };
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 } // End namespace functionObjects
294 } // End namespace Foam
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 #endif
299 
300 // ************************************************************************* //
dictionary dict
virtual ~graphFunctionObject()=default
Destructor.
engineTime & runTime
const word & name() const noexcept
Return the name of this functionObject.
TypeName("graphFunctionObject")
Runtime type information.
List< word > wordList
List of word.
Definition: fileName.H:59
Namespace for OpenFOAM.