ensightSurfaceWriter.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-2021 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 "ensightSurfaceWriter.H"
27 #include "OFstream.H"
28 #include "OSspecific.H"
29 #include "IOmanip.H"
30 #include "ensightPartFaces.H"
31 #include "ensightPTraits.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
45 
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
53 (
54  const fileName& outputDir,
55  const fileName& surfaceName,
56  const pointField& points,
57  const faceList& faces,
58  const wordList& fieldNames,
59  const bool writePointValues
60  #define FieldTypeValuesConstArg(Type, nullArg) \
61  , const UPtrList<const Field<Type>>& field##Type##Values
64 ) const
65 {
66  if (!isDir(outputDir))
67  {
68  mkDir(outputDir);
69  }
70 
71  // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
72  const scalar timeValue = 0.0;
73 
74  OFstream osCase(outputDir/surfaceName + ".case");
75  ensightGeoFile osGeom
76  (
77  outputDir/surfaceName + ".000.mesh",
78  writeFormat_
79  );
80 
81  if (debug)
82  {
83  Info<< "Writing case file to " << osCase.name() << endl;
84  }
85 
86  osCase
87  << "FORMAT" << nl
88  << "type: ensight gold" << nl
89  << nl;
90 
91  osCase
92  << "GEOMETRY" << nl
93  << "model: 1 " << osGeom.name().name() << nl
94  << nl;
95 
96  osCase
97  << "VARIABLE" << nl;
98  forAll(fieldNames, fieldi)
99  {
100  #define WriteTypeCase(Type, nullArg) \
101  if (field##Type##Values.set(fieldi)) \
102  { \
103  osCase \
104  << ensightPTraits<Type>::typeName << " per " \
105  << word(writePointValues ? "node:" : "element:") \
106  << setw(10) << 1 << " " << fieldNames[fieldi] \
107  << " " << surfaceName.c_str() << ".***." \
108  << fieldNames[fieldi] << nl; \
109  }
111  #undef WriteTypeCase
112  }
113  osCase
114  << nl;
115 
116  osCase
117  << "TIME" << nl
118  << "time set: 1" << nl
119  << "number of steps: 1" << nl
120  << "filename start number: 0" << nl
121  << "filename increment: 1" << nl
122  << "time values:" << nl
123  << timeValue << nl
124  << nl;
125 
126  ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
127  osGeom << ensPart;
128 
129  forAll(fieldNames, fieldi)
130  {
131  #define WriteTypeValues(Type, nullArg) \
132  if (field##Type##Values.set(fieldi)) \
133  { \
134  ensightFile osField \
135  ( \
136  outputDir/surfaceName \
137  + ".000." \
138  + fieldNames[fieldi], \
139  writeFormat_ \
140  ); \
141  osField.writeKeyword(ensightPTraits<Type>::typeName); \
142  ensPart.writeField \
143  ( \
144  osField, \
145  field##Type##Values[fieldi], \
146  writePointValues \
147  ); \
148  }
150  #undef WriteTypeValues
151  }
152 }
153 
154 
155 // ************************************************************************* //
Istream and Ostream manipulators taking arguments.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Output to file stream.
Definition: OFstream.H:86
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:120
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
Specialised Ensight output with extra geometry file header.
An implementation of ensightPart to hold volume mesh faces.
A surfaceWriter for Ensight format.
virtual ~ensightSurfaceWriter()
Destructor.
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const wordList &fieldNames, const bool writePointValues #define FieldTypeValuesConstArg(Type, nullArg)) const=0
Inherit base class templated write.
A class for handling file names.
Definition: fileName.H:82
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
Base class for surface writers.
Definition: surfaceWriter.H:55
A class for handling words, derived from string.
Definition: word.H:62
#define WriteTypeValues(Type, nullArg)
#define WriteTypeCase(Type, nullArg)
#define FieldTypeValuesConstArg(Type, nullArg)
static List< word > fieldNames
Definition: globalFoam.H:46
const pointField & points
Namespace for OpenFOAM.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
static const char nl
Definition: Ostream.H:266
dictionary dict