PatchToPatchInterpolate.C
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-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2022 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 Description
28  Patch to patch interpolation functions
29 
30 \*---------------------------------------------------------------------------*/
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 
39 template<class FromPatch, class ToPatch>
40 template<class Type>
43 (
44  const Field<Type>& pf
45 ) const
46 {
47  if (pf.size() != fromPatch_.nPoints())
48  {
50  << "given field does not correspond to patch. Patch size: "
51  << fromPatch_.nPoints() << " field size: " << pf.size()
52  << abort(FatalError);
53  }
54 
55  auto tresult = tmp<Field<Type>>::New(toPatch_.nPoints(), Zero);
56  auto& result = tresult.ref();
57 
58  const auto& fromPatchLocalFaces = fromPatch_.localFaces();
59 
60  const FieldField<Field, scalar>& weights = pointWeights();
61 
62  const labelList& addr = pointAddr();
63 
64  forAll(result, pointi)
65  {
66  const scalarField& curWeights = weights[pointi];
67 
68  if (addr[pointi] > -1)
69  {
70  const labelList& hitFacePoints =
71  fromPatchLocalFaces[addr[pointi]];
72 
73  forAll(curWeights, wI)
74  {
75  result[pointi] += curWeights[wI]*pf[hitFacePoints[wI]];
76  }
77  }
78  }
79 
80  return tresult;
81 }
82 
83 
84 template<class FromPatch, class ToPatch>
85 template<class Type>
88 (
89  const tmp<Field<Type>>& tpf
90 ) const
91 {
92  tmp<Field<Type>> tint = pointInterpolate<Type>(tpf());
93  tpf.clear();
94  return tint;
95 }
96 
97 
98 template<class FromPatch, class ToPatch>
99 template<class Type>
102 (
103  const Field<Type>& ff
104 ) const
105 {
106  if (ff.size() != fromPatch_.size())
107  {
109  << "given field does not correspond to patch. Patch size: "
110  << fromPatch_.size() << " field size: " << ff.size()
111  << abort(FatalError);
112  }
113 
114  auto tresult = tmp<Field<Type>>::New(toPatch_.size(), Zero);
115  auto& result = tresult.ref();
116 
117  const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
118 
119  const FieldField<Field, scalar>& weights = faceWeights();
120 
121  const labelList& addr = faceAddr();
122 
123  forAll(result, facei)
124  {
125  const scalarField& curWeights = weights[facei];
126 
127  if (addr[facei] > -1)
128  {
129  const labelList& hitFaceFaces =
130  fromPatchFaceFaces[addr[facei]];
131 
132  // first add the hit face
133  result[facei] += ff[addr[facei]]*curWeights[0];
134 
135  for (label wI = 1; wI < curWeights.size(); wI++)
136  {
137  result[facei] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
138  }
139  }
140  }
141 
142  return tresult;
143 }
145 
146 template<class FromPatch, class ToPatch>
147 template<class Type>
150 (
151  const tmp<Field<Type>>& tff
152 ) const
153 {
154  tmp<Field<Type>> tint = faceInterpolate(tff());
155  tff.clear();
156  return tint;
157 }
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace Foam
163 
164 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Generic templated field type.
Definition: Field.H:62
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition: tmpI.H:289
A class for managing temporary objects.
Definition: HashPtrTable.H:50
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127