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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
31Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated()
32{
33 checkOpen();
34
35 const ensight::FileName baseName(outputPath_.name());
36
37
38 // Uncollated
39 // ==========
40 // CaseFile: rootdir/<TIME>/NAME.case
41 // Geometry: rootdir/<TIME>/NAME.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 / baseName + ".case";
55
56 if (verbose_)
57 {
58 Info<< "Writing case file to " << outputFile << endl;
59 }
60
61
62 // const meshedSurf& surf = surface();
63 const meshedSurfRef& surf = adjustSurface();
64
65 if (Pstream::master() || !parallel_)
66 {
67 if (!isDir(outputDir))
68 {
69 mkDir(outputDir);
70 }
71
72 OFstream osCase(outputFile);
73 ensightGeoFile osGeom
74 (
75 outputDir,
76 baseName + ".00000000.mesh",
77 writeFormat_
78 );
79
80 osCase
81 << "FORMAT" << nl
82 << "type: ensight gold" << nl
83 << nl
84 << "GEOMETRY" << nl
85 << "model: 1 " << osGeom.name().name() << nl
86 << nl
87 << "TIME" << nl;
88
89 ensightCase::printTimeset(osCase, 1, scalar(0));
90
91 ensightOutputSurface part
92 (
93 surf.points(),
94 surf.faces(),
95 osGeom.name().name()
96 );
97 part.write(osGeom); // serial
98 }
99
100 wroteGeom_ = true;
101 return outputFile;
102}
103
104
105template<class Type>
106Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated
107(
108 const word& fieldName,
109 const Field<Type>& localValues
110)
111{
112 checkOpen();
113
114 const ensight::FileName baseName(outputPath_.name());
115 const ensight::VarName varName(fieldName);
116
117
118 // Uncollated
119 // ==========
120 // CaseFile: rootdir/time/<field>/NAME.case
121 // Geometry: rootdir/time/<field>/NAME.<index>.mesh
122 // Field: rootdir/time/<field>/NAME.<index>.<field>
123
124 // Variable name as sub-directory for results. Eg,
125 // - VAR1/NAME1.case
126 // - VAR1/NAME1.00000000.mesh
127 // - VAR1/NAME1.00000001.VAR1
128 // and
129 // - VAR2/NAME1.case
130 // - VAR2/NAME1.00000000.mesh
131 // - VAR2/NAME1.00000001.VAR2
132
133 fileName outputDir;
134 if (useTimeDir() && !timeName().empty())
135 {
136 // Splice in time-directory
137 outputDir = outputPath_.path() / timeName();
138 }
139 else
140 {
141 outputDir = outputPath_.path();
142 }
143
144 const fileName baseDir = outputDir / varName;
145 const word timeDir = timeName();
146 const scalar timeValue = currTime_.value();
147
148 const fileName outputFile = baseDir / baseName + ".case";
149
150 if (verbose_)
151 {
152 Info<< "Writing case file to " << outputFile << nl;
153 }
154
155 // Implicit geometry merge()
156 tmp<Field<Type>> tfield = adjustField(fieldName, mergeField(localValues));
157
158 if (verbose_)
159 {
160 Info<< endl;
161 }
162
163 // const meshedSurf& surf = surface();
164 const meshedSurfRef& surf = adjustSurface();
165
166 if (Pstream::master() || !parallel_)
167 {
168 if (!isDir(outputFile.path()))
169 {
170 mkDir(outputFile.path());
171 }
172
173 OFstream osCase(outputFile, IOstream::ASCII);
174
175 // Format options
176 osCase.setf(ios_base::left);
177 osCase.setf(ios_base::scientific, ios_base::floatfield);
178 osCase.precision(5);
179
180 // Two-argument form for path-name to avoid validating base-dir
181 ensightGeoFile osGeom
182 (
183 baseDir,
184 baseName + ".00000000.mesh",
185 writeFormat_
186 );
187 ensightFile osField
188 (
189 baseDir,
190 baseName + ".00000000." + varName,
191 writeFormat_
192 );
193
194 osCase
195 << "FORMAT" << nl
196 << "type: ensight gold" << nl
197 << nl
198 << "GEOMETRY" << nl
199 << "model: 1 " << osGeom.name().name() << nl
200 << nl
201 << "VARIABLE" << nl
203 <<
204 (
205 this->isPointData()
206 ? " per node: 1 " // time-set 1
207 : " per element: 1 " // time-set 1
208 )
209 << setw(15) << varName << ' '
210 << baseName.c_str() << ".********." << varName << nl;
211
212 osCase
213 << nl
214 << "TIME" << nl;
215
216 ensightCase::printTimeset(osCase, 1, timeValue);
217 osCase << "# end" << nl;
218
219
220 // Ensight Geometry
222 (
223 surf.points(),
224 surf.faces(),
225 osGeom.name().name()
226 );
227 part.write(osGeom); // serial
228
229 // Write field (serial)
231 part.writeData(osField, tfield(), this->isPointData());
232 }
233
234 wroteGeom_ = true;
235 return outputFile;
236}
237
238
239// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:378
Output to file stream, using an OSstream.
Definition: OFstream.H:57
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:107
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:326
static void printTimeset(OSstream &os, const label ts, const scalar timeValue)
Print time-set for ensight case file with a single time.
Definition: ensightCase.C:44
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:55
virtual Ostream & writeKeyword(const keyType &key)
Definition: ensightFile.C:320
Specialized Ensight output with extra geometry file header.
A variant of ensightFaces that holds references to contiguous points/faces with its own encapsulated ...
void write(ensightGeoFile &os) const
Write processor-local geometry (serial-only)
void writeData(ensightFile &os, const Field< Type > &fld, const bool isPointData=false) const
Write a field of face or point values (serial-only)
Specification of a valid Ensight file-name.
Specification of a valid Ensight variable-name.
A class for handling file names.
Definition: fileName.H:76
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition: fileNameI.H:199
Implements a meshed surface by referencing another meshed surface or faces/points components.
Definition: meshedSurfRef.H:56
virtual const pointField & points() const
The points used for the surface.
virtual const faceList & faces() const
The faces used for the surface.
splitCell * master() const
Definition: splitCell.H:113
bool wroteGeom_
Track if geometry has been written since the last open.
bool useTimeDir() const noexcept
Should a time directory be spliced into the output path?
const word & timeName() const
The current time value/name.
void checkOpen() const
Verify that the outputPath_ has been set or FatalError.
bool parallel_
Writing in parallel (via master)
bool empty() const
The surface to write is empty if the global number of faces is zero.
bool verbose_
Additional output verbosity.
const meshedSurfRef & adjustSurface() const
fileName outputPath_
The full output directory and file (surface) name.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
word timeName
Definition: getTimeIndex.H:3
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:515
messageStream Info
Information stream (stdout output on master, null elsewhere)
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:651
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Ensight names and component order for base types.