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 PatchFieldType, class FieldType>
33 (
34  const PatchFieldType& field,
35  const FieldType& iF,
36  const dictionary& context,
37  const label froms
38 )
39 {
40  const polyPatch& pp = field.patch().patch();
41 
42  if (!isA<mappedPatchBase>(pp))
43  {
44  OStringStream str;
45  str << "Field " << iF.name() << " of type "
46  << field.type() << " cannot apply to patch " << pp.name()
47  << " because the patch is not of " << typeName << " type";
48  FatalIOErrorInFunction(context)
49  << stringOps::breakIntoIndentedLines(str.str()).c_str()
50  << exit(FatalIOError);
51  }
52 
53  refCast<const mappedPatchBase>(pp).validateForField
54  (
55  field,
56  iF,
57  context,
58  froms
59  );
60 }
61 
62 
63 template<class PatchFieldType, class FieldType>
65 (
66  const PatchFieldType& field,
67  const FieldType& iF,
68  const dictionary& context,
69  const label froms
70 ) const
71 {
72  const bool isNotRegion = !sameRegion() && (froms & from::sameRegion);
73  const bool isRegion = sameRegion() && (froms & from::differentRegion);
74  const bool isPatch = samePatch() && (froms & from::differentPatch);
75 
76  OStringStream str;
77 
78  if (isNotRegion || isRegion || isPatch)
79  {
80  str << "Field " << iF.name() << " of type "
81  << field.type() << " cannot apply to patch " << patch_.name()
82  << " because values are mapped from ";
83  }
84 
85  if (isNotRegion)
86  {
87  str << "a different region";
88  }
89  else if (isRegion)
90  {
91  str << "within the same region";
92  }
93  else if (isPatch)
94  {
95  str << "the same patch";
96  }
97 
98  if (isNotRegion || isRegion || isPatch)
99  {
100  FatalIOErrorInFunction(context)
101  << stringOps::breakIntoIndentedLines(str.str()).c_str()
102  << exit(FatalIOError);
103  }
104 }
105 
106 
107 template<class Type>
110 {
111  if (sameUntransformedPatch())
112  {
113  return nbrFld;
114  }
115 
116  if (nbrPatchIsMapped() && nbrMappedPatch().reMapNbr_)
117  {
118  treeMapPtr_.clear();
119  treeNbrPatchFaceIndices_.clear();
120  patchToPatchIsValid_ = false;
121  nbrMappedPatch().reMapNbr_ = false;
122  }
123 
124  if (usingTree_)
125  {
126  if (treeMapPtr_.empty())
127  {
128  calcMapping();
129  }
130 
131  tmp<Field<Type>> tResult
132  (
133  new Field<Type>(nbrFld, treeNbrPatchFaceIndices_)
134  );
135  treeMapPtr_->distribute(tResult.ref());
136  return transform_.transform().transform(tResult);
137  }
138  else
139  {
140  if
141  (
142  !patchToPatchIsValid_
143  && !(symmetric() && nbrMappedPatch().patchToPatchIsValid_)
144  )
145  {
146  calcMapping();
147  }
148 
149  return
150  transform_.transform().transform
151  (
152  patchToPatchIsValid_
153  ? patchToPatchPtr_->tgtToSrc(nbrFld)
154  : nbrMappedPatch().patchToPatchPtr_->srcToTgt(nbrFld)
155  );
156  }
157 }
158 
159 
160 template<class Type>
163 {
164  tmp<Field<Type>> tResult = fromNeighbour(nbrFld());
165  nbrFld.clear();
166  return tResult;
167 }
168 
169 
170 template<class Type>
173 {
174  if (sameUntransformedPatch())
175  {
176  return fld;
177  }
178 
179  if (nbrPatchIsMapped() && nbrMappedPatch().reMapNbr_)
180  {
181  treeMapPtr_.clear();
182  treeNbrPatchFaceIndices_.clear();
183  patchToPatchIsValid_ = false;
184  nbrMappedPatch().reMapNbr_ = false;
185  }
186 
187  if (usingTree_)
188  {
189  if (treeMapPtr_.empty())
190  {
191  calcMapping();
192  }
193 
194  Field<Type> nbrFld(fld);
195  treeMapPtr_->reverseDistribute(treeNbrPatchFaceIndices_.size(), nbrFld);
196  tmp<Field<Type>> tResult(new Field<Type>(nbrPolyPatch().size()));
197  tResult.ref().rmap(nbrFld, treeNbrPatchFaceIndices_);
198  return transform_.transform().invTransform(tResult);
199  }
200  else
201  {
202  if
203  (
204  !patchToPatchIsValid_
205  && !(symmetric() && nbrMappedPatch().patchToPatchIsValid_)
206  )
207  {
208  calcMapping();
209  }
210 
211  return
212  transform_.transform().invTransform
213  (
214  patchToPatchIsValid_
215  ? patchToPatchPtr_->srcToTgt(fld)
216  : nbrMappedPatch().patchToPatchPtr_->tgtToSrc(fld)
217  );
218  }
219 }
220 
221 
222 template<class Type>
225 {
226  tmp<Field<Type>> tResult = toNeighbour(fld());
227  fld.clear();
228  return tResult;
229 }
230 
231 
232 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:82
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
fileType type(const bool checkVariants=true, const bool followLink=true) const
Return the file type: file, directory, undefined or.
Definition: fileName.C:52
tmp< Field< Type > > toNeighbour(const Field< Type > &fld) const
Map/interpolate patch field to the neighbour patch.
static void validateMapForField(const PatchFieldType &field, const FieldType &iF, const dictionary &context, const label froms=from::any)
Validate that the map exists and is appropriate for the given.
void validateForField(const PatchFieldType &field, const FieldType &iF, const dictionary &context, const label froms=from::any) const
Validate that the map is appropriate for the given.
tmp< Field< Type > > fromNeighbour(const Field< Type > &nbrFld) const
Map/interpolate the neighbour patch field to this patch.
const word & name() const
Return name.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
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
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
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))
string breakIntoIndentedLines(const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
Break a string up into indented lines.
Definition: stringOps.C:950
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
IOerror FatalIOError