boundaryDataSurfaceWriterTemplates.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) 2015 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 i
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 "OFstream.H"
27 #include "OSspecific.H"
28 #include "IOmanip.H"
29 #include "Time.H"
30 #include "pointIOField.H"
31 #include "AverageIOField.H"
32 #include "primitivePatch.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  const fileName& outputDir,
40  const fileName& surfaceName,
41  const pointField& points,
42  const faceList& faces,
43  const word& fieldName,
44  const Field<Type>& values,
45  const bool isNodeValues,
46  const bool verbose
47 ) const
48 {
49  const fileName baseDir(outputDir.path()/surfaceName);
50  const fileName timeName(outputDir.name());
51 
52 
53  // Construct dummy time to use as an objectRegistry
54  const fileName caseDir(getEnv("FOAM_CASE"));
55  Time dummyTime
56  (
57  caseDir.path(), //rootPath,
58  caseDir.name(), //caseName,
59  "system", //systemName,
60  "constant", //constantName,
61  false //enableFunctionObjects
62  );
63 
64 
65  // Write points
66 
67  pointIOField pts
68  (
69  IOobject
70  (
71  baseDir/"points",
72  dummyTime,
73  IOobject::NO_READ,
74  IOobject::NO_WRITE,
75  false
76  ),
77  0
78  );
79 
80  if (isNodeValues)
81  {
82  if (verbose)
83  {
84  Info<< "Writing points to " << baseDir/"points" << endl;
85  }
86  pts = points;
87  }
88  else
89  {
90  if (verbose)
91  {
92  Info<< "Writing face centres to " << baseDir/"points" << endl;
93  }
94 
95  primitivePatch pp(SubList<face>(faces, faces.size()), points);
96 
97  pts = pp.faceCentres();
98  }
99 
100  {
101  // Do like regIOobject::writeObject but don't do instance() adaptation
102  // since this would write to e.g. 0/ instead of postProcessing/
103 
104  // Try opening an OFstream for object
105  mkDir(pts.path());
106  OFstream os(pts.objectPath());
107 
108  pts.writeHeader(os);
109  pts.writeData(os);
110  pts.writeEndDivider(os);
111  }
112 
113 
114  // Write field
115  {
117  (
118  IOobject
119  (
120  baseDir/timeName/fieldName,
121  dummyTime,
122  IOobject::NO_READ,
123  IOobject::NO_WRITE,
124  false
125  ),
127  values
128  );
129 
130  // Do like regIOobject::writeObject but don't do instance() adaptation
131  // since this would write to e.g. 0/ instead of postProcessing/
132 
133  // Try opening an OFstream for object
134  mkDir(vals.path());
135  OFstream os(vals.objectPath());
136 
137  vals.writeHeader(os);
138  vals.writeData(os);
139  vals.writeEndDivider(os);
140  }
141 
142  return baseDir;
143 }
144 
145 
146 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOField< vector >
Foam::boundaryDataSurfaceWriter::writeTemplate
fileName writeTemplate(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const word &fieldName, const Field< Type > &values, const bool isNodeValues, const bool verbose) const
Templated write operation.
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::IOobject::writeEndDivider
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:118
AverageIOField.H
Foam::fileName::path
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:293
pointIOField.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::AverageIOField::writeData
bool writeData(Ostream &os) const
Pure virtual writaData function.
Definition: AverageIOField.C:80
Foam::fileName::name
word name() const
Return file name (part beyond last /)
Definition: fileName.C:212
OFstream.H
Foam::IOobject::objectPath
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:376
Foam::IOobject::writeHeader
bool writeHeader(Ostream &) const
Write header.
Definition: IOobjectWriteHeader.C:67
Foam::getEnv
string getEnv(const word &)
Return environment variable of given name.
Definition: POSIX.C:101
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
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
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::AverageIOField
A primitive field + average with IO.
Definition: AverageIOField.H:50
Foam::PrimitivePatch::faceCentres
const Field< PointType > & faceCentres() const
Return face centres for patch.
Definition: PrimitivePatchTemplate.C:500
points
const pointField & points
Definition: gmvOutputHeader.H:1
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
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
Foam::IOobject::path
fileName path() const
Return complete path.
Definition: IOobject.C:293
caseDir
static fileName caseDir
Definition: globalFoam.H:42
Foam::IOField::writeData
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOField.C:169
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88