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& bfld = fld.boundaryFieldRef();
40 
42 
43  if
44  (
46  || commsType == UPstream::commsTypes::nonBlocking
47  )
48  {
49  const label startOfRequests = UPstream::nRequests();
50 
51  for (auto& pfld : bfld)
52  {
53  if
54  (
55  pfld.type() == pfld.patch().patch().type()
56  && polyPatch::constraintType(pfld.patch().patch().type())
57  )
58  {
59  pfld.initEvaluate(commsType);
60  }
61  }
62 
63  // Wait for outstanding requests (non-blocking)
64  UPstream::waitRequests(startOfRequests);
65 
66  for (auto& pfld : bfld)
67  {
68  if
69  (
70  pfld.type() == pfld.patch().patch().type()
71  && polyPatch::constraintType(pfld.patch().patch().type())
72  )
73  {
74  pfld.evaluate(commsType);
75  }
76  }
77  }
78  else if (commsType == UPstream::commsTypes::scheduled)
79  {
80  const lduSchedule& patchSchedule =
81  fld.mesh().globalData().patchSchedule();
82 
83  for (const auto& schedEval : patchSchedule)
84  {
85  const label patchi = schedEval.patch;
86  auto& pfld = bfld[patchi];
87 
88  if
89  (
90  pfld.type() == pfld.patch().patch().type()
91  && polyPatch::constraintType(pfld.patch().patch().type())
92  )
93  {
94  if (schedEval.init)
95  {
96  pfld.initEvaluate(commsType);
97  }
98  else
99  {
100  pfld.evaluate(commsType);
101  }
102  }
103  }
104  }
105 }
106 
107 
108 template<class Type>
109 bool Foam::functionObjects::mapFields::mapFieldType() const
110 {
111  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
112 
113  const fvMesh& mapRegion = mapRegionPtr_();
114 
115  wordList fieldNames(this->mesh_.sortedNames<VolFieldType>(fieldNames_));
116 
117  const bool processed = !fieldNames.empty();
118 
119  for (const word& fieldName : fieldNames)
120  {
121  const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
122 
123  auto* mapFieldPtr = mapRegion.getObjectPtr<VolFieldType>(fieldName);
124 
125  if (!mapFieldPtr)
126  {
127  mapFieldPtr = new VolFieldType
128  (
129  IOobject
130  (
131  fieldName,
132  time_.timeName(),
133  mapRegion,
137  ),
138  mapRegion,
139  dimensioned<Type>(field.dimensions(), Zero)
140  );
141 
142  mapFieldPtr->store();
143  }
144 
145  auto& mappedField = *mapFieldPtr;
146 
147  mappedField = interpPtr_->mapTgtToSrc(field);
148 
149  Log << " " << fieldName << ": interpolated";
150 
151  evaluateConstraintTypes(mappedField);
152  }
153 
154  return processed;
155 }
156 
157 
158 template<class Type>
159 bool Foam::functionObjects::mapFields::writeFieldType() const
160 {
161  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
162 
163  const fvMesh& mapRegion = mapRegionPtr_();
164 
165  wordList fieldNames(this->mesh_.sortedNames<VolFieldType>(fieldNames_));
166 
167  const bool processed = !fieldNames.empty();
168 
169  for (const word& fieldName : fieldNames)
170  {
171  const VolFieldType& mappedField =
172  mapRegion.template lookupObject<VolFieldType>(fieldName);
173 
174  mappedField.write();
175 
176  Log << " " << fieldName << ": written";
177  }
178 
179  return processed;
180 }
181 
182 
183 // ************************************************************************* //
rDeltaTY field()
commsTypes
Communications types.
Definition: UPstream.H:77
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:1561
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:35
"scheduled" (MPI standard) : (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:397
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: polyPatch.C:255
Nothing to be read.
#define Log
Definition: PDRblock.C:28
"nonBlocking" (immediate) : (MPI_Isend, MPI_Irecv)
"buffered" : (MPI_Bsend, MPI_Recv)
Request registration (bool: true)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127