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 "faceSource.H"
28 #include "cyclicPolyPatch.H"
29 #include "emptyPolyPatch.H"
30 #include "coupledPolyPatch.H"
31 #include "sampledSurface.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(Foam::fieldValues::faceSource, 0);
40 const char* Foam::NamedEnum
42 Foam::fieldValues::faceSource::sourceType,
53 const char* Foam::NamedEnum
55 Foam::fieldValues::faceSource::operationType,
71 const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>
72 Foam::fieldValues::faceSource::sourceTypeNames_;
74 const Foam::NamedEnum<Foam::fieldValues::faceSource::operationType, 7>
75 Foam::fieldValues::faceSource::operationTypeNames_;
78 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
80 void Foam::fieldValues::faceSource::setFaceZoneFaces()
82 label zoneId = mesh().faceZones().findZoneID(sourceName_);
86 FatalErrorIn("faceSource::faceSource::setFaceZoneFaces()")
87 << type() << " " << name_ << ": "
88 << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
89 << " Unknown face zone name: " << sourceName_
90 << ". Valid face zones are: " << mesh().faceZones().names()
91 << nl << exit(FatalError);
94 const faceZone& fZone = mesh().faceZones()[zoneId];
96 faceId_.setSize(fZone.size());
97 facePatchId_.setSize(fZone.size());
98 faceSign_.setSize(fZone.size());
103 label faceI = fZone[i];
106 label facePatchId = -1;
107 if (mesh().isInternalFace(faceI))
114 facePatchId = mesh().boundaryMesh().whichPatch(faceI);
115 const polyPatch& pp = mesh().boundaryMesh()[facePatchId];
116 if (isA<coupledPolyPatch>(pp))
118 if (refCast<const coupledPolyPatch>(pp).owner())
120 faceId = pp.whichFace(faceI);
127 else if (!isA<emptyPolyPatch>(pp))
129 faceId = faceI - pp.start();
140 if (fZone.flipMap()[i])
142 faceSign_[count] = -1;
146 faceSign_[count] = 1;
148 faceId_[count] = faceId;
149 facePatchId_[count] = facePatchId;
154 faceId_.setSize(count);
155 facePatchId_.setSize(count);
156 faceSign_.setSize(count);
157 nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
161 Pout<< "Original face zone size = " << fZone.size()
162 << ", new size = " << count << endl;
167 void Foam::fieldValues::faceSource::setPatchFaces()
169 const label patchId = mesh().boundaryMesh().findPatchID(sourceName_);
173 FatalErrorIn("faceSource::constructFaceAddressing()")
174 << type() << " " << name_ << ": "
175 << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
176 << " Unknown patch name: " << sourceName_
177 << ". Valid patch names are: "
178 << mesh().boundaryMesh().names() << nl
182 const polyPatch& pp = mesh().boundaryMesh()[patchId];
184 label nFaces = pp.size();
185 if (isA<cyclicPolyPatch>(pp))
189 else if (isA<emptyPolyPatch>(pp))
194 faceId_.setSize(nFaces);
195 facePatchId_.setSize(nFaces);
196 faceSign_.setSize(nFaces);
197 nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
199 forAll(faceId_, faceI)
201 faceId_[faceI] = faceI;
202 facePatchId_[faceI] = patchId;
203 faceSign_[faceI] = 1;
208 void Foam::fieldValues::faceSource::sampledSurfaceFaces(const dictionary& dict)
210 surfacePtr_ = sampledSurface::New
214 dict.subDict("sampledSurfaceDict")
216 surfacePtr_().update();
217 nFaces_ = returnReduce(surfacePtr_().faces().size(), sumOp<label>());
221 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
223 void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
237 case stSampledSurface:
239 sampledSurfaceFaces(dict);
244 FatalErrorIn("faceSource::initialise()")
245 << type() << " " << name_ << ": "
246 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
247 << nl << " Unknown source type. Valid source types are:"
248 << sourceTypeNames_.sortedToc() << nl << exit(FatalError);
256 "Foam::fieldValues::faceSource::initialise(const dictionary&)"
258 << type() << " " << name_ << ": "
259 << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
260 << " Source has no faces - deactivating" << endl;
268 if (surfacePtr_.valid())
270 surfacePtr_().update();
271 totalArea = gSum(surfacePtr_().magSf());
275 totalArea = gSum(filterField(mesh().magSf(), false));
278 Info<< type() << " " << name_ << ":" << nl
279 << " total faces = " << nFaces_
281 << " total area = " << totalArea
284 if (operation_ == opWeightedAverage)
286 dict.lookup("weightField") >> weightFieldName_;
287 Info<< " weight field = " << weightFieldName_;
294 void Foam::fieldValues::faceSource::writeFileHeader()
296 if (outputFilePtr_.valid())
299 << "# Source : " << sourceTypeNames_[source_] << " "
300 << sourceName_ << nl << "# Faces : " << nFaces_ << nl
301 << "# Time" << tab << "sum(magSf)";
306 << tab << operationTypeNames_[operation_]
307 << "(" << fields_[i] << ")";
310 outputFilePtr_() << endl;
315 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
317 Foam::fieldValues::faceSource::faceSource
320 const objectRegistry& obr,
321 const dictionary& dict,
322 const bool loadFromFiles
325 fieldValue(name, obr, dict, loadFromFiles),
326 source_(sourceTypeNames_.read(dict.lookup("source"))),
327 operation_(operationTypeNames_.read(dict.lookup("operation"))),
328 weightFieldName_("undefinedWeightedFieldName"),
338 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
340 Foam::fieldValues::faceSource::~faceSource()
344 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
346 void Foam::fieldValues::faceSource::read(const dictionary& dict)
348 fieldValue::read(dict);
357 void Foam::fieldValues::faceSource::write()
365 if (surfacePtr_.valid())
367 surfacePtr_().update();
368 totalArea = gSum(surfacePtr_().magSf());
372 totalArea = gSum(filterField(mesh().magSf(), false));
376 if (Pstream::master())
378 outputFilePtr_() << obr_.time().value() << tab << totalArea;
383 writeValues<scalar>(fields_[i]);
384 writeValues<vector>(fields_[i]);
385 writeValues<sphericalTensor>(fields_[i]);
386 writeValues<symmTensor>(fields_[i]);
387 writeValues<tensor>(fields_[i]);
390 if (Pstream::master())
392 outputFilePtr_()<< endl;
403 // ************************************************************************* //