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 | Copyright (C) 2011 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 Description
25  Patch to patch interpolation functions
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
36 //- Interpolate point field
37 template<class FromPatch, class ToPatch>
38 template<class Type>
39 tmp<Field<Type> >
41 (
42  const Field<Type>& pf
43 ) const
44 {
45  if (pf.size() != fromPatch_.nPoints())
46  {
48  (
49  "PatchToPatchInterpolation::pointInterpolate"
50  "(const Field<Type> pf)"
51  ) << "given field does not correspond to patch. Patch size: "
52  << fromPatch_.nPoints() << " field size: " << pf.size()
53  << abort(FatalError);
54  }
55 
56  tmp<Field<Type> > tresult
57  (
58  new Field<Type>
59  (
60  toPatch_.nPoints(),
62  )
63  );
64 
65  Field<Type>& result = tresult();
66 
67  const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
68  fromPatch_.localFaces();
69 
70  const FieldField<Field, scalar>& weights = pointWeights();
71 
72  const labelList& addr = pointAddr();
73 
74  forAll(result, pointI)
75  {
76  const scalarField& curWeights = weights[pointI];
77 
78  if (addr[pointI] > -1)
79  {
80  const labelList& hitFacePoints =
81  fromPatchLocalFaces[addr[pointI]];
82 
83  forAll(curWeights, wI)
84  {
85  result[pointI] += curWeights[wI]*pf[hitFacePoints[wI]];
86  }
87  }
88  }
89 
90  return tresult;
91 }
92 
93 
94 template<class FromPatch, class ToPatch>
95 template<class Type>
98 (
99  const tmp<Field<Type> >& tpf
100 ) const
101 {
102  tmp<Field<Type> > tint = pointInterpolate<Type>(tpf());
103  tpf.clear();
104  return tint;
105 }
106 
107 
108 //- Interpolate face field
109 template<class FromPatch, class ToPatch>
110 template<class Type>
113 (
114  const Field<Type>& ff
115 ) const
116 {
117  if (ff.size() != fromPatch_.size())
118  {
120  (
121  "PatchToPatchInterpolation::faceInterpolate"
122  "(const Field<Type> ff)"
123  ) << "given field does not correspond to patch. Patch size: "
124  << fromPatch_.size() << " field size: " << ff.size()
125  << abort(FatalError);
126  }
127 
128  tmp<Field<Type> > tresult
129  (
130  new Field<Type>
131  (
132  toPatch_.size(),
134  )
135  );
136 
137  Field<Type>& result = tresult();
138 
139  const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
140 
141  const FieldField<Field, scalar>& weights = faceWeights();
142 
143  const labelList& addr = faceAddr();
144 
145  forAll(result, faceI)
146  {
147  const scalarField& curWeights = weights[faceI];
148 
149  if (addr[faceI] > -1)
150  {
151  const labelList& hitFaceFaces =
152  fromPatchFaceFaces[addr[faceI]];
153 
154  // first add the hit face
155  result[faceI] += ff[addr[faceI]]*curWeights[0];
156 
157  for (label wI = 1; wI < curWeights.size(); wI++)
158  {
159  result[faceI] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
160  }
161  }
162  }
163 
164  return tresult;
165 }
166 
167 
168 template<class FromPatch, class ToPatch>
169 template<class Type>
172 (
173  const tmp<Field<Type> >& tff
174 ) const
175 {
176  tmp<Field<Type> > tint = faceInterpolate(tff());
177  tff.clear();
178  return tint;
179 }
180 
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 } // End namespace Foam
185 
186 // ************************************************************************* //
Generic field type.
Definition: FieldField.H:51
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:174
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
void size(const label)
Override size to be inconsistent with allocated storage.
Namespace for OpenFOAM.
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
#define forAll(list, i)
Definition: UList.H:421
Pre-declare SubField and related Field type.
Definition: Field.H:57
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Traits class for primitives.
Definition: pTraits.H:50
error FatalError
A class for managing temporary objects.
Definition: PtrList.H:118