FreeFOAM The Cross-Platform CFD Toolkit
sampledSurfacesTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "sampledSurfaces.H"
27 #include <finiteVolume/volFields.H>
28 #include <OpenFOAM/ListListOps.H>
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
33 void Foam::sampledSurfaces::sampleAndWrite
34 (
35  const GeometricField<Type, fvPatchField, volMesh>& vField,
36  const surfaceWriter<Type>& formatter
37 )
38 {
39  // interpolator for this field
40  autoPtr< interpolation<Type> > interpolator;
41 
42  const word& fieldName = vField.name();
43  const fileName outputDir = outputPath_/vField.time().timeName();
44 
45  forAll(*this, surfI)
46  {
47  const sampledSurface& s = operator[](surfI);
48 
49  Field<Type> values;
50 
51  if (s.interpolate())
52  {
53  if (interpolator.empty())
54  {
55  interpolator = interpolation<Type>::New
56  (
57  interpolationScheme_,
58  vField
59  );
60  }
61 
62  values = s.interpolate(interpolator());
63  }
64  else
65  {
66  values = s.sample(vField);
67  }
68 
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);
75 
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  );
87 
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  }
94 
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  }
129 }
130 
131 
132 template<class Type>
133 void Foam::sampledSurfaces::sampleAndWrite
134 (
135  fieldGroup<Type>& fields
136 )
137 {
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  }
145 
146  forAll(fields, fieldI)
147  {
148  if (Pstream::master() && verbose_)
149  {
150  Pout<< "sampleAndWrite: " << fields[fieldI] << endl;
151  }
152 
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_,
166  false
167  ),
168  mesh_
169  ),
170  fields.formatter()
171  );
172  }
173  else
174  {
176  mesh_.find(fields[fieldI]);
177 
178  if
179  (
180  iter != mesh_.objectRegistry::end()
181  && iter()->type()
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  }
198 }
199 
200 
201 // ************************ vim: set sw=4 sts=4 et: ************************ //