foamFileSurfaceWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "foamFileSurfaceWriter.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  makeSurfaceWriterType(foamFileSurfaceWriter);
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
42 {}
43 
44 
45 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
46 
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
54 (
55  const fileName& outputDir,
56  const fileName& surfaceName,
57  const pointField& points,
58  const faceList& faces,
59  const bool verbose
60 ) const
61 {
62  fileName surfaceDir(outputDir/surfaceName);
63 
64  if (!isDir(surfaceDir))
65  {
66  mkDir(surfaceDir);
67  }
68 
69  if (verbose)
70  {
71  Info<< "Writing geometry to " << surfaceDir << endl;
72  }
73 
74 
75  // Points
76  OFstream(surfaceDir/"points")() << points;
77 
78  // Faces
79  OFstream(surfaceDir/"faces")() << faces;
80 
81  // Face centers. Not really necessary but very handy when reusing as inputs
82  // for e.g. timeVaryingMapped bc.
83  pointField faceCentres(faces.size(),point::zero);
84 
85  forAll(faces, faceI)
86  {
87  faceCentres[faceI] = faces[faceI].centre(points);
88  }
89 
90  OFstream(surfaceDir/"faceCentres")() << faceCentres;
91 
92  return surfaceDir;
93 }
94 
95 
96 // create write methods
98 
99 
100 // ************************************************************************* //
Foam::foamFileSurfaceWriter::write
virtual fileName write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
Definition: foamFileSurfaceWriter.C:54
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:54
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::foamFileSurfaceWriter::foamFileSurfaceWriter
foamFileSurfaceWriter()
Construct null.
Definition: foamFileSurfaceWriter.C:39
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::foamFileSurfaceWriter
A surfaceWriter for foamFiles.
Definition: foamFileSurfaceWriter.H:48
makeSurfaceWriterMethods.H
Convenience macros for instantiating writer methods for surfaceWriter classes.
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
foamFileSurfaceWriter.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter
virtual ~foamFileSurfaceWriter()
Destructor.
Definition: foamFileSurfaceWriter.C:47
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::makeSurfaceWriterType
makeSurfaceWriterType(boundaryDataSurfaceWriter)
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419