Commit 7e05548e authored by mattijs's avatar mattijs
Browse files

BUG: TimeActivatedExplicitSource : absolute source incorrect.

Also added cellZone and all as source selection mechanism.
parent 1ed3261f
......@@ -33,7 +33,7 @@ template<class Type>
const Foam::wordList Foam::TimeActivatedExplicitSource<Type>::
selectionModeTypeNames_
(
IStringStream("(points cellSet)")()
IStringStream("(points cellSet cellZone all)")()
);
......@@ -156,6 +156,15 @@ void Foam::TimeActivatedExplicitSource<Type>::setSelection
dict.lookup("cellSet") >> cellSetName_;
break;
}
case smCellZone:
{
dict.lookup("cellZone") >> cellSetName_;
break;
}
case smAll:
{
break;
}
default:
{
FatalErrorIn
......@@ -221,13 +230,14 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
{
Info<< indent << "- selecting cells using points" << endl;
labelHashSet cellOwners;
labelHashSet selectedCells;
forAll(points_, i)
{
label cellI = mesh_.findCell(points_[i]);
if (cellI >= 0)
{
cellOwners.insert(cellI);
selectedCells.insert(cellI);
}
label globalCellI = returnReduce(cellI, maxOp<label>());
......@@ -239,7 +249,7 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
}
}
cellsPtr_.reset(new cellSet(mesh_, "points", cellOwners));
cells_ = selectedCells.toc();
break;
}
......@@ -247,7 +257,32 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
{
Info<< indent << "- selecting cells using cellSet "
<< cellSetName_ << endl;
cellsPtr_.reset(new cellSet(mesh_, cellSetName_));
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("TimeActivatedExplicitSource<Type>::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;
}
......@@ -261,21 +296,20 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
}
}
const cellSet& cSet = cellsPtr_();
// Set volume normalisation
V_ = scalarField(cSet.size(), 1.0);
if (volumeMode_ == vmAbsolute)
{
label i = 0;
forAllConstIter(cellSet, cSet, iter)
V_ = 0.0;
forAll(cells_, i)
{
V_[i++] = mesh_.V()[iter.key()];
V_ += mesh_.V()[cells_[i]];
}
reduce(V_, sumOp<scalar>());
}
Info<< indent << "- selected " << returnReduce(cSet.size(), sumOp<label>())
<< " cell(s)" << nl << decrIndent << endl;
Info<< indent << "- selected "
<< returnReduce(cells_.size(), sumOp<label>())
<< " cell(s) with volume " << V_ << nl << decrIndent << endl;
}
......@@ -299,8 +333,7 @@ Foam::TimeActivatedExplicitSource<Type>::TimeActivatedExplicitSource
selectionMode_(wordToSelectionModeType(dict.lookup("selectionMode"))),
points_(),
cellSetName_("none"),
V_(),
cellsPtr_(),
V_(1.0),
fieldData_(),
fieldIds_(fieldNames.size(), -1)
{
......@@ -345,12 +378,9 @@ void Foam::TimeActivatedExplicitSource<Type>::addToField
setCellSet();
}
const cellSet& cSet = cellsPtr_();
label i = 0;
forAllConstIter(cellSet, cSet, iter)
forAll(cells_, i)
{
Su[iter.key()] = fieldData_[fid].second()/V_[i++];
Su[cells_[i]] = fieldData_[fid].second()/V_;
}
}
}
......
......@@ -33,7 +33,7 @@ Description
active true; // on/off switch
timeStart 0.2; // start time
duration 2.0; // duration
selectionMode points; // cellSet
selectionMode points; // cellSet/cellZone/all
volumeMode absolute; // specific
fieldData // field data - usage for multiple fields
......@@ -48,7 +48,8 @@ Description
(2.75 0.5 0)
);
cellSet c0; // cellSet name when selectionMode = cekllSet
cellSet c0; // cellSet name when selectionMode=cellSet
cellZone c0; // cellZone name when selectionMode=cellZone
}
SourceFiles
......@@ -100,7 +101,9 @@ public:
enum selectionModeType
{
smPoints,
smCellSet
smCellSet,
smCellZone,
smAll
};
//- Word list of selection mode type names
......@@ -147,14 +150,14 @@ protected:
//- List of points for "points" selectionMode
List<point> points_;
//- Name of cell set for "cellSet" selectionMode
//- Name of cell set for "cellSet" and "cellZone" selectionMode
word cellSetName_;
//- Field of cell volumes according to cell set cells
scalarList V_;
//- Set of cells to apply source to
labelList cells_;
//- Cell set
autoPtr<cellSet> cellsPtr_;
//- Sum of cell volumes
scalar V_;
//- List of source field name vs value pairs
List<fieldNameValuePair> fieldData_;
......@@ -288,12 +291,11 @@ public:
// selectionMode
inline const word& cellSetName() const;
//- Return const access to the field of cell volumes according to
// cell set cells
inline const scalarList& V() const;
//- Return const access to the total cell volume
inline scalar V() const;
//- Return const access to the cell set
inline const cellSet& cells() const;
inline const labelList& cells() const;
//- Return const access to the source field name vs value pairs
inline const List<fieldNameValuePair>& fieldData() const;
......@@ -330,12 +332,11 @@ public:
// selectionMode
inline word& cellSetName();
//- Return access to the field of cell volumes according to
// cell set cells
inline scalarList& V();
//- Return access to the total cell volume
inline scalar& V();
//- Return access to the cell set
inline cellSet& cells();
inline labelList& cells();
//- Return access to the source field name vs value pairs
inline List<fieldNameValuePair>& fieldData();
......
......@@ -103,18 +103,17 @@ Foam::TimeActivatedExplicitSource<Type>::cellSetName() const
template<class Type>
inline const Foam::scalarList&
Foam::TimeActivatedExplicitSource<Type>::V() const
inline Foam::scalar Foam::TimeActivatedExplicitSource<Type>::V() const
{
return V_;
}
template<class Type>
inline const Foam::cellSet&
inline const Foam::labelList&
Foam::TimeActivatedExplicitSource<Type>::cells() const
{
return cellsPtr_();
return cells_;
}
......@@ -195,16 +194,16 @@ inline Foam::word& Foam::TimeActivatedExplicitSource<Type>::cellSetName()
template<class Type>
inline Foam::scalarList& Foam::TimeActivatedExplicitSource<Type>::V()
inline Foam::scalar& Foam::TimeActivatedExplicitSource<Type>::V()
{
return V_;
}
template<class Type>
inline Foam::cellSet& Foam::TimeActivatedExplicitSource<Type>::cells()
inline Foam::labelList& Foam::TimeActivatedExplicitSource<Type>::cells()
{
return cellsPtr_();
return cells_;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment