sampledSetsTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
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 "sampledSets.H"
27 #include "volFields.H"
28 #include "ListListOps.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 Foam::functionObjects::sampledSets::sampleLocalType
35 (
36  const label seti,
37  const wordList& fieldNames,
38  HashPtrTable<interpolation<Type>>& interpolations
39 )
40 {
41  PtrList<Field<Type>> fieldTypeValues(fieldNames.size());
42 
43  const sampledSet& s = operator[](seti);
44 
45  forAll(fieldNames, fieldi)
46  {
47  const word& name = fieldNames[fieldi];
48 
49  if (mesh_.foundObject<VolField<Type>>(name))
50  {
51  const VolField<Type>& vf =
52  mesh_.lookupObject<VolField<Type>>(name);
53 
54  if (!interpolations.found(name))
55  {
56  interpolations.insert
57  (
58  name,
60  (
61  interpolationScheme_,
62  vf
63  ).ptr()
64  );
65  }
66 
67  const interpolation<Type>& interp = *interpolations[name];
68 
69  tmp<Field<Type>> tfield(new Field<Type>(s.size()));
70  Field<Type>& field = tfield.ref();
71 
72  forAll(s, i)
73  {
74  const point& position = s.positions()[i];
75  const label celli = s.cells()[i];
76  const label facei = s.faces()[i];
77 
78  if (celli == -1 && facei == -1)
79  {
80  // Special condition for illegal sampling points
81  field[i] = pTraits<Type>::max;
82  }
83  else
84  {
85  field[i] = interp.interpolate(position, celli, facei);
86  }
87  }
88 
89  fieldTypeValues.set(fieldi, tfield.ptr());
90  }
91  }
92 
93  return fieldTypeValues;
94 }
95 
96 
97 template<class Type>
99 Foam::functionObjects::sampledSets::sampleType
100 (
101  const label seti,
102  const wordList& fieldNames,
103  HashPtrTable<interpolation<Type>>& interpolations
104 )
105 {
106  PtrList<Field<Type>> fieldTypeValues =
107  sampleLocalType<Type>(seti, fieldNames, interpolations);
108 
109  if (Pstream::parRun())
110  {
111  forAll(fieldNames, fieldi)
112  {
113  if (fieldTypeValues.set(fieldi))
114  {
115  fieldTypeValues[fieldi] =
116  coordSet::gather
117  (
118  fieldTypeValues[fieldi],
119  masterSetOrders_[seti]
120  );
121  }
122  }
123  }
124 
125  return fieldTypeValues;
126 }
127 
128 
129 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Traits class for primitives.
Definition: pTraits.H:50
Generic GeometricField class.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:50
static List< word > fieldNames
Definition: globalFoam.H:46
virtual Type interpolate(const vector &position, const label celli, const label facei=-1) const =0
Interpolate field to the given point in the given cell.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().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))
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:61
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
Abstract base class for interpolation.
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53