writeVTK.C
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) 2016-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "writeVTK.H"
27 #include "dictionary.H"
28 #include "Time.H"
29 #include "vtkMesh.H"
30 #include "internalWriter.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
40  addToRunTimeSelectionTable(functionObject, writeVTK, dictionary);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& name,
50  const Time& runTime,
51  const dictionary& dict
52 )
53 :
54  fvMeshFunctionObject(name, runTime, dict),
55  objectNames_()
56 {
57  read(dict);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
69 bool Foam::functionObjects::writeVTK::read(const dictionary& dict)
70 {
71  dict.lookup("objects") >> objectNames_;
72 
73  return true;
74 }
75 
76 
78 {
79  return true;
80 }
81 
82 
84 {
85  Info<< type() << " " << name() << " output:" << nl;
86 
87  Info<< "Time: " << time_.timeName() << endl;
88 
89  word timeDesc = time_.timeName();
90 
91  // VTK/ directory in the case
92  fileName fvPath(time_.path()/"VTK");
93 
94  mkDir(fvPath);
95 
96  string vtkName = time_.caseName();
97 
98  if (Pstream::parRun())
99  {
100  // Strip off leading casename, leaving just processor_DDD ending.
101  string::size_type i = vtkName.rfind("processor");
102 
103  if (i != string::npos)
104  {
105  vtkName = vtkName.substr(i);
106  }
107  }
108 
109  // Create file and write header
110  fileName vtkFileName
111  (
112  fvPath/vtkName
113  + "_"
114  + timeDesc
115  + ".vtk"
116  );
117 
118  Info<< " Internal : " << vtkFileName << endl;
119 
120  vtkMesh vMesh(const_cast<fvMesh&>(mesh_));
121 
122  // Write mesh
123  internalWriter writer(vMesh, false, vtkFileName);
124 
125  UPtrList<const volScalarField> vsf(lookupFields<volScalarField>());
126  UPtrList<const volVectorField> vvf(lookupFields<volVectorField>());
127  UPtrList<const volSphericalTensorField> vsptf
128  (
129  lookupFields<volSphericalTensorField>()
130  );
131  UPtrList<const volSymmTensorField> vstf(lookupFields<volSymmTensorField>());
132  UPtrList<const volTensorField> vtf(lookupFields<volTensorField>());
133 
134  // Write header for cellID and volFields
136  (
137  writer.os(),
138  vMesh.nFieldCells(),
139  1 + vsf.size() + vvf.size() + vsptf.size() + vstf.size() + vtf.size()
140  );
141 
142  // Write cellID field
143  writer.writeCellIDs();
144 
145  // Write volFields
146  writer.write(vsf);
147  writer.write(vvf);
148  writer.write(vsptf);
149  writer.write(vstf);
150  writer.write(vtf);
151 
152  return true;
153 }
154 
155 
156 // ************************************************************************* //
static void writeCellDataHeader(std::ostream &, const label nCells, const label nFields)
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Macros for easy insertion into run-time selection tables.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual ~writeVTK()
Destructor.
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
virtual bool write()
Write the writeVTK.
static const char nl
Definition: Ostream.H:265
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
virtual bool read(const dictionary &)
Read the writeVTK data.
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
virtual bool execute()
Execute, currently does nothing.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
messageStream Info
void writeVTK(OFstream &os, const Type &value)
writeVTK(const word &name, const Time &t, const dictionary &)
Construct from Time and dictionary.
Namespace for OpenFOAM.