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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "sampledSurfaces.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "polySurface.H"
33 #include "polySurfaceFields.H"
34 #include "polySurfacePointFields.H"
35 #include "surfMesh.H"
36 #include "surfGeoMesh.H"
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 template<class Type>
41 void Foam::sampledSurfaces::writeSurface
42 (
43  surfaceWriter& writer,
44  const Field<Type>& values,
45  const word& fieldName
46 )
47 {
48  fileName outputName = writer.write(fieldName, values);
49 
50  // Case-local file name with "<case>" to make relocatable
51 
52  dictionary propsDict;
53  propsDict.add
54  (
55  "file",
57  );
58  setProperty(fieldName, propsDict);
59 }
60 
61 
62 template<class Type, class GeoMeshType>
63 bool Foam::sampledSurfaces::storeRegistryField
64 (
65  const sampledSurface& s,
66  const word& fieldName,
67  const dimensionSet& dims,
68  Field<Type>&& values
69 )
70 {
71  return s.storeRegistryField<Type, GeoMeshType>
72  (
73  storedObjects(),
74  fieldName,
75  dims,
76  std::move(values),
77  IOobject::groupName(name(), s.name())
78  );
79 }
80 
81 
82 template<class Type>
83 void Foam::sampledSurfaces::performAction
84 (
85  const GeometricField<Type, fvPatchField, volMesh>& fld,
86  unsigned request
87 )
88 {
89  // The sampler for this field
90  autoPtr<interpolation<Type>> samplePtr;
91 
92  // The interpolator for this field
93  autoPtr<interpolation<Type>> interpPtr;
94 
95  const word& fieldName = fld.name();
96 
97  const dimensionSet& dims = fld.dimensions();
98 
99  forAll(*this, surfi)
100  {
101  const sampledSurface& s = operator[](surfi);
102 
103  // Skip surface without faces (eg, failed cut-plane)
104  if (!nFaces_[surfi])
105  {
106  continue;
107  }
108 
109  Field<Type> values;
110 
111  if (s.isPointData())
112  {
113  if (!interpPtr)
114  {
115  interpPtr = interpolation<Type>::New
116  (
117  sampleNodeScheme_,
118  fld
119  );
120  }
121 
122  values = s.interpolate(*interpPtr);
123  }
124  else
125  {
126  if (!samplePtr)
127  {
128  samplePtr = interpolation<Type>::New
129  (
130  sampleFaceScheme_,
131  fld
132  );
133  }
134 
135  values = s.sample(*samplePtr);
136  }
137 
138  if ((request & actions_[surfi]) & ACTION_WRITE)
139  {
140  writeSurface<Type>(writers_[surfi], values, fieldName);
141  }
142 
143  if ((request & actions_[surfi]) & ACTION_SURF_MESH)
144  {
145  // Face fields only!
146  s.storeSurfMeshField<Type, surfGeoMesh>
147  (
148  fieldName, dims, values
149  );
150  }
151 
152  if ((request & actions_[surfi]) & ACTION_STORE)
153  {
154  if (s.isPointData())
155  {
156  storeRegistryField<Type, polySurfacePointGeoMesh>
157  (
158  s, fieldName, dims, std::move(values)
159  );
160  }
161  else
162  {
163  storeRegistryField<Type, polySurfaceGeoMesh>
164  (
165  s, fieldName, dims, std::move(values)
166  );
167  }
168  }
169  }
170 }
171 
172 
173 template<class Type>
174 void Foam::sampledSurfaces::performAction
175 (
176  const GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
177  unsigned request
178 )
179 {
180  const word& fieldName = fld.name();
181 
182  const dimensionSet& dims = fld.dimensions();
183 
184  forAll(*this, surfi)
185  {
186  const sampledSurface& s = (*this)[surfi];
187 
188  // Skip surface without faces (eg, failed cut-plane)
189  if (!nFaces_[surfi])
190  {
191  continue;
192  }
193 
194  Field<Type> values(s.sample(fld));
195 
196  if ((request & actions_[surfi]) & ACTION_WRITE)
197  {
198  writeSurface<Type>(writers_[surfi], values, fieldName);
199  }
200 
201  if ((request & actions_[surfi]) & ACTION_SURF_MESH)
202  {
203  s.storeSurfMeshField<Type, surfGeoMesh>
204  (
205  fieldName, dims, values
206  );
207  }
208 
209  if ((request & actions_[surfi]) & ACTION_STORE)
210  {
211  storeRegistryField<Type, polySurfaceGeoMesh>
212  (
213  s, fieldName, dims, std::move(values)
214  );
215  }
216  }
217 }
218 
219 
220 template<class GeoField>
221 void Foam::sampledSurfaces::performAction
222 (
223  const IOobjectList& objects,
224  unsigned request
225 )
226 {
228  if (loadFromFiles_)
229  {
230  fieldNames = objects.sortedNames<GeoField>(fieldSelection_);
231  }
232  else
233  {
234  fieldNames = mesh_.thisDb().sortedNames<GeoField>(fieldSelection_);
235  }
236 
237  for (const word& fieldName : fieldNames)
238  {
239  if (verbose_)
240  {
241  Info<< "sampleWrite: " << fieldName << endl;
242  }
243 
244  if (loadFromFiles_)
245  {
246  const GeoField fld
247  (
248  IOobject
249  (
250  fieldName,
251  time_.timeName(),
252  mesh_,
254  ),
255  mesh_
256  );
257 
258  performAction(fld, request);
259  }
260  else
261  {
262  performAction
263  (
264  mesh_.thisDb().lookupObject<GeoField>(fieldName),
265  request
266  );
267  }
268  }
269 }
270 
271 
272 template<class Container, class Predicate>
273 bool Foam::sampledSurfaces::testAny
274 (
275  const Container& items,
276  const Predicate& pred
277 )
278 {
279  for (const auto& item : items)
280  {
281  if (pred(item))
282  {
283  return true;
284  }
285  }
286 
287  return false;
288 }
289 
290 
291 // ************************************************************************* //
volFields.H
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
polySurface.H
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
polySurfaceFields.H
Fields for polySurface.
Foam::functionObjects::timeFunctionObject::time_
const Time & time_
Reference to the time database.
Definition: timeFunctionObject.H:65
polySurfacePointFields.H
Point fields for polySurface.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
sampledSurfaces.H
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
outputName
word outputName("finiteArea-edges.obj")
Foam::TimePaths::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: TimePathsI.H:87
Foam::interpolation::New
static autoPtr< interpolation< Type > > New(const word &interpolationType, const GeometricField< Type, fvPatchField, volMesh > &psi)
Return a reference to the specified interpolation scheme.
Definition: interpolationNew.C:36
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
surfGeoMesh.H
propsDict
IOdictionary propsDict(IOobject("particleTrackProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED))
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
surfMesh.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IOobject::groupName
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::functionObjects::stateFunctionObject::setProperty
void setProperty(const word &entryName, const Type &value)
Add generic property.
Definition: stateFunctionObjectTemplates.C:59
Foam::IOobject::MUST_READ
Definition: IOobject.H:185