ensightSurfaceWriter.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 #include "ensightSurfaceWriter.H"
30 #include "IOmanip.H"
31 #include "Fstream.H"
32 #include "OSspecific.H"
33 #include "ensightCase.H"
34 #include "ensightOutput.H"
35 #include "ensightOutputSurface.H"
36 #include "ensightPTraits.H"
37 #include "surfaceWriterMethods.H"
39 
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 namespace surfaceWriters
45 {
46  defineTypeName(ensightWriter);
47  addToRunTimeSelectionTable(surfaceWriter, ensightWriter, word);
48  addToRunTimeSelectionTable(surfaceWriter, ensightWriter, wordDict);
49 }
50 }
51 
52 
53 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
54 
55 void Foam::surfaceWriters::ensightWriter::printTimeset
56 (
57  OSstream& os,
58  const label ts,
59  const scalar timeValue
60 )
61 {
62  os
63  << "time set: " << ts << nl
64  << "number of steps: " << 1 << nl;
65 
66  // Single value - starts at index 0
67  os << "filename start number: 0" << nl
68  << "filename increment: 1" << nl
69  << "time values:" << nl;
70 
71  os << " " << timeValue
72  << nl << nl;
73 }
74 
75 
76 void Foam::surfaceWriters::ensightWriter::printTimeset
77 (
78  OSstream& os,
79  const label ts,
80  const UList<scalar>& values
81 )
82 {
83  label pos_;
84 
85  os
86  << "time set: " << ts << nl
87  << "number of steps: " << values.size() << nl;
88 
89  // Assume contiguous numbering - starts at index 0
90  os << "filename start number: 0" << nl
91  << "filename increment: 1" << nl;
92 
93 
94  os << "time values:" << nl;
95  pos_ = 0;
96  for (const scalar& val : values)
97  {
98  if (pos_ == 6)
99  {
100  os << nl;
101  pos_ = 0;
102  }
103  ++pos_;
104 
105  os << ' ' << setf(ios_base::right) << setw(12) << val;
106  }
107  os << nl << nl;
108 }
109 
110 
111 void Foam::surfaceWriters::ensightWriter::printTimeset
112 (
113  OSstream& os,
114  const label ts,
115  const UList<scalar>& values,
116  const bitSet& indices
117 )
118 {
119  label pos_;
120 
121  // Check if continuous numbering can be used
122  if
123  (
124  values.empty()
125  || (indices.size() == values.size() && indices.all())
126  )
127  {
128  // Can simply emit as 0-based with increment
129  printTimeset(os, ts, values);
130  return;
131  }
132 
133 
134  // Generate time set
135  os
136  << "time set: " << ts << nl
137  << "number of steps: " << indices.count() << nl;
138 
139 
140  os << "filename numbers:" << nl;
141  pos_ = 0;
142  for (const label& idx : indices)
143  {
144  if (pos_ == 6)
145  {
146  os << nl;
147  pos_ = 0;
148  }
149  ++pos_;
150 
151  os << ' ' << setf(ios_base::right) << setw(8) << idx;
152  }
153  os << nl;
154 
155 
156  os << "time values:" << nl;
157  pos_ = 0;
158  for (const label& idx : indices)
159  {
160  if (pos_ == 6)
161  {
162  os << nl;
163  pos_ = 0;
164  }
165  ++pos_;
166 
167  os << ' ' << setf(ios_base::right) << setw(12) << values[idx];
168  }
169  os << nl << nl;
170 }
171 
172 
173 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
174 
176 :
177  surfaceWriter(),
178  writeFormat_(IOstream::ASCII),
179  collateTimes_(true),
180  caching_("fieldsDict") // Historic name
181 {}
182 
183 
185 (
186  const dictionary& options
187 )
188 :
189  surfaceWriter(options),
190  writeFormat_
191  (
192  IOstreamOption::formatEnum("format", options, IOstream::ASCII)
193  ),
194  collateTimes_(options.getOrDefault("collateTimes", true)),
195  caching_("fieldsDict") // Historic name
196 {}
197 
198 
200 (
201  const meshedSurf& surf,
202  const fileName& outputPath,
203  bool parallel,
204  const dictionary& options
205 )
206 :
207  ensightWriter(options)
208 {
209  open(surf, outputPath, parallel);
210 }
211 
212 
214 (
215  const pointField& points,
216  const faceList& faces,
217  const fileName& outputPath,
218  bool parallel,
219  const dictionary& options
220 )
221 :
222  ensightWriter(options)
223 {
224  open(points, faces, outputPath, parallel);
225 }
226 
227 
228 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
229 
231 {
232  caching_.clear();
234 }
235 
236 
237 // Note that ensight does supports geometry in a separate file,
238 // but setting this true leaves geometry files in the wrong places
239 // (when there are fields).
240 //
241 // Make this false to let the field writers take back control
243 {
244  return false;
245 }
246 
247 
249 {
250  // if (collateTimes_)
251  // {
252  // return writeCollated();
253  // }
254  // else
255  // {
256  // return writeUncollated();
257  // }
258 
259  return writeUncollated();
260 }
261 
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
267 
268 
269 // Field writing implementations
270 
271 template<class Type>
272 Foam::fileName Foam::surfaceWriters::ensightWriter::writeTemplate
273 (
274  const word& fieldName,
275  const Field<Type>& localValues
276 )
277 {
278  if (collateTimes_)
279  {
280  return writeCollated(fieldName, localValues);
281  }
282  else
283  {
284  return writeUncollated(fieldName, localValues);
285  }
286 }
287 
288 
290 
291 
292 // ************************************************************************* //
Foam::setf
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Definition: IOmanip.H:169
Foam::surfaceWriters::ensightWriter::ensightWriter
ensightWriter()
Default construct.
Definition: ensightSurfaceWriter.C:175
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::surfaceWriter::timeValue
scalar timeValue() const
The current time value/name.
Definition: surfaceWriterI.H:118
ensightCase.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:111
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::surfaceWriters::defineTypeName
defineTypeName(abaqusWriter)
ensightSurfaceWriterCollated.C
Foam::surfaceWriters::ensightWriter
A surfaceWriter for Ensight format.
Definition: ensightSurfaceWriter.H:91
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::IOstream
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:75
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(Foam::surfaceWriters::ensightWriter)
ensightSurfaceWriterUncollated.C
surfaceWriterMethods.H
Convenience macros for instantiating surfaceWriter methods.
Foam::surfaceWriters::ensightWriter::write
virtual fileName write()
Write surface geometry to file.
Definition: ensightSurfaceWriter.C:248
Foam::surfaceWriters::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surfaceWriter, abaqusWriter, word)
ensightOutput.H
Foam::Field< vector >
Foam::surfaceWriters::ensightWriter::ensightWriter
ensightWriter(const meshedSurf &surf, const fileName &outputPath, bool parallel=Pstream::parRun(), const dictionary &options=dictionary())
Construct from components.
Definition: ensightSurfaceWriter.C:200
ensightPTraits.H
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
ensightSurfaceWriter.H
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::surfaceWriters::ensightWriter::separateGeometry
virtual bool separateGeometry() const
True if the surface format supports geometry in a separate file.
Definition: ensightSurfaceWriter.C:242
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Fstream.H
Foam::IOstreamOption::formatEnum
static streamFormat formatEnum(const word &formatName, const streamFormat deflt=streamFormat::ASCII)
Definition: IOstreamOption.C:53
Foam::List< face >
ensightOutputSurface.H
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::surfaceWriter::close
virtual void close()
Finish output, performing any necessary cleanup.
Definition: surfaceWriter.C:306
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
Foam::surfaceWriters::ensightWriter::close
virtual void close()
Finish output, clears output times.
Definition: ensightSurfaceWriter.C:230