ensightWrite.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "ensightWrite.H"
29 #include "Time.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(ensightWrite, 0);
40 
42  (
43  functionObject,
44  ensightWrite,
45  dictionary
46  );
47 }
48 }
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 Foam::label Foam::functionObjects::ensightWrite::writeAllVolFields
53 (
54  const fvMeshSubset& proxy,
55  const wordHashSet& acceptField
56 )
57 {
58  label count = 0;
59 
60  count += writeVolFields<scalar>(proxy, acceptField);
61  count += writeVolFields<vector>(proxy, acceptField);
62  count += writeVolFields<sphericalTensor>(proxy, acceptField);
63  count += writeVolFields<symmTensor>(proxy, acceptField);
64  count += writeVolFields<tensor>(proxy, acceptField);
65 
66  return count;
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 Foam::functionObjects::ensightWrite::ensightWrite
73 (
74  const word& name,
75  const Time& runTime,
76  const dictionary& dict
77 )
78 :
80  writeOpts_(),
81  caseOpts_
82  (
83  IOstreamOption::formatEnum("format", dict, runTime.writeFormat())
84  ),
85  outputDir_(),
86  consecutive_(false),
87  meshState_(polyMesh::TOPO_CHANGE),
88  selectFields_(),
89  selection_(),
90  meshSubset_(mesh_),
91  ensCase_(nullptr),
92  ensMesh_(nullptr)
93 {
94  // May still want this? (OCT-2018)
95  // if (postProcess)
96  // {
97  // // Disable for post-process mode.
98  // // Emit as FatalError for the try/catch in the caller.
99  // FatalError
100  // << type() << " disabled in post-process mode"
101  // << exit(FatalError);
102  // }
103 
104  read(dict);
105 }
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
111 {
113 
114  readSelection(dict);
115 
116 
117  // Writer options
118 
119  consecutive_ = dict.getOrDefault("consecutive", false);
120 
121  writeOpts_.useBoundaryMesh(dict.getOrDefault("boundary", true));
122  writeOpts_.useInternalMesh(dict.getOrDefault("internal", true));
123 
124 
125  // Warn if noPatches keyword (1806) exists and contradicts our settings
126  // Cannot readily use Compat since the boolean has the opposite value.
127  if
128  (
129  dict.getOrDefault("noPatches", false)
130  && writeOpts_.useBoundaryMesh()
131  )
132  {
134  << "Use 'boundary' instead of 'noPatches' to enable/disable "
135  << "conversion of the boundaries" << endl;
136  }
137 
138  wordRes list;
139  if (dict.readIfPresent("patches", list))
140  {
141  list.uniq();
142  writeOpts_.patchSelection(list);
143  }
144 
145  if (dict.readIfPresent("faceZones", list))
146  {
147  list.uniq();
148  writeOpts_.faceZoneSelection(list);
149  }
150 
151 
152  // Case options
153 
154  caseOpts_.nodeValues(dict.getOrDefault("nodeValues", false));
155  caseOpts_.width(dict.getOrDefault<label>("width", 8));
156  caseOpts_.overwrite(dict.getOrDefault("overwrite", false));
157 
158 
159  // Output directory
160 
161  outputDir_.clear();
162  dict.readIfPresent("directory", outputDir_);
163 
164  if (outputDir_.size())
165  {
166  // User-defined output directory
167  outputDir_.expand();
168  if (!outputDir_.isAbsolute())
169  {
170  outputDir_ = time_.globalPath()/outputDir_;
171  }
172  }
173  else
174  {
175  // Standard postProcessing/ naming
176  outputDir_ = time_.globalPath()/functionObject::outputPrefix/name();
177  }
178  outputDir_.clean(); // Remove unneeded ".."
179 
180  return true;
181 }
182 
183 
185 {
186  return true;
187 }
188 
189 
191 {
192  if (!ensCase_)
193  {
194  ensCase_.reset
195  (
196  new ensightCase(outputDir_, time_.globalCaseName(), caseOpts_)
197  );
198  }
199 
200  if (consecutive_)
201  {
202  ensCase().nextTime(time_.value());
203  }
204  else
205  {
206  ensCase().setTime(time_.value(), time_.timeIndex());
207  }
208 
209 
210  if (update())
211  {
212  // Treat all geometry as moving, since we do not know a priori
213  // if the simulation has mesh motion later on.
214  autoPtr<ensightGeoFile> os = ensCase_().newGeometry(true);
215  ensMesh_().write(os);
216  }
217 
218  wordHashSet acceptField(mesh_.names<void>(selectFields_));
219 
220  // Prune restart fields
221  acceptField.filterKeys
222  (
223  [](const word& k){ return k.ends_with("_0"); },
224  true // prune
225  );
226 
227  Log << type() << " " << name() << " write: (";
228  writeAllVolFields(meshSubset_, acceptField);
229 
230  Log << " )" << nl;
231 
232  ensCase().write(); // Flush case information
233 
234  return true;
235 }
236 
237 
239 {
240  return true;
241 }
242 
243 
244 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
update
mesh update()
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::ensightWrite::end
virtual bool end()
Do nothing at the final time-loop.
Definition: ensightWrite.C:238
Foam::functionObjects::ensightWrite::write
virtual bool write()
Write fields, flush case file.
Definition: ensightWrite.C:190
Foam::functionObjects::ensightWrite::read
virtual bool read(const dictionary &dict)
Read the ensightWrite specification.
Definition: ensightWrite.C:110
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
polyMesh.H
Foam::HashSet< word, Hash< word > >
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::writeAllVolFields
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Definition: writeVolFields.H:126
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:94
Foam::functionObject::outputPrefix
static word outputPrefix
Directory prefix.
Definition: functionObject.H:376
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::ensightWrite::execute
virtual bool execute()
Do nothing.
Definition: ensightWrite.C:184
Foam::ensightCase
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:67
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::IOstreamOption::formatEnum
static streamFormat formatEnum(const word &formatName, const streamFormat deflt=streamFormat::ASCII)
Definition: IOstreamOption.C:53
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::wordHashSet
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:77
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
ensightWrite.H
Foam::wordRes::uniq
static wordRes uniq(const UList< wordRe > &input)
Return a wordRes with duplicate entries filtered out.
Definition: wordRes.C:32
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328