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 
50  {
51  const VolField<Type>& vf =
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] =
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
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
bool set(const label) const
Is element set.
Definition: PtrListI.H:62
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
const T & operator[](const label) const
Return element const reference.
Definition: UPtrListI.H:105
Tuple2< coordSet, labelList > gather() const
Combine coordinate sets onto the master. Return both the combined.
Definition: coordSet.C:409
const word & name() const
Return the name of this functionObject.
const fvMesh & mesh_
Reference to the fvMesh.
Abstract base class for interpolation.
Definition: interpolation.H:55
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.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
bool foundObject(const word &name) const
Is the named Type in registry.
Traits class for primitives.
Definition: pTraits.H:53
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
A class for managing temporary objects.
Definition: tmp.H:55
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
A class for handling words, derived from string.
Definition: word.H:62
static List< word > fieldNames
Definition: globalFoam.H:46
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59