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