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-2019 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::writeTemplate
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 bool verbose
52 ) const
53 {
54  fileName surfaceDir(outputDir/surfaceName);
55 
56  if (!isDir(surfaceDir))
57  {
58  mkDir(surfaceDir);
59  }
60 
61  if (verbose)
62  {
63  Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
64  }
65 
66  // geometry should already have been written
67  // Values to separate directory (e.g. "scalarField/p")
68 
69  fileName foamName(pTraits<Type>::typeName);
70  fileName valuesDir(surfaceDir / (foamName + Field<Type>::typeName));
71 
72  if (!isDir(valuesDir))
73  {
74  mkDir(valuesDir);
75  }
76 
77  // values
78  OFstream(valuesDir/fieldName)() << values;
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
85 :
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
91 
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
99 (
100  const fileName& outputDir,
101  const fileName& surfaceName,
102  const pointField& points,
103  const faceList& faces,
104  const bool verbose
105 ) const
106 {
107  fileName surfaceDir(outputDir/surfaceName);
108 
109  if (!isDir(surfaceDir))
110  {
111  mkDir(surfaceDir);
112  }
113 
114  if (verbose)
115  {
116  Info<< "Writing geometry to " << surfaceDir << endl;
117  }
118 
119 
120  // Points
121  OFstream(surfaceDir/"points")() << points;
122 
123  // Faces
124  OFstream(surfaceDir/"faces")() << faces;
125 
126  // Face centers. Not really necessary but very handy when reusing as inputs
127  // for e.g. timeVaryingMapped bc.
128  pointField faceCentres(faces.size(),point::zero);
129 
130  forAll(faces, facei)
131  {
132  faceCentres[facei] = faces[facei].centre(points);
133  }
134 
135  OFstream(surfaceDir/"faceCentres")() << faceCentres;
136 }
137 
138 
139 // Create write methods
141 
142 
143 // ************************************************************************* //
virtual ~foamSurfaceWriter()
Destructor.
#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:163
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
A surfaceWriter for foams.
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.
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.
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
foamSurfaceWriter()
Construct null.
makeSurfaceWriterType(ensightSurfaceWriter)
messageStream Info
Base class for surface writers.
Definition: surfaceWriter.H:54
Namespace for OpenFOAM.