Loading...
Searching...
No Matches
triSurfaceNew.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) 2020-2022 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 "triSurface.H"
29#include "Fstream.H"
30#include "MeshedSurface.H"
32
33// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
34
37(
38 const fileName& name,
39 const word& fileType
40)
41{
42 const word ext(name.ext());
43
44 if (fileType.empty())
45 {
46 // Handle empty/missing type
47
48 if (ext.empty())
49 {
51 << "Cannot determine format from filename" << nl
52 << " " << name << nl
53 << exit(FatalError);
54 }
55
56 return New(name, ext);
57 }
58 else if (fileType == "gz")
59 {
60 // Degenerate call
61 return New(name.lessExt(), name.stem().ext());
62 }
63 else if (ext == "gz")
64 {
65 // Handle trailing "gz" on file name
66 return New(name.lessExt(), fileType);
67 }
68
69 // if (check && !exists(name))
70 // {
71 // FatalErrorInFunction
72 // << "No such file " << name << nl
73 // << exit(FatalError);
74 // }
75
76
77 // Hard-coded readers
78 if (fileType == "ftr")
79 {
80 auto surf = autoPtr<triSurface>::New();
81
82 IFstream is(name);
83 surf->readNative(is);
84 return surf;
85 }
86 else if (fileType == "stl")
87 {
88 auto surf = autoPtr<triSurface>::New();
89
90 surf->readSTL(name); // ASCII
91 return surf;
92 }
93 else if (fileType == "stlb")
94 {
95 auto surf = autoPtr<triSurface>::New();
96
97 surf->readSTL(name, true); // Force BINARY
98 return surf;
99 }
100
101 {
102 // UnsortedMeshedSurface
103 using proxyType = UnsortedMeshedSurface<labelledTri>;
104 if (proxyType::readTypes().found(fileType))
105 {
106 auto surf = autoPtr<triSurface>::New();
107
108 surf->transfer(*proxyType::New(name, fileType));
109 return surf;
110 }
111 }
112
113 // MeshedSurface
114 {
115 using proxyType = MeshedSurface<labelledTri>;
116 if (proxyType::readTypes().found(fileType))
117 {
118 auto surf = autoPtr<triSurface>::New();
119
120 surf->transfer(*proxyType::New(name, fileType));
121 return surf;
122 }
123 }
124
125 {
127 << "Unknown surface format " << fileType
128 << " for reading file " << name << nl
129 << "Valid types:" << nl
130 << " " << flatOutput(readTypes().sortedToc()) << nl
131 << exit(FatalError);
132 }
134 // Failed
135 return nullptr;
136}
137
138
141{
142 if (name.has_ext("gz"))
143 {
144 // Handle trailing "gz" on file name
145 return New(name.lessExt(), name.stem().ext());
146 }
147
148 return New(name, name.ext());
149}
150
151
152// ************************************************************************* //
bool found
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
Definition IFstream.H:55
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
A class for handling file names.
Definition fileName.H:75
static autoPtr< triSurface > New(const fileName &name, const word &fileType)
Read construct from filename with given file type.
static wordHashSet readTypes()
Known readable file-types, including via friends or proxies.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
auto & name
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50