All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
foamSurfaceWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 "foamSurfaceWriter.H"
27 #include "OFstream.H"
28 #include "OSspecific.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  makeSurfaceWriterType(foamSurfaceWriter);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 template<class Type>
42 void Foam::foamSurfaceWriter::Write
43 (
44  const fileName& outputDir,
45  const fileName& surfaceName,
46  const pointField& points,
47  const faceList& faces,
48  const word& fieldName,
49  const Field<Type>& values,
50  const bool isNodeValues
51 ) const
52 {
53  const fileName surfaceDir(outputDir/surfaceName);
54 
55  if (!isDir(surfaceDir))
56  {
57  mkDir(surfaceDir);
58  }
59 
60  if (debug)
61  {
62  Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
63  }
64 
65  // Geometry should already have been written
66  // Values to separate directory (e.g. "scalarField/p")
67 
68  const fileName foamName(pTraits<Type>::typeName);
69  const fileName valuesDir(surfaceDir/(foamName + Field<Type>::typeName));
70 
71  if (!isDir(valuesDir))
72  {
73  mkDir(valuesDir);
74  }
75 
76  OFstream(valuesDir/fieldName, writeFormat_)() << values;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 (
84  const IOstream::streamFormat writeFormat
85 )
86 :
87  surfaceWriter(writeFormat)
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 (
101  const fileName& outputDir,
102  const fileName& surfaceName,
103  const pointField& points,
104  const faceList& faces
105 ) const
106 {
107  const fileName surfaceDir(outputDir/surfaceName);
108 
109  if (!isDir(surfaceDir))
110  {
111  mkDir(surfaceDir);
112  }
113 
114  if (debug)
115  {
116  Info<< "Writing geometry to " << surfaceDir << endl;
117  }
118 
119  // Points
120  OFstream(surfaceDir/"points", writeFormat_)() << points;
121 
122  // Faces
123  OFstream(surfaceDir/"faces", writeFormat_)() << faces;
124 
125  // Face centers. Not really necessary but very handy when reusing as inputs
126  // for e.g. timeVaryingMapped bc.
127  pointField faceCentres(faces.size(), Zero);
128 
129  forAll(faces, facei)
130  {
131  faceCentres[facei] = faces[facei].centre(points);
132  }
133 
134  OFstream(surfaceDir/"faceCentres", writeFormat_)() << faceCentres;
135 }
136 
137 
138 // Create write methods
140 
141 
142 // ************************************************************************* //
virtual ~foamSurfaceWriter()
Destructor.
foamSurfaceWriter(const IOstream::streamFormat writeFormat)
Construct given write format.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for handling file names.
Definition: fileName.H:79
static const char *const typeName
Definition: Field.H:105
Output to file stream.
Definition: OFstream.H:82
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A surfaceWriter for native OpenFOAM format with support for writing ASCII or binary.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
Convenience macros for instantiating writer methods for surfaceWriter classes.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
static const zero Zero
Definition: zero.H:97
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
makeSurfaceWriterType(ensightSurfaceWriter)
messageStream Info
Base class for surface writers.
Definition: surfaceWriter.H:54
Namespace for OpenFOAM.
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces) const
Write single surface geometry to file.