Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / sampling / sampledSurface / sampledSurfaces / sampledSurfacesTemplates.C
blob7c643a6081e66b58fdb9755eb658a172ce29b565
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sampledSurfaces.H"
27 #include "volFields.H"
28 #include "ListListOps.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 template<class Type>
33 void Foam::sampledSurfaces::sampleAndWrite
35     const GeometricField<Type, fvPatchField, volMesh>& vField,
36     const surfaceWriter<Type>& formatter
39     // interpolator for this field
40     autoPtr<interpolation<Type> > interpolator;
42     const word& fieldName = vField.name();
43     const fileName outputDir = outputPath_/vField.time().timeName();
45     forAll(*this, surfI)
46     {
47         const sampledSurface& s = operator[](surfI);
49         Field<Type> values;
51         if (s.interpolate())
52         {
53             if (interpolator.empty())
54             {
55                 interpolator = interpolation<Type>::New
56                 (
57                     interpolationScheme_,
58                     vField
59                 );
60             }
62             values = s.interpolate(interpolator());
63         }
64         else
65         {
66             values = s.sample(vField);
67         }
69         if (Pstream::parRun())
70         {
71             // Collect values from all processors
72             List<Field<Type> > gatheredValues(Pstream::nProcs());
73             gatheredValues[Pstream::myProcNo()] = values;
74             Pstream::gatherList(gatheredValues);
76             if (Pstream::master())
77             {
78                 // Combine values into single field
79                 Field<Type> allValues
80                 (
81                     ListListOps::combine<Field<Type> >
82                     (
83                         gatheredValues,
84                         accessOp<Field<Type> >()
85                     )
86                 );
88                 // Renumber (point data) to correspond to merged points
89                 if (mergeList_[surfI].pointsMap.size() == allValues.size())
90                 {
91                     inplaceReorder(mergeList_[surfI].pointsMap, allValues);
92                     allValues.setSize(mergeList_[surfI].points.size());
93                 }
95                 // Write to time directory under outputPath_
96                 // skip surface without faces (eg, a failed cut-plane)
97                 if (mergeList_[surfI].faces.size())
98                 {
99                     formatter.write
100                     (
101                         outputDir,
102                         s.name(),
103                         mergeList_[surfI].points,
104                         mergeList_[surfI].faces,
105                         fieldName,
106                         allValues
107                     );
108                 }
109             }
110         }
111         else
112         {
113             // Write to time directory under outputPath_
114             // skip surface without faces (eg, a failed cut-plane)
115             if (s.faces().size())
116             {
117                 formatter.write
118                 (
119                     outputDir,
120                     s.name(),
121                     s.points(),
122                     s.faces(),
123                     fieldName,
124                     values
125                 );
126             }
127         }
128     }
132 template<class Type>
133 void Foam::sampledSurfaces::sampleAndWrite
135     fieldGroup<Type>& fields
138     if (fields.size())
139     {
140         // create or use existing surfaceWriter
141         if (fields.formatter.empty())
142         {
143             fields.formatter = surfaceWriter<Type>::New(writeFormat_);
144         }
146         forAll(fields, fieldI)
147         {
148             if (Pstream::master() && verbose_)
149             {
150                 Pout<< "sampleAndWrite: " << fields[fieldI] << endl;
151             }
153             if (loadFromFiles_)
154             {
155                 sampleAndWrite
156                 (
157                     GeometricField<Type, fvPatchField, volMesh>
158                     (
159                         IOobject
160                         (
161                             fields[fieldI],
162                             mesh_.time().timeName(),
163                             mesh_,
164                             IOobject::MUST_READ,
165                             IOobject::NO_WRITE,
166                             false
167                         ),
168                         mesh_
169                     ),
170                     fields.formatter()
171                 );
172             }
173             else
174             {
175                 objectRegistry::const_iterator iter =
176                     mesh_.find(fields[fieldI]);
178                 if
179                 (
180                     iter != mesh_.objectRegistry::end()
181                  && iter()->type()
182                  == GeometricField<Type, fvPatchField, volMesh>::typeName
183                 )
184                 {
185                    sampleAndWrite
186                    (
187                        mesh_.lookupObject
188                        <GeometricField<Type, fvPatchField, volMesh> >
189                        (
190                            fields[fieldI]
191                        ),
192                        fields.formatter()
193                    );
194                 }
195             }
196         }
197     }
201 // ************************************************************************* //