mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add updateMesh(), movePoints() to volRegion
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -51,6 +51,67 @@ Foam::functionObjects::volRegion::regionTypeNames_
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::volRegion::calculateCache()
|
||||
{
|
||||
regionID_ = -1;
|
||||
cellIds_.clear();
|
||||
|
||||
switch (regionType_)
|
||||
{
|
||||
case vrtAll:
|
||||
{
|
||||
nCells_ = volMesh_.globalData().nTotalCells();
|
||||
V_ = gSum(volMesh_.V());
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
case vrtCellSet:
|
||||
{
|
||||
cellIds_ = cellSet(volMesh_, regionName_).sortedToc();
|
||||
break;
|
||||
}
|
||||
|
||||
case vrtCellZone:
|
||||
{
|
||||
regionID_ = volMesh_.cellZones().findZoneID(regionName_);
|
||||
|
||||
if (regionID_ < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown cell zone name: " << regionName_
|
||||
<< ". Valid cell zones : "
|
||||
<< flatOutput(volMesh_.cellZones().names())
|
||||
<< exit(FatalError);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cached value for nCells()
|
||||
nCells_ = returnReduce(cellIDs().size(), sumOp<label>());
|
||||
|
||||
// Cached value for V()
|
||||
V_ = 0;
|
||||
for (const label celli : cellIDs())
|
||||
{
|
||||
V_ += volMesh_.V()[celli];
|
||||
}
|
||||
reduce(V_, sumOp<scalar>());
|
||||
|
||||
if (!nCells_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< regionTypeNames_[regionType_]
|
||||
<< "(" << regionName_ << "):" << nl
|
||||
<< " Region has no cells"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::volRegion::writeFileHeader
|
||||
@ -76,6 +137,9 @@ Foam::functionObjects::volRegion::volRegion
|
||||
)
|
||||
:
|
||||
volMesh_(mesh),
|
||||
cellIds_(),
|
||||
nCells_(0),
|
||||
V_(Zero),
|
||||
regionType_
|
||||
(
|
||||
regionTypeNames_.lookupOrDefault
|
||||
@ -89,10 +153,6 @@ Foam::functionObjects::volRegion::volRegion
|
||||
regionID_(-1)
|
||||
{
|
||||
read(dict);
|
||||
|
||||
// Cache integral properties of the region for writeFileHeader
|
||||
nCells_ = nCells();
|
||||
V_ = V();
|
||||
}
|
||||
|
||||
|
||||
@ -103,59 +163,18 @@ bool Foam::functionObjects::volRegion::read
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
regionID_ = -1;
|
||||
cellIds_.clear();
|
||||
|
||||
switch (regionType_)
|
||||
{
|
||||
case vrtCellSet:
|
||||
case vrtAll:
|
||||
{
|
||||
dict.readEntry("name", regionName_);
|
||||
|
||||
cellIds_ = cellSet(volMesh_, regionName_).sortedToc();
|
||||
|
||||
if (nCells() == 0)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< regionTypeNames_[regionType_]
|
||||
<< "(" << regionName_ << "):" << nl
|
||||
<< " Region has no cells"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
regionName_ = volMesh_.name();
|
||||
break;
|
||||
}
|
||||
|
||||
case vrtCellSet:
|
||||
case vrtCellZone:
|
||||
{
|
||||
dict.readEntry("name", regionName_);
|
||||
|
||||
regionID_ = volMesh_.cellZones().findZoneID(regionName_);
|
||||
|
||||
if (regionID_ < 0)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Unknown cell zone name: " << regionName_
|
||||
<< ". Valid cell zones : "
|
||||
<< flatOutput(volMesh_.cellZones().names())
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
if (nCells() == 0)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< regionTypeNames_[regionType_]
|
||||
<< "(" << regionName_ << "):" << nl
|
||||
<< " Region has no cells"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case vrtAll:
|
||||
{
|
||||
regionName_= volMesh_.name();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -165,9 +184,11 @@ bool Foam::functionObjects::volRegion::read
|
||||
<< "Unknown region type. Valid region types are:"
|
||||
<< flatOutput(regionTypeNames_.names()) << nl
|
||||
<< exit(FatalIOError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
calculateCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -192,35 +213,15 @@ const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjects::volRegion::nCells() const
|
||||
void Foam::functionObjects::volRegion::updateMesh(const mapPolyMesh&)
|
||||
{
|
||||
if (regionType_ == vrtAll)
|
||||
{
|
||||
return volMesh_.globalData().nTotalCells();
|
||||
}
|
||||
else
|
||||
{
|
||||
return returnReduce(cellIDs().size(), sumOp<label>());
|
||||
}
|
||||
calculateCache();
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjects::volRegion::V() const
|
||||
void Foam::functionObjects::volRegion::movePoints(const polyMesh&)
|
||||
{
|
||||
if (regionType_ == vrtAll)
|
||||
{
|
||||
return gSum(volMesh_.V());
|
||||
}
|
||||
else
|
||||
{
|
||||
scalar vol = 0;
|
||||
for (const label celli : cellIDs())
|
||||
{
|
||||
vol += volMesh_.V()[celli];
|
||||
}
|
||||
|
||||
return returnReduce(vol, sumOp<scalar>());
|
||||
}
|
||||
calculateCache();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -80,6 +80,8 @@ namespace Foam
|
||||
|
||||
// Forward declarations
|
||||
class fvMesh;
|
||||
class polyMesh;
|
||||
class mapPolyMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
@ -97,12 +99,19 @@ class volRegion
|
||||
//- The cell ids, from cellSet
|
||||
labelList cellIds_;
|
||||
|
||||
// Cache integral properties of the region for writeFileHeader
|
||||
//- 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
|
||||
@ -155,10 +164,7 @@ public:
|
||||
virtual ~volRegion() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Read from dictionary
|
||||
bool read(const dictionary& dict);
|
||||
// Member Functions
|
||||
|
||||
//- Return the region type
|
||||
inline const regionTypes& regionType() const;
|
||||
@ -167,10 +173,20 @@ public:
|
||||
const labelList& cellIDs() const;
|
||||
|
||||
//- Return the number of cells selected in the region
|
||||
label nCells() const;
|
||||
inline label nCells() const;
|
||||
|
||||
//- Return total volume of the region
|
||||
scalar V() const;
|
||||
//- Return total volume of the selected region
|
||||
inline scalar V() const;
|
||||
|
||||
|
||||
//- Read from dictionary
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh&);
|
||||
|
||||
//- Update for mesh point-motion
|
||||
virtual void movePoints(const polyMesh&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,4 +31,17 @@ Foam::functionObjects::volRegion::regionType() const
|
||||
return regionType_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::functionObjects::volRegion::nCells() const
|
||||
{
|
||||
return nCells_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar Foam::functionObjects::volRegion::V() const
|
||||
{
|
||||
return V_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user