surfaceWriter.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 "surfaceWriter.H"
27 #include "MeshedSurfaceProxy.H"
28 #include "proxySurfaceWriter.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  const IOstream::streamFormat writeFormat,
46  const IOstream::compressionType writeCompression
47 )
48 :
49  writeFormat_(writeFormat),
50  writeCompression_(writeCompression)
51 {}
52 
53 
55 :
56  writeFormat_
57  (
58  dict.found("writeFormat")
59  ? IOstream::formatEnum(dict.lookup("writeFormat"))
60  : IOstream::ASCII
61  ),
62  writeCompression_
63  (
64  dict.found("writeCompression")
65  ? IOstream::compressionEnum(dict.lookup("writeCompression"))
66  : IOstream::UNCOMPRESSED
67  )
68 {}
69 
70 
71 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
72 
75 (
76  const word& writeType,
77  const IOstream::streamFormat writeFormat,
78  const IOstream::compressionType writeCompression
79 )
80 {
81  wordConstructorTable::iterator cstrIter =
82  wordConstructorTablePtr_->find(writeType);
83 
84  if (cstrIter == wordConstructorTablePtr_->end())
85  {
87  {
88  // generally unknown, but can be written via MeshedSurfaceProxy
89  // use 'proxy' handler instead
90  return autoPtr<surfaceWriter>(new proxySurfaceWriter(writeType));
91  }
92 
93  if (cstrIter == wordConstructorTablePtr_->end())
94  {
96  << "Unknown write type \"" << writeType << "\"\n\n"
97  << "Valid write types : "
98  << wordConstructorTablePtr_->sortedToc() << nl
99  << "Valid proxy types : "
101  << exit(FatalError);
102  }
103  }
104 
105  return autoPtr<surfaceWriter>(cstrIter()(writeFormat, writeCompression));
106 }
107 
108 
111 (
112  const word& writeType,
113  const dictionary& dict
114 )
115 {
116  // find constructors with dictionary options
117  dictConstructorTable::iterator cstrIter =
118  dictConstructorTablePtr_->find(writeType);
119 
120  if (cstrIter == dictConstructorTablePtr_->end())
121  {
122  const IOstream::streamFormat writeFormat =
123  dict.found("writeFormat")
124  ? IOstream::formatEnum(dict.lookup("writeFormat"))
125  : IOstream::ASCII;
126 
127  const IOstream::compressionType writeCompression =
128  dict.found("writeCompression")
129  ? IOstream::compressionEnum(dict.lookup("writeCompression"))
130  : IOstream::UNCOMPRESSED;
131 
132  // Revert to versions without options
133  return
135  (
136  writeType,
137  writeFormat,
138  writeCompression
139  );
140  }
141 
142  return autoPtr<surfaceWriter>(cstrIter()(dict));
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
147 
149 {}
150 
151 
152 // ************************************************************************* //
bool found
Macros for easy insertion into run-time selection tables.
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:72
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
static streamFormat formatEnum(const word &)
Return stream format of given format name.
Definition: IOstream.C:39
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
static compressionType compressionEnum(const word &)
Return compression of given compression name.
Definition: IOstream.C:61
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
static wordHashSet writeTypes()
The file format types that can be written via MeshedSurfaceProxy.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:659
A surfaceWriter that writes the geometry via the MeshedSurfaceProxy, but which does not support any f...
Base class for surface writers.
Definition: surfaceWriter.H:55
virtual ~surfaceWriter()
Destructor.
surfaceWriter(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Construct given write options.
Definition: surfaceWriter.C:44
static autoPtr< surfaceWriter > New(const word &writeType, const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Select given write options.
Definition: surfaceWriter.C:75
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
static const char nl
Definition: Ostream.H:260
dictionary dict