mappedPatchBaseTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "mappedPatchBase.H"
27 #include "stringOps.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
34 {
36  {
37  return nbrFld;
38  }
39 
41  {
42  treeMapPtr_.clear();
44  patchToPatchIsValid_ = false;
45  nbrMappedPatch().reMapNbr_ = false;
46  }
47 
48  if (usingTree_)
49  {
50  if (treeMapPtr_.empty())
51  {
52  calcMapping();
53  }
54 
55  tmp<Field<Type>> tResult
56  (
58  );
59  treeMapPtr_->distribute(tResult.ref());
60  return transform_.transform().transform(tResult);
61  }
62  else
63  {
64  if
65  (
68  )
69  {
70  calcMapping();
71  }
72 
73  return
75  (
77  ? patchToPatchPtr_->tgtToSrc(nbrFld)
78  : nbrMappedPatch().patchToPatchPtr_->srcToTgt(nbrFld)
79  );
80  }
81 }
82 
83 
84 template<class Type>
87 {
88  tmp<Field<Type>> tResult = fromNeighbour(nbrFld());
89  nbrFld.clear();
90  return tResult;
91 }
92 
93 
94 template<class Type>
97 {
98  if (sameUntransformedPatch())
99  {
100  return fld;
101  }
102 
103  if (nbrPatchIsMapped() && nbrMappedPatch().reMapNbr_)
104  {
105  treeMapPtr_.clear();
106  treeNbrPatchFaceIndices_.clear();
107  patchToPatchIsValid_ = false;
108  nbrMappedPatch().reMapNbr_ = false;
109  }
110 
111  if (usingTree_)
112  {
113  if (treeMapPtr_.empty())
114  {
115  calcMapping();
116  }
117 
118  Field<Type> nbrFld(fld);
119  treeMapPtr_->reverseDistribute(treeNbrPatchFaceIndices_.size(), nbrFld);
120  tmp<Field<Type>> tResult(new Field<Type>(nbrPolyPatch().size()));
121  tResult.ref().rmap(nbrFld, treeNbrPatchFaceIndices_);
122  return transform_.transform().invTransform(tResult);
123  }
124  else
125  {
126  if
127  (
128  !patchToPatchIsValid_
129  && !(symmetric() && nbrMappedPatch().patchToPatchIsValid_)
130  )
131  {
132  calcMapping();
133  }
134 
135  return
136  transform_.transform().invTransform
137  (
138  patchToPatchIsValid_
139  ? patchToPatchPtr_->srcToTgt(fld)
140  : nbrMappedPatch().patchToPatchPtr_->tgtToSrc(fld)
141  );
142  }
143 }
144 
145 
146 template<class Type>
149 {
150  tmp<Field<Type>> tResult = toNeighbour(fld());
151  fld.clear();
152  return tResult;
153 }
154 
155 
156 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
const transformer & transform() const
Return transformation between the coupled patches.
cyclicTransform transform_
The transformation between the patches.
bool sameUntransformedPatch() const
Is the neighbour patch the same as this patch with no transform?
tmp< Field< Type > > toNeighbour(const Field< Type > &fld) const
Map/interpolate patch field to the neighbour patch.
bool symmetric() const
Determine whether the neighbouring patch maps from this patch in.
bool patchToPatchIsValid_
Is the patch-to-patch intersection engine up to date? (if using.
autoPtr< patchToPatch > patchToPatchPtr_
Patch-to-patch intersection engine (if using patch-to-patch)
labelList treeNbrPatchFaceIndices_
Indices of the neighbouring patch faces who's values.
autoPtr< distributionMap > treeMapPtr_
Distributor (if using tree)
bool reMapNbr_
Do we need to re-map the neighbour because this patch moved?
const mappedPatchBase & nbrMappedPatch() const
Get the mapped neighbouring patch.
void calcMapping() const
Calculate mapping.
tmp< Field< Type > > fromNeighbour(const Field< Type > &nbrFld) const
Map/interpolate the neighbour patch field to this patch.
const bool usingTree_
Are we using the tree mapping method, or a patch-to-patch.
bool nbrPatchIsMapped() const
Return whether or not the neighbour patch is of mapped type.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Type transform(const Type &) const
Transform the given type.
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))