Commit b8d15ba4 authored by Henry's avatar Henry
Browse files

fvOptions: Separate options for all cells, cellSets and inter-region coupling

by introducing rational base-classes rather than using the hideous
'switch' statement.  Further rationalization of the cell-selection
mechanism will be implemented via an appropriate class hierarchy to
replace the remaining 'switch' statement.

Mesh-motion is currently handled very inefficiently for cellSets and not
at all for inter-region coupling.  The former will be improved when the
cell-selection classes are written and the latter by making the
meshToMesh class a MeshObject after it has been corrected for mapFields.
parent 2b9a2adf
fvOptions/fvOption.C
fvOptions/fvOptionIO.C
fvOptions/fvOptionList.C
fvOptions/fvIOoptionList.C
fvOption/fvOption.C
fvOption/fvOptionIO.C
fvOption/fvOptionList.C
fvOption/fvIOoptionList.C
cellSetOption/cellSetOption.C
cellSetOption/cellSetOptionIO.C
/* sources */
interRegionOption/interRegionOption.C
interRegionOption/interRegionOptionIO.C
/* Sources */
generalSources=sources/general
$(generalSources)/codedSource/codedSource.C
......@@ -32,16 +38,17 @@ $(derivedSources)/solidificationMeltingSource/solidificationMeltingSourceIO.C
$(derivedSources)/tabulatedAccelerationSource/tabulatedAccelerationSource.C
$(derivedSources)/tabulatedAccelerationSource/tabulated6DoFAcceleration/tabulated6DoFAcceleration.C
interRegion = sources/interRegion
$(interRegion)/interRegionHeatTransferModel/constantHeatTransfer/constantHeatTransfer.C
$(interRegion)/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C
$(interRegion)/interRegionHeatTransferModel/tabulatedHeatTransfer/tabulatedHeatTransfer.C
$(interRegion)/interRegionHeatTransferModel/variableHeatTransfer/variableHeatTransfer.C
$(interRegion)/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModel.C
$(interRegion)/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModelIO.C
$(interRegion)/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.C
$(interRegion)/interRegionHeatTransfer/tabulatedHeatTransfer/tabulatedHeatTransfer.C
$(interRegion)/interRegionHeatTransfer/variableHeatTransfer/variableHeatTransfer.C
$(interRegion)/interRegionExplicitPorositySource/interRegionExplicitPorositySource.C
/* constraints */
/* Constraints */
generalConstraints=constraints/general
$(generalConstraints)/explicitSetValue/explicitSetValue.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 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 "cellSetOption.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(cellSetOption, 0);
}
template<> const char* NamedEnum
<
fv::cellSetOption::selectionModeType,
4
>::names[] =
{
"points",
"cellSet",
"cellZone",
"all"
};
const NamedEnum<fv::cellSetOption::selectionModeType, 4>
fv::cellSetOption::selectionModeTypeNames_;
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fv::cellSetOption::setSelection(const dictionary& dict)
{
switch (selectionMode_)
{
case smPoints:
{
dict.lookup("points") >> points_;
break;
}
case smCellSet:
{
dict.lookup("cellSet") >> cellSetName_;
break;
}
case smCellZone:
{
dict.lookup("cellZone") >> cellSetName_;
break;
}
case smAll:
{
break;
}
default:
{
FatalErrorIn("::setSelection(const dictionary&)")
<< "Unknown selectionMode "
<< selectionModeTypeNames_[selectionMode_]
<< ". Valid selectionMode types are" << selectionModeTypeNames_
<< exit(FatalError);
}
}
}
void Foam::fv::cellSetOption::setCellSet()
{
switch (selectionMode_)
{
case smPoints:
{
Info<< indent << "- selecting cells using points" << endl;
labelHashSet selectedCells;
forAll(points_, i)
{
label cellI = mesh_.findCell(points_[i]);
if (cellI >= 0)
{
selectedCells.insert(cellI);
}
label globalCellI = returnReduce(cellI, maxOp<label>());
if (globalCellI < 0)
{
WarningIn("cellSetOption::setCellSet()")
<< "Unable to find owner cell for point " << points_[i]
<< endl;
}
}
cells_ = selectedCells.toc();
break;
}
case smCellSet:
{
Info<< indent
<< "- selecting cells using cellSet " << cellSetName_ << endl;
cellSet selectedCells(mesh_, cellSetName_);
cells_ = selectedCells.toc();
break;
}
case smCellZone:
{
Info<< indent
<< "- selecting cells using cellZone " << cellSetName_ << endl;
label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
if (zoneID == -1)
{
FatalErrorIn("cellSetOption::setCellIds()")
<< "Cannot find cellZone " << cellSetName_ << endl
<< "Valid cellZones are " << mesh_.cellZones().names()
<< exit(FatalError);
}
cells_ = mesh_.cellZones()[zoneID];
break;
}
case smAll:
{
Info<< indent << "- selecting all cells" << endl;
cells_ = identity(mesh_.nCells());
break;
}
default:
{
FatalErrorIn("cellSetOption::setCellSet()")
<< "Unknown selectionMode "
<< selectionModeTypeNames_[selectionMode_]
<< ". Valid selectionMode types are" << selectionModeTypeNames_
<< exit(FatalError);
}
}
// Set volume information
V_ = 0.0;
forAll(cells_, i)
{
V_ += mesh_.V()[cells_[i]];
}
reduce(V_, sumOp<scalar>());
Info<< indent
<< "- selected " << returnReduce(cells_.size(), sumOp<label>())
<< " cell(s) with volume " << V_ << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::cellSetOption::cellSetOption
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
option(name, modelType, dict, mesh),
timeStart_(-1.0),
duration_(0.0),
selectionMode_
(
selectionModeTypeNames_.read(coeffs_.lookup("selectionMode"))
),
cellSetName_("none"),
V_(0.0)
{
Info<< incrIndent;
read(dict);
setSelection(coeffs_);
setCellSet();
Info<< decrIndent;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::cellSetOption::~cellSetOption()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::cellSetOption::isActive()
{
if (option::isActive() && inTimeLimits(mesh_.time().value()))
{
// Update the cell set if the mesh is changing
if (mesh_.changing())
{
setCellSet();
}
return true;
}
else
{
return false;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 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::fv::cellSetOption
Description
Cell-set options abtract base class. Provides a base set of controls,
e.g.
type scalarExplicitSource // Source type
active on; // on/off switch
scalarExplicitSourceCoeffs
{
timeStart 0.0; // Start time
duration 1000.0; // Duration
selectionMode cellSet; // cellSet, points, cellZone
.
.
.
}
Note:
Source/sink options are to be added to the equation R.H.S.
SourceFiles
cellSetOption.C
cellSetOptionIO.C
\*---------------------------------------------------------------------------*/
#ifndef cellSetOption_H
#define cellSetOption_H
#include "fvOption.H"
#include "cellSet.H"
#include "fvMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
/*---------------------------------------------------------------------------*\
Class cellSetOption Declaration
\*---------------------------------------------------------------------------*/
class cellSetOption
:
public option
{
public:
// Public data
//- Enumeration for selection mode types
enum selectionModeType
{
smPoints,
smCellSet,
smCellZone,
smAll
};
//- Word list of selection mode type names
static const NamedEnum<selectionModeType, 4>
selectionModeTypeNames_;
protected:
// Protected data
//- Time start
scalar timeStart_;
//- Duration
scalar duration_;
//- Cell selection mode
selectionModeType selectionMode_;
//- Name of cell set for "cellSet" and "cellZone" selectionMode
word cellSetName_;
//- List of points for "points" selectionMode
List<point> points_;
//- Set of cells to apply source to
labelList cells_;
//- Sum of cell volumes
scalar V_;
// Protected functions
//- Set the cellSet or points selection
void setSelection(const dictionary& dict);
//- Set the cell set based on the user input selection mode
void setCellSet();
public:
//- Runtime type information
TypeName("cellSetOption");
// Constructors
//- Construct from components
cellSetOption
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
);
//- Destructor
virtual ~cellSetOption();
// Member Functions
// Access
//- Return const access to the time start
inline scalar timeStart() const;
//- Return const access to the duration
inline scalar duration() const;
//- Return true if within time limits
inline bool inTimeLimits(const scalar time) const;
//- Return const access to the cell selection mode
inline const selectionModeType& selectionMode() const;
//- Return const access to the name of cell set for "cellSet"
// selectionMode
inline const word& cellSetName() const;
//- Return const access to the total cell volume
inline scalar V() const;
//- Return const access to the cell set
inline const labelList& cells() const;
// Edit
//- Return access to the time start
inline scalar& timeStart();
//- Return access to the duration
inline scalar& duration();
// Checks
//- Is the source active?
virtual bool isActive();
// I-O
//- Write the source header information
virtual void writeHeader(Ostream&) const;
//- Write the source footer information
virtual void writeFooter(Ostream&) const;
//- Write the source properties
virtual void writeData(Ostream&) const;
//- Read source dictionary
virtual bool read(const dictionary& dict);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fv
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "cellSetOptionI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 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 Foam::scalar Foam::fv::cellSetOption::timeStart() const
{
return timeStart_;
}
inline Foam::scalar Foam::fv::cellSetOption::duration() const
{
return duration_;
}
inline bool Foam::fv::cellSetOption::inTimeLimits(const scalar time) const
{
return
(
(timeStart_ < 0)
||
(
(mesh_.time().value() >= timeStart_)
&& (mesh_.time().value() <= (timeStart_ + duration_))
)
);
}
inline const Foam::fv::cellSetOption::selectionModeType&
Foam::fv::cellSetOption::selectionMode() const
{
return selectionMode_;
}
inline const Foam::word& Foam::fv::cellSetOption::cellSetName() const
{
return cellSetName_;
}
inline Foam::scalar Foam::fv::cellSetOption::V() const
{
return V_;
}
inline const Foam::labelList& Foam::fv::cellSetOption::cells() const
{
return cells_;
}
inline Foam::scalar& Foam::fv::cellSetOption::timeStart()
{
return timeStart_;
}
inline Foam::scalar& Foam::fv::cellSetOption::duration()
{
return duration_;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -23,26 +23,27 @@ License
\*---------------------------------------------------------------------------*/
#include "fvOption.H"
#include "cellSetOption.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fv::option::writeHeader(Ostream& os) const
void Foam::fv::cellSetOption::writeHeader(Ostream& os) const
{
os << indent << name_ << nl
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
}