1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-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 "sampledSurfaces.H"
28 #include "volFields.H"
29 #include "ListListOps.H"
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 void Foam::sampledSurfaces::sampleAndWrite
36 const GeometricField<Type, fvPatchField, volMesh>& vField,
37 const surfaceWriter<Type>& formatter
40 // interpolator for this field
41 autoPtr< interpolation<Type> > interpolator;
43 const word& fieldName = vField.name();
44 const fileName outputDir = outputPath_/vField.time().timeName();
48 const sampledSurface& s = operator[](surfI);
54 if (interpolator.empty())
56 interpolator = interpolation<Type>::New
63 values = s.interpolate(interpolator());
67 values = s.sample(vField);
70 if (Pstream::parRun())
72 // Collect values from all processors
73 List<Field<Type> > gatheredValues(Pstream::nProcs());
74 gatheredValues[Pstream::myProcNo()] = values;
75 Pstream::gatherList(gatheredValues);
77 if (Pstream::master())
79 // Combine values into single field
82 ListListOps::combine<Field<Type> >
85 accessOp<Field<Type> >()
89 // Renumber (point data) to correspond to merged points
90 if (mergeList_[surfI].pointsMap.size() == allValues.size())
92 inplaceReorder(mergeList_[surfI].pointsMap, allValues);
93 allValues.setSize(mergeList_[surfI].points.size());
96 // Write to time directory under outputPath_
97 // skip surface without faces (eg, a failed cut-plane)
98 if (mergeList_[surfI].faces.size())
104 mergeList_[surfI].points,
105 mergeList_[surfI].faces,
114 // Write to time directory under outputPath_
115 // skip surface without faces (eg, a failed cut-plane)
116 if (s.faces().size())
134 void Foam::sampledSurfaces::sampleAndWrite
136 fieldGroup<Type>& fields
141 // create or use existing surfaceWriter
142 if (fields.formatter.empty())
144 fields.formatter = surfaceWriter<Type>::New(writeFormat_);
147 forAll(fields, fieldI)
149 if (Pstream::master() && verbose_)
151 Pout<< "sampleAndWrite: " << fields[fieldI] << endl;
158 GeometricField<Type, fvPatchField, volMesh>
163 mesh_.time().timeName(),
176 objectRegistry::const_iterator iter =
177 mesh_.find(fields[fieldI]);
181 iter != mesh_.objectRegistry::end()
183 == GeometricField<Type, fvPatchField, volMesh>::typeName
189 <GeometricField<Type, fvPatchField, volMesh> >
202 // ************************************************************************* //