ensightFile.H 6.18 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5 6 7 8
    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
                            | Copyright (C) 2011-2015 OpenFOAM Foundation
9 10 11 12
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

13 14 15 16
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
17 18 19 20 21 22 23

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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 29 30 31 32 33

Class
    Foam::ensightFile

Description
    Ensight output with specialized write() for strings, integers and floats.
    Correctly handles binary write as well.

\*---------------------------------------------------------------------------*/
34

35 36 37 38 39 40
#ifndef ensightFile_H
#define ensightFile_H

#include "OFstream.H"
#include "IOstream.H"

41 42
#include "ensightFileName.H"
#include "ensightVarName.H"
43
#include "UList.H"
44

45 46
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

47 48 49 50
namespace Foam
{

/*---------------------------------------------------------------------------*\
51
                         Class ensightFile Declaration
52 53 54 55 56 57
\*---------------------------------------------------------------------------*/

class ensightFile
:
    public OFstream
{
58 59
    // Private data

60
        //- Allow undef in results
61
        static bool allowUndef_;
62

63
        //- Value to represent undef in results
64
        static scalar undefValue_;
65

66 67 68 69 70 71
        //- The '*' mask appropriate for subDir
        static string mask_;

        //- The printf format for zero-padded subdirectory numbers
        static string dirFmt_;

72

73
    // Private Member Functions
74

75 76 77
        //- Initialize by setting the ASCII output formatting
        void initialize();

78 79 80 81
        //- No copy construct
        ensightFile(const ensightFile&) = delete;

        //- No copy assignment
82
        void operator=(const ensightFile&) = delete;
83

84 85

public:
86

87 88 89 90 91 92 93
    // Static Member Functions

        //- Return a null ensightFile
        inline static const ensightFile& null()
        {
            return NullObjectRef<ensightFile>();
        }
94 95


96 97
    // Constructors

98 99
        //- Construct from pathname.
        //  The entire pathname is checked for valid ensight naming.
100 101 102 103 104 105
        ensightFile
        (
            const fileName& pathname,
            IOstream::streamFormat format=IOstream::BINARY
        );

106 107 108 109 110 111 112 113 114
        //- Construct from path and name.
        //  Only the name portion is checked for valid ensight naming.
        ensightFile
        (
            const fileName& path,
            const fileName& name,
            IOstream::streamFormat format=IOstream::BINARY
        );

115

116
    //- Destructor
117
    ~ensightFile() = default;
118

119 120

    // Access
121

122 123 124
        //- Return setting for whether 'undef' values are allowed in results
        static bool allowUndef();

125
        //- The '*' mask appropriate for subDir
126 127
        static string mask();

128
        //- Consistent zero-padded numbers for subdirectories
129 130
        static string subDir(const label);

131 132 133 134 135 136 137
        //- Set width of subDir and mask. Default width is 8 digits.
        //  Max width is 31 digits.
        static void subDirWidth(const label);

        //- Return current width of subDir and mask.
        static label subDirWidth();

138

139
    // Edit
140

141 142
        //- Enable/disable use of \c undef keyword and value
        static bool allowUndef(bool enabled);
143 144 145 146

        //- Assign the value to represent undef in the results
        //  Returns the previous value
        //  NB: do not use values larger than floatScalarVGREAT
147
        static scalar undefValue(const scalar value);
148

149

150 151
    // Output

152 153 154
        //- Inherit write from Ostream
        using Ostream::write;

155
        //- Binary write
156
        virtual Ostream& write(const char* buf, std::streamsize count);
157

158
        //- Write element keyword with trailing newline, optionally with undef
159
        virtual Ostream& writeKeyword(const keyType& key);
160

161
        //- Write "C Binary" for binary files (eg, geometry/measured)
162 163
        Ostream& writeBinaryHeader();

164
        //- Write undef value
165 166
        Ostream& writeUndef();

167
        //- Write C-string as "%79s" or as binary (max 80 chars)
168
        Ostream& write(const char*);
169

170
        //- Write string as "%79s" or as binary (max 80 chars)
171
        Ostream& write(const string&);
172

173
        //- Write integer as "%10d" or as binary
174
        Ostream& write(const label);
175

176
        //- Write integer with specified width or as binary
177
        Ostream& write(const label, const label fieldWidth);
178

179
        //- Write float as "%12.5e" or as binary
180
        Ostream& write(const scalar);
181 182 183

        //- Add carriage return to ascii stream
        void newline();
184 185 186 187


    // Convenience Output Methods

188
        //- Begin a part (0-based index internally).
189 190 191 192 193 194 195 196 197 198 199
        void beginPart(const label index);

        //- Begin a "particle coordinates" block (measured data)
        void beginParticleCoordinates(const label nparticles);

        //- Write a list of floats as "%12.5e" or as binary
        //  With carriage return after each value (ascii stream)
        void writeList(const UList<scalar>& field);

        //- Write an indirect list of scalars as "%12.5e" or as binary
        //  With carriage return after each value (ascii stream)
200
        void writeList(const UList<scalar>& field, const labelUList& addr);
201

202 203 204 205 206 207 208
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

209 210
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

211 212 213
#endif

// ************************************************************************* //