ENH: add cellSet support for volRegion (#1106)

This commit is contained in:
Mark Olesen
2018-12-04 13:22:59 +01:00
parent cacbcd98d9
commit d842118994
2 changed files with 74 additions and 37 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,6 +25,7 @@ License
#include "volRegion.H" #include "volRegion.H"
#include "volMesh.H" #include "volMesh.H"
#include "cellSet.H"
#include "globalMeshData.H" #include "globalMeshData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -44,8 +45,9 @@ const Foam::Enum
> >
Foam::functionObjects::volRegion::regionTypeNames_ Foam::functionObjects::volRegion::regionTypeNames_
({ ({
{ regionTypes::vrtCellZone, "cellZone" },
{ regionTypes::vrtAll, "all" }, { regionTypes::vrtAll, "all" },
{ regionTypes::vrtCellSet, "cellSet" },
{ regionTypes::vrtCellZone, "cellZone" },
}); });
@ -73,7 +75,7 @@ Foam::functionObjects::volRegion::volRegion
const dictionary& dict const dictionary& dict
) )
: :
mesh_(mesh), volMesh_(mesh),
regionType_ regionType_
( (
regionTypeNames_.lookupOrDefault regionTypeNames_.lookupOrDefault
@ -83,7 +85,7 @@ Foam::functionObjects::volRegion::volRegion
regionTypes::vrtAll regionTypes::vrtAll
) )
), ),
regionName_(polyMesh::defaultRegion), regionName_(volMesh_.name()),
regionID_(-1) regionID_(-1)
{ {
read(dict); read(dict);
@ -94,12 +96,6 @@ Foam::functionObjects::volRegion::volRegion
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::volRegion::~volRegion()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::volRegion::read bool Foam::functionObjects::volRegion::read
@ -107,19 +103,41 @@ bool Foam::functionObjects::volRegion::read
const dictionary& dict const dictionary& dict
) )
{ {
regionID_ = -1;
cellIds_.clear();
switch (regionType_) switch (regionType_)
{ {
case vrtCellSet:
{
dict.readEntry("name", regionName_);
cellIds_ = cellSet(volMesh_, regionName_).sortedToc();
if (nCells() == 0)
{
FatalIOErrorInFunction(dict)
<< regionTypeNames_[regionType_]
<< "(" << regionName_ << "):" << nl
<< " Region has no cells"
<< exit(FatalIOError);
}
break;
}
case vrtCellZone: case vrtCellZone:
{ {
dict.readEntry("name", regionName_); dict.readEntry("name", regionName_);
regionID_ = mesh_.cellZones().findZoneID(regionName_); regionID_ = volMesh_.cellZones().findZoneID(regionName_);
if (regionID_ < 0) if (regionID_ < 0)
{ {
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)
<< "Unknown cell zone name: " << regionName_ << "Unknown cell zone name: " << regionName_
<< ". Valid cell zones are: " << mesh_.cellZones().names() << ". Valid cell zones : "
<< flatOutput(volMesh_.cellZones().names())
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -137,6 +155,7 @@ bool Foam::functionObjects::volRegion::read
case vrtAll: case vrtAll:
{ {
regionName_= volMesh_.name();
break; break;
} }
@ -144,7 +163,7 @@ bool Foam::functionObjects::volRegion::read
{ {
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)
<< "Unknown region type. Valid region types are:" << "Unknown region type. Valid region types are:"
<< regionTypeNames_.sortedToc() << flatOutput(regionTypeNames_.names()) << nl
<< exit(FatalIOError); << exit(FatalIOError);
} }
} }
@ -155,14 +174,21 @@ bool Foam::functionObjects::volRegion::read
const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
{ {
if (regionType_ == vrtAll) switch (regionType_)
{ {
case vrtCellSet:
return cellIds_;
break;
case vrtCellZone:
return volMesh_.cellZones()[regionID_];
break;
default:
break;
}
return labelList::null(); return labelList::null();
}
else
{
return mesh_.cellZones()[regionID_];
}
} }
@ -170,7 +196,7 @@ Foam::label Foam::functionObjects::volRegion::nCells() const
{ {
if (regionType_ == vrtAll) if (regionType_ == vrtAll)
{ {
return mesh_.globalData().nTotalCells(); return volMesh_.globalData().nTotalCells();
} }
else else
{ {
@ -183,11 +209,17 @@ Foam::scalar Foam::functionObjects::volRegion::V() const
{ {
if (regionType_ == vrtAll) if (regionType_ == vrtAll)
{ {
return gSum(mesh_.V()); return gSum(volMesh_.V());
} }
else else
{ {
return gSum(scalarField(mesh_.V(), cellIDs())); scalar vol = 0;
for (const label celli : cellIDs())
{
vol += volMesh_.V()[celli];
}
return returnReduce(vol, sumOp<scalar>());
} }
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -54,9 +54,9 @@ Description
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default
regionType | cellZone or all | no | all regionType | Selection type: all/cellSet/cellZone | no | all
name | Name of cellZone if required | no | name | Name of cellSet/cellZone if required | no |
\endtable \endtable
See also See also
@ -78,7 +78,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class fvMesh; class fvMesh;
namespace functionObjects namespace functionObjects
@ -90,12 +90,16 @@ namespace functionObjects
class volRegion class volRegion
{ {
// Private member data // Private Member Data
const fvMesh& mesh_; const fvMesh& volMesh_;
//- The cell ids, from cellSet
labelList cellIds_;
// Cache integral properties of the region for writeFileHeader // Cache integral properties of the region for writeFileHeader
label nCells_; label nCells_;
scalar V_; scalar V_;
@ -106,8 +110,9 @@ public:
//- Region type enumeration //- Region type enumeration
enum regionTypes enum regionTypes
{ {
vrtCellZone, //!< cell zone vrtAll, //!< All cells
vrtAll //!< all cells vrtCellSet, //!< A cellSet
vrtCellZone //!< A cellZone
}; };
//- Region type names //- Region type names
@ -116,15 +121,15 @@ public:
protected: protected:
// Protected data // Protected Data
//- Region type //- Region type
regionTypes regionType_; regionTypes regionType_;
//- Region name (patch, zone, etc.) //- Region name (cellSet, cellZone, ...)
word regionName_; word regionName_;
//- Region ID (patch ID, zone ID, etc.) //- Region ID (zone ID, ...)
label regionID_; label regionID_;
@ -147,13 +152,13 @@ public:
//- Destructor //- Destructor
virtual ~volRegion(); virtual ~volRegion() = default;
// Public Member Functions // Public Member Functions
//- Read from dictionary //- Read from dictionary
bool read(const dictionary&); bool read(const dictionary& dict);
//- Return the region type //- Return the region type
inline const regionTypes& regionType() const; inline const regionTypes& regionType() const;
@ -161,7 +166,7 @@ public:
//- Return the local list of cell IDs //- Return the local list of cell IDs
const labelList& cellIDs() const; const labelList& cellIDs() const;
//- Return the number of cells in the region //- Return the number of cells selected in the region
label nCells() const; label nCells() const;
//- Return total volume of the region //- Return total volume of the region