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-------------------------------------------------------------------------------
10License
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
35namespace Foam
36{
37namespace functionObjects
38{
40
42 (
46 );
47}
48}
49
50// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51
52Foam::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
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// ************************************************************************* //
label k
#define Log
Definition: PDRblock.C:35
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
The IOstreamOption is a simple container for options an IOstream can normally have.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:69
Abstract base-class for Time/database function objects.
static word outputPrefix
Directory prefix.
Writes fields in ensight format.
Definition: ensightWrite.H:249
virtual bool read(const dictionary &dict)
Read the ensightWrite specification.
Definition: ensightWrite.C:110
virtual bool execute()
Do nothing.
Definition: ensightWrite.C:184
virtual bool write()
Write fields, flush case file.
Definition: ensightWrite.C:190
virtual bool end()
Do nothing at the final time-loop.
Definition: ensightWrite.C:238
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
static wordRes uniq(const UList< wordRe > &input)
Return a wordRes with duplicate entries filtered out.
Definition: wordRes.C:32
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
mesh update()
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict