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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Description
27  Patch to patch interpolation functions
28 
29 \*---------------------------------------------------------------------------*/
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
38 template<class FromPatch, class ToPatch>
39 template<class Type>
40 tmp<Field<Type>>
42 (
43  const Field<Type>& pf
44 ) const
45 {
46  if (pf.size() != fromPatch_.nPoints())
47  {
49  << "given field does not correspond to patch. Patch size: "
50  << fromPatch_.nPoints() << " field size: " << pf.size()
51  << abort(FatalError);
52  }
53 
54  tmp<Field<Type>> tresult
55  (
56  new Field<Type>(toPatch_.nPoints(), Zero)
57  );
58 
59  Field<Type>& result = tresult.ref();
60 
61  const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
62  fromPatch_.localFaces();
63 
64  const FieldField<Field, scalar>& weights = pointWeights();
65 
66  const labelList& addr = pointAddr();
67 
68  forAll(result, pointi)
69  {
70  const scalarField& curWeights = weights[pointi];
71 
72  if (addr[pointi] > -1)
73  {
74  const labelList& hitFacePoints =
75  fromPatchLocalFaces[addr[pointi]];
76 
77  forAll(curWeights, wI)
78  {
79  result[pointi] += curWeights[wI]*pf[hitFacePoints[wI]];
80  }
81  }
82  }
83 
84  return tresult;
85 }
86 
87 
88 template<class FromPatch, class ToPatch>
89 template<class Type>
92 (
93  const tmp<Field<Type>>& tpf
94 ) const
95 {
96  tmp<Field<Type>> tint = pointInterpolate<Type>(tpf());
97  tpf.clear();
98  return tint;
99 }
100 
101 
102 template<class FromPatch, class ToPatch>
103 template<class Type>
106 (
107  const Field<Type>& ff
108 ) const
109 {
110  if (ff.size() != fromPatch_.size())
111  {
113  << "given field does not correspond to patch. Patch size: "
114  << fromPatch_.size() << " field size: " << ff.size()
115  << abort(FatalError);
116  }
117 
118  tmp<Field<Type>> tresult
119  (
120  new Field<Type>(toPatch_.size(), Zero)
121  );
122 
123  Field<Type>& result = tresult.ref();
124 
125  const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
126 
127  const FieldField<Field, scalar>& weights = faceWeights();
128 
129  const labelList& addr = faceAddr();
130 
131  forAll(result, facei)
132  {
133  const scalarField& curWeights = weights[facei];
134 
135  if (addr[facei] > -1)
136  {
137  const labelList& hitFaceFaces =
138  fromPatchFaceFaces[addr[facei]];
139 
140  // first add the hit face
141  result[facei] += ff[addr[facei]]*curWeights[0];
142 
143  for (label wI = 1; wI < curWeights.size(); wI++)
144  {
145  result[facei] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
146  }
147  }
148  }
149 
150  return tresult;
151 }
152 
153 
154 template<class FromPatch, class ToPatch>
155 template<class Type>
158 (
159  const tmp<Field<Type>>& tff
160 ) const
161 {
162  tmp<Field<Type>> tint = faceInterpolate(tff());
163  tff.clear();
164  return tint;
165 }
166 
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 } // End namespace Foam
171 
172 // ************************************************************************* //
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::PatchToPatchInterpolation::faceInterpolate
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
Definition: PatchToPatchInterpolate.C:106
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::label
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:62
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::FatalError
error FatalError
Foam::PatchToPatchInterpolation::pointInterpolate
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
Definition: PatchToPatchInterpolate.C:42
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::fv::ff
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Definition: CrankNicolsonDdtScheme.C:272
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102