initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / sampling / sampledSurface / sampledSurfaces / sampledSurfacesTemplates.C
blob6da55cfe8736220134b921afdef9403ea9f3fb6e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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  * * * * * * * * * * * //
33 template<class Type>
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();
46     forAll(*this, surfI)
47     {
48         const sampledSurface& s = operator[](surfI);
50         Field<Type> values;
52         if (s.interpolate())
53         {
54             if (interpolator.empty())
55             {
56                 interpolator = interpolation<Type>::New
57                 (
58                     interpolationScheme_,
59                     vField
60                 );
61             }
63             values = s.interpolate(interpolator());
64         }
65         else
66         {
67             values = s.sample(vField);
68         }
70         if (Pstream::parRun())
71         {
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())
78             {
79                 // Combine values into single field
80                 Field<Type> allValues
81                 (
82                     ListListOps::combine<Field<Type> >
83                     (
84                         gatheredValues,
85                         accessOp<Field<Type> >()
86                     )
87                 );
89                 // Renumber (point data) to correspond to merged points
90                 if (mergeList_[surfI].pointsMap.size() == allValues.size())
91                 {
92                     inplaceReorder(mergeList_[surfI].pointsMap, allValues);
93                     allValues.setSize(mergeList_[surfI].points.size());
94                 }
96                 // Write to time directory under outputPath_
97                 // skip surface without faces (eg, a failed cut-plane)
98                 if (mergeList_[surfI].faces.size())
99                 {
100                     formatter.write
101                     (
102                         outputDir,
103                         s.name(),
104                         mergeList_[surfI].points,
105                         mergeList_[surfI].faces,
106                         fieldName,
107                         allValues
108                     );
109                 }
110             }
111         }
112         else
113         {
114             // Write to time directory under outputPath_
115             // skip surface without faces (eg, a failed cut-plane)
116             if (s.faces().size())
117             {
118                 formatter.write
119                 (
120                     outputDir,
121                     s.name(),
122                     s.points(),
123                     s.faces(),
124                     fieldName,
125                     values
126                 );
127             }
128         }
129     }
133 template<class Type>
134 void Foam::sampledSurfaces::sampleAndWrite
136     fieldGroup<Type>& fields
139     if (fields.size())
140     {
141         // create or use existing surfaceWriter
142         if (fields.formatter.empty())
143         {
144             fields.formatter = surfaceWriter<Type>::New(writeFormat_);
145         }
147         forAll(fields, fieldI)
148         {
149             if (Pstream::master() && verbose_)
150             {
151                 Pout<< "sampleAndWrite: " << fields[fieldI] << endl;
152             }
154             if (loadFromFiles_)
155             {
156                 sampleAndWrite
157                 (
158                     GeometricField<Type, fvPatchField, volMesh>
159                     (
160                         IOobject
161                         (
162                             fields[fieldI],
163                             mesh_.time().timeName(),
164                             mesh_,
165                             IOobject::MUST_READ,
166                             IOobject::NO_WRITE,
167                             false
168                         ),
169                         mesh_
170                     ),
171                     fields.formatter()
172                 );
173             }
174             else
175             {
176                 objectRegistry::const_iterator iter =
177                     mesh_.find(fields[fieldI]);
179                 if
180                 (
181                     iter != mesh_.objectRegistry::end()
182                  && iter()->type()
183                  == GeometricField<Type, fvPatchField, volMesh>::typeName
184                 )
185                 {
186                    sampleAndWrite
187                    (
188                        mesh_.lookupObject
189                        <GeometricField<Type, fvPatchField, volMesh> >
190                        (
191                            fields[fieldI]
192                        ),
193                        fields.formatter()
194                    );
195                 }
196             }
197         }
198     }
202 // ************************************************************************* //