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-2020 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  // CaseFile: 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, scalar(0));
89 
90  ensightOutputSurface part
91  (
92  surf.points(),
93  surf.faces(),
94  osGeom.name().name()
95  );
96  part.write(osGeom); // serial
97  }
98 
99  wroteGeom_ = true;
100  return outputFile;
101 }
102 
103 
104 template<class Type>
105 Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated
106 (
107  const word& fieldName,
108  const Field<Type>& localValues
109 )
110 {
111  checkOpen();
112 
113  const ensight::FileName surfName(outputPath_.name());
114  const ensight::VarName varName(fieldName);
115 
116 
117  // Uncollated
118  // ==========
119  // CaseFile: rootdir/time/<field>/surfaceName.case
120  // Geometry: rootdir/time/<field>/surfaceName.<index>.mesh
121  // Field: rootdir/time/<field>/surfaceName.<index>.<field>
122 
123  // Variable name as sub-directory for results. Eg,
124  // - VAR1/SURF1.case
125  // - VAR1/SURF1.00000000.mesh
126  // - VAR1/SURF1.00000001.VAR1
127  // and
128  // - VAR2/SURF1.case
129  // - VAR2/SURF1.00000000.mesh
130  // - VAR2/SURF1.00000001.VAR2
131 
132  fileName outputDir;
133  if (useTimeDir() && !timeName().empty())
134  {
135  // Splice in time-directory
136  outputDir = outputPath_.path() / timeName();
137  }
138  else
139  {
140  outputDir = outputPath_.path();
141  }
142 
143  const fileName baseDir = outputDir / varName;
144  const word timeDir = timeName();
145  const scalar timeValue = currTime_.value();
146 
147  const fileName outputFile = baseDir / surfName + ".case";
148 
149  if (verbose_)
150  {
151  Info<< "Writing case file to " << outputFile << endl;
152  }
153 
154 
155  // geometry merge() implicit
156  tmp<Field<Type>> tfield = mergeField(localValues);
157 
158  const meshedSurf& surf = surface();
159 
160  if (Pstream::master() || !parallel_)
161  {
162  if (!isDir(outputFile.path()))
163  {
164  mkDir(outputFile.path());
165  }
166 
167  OFstream osCase(outputFile, IOstream::ASCII);
168 
169  // Format options
170  osCase.setf(ios_base::left);
171  osCase.setf(ios_base::scientific, ios_base::floatfield);
172  osCase.precision(5);
173 
174  // Two-argument form for path-name to avoid validating base-dir
175  ensightGeoFile osGeom
176  (
177  baseDir,
178  surfName + ".00000000.mesh",
179  writeFormat_
180  );
181  ensightFile osField
182  (
183  baseDir,
184  surfName + ".00000000." + varName,
185  writeFormat_
186  );
187 
188  osCase
189  << "FORMAT" << nl
190  << "type: ensight gold" << nl
191  << nl
192  << "GEOMETRY" << nl
193  << "model: 1 " << osGeom.name().name() << nl
194  << nl
195  << "VARIABLE" << nl
197  <<
198  (
199  this->isPointData()
200  ? " per node: 1 " // time-set 1
201  : " per element: 1 " // time-set 1
202  )
203  << setw(15) << varName << ' '
204  << surfName.c_str() << ".********." << varName << nl;
205 
206  osCase
207  << nl
208  << "TIME" << nl;
209 
210  printTimeset(osCase, 1, timeValue);
211  osCase << "# end" << nl;
212 
213 
214  // Ensight Geometry
216  (
217  surf.points(),
218  surf.faces(),
219  osGeom.name().name()
220  );
221  part.write(osGeom); // serial
222 
223  // Write field (serial)
225  part.writeData(osField, tfield(), this->isPointData());
226  }
227 
228  wroteGeom_ = true;
229  return outputFile;
230 }
231 
232 
233 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::OFstream::name
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:107
Foam::fileName::path
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::ensightPTraits
Ensight names and component order for base types.
Definition: ensightPTraits.H:53
Foam::fileName::name
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition: fileNameI.H:199
Foam::surfaceWriter::useTimeDir
bool useTimeDir() const
Should a time directory be spliced into the output path?
Definition: surfaceWriterI.H:58
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:472
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::surfaceWriter::timeName
const word & timeName() const
The current time value/name.
Definition: surfaceWriterI.H:106
Foam::ensightFile::writeKeyword
virtual Ostream & writeKeyword(const keyType &key)
Definition: ensightFile.C:320
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:60
Foam::ensight::VarName
Specification of a valid Ensight variable-name.
Definition: ensightVarName.H:59
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::ensightOutputSurface::write
void write(ensightGeoFile &os) const
Write processor-local geometry (serial-only)
Definition: ensightOutputSurface.C:51
Foam::surfaceWriter::parallel_
bool parallel_
Writing in parallel (via master)
Definition: surfaceWriter.H:142
Foam::surfaceWriter::checkOpen
bool checkOpen() const
Verify that the outputPath_ has been set or FatalError.
Definition: surfaceWriter.C:433
Foam::surfaceWriter::outputPath_
fileName outputPath_
The full output directory and file (surface) name.
Definition: surfaceWriter.H:166
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:52
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::scientific
IOstream & scientific(IOstream &io)
Definition: IOstream.H:464
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::IOstream::setf
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:378
Foam::OSstream::precision
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:326
Foam::ensightOutputSurface
A variant of ensightFaces that holds references to contiguous points/faces with its own encapsulated ...
Definition: ensightOutputSurface.H:58
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::surfaceWriter::wroteGeom_
bool wroteGeom_
Track if geometry has been written since the last open.
Definition: surfaceWriter.H:139
Foam::surfaceWriter::verbose_
bool verbose_
Additional output verbosity.
Definition: surfaceWriter.H:151
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