1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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"
29 #include "OSspecific.H"
31 #include "makeSurfaceWriterMethods.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 makeSurfaceWriterType(foamFileSurfaceWriter);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
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,
56 fileName surfaceDir(outputDir/surfaceName);
58 if (!isDir(surfaceDir))
65 Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
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))
80 OFstream(valuesDir/fieldName)() << values;
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 Foam::foamFileSurfaceWriter::foamFileSurfaceWriter()
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,
109 fileName surfaceDir(outputDir/surfaceName);
111 if (!isDir(surfaceDir))
118 Info<< "Writing geometry to " << surfaceDir << endl;
123 OFstream(surfaceDir/"points")() << points;
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);
134 faceCentres[faceI] = faces[faceI].centre(points);
137 OFstream(surfaceDir/"faceCentres")() << faceCentres;
141 // create write methods
142 defineSurfaceWriterWriteFields(Foam::foamFileSurfaceWriter);
145 // ************************************************************************* //