1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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 "sampledSets.H"
27 #include <finiteVolume/volFields.H>
28 #include <OpenFOAM/ListListOps.H>
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
35 const word& interpolationScheme,
36 const GeometricField<Type, fvPatchField, volMesh>& field,
37 const PtrList<sampledSet>& samplers
40 List<Field<Type> >(samplers.size()),
43 autoPtr<interpolation<Type> > interpolator
45 interpolation<Type>::New(interpolationScheme, field)
48 forAll(samplers, seti)
50 Field<Type>& values = this->operator[](seti);
51 const sampledSet& samples = samplers[seti];
53 values.setSize(samples.size());
54 forAll(samples, samplei)
56 const point& samplePt = samples[samplei];
57 label celli = samples.cells()[samplei];
58 label facei = samples.faces()[samplei];
60 if (celli == -1 && facei == -1)
62 // Special condition for illegal sampling points
63 values[samplei] = pTraits<Type>::max;
67 values[samplei] = interpolator().interpolate
80 Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
82 const GeometricField<Type, fvPatchField, volMesh>& field,
83 const PtrList<sampledSet>& samplers
86 List<Field<Type> >(samplers.size()),
89 forAll(samplers, seti)
91 Field<Type>& values = this->operator[](seti);
92 const sampledSet& samples = samplers[seti];
94 values.setSize(samples.size());
95 forAll(samples, samplei)
97 label celli = samples.cells()[samplei];
101 values[samplei] = pTraits<Type>::max;
105 values[samplei] = field[celli];
112 template <class Type>
113 Foam::sampledSets::volFieldSampler<Type>::volFieldSampler
115 const List<Field<Type> >& values,
119 List<Field<Type> >(values),
125 Foam::label Foam::sampledSets::grep
127 fieldGroup<Type>& fieldList,
128 const wordList& fieldTypes
131 fieldList.setSize(fieldNames_.size());
134 forAll(fieldNames_, fieldi)
139 == GeometricField<Type, fvPatchField, volMesh>::typeName
142 fieldList[nFields] = fieldNames_[fieldi];
147 fieldList.setSize(nFields);
154 void Foam::sampledSets::writeSampleFile
156 const coordSet& masterSampleSet,
157 const PtrList<volFieldSampler<Type> >& masterFields,
159 const fileName& timeDir,
160 const writer<Type>& formatter
163 wordList valueSetNames(masterFields.size());
164 List<const Field<Type>*> valueSets(masterFields.size());
166 forAll(masterFields, fieldi)
168 valueSetNames[fieldi] = masterFields[fieldi].name();
169 valueSets[fieldi] = &masterFields[fieldi][seti];
174 timeDir/formatter.getFileName(masterSampleSet, valueSetNames)
192 "void Foam::sampledSets::writeSampleFile"
195 "const PtrList<volFieldSampler<Type> >&, "
198 "const writer<Type>&"
200 ) << "File " << ofs.name() << " could not be opened. "
201 << "No data will be written" << endl;
207 void Foam::sampledSets::combineSampledValues
209 const PtrList<volFieldSampler<T> >& sampledFields,
210 const labelListList& indexSets,
211 PtrList<volFieldSampler<T> >& masterFields
214 forAll(sampledFields, fieldi)
216 List<Field<T> > masterValues(indexSets.size());
218 forAll(indexSets, seti)
220 // Collect data from all processors
221 List<Field<T> > gatheredData(Pstream::nProcs());
222 gatheredData[Pstream::myProcNo()] = sampledFields[fieldi][seti];
223 Pstream::gatherList(gatheredData);
225 if (Pstream::master())
229 ListListOps::combine<Field<T> >
232 Foam::accessOp<Field<T> >()
236 masterValues[seti] = UIndirectList<T>
247 new volFieldSampler<T>
250 sampledFields[fieldi].name()
258 void Foam::sampledSets::sampleAndWrite
260 fieldGroup<Type>& fields
265 bool interpolate = interpolationScheme_ != "cell";
267 // Create or use existing writer
268 if (fields.formatter.empty())
270 fields.formatter = writer<Type>::New(writeFormat_);
273 // Storage for interpolated values
274 PtrList<volFieldSampler<Type> > sampledFields(fields.size());
276 forAll(fields, fieldi)
278 if (Pstream::master() && verbose_)
280 Pout<< "sampledSets::sampleAndWrite: "
281 << fields[fieldi] << endl;
286 GeometricField<Type, fvPatchField, volMesh> vf
291 mesh_.time().timeName(),
305 new volFieldSampler<Type>
307 interpolationScheme_,
318 new volFieldSampler<Type>(vf, *this)
329 new volFieldSampler<Type>
331 interpolationScheme_,
333 <GeometricField<Type, fvPatchField, volMesh> >
344 new volFieldSampler<Type>
347 <GeometricField<Type, fvPatchField, volMesh> >
356 // Combine sampled fields from processors.
357 // Note: only master results are valid
359 PtrList<volFieldSampler<Type> > masterFields(sampledFields.size());
360 combineSampledValues(sampledFields, indexSets_, masterFields);
362 if (Pstream::master())
364 forAll(masterSampledSets_, seti)
368 masterSampledSets_[seti],
371 outputPath_/mesh_.time().timeName(),
380 // ************************ vim: set sw=4 sts=4 et: ************************ //