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

11 12 13 14
    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.
15 16 17 18 19 20 21

    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
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23 24 25 26 27 28 29 30 31

Class
    Foam::ensightFile

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

\*---------------------------------------------------------------------------*/
32

33 34 35 36 37 38
#ifndef ensightFile_H
#define ensightFile_H

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

39 40
#include "ensightFileName.H"
#include "ensightVarName.H"
41
#include "UList.H"
42

43 44
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

45 46 47 48
namespace Foam
{

/*---------------------------------------------------------------------------*\
49
                         Class ensightFile Declaration
50 51 52 53 54 55
\*---------------------------------------------------------------------------*/

class ensightFile
:
    public OFstream
{
56 57
    // Private data

58
        //- Allow undef in results
59
        static bool allowUndef_;
60

61
        //- Value to represent undef in results
62
        static scalar undefValue_;
63

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

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

70

71
    // Private Member Functions
72

73 74 75
        //- Initialize by setting the ASCII output formatting
        void initialize();

76 77 78 79
        //- No copy construct
        ensightFile(const ensightFile&) = delete;

        //- No copy assignment
80
        void operator=(const ensightFile&) = delete;
81

82 83

public:
84

85 86 87 88 89 90 91
    // Static Member Functions

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


94 95
    // Constructors

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

104 105 106 107 108 109 110 111 112
        //- 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
        );

113

114
    //- Destructor
115
    ~ensightFile() = default;
116

117 118

    // Access
119

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

123
        //- The '*' mask appropriate for subDir
124 125
        static string mask();

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

129 130 131 132 133 134 135
        //- 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();

136

137
    // Edit
138

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

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

147

148 149
    // Output

150 151 152
        //- Inherit write from Ostream
        using Ostream::write;

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

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

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

162
        //- Write undef value
163 164
        Ostream& writeUndef();

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

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

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

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

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

        //- Add carriage return to ascii stream
        void newline();
182 183 184 185


    // Convenience Output Methods

186
        //- Begin a part (0-based index internally).
187 188 189 190 191 192 193 194 195 196 197
        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)
198
        void writeList(const UList<scalar>& field, const labelUList& addr);
199

200 201 202 203 204 205 206
};


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

} // End namespace Foam

207 208
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

209 210 211
#endif

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