Skip to content
Snippets Groups Projects
Commit dc1446d6 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add updateMesh(), movePoints() to volRegion

parent 671c4107
Branches
Tags
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -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-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -51,6 +51,67 @@ Foam::functionObjects::volRegion::regionTypeNames_ ...@@ -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 * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::volRegion::writeFileHeader void Foam::functionObjects::volRegion::writeFileHeader
...@@ -76,6 +137,9 @@ Foam::functionObjects::volRegion::volRegion ...@@ -76,6 +137,9 @@ Foam::functionObjects::volRegion::volRegion
) )
: :
volMesh_(mesh), volMesh_(mesh),
cellIds_(),
nCells_(0),
V_(Zero),
regionType_ regionType_
( (
regionTypeNames_.lookupOrDefault regionTypeNames_.lookupOrDefault
...@@ -89,10 +153,6 @@ Foam::functionObjects::volRegion::volRegion ...@@ -89,10 +153,6 @@ Foam::functionObjects::volRegion::volRegion
regionID_(-1) regionID_(-1)
{ {
read(dict); read(dict);
// Cache integral properties of the region for writeFileHeader
nCells_ = nCells();
V_ = V();
} }
...@@ -103,59 +163,18 @@ bool Foam::functionObjects::volRegion::read ...@@ -103,59 +163,18 @@ bool Foam::functionObjects::volRegion::read
const dictionary& dict const dictionary& dict
) )
{ {
regionID_ = -1;
cellIds_.clear();
switch (regionType_) switch (regionType_)
{ {
case vrtCellSet: case vrtAll:
{ {
dict.readEntry("name", regionName_); regionName_ = volMesh_.name();
cellIds_ = cellSet(volMesh_, regionName_).sortedToc();
if (nCells() == 0)
{
FatalIOErrorInFunction(dict)
<< regionTypeNames_[regionType_]
<< "(" << regionName_ << "):" << nl
<< " Region has no cells"
<< exit(FatalIOError);
}
break; break;
} }
case vrtCellSet:
case vrtCellZone: case vrtCellZone:
{ {
dict.readEntry("name", regionName_); 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; break;
} }
...@@ -165,9 +184,11 @@ bool Foam::functionObjects::volRegion::read ...@@ -165,9 +184,11 @@ bool Foam::functionObjects::volRegion::read
<< "Unknown region type. Valid region types are:" << "Unknown region type. Valid region types are:"
<< flatOutput(regionTypeNames_.names()) << nl << flatOutput(regionTypeNames_.names()) << nl
<< exit(FatalIOError); << exit(FatalIOError);
break;
} }
} }
calculateCache();
return true; return true;
} }
...@@ -192,35 +213,15 @@ const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const ...@@ -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) calculateCache();
{
return volMesh_.globalData().nTotalCells();
}
else
{
return returnReduce(cellIDs().size(), sumOp<label>());
}
} }
Foam::scalar Foam::functionObjects::volRegion::V() const void Foam::functionObjects::volRegion::movePoints(const polyMesh&)
{ {
if (regionType_ == vrtAll) calculateCache();
{
return gSum(volMesh_.V());
}
else
{
scalar vol = 0;
for (const label celli : cellIDs())
{
vol += volMesh_.V()[celli];
}
return returnReduce(vol, sumOp<scalar>());
}
} }
......
...@@ -3,7 +3,7 @@ ...@@ -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-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -80,6 +80,8 @@ namespace Foam ...@@ -80,6 +80,8 @@ namespace Foam
// Forward declarations // Forward declarations
class fvMesh; class fvMesh;
class polyMesh;
class mapPolyMesh;
namespace functionObjects namespace functionObjects
{ {
...@@ -97,12 +99,19 @@ class volRegion ...@@ -97,12 +99,19 @@ class volRegion
//- The cell ids, from cellSet //- The cell ids, from cellSet
labelList cellIds_; labelList cellIds_;
// Cache integral properties of the region for writeFileHeader //- Cached total number of cells selected
label nCells_; label nCells_;
//- Cached total selection volume
scalar V_; scalar V_;
// Private Member Functions
//- Update cellIds, nCells, volume
void calculateCache();
public: public:
// Public data types // Public data types
...@@ -155,10 +164,7 @@ public: ...@@ -155,10 +164,7 @@ public:
virtual ~volRegion() = default; virtual ~volRegion() = default;
// Public Member Functions // Member Functions
//- Read from dictionary
bool read(const dictionary& dict);
//- Return the region type //- Return the region type
inline const regionTypes& regionType() const; inline const regionTypes& regionType() const;
...@@ -167,10 +173,20 @@ public: ...@@ -167,10 +173,20 @@ public:
const labelList& cellIDs() const; const labelList& cellIDs() const;
//- Return the number of cells selected in the region //- Return the number of cells selected in the region
label nCells() const; inline label nCells() 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&);
//- Return total volume of the region //- Update for mesh point-motion
scalar V() const; virtual void movePoints(const polyMesh&);
}; };
......
...@@ -3,7 +3,7 @@ ...@@ -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 | \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -31,4 +31,17 @@ Foam::functionObjects::volRegion::regionType() const ...@@ -31,4 +31,17 @@ Foam::functionObjects::volRegion::regionType() const
return regionType_; return regionType_;
} }
inline Foam::label Foam::functionObjects::volRegion::nCells() const
{
return nCells_;
}
inline Foam::scalar Foam::functionObjects::volRegion::V() const
{
return V_;
}
// ************************************************************************* // // ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment