Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
3ef8906a
Commit
3ef8906a
authored
Nov 20, 2017
by
Mark Olesen
Browse files
ENH: consolidate surfaceFormats for reading/writing triSurface (issue
#294
)
- eliminates previous code duplication and improves maintainability
parent
5947f9a3
Changes
111
Hide whitespace changes
Inline
Side-by-side
applications/utilities/surface/surfaceConvert/surfaceConvert.C
View file @
3ef8906a
...
...
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
{
argList
::
addNote
(
"convert between surface formats"
"convert between surface formats
, using triSurface library components
"
);
argList
::
noParallel
();
...
...
@@ -96,16 +96,6 @@ int main(int argc, char *argv[])
argList
args
(
argc
,
argv
);
if
(
args
.
optionFound
(
"writePrecision"
))
{
label
writePrecision
=
args
.
optionRead
<
label
>
(
"writePrecision"
);
IOstream
::
defaultPrecision
(
writePrecision
);
Sout
.
precision
(
writePrecision
);
Info
<<
"Output write precision set to "
<<
writePrecision
<<
endl
;
}
const
fileName
importName
=
args
[
1
];
const
fileName
exportName
=
args
[
2
];
...
...
@@ -116,6 +106,26 @@ int main(int argc, char *argv[])
<<
exit
(
FatalError
);
}
// Check that reading/writing is supported
if
(
!
triSurface
::
canRead
(
importName
,
true
)
||
!
triSurface
::
canWriteType
(
exportName
.
ext
(),
true
)
)
{
return
1
;
}
if
(
args
.
optionFound
(
"writePrecision"
))
{
label
writePrecision
=
args
.
optionRead
<
label
>
(
"writePrecision"
);
IOstream
::
defaultPrecision
(
writePrecision
);
Sout
.
precision
(
writePrecision
);
Info
<<
"Output write precision set to "
<<
writePrecision
<<
endl
;
}
const
scalar
scaleFactor
=
args
.
optionLookupOrDefault
<
scalar
>
(
"scale"
,
-
1
);
Info
<<
"Reading : "
<<
importName
<<
endl
;
...
...
applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C
View file @
3ef8906a
...
...
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
{
argList
::
addNote
(
"convert between surface formats"
"convert between surface formats
, using MeshSurface library components
"
);
argList
::
noParallel
();
...
...
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
<<
exit
(
FatalError
);
}
//
c
heck that reading/writing is supported
//
C
heck that reading/writing is supported
if
(
!
MeshedSurface
<
face
>::
canRead
(
importName
,
true
)
...
...
src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H
View file @
3ef8906a
...
...
@@ -288,6 +288,10 @@ public:
// Member Functions
//- Suppress direct swapping, since storage containers may be const
void
swap
(
PrimitivePatch
&
)
=
delete
;
// Access
//- Return reference to global points
...
...
@@ -320,9 +324,9 @@ public:
label
nInternalEdges
()
const
;
//- Is internal edge?
bool
isInternalEdge
(
const
label
edge
I
)
const
bool
isInternalEdge
(
const
label
edge
i
)
const
{
return
edge
I
<
nInternalEdges
();
return
edge
i
<
nInternalEdges
();
}
//- Return list of boundary points,
...
...
src/OpenFOAM/primitives/strings/stringOps/stringOps.H
View file @
3ef8906a
...
...
@@ -365,13 +365,18 @@ namespace stringOps
const
std
::
string
&
delim
);
//- Split string into sub-strings using a fixed field width
//- Split string into sub-strings using a fixed field width
.
// Behaviour is ill-defined if width is zero.
// \param str the string to be split
// \param width the fixed field width for each sub-string
// \param start the optional offset of where to start the splitting.
// Any text prior to start is ignored in the operation.
template
<
class
StringType
>
Foam
::
SubStrings
<
StringType
>
splitFixed
(
const
StringType
&
str
,
const
std
::
string
::
size_type
width
const
std
::
string
::
size_type
width
,
const
std
::
string
::
size_type
start
=
0
);
//- Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)
...
...
src/OpenFOAM/primitives/strings/stringOps/stringOpsTemplates.C
View file @
3ef8906a
...
...
@@ -183,7 +183,8 @@ template<class StringType>
Foam
::
SubStrings
<
StringType
>
Foam
::
stringOps
::
splitFixed
(
const
StringType
&
str
,
const
std
::
string
::
size_type
width
const
std
::
string
::
size_type
width
,
const
std
::
string
::
size_type
start
)
{
Foam
::
SubStrings
<
StringType
>
lst
;
...
...
@@ -195,7 +196,7 @@ Foam::SubStrings<StringType> Foam::stringOps::splitFixed
const
auto
len
=
str
.
size
();
lst
.
reserve
(
1
+
(
len
/
width
));
for
(
std
::
string
::
size_type
pos
=
0
;
pos
<
len
;
pos
+=
width
)
for
(
std
::
string
::
size_type
pos
=
start
;
pos
<
len
;
pos
+=
width
)
{
const
auto
end
=
(
pos
+
width
);
...
...
src/fileFormats/fire/FIRECore.C
View file @
3ef8906a
...
...
@@ -40,12 +40,6 @@ Foam::fileFormats::FIRECore::file3dExtensions
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
fileFormats
::
FIRECore
::
FIRECore
()
{}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
Foam
::
label
Foam
::
fileFormats
::
FIRECore
::
readPoints
...
...
src/fileFormats/fire/FIRECore.H
View file @
3ef8906a
...
...
@@ -108,7 +108,7 @@ protected:
// Protected Member Functions
//- Construct null
FIRECore
();
FIRECore
()
=
default
;
//- Read points.
...
...
src/fileFormats/nas/NASCore.C
View file @
3ef8906a
...
...
@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 201
1
Open
FOAM Foundation
\\/ M anipulation |
Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 201
7
Open
CFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -24,11 +24,27 @@ License
\*---------------------------------------------------------------------------*/
#include "NASCore.H"
#include "IOmanip.H"
#include "Ostream.H"
#include "parsing.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const
Foam
::
Enum
<
Foam
::
fileFormats
::
NASCore
::
fieldFormat
>
Foam
::
fileFormats
::
NASCore
::
fieldFormatNames
{
{
fieldFormat
::
SHORT
,
"short"
},
{
fieldFormat
::
LONG
,
"long"
},
{
fieldFormat
::
FREE
,
"free"
},
};
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam
::
scalar
Foam
::
fileFormats
::
NASCore
::
readNasScalar
(
const
string
&
str
)
Foam
::
scalar
Foam
::
fileFormats
::
NASCore
::
readNasScalar
(
const
std
::
string
&
str
)
{
const
auto
signPos
=
str
.
find_last_of
(
"+-"
);
...
...
@@ -54,7 +70,7 @@ Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const string& str)
if
(
readScalar
(
str
.
substr
(
0
,
signPos
),
value
)
// Mantissa
&&
readInt
(
str
.
substr
(
signPos
),
exponent
)
// Exponent (with sign)
&&
readInt
(
str
.
substr
(
signPos
),
exponent
)
// Exponent (with sign)
)
{
// Note: this does not catch underflow/overflow
...
...
@@ -74,10 +90,98 @@ Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const string& str)
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
std
::
string
Foam
::
fileFormats
::
NASCore
::
nextNasField
(
const
std
::
string
&
str
,
std
::
string
::
size_type
&
pos
,
std
::
string
::
size_type
len
)
{
const
auto
beg
=
pos
;
const
auto
end
=
str
.
find
(
','
,
pos
);
if
(
end
==
std
::
string
::
npos
)
{
pos
=
beg
+
len
;
// Continue after field width
}
else
{
len
=
(
end
-
beg
);
// Efffective width
pos
=
end
+
1
;
// Continue after comma
}
return
str
.
substr
(
beg
,
len
);
}
void
Foam
::
fileFormats
::
NASCore
::
setPrecision
(
Ostream
&
os
,
const
fieldFormat
format
)
{
os
.
setf
(
ios_base
::
scientific
);
Foam
::
fileFormats
::
NASCore
::
NASCore
()
{}
// Capitalise the E marker
os
.
setf
(
ios_base
::
uppercase
);
const
label
offset
=
7
;
label
prec
=
16
-
offset
;
switch
(
format
)
{
case
fieldFormat
:
:
SHORT
:
{
prec
=
8
-
offset
;
break
;
}
case
fieldFormat
:
:
LONG
:
case
fieldFormat
:
:
FREE
:
{
prec
=
16
-
offset
;
break
;
}
}
os
.
precision
(
prec
);
}
Foam
::
Ostream
&
Foam
::
fileFormats
::
NASCore
::
writeKeyword
(
Ostream
&
os
,
const
word
&
keyword
,
const
fieldFormat
format
)
{
os
.
setf
(
ios_base
::
left
);
switch
(
format
)
{
case
fieldFormat
:
:
SHORT
:
{
os
<<
setw
(
8
)
<<
keyword
;
break
;
}
case
fieldFormat
:
:
LONG
:
{
os
<<
setw
(
8
)
<<
word
(
keyword
+
'*'
);
break
;
}
case
fieldFormat
:
:
FREE
:
{
os
<<
keyword
;
break
;
}
}
os
.
unsetf
(
ios_base
::
left
);
return
os
;
}
// ************************************************************************* //
src/fileFormats/nas/NASCore.H
View file @
3ef8906a
...
...
@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 201
1
Open
FOAM Foundation
\\/ M anipulation |
Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 201
7
Open
CFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -37,11 +37,16 @@ SourceFiles
#include "scalar.H"
#include "string.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace
Foam
{
// Forward declarations
class
Ostream
;
namespace
fileFormats
{
...
...
@@ -53,23 +58,64 @@ class NASCore
{
public:
// Public Member Functions
//- File field formats
enum
fieldFormat
{
SHORT
,
//<! Short format (field width = 8)
LONG
,
//<! Long format (field width = 16)
FREE
//<! Free format (comma-separated fields)
};
//- Selection names for the NASTRAN file field formats
static
const
Enum
<
fieldFormat
>
fieldFormatNames
;
// Constructors
//- Construct null
NASCore
()
=
default
;
// Public Static Member Functions
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
static
scalar
readNasScalar
(
const
string
&
str
);
static
scalar
readNasScalar
(
const
std
::
string
&
str
);
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
// \deprecated use readNasScalar instead (deprecated Sep 2017)
inline
static
scalar
parseNASCoord
(
const
string
&
str
)
inline
static
scalar
parseNASCoord
(
const
std
::
string
&
str
)
{
return
readNasScalar
(
str
);
}
//- A string::substr() to handle fixed-format and free-format NASTRAN.
// Returns the substr to the next comma (if found) or the given length
//
// \param str The string to extract from
// \param pos On input, the position of the first character of the
// substring. On output, advances to the next position to use.
// \param len The fixed-format length to use if a comma is not found.
static
std
::
string
nextNasField
(
const
std
::
string
&
str
,
std
::
string
::
size_type
&
pos
,
std
::
string
::
size_type
len
);
//- Set output stream precision and format flags
static
void
setPrecision
(
Ostream
&
os
,
const
fieldFormat
format
);
//- Write initial keyword (eg, 'GRID' or 'GRID*') followed by the
//- requisite number of spaces for the field-width
static
Ostream
&
writeKeyword
(
Ostream
&
os
,
const
word
&
keyword
,
const
fieldFormat
format
);
// Constructors
//- Construct null
NASCore
();
};
...
...
src/fileFormats/starcd/STARCDCore.C
View file @
3ef8906a
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016
-2017
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -27,6 +27,7 @@ License
#include "ListOps.H"
#include "clock.H"
#include "PackedBoolList.H"
#include "DynamicList.H"
#include "StringStream.H"
#include "OSspecific.H"
...
...
@@ -85,12 +86,6 @@ Foam::fileFormats::STARCDCore::starToFoamFaceAddr =
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
fileFormats
::
STARCDCore
::
STARCDCore
()
{}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
bool
Foam
::
fileFormats
::
STARCDCore
::
readHeader
...
...
@@ -173,8 +168,8 @@ void Foam::fileFormats::STARCDCore::removeFiles(const fileName& base)
Foam
::
label
Foam
::
fileFormats
::
STARCDCore
::
readPoints
(
IFstream
&
is
,
pointField
&
points
,
label
List
&
ids
List
<
point
>
&
points
,
List
<
label
>
&
ids
)
{
label
maxId
=
0
;
...
...
@@ -219,7 +214,7 @@ Foam::label Foam::fileFormats::STARCDCore::readPoints
void
Foam
::
fileFormats
::
STARCDCore
::
writePoints
(
Ostream
&
os
,
const
pointField
&
points
,
const
UList
<
point
>
&
points
,
const
scalar
scaleFactor
)
{
...
...
src/fileFormats/starcd/STARCDCore.H
View file @
3ef8906a
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016
-2017
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -37,9 +37,10 @@ SourceFiles
#include "IFstream.H"
#include "Enum.H"
#include "pointField.H"
#include "Map.H"
#include "point.H"
#include "FixedList.H"
#include "List.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...
...
@@ -133,13 +134,13 @@ protected:
// Constructors
//- Construct null
STARCDCore
();
STARCDCore
()
=
default
;
//- Read header and check signature PROSTAR_(CELL|VERTEX|BOUNDARY)
static
bool
readHeader
(
IFstream
&
,
const
enum
fileHeader
);
static
bool
readHeader
(
IFstream
&
is
,
const
enum
fileHeader
header
);
//- Write header for fileType (CELL|VERTEX|BOUNDARY)
static
void
writeHeader
(
Ostream
&
,
const
enum
fileHeader
);
static
void
writeHeader
(
Ostream
&
os
,
const
enum
fileHeader
header
);
public:
...
...
@@ -150,7 +151,7 @@ public:
static
fileName
starFileName
(
const
fileName
&
baseName
,
const
enum
fileExt
const
enum
fileExt
ext
);
...
...
@@ -173,16 +174,16 @@ public:
// \endverbatim
static
label
readPoints
(
IFstream
&
,
pointField
&
,
label
List
&
ids
IFstream
&
is
,
List
<
point
>&
points
,
List
<
label
>
&
ids
);
//- Write header and points to (.vrt) file, optionally with scaling
static
void
writePoints
(
Ostream
&
,
const
pointField
&
,
Ostream
&
os
,
const
UList
<
point
>&
points
,
const
scalar
scaleFactor
=
1.0
);
...
...
src/fileFormats/stl/STLCore.C
View file @
3ef8906a
...
...
@@ -59,21 +59,20 @@ static bool startsWithSolid(const char header[STLHeaderSize])
//! \endcond
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
fileFormats
::
STLCore
::
STLCore
()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool
Foam
::
fileFormats
::
STLCore
::
isBinaryName
(
const
fileName
&
filename
,
const
STLFormat
&
format
const
STLFormat
format
)
{
return
(
format
==
UNKNOWN
?
(
filename
.
ext
()
==
"stlb"
)
:
format
==
BINARY
);
return
(
format
==
STLFormat
::
UNKNOWN
?
(
filename
.
ext
()
==
"stlb"
)
:
format
==
STLFormat
::
BINARY
);
}
...
...
src/fileFormats/stl/STLCore.H
View file @
3ef8906a
...
...
@@ -69,11 +69,12 @@ protected:
// Protected Member Functions
//- Detect 'stlb' extension as binary
//- Detect 'stlb' extension as binary when format = UNKNOWN.
// Otherwise test if format == BINARY.
static
bool
isBinaryName
(
const
fileName
&
filename
,
const
STLFormat
&
format
const
STLFormat
format
);
...
...
@@ -98,7 +99,7 @@ protected:
// Constructors
//- Construct null
STLCore
();
STLCore
()
=
default
;
};
...
...
src/fileFormats/stl/STLReader.C
View file @
3ef8906a
...
...
@@ -38,7 +38,7 @@ bool Foam::fileFormats::STLReader::readBINARY
)
{
sorted_
=
true
;
format_
=
UNKNOWN
;
format_
=
STLFormat
::
UNKNOWN
;
label
nTris
=
0
;
autoPtr
<
istream
>
streamPtr
=
readBinaryHeader
(
filename
,
nTris
);
...
...
@@ -125,7 +125,7 @@ bool Foam::fileFormats::STLReader::readBINARY
names_
.
clear
();
sizes_
.
transfer
(
dynSizes
);
format_
=
BINARY
;
format_
=
STLFormat
::
BINARY
;
return
true
;
}
...
...
@@ -133,10 +133,15 @@ bool Foam::fileFormats::STLReader::readBINARY
bool
Foam
::
fileFormats
::
STLReader
::
readFile
(
const
fileName
&
filename
,
const
STLFormat
&
format
const
STLFormat
format
)
{
if
(
format
==
UNKNOWN
?
detectBinaryHeader
(
filename
)
:
format
==
BINARY
)
if
(
format
==
STLFormat
::
UNKNOWN
?
detectBinaryHeader
(
filename
)
:
format
==
STLFormat
::
BINARY
)
{
return
readBINARY
(
filename
);
}
...
...
@@ -159,17 +164,17 @@ Foam::fileFormats::STLReader::STLReader
zoneIds_
(),
names_
(),
sizes_
(),
format_
(
STL
C
or
e
::
UNKNOWN
)
format_
(
STL
F
or
mat
::
UNKNOWN
)
{
// Auto-detect ASCII/BINARY format
readFile
(
filename
,
STL
C
or
e
::
UNKNOWN
);
readFile
(
filename
,
STL
F
or
mat
::
UNKNOWN
);
}