Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / sampling / sampledSurface / writers / foamFile / foamFileSurfaceWriter.C
blob06005b5c0aea7af1c4fd914a7126b9bd76ba6c62
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "foamFileSurfaceWriter.H"
28 #include "OFstream.H"
29 #include "OSspecific.H"
31 #include "makeSurfaceWriterMethods.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     makeSurfaceWriterType(foamFileSurfaceWriter);
41 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
43 template<class Type>
44 void Foam::foamFileSurfaceWriter::writeTemplate
46     const fileName& outputDir,
47     const fileName& surfaceName,
48     const pointField& points,
49     const faceList& faces,
50     const word& fieldName,
51     const Field<Type>& values,
52     const bool isNodeValues,
53     const bool verbose
54 ) const
56     fileName surfaceDir(outputDir/surfaceName);
58     if (!isDir(surfaceDir))
59     {
60         mkDir(surfaceDir);
61     }
63     if (verbose)
64     {
65         Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
66     }
68     // geometry should already have been written
69     // Values to separate directory (e.g. "scalarField/p")
71     fileName foamName(pTraits<Type>::typeName);
72     fileName valuesDir(surfaceDir  / (foamName + Field<Type>::typeName));
74     if (!isDir(valuesDir))
75     {
76         mkDir(valuesDir);
77     }
79     // values
80     OFstream(valuesDir/fieldName)()  << values;
84 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
86 Foam::foamFileSurfaceWriter::foamFileSurfaceWriter()
88     surfaceWriter()
92 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
94 Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter()
98 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
100 void Foam::foamFileSurfaceWriter::write
102     const fileName& outputDir,
103     const fileName& surfaceName,
104     const pointField& points,
105     const faceList& faces,
106     const bool verbose
107 ) const
109     fileName surfaceDir(outputDir/surfaceName);
111     if (!isDir(surfaceDir))
112     {
113         mkDir(surfaceDir);
114     }
116     if (verbose)
117     {
118         Info<< "Writing geometry to " << surfaceDir << endl;
119     }
122     // Points
123     OFstream(surfaceDir/"points")() << points;
125     // Faces
126     OFstream(surfaceDir/"faces")() << faces;
128     // Face centers. Not really necessary but very handy when reusing as inputs
129     // for e.g. timeVaryingMapped bc.
130     pointField faceCentres(faces.size(),point::zero);
132     forAll(faces, faceI)
133     {
134         faceCentres[faceI] = faces[faceI].centre(points);
135     }
137     OFstream(surfaceDir/"faceCentres")() << faceCentres;
141 // create write methods
142 defineSurfaceWriterWriteFields(Foam::foamFileSurfaceWriter);
145 // ************************************************************************* //