diff --git a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.C b/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.C index b8fbe54a89a0ea11ffe42347e93b538dc1540283..1873bbe3fec8ca7db272376d5a39dff8ed6d5d10 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.C +++ b/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.C @@ -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_; } } } diff --git a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.H b/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.H index 11282a54d3a5222268ff1e4a288064ddadd07f3f..e014e02cd487126196d59cbce56ea1f3a1ef7e54 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSource.H @@ -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(); diff --git a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceI.H b/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceI.H index be8bd5844a9c70ac02388fe29ed41058111fddba..55a9e7336e82c560053766034f4b1cf687c38d25 100644 --- a/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceI.H +++ b/src/finiteVolume/cfdTools/general/fieldSources/timeActivatedExplicitSource/TimeActivatedExplicitSourceI.H @@ -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_; }