FreeFOAM The Cross-Platform CFD Toolkit
explicitSource.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "explicitSource.H"
27 #include <finiteVolume/fvMesh.H>
28 #include <finiteVolume/volFields.H>
30 #include <OpenFOAM/HashSet.H>
31 
32 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(explicitSource, 0);
38  (
39  basicSource,
40  explicitSource,
41  dictionary
42  );
43 }
44 
46 (
47  IStringStream("(absolute specific)")()
48 );
49 
50 
51 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 
54 {
55  labelHashSet selectedCells;
56 
57  forAll(points_, i)
58  {
59  label cellI = this->mesh().findCell(points_[i]);
60  if (cellI >= 0)
61  {
62  selectedCells.insert(cellI);
63  }
64 
65  label globalCellI = returnReduce(cellI, maxOp<label>());
66 
67  if (globalCellI < 0)
68  {
69  WarningIn("explicitSource::setSelectedCellsFromPoints()")
70  << "Unable to find owner cell for point " << points_[i]
71  << endl;
72  }
73  }
74 
75  this->cells() = selectedCells.toc();
76 }
77 
78 
79 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
80 
83 (
84  const word& vmtName
85 ) const
86 {
87  forAll(volumeModeTypeNames_, i)
88  {
89  if (vmtName == volumeModeTypeNames_[i])
90  {
91  return volumeModeType(i);
92  }
93  }
94 
96  (
97  "explicitSource<Type>::volumeModeType"
98  "explicitSource<Type>::wordToVolumeModeType(const word&)"
99  ) << "Unknown volumeMode type " << vmtName
100  << ". Valid volumeMode types are:" << nl << volumeModeTypeNames_
101  << exit(FatalError);
102 
103  return volumeModeType(0);
104 }
105 
106 
108 (
109  const volumeModeType& vmtType
110 ) const
111 {
112  if (vmtType > volumeModeTypeNames_.size())
113  {
114  return "UNKNOWN";
115  }
116  else
117  {
118  return volumeModeTypeNames_[vmtType];
119  }
120 }
121 
122 
124 {
125  scalarFields_.clear();
126  vectorFields_.clear();
127 
128  wordList fieldTypes(dict.toc().size());
129  wordList fieldNames(dict.toc().size());
130 
131  forAll(dict.toc(), i)
132  {
133  const word& fieldName = dict.toc()[i];
134  IOobject io
135  (
136  fieldName,
137  this->mesh().time().timeName(0),
138  this->mesh(),
141  false
142  );
143  if (io.headerOk())
144  {
145  fieldTypes[i] = io.headerClassName();
146  fieldNames[i] = dict.toc()[i];
147  }
148  else
149  {
151  (
152  "explicitSource::setFieldData"
153  ) << "header not OK " << io.name()
154  << exit(FatalError);
155  }
156  }
157 
158  addField(scalarFields_, fieldTypes, fieldNames, dict);
159  addField(vectorFields_, fieldTypes, fieldNames, dict);
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
164 
166 (
167  const word& name,
168  const dictionary& dict,
169  const fvMesh& mesh
170 )
171 :
172  basicSource(name, dict, mesh),
173  scalarFields_(0, *this),
174  vectorFields_(0, *this),
175  dict_(dict.subDict(typeName + "Coeffs")),
176  volumeMode_(wordToVolumeModeType(dict_.lookup("volumeMode"))),
177  points_(),
178  volSource_(this->cells().size(), 1.0)
179 {
180  setFieldData(dict_.subDict("fieldData"));
181 
182  // Set points if selectionMode is smPoints
183  if (this->selectionMode() == smPoints)
184  {
185  dict_.lookup("points") >> points_;
186  setSelectedCellsFromPoints();
187  volSource_.setSize(points_.size(), 1.0);
188  }
189 
190  const labelList& cellList = this->cells();
191  scalar V = 0.0;
192  if (volumeMode_ == vmAbsolute)
193  {
194  forAll(cellList, cellI)
195  {
196  volSource_[cellI] = mesh.V()[cellList[cellI]];
197  V += volSource_[cellI];
198  }
199  }
200  else
201  {
202  forAll(cellList, cellI)
203  {
204  V += mesh.V()[cellList[cellI]];
205  }
206  }
207 
208  reduce(V, sumOp<scalar>());
209 
210  Info<< "- selected " << returnReduce(cellList.size(), sumOp<label>())
211  << " cell(s) with Volume: " << V << " in time activated sources "
212  << endl;
213 }
214 
215 
217 {
218  Field<scalar>& source = Eqn.source();
219  scalar data = scalarFields_[Eqn.psi().name()];
220  addSources<scalar>(source, data);
221 }
222 
223 
225 {
226  Field<vector>& source = Eqn.source();
227  vector data = vectorFields_[Eqn.psi().name()];
228  addSources<vector>(source, data);
229 }
230 
231 
233 {
234  scalar data = scalarFields_[field.name()];
235  addSources<scalar>(field, data);
236 }
237 
238 
240 {
241  vector data = vectorFields_[field.name()];
242  addSources<vector>(field, data);
243 }
244 
245 
247 {
248  scalarFields_.applySources();
249  vectorFields_.applySources();
250 }
251 
252 
253 // ************************************************************************* //