mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support zone group selection for volRegion function objects
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -58,8 +58,8 @@ Foam::functionObjects::volRegion::regionTypeNames_
|
||||
|
||||
void Foam::functionObjects::volRegion::calculateCache()
|
||||
{
|
||||
regionID_ = -1;
|
||||
cellIds_.clear();
|
||||
regionIDs_.clear();
|
||||
|
||||
// Update now. Need a valid state for the cellIDs() call
|
||||
requireUpdate_ = false;
|
||||
@ -82,16 +82,24 @@ void Foam::functionObjects::volRegion::calculateCache()
|
||||
|
||||
case vrtCellZone:
|
||||
{
|
||||
regionID_ = volMesh_.cellZones().findZoneID(regionName_);
|
||||
regionIDs_ = volMesh_.cellZones().indices(regionName_);
|
||||
|
||||
if (regionID_ < 0)
|
||||
if (regionIDs_.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown cell zone name: " << regionName_
|
||||
<< ". Valid cell zones : "
|
||||
<< flatOutput(volMesh_.cellZones().names())
|
||||
<< "Unknown cell zone: " << regionName_ << nl
|
||||
<< " Valid zones : "
|
||||
<< flatOutput(volMesh_.cellZones().names()) << nl
|
||||
<< " Valid groups: "
|
||||
<< flatOutput(volMesh_.cellZones().groupNames()) << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (regionIDs_.size() > 1)
|
||||
{
|
||||
cellIds_ =
|
||||
volMesh_.cellZones().selected(regionIDs_).sortedToc();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -100,14 +108,13 @@ void Foam::functionObjects::volRegion::calculateCache()
|
||||
// Calculate cache value for nCells() and V()
|
||||
const labelList& selected = this->cellIDs();
|
||||
|
||||
nCells_ = selected.size();
|
||||
V_ = 0;
|
||||
for (const label celli : selected)
|
||||
{
|
||||
V_ += volMesh_.V()[celli];
|
||||
}
|
||||
|
||||
reduce(nCells_, sumOp<label>());
|
||||
nCells_ = returnReduce(selected.size(), sumOp<label>();
|
||||
reduce(V_, sumOp<scalar>());
|
||||
|
||||
if (!nCells_)
|
||||
@ -146,10 +153,11 @@ Foam::functionObjects::volRegion::volRegion
|
||||
)
|
||||
:
|
||||
volMesh_(mesh),
|
||||
requireUpdate_(true),
|
||||
cellIds_(),
|
||||
regionIDs_(),
|
||||
nCells_(0),
|
||||
V_(Zero),
|
||||
requireUpdate_(true),
|
||||
regionType_
|
||||
(
|
||||
regionTypeNames_.getOrDefault
|
||||
@ -159,8 +167,7 @@ Foam::functionObjects::volRegion::volRegion
|
||||
regionTypes::vrtAll
|
||||
)
|
||||
),
|
||||
regionName_(volMesh_.name()),
|
||||
regionID_(-1)
|
||||
regionName_(volMesh_.name());
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -214,12 +221,23 @@ const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
|
||||
switch (regionType_)
|
||||
{
|
||||
case vrtCellSet:
|
||||
{
|
||||
return cellIds_;
|
||||
break;
|
||||
}
|
||||
|
||||
case vrtCellZone:
|
||||
return volMesh_.cellZones()[regionID_];
|
||||
{
|
||||
if (regionIDs_.size() == 1)
|
||||
{
|
||||
return volMesh_.cellZones()[regionIDs_.first()];
|
||||
}
|
||||
else
|
||||
{
|
||||
return cellIds_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -75,8 +75,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_volRegion_H
|
||||
#define functionObjects_volRegion_H
|
||||
#ifndef Foam_functionObjects_volRegion_H
|
||||
#define Foam_functionObjects_volRegion_H
|
||||
|
||||
#include "writeFile.H"
|
||||
#include "Enum.H"
|
||||
@ -100,35 +100,12 @@ namespace functionObjects
|
||||
|
||||
class volRegion
|
||||
{
|
||||
// Private Member Data
|
||||
|
||||
const fvMesh& volMesh_;
|
||||
|
||||
//- Flag to indicate whether the volRegion requires updating
|
||||
bool requireUpdate_;
|
||||
|
||||
//- The cell ids, from cellSet
|
||||
labelList cellIds_;
|
||||
|
||||
//- Cached total number of cells selected
|
||||
label nCells_;
|
||||
|
||||
//- Cached total selection volume
|
||||
scalar V_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Update cellIds, nCells, volume
|
||||
void calculateCache();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
// Public Data Types
|
||||
|
||||
//- Region type enumeration
|
||||
enum regionTypes
|
||||
enum regionTypes : char
|
||||
{
|
||||
vrtAll = 0, //!< All cells
|
||||
vrtCellSet, //!< A cellSet
|
||||
@ -139,6 +116,35 @@ public:
|
||||
static const Enum<regionTypes> regionTypeNames_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Data
|
||||
|
||||
//- Reference to the volume mesh
|
||||
const fvMesh& volMesh_;
|
||||
|
||||
//- The cell ids, from cellSet or multiple cell zones
|
||||
labelList cellIds_;
|
||||
|
||||
//- Region IDs (zone ID, ...)
|
||||
labelList regionIDs_;
|
||||
|
||||
//- Cached total number of cells selected
|
||||
label nCells_;
|
||||
|
||||
//- Cached total selection volume
|
||||
scalar V_;
|
||||
|
||||
//- Flag to indicate whether the volRegion requires updating
|
||||
bool requireUpdate_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Update cellIds, nCells, volume
|
||||
void calculateCache();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
@ -147,10 +153,7 @@ protected:
|
||||
regionTypes regionType_;
|
||||
|
||||
//- Region name (cellSet, cellZone, ...)
|
||||
word regionName_;
|
||||
|
||||
//- Region ID (zone ID, ...)
|
||||
label regionID_;
|
||||
wordRe regionName_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
Reference in New Issue
Block a user