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-2023 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  for
136  (
137  const IOobject& io :
138  (
139  selectedFields.empty()
140  ? objects.csorted<fieldType>()
141  : objects.csorted<fieldType>(selectedFields)
142  )
143  )
144  {
145  const fieldType fieldSource(io, meshSource, false);
146 
147  IOobject targetIO
148  (
149  io.name(),
150  meshTarget.time().timeName(),
151  meshTarget,
153  );
154 
155  if (targetIO.typeHeaderOk<fieldType>(true))
156  {
157  Info<< " interpolating onto existing field "
158  << targetIO.name() << endl;
159 
160  fieldType fieldTarget(targetIO, meshTarget, false);
161 
162  interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
163 
164  evaluateConstraintTypes(fieldTarget);
165 
166  fieldTarget.write();
167  }
168  else
169  {
170  Info<< " creating new field "
171  << targetIO.name() << endl;
172 
173  targetIO.readOpt(IOobject::NO_READ);
174 
175  tmp<fieldType> tfieldTarget
176  (
177  interp.mapSrcToTgt(fieldSource, cop)
178  );
179 
180  fieldType fieldTarget(targetIO, tfieldTarget);
181 
182  evaluateConstraintTypes(fieldTarget);
183 
184  fieldTarget.write();
185  }
186  }
187 }
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
"blocking" : (MPI_Bsend, MPI_Recv)
commsTypes
Communications types.
Definition: UPstream.H:72
const fvPatch & patch() const noexcept
Return the patch.
Definition: fvPatchField.H:269
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
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:758
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
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))
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
Definition: fvPatchField.C:329
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.
"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:36
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
const polyPatch & patch() const noexcept
Return the polyPatch.
Definition: fvPatch.H:202
Namespace for OpenFOAM.