ensightAsciiStream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::ensightAsciiStream
26 
27 Description
28 
29 SourceFiles
30  ensightAsciiStream.C
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef ensightAsciiStream_H
35 #define ensightAsciiStream_H
36 
37 #include "ensightStream.H"
38 #include "OFstream.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 /*---------------------------------------------------------------------------*\
46  Class ensightAsciiStream Declaration
47 \*---------------------------------------------------------------------------*/
48 
50 :
51  public ensightStream
52 {
53  // Private Data
54 
55  //- Description of data_
56  OFstream str_;
57 
58 
59 public:
60 
61  // Constructors
62 
63  //- Construct from components
64  ensightAsciiStream(const fileName& f, const Time& runTime)
65  :
66  ensightStream(f),
67  str_
68  (
69  f,
70  runTime.writeFormat(),
71  runTime.writeVersion(),
72  IOstream::UNCOMPRESSED
73  )
74  {
75 
76  str_.setf(ios_base::scientific, ios_base::floatfield);
77  str_.precision(5);
78  }
79 
80  //- Disallow default bitwise copy construction
81  ensightAsciiStream(const ensightAsciiStream&) = delete;
82 
83 
84  //- Destructor
85  virtual ~ensightAsciiStream()
86  {}
87 
88 
89  // Member Functions
90 
91  virtual bool ascii() const
92  {
93  return true;
94  }
95 
96  virtual void write(const char* c)
97  {
98  str_ << c << nl;
99  }
101  virtual void write(const int v)
102  {
103  str_ << setw(10) << v << nl;
104  }
106  virtual void write(const scalarField& sf)
107  {
108  forAll(sf, i)
109  {
110  if (mag(sf[i]) >= scalar(floatScalarVSmall))
111  {
112  str_ << setw(12) << sf[i] << nl;
113  }
114  else
115  {
116  str_ << setw(12) << scalar(0) << nl;
117  }
118  }
119  }
121  virtual void write(const List<int>& sf)
122  {
123  forAll(sf, i)
124  {
125  str_ << setw(10) << sf[i];
126  }
127  str_<< nl;
128  }
130  virtual void writePartHeader(const label partI)
131  {
132  str_<< "part" << nl
133  << setw(10) << partI << nl;
134  }
135 
136 
137  // Member Operators
138 
139  //- Disallow default bitwise assignment
140  void operator=(const ensightAsciiStream&) = delete;
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #endif
151 
152 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for handling file names.
Definition: fileName.H:79
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:246
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:493
Output to file stream.
Definition: OFstream.H:82
static const floatScalar floatScalarVSmall
Definition: floatScalar.H:58
Abstract base class for writing Ensight data.
Definition: ensightStream.H:50
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const dimensionedScalar c
Speed of light in a vacuum.
ensightAsciiStream(const fileName &f, const Time &runTime)
Construct from components.
static const char nl
Definition: Ostream.H:260
labelList f(nPoints)
void operator=(const ensightAsciiStream &)=delete
Disallow default bitwise assignment.
volScalarField sf(fieldObject, mesh)
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
Definition: IOstream.H:71
virtual void writePartHeader(const label partI)
dimensioned< scalar > mag(const dimensioned< Type > &)
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
virtual ~ensightAsciiStream()
Destructor.
virtual bool ascii() const
IOstream & scientific(IOstream &io)
Definition: IOstream.H:579
virtual void write(const char *c)
Namespace for OpenFOAM.