cyclicPointPatchField.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 
28 #include "cyclicPointPatchField.H"
29 #include "transformField.H"
30 #include "pointFields.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const pointPatch& p,
39 )
40 :
42  cyclicPatch_(refCast<const cyclicPointPatch>(p))
43 {}
44 
45 
46 template<class Type>
48 (
49  const pointPatch& p,
51  const dictionary& dict
52 )
53 :
54  coupledPointPatchField<Type>(p, iF, dict),
55  cyclicPatch_(refCast<const cyclicPointPatch>(p, dict))
56 {
57  if (!isType<cyclicPointPatch>(p))
58  {
60  << "patch " << this->patch().index() << " not cyclic type. "
61  << "Patch type = " << p.type()
63  }
64 }
65 
66 
67 template<class Type>
69 (
70  const cyclicPointPatchField<Type>& ptf,
71  const pointPatch& p,
72  const DimensionedField<Type, pointMesh>& iF,
73  const pointPatchFieldMapper& mapper
74 )
75 :
76  coupledPointPatchField<Type>(ptf, p, iF, mapper),
77  cyclicPatch_(refCast<const cyclicPointPatch>(p))
78 {
79  if (!isType<cyclicPointPatch>(this->patch()))
80  {
82  << "Field type does not correspond to patch type for patch "
83  << this->patch().index() << "." << endl
84  << "Field type: " << typeName << endl
85  << "Patch type: " << this->patch().type()
87  }
88 }
89 
90 
91 template<class Type>
93 (
94  const cyclicPointPatchField<Type>& ptf,
95  const DimensionedField<Type, pointMesh>& iF
96 )
97 :
98  coupledPointPatchField<Type>(ptf, iF),
99  cyclicPatch_(ptf.cyclicPatch_)
100 {}
101 
102 
103 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104 
105 template<class Type>
107 (
108  const Pstream::commsTypes,
109  Field<Type>& pField
110 ) const
111 {
112  // Get neighbouring pointPatch
113  const cyclicPointPatch& nbrPatch = cyclicPatch_.neighbPatch();
114 
115  if (cyclicPatch_.cyclicPatch().owner())
116  {
117  // We inplace modify pField. To prevent the other side (which gets
118  // evaluated at a later date) using already changed values we do
119  // all swaps on the side that gets evaluated first.
120 
121  // Get neighbouring pointPatchField
123  refCast<const GeometricField<Type, pointPatchField, pointMesh>>
124  (
125  this->internalField()
126  );
127 
128  const cyclicPointPatchField<Type>& nbr =
129  refCast<const cyclicPointPatchField<Type>>
130  (
131  fld.boundaryField()[nbrPatch.index()]
132  );
133 
134 
135  Field<Type> pf(this->patchInternalField(pField));
136  Field<Type> nbrPf(nbr.patchInternalField(pField));
137 
138  const edgeList& pairs = cyclicPatch_.transformPairs();
139 
140  if (doTransform())
141  {
142  // Transform both sides.
143  forAll(pairs, pairi)
144  {
145  label pointi = pairs[pairi][0];
146  label nbrPointi = pairs[pairi][1];
147 
148  Type tmp = pf[pointi];
149  pf[pointi] = transform(forwardT()[0], nbrPf[nbrPointi]);
150  nbrPf[nbrPointi] = transform(reverseT()[0], tmp);
151  }
152  }
153  else
154  {
155  forAll(pairs, pairi)
156  {
157  Foam::Swap(pf[pairs[pairi][0]], nbrPf[pairs[pairi][1]]);
158  }
159  }
160  this->addToInternalField(pField, pf);
161  nbr.addToInternalField(pField, nbrPf);
162  }
163 }
164 
165 
166 // ************************************************************************* //
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
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
Cyclic front and back plane patch field.
Cyclic patch for post-processing.
virtual label index() const
Return the index of this patch in the pointBoundaryMesh.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Spatial transformation functions for primitive fields.
Generic templated field type.
Definition: Field.H:62
virtual void swapAddSeparated(const Pstream::commsTypes commsType, Field< Type > &) const
Complete swap of patch point values and add to local values.
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
cyclicPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Exchange contents of lists - see DynamicList::swap().
Definition: DynamicList.H:692
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const cyclicPointPatch & neighbPatch() const
Return neighbour point patch.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...