1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "cellSource.H"
29 #include "volFields.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(cellSource, 0);
42 const char* NamedEnum<fieldValues::cellSource::sourceType, 1>::
43 names[] = {"cellZone"};
45 const NamedEnum<fieldValues::cellSource::sourceType, 1>
46 fieldValues::cellSource::sourceTypeNames_;
49 const char* NamedEnum<fieldValues::cellSource::operationType, 5>::
52 "none", "sum", "volAverage", "volIntegrate", "weightedAverage"
55 const NamedEnum<fieldValues::cellSource::operationType, 5>
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);
91 Info<< "Original cell zone size = " << cZone.size()
92 << ", new size = " << count << endl;
97 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
99 void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
110 FatalErrorIn("cellSource::initialise()")
111 << "Unknown source type. Valid source types are:"
112 << sourceTypeNames_ << nl << exit(FatalError);
116 Info<< type() << " " << name_ << ":" << nl
117 << " total cells = " << cellId_.size() << nl
118 << " total volume = " << sum(filterField(mesh().V()))
121 if (operation_ == opWeightedAverage)
123 dict.lookup("weightField") >> weightFieldName_;
126 obr().foundObject<volScalarField>(weightFieldName_)
129 Info<< " weight field = " << weightFieldName_;
133 FatalErrorIn("cellSource::initialise()")
134 << type() << " " << name_ << ": "
135 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
136 << nl << " Weight field " << weightFieldName_
137 << " must be a " << volScalarField::typeName
138 << nl << exit(FatalError);
146 void Foam::fieldValues::cellSource::writeFileHeader()
148 if (outputFilePtr_.valid())
151 << "# Source : " << sourceTypeNames_[source_] << " "
152 << sourceName_ << nl << "# Cells : " << cellId_.size() << nl
153 << "# Time" << tab << "sum(V)";
158 << tab << operationTypeNames_[operation_]
159 << "(" << fields_[i] << ")";
162 outputFilePtr_() << endl;
167 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
169 Foam::fieldValues::cellSource::cellSource
172 const objectRegistry& obr,
173 const dictionary& dict,
174 const bool loadFromFiles
177 fieldValue(name, obr, dict, loadFromFiles),
178 source_(sourceTypeNames_.read(dict.lookup("source"))),
179 operation_(operationTypeNames_.read(dict.lookup("operation"))),
186 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
188 Foam::fieldValues::cellSource::~cellSource()
192 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 void Foam::fieldValues::cellSource::read(const dictionary& dict)
196 fieldValue::read(dict);
200 // no additional info to read
206 void Foam::fieldValues::cellSource::write()
212 if (Pstream::master())
215 << obr_.time().value() << tab
216 << sum(filterField(mesh().V()));
221 writeValues<scalar>(fields_[i]);
222 writeValues<vector>(fields_[i]);
223 writeValues<sphericalTensor>(fields_[i]);
224 writeValues<symmTensor>(fields_[i]);
225 writeValues<tensor>(fields_[i]);
228 if (Pstream::master())
230 outputFilePtr_()<< endl;
241 // ************************************************************************* //