Loading...
Searching...
No Matches
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-2023 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
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 if (!Foam::isDir(outputFile.path()))
95 {
96 Foam::mkDir(outputFile.path());
97 }
98
99 // Two-argument form for path-name to avoid validating base-dir
100 ensightGeoFile osGeom
101 (
102 baseDir,
103 baseName + ".00000000.mesh",
104 caseOpts_.format()
105 );
106 ensightFile osField
107 (
108 baseDir,
109 baseName + ".00000000." + varName,
110 caseOpts_.format()
111 );
112
113 osGeom.beginGeometry();
114 writeGeometry(osGeom, elemOutput);
115
116 // Write field (serial only)
117 writeTrackField<Type>(osField, fieldPtrs);
118
119
120 // Update case file
121 {
122 OFstream osCase
123 (
125 outputFile,
127 );
128 ensightCase::setTimeFormat(osCase, caseOpts_); // time-format
129
130 osCase
131 << "FORMAT" << nl
132 << "type: ensight gold" << nl
133 << nl
134 << "GEOMETRY" << nl
135 << "model: 1 " << osGeom.name().name() << nl
136 << nl
137 << "VARIABLE" << nl
139 <<
140 (
141 true // this->isPointData()
142 ? " per node: 1 " // time-set 1
143 : " per element: 1 " // time-set 1
144 )
145 << setw(15) << varName << ' '
146 << baseName.c_str() << ".********."
147 << ensight::FileName(varName).c_str() << nl;
148
149 osCase
150 << nl
151 << "TIME" << nl;
152
153 ensightCase::printTimeset(osCase, 1, timeValue);
154 osCase << "# end" << nl;
155 }
156 }
157
158 wroteGeom_ = true;
159 return outputFile;
160}
161
162
163// ************************************************************************* //
writer writeGeometry()
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
@ ASCII
"ascii" (normal default)
@ ATOMIC
atomic = true
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
virtual const fileName & name() const override
Read/write access to the name of the stream.
Definition OSstream.H:134
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition UPtrList.H:101
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?
void checkOpen() const
Verify that the outputPath_ has been set or FatalError.
bool empty() const
Writer is not associated with content.
virtual bool merge() const
Perform any merging if not already upToDate (parallel) or simply mark as being up-to-date.
bool verbose_
Additional output verbosity.
instant currTime_
The current time value/name.
scalar timeValue() const
The current time value/name.
fileName outputPath_
The full output directory and file (coords) name.
static void setTimeFormat(OSstream &os, IOstreamOption::floatFormat timeFmt, const int timePrec)
Set output time format for ensight case file.
Definition ensightCase.C:63
static void printTimeset(OSstream &os, const label ts, const scalar timeValue)
Print time-set for ensight case file with a single time.
A variant of OFstream with specialised handling for Ensight writing of strings, integers and floats (...
Definition ensightFile.H:50
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information.
void beginGeometry()
Start of geometry information.
Specification of a valid Ensight file-name.
Specification of a valid Ensight variable-name.
A class for handling file names.
Definition fileName.H:75
static const fileName null
An empty fileName.
Definition fileName.H:111
static std::string path(const std::string &str)
Return directory path name (part before last /).
Definition fileNameI.H:169
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition fileNameI.H:192
A class for handling words, derived from Foam::string.
Definition word.H:66
word timeName
Definition getTimeIndex.H:3
static void writeTrackField(ensightFile &os, const UPtrList< const Field< Type > > &fieldPtrs)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition POSIX.C:616
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:519
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition POSIX.C:862
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
static const char *const typeName
The type name used in ensight case files.