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_.names(VolFieldType::typeName));
123 
124  const labelList selected(fieldNames_.matching(fieldNames));
125 
126  for (const label fieldi : selected)
127  {
128  const word& fieldName = fieldNames[fieldi];
129 
130  const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
131 
132  if (!mapRegion.foundObject<VolFieldType>(fieldName))
133  {
134  VolFieldType* tmappedField =
135  new VolFieldType
136  (
137  IOobject
138  (
139  fieldName,
140  time_.timeName(),
141  mapRegion,
144  ),
145  mapRegion,
146  dimensioned<Type>(field.dimensions(), Zero)
147  );
148 
149  tmappedField->store();
150  }
151 
152  VolFieldType& mappedField =
153  mapRegion.template lookupObjectRef<VolFieldType>(fieldName);
154 
155  mappedField = interpPtr_->mapTgtToSrc(field);
156 
157  Log << " " << fieldName << ": interpolated";
158 
159  evaluateConstraintTypes(mappedField);
160  }
161 
162  return !selected.empty();
163 }
164 
165 
166 template<class Type>
167 bool Foam::functionObjects::mapFields::writeFieldType() const
168 {
169  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
170 
171  const fvMesh& mapRegion = mapRegionPtr_();
172 
173  wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
174 
175  const labelList selected(fieldNames_.matching(fieldNames));
176 
177  for (const label fieldi : selected)
178  {
179  const word& fieldName = fieldNames[fieldi];
180 
181  const VolFieldType& mappedField =
182  mapRegion.template lookupObject<VolFieldType>(fieldName);
183 
184  mappedField.write();
185 
186  Log << " " << fieldName << ": written";
187  }
188 
189  return !selected.empty();
190 }
191 
192 
193 // ************************************************************************* //
"blocking" : (MPI_Bsend, MPI_Recv)
rDeltaTY field()
commsTypes
Types of communications.
Definition: UPstream.H:66
static label nRequests() noexcept
Number of outstanding requests.
Definition: UPstream.C:83
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Definition: lduSchedule.H:46
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:35
"scheduled" : (MPI_Send, MPI_Recv)
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:93
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
A List of words.
Definition: fileName.H:58
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:337
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: polyPatch.C:270
Nothing to be read.
#define Log
Definition: PDRblock.C:28
"nonBlocking" : (MPI_Isend, MPI_Irecv)
List< label > labelList
A List of labels.
Definition: List.H:62
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157