ensightCoordSetWriterUncollated.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) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29
30Foam::fileName Foam::coordSetWriters::ensightWriter::writeUncollated
31(
32 const bool writeTracks
33)
34{
35 return fileName::null;
36}
37
38
39template<class Type>
40Foam::fileName Foam::coordSetWriters::ensightWriter::writeUncollated
41(
42 const word& fieldName,
43 const UPtrList<const Field<Type>>& fieldPtrs,
44 elemOutputType elemOutput
45)
46{
47 checkOpen();
48
49 const ensight::FileName baseName(outputPath_.name());
50 const ensight::VarName varName(fieldName);
51
52
53 // Uncollated
54 // ==========
55 // CaseFile: rootdir/time/<field>/NAME.case
56 // Geometry: rootdir/time/<field>/NAME.<index>.mesh
57 // Field: rootdir/time/<field>/NAME.<index>.<field>
58
59 // Variable name as sub-directory for results. Eg,
60 // - VAR1/NAME1.case
61 // - VAR1/NAME1.00000000.mesh
62 // - VAR1/NAME1.00000001.VAR1
63 // and
64 // - VAR2/NAME1.case
65 // - VAR2/NAME1.00000000.mesh
66 // - VAR2/NAME1.00000001.VAR2
67
68
69 fileName outputDir;
70 if (useTimeDir() && !timeName().empty())
71 {
72 // Splice in time-directory
73 outputDir = outputPath_.path() / timeName();
74 }
75 else
76 {
77 outputDir = outputPath_.path();
78 }
79
80 const fileName baseDir = outputDir / varName;
81 const word timeDir = timeName();
82 const scalar timeValue = currTime_.value();
83
84 const fileName outputFile = baseDir / baseName + ".case";
85
86 if (verbose_)
87 {
88 Info<< "Writing case file to " << outputFile << endl;
89 }
90
91 merge();
92
93
94 {
95 if (!isDir(outputFile.path()))
96 {
97 mkDir(outputFile.path());
98 }
99
100 OFstream osCase(outputFile, IOstream::ASCII);
101
102 // Format options
103 osCase.setf(ios_base::left);
104 osCase.setf(ios_base::scientific, ios_base::floatfield);
105 osCase.precision(5);
106
107 // Two-argument form for path-name to avoid validating base-dir
108 ensightGeoFile osGeom
109 (
110 baseDir,
111 baseName + ".00000000.mesh",
112 writeFormat_
113 );
114 ensightFile osField
115 (
116 baseDir,
117 baseName + ".00000000." + varName,
118 writeFormat_
119 );
120
121 osCase
122 << "FORMAT" << nl
123 << "type: ensight gold" << nl
124 << nl
125 << "GEOMETRY" << nl
126 << "model: 1 " << osGeom.name().name() << nl
127 << nl
128 << "VARIABLE" << nl
130 <<
131 (
132 true // this->isPointData()
133 ? " per node: 1 " // time-set 1
134 : " per element: 1 " // time-set 1
135 )
136 << setw(15) << varName << ' '
137 << baseName.c_str() << ".********." << varName << nl;
138
139 osCase
140 << nl
141 << "TIME" << nl;
142
143 ensightCase::printTimeset(osCase, 1, timeValue);
144 osCase << "# end" << nl;
145
146
147 writeGeometry(osGeom, elemOutput);
148
149 // Write field (serial only)
150 writeTrackField<Type>(osField, fieldPtrs);
151 }
152
153 wroteGeom_ = true;
154 return outputFile;
155}
156
157
158// ************************************************************************* //
writer writeGeometry()
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
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:71
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
Specialized Ensight output with extra geometry file header.
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 const fileName null
An empty fileName.
Definition: fileName.H:102
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
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.