Commit 2a98c4e6 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: consistency improvements for surface patch handling (fixes #483)

- remove (unused) Istream constructors, prune some unused methods,
  rationalize write() vs writeDict().
  Deprecate inconsistent construction order.

- handle empty names for ".ftr" surface patches (for plain triSurface
  format) with double-quoted strings for more reliable streaming.
  Written on a single line.

  This is _backward_ compatible, but if users have been parsing these
  files manually, they will need to adjust their code.

Previously:
```
  (
  frt-fairing:001%1
  empty

  windshield:002%2
  empty
  ...
  )
```

Updated (with example handling of empty name):
```
  (
  frt-fairing:001%1 empty

  windshield:002%2 ""
  ...
  )
```
parent 9dbf9477
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -550,9 +550,9 @@ int main(int argc, char *argv[])
{
patches[nRegions] = geometricSurfacePatch
(
"patch",
geometry[surfaces[i]].name() + "_" + regions[regionI],
nRegions
nRegions,
"patch"
);
nRegions++;
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -262,9 +263,9 @@ int main(int argc, char *argv[])
{
patches[nRegions] = geometricSurfacePatch
(
"patch",
geometry[surfaces[i]].name() + "_" + regions[regionI],
nRegions
nRegions,
"patch"
);
nRegions++;
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -121,9 +122,9 @@ bool Foam::searchableSurfaceModifiers::autoPatch::modify
{
geometricSurfacePatch patch
(
surf.patches()[regionI].geometricType(),
surf.patches()[regionI].name() + Foam::name(subI),
surf.patches().size()
surf.patches().size(),
surf.patches()[regionI].geometricType()
);
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -73,13 +74,12 @@ void Foam::searchableSurfaceModifiers::cut::triangulate
}
}
geometricSurfacePatchList patches(fcs.size());
forAll(patches, patchI)
forAll(patches, patchi)
{
patches[patchI] = geometricSurfacePatch
patches[patchi] = geometricSurfacePatch
(
"",
"patch" + Foam::name(patchI),
patchI
"patch" + Foam::name(patchi),
patchi
);
}
cutSurf = triSurface(tris, patches, pts, true);
......@@ -345,9 +345,9 @@ bool Foam::searchableSurfaceModifiers::cut::modify
newPatches.setSize(sz+1);
newPatches[sz] = geometricSurfacePatch
(
newPatches[sz-1].geometricType(),
newPatches[sz-1].name() + "_inside",
newPatches[sz-1].index()
newPatches[sz-1].index(),
newPatches[sz-1].geometricType()
);
Info<< "Moving " << nInside << " out of " << surf3.size()
......
......@@ -588,7 +588,6 @@ DebugSwitches
generic 0;
genericPatch 0;
geomCellLooper 0;
geometricSurfacePatch 0;
global 0;
globalIndexAndTransform 0;
globalMeshData 0;
......@@ -880,7 +879,6 @@ DebugSwitches
surfaceInterpolationScheme 0;
surfaceIntersection 0;
surfaceNormalFixedValue 0;
surfacePatch 0;
surfaceScalarField 0;
surfaceScalarField::Internal 0;
surfaceSlipDisplacement 0;
......
......@@ -49,8 +49,7 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
<< exit(FatalError);
}
HashTable<labelList>::const_iterator fnd =
pbm.groupPatchIDs().find(name());
const auto fnd = pbm.groupPatchIDs().cfind(name());
if (!fnd.found())
{
......@@ -131,18 +130,6 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::coupleGroupIdentifier::coupleGroupIdentifier()
:
name_()
{}
Foam::coupleGroupIdentifier::coupleGroupIdentifier(const word& patchGroupName)
:
name_(patchGroupName)
{}
Foam::coupleGroupIdentifier::coupleGroupIdentifier(const dictionary& dict)
:
name_()
......@@ -232,7 +219,7 @@ void Foam::coupleGroupIdentifier::write(Ostream& os) const
}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const coupleGroupIdentifier& p)
{
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,12 +28,11 @@ Class
Foam::coupleGroupIdentifier
Description
Encapsulates using patchGroups to specify coupled patch
Encapsulates using "patchGroups" to specify coupled patch
SourceFiles
coupleGroupIdentifierI.H
coupleGroupIdentifier.C
coupleGroupIdentifierIO.C
\*---------------------------------------------------------------------------*/
......@@ -47,16 +47,10 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class dictionary;
class polyMesh;
class polyPatch;
class Ostream;
// Forward declaration of friend functions and operators
class coupleGroupIdentifier;
Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p);
/*---------------------------------------------------------------------------*\
Class coupleGroupIdentifier Declaration
......@@ -64,7 +58,7 @@ Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p);
class coupleGroupIdentifier
{
// Private data
// Private Data
//- Name of patchGroup
word name_;
......@@ -72,7 +66,8 @@ class coupleGroupIdentifier
// Private Member Functions
//- Find other patch in specified mesh. Returns index of patch or -1.
//- Find other patch in specified mesh.
// \return index of patch or -1
label findOtherPatchID
(
const polyMesh& mesh,
......@@ -82,16 +77,19 @@ class coupleGroupIdentifier
public:
// Constructors
// Generated Methods
//- Default construct
coupleGroupIdentifier() = default;
//- Construct null
coupleGroupIdentifier();
// Constructors
//- Construct from components
coupleGroupIdentifier(const word& patchGroupName);
inline explicit coupleGroupIdentifier(const word& patchGroupName);
//- Construct from dictionary
coupleGroupIdentifier(const dictionary& dict);
explicit coupleGroupIdentifier(const dictionary& dict);
// Member Functions
......@@ -102,29 +100,28 @@ public:
//- Is a valid patchGroup
inline bool valid() const;
//- Find other patch in same region. Returns index of patch or -1.
//- Find other patch in same region.
// \return index of patch or -1.
label findOtherPatchID(const polyPatch& thisPatch) const;
//- Find other patch and region. Returns index of patch and sets
// otherRegion to name of region. Fatal error if patch not found
//- Find other patch and region.
// Returns index of patch and sets otherRegion to name of region.
// FatalError if patch not found
label findOtherPatchID
(
const polyPatch& thisPatch,
word& otherRegion
) const;
//- Write the data as a dictionary
//- Write the coupleGroup dictionary entry
void write(Ostream& os) const;
};
// IOstream Operators
// Global Operators
friend Ostream& operator<<
(
Ostream& os,
const coupleGroupIdentifier& p
);
};
//- Write the coupleGroup dictionary entry
Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -25,7 +25,16 @@ License
\*---------------------------------------------------------------------------*/
#include "coupleGroupIdentifier.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::coupleGroupIdentifier::coupleGroupIdentifier
(
const word& patchGroupName
)
:
name_(patchGroupName)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,10 +28,27 @@ License
#include "patchIdentifier.H"
#include "dictionary.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::patchIdentifier::patchIdentifier()
:
name_(),
index_(0)
{}
Foam::patchIdentifier::patchIdentifier
(
const word& name,
const label index
)
:
name_(name),
index_(index)
{}
Foam::patchIdentifier::patchIdentifier
(
const word& name,
......@@ -53,8 +71,7 @@ Foam::patchIdentifier::patchIdentifier
const label index
)
:
name_(name),
index_(index)
patchIdentifier(name, index)
{
dict.readIfPresent("physicalType", physicalType_);
dict.readIfPresent("inGroups", inGroups_);
......@@ -76,18 +93,13 @@ Foam::patchIdentifier::patchIdentifier
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::patchIdentifier::inGroup(const word& name) const
{
return inGroups_.found(name);
}
void Foam::patchIdentifier::write(Ostream& os) const
{
if (physicalType_.size())
{
os.writeEntry("physicalType", physicalType_);
}
if (inGroups_.size())
{
os.writeKeyword("inGroups");
......@@ -97,7 +109,7 @@ void Foam::patchIdentifier::write(Ostream& os) const
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const patchIdentifier& p)
{
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -38,18 +39,14 @@ SourceFiles
#define patchIdentifier_H
#include "wordList.H"
#include "label.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
// Forward Declarations
class dictionary;
class patchIdentifier;
Ostream& operator<<(Ostream& os, const patchIdentifier& p);
/*---------------------------------------------------------------------------*\
Class patchIdentifier Declaration
......@@ -57,7 +54,7 @@ Ostream& operator<<(Ostream& os, const patchIdentifier& p);
class patchIdentifier
{
// Private data
// Private Data
//- Name of patch
word name_;
......@@ -73,14 +70,32 @@ class patchIdentifier
public:
// Generated Methods
//- Copy construct
patchIdentifier(const patchIdentifier&) = default;
//- Copy assignment
patchIdentifier& operator=(const patchIdentifier&) = default;
//- Destructor
virtual ~patchIdentifier() = default;
// Constructors
//- Default construct, with index zero
patchIdentifier();
//- Construct from mandatory components
patchIdentifier(const word& name, const label index);
//- Construct from components
patchIdentifier
(
const word& name,
const label index,
const word& physicalType = word::null,
const word& physicalType,
const wordList& inGroups = wordList()
);
......@@ -100,13 +115,9 @@ public:
);
//- Destructor
virtual ~patchIdentifier() = default;
// Member Functions
//- Return the patch name
//- The patch name
const word& name() const
{
return name_;
......@@ -118,13 +129,13 @@ public:
return name_;
}
//- The optional physical type of the patch
//- The (optional) physical type of the patch
const word& physicalType() const
{
return physicalType_;
}
//- Modifiable optional physical type of the patch
//- Modifiable (optional) physical type of the patch
word& physicalType()
{
return physicalType_;
......@@ -136,35 +147,41 @@ public:
return index_;
}
//- Modifiable the index of this patch in the boundaryMesh
//- Modifiable index of this patch in the boundaryMesh
label& index()
{
return index_;
}
//- The optional groups that the patch belongs to
//- The (optional) groups that the patch belongs to
const wordList& inGroups() const
{
return inGroups_;
}
//- Modifiable optional groups that the patch belongs to
//- Modifiable (optional) groups that the patch belongs to
wordList& inGroups()
{
return inGroups_;
}
//- Check if the patch is in named group
bool inGroup(const word& name) const;
//- True if the patch is in named group
bool inGroup(const word& name) const
{
return inGroups_.found(name);
}
//- Write patchIdentifier as a dictionary
//- Write (physicalType, inGroups) dictionary entries
//- (without surrounding braces)
void write(Ostream& os) const;
};
// Ostream Operator
// Global Operators
friend Ostream& operator<<(Ostream& os, const patchIdentifier& p);
};
//- Write (physicalType, inGroups) dictionary entries
//- (without surrounding braces)
Ostream& operator<<(Ostream& os, const patchIdentifier& p);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -29,130 +29,102 @@ License
#include "geometricSurfacePatch.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(geometricSurfacePatch, 0);
static inline word readOptionalWord(Istream& is)
{
token tok(is);
if (tok.isWord())
{
return tok.wordToken();
}
else
{
// Allow empty words
return word::validate(tok.stringToken());
}
}
const Foam::word Foam::geometricSurfacePatch::emptyType = "empty";
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::geometricSurfacePatch::geometricSurfacePatch()
:
geometricType_(emptyType),
name_("patch"),
index_(0)
geometricSurfacePatch(0)
{}
Foam::geometricSurfacePatch::geometricSurfacePatch(const label index)
:
geometricType_(emptyType),
name_("patch"),
index_(index)
index_(index),
geometricType_(emptyType)
{}
Foam::geometricSurfacePatch::geometricSurfacePatch
(
const word& name,
const label index,
const word& geometricType
const label index
)
:
geometricType_(geometricType),
name_(name),
index_(index)
{
if (geometricType_.empty())
{
geometricType_ = emptyType;
}
}
index_(index),
geometricType_()
{}
Foam::geometricSurfacePatch::geometricSurfacePatch
(
const word& geometricType,
const word& name,
const label index
const label index,
const word& geometricType
)
:
geometricType_(geometricType),
name_(name),
index_(index)