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 {
45  Boundary& fldBf = fld.boundaryFieldRef();
46 
47  if
48  (
51  )
52  {
53  const label nReq = Pstream::nRequests();
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  {
66  }
67  }
68 
69  // Block for any outstanding requests
70  if
71  (
74  )
75  {
77  }
78 
79  forAll(fldBf, patchi)
80  {
81  fvPatchField<Type>& tgtField = fldBf[patchi];
82 
83  if
84  (
85  tgtField.type() == tgtField.patch().patch().type()
86  && polyPatch::constraintType(tgtField.patch().patch().type())
87  )
88  {
90  }
91  }
92  }
94  {
95  const lduSchedule& patchSchedule =
96  fld.mesh().globalData().patchSchedule();
97 
98  forAll(patchSchedule, patchEvali)
99  {
100  label patchi = patchSchedule[patchEvali].patch;
101  fvPatchField<Type>& tgtField = fldBf[patchi];
102 
103  if
104  (
105  tgtField.type() == tgtField.patch().patch().type()
106  && polyPatch::constraintType(tgtField.patch().patch().type())
107  )
108  {
109  if (patchSchedule[patchEvali].init)
110  {
112  }
113  else
114  {
116  }
117  }
118  }
119  }
120 }
121 
122 
123 template<class Type, class CombineOp>
124 void MapVolFields
125 (
126  const IOobjectList& objects,
127  const wordRes& selectedFields,
128  const meshToMesh& interp,
129  const CombineOp& cop
130 )
131 {
133 
134  const fvMesh& meshSource = static_cast<const fvMesh&>(interp.srcRegion());
135  const fvMesh& meshTarget = static_cast<const fvMesh&>(interp.tgtRegion());
136 
137  // Available fields, sorted order
138  const wordList fieldNames =
139  (
140  selectedFields.empty()
141  ? objects.sortedNames<fieldType>()
142  : objects.sortedNames<fieldType>(selectedFields)
143  );
144 
145  for (const word& fieldName : fieldNames)
146  {
147  const fieldType fieldSource(*(objects[fieldName]), meshSource, false);
148 
149  IOobject targetIO
150  (
151  fieldName,
152  meshTarget.time().timeName(),
153  meshTarget,
155  );
156 
157  if (targetIO.typeHeaderOk<fieldType>(true))
158  {
159  Info<< " interpolating onto existing field "
160  << fieldName << endl;
161 
162  fieldType fieldTarget(targetIO, meshTarget, false);
163 
164  interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
165 
166  evaluateConstraintTypes(fieldTarget);
167 
168  fieldTarget.write();
169  }
170  else
171  {
172  Info<< " creating new field "
173  << fieldName << endl;
174 
175  targetIO.readOpt(IOobject::NO_READ);
176 
177  tmp<fieldType> tfieldTarget
178  (
179  interp.mapSrcToTgt(fieldSource, cop)
180  );
181 
182  fieldType fieldTarget(targetIO, tfieldTarget);
183 
184  evaluateConstraintTypes(fieldTarget);
185 
186  fieldTarget.write();
187  }
188  }
189 }
190 
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 } // End namespace Foam
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
meshToMesh.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
Foam::UPstream::waitRequests
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:262
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::UPstream::defaultCommsType
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:281
Foam::fvPatchField::initEvaluate
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: fvPatchField.H:456
Foam::meshToMesh::mapSrcToTgt
void mapSrcToTgt(const UList< Type > &srcFld, const CombineOp &cop, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
Definition: meshToMeshTemplates.C:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::meshToMesh
Class to calculate the cell-addressing between two overlapping meshes.
Definition: meshToMesh.H:64
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
init
mesh init(true)
Foam::fvPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:341
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
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()))
Foam::meshToMesh::srcRegion
const polyMesh & srcRegion() const
Return const access to the source mesh.
Definition: meshToMeshI.H:33
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::MapVolFields
void MapVolFields(const IOobjectList &objects, const meshToMesh0 &meshToMesh0Interp, const meshToMesh0::order &mapOrder, const CombineOp &cop)
Definition: MapVolFields.H:42
GeometricField.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::List< lduScheduleEntry >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::meshToMesh::tgtRegion
const polyMesh & tgtRegion() const
Return const access to the target mesh.
Definition: meshToMeshI.H:39
Foam::fvPatch::patch
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:161
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::evaluateConstraintTypes
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
Definition: MapVolFields.H:42
Foam::fvPatchField::patch
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:357
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::UPstream::commsTypes::blocking
Foam::IOobject::MUST_READ
Definition: IOobject.H:185