mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
functionObjects::volRegion: General base-class to handle vol (cell) region processing
Renamed the original volRegion -> volFieldValue to clarify the purpose of this class to process vol fields on a volRegion.
This commit is contained in:
@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "Time.H"
|
||||
#include "fvMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(fvMeshFunctionObject, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
regionFunctionObject(name, runTime, dict),
|
||||
mesh_(refCast<const fvMesh>(obr_))
|
||||
{}
|
||||
|
||||
|
||||
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
regionFunctionObject(name, obr, dict),
|
||||
mesh_(refCast<const fvMesh>(obr_))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fvMeshFunctionObject::~fvMeshFunctionObject()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,126 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
|
||||
Description
|
||||
Specialization of Foam::functionObject for an Foam::fvMesh, providing a
|
||||
reference to the Foam::fvMesh.
|
||||
|
||||
If the selected region is not an Foam::fvMesh a Foam::FatalError will be
|
||||
generated.
|
||||
|
||||
See also
|
||||
Foam::regionFunctionObject
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
fvMeshFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fvMeshFunctionObject_H
|
||||
#define functionObjects_fvMeshFunctionObject_H
|
||||
|
||||
#include "regionFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class fvMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fvMeshFunctionObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fvMeshFunctionObject
|
||||
:
|
||||
public regionFunctionObject
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected member data
|
||||
|
||||
//- Reference to the fvMesh
|
||||
const fvMesh& mesh_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
fvMeshFunctionObject(const fvMeshFunctionObject&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const fvMeshFunctionObject&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("fvMeshFunctionObject");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
fvMeshFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct from the region objectRegistry and dictionary
|
||||
fvMeshFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fvMeshFunctionObject();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
189
src/finiteVolume/functionObjects/volRegion/volRegion.C
Normal file
189
src/finiteVolume/functionObjects/volRegion/volRegion.C
Normal file
@ -0,0 +1,189 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "volRegion.H"
|
||||
#include "volMesh.H"
|
||||
#include "globalMeshData.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(volRegion, 0);
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char*
|
||||
Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::volRegion::regionTypes,
|
||||
2
|
||||
>::names[] = {"cellZone", "all"};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::volRegion::regionTypes,
|
||||
2
|
||||
> Foam::functionObjects::volRegion::regionTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::volRegion::writeFileHeader
|
||||
(
|
||||
const writeFile& wf,
|
||||
Ostream& file
|
||||
)
|
||||
{
|
||||
wf.writeCommented(file, "Region : ");
|
||||
file << regionTypeNames_[regionType_] << " " << regionName_ << endl;
|
||||
wf.writeHeaderValue(file, "Cells", nCells());
|
||||
wf.writeHeaderValue(file, "Volume", V());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::volRegion::volRegion
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
mesh_(mesh),
|
||||
regionType_
|
||||
(
|
||||
dict.found("regionType")
|
||||
? regionTypeNames_.read(dict.lookup("regionType"))
|
||||
: vrtAll
|
||||
),
|
||||
regionID_(-1)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::volRegion::~volRegion()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::volRegion::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
switch (regionType_)
|
||||
{
|
||||
case vrtCellZone:
|
||||
{
|
||||
dict.lookup("name") >> regionName_;
|
||||
|
||||
regionID_ = mesh_.cellZones().findZoneID(regionName_);
|
||||
|
||||
if (regionID_ < 0)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Unknown cell zone name: " << regionName_
|
||||
<< ". Valid cell zones are: " << mesh_.cellZones().names()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
if (nCells() == 0)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< regionTypeNames_[regionType_]
|
||||
<< "(" << regionName_ << "):" << nl
|
||||
<< " Region has no cells"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case vrtAll:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Unknown region type. Valid region types are:"
|
||||
<< regionTypeNames_
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
|
||||
{
|
||||
if (regionType_ == vrtAll)
|
||||
{
|
||||
return labelList::null();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mesh_.cellZones()[regionID_];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjects::volRegion::nCells() const
|
||||
{
|
||||
if (regionType_ == vrtAll)
|
||||
{
|
||||
return mesh_.globalData().nTotalCells();
|
||||
}
|
||||
else
|
||||
{
|
||||
return returnReduce(cellIDs().size(), sumOp<label>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjects::volRegion::V() const
|
||||
{
|
||||
if (regionType_ == vrtAll)
|
||||
{
|
||||
return gSum(mesh_.V());
|
||||
}
|
||||
else
|
||||
{
|
||||
return gSum(scalarField(mesh_.V(), cellIDs()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
185
src/finiteVolume/functionObjects/volRegion/volRegion.H
Normal file
185
src/finiteVolume/functionObjects/volRegion/volRegion.H
Normal file
@ -0,0 +1,185 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::volRegion
|
||||
|
||||
Group
|
||||
grpFieldFunctionObjects
|
||||
|
||||
Description
|
||||
Volume (cell) region selection class.
|
||||
|
||||
Examples of function object specification:
|
||||
\verbatim
|
||||
volRegion0
|
||||
{
|
||||
.
|
||||
.
|
||||
regionType cellZone;
|
||||
name c0;
|
||||
.
|
||||
.
|
||||
}
|
||||
|
||||
volRegionAll
|
||||
{
|
||||
.
|
||||
.
|
||||
regionType all;
|
||||
.
|
||||
.
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
regionType | cellZone or all | no | all
|
||||
name | Name of cellZone if required | no |
|
||||
\endtable
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
volRegion.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_volRegion_H
|
||||
#define functionObjects_volRegion_H
|
||||
|
||||
#include "writeFile.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class fvMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class volRegion Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class volRegion
|
||||
{
|
||||
// Private member data
|
||||
|
||||
const fvMesh& mesh_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
//- Region type enumeration
|
||||
enum regionTypes
|
||||
{
|
||||
vrtCellZone,
|
||||
vrtAll
|
||||
};
|
||||
|
||||
//- Region type names
|
||||
static const NamedEnum<regionTypes, 2> regionTypeNames_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Region type
|
||||
regionTypes regionType_;
|
||||
|
||||
//- Region name (patch, zone, etc.)
|
||||
word regionName_;
|
||||
|
||||
//- Region ID (patch ID, zone ID, etc.)
|
||||
label regionID_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Output file header information
|
||||
void writeFileHeader(const writeFile& wf, Ostream& file);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("volRegion");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from fvMesh and dictionary
|
||||
volRegion
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~volRegion();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Read from dictionary
|
||||
bool read(const dictionary&);
|
||||
|
||||
//- Return the region type
|
||||
inline const regionTypes& regionType() const;
|
||||
|
||||
//- Return the local list of cell IDs
|
||||
const labelList& cellIDs() const;
|
||||
|
||||
//- Return the number of cells in the region
|
||||
label nCells() const;
|
||||
|
||||
//- Return total volume of the region
|
||||
scalar V() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "volRegionI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
34
src/finiteVolume/functionObjects/volRegion/volRegionI.H
Normal file
34
src/finiteVolume/functionObjects/volRegion/volRegionI.H
Normal file
@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::functionObjects::volRegion::regionTypes&
|
||||
Foam::functionObjects::volRegion::regionType() const
|
||||
{
|
||||
return regionType_;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user