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-2018 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  (
82  IOstreamOption::formatNames.lookupOrDefault
83  (
84  "format",
85  dict,
86  runTime.writeFormat(),
87  true // Failsafe behaviour
88  )
89  ),
90  caseOpts_(writeOpts_.format()),
91  outputDir_(),
92  consecutive_(false),
93  meshState_(polyMesh::TOPO_CHANGE),
94  selectFields_(),
95  selection_(),
96  meshSubset_(mesh_),
97  ensCase_(nullptr),
98  ensMesh_(nullptr)
99 {
100  // May still want this? (OCT-2018)
101  // if (postProcess)
102  // {
103  // // Disable for post-process mode.
104  // // Emit as FatalError for the try/catch in the caller.
105  // FatalError
106  // << type() << " disabled in post-process mode"
107  // << exit(FatalError);
108  // }
109 
110  read(dict);
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 {
119 
120  readSelection(dict);
121 
122 
123  // Writer options
124 
125  consecutive_ = dict.lookupOrDefault("consecutive", false);
126 
127  writeOpts_.useBoundaryMesh(dict.lookupOrDefault("boundary", true));
128  writeOpts_.useInternalMesh(dict.lookupOrDefault("internal", true));
129 
130 
131  // Warn if noPatches keyword (1806) exists and contradicts our settings
132  // Cannot readily use Compat since the boolean has the opposite value.
133  if
134  (
135  dict.lookupOrDefault("noPatches", false)
136  && writeOpts_.useBoundaryMesh()
137  )
138  {
140  << "Use 'boundary' instead of 'noPatches' to enable/disable "
141  << "conversion of the boundaries" << endl;
142  }
143 
144  wordRes list;
145  if (dict.readIfPresent("patches", list))
146  {
147  list.uniq();
148  writeOpts_.patchSelection(list);
149  }
150 
151  if (dict.readIfPresent("faceZones", list))
152  {
153  list.uniq();
154  writeOpts_.faceZoneSelection(list);
155  }
156 
157 
158  // Case options
159 
160  caseOpts_.nodeValues(dict.lookupOrDefault("nodeValues", false));
161  caseOpts_.width(dict.lookupOrDefault<label>("width", 8));
162  caseOpts_.overwrite(dict.lookupOrDefault("overwrite", false));
163 
164 
165  // Output directory
166 
167  outputDir_.clear();
168  dict.readIfPresent("directory", outputDir_);
169 
170  if (outputDir_.size())
171  {
172  // User-defined output directory
173  outputDir_.expand();
174  if (!outputDir_.isAbsolute())
175  {
176  outputDir_ = time_.globalPath()/outputDir_;
177  }
178  }
179  else
180  {
181  // Standard postProcessing/ naming
182  outputDir_ = time_.globalPath()/functionObject::outputPrefix/name();
183  }
184  outputDir_.clean();
185 
186  return true;
187 }
188 
189 
191 {
192  return true;
193 }
194 
195 
197 {
198  if (!ensCase_.valid())
199  {
200  ensCase_.reset
201  (
202  new ensightCase(outputDir_, time_.globalCaseName(), caseOpts_)
203  );
204  }
205 
206  if (consecutive_)
207  {
208  ensCase().nextTime(time_.value());
209  }
210  else
211  {
212  ensCase().setTime(time_.value(), time_.timeIndex());
213  }
214 
215 
216  if (update())
217  {
218  // Treat all geometry as moving, since we do not know a priori
219  // if the simulation has mesh motion later on.
220  autoPtr<ensightGeoFile> os = ensCase_().newGeometry(true);
221  ensMesh_().write(os);
222  }
223 
224  wordHashSet acceptField(mesh_.names<void>(selectFields_));
225 
226  // Prune restart fields
227  acceptField.filterKeys
228  (
229  [](const word& k){ return k.ends_with("_0"); },
230  true // prune
231  );
232 
233  Log << type() << " " << name() << " write: (";
234  writeAllVolFields(meshSubset_, acceptField);
235 
236  Log << " )" << nl;
237 
238  ensCase().write(); // Flush case information
239 
240  return true;
241 }
242 
243 
245 {
246  return true;
247 }
248 
249 
250 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
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:62
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:244
Foam::functionObjects::ensightWrite::write
virtual bool write()
Write fields, flush case file.
Definition: ensightWrite.C:196
Foam::functionObjects::ensightWrite::read
virtual bool read(const dictionary &dict)
Read the ensightWrite specification.
Definition: ensightWrite.C:116
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
polyMesh.H
Foam::HashSet< word >
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::writeAllVolFields
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const fvMeshSubsetProxy &proxy, const IOobjectList &objects, const bool nodeValues)
Definition: writeVolFields.H:118
Foam::polyMesh::TOPO_CHANGE
Definition: polyMesh.H:95
Foam::functionObject::outputPrefix
static word outputPrefix
Directory prefix.
Definition: functionObject.H:259
Foam::HashTable::filterKeys
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
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:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
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:190
Foam::ensightCase
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:63
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
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:372
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
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:115
Foam::wordHashSet
HashSet< word > wordHashSet
A HashSet with word keys.
Definition: HashSet.H:412
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:294
Foam::IOstreamOption::formatNames
static const Enum< streamFormat > formatNames
Stream format names (ascii, binary)
Definition: IOstreamOption.H:187
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332