1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "TimeActivatedExplicitSource.H"
28 #include "volFields.H"
30 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
33 const Foam::wordList Foam::TimeActivatedExplicitSource<Type>::
34 selectionModeTypeNames_
36 IStringStream("(points cellSet cellZone all)")()
41 const Foam::wordList Foam::TimeActivatedExplicitSource<Type>::
44 IStringStream("(absolute specific)")()
48 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
51 typename Foam::TimeActivatedExplicitSource<Type>::selectionModeType
52 Foam::TimeActivatedExplicitSource<Type>::wordToSelectionModeType
57 forAll(selectionModeTypeNames_, i)
59 if (smtName == selectionModeTypeNames_[i])
61 return selectionModeType(i);
67 "TimeActivatedExplicitSource<Type>::selectionModeType"
68 "TimeActivatedExplicitSource<Type>::wordToSelectionModeType"
72 ) << "Unknown selectionMode type " << smtName
73 << ". Valid selectionMode types are:" << nl << selectionModeTypeNames_
76 return selectionModeType(0);
81 typename Foam::TimeActivatedExplicitSource<Type>::volumeModeType
82 Foam::TimeActivatedExplicitSource<Type>::wordToVolumeModeType
87 forAll(volumeModeTypeNames_, i)
89 if (vmtName == volumeModeTypeNames_[i])
91 return volumeModeType(i);
97 "TimeActivatedExplicitSource<Type>::volumeModeType"
98 "TimeActivatedExplicitSource<Type>::wordToVolumeModeType(const word&)"
99 ) << "Unknown volumeMode type " << vmtName
100 << ". Valid volumeMode types are:" << nl << volumeModeTypeNames_
103 return volumeModeType(0);
108 Foam::word Foam::TimeActivatedExplicitSource<Type>::selectionModeTypeToWord
110 const selectionModeType& smtType
113 if (smtType > selectionModeTypeNames_.size())
119 return selectionModeTypeNames_[smtType];
125 Foam::word Foam::TimeActivatedExplicitSource<Type>::volumeModeTypeToWord
127 const volumeModeType& vmtType
130 if (vmtType > volumeModeTypeNames_.size())
136 return volumeModeTypeNames_[vmtType];
142 void Foam::TimeActivatedExplicitSource<Type>::setSelection
144 const dictionary& dict
147 switch (selectionMode_)
151 dict.lookup("points") >> points_;
156 dict.lookup("cellSet") >> cellSetName_;
161 dict.lookup("cellZone") >> cellSetName_;
172 "TimeActivatedExplicitSource::setSelection(const dictionary&)"
173 ) << "Unknown selectionMode "
174 << selectionModeTypeNames_[selectionMode_]
175 << ". Valid selectionMode types are" << selectionModeTypeNames_
183 void Foam::TimeActivatedExplicitSource<Type>::setFieldData
185 const dictionary& dict,
186 const wordList& fieldNames
189 dict.lookup("fieldData") >> fieldData_;
190 labelList localFieldIds(fieldData_.size(), -1);
191 forAll(fieldNames, i)
193 forAll(fieldData_, j)
195 const word& fdName = fieldData_[j].first();
196 if (fdName == fieldNames[i])
199 localFieldIds[j] = i;
204 forAll(localFieldIds, i)
206 if (localFieldIds[i] < 0)
210 "TimeActivatedExplicitSource<Type>::setFieldData"
212 "const dictionary&, "
215 ) << "Field " << fieldData_[i].first() << " not found in "
216 << "field list. Available fields are: " << nl << fieldNames
224 void Foam::TimeActivatedExplicitSource<Type>::setCellSet()
226 Info<< incrIndent << indent << "Source: " << name_ << endl;
227 switch (selectionMode_)
231 Info<< indent << "- selecting cells using points" << endl;
233 labelHashSet selectedCells;
237 label cellI = mesh_.findCell(points_[i]);
240 selectedCells.insert(cellI);
243 label globalCellI = returnReduce(cellI, maxOp<label>());
246 WarningIn("TimeActivatedExplicitSource<Type>::setCellIds()")
247 << "Unable to find owner cell for point " << points_[i]
252 cells_ = selectedCells.toc();
258 Info<< indent << "- selecting cells using cellSet "
259 << cellSetName_ << endl;
261 cellSet selectedCells(mesh_, cellSetName_);
262 cells_ = selectedCells.toc();
268 Info<< indent << "- selecting cells using cellZone "
269 << cellSetName_ << endl;
270 label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
273 FatalErrorIn("TimeActivatedExplicitSource<Type>::setCellIds()")
274 << "Cannot find cellZone " << cellSetName_ << endl
275 << "Valid cellZones are " << mesh_.cellZones().names()
278 cells_ = mesh_.cellZones()[zoneID];
284 Info<< indent << "- selecting all cells" << endl;
285 cells_ = identity(mesh_.nCells());
291 FatalErrorIn("TimeActivatedExplicitSource<Type>::setCellIds()")
292 << "Unknown selectionMode "
293 << selectionModeTypeNames_[selectionMode_]
294 << ". Valid selectionMode types are" << selectionModeTypeNames_
299 // Set volume normalisation
300 if (volumeMode_ == vmAbsolute)
305 V_ += mesh_.V()[cells_[i]];
307 reduce(V_, sumOp<scalar>());
310 Info<< indent << "- selected "
311 << returnReduce(cells_.size(), sumOp<label>())
312 << " cell(s) with volume " << V_ << nl << decrIndent << endl;
316 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
319 Foam::TimeActivatedExplicitSource<Type>::TimeActivatedExplicitSource
322 const dictionary& dict,
324 const wordList& fieldNames
329 active_(readBool(dict.lookup("active"))),
330 timeStart_(readScalar(dict.lookup("timeStart"))),
331 duration_(readScalar(dict.lookup("duration"))),
332 volumeMode_(wordToVolumeModeType(dict.lookup("volumeMode"))),
333 selectionMode_(wordToSelectionModeType(dict.lookup("selectionMode"))),
335 cellSetName_("none"),
338 fieldIds_(fieldNames.size(), -1)
342 if (fieldNames.size() == 1)
344 fieldData_.setSize(1);
345 fieldData_[0].first() = fieldNames[0];
346 dict.lookup("fieldData") >> fieldData_[0].second();
351 setFieldData(dict, fieldNames);
359 void Foam::TimeActivatedExplicitSource<Type>::addToField
361 DimensionedField<Type, volMesh>& Su,
365 const label fid = fieldIds_[fieldI];
371 && (mesh_.time().value() >= timeStart_)
372 && (mesh_.time().value() <= timeEnd())
375 // Update the cell set if the mesh is changing
376 if (mesh_.changing())
383 Su[cells_[i]] = fieldData_[fid].second()/V_;
389 // ************************************************************************* //