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-2015 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  << "given field does not correspond to patch. Patch size: "
49  << fromPatch_.nPoints() << " field size: " << pf.size()
50  << abort(FatalError);
51  }
52 
53  tmp<Field<Type> > tresult
54  (
55  new Field<Type>
56  (
57  toPatch_.nPoints(),
59  )
60  );
61 
62  Field<Type>& result = tresult();
63 
64  const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
65  fromPatch_.localFaces();
66 
67  const FieldField<Field, scalar>& weights = pointWeights();
68 
69  const labelList& addr = pointAddr();
70 
71  forAll(result, pointI)
72  {
73  const scalarField& curWeights = weights[pointI];
74 
75  if (addr[pointI] > -1)
76  {
77  const labelList& hitFacePoints =
78  fromPatchLocalFaces[addr[pointI]];
79 
80  forAll(curWeights, wI)
81  {
82  result[pointI] += curWeights[wI]*pf[hitFacePoints[wI]];
83  }
84  }
85  }
86 
87  return tresult;
88 }
89 
90 
91 template<class FromPatch, class ToPatch>
92 template<class Type>
95 (
96  const tmp<Field<Type> >& tpf
97 ) const
98 {
99  tmp<Field<Type> > tint = pointInterpolate<Type>(tpf());
100  tpf.clear();
101  return tint;
102 }
103 
104 
105 //- Interpolate face field
106 template<class FromPatch, class ToPatch>
107 template<class Type>
110 (
111  const Field<Type>& ff
112 ) const
113 {
114  if (ff.size() != fromPatch_.size())
115  {
117  << "given field does not correspond to patch. Patch size: "
118  << fromPatch_.size() << " field size: " << ff.size()
119  << abort(FatalError);
120  }
121 
122  tmp<Field<Type> > tresult
123  (
124  new Field<Type>
125  (
126  toPatch_.size(),
128  )
129  );
130 
131  Field<Type>& result = tresult();
132 
133  const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
134 
135  const FieldField<Field, scalar>& weights = faceWeights();
136 
137  const labelList& addr = faceAddr();
138 
139  forAll(result, faceI)
140  {
141  const scalarField& curWeights = weights[faceI];
142 
143  if (addr[faceI] > -1)
144  {
145  const labelList& hitFaceFaces =
146  fromPatchFaceFaces[addr[faceI]];
147 
148  // first add the hit face
149  result[faceI] += ff[addr[faceI]]*curWeights[0];
150 
151  for (label wI = 1; wI < curWeights.size(); wI++)
152  {
153  result[faceI] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
154  }
155  }
156  }
157 
158  return tresult;
159 }
160 
161 
162 template<class FromPatch, class ToPatch>
163 template<class Type>
166 (
167  const tmp<Field<Type> >& tff
168 ) const
169 {
170  tmp<Field<Type> > tint = faceInterpolate(tff());
171  tff.clear();
172  return tint;
173 }
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace Foam
179 
180 // ************************************************************************* //
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::PatchToPatchInterpolation::faceInterpolate
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
Definition: PatchToPatchInterpolate.C:110
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:59
Foam::Field< Type >
Foam::FatalError
error FatalError
Foam::PatchToPatchInterpolation::pointInterpolate
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
Definition: PatchToPatchInterpolate.C:41
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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:318
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:59
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50