1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 "sampledSurfaces.H"
28 #include "volFields.H"
29 #include "ListListOps.H"
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 Foam::label Foam::sampledSurfaces::grep
36 fieldGroup<Type>& fieldList,
37 const wordList& fieldTypes
40 fieldList.setSize(fieldNames_.size());
43 forAll(fieldNames_, fieldI)
48 == GeometricField<Type, fvPatchField, volMesh>::typeName
51 fieldList[nFields] = fieldNames_[fieldI];
56 fieldList.setSize(nFields);
63 Foam::autoPtr<Foam::interpolation<Type> >
64 Foam::sampledSurfaces::setInterpolator
66 const GeometricField<Type, fvPatchField, volMesh>& vField
69 if (!pMeshPtr_.valid() || !pInterpPtr_.valid())
71 // set up interpolation
72 pMeshPtr_.reset(new pointMesh(mesh_));
73 pInterpPtr_.reset(new volPointInterpolation(mesh_, pMeshPtr_()));
76 // interpolator for this field
77 return interpolation<Type>::New
87 void Foam::sampledSurfaces::sampleAndWrite
89 const GeometricField<Type, fvPatchField, volMesh>& vField,
90 const surfaceWriter<Type>& formatter
93 // interpolator for this field
94 autoPtr<interpolation<Type> > interpolator;
96 const word& fieldName = vField.name();
97 const fileName& timeDir = vField.time().timeName();
101 const sampledSurface& s = operator[](surfI);
107 if (!interpolator.valid())
109 interpolator = setInterpolator(vField);
112 values = s.interpolate(interpolator());
116 values = s.sample(vField);
119 if (Pstream::parRun())
121 // Collect values from all processors
122 List<Field<Type> > gatheredValues(Pstream::nProcs());
123 gatheredValues[Pstream::myProcNo()] = values;
124 Pstream::gatherList(gatheredValues);
126 if (Pstream::master())
128 // Combine values into single field
129 Field<Type> allValues
131 ListListOps::combine<Field<Type> >
134 accessOp<Field<Type> >()
138 // Renumber (point data) to correspond to merged points
139 if (mergeList_[surfI].pointsMap.size() == allValues.size())
141 inplaceReorder(mergeList_[surfI].pointsMap, allValues);
142 allValues.setSize(mergeList_[surfI].points.size());
145 // Write to time directory under outputPath_
146 // skip surface without faces (eg, a failed cut-plane)
147 if (mergeList_[surfI].faces.size())
154 mergeList_[surfI].points,
155 mergeList_[surfI].faces,
164 // Write to time directory under outputPath_
165 // skip surface without faces (eg, a failed cut-plane)
166 if (s.faces().size())
184 template <class Type>
185 void Foam::sampledSurfaces::sampleAndWrite
187 fieldGroup<Type>& fields
192 // create or use existing surfaceWriter
193 if (!fields.formatter.valid())
195 fields.formatter = surfaceWriter<Type>::New(writeFormat_);
198 forAll(fields, fieldI)
200 if (Pstream::master() && verbose_)
202 Pout<< "sampleAndWrite: " << fields[fieldI] << endl;
209 GeometricField<Type, fvPatchField, volMesh>
214 mesh_.time().timeName(),
227 objectRegistry::const_iterator iter =
228 mesh_.find(fields[fieldI]);
232 iter != mesh_.objectRegistry::end()
234 == GeometricField<Type, fvPatchField, volMesh>::typeName
240 <GeometricField<Type, fvPatchField, volMesh> >
253 // ************************************************************************* //