1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
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 "cellSource.H"
28 #include "volFields.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::fieldValues::cellSource, 0);
38 const char* Foam::NamedEnum
40 Foam::fieldValues::cellSource::sourceType,
50 const char* Foam::NamedEnum
52 Foam::fieldValues::cellSource::operationType,
67 const Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 2>
68 Foam::fieldValues::cellSource::sourceTypeNames_;
70 const Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 7>
71 Foam::fieldValues::cellSource::operationTypeNames_;
74 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
76 void Foam::fieldValues::cellSource::setCellZoneCells()
82 label zoneId = mesh().cellZones().findZoneID(sourceName_);
86 FatalErrorIn("cellSource::cellSource::setCellZoneCells()")
87 << "Unknown cell zone name: " << sourceName_
88 << ". Valid cell zones are: " << mesh().cellZones().names()
89 << nl << exit(FatalError);
92 cellId_ = mesh().cellZones()[zoneId];
93 nCells_ = returnReduce(cellId_.size(), sumOp<label>());
99 cellId_ = identity(mesh().nCells());
100 nCells_ = returnReduce(cellId_.size(), sumOp<label>());
106 FatalErrorIn("cellSource::setCellZoneCells()")
107 << "Unknown source type. Valid source types are:"
108 << sourceTypeNames_ << nl << exit(FatalError);
114 Pout<< "Selected source size = " << cellId_.size() << endl;
119 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
121 void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
129 "Foam::fieldValues::cellSource::initialise(const dictionary&)"
131 << type() << " " << name_ << ": "
132 << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
133 << " Source has no cells - deactivating" << endl;
139 Info<< type() << " " << name_ << ":"
140 << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
141 << " total cells = " << nCells_ << nl
142 << " total volume = " << gSum(filterField(mesh().V()))
145 if (operation_ == opWeightedAverage)
147 dict.lookup("weightField") >> weightFieldName_;
150 obr().foundObject<volScalarField>(weightFieldName_)
153 Info<< " weight field = " << weightFieldName_;
157 FatalErrorIn("cellSource::initialise()")
158 << type() << " " << name_ << ": "
159 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
160 << nl << " Weight field " << weightFieldName_
161 << " must be a " << volScalarField::typeName
162 << nl << exit(FatalError);
170 void Foam::fieldValues::cellSource::writeFileHeader()
172 if (outputFilePtr_.valid())
175 << "# Source : " << sourceTypeNames_[source_] << " "
176 << sourceName_ << nl << "# Cells : " << nCells_ << nl
177 << "# Time" << tab << "sum(V)";
182 << tab << operationTypeNames_[operation_]
183 << "(" << fields_[i] << ")";
186 outputFilePtr_() << endl;
191 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
193 Foam::fieldValues::cellSource::cellSource
196 const objectRegistry& obr,
197 const dictionary& dict,
198 const bool loadFromFiles
201 fieldValue(name, obr, dict, loadFromFiles),
202 source_(sourceTypeNames_.read(dict.lookup("source"))),
203 operation_(operationTypeNames_.read(dict.lookup("operation"))),
211 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
213 Foam::fieldValues::cellSource::~cellSource()
217 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
219 void Foam::fieldValues::cellSource::read(const dictionary& dict)
221 fieldValue::read(dict);
225 // no additional info to read
231 void Foam::fieldValues::cellSource::write()
237 scalar totalVolume = gSum(filterField(mesh().V()));
238 if (Pstream::master())
240 outputFilePtr_() << obr_.time().value() << tab << totalVolume;
245 writeValues<scalar>(fields_[i]);
246 writeValues<vector>(fields_[i]);
247 writeValues<sphericalTensor>(fields_[i]);
248 writeValues<symmTensor>(fields_[i]);
249 writeValues<tensor>(fields_[i]);
252 if (Pstream::master())
254 outputFilePtr_()<< endl;
265 // ************************************************************************* //