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 -------------------------------------------------------------------------------
10 License
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 
30 Foam::fileName Foam::coordSetWriters::ensightWriter::writeUncollated
31 (
32  const bool writeTracks
33 )
34 {
35  return fileName::null;
36 }
37 
38 
39 template<class Type>
40 Foam::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 (!isDir(outputFile.path()))
95  {
96  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  writeGeometry(osGeom, elemOutput);
114 
115  // Write field (serial only)
116  writeTrackField<Type>(osField, fieldPtrs);
117 
118 
119  // Update case file
120  {
121  OFstream osCase(outputFile, IOstreamOption::ASCII);
122  ensightCase::setTimeFormat(osCase, caseOpts_); // time-format
123 
124  osCase
125  << "FORMAT" << nl
126  << "type: ensight gold" << nl
127  << nl
128  << "GEOMETRY" << nl
129  << "model: 1 " << osGeom.name().name() << nl
130  << nl
131  << "VARIABLE" << nl
133  <<
134  (
135  true // this->isPointData()
136  ? " per node: 1 " // time-set 1
137  : " per element: 1 " // time-set 1
138  )
139  << setw(15) << varName << ' '
140  << baseName.c_str() << ".********."
141  << ensight::FileName(varName).c_str() << nl;
142 
143  osCase
144  << nl
145  << "TIME" << nl;
146 
147  ensightCase::printTimeset(osCase, 1, timeValue);
148  osCase << "# end" << nl;
149  }
150  }
151 
152  wroteGeom_ = true;
153  return outputFile;
154 }
155 
156 
157 // ************************************************************************* //
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:91
A class for handling file names.
Definition: fileName.H:72
static void setTimeFormat(OSstream &os, IOstreamOption::floatFormat timeFmt, const int timePrec)
Set output time format for ensight case file.
Definition: ensightCase.C:53
writer writeGeometry()
Specification of a valid Ensight file-name.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
"ascii" (normal default)
static const fileName null
An empty fileName.
Definition: fileName.H:111
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:169
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:860
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: POSIX.C:614
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
const char *const typeName
Specification of a valid Ensight variable-name.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Omanip< int > setw(const int i)
Definition: IOmanip.H:199