MapVolFields.H
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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef MapConsistentVolFields_H
30 #define MapConsistentVolFields_H
31 
32 #include "GeometricField.H"
33 #include "meshToMesh.H"
34 #include "IOobjectList.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 template<class Type>
43 {
44  auto& fldBf = fld.boundaryFieldRef();
45 
47  const label startOfRequests = UPstream::nRequests();
48 
49  if
50  (
52  || commsType == UPstream::commsTypes::nonBlocking
53  )
54  {
55  forAll(fldBf, patchi)
56  {
57  fvPatchField<Type>& tgtField = fldBf[patchi];
58 
59  if
60  (
61  tgtField.type() == tgtField.patch().patch().type()
62  && polyPatch::constraintType(tgtField.patch().patch().type())
63  )
64  {
65  tgtField.initEvaluate(commsType);
66  }
67  }
68 
69  // Wait for outstanding requests
70  if (commsType == UPstream::commsTypes::nonBlocking)
71  {
72  UPstream::waitRequests(startOfRequests);
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(commsType);
86  }
87  }
88  }
89  else if (commsType == UPstream::commsTypes::scheduled)
90  {
91  const lduSchedule& patchSchedule =
92  fld.mesh().globalData().patchSchedule();
93 
94  for (const auto& schedEval : patchSchedule)
95  {
96  const label patchi = schedEval.patch;
97 
98  fvPatchField<Type>& tgtField = fldBf[patchi];
99 
100  if
101  (
102  tgtField.type() == tgtField.patch().patch().type()
103  && polyPatch::constraintType(tgtField.patch().patch().type())
104  )
105  {
106  if (schedEval.init)
107  {
108  tgtField.initEvaluate(commsType);
109  }
110  else
111  {
112  tgtField.evaluate(commsType);
113  }
114  }
115  }
116  }
117 }
118 
119 
120 template<class Type, class CombineOp>
121 void MapVolFields
122 (
123  const IOobjectList& objects,
124  const wordRes& selectedFields,
125  const meshToMesh& interp,
126  const CombineOp& cop
127 )
128 {
129  typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
130 
131  const fvMesh& meshSource = static_cast<const fvMesh&>(interp.srcRegion());
132  const fvMesh& meshTarget = static_cast<const fvMesh&>(interp.tgtRegion());
133 
134  // Available fields, sorted order
135  const wordList fieldNames =
136  (
137  selectedFields.empty()
138  ? objects.sortedNames<fieldType>()
139  : objects.sortedNames<fieldType>(selectedFields)
140  );
141 
142  for (const word& fieldName : fieldNames)
143  {
144  const fieldType fieldSource(*(objects[fieldName]), meshSource, false);
145 
146  IOobject targetIO
147  (
148  fieldName,
149  meshTarget.time().timeName(),
150  meshTarget,
152  );
153 
154  if (targetIO.typeHeaderOk<fieldType>(true))
155  {
156  Info<< " interpolating onto existing field "
157  << fieldName << endl;
158 
159  fieldType fieldTarget(targetIO, meshTarget, false);
160 
161  interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
162 
163  evaluateConstraintTypes(fieldTarget);
164 
165  fieldTarget.write();
166  }
167  else
168  {
169  Info<< " creating new field "
170  << fieldName << endl;
171 
172  targetIO.readOpt(IOobject::NO_READ);
173 
174  tmp<fieldType> tfieldTarget
175  (
176  interp.mapSrcToTgt(fieldSource, cop)
177  );
178 
179  fieldType fieldTarget(targetIO, tfieldTarget);
180 
181  evaluateConstraintTypes(fieldTarget);
182 
183  fieldTarget.write();
184  }
185  }
186 }
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
"blocking" : (MPI_Bsend, MPI_Recv)
commsTypes
Types of communications.
Definition: UPstream.H:66
const fvPatch & patch() const noexcept
Return the patch.
Definition: fvPatchField.H:199
static label nRequests() noexcept
Number of outstanding requests.
Definition: UPstream.C:83
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: fvPatchField.H:671
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
#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))
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:290
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.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
messageStream Info
Information stream (stdout output on master, null elsewhere)
void MapVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
Definition: MapVolFields.H:35
const polyPatch & patch() const noexcept
Return the polyPatch.
Definition: fvPatch.H:200
Namespace for OpenFOAM.