runTimePostProcessing.C
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) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
25 
26 // OpenFOAM includes
27 #include "runTimePostProcessing.H"
28 #include "dictionary.H"
29 #include "pointData.H"
30 #include "pathline.H"
31 #include "surface.H"
32 #include "text.H"
33 #include "Time.H"
34 #include "sigFpe.H"
35 
36 // VTK includes
37 #include "vtkPolyDataMapper.h"
38 #include "vtkRenderer.h"
39 #include "vtkRenderWindow.h"
40 #include "vtkSmartPointer.h"
41 
42 #include "vtkLight.h"
43 
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48  defineTypeNameAndDebug(runTimePostProcessing, 0);
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const word& name,
57  const objectRegistry& obr,
58  const dictionary& dict,
59  const bool loadFromFiles
60 )
61 :
63  scene_(obr, name),
64  points_(),
65  lines_(),
66  surfaces_(),
67  text_(),
68  obr_(obr),
69  active_(true)
70 {
71  read(dict);
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  Info<< type() << " " << name_ << ": reading post-processing data" << endl;
86 
87  scene_.read(dict);
88 
89  const dictionary& outputDict = dict.subDict("output");
90  outputDict.lookup("name") >> output_.name_;
91  outputDict.lookup("width") >> output_.width_;
92  outputDict.lookup("height") >> output_.height_;
93 
94 
95  readObjects(dict.subOrEmptyDict("points"), points_);
96  readObjects(dict.subOrEmptyDict("lines"), lines_);
97  readObjects(dict.subOrEmptyDict("surfaces"), surfaces_);
98 
99 
100  const dictionary& textDict = dict.subDict("text");
101  forAllConstIter(dictionary, textDict, iter)
102  {
103  if (!iter().isDict())
104  {
105  FatalIOErrorInFunction(textDict)
106  << "text must be specified in dictionary format"
107  << exit(FatalIOError);
108  }
109 
110  text_.append(new text(*this, iter().dict(), scene_.colours()));
111  }
112 }
113 
114 
116 {
117  // Do nothing
118 }
119 
120 
122 {
123  // Do nothing
124 }
125 
126 
128 {
129  // Do nothing
130 }
131 
132 
134 {
135  if (!Pstream::master())
136  {
137  return;
138  }
139 
140  Info<< type() << " " << name_ << " output:" << nl
141  << " Constructing scene" << endl;
142 
143  // Unset any floating point trapping (some low-level rendering functionality
144  // does not like it)
145  sigFpe::unset(false);
146 
147  // Initialise render window
148  vtkSmartPointer<vtkRenderWindow> renderWindow =
150  renderWindow->OffScreenRenderingOn();
151  renderWindow->SetSize(output_.width_, output_.height_);
152  renderWindow->SetAAFrames(10);
153  renderWindow->SetAlphaBitPlanes(true);
154  renderWindow->SetMultiSamples(0);
155 // renderWindow->PolygonSmoothingOn();
156 
157  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
158  scene_.initialise(renderer, output_.name_);
159 
160  renderWindow->AddRenderer(renderer);
161 
162  // Add the points
163  forAll(points_, i)
164  {
165  points_[i].addGeometryToScene(0, renderer);
166  }
167 
168  // Add the lines
169  forAll(lines_, i)
170  {
171  lines_[i].addGeometryToScene(0, renderer);
172  }
173 
174  // Add the surfaces
175  forAll(surfaces_, i)
176  {
177  surfaces_[i].addGeometryToScene(0, renderer);
178  }
179 
180  while (scene_.loop(renderer))
181  {
182  scalar position = scene_.position();
183 
184  // Add the text
185  forAll(text_, i)
186  {
187  text_[i].addGeometryToScene(position, renderer);
188  }
189 
190  // Update the points
191  forAll(points_, i)
192  {
193  points_[i].updateActors(position);
194  }
195 
196  // Update the lines
197  forAll(lines_, i)
198  {
199  lines_[i].updateActors(position);
200  }
201 
202  // Update the surfaces
203  forAll(surfaces_, i)
204  {
205  surfaces_[i].updateActors(position);
206  }
207  }
208 
209  // Reset any floating point trapping
210  sigFpe::set(false);
211 }
212 
213 
214 // ************************************************************************* //
Foam::sigFpe::set
static void set(const bool verbose)
Activate SIGFPE signal handler when FOAM_SIGFPE is set.
Definition: sigFpe.C:131
surface.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
pathline.H
Foam::runTimePostProcessing::~runTimePostProcessing
virtual ~runTimePostProcessing()
Desructor.
Definition: runTimePostProcessing.C:77
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
pointData.H
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::runTimePostProcessing::execute
virtual void execute()
Execute, currently does nothing.
Definition: runTimePostProcessing.C:115
text.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::runTimePostProcessing::write
virtual void write()
Write.
Definition: runTimePostProcessing.C:133
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::runTimePostProcessing::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: runTimePostProcessing.C:127
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::runTimePostProcessing::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: runTimePostProcessing.C:121
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
runTimePostProcessing.H
Foam::ITstream::name_
fileName name_
Name of ITstream.
Definition: ITstream.H:57
Foam::runTimePostProcessing::runTimePostProcessing
runTimePostProcessing(const word &name, const objectRegistry &, const dictionary &, const bool loadFromFiles=false)
Construct from dictionary.
Definition: runTimePostProcessing.C:55
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:666
dictionary.H
Foam::runTimePostProcessing::read
virtual void read(const dictionary &)
Read the field min/max data.
Definition: runTimePostProcessing.C:83
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::text
Definition: text.H:50
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
sigFpe.H
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::sigFpe::unset
static void unset(const bool verbose)
Deactivate SIGFPE signal handler and NaN memory initialisation.
Definition: sigFpe.C:226