cyclicAMIPointPatchField.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 \*---------------------------------------------------------------------------*/
27 
29 #include "transformField.H"
30 #include "pointFields.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const pointPatch& p,
39 )
40 :
41  coupledPointPatchField<Type>(p, iF),
42  cyclicAMIPatch_(refCast<const cyclicAMIPointPatch>(p)),
43  ppiPtr_(nullptr),
44  nbrPpiPtr_(nullptr)
45 {}
46 
47 
48 template<class Type>
50 (
51  const pointPatch& p,
53  const dictionary& dict
54 )
55 :
56  coupledPointPatchField<Type>(p, iF, dict),
57  cyclicAMIPatch_(refCast<const cyclicAMIPointPatch>(p, dict)),
58  ppiPtr_(nullptr),
59  nbrPpiPtr_(nullptr)
60 {
61  if (!isType<cyclicAMIPointPatch>(p))
62  {
64  << "patch " << this->patch().index() << " not cyclicAMI type. "
65  << "Patch type = " << p.type()
67  }
68 }
69 
70 
71 template<class Type>
73 (
74  const cyclicAMIPointPatchField<Type>& ptf,
75  const pointPatch& p,
76  const DimensionedField<Type, pointMesh>& iF,
77  const pointPatchFieldMapper& mapper
78 )
79 :
80  coupledPointPatchField<Type>(ptf, p, iF, mapper),
81  cyclicAMIPatch_(refCast<const cyclicAMIPointPatch>(p)),
82  ppiPtr_(nullptr),
83  nbrPpiPtr_(nullptr)
84 {
85  if (!isType<cyclicAMIPointPatch>(this->patch()))
86  {
88  << "Field type does not correspond to patch type for patch "
89  << this->patch().index() << "." << endl
90  << "Field type: " << typeName << endl
91  << "Patch type: " << this->patch().type()
93  }
94 }
95 
96 
97 template<class Type>
99 (
100  const cyclicAMIPointPatchField<Type>& ptf,
101  const DimensionedField<Type, pointMesh>& iF
102 )
103 :
104  coupledPointPatchField<Type>(ptf, iF),
105  cyclicAMIPatch_(ptf.cyclicAMIPatch_),
106  ppiPtr_(nullptr),
107  nbrPpiPtr_(nullptr)
108 {}
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
113 template<class Type>
115 {
116  return cyclicAMIPatch_.coupled();
117 }
118 
119 
120 template<class Type>
122 (
123  const Pstream::commsTypes,
124  Field<Type>& pField
125 ) const
126 {
127  if (cyclicAMIPatch_.cyclicAMIPatch().owner())
128  {
129  // We inplace modify pField. To prevent the other side (which gets
130  // evaluated at a later date) using already changed values we do
131  // all swaps on the side that gets evaluated first.
132 
133  // Get neighbouring pointPatch
134  const cyclicAMIPointPatch& nbrPatch = cyclicAMIPatch_.neighbPatch();
135 
136  // Get neighbouring pointPatchField
138  refCast<const GeometricField<Type, pointPatchField, pointMesh>>
139  (
140  this->internalField()
141  );
142 
143  const cyclicAMIPointPatchField<Type>& nbr =
144  refCast<const cyclicAMIPointPatchField<Type>>
145  (
146  fld.boundaryField()[nbrPatch.index()]
147  );
148 
149 
150  Field<Type> ptFld(this->patchInternalField(pField));
151  Field<Type> nbrPtFld(nbr.patchInternalField(pField));
152 
153 
154  if (doTransform())
155  {
156  const tensor& forwardT = this->forwardT()[0];
157  const tensor& reverseT = this->reverseT()[0];
158 
159  transform(ptFld, reverseT, ptFld);
160  transform(nbrPtFld, forwardT, nbrPtFld);
161  }
162 
163  // convert point field to face field, AMI interpolate, then
164  // face back to point
165  {
166  // add neighbour side contribution to owner
167  Field<Type> nbrFcFld(nbrPpi().pointToFaceInterpolate(nbrPtFld));
168 
169  // interpolate to owner
170  if (cyclicAMIPatch_.cyclicAMIPatch().applyLowWeightCorrection())
171  {
172  Field<Type> fcFld(ppi().pointToFaceInterpolate(ptFld));
173 
174  nbrFcFld =
175  cyclicAMIPatch_.cyclicAMIPatch().interpolate
176  (
177  nbrFcFld,
178  fcFld
179  );
180  }
181  else
182  {
183  nbrFcFld =
184  cyclicAMIPatch_.cyclicAMIPatch().interpolate(nbrFcFld);
185  }
186 
187  // add to internal field
188  this->addToInternalField
189  (
190  pField,
191  ppi().faceToPointInterpolate(nbrFcFld)()
192  );
193  }
194 
195  {
196  // add owner side contribution to neighbour
197  Field<Type> fcFld(ppi().pointToFaceInterpolate(ptFld));
198 
199  // interpolate to neighbour
200  if (cyclicAMIPatch_.cyclicAMIPatch().applyLowWeightCorrection())
201  {
202  Field<Type> nbrFcFld(nbrPpi().pointToFaceInterpolate(nbrPtFld));
203 
204  fcFld =
205  cyclicAMIPatch_.cyclicAMIPatch().neighbPatch().interpolate
206  (
207  fcFld,
208  nbrFcFld
209  );
210  }
211  else
212  {
213  fcFld =
214  cyclicAMIPatch_.cyclicAMIPatch().neighbPatch().interpolate
215  (
216  fcFld
217  );
218  }
219 
220  // add to internal field
221  nbr.addToInternalField
222  (
223  pField,
224  nbrPpi().faceToPointInterpolate(fcFld)()
225  );
226  }
227  }
228 }
229 
230 
231 // ************************************************************************* //
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const pointPatch & patch() const noexcept
Return the patch.
commsTypes
Communications types.
Definition: UPstream.H:72
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
cyclicAMIPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual bool coupled() const
Return true if coupled. Note that the underlying patch is not coupled() - the points don&#39;t align...
virtual label index() const
Return the index of this patch in the pointBoundaryMesh.
virtual void swapAddSeparated(const Pstream::commsTypes commsType, Field< Type > &) const
Complete swap of patch point values and add to local values.
Spatial transformation functions for primitive fields.
Cyclic AMI front and back plane patch field.
Generic templated field type.
Definition: Field.H:62
const cyclicAMIPointPatch & neighbPatch() const
Return neighbour point patch.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
virtual label index() const =0
Return the index of this patch in the pointBoundaryMesh.
A Coupled boundary condition for pointField.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
volScalarField & p
Cyclic AMI point patch - place holder only.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
Tensor of scalars, i.e. Tensor<scalar>.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...