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 |
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"
27 
28 #include "OFstream.H"
29 #include "OSspecific.H"
30 
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  makeSurfaceWriterType(foamFileSurfaceWriter);
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 template<class Type>
44 void Foam::foamFileSurfaceWriter::writeTemplate
45 (
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
55 {
56  fileName surfaceDir(outputDir/surfaceName);
57 
58  if (!isDir(surfaceDir))
59  {
60  mkDir(surfaceDir);
61  }
62 
63  if (verbose)
64  {
65  Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
66  }
67 
68  // geometry should already have been written
69  // Values to separate directory (e.g. "scalarField/p")
70 
71  fileName foamName(pTraits<Type>::typeName);
72  fileName valuesDir(surfaceDir / (foamName + Field<Type>::typeName));
73 
74  if (!isDir(valuesDir))
75  {
76  mkDir(valuesDir);
77  }
78 
79  // values
80  OFstream(valuesDir/fieldName)() << values;
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 
87 :
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
93 
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 (
102  const fileName& outputDir,
103  const fileName& surfaceName,
104  const pointField& points,
105  const faceList& faces,
106  const bool verbose
107 ) const
108 {
109  fileName surfaceDir(outputDir/surfaceName);
110 
111  if (!isDir(surfaceDir))
112  {
113  mkDir(surfaceDir);
114  }
115 
116  if (verbose)
117  {
118  Info<< "Writing geometry to " << surfaceDir << endl;
119  }
120 
121 
122  // Points
123  OFstream(surfaceDir/"points")() << points;
124 
125  // Faces
126  OFstream(surfaceDir/"faces")() << faces;
127 
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);
131 
132  forAll(faces, faceI)
133  {
134  faceCentres[faceI] = faces[faceI].centre(points);
135  }
136 
137  OFstream(surfaceDir/"faceCentres")() << faceCentres;
138 }
139 
140 
141 // create write methods
143 
144 
145 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
static const char *const typeName
Definition: Field.H:94
A surfaceWriter for foamFiles.
foamFileSurfaceWriter()
Construct null.
Convenience macros for instantiating writer methods for surfaceWriter classes.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual ~foamFileSurfaceWriter()
Destructor.
messageStream Info
List< face > faceList
Definition: faceListFwd.H:43
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Namespace for OpenFOAM.
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Base class for surface writers.
Definition: surfaceWriter.H:54
#define forAll(list, i)
Definition: UList.H:421
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:616
A class for handling file names.
Definition: fileName.H:69
makeSurfaceWriterType(dxSurfaceWriter)
static const Vector zero
Definition: Vector.H:80
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:420