BUG: TimeActivatedExplicitSource : absolute source incorrect.

Also added cellZone and all as source selection mechanism.
This commit is contained in:
mattijs
2010-05-14 17:55:23 +01:00
parent 1ed3261f33
commit 7e05548ec0
3 changed files with 73 additions and 43 deletions

View File

@ -33,7 +33,7 @@ template<class Type>
const Foam::wordList Foam::TimeActivatedExplicitSource<Type>:: const Foam::wordList Foam::TimeActivatedExplicitSource<Type>::
selectionModeTypeNames_ selectionModeTypeNames_
( (
IStringStream("(points cellSet)")() IStringStream("(points cellSet cellZone all)")()
); );
@ -156,6 +156,15 @@ void Foam::TimeActivatedExplicitSource<Type>::setSelection
dict.lookup("cellSet") >> cellSetName_; dict.lookup("cellSet") >> cellSetName_;
break; break;
} }
case smCellZone:
{
dict.lookup("cellZone") >> cellSetName_;
break;
}
case smAll:
{
break;
}
default: default:
{ {
FatalErrorIn FatalErrorIn
@ -221,13 +230,14 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
{ {
Info<< indent << "- selecting cells using points" << endl; Info<< indent << "- selecting cells using points" << endl;
labelHashSet cellOwners; labelHashSet selectedCells;
forAll(points_, i) forAll(points_, i)
{ {
label cellI = mesh_.findCell(points_[i]); label cellI = mesh_.findCell(points_[i]);
if (cellI >= 0) if (cellI >= 0)
{ {
cellOwners.insert(cellI); selectedCells.insert(cellI);
} }
label globalCellI = returnReduce(cellI, maxOp<label>()); 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; break;
} }
@ -247,7 +257,32 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
{ {
Info<< indent << "- selecting cells using cellSet " Info<< indent << "- selecting cells using cellSet "
<< cellSetName_ << endl; << 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; break;
} }
@ -261,21 +296,20 @@ void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
} }
} }
const cellSet& cSet = cellsPtr_();
// Set volume normalisation // Set volume normalisation
V_ = scalarField(cSet.size(), 1.0);
if (volumeMode_ == vmAbsolute) if (volumeMode_ == vmAbsolute)
{ {
label i = 0; V_ = 0.0;
forAllConstIter(cellSet, cSet, iter) 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>()) Info<< indent << "- selected "
<< " cell(s)" << nl << decrIndent << endl; << 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"))), selectionMode_(wordToSelectionModeType(dict.lookup("selectionMode"))),
points_(), points_(),
cellSetName_("none"), cellSetName_("none"),
V_(), V_(1.0),
cellsPtr_(),
fieldData_(), fieldData_(),
fieldIds_(fieldNames.size(), -1) fieldIds_(fieldNames.size(), -1)
{ {
@ -345,12 +378,9 @@ void Foam::TimeActivatedExplicitSource<Type>::addToField
setCellSet(); setCellSet();
} }
const cellSet& cSet = cellsPtr_(); forAll(cells_, i)
label i = 0;
forAllConstIter(cellSet, cSet, iter)
{ {
Su[iter.key()] = fieldData_[fid].second()/V_[i++]; Su[cells_[i]] = fieldData_[fid].second()/V_;
} }
} }
} }

View File

@ -33,7 +33,7 @@ Description
active true; // on/off switch active true; // on/off switch
timeStart 0.2; // start time timeStart 0.2; // start time
duration 2.0; // duration duration 2.0; // duration
selectionMode points; // cellSet selectionMode points; // cellSet/cellZone/all
volumeMode absolute; // specific volumeMode absolute; // specific
fieldData // field data - usage for multiple fields fieldData // field data - usage for multiple fields
@ -48,7 +48,8 @@ Description
(2.75 0.5 0) (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 SourceFiles
@ -100,7 +101,9 @@ public:
enum selectionModeType enum selectionModeType
{ {
smPoints, smPoints,
smCellSet smCellSet,
smCellZone,
smAll
}; };
//- Word list of selection mode type names //- Word list of selection mode type names
@ -147,14 +150,14 @@ protected:
//- List of points for "points" selectionMode //- List of points for "points" selectionMode
List<point> points_; List<point> points_;
//- Name of cell set for "cellSet" selectionMode //- Name of cell set for "cellSet" and "cellZone" selectionMode
word cellSetName_; word cellSetName_;
//- Field of cell volumes according to cell set cells //- Set of cells to apply source to
scalarList V_; labelList cells_;
//- Cell set //- Sum of cell volumes
autoPtr<cellSet> cellsPtr_; scalar V_;
//- List of source field name vs value pairs //- List of source field name vs value pairs
List<fieldNameValuePair> fieldData_; List<fieldNameValuePair> fieldData_;
@ -288,12 +291,11 @@ public:
// selectionMode // selectionMode
inline const word& cellSetName() const; inline const word& cellSetName() const;
//- Return const access to the field of cell volumes according to //- Return const access to the total cell volume
// cell set cells inline scalar V() const;
inline const scalarList& V() const;
//- Return const access to the cell set //- 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 //- Return const access to the source field name vs value pairs
inline const List<fieldNameValuePair>& fieldData() const; inline const List<fieldNameValuePair>& fieldData() const;
@ -330,12 +332,11 @@ public:
// selectionMode // selectionMode
inline word& cellSetName(); inline word& cellSetName();
//- Return access to the field of cell volumes according to //- Return access to the total cell volume
// cell set cells inline scalar& V();
inline scalarList& V();
//- Return access to the cell set //- Return access to the cell set
inline cellSet& cells(); inline labelList& cells();
//- Return access to the source field name vs value pairs //- Return access to the source field name vs value pairs
inline List<fieldNameValuePair>& fieldData(); inline List<fieldNameValuePair>& fieldData();

View File

@ -103,18 +103,17 @@ Foam::TimeActivatedExplicitSource<Type>::cellSetName() const
template<class Type> template<class Type>
inline const Foam::scalarList& inline Foam::scalar Foam::TimeActivatedExplicitSource<Type>::V() const
Foam::TimeActivatedExplicitSource<Type>::V() const
{ {
return V_; return V_;
} }
template<class Type> template<class Type>
inline const Foam::cellSet& inline const Foam::labelList&
Foam::TimeActivatedExplicitSource<Type>::cells() const Foam::TimeActivatedExplicitSource<Type>::cells() const
{ {
return cellsPtr_(); return cells_;
} }
@ -195,16 +194,16 @@ inline Foam::word& Foam::TimeActivatedExplicitSource<Type>::cellSetName()
template<class Type> template<class Type>
inline Foam::scalarList& Foam::TimeActivatedExplicitSource<Type>::V() inline Foam::scalar& Foam::TimeActivatedExplicitSource<Type>::V()
{ {
return V_; return V_;
} }
template<class Type> template<class Type>
inline Foam::cellSet& Foam::TimeActivatedExplicitSource<Type>::cells() inline Foam::labelList& Foam::TimeActivatedExplicitSource<Type>::cells()
{ {
return cellsPtr_(); return cells_;
} }