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 Foam_MapConsistentVolFields_H
30 #define Foam_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& bfld = fld.boundaryFieldRef();
45 
47 
48  if
49  (
51  || commsType == UPstream::commsTypes::nonBlocking
52  )
53  {
54  const label startOfRequests = UPstream::nRequests();
55 
56  for (auto& pfld : bfld)
57  {
58  if
59  (
60  pfld.type() == pfld.patch().patch().type()
61  && polyPatch::constraintType(pfld.patch().patch().type())
62  )
63  {
64  pfld.initEvaluate(commsType);
65  }
66  }
67 
68  // Wait for outstanding requests (non-blocking)
69  UPstream::waitRequests(startOfRequests);
70 
71  for (auto& pfld : bfld)
72  {
73  if
74  (
75  pfld.type() == pfld.patch().patch().type()
76  && polyPatch::constraintType(pfld.patch().patch().type())
77  )
78  {
79  pfld.evaluate(commsType);
80  }
81  }
82  }
83  else if (commsType == UPstream::commsTypes::scheduled)
84  {
85  const lduSchedule& patchSchedule =
86  fld.mesh().globalData().patchSchedule();
87 
88  for (const auto& schedEval : patchSchedule)
89  {
90  const label patchi = schedEval.patch;
91  auto& pfld = bfld[patchi];
92 
93  if
94  (
95  pfld.type() == pfld.patch().patch().type()
96  && polyPatch::constraintType(pfld.patch().patch().type())
97  )
98  {
99  if (schedEval.init)
100  {
101  pfld.initEvaluate(commsType);
102  }
103  else
104  {
105  pfld.evaluate(commsType);
106  }
107  }
108  }
109  }
110 }
111 
112 
113 template<class Type, class CombineOp>
114 void MapVolFields
115 (
116  const IOobjectList& objects,
117  const wordRes& selectedFields,
118  const meshToMesh& interp,
119  const CombineOp& cop
120 )
121 {
122  typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
123 
124  const fvMesh& meshSource = static_cast<const fvMesh&>(interp.srcRegion());
125  const fvMesh& meshTarget = static_cast<const fvMesh&>(interp.tgtRegion());
126 
127  // Available fields, sorted order
128  for
129  (
130  const IOobject& io :
131  (
132  selectedFields.empty()
133  ? objects.csorted<fieldType>()
134  : objects.csorted<fieldType>(selectedFields)
135  )
136  )
137  {
138  const fieldType fieldSource(io, meshSource, false);
139 
140  IOobject targetIO
141  (
142  io.name(),
143  meshTarget.time().timeName(),
144  meshTarget,
146  );
147 
148  if (targetIO.typeHeaderOk<fieldType>(true))
149  {
150  Info<< " interpolating onto existing field "
151  << targetIO.name() << endl;
152 
153  fieldType fieldTarget(targetIO, meshTarget, false);
154 
155  interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
156 
157  evaluateConstraintTypes(fieldTarget);
158 
159  fieldTarget.write();
160  }
161  else
162  {
163  Info<< " creating new field "
164  << targetIO.name() << endl;
165 
166  targetIO.readOpt(IOobject::NO_READ);
167 
168  tmp<fieldType> tfieldTarget
169  (
170  interp.mapSrcToTgt(fieldSource, cop)
171  );
172 
173  fieldType fieldTarget(targetIO, tfieldTarget);
174 
175  evaluateConstraintTypes(fieldTarget);
176 
177  fieldTarget.write();
178  }
179  }
180 }
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
commsTypes
Communications types.
Definition: UPstream.H:77
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
Generic GeometricField class.
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))
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.
"nonBlocking" (immediate) : (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)
"buffered" : (MPI_Bsend, MPI_Recv)
Namespace for OpenFOAM.