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-2020 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  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
40 
41  typename VolFieldType::Boundary& fldBf = fld.boundaryFieldRef();
42 
43  if
44  (
47  )
48  {
49  const label nReq = Pstream::nRequests();
50 
51  forAll(fldBf, patchi)
52  {
53  fvPatchField<Type>& tgtField = fldBf[patchi];
54 
55  if
56  (
57  tgtField.type() == tgtField.patch().patch().type()
58  && polyPatch::constraintType(tgtField.patch().patch().type())
59  )
60  {
61  tgtField.initEvaluate(Pstream::defaultCommsType);
62  }
63  }
64 
65  // Block for any outstanding requests
66  if
67  (
70  )
71  {
73  }
74 
75  forAll(fldBf, patchi)
76  {
77  fvPatchField<Type>& tgtField = fldBf[patchi];
78 
79  if
80  (
81  tgtField.type() == tgtField.patch().patch().type()
82  && polyPatch::constraintType(tgtField.patch().patch().type())
83  )
84  {
85  tgtField.evaluate(Pstream::defaultCommsType);
86  }
87  }
88  }
90  {
91  const lduSchedule& patchSchedule =
92  fld.mesh().globalData().patchSchedule();
93 
94  forAll(patchSchedule, patchEvali)
95  {
96  label patchi = patchSchedule[patchEvali].patch;
97  fvPatchField<Type>& tgtField = fldBf[patchi];
98 
99  if
100  (
101  tgtField.type() == tgtField.patch().patch().type()
102  && polyPatch::constraintType(tgtField.patch().patch().type())
103  )
104  {
105  if (patchSchedule[patchEvali].init)
106  {
107  tgtField.initEvaluate(Pstream::commsTypes::scheduled);
108  }
109  else
110  {
111  tgtField.evaluate(Pstream::commsTypes::scheduled);
112  }
113  }
114  }
115  }
116 }
117 
118 
119 template<class Type>
120 bool Foam::functionObjects::mapFields::mapFieldType() const
121 {
122  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
123 
124  const fvMesh& mapRegion = mapRegionPtr_();
125 
126  wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
127 
128  const labelList selected(fieldNames_.matching(fieldNames));
129 
130  for (const label fieldi : selected)
131  {
132  const word& fieldName = fieldNames[fieldi];
133 
134  const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
135 
136  if (!mapRegion.foundObject<VolFieldType>(fieldName))
137  {
138  VolFieldType* tmappedField =
139  new VolFieldType
140  (
141  IOobject
142  (
143  fieldName,
144  time_.timeName(),
145  mapRegion,
148  ),
149  mapRegion,
150  dimensioned<Type>(field.dimensions(), Zero)
151  );
152 
153  tmappedField->store();
154  }
155 
156  VolFieldType& mappedField =
157  mapRegion.template lookupObjectRef<VolFieldType>(fieldName);
158 
159  mappedField = interpPtr_->mapTgtToSrc(field);
160 
161  Log << " " << fieldName << ": interpolated";
162 
163  evaluateConstraintTypes(mappedField);
164  }
165 
166  return !selected.empty();
167 }
168 
169 
170 template<class Type>
171 bool Foam::functionObjects::mapFields::writeFieldType() const
172 {
173  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
174 
175  const fvMesh& mapRegion = mapRegionPtr_();
176 
177  wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
178 
179  const labelList selected(fieldNames_.matching(fieldNames));
180 
181  for (const label fieldi : selected)
182  {
183  const word& fieldName = fieldNames[fieldi];
184 
185  const VolFieldType& mappedField =
186  mapRegion.template lookupObject<VolFieldType>(fieldName);
187 
188  mappedField.write();
189 
190  Log << " " << fieldName << ": written";
191  }
192 
193  return !selected.empty();
194 }
195 
196 
197 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Log
#define Log
Definition: PDRblock.C:35
Foam::lduSchedule
List< lduScheduleEntry > lduSchedule
Definition: lduSchedule.H:76
polyPatch.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
meshToMesh.H
Foam::UPstream::waitRequests
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:262
Foam::UPstream::defaultCommsType
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:281
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
init
mesh init(true)
field
rDeltaTY field()
fld
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))
Definition: gmvOutputLagrangian.H:23
lduSchedule.H
Foam::polyPatch::constraintType
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:277
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
fvMesh.H
Foam::UPstream::commsTypes::nonBlocking
Foam::UPstream::nRequests
static label nRequests()
Get number of outstanding requests.
Definition: UPstream.C:252
Foam::UPstream::commsTypes::scheduled
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::evaluateConstraintTypes
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:42
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::UPstream::commsTypes::blocking