FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/OFstream.H>
29 #include <OpenFOAM/OSspecific.H>
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 :
36  surfaceWriter<Type>()
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
41 
42 template<class Type>
44 {}
45 
46 
47 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
48 
49 template<class Type>
51 (
52  const fileName& outputDir,
53  const fileName& surfaceName,
54  const pointField& points,
55  const faceList& faces,
56  const bool verbose
57 ) const
58 {
59  fileName surfaceDir(outputDir/surfaceName);
60 
61  if (!isDir(surfaceDir))
62  {
63  mkDir(surfaceDir);
64  }
65 
66  if (verbose)
67  {
68  Info<< "Writing geometry to " << surfaceDir << endl;
69  }
70 
71  // Points
72  OFstream(surfaceDir/"points")() << points;
73 
74  // Faces
75  OFstream(surfaceDir/"faces")() << faces;
76 
77  // Face centers. Not really necessary but very handy when reusing as inputs
78  // for e.g. timeVaryingMapped bc.
79  pointField faceCentres(faces.size(),point::zero);
80 
81  forAll (faces, faceI)
82  {
83  faceCentres[faceI] = faces[faceI].centre(points);
84  }
85 
86  OFstream(surfaceDir/"faceCentres")() << faceCentres;
87 }
88 
89 
90 template<class Type>
92 (
93  const fileName& outputDir,
94  const fileName& surfaceName,
95  const pointField& points,
96  const faceList& faces,
97  const fileName& fieldName,
98  const Field<Type>& values,
99  const bool verbose
100 ) const
101 {
102  fileName surfaceDir(outputDir/surfaceName);
103 
104  if (!isDir(surfaceDir))
105  {
106  mkDir(surfaceDir);
107  }
108 
109  if (verbose)
110  {
111  Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
112  }
113 
114  // geometry should already have been written
115 
116  // Values to separate directory (e.g. "scalarField/p")
117 
119  fileName valuesDir(surfaceDir / (foamName + Field<Type>::typeName));
120 
121  if (!isDir(valuesDir))
122  {
123  mkDir(valuesDir);
124  }
125 
126  // values
127  OFstream(valuesDir/fieldName)() << values;
128 }
129 
130 
131 // ************************ vim: set sw=4 sts=4 et: ************************ //