mapFieldsTemplates.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) 2016-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "fvMesh.H"
29 #include "polyPatch.H"
30 #include "lduSchedule.H"
31 #include "meshToMesh.H"
32 
33 template<class Type>
34 void Foam::functionObjects::mapFields::evaluateConstraintTypes
35 (
36  GeometricField<Type, fvPatchField, volMesh>& fld
37 ) const
38 {
39  auto& fldBf = fld.boundaryFieldRef();
40 
42  const label startOfRequests = UPstream::nRequests();
43 
44  if
45  (
47  || commsType == UPstream::commsTypes::nonBlocking
48  )
49  {
50  forAll(fldBf, patchi)
51  {
52  fvPatchField<Type>& tgtField = fldBf[patchi];
53 
54  if
55  (
56  tgtField.type() == tgtField.patch().patch().type()
57  && polyPatch::constraintType(tgtField.patch().patch().type())
58  )
59  {
60  tgtField.initEvaluate(commsType);
61  }
62  }
63 
64  // Wait for outstanding requests
65  if (commsType == UPstream::commsTypes::nonBlocking)
66  {
67  UPstream::waitRequests(startOfRequests);
68  }
69 
70  forAll(fldBf, patchi)
71  {
72  fvPatchField<Type>& tgtField = fldBf[patchi];
73 
74  if
75  (
76  tgtField.type() == tgtField.patch().patch().type()
77  && polyPatch::constraintType(tgtField.patch().patch().type())
78  )
79  {
80  tgtField.evaluate(commsType);
81  }
82  }
83  }
84  else if (commsType == UPstream::commsTypes::scheduled)
85  {
86  const lduSchedule& patchSchedule =
87  fld.mesh().globalData().patchSchedule();
88 
89  for (const auto& schedEval : patchSchedule)
90  {
91  const label patchi = schedEval.patch;
92 
93  fvPatchField<Type>& tgtField = fldBf[patchi];
94 
95  if
96  (
97  tgtField.type() == tgtField.patch().patch().type()
98  && polyPatch::constraintType(tgtField.patch().patch().type())
99  )
100  {
101  if (schedEval.init)
102  {
103  tgtField.initEvaluate(commsType);
104  }
105  else
106  {
107  tgtField.evaluate(commsType);
108  }
109  }
110  }
111  }
112 }
113 
114 
115 template<class Type>
116 bool Foam::functionObjects::mapFields::mapFieldType() const
117 {
118  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
119 
120  const fvMesh& mapRegion = mapRegionPtr_();
121 
122  wordList fieldNames(this->mesh_.sortedNames<VolFieldType>(fieldNames_));
123 
124  const bool processed = !fieldNames.empty();
125 
126  for (const word& fieldName : fieldNames)
127  {
128  const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
129 
130  auto* mapFieldPtr = mapRegion.getObjectPtr<VolFieldType>(fieldName);
131 
132  if (!mapFieldPtr)
133  {
134  mapFieldPtr = new VolFieldType
135  (
136  IOobject
137  (
138  fieldName,
139  time_.timeName(),
140  mapRegion,
144  ),
145  mapRegion,
146  dimensioned<Type>(field.dimensions(), Zero)
147  );
148 
149  mapFieldPtr->store();
150  }
151 
152  auto& mappedField = *mapFieldPtr;
153 
154  mappedField = interpPtr_->mapTgtToSrc(field);
155 
156  Log << " " << fieldName << ": interpolated";
157 
158  evaluateConstraintTypes(mappedField);
159  }
160 
161  return processed;
162 }
163 
164 
165 template<class Type>
166 bool Foam::functionObjects::mapFields::writeFieldType() const
167 {
168  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
169 
170  const fvMesh& mapRegion = mapRegionPtr_();
171 
172  wordList fieldNames(this->mesh_.sortedNames<VolFieldType>(fieldNames_));
173 
174  const bool processed = !fieldNames.empty();
175 
176  for (const word& fieldName : fieldNames)
177  {
178  const VolFieldType& mappedField =
179  mapRegion.template lookupObject<VolFieldType>(fieldName);
180 
181  mappedField.write();
182 
183  Log << " " << fieldName << ": written";
184  }
185 
186  return processed;
187 }
188 
189 
190 // ************************************************************************* //
"blocking" : (MPI_Bsend, MPI_Recv)
rDeltaTY field()
commsTypes
Communications types.
Definition: UPstream.H:72
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Definition: lduSchedule.H:46
Ignore writing from objectRegistry::writeObject()
static void waitRequests()
Wait for all requests to finish.
Definition: UPstream.H:1538
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:35
"scheduled" : (MPI_Send, MPI_Recv)
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))
List< word > wordList
List of word.
Definition: fileName.H:59
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:385
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: polyPatch.C:269
Nothing to be read.
#define Log
Definition: PDRblock.C:28
"nonBlocking" : (MPI_Isend, MPI_Irecv)
Request registration (bool: true)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127