cyclicPointPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 \*---------------------------------------------------------------------------*/
25 
26 #include "cyclicPointPatchField.H"
27 #include "Swap.H"
28 #include "transformField.H"
29 #include "pointFields.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const pointPatch& p,
38 )
39 :
41  cyclicPatch_(refCast<const cyclicPointPatch>(p))
42 {}
43 
44 
45 template<class Type>
47 (
48  const pointPatch& p,
50  const dictionary& dict
51 )
52 :
54  cyclicPatch_(refCast<const cyclicPointPatch>(p))
55 {
56  if (!isType<cyclicPointPatch>(p))
57  {
59  (
60  dict
61  ) << "patch " << this->patch().index() << " not cyclic type. "
62  << "Patch type = " << p.type()
63  << exit(FatalIOError);
64  }
65 }
66 
67 
68 template<class Type>
70 (
71  const cyclicPointPatchField<Type>& ptf,
72  const pointPatch& p,
74  const pointPatchFieldMapper& mapper
75 )
76 :
77  coupledPointPatchField<Type>(ptf, p, iF, mapper),
78  cyclicPatch_(refCast<const cyclicPointPatch>(p))
79 {
80  if (!isType<cyclicPointPatch>(this->patch()))
81  {
83  << "Field type does not correspond to patch type for patch "
84  << this->patch().index() << "." << endl
85  << "Field type: " << typeName << endl
86  << "Patch type: " << this->patch().type()
87  << exit(FatalError);
88  }
89 }
90 
91 
92 template<class Type>
94 (
95  const cyclicPointPatchField<Type>& ptf,
97 )
98 :
100  cyclicPatch_(ptf.cyclicPatch_)
101 {}
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
106 template<class Type>
108 (
109  const Pstream::commsTypes,
110  Field<Type>& pField
111 ) const
112 {
113  // Get neighbouring pointPatch
114  const cyclicPointPatch& nbrPatch = cyclicPatch_.nbrPatch();
115 
116  if (cyclicPatch_.cyclicPatch().owner())
117  {
118  // We inplace modify pField. To prevent the other side (which gets
119  // evaluated at a later date) using already changed values we do
120  // all swaps on the side that gets evaluated first.
121 
122  // Get neighbouring pointPatchField
124  refCast<const GeometricField<Type, pointPatchField, pointMesh>>
125  (
126  this->internalField()
127  );
128 
129  const cyclicPointPatchField<Type>& nbr =
130  refCast<const cyclicPointPatchField<Type>>
131  (
132  fld.boundaryField()[nbrPatch.index()]
133  );
134 
135 
136  Field<Type> pf(this->patchInternalField(pField));
137  Field<Type> nbrPf(nbr.patchInternalField(pField));
138 
139  const edgeList& pairs = cyclicPatch_.transformPairs();
140 
141  if (transform().template transforms<Type>())
142  {
143  // Transform both sides.
144  forAll(pairs, pairi)
145  {
146  label pointi = pairs[pairi][0];
147  label nbrPointi = pairs[pairi][1];
148 
149  Type tmp = pf[pointi];
150  pf[pointi] = transform().transform(nbrPf[nbrPointi]);
151  nbrPf[nbrPointi] = transform().invTransform(tmp);
152  }
153  }
154  else
155  {
156  forAll(pairs, pairi)
157  {
158  Swap(pf[pairs[pairi][0]], nbrPf[pairs[pairi][1]]);
159  }
160  }
161 
162  this->addToInternalField(pField, pf);
163  nbr.addToInternalField(pField, nbrPf);
164  }
165 }
166 
167 
168 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
const Boundary & boundaryField() const
Return const-reference to the boundary field.
commsTypes
Types of communications.
Definition: UPstream.H:64
Foam::pointPatchFieldMapper.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const cyclicPointPatch & nbrPatch() const
Return neighbour point patch.
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.
Spatial transformation functions for primitive fields.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void Swap(T &a, T &b)
Definition: Swap.H:43
Pre-declare SubField and related Field type.
Definition: Field.H:56
virtual void swapAddSeparated(const Pstream::commsTypes commsType, Field< Type > &) const
Complete swap of patch point values and add to local values.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
A Coupled boundary condition for pointField.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
cyclicPointPatchField(const pointPatch &, const DimensionedField< Type, pointMesh > &)
Construct from patch and internal field.
Swap its arguments.
friend dimensionSet transform(const dimensionSet &)
Return the argument; transformations do not change the dimensions.
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:477
IOerror FatalIOError