1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cellSource.H"
28 #include "volFields.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(cellSource, 0);
41 const char* NamedEnum<fieldValues::cellSource::sourceType, 1>::
42 names[] = {"cellZone"};
44 const NamedEnum<fieldValues::cellSource::sourceType, 1>
45 fieldValues::cellSource::sourceTypeNames_;
48 const char* NamedEnum<fieldValues::cellSource::operationType, 7>::
51 "none", "sum", "volAverage",
52 "volIntegrate", "weightedAverage", "min", "max"
55 const NamedEnum<fieldValues::cellSource::operationType, 7>
56 fieldValues::cellSource::operationTypeNames_;
61 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 void Foam::fieldValues::cellSource::setCellZoneCells()
65 label zoneId = mesh().cellZones().findZoneID(sourceName_);
69 FatalErrorIn("cellSource::cellSource::setCellZoneCells()")
70 << "Unknown cell zone name: " << sourceName_
71 << ". Valid cell zones are: " << mesh().cellZones().names()
72 << nl << exit(FatalError);
75 const cellZone& cZone = mesh().cellZones()[zoneId];
77 cellId_.setSize(cZone.size());
82 label cellI = cZone[i];
83 cellId_[count] = cellI;
87 cellId_.setSize(count);
88 nCells_ = returnReduce(cellId_.size(), sumOp<label>());
92 Pout<< "Original cell zone size = " << cZone.size()
93 << ", new size = " << count << endl;
98 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
100 void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
111 FatalErrorIn("cellSource::initialise()")
112 << "Unknown source type. Valid source types are:"
113 << sourceTypeNames_ << nl << exit(FatalError);
117 Info<< type() << " " << name_ << ":" << nl
118 << " total cells = " << nCells_ << nl
119 << " total volume = " << gSum(filterField(mesh().V()))
122 if (operation_ == opWeightedAverage)
124 dict.lookup("weightField") >> weightFieldName_;
127 obr().foundObject<volScalarField>(weightFieldName_)
130 Info<< " weight field = " << weightFieldName_;
134 FatalErrorIn("cellSource::initialise()")
135 << type() << " " << name_ << ": "
136 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
137 << nl << " Weight field " << weightFieldName_
138 << " must be a " << volScalarField::typeName
139 << nl << exit(FatalError);
147 void Foam::fieldValues::cellSource::writeFileHeader()
149 if (outputFilePtr_.valid())
152 << "# Source : " << sourceTypeNames_[source_] << " "
153 << sourceName_ << nl << "# Cells : " << nCells_ << nl
154 << "# Time" << tab << "sum(V)";
159 << tab << operationTypeNames_[operation_]
160 << "(" << fields_[i] << ")";
163 outputFilePtr_() << endl;
168 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
170 Foam::fieldValues::cellSource::cellSource
173 const objectRegistry& obr,
174 const dictionary& dict,
175 const bool loadFromFiles
178 fieldValue(name, obr, dict, loadFromFiles),
179 source_(sourceTypeNames_.read(dict.lookup("source"))),
180 operation_(operationTypeNames_.read(dict.lookup("operation"))),
188 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 Foam::fieldValues::cellSource::~cellSource()
194 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
196 void Foam::fieldValues::cellSource::read(const dictionary& dict)
198 fieldValue::read(dict);
202 // no additional info to read
208 void Foam::fieldValues::cellSource::write()
214 if (Pstream::master())
217 << obr_.time().value() << tab
218 << sum(filterField(mesh().V()));
223 writeValues<scalar>(fields_[i]);
224 writeValues<vector>(fields_[i]);
225 writeValues<sphericalTensor>(fields_[i]);
226 writeValues<symmTensor>(fields_[i]);
227 writeValues<tensor>(fields_[i]);
230 if (Pstream::master())
232 outputFilePtr_()<< endl;
243 // ************************************************************************* //