proxySurfaceWriter.C 3.88 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
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011 OpenFOAM Foundation
9
    Copyright (C) 2015-2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
18 19 20 21 22 23 24

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

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

29
#include "proxySurfaceWriter.H"
Mark Olesen's avatar
Mark Olesen committed
30
#include "MeshedSurfaceProxy.H"
31
#include "OSspecific.H"
32
#include "surfaceWriterMethods.H"
33 34 35 36 37

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
38 39 40 41
namespace surfaceWriters
{
    defineTypeName(proxyWriter);
}
42 43 44
}


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

47
Foam::surfaceWriters::proxyWriter::proxyWriter(const word& fileExt)
48
:
49
    surfaceWriter(),
50 51
    fileExtension_(fileExt),
    streamOpt_()
52 53 54
{}


55
Foam::surfaceWriters::proxyWriter::proxyWriter
56 57 58 59 60
(
    const word& fileExt,
    const dictionary& options
)
:
61
    surfaceWriter(options),
62
    fileExtension_(fileExt),
63 64 65 66 67
    streamOpt_
    (
        IOstream::formatEnum("format", options, IOstream::ASCII),
        IOstream::compressionEnum("compression", options)
    ),
68 69 70 71
    options_(options)
{}


72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Foam::surfaceWriters::proxyWriter::proxyWriter
(
    const meshedSurf& surf,
    const fileName& outputPath,
    bool parallel,
    const dictionary& options
)
:
    proxyWriter(outputPath.ext(), options)
{
    surfaceWriter::open(surf, outputPath, parallel);
}


Foam::surfaceWriters::proxyWriter::proxyWriter
(
    const pointField& points,
    const faceList& faces,
    const fileName& outputPath,
    bool parallel,
    const dictionary& options
)
:
    proxyWriter(outputPath.ext(), options)
{
    surfaceWriter::open(points, faces, outputPath, parallel);
}


101 102
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

103
Foam::fileName Foam::surfaceWriters::proxyWriter::write()
104
{
105 106
    checkOpen();

107 108
    // Avoid bad values
    if (fileExtension_.empty())
109
    {
110
        return fileName::null;
111 112
    }

113
    // Geometry:  rootdir/<TIME>/surfaceName.{extension}
114

115 116
    fileName outputFile = outputPath_;
    if (useTimeDir() && !timeName().empty())
117
    {
118 119
        // Splice in time-directory
        outputFile = outputPath_.path() / timeName() / outputPath_.name();
120
    }
121
    outputFile.ext(fileExtension_);
122

123
    if (verbose_)
124
    {
125
        Info<< "Writing geometry to " << outputFile << endl;
126 127
    }

128 129 130 131 132 133 134 135 136 137 138 139 140
    const meshedSurf& surf = surface();

    if (Pstream::master() || !parallel_)
    {
        if (!isDir(outputFile.path()))
        {
            mkDir(outputFile.path());
        }

        MeshedSurfaceProxy<face>(surf.points(), surf.faces()).write
        (
            outputFile,
            fileExtension_,
141
            streamOpt_,
142 143 144
            options_
        );
    }
145

146
    wroteGeom_ = true;
147
    return outputFile;
148 149 150
}


151 152 153 154
// Field writing methods
defineSurfaceWriterWriteFields(Foam::surfaceWriters::proxyWriter);


155
// ************************************************************************* //