ensightSurfaceWriterUncollated.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2014 OpenFOAM Foundation
9  Copyright (C) 2015-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated()
32 {
33  checkOpen();
34 
35  const ensight::FileName surfName(outputPath_.name());
36 
37 
38  // Uncollated
39  // ==========
40  // Geometry: rootdir/<TIME>/surfaceName.case
41  // Geometry: rootdir/<TIME>/surfaceName.00000000.mesh
42 
43  fileName outputDir;
44  if (useTimeDir() && !timeName().empty())
45  {
46  // Splice in time-directory
47  outputDir = outputPath_.path() / timeName();
48  }
49  else
50  {
51  outputDir = outputPath_.path();
52  }
53 
54  const fileName outputFile = outputDir / surfName + ".case";
55 
56  if (verbose_)
57  {
58  Info<< "Writing case file to " << outputFile << endl;
59  }
60 
61 
62  const meshedSurf& surf = surface();
63 
64  if (Pstream::master() || !parallel_)
65  {
66  if (!isDir(outputDir))
67  {
68  mkDir(outputDir);
69  }
70 
71  OFstream osCase(outputFile);
72  ensightGeoFile osGeom
73  (
74  outputDir,
75  surfName + ".00000000.mesh",
76  writeFormat_
77  );
78 
79  osCase
80  << "FORMAT" << nl
81  << "type: ensight gold" << nl
82  << nl
83  << "GEOMETRY" << nl
84  << "model: 1 " << osGeom.name().name() << nl
85  << nl
86  << "TIME" << nl;
87 
88  printTimeset(osCase, 1, 0.0);
89 
90  ensightPartFaces ensPart
91  (
92  0,
93  osGeom.name().name(),
94  surf.points(),
95  surf.faces(),
96  true // contiguous points
97  );
98  osGeom << ensPart;
99  }
100 
101  wroteGeom_ = true;
102  return outputFile;
103 }
104 
105 
106 template<class Type>
107 Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated
108 (
109  const word& fieldName,
110  const Field<Type>& localValues
111 )
112 {
113  checkOpen();
114 
115  const ensight::FileName surfName(outputPath_.name());
116  const ensight::VarName varName(fieldName);
117 
118 
119  // Uncollated
120  // ==========
121  // geometry: rootdir/time/<field>/surfaceName.case
122  // geometry: rootdir/time/<field>/surfaceName.<index>.mesh
123  // field: rootdir/time/<field>/surfaceName.<index>.<field>
124 
125  // Variable name as sub-directory for results. Eg,
126  // - VAR1/SURF1.case
127  // - VAR1/SURF1.00000000.mesh
128  // - VAR1/SURF1.00000001.VAR1
129  // and
130  // - VAR2/SURF1.case
131  // - VAR2/SURF1.00000000.mesh
132  // - VAR2/SURF1.00000001.VAR2
133 
134  fileName outputDir;
135  if (useTimeDir() && !timeName().empty())
136  {
137  // Splice in time-directory
138  outputDir = outputPath_.path() / timeName();
139  }
140  else
141  {
142  outputDir = outputPath_.path();
143  }
144 
145  const fileName baseDir = outputDir / varName;
146  const word timeDir = timeName();
147  const scalar timeValue = currTime_.value();
148 
149  const fileName outputFile = baseDir / surfName + ".case";
150 
151  if (verbose_)
152  {
153  Info<< "Writing case file to " << outputFile << endl;
154  }
155 
156 
157  // geometry merge() implicit
158  tmp<Field<Type>> tfield = mergeField(localValues);
159 
160  const meshedSurf& surf = surface();
161 
162  if (Pstream::master() || !parallel_)
163  {
164  if (!isDir(outputFile.path()))
165  {
166  mkDir(outputFile.path());
167  }
168 
169  OFstream osCase(outputFile, IOstream::ASCII);
170 
171  // Format options
172  osCase.setf(ios_base::left);
173  osCase.setf(ios_base::scientific, ios_base::floatfield);
174  osCase.precision(5);
175 
176  ensightGeoFile osGeom
177  (
178  baseDir,
179  surfName + ".00000000.mesh",
180  writeFormat_
181  );
182  ensightFile osField
183  (
184  baseDir,
185  surfName + ".00000000." + varName,
186  writeFormat_
187  );
188 
189  osCase
190  << "FORMAT" << nl
191  << "type: ensight gold" << nl
192  << nl
193  << "GEOMETRY" << nl
194  << "model: 1 " << osGeom.name().name() << nl
195  << nl
196  << "VARIABLE" << nl
198  <<
199  (
200  this->isPointData()
201  ? " per node: 1 " // time-set 1
202  : " per element: 1 " // time-set 1
203  )
204  << setw(15) << varName << ' '
205  << surfName.c_str() << ".********." << varName << nl;
206 
207  osCase
208  << nl
209  << "TIME" << nl;
210 
211  printTimeset(osCase, 1, timeValue);
212  osCase << "# end" << nl;
213 
214 
215  ensightPartFaces ensPart
216  (
217  0,
218  osGeom.name().name(),
219  surf.points(),
220  surf.faces(),
221  true // contiguous points
222  );
223  osGeom << ensPart;
224 
225  // Write field
227 
228  if (this->isPointData())
229  {
231  (
232  tfield(),
233  ensPart,
234  osField
235  // serial
236  );
237  }
238  else
239  {
241  (
242  tfield(),
243  ensPart,
244  osField,
245  false // serial
246  );
247  }
248  }
249 
250  wroteGeom_ = true;
251  return outputFile;
252 }
253 
254 
255 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::OFstream::name
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:91
Foam::fileName::path
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:186
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::fileName::name
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition: fileNameI.H:209
Foam::surfaceWriter::useTimeDir
bool useTimeDir() const
Should a time directory be spliced into the output path?
Definition: surfaceWriterI.H:54
Foam::meshedSurf::faces
virtual const faceList & faces() const =0
The faces used for the surface.
Foam::surfaceWriter::surface
const meshedSurf & surface() const
Definition: surfaceWriter.C:469
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::surfaceWriter::timeName
const word & timeName() const
The current time value/name.
Definition: surfaceWriterI.H:96
Foam::ensightFile::writeKeyword
virtual Ostream & writeKeyword(const keyType &key)
Write element keyword with trailing newline, optionally with undef.
Definition: ensightFile.C:285
Foam::ensightPTraits
Conversion of OpenFOAM pTraits into the Ensight equivalent.
Definition: ensightPTraits.H:54
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
Foam::ensight::FileName
Specification of a valid Ensight file-name.
Definition: ensightFileName.H:56
Foam::ensight::VarName
Specification of a valid Ensight variable-name.
Definition: ensightVarName.H:58
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::ensightOutput::Serial::writePointField
bool writePointField(const Field< Type > &fld, const ensightFaces &part, ensightFile &os)
Write a field of point (node) values (already compacted?)
Definition: ensightOutputTemplates.C:229
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::surfaceWriter::parallel_
bool parallel_
Writing in parallel (via master)
Definition: surfaceWriter.H:139
Foam::surfaceWriter::checkOpen
bool checkOpen() const
Verify that the outputPath_ has been set or FatalError.
Definition: surfaceWriter.C:430
Foam::surfaceWriter::outputPath_
fileName outputPath_
The full output directory and file (surface) name.
Definition: surfaceWriter.H:163
Foam::meshedSurf::points
virtual const pointField & points() const =0
The points used for the surface.
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:54
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::scientific
IOstream & scientific(IOstream &io)
Definition: IOstream.H:447
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Foam::IOstream::setf
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:361
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::OSstream::precision
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:311
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::ensightOutput::Detail::writeFaceField
bool writeFaceField(const Field< Type > &fld, const ensightFaces &part, ensightFile &os, bool parallel)
Definition: ensightOutputTemplates.C:119
Foam::ensightPartFaces
An implementation of ensightPart to hold mesh faces.
Definition: ensightPartFaces.H:53
Foam::surfaceWriter::wroteGeom_
bool wroteGeom_
Track if geometry has been written since the last open.
Definition: surfaceWriter.H:136
Foam::surfaceWriter::verbose_
bool verbose_
Additional output verbosity.
Definition: surfaceWriter.H:148
Foam::mkDir
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:507
Foam::isDir
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:643