cyclicFaPatchField.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cyclicFaPatchField.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const faPatch& p,
38 )
39 :
41  cyclicPatch_(refCast<const cyclicFaPatch>(p))
42 {}
43 
44 
45 template<class Type>
47 (
48  const cyclicFaPatchField<Type>& ptf,
49  const faPatch& p,
51  const faPatchFieldMapper& mapper
52 )
53 :
54  coupledFaPatchField<Type>(ptf, p, iF, mapper),
55  cyclicPatch_(refCast<const cyclicFaPatch>(p))
56 {
57  if (!isA<cyclicFaPatch>(this->patch()))
58  {
60  << "\n patch type '" << p.type()
61  << "' not constraint type '" << typeName << "'"
62  << "\n for patch " << p.name()
63  << " of field " << this->internalField().name()
64  << " in file " << this->internalField().objectPath()
65  << exit(FatalIOError);
66  }
67 }
68 
69 
70 template<class Type>
72 (
73  const faPatch& p,
75  const dictionary& dict
76 )
77 :
79  cyclicPatch_(refCast<const cyclicFaPatch>(p, dict))
80 {
81  if (!isA<cyclicFaPatch>(p))
82  {
84  << "\n patch type '" << p.type()
85  << "' not constraint type '" << typeName << "'"
86  << "\n for patch " << p.name()
87  << " of field " << this->internalField().name()
88  << " in file " << this->internalField().objectPath()
89  << exit(FatalIOError);
90  }
91 
92  this->evaluate(Pstream::commsTypes::blocking);
93 }
94 
95 
96 template<class Type>
98 (
99  const cyclicFaPatchField<Type>& ptf
100 )
101 :
104  cyclicPatch_(ptf.cyclicPatch_)
105 {}
106 
107 
108 template<class Type>
110 (
111  const cyclicFaPatchField<Type>& ptf,
113 )
114 :
115  coupledFaPatchField<Type>(ptf, iF),
116  cyclicPatch_(ptf.cyclicPatch_)
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
122 template<class Type>
125 {
126  const Field<Type>& iField = this->primitiveField();
127  const labelUList& faceCells = cyclicPatch_.faceCells();
128 
129  tmp<Field<Type>> tpnf(new Field<Type>(this->size()));
130  Field<Type>& pnf = tpnf.ref();
131 
132  label sizeby2 = this->size()/2;
133 
134  if (doTransform())
135  {
136  for (label facei=0; facei<sizeby2; ++facei)
137  {
138  pnf[facei] = transform
139  (
140  forwardT()[0], iField[faceCells[facei + sizeby2]]
141  );
142 
143  pnf[facei + sizeby2] = transform
144  (
145  reverseT()[0], iField[faceCells[facei]]
146  );
147  }
148  }
149  else
150  {
151  for (label facei=0; facei<sizeby2; ++facei)
152  {
153  pnf[facei] = iField[faceCells[facei + sizeby2]];
154  pnf[facei + sizeby2] = iField[faceCells[facei]];
155  }
156  }
157 
158  return tpnf;
159 }
160 
161 
162 template<class Type>
164 (
165  solveScalarField& result,
166  const bool add,
167  const solveScalarField& psiInternal,
168  const scalarField& coeffs,
169  const direction cmpt,
170  const Pstream::commsTypes commsType
171 ) const
172 {
173  solveScalarField pnf(this->size());
174 
175  label sizeby2 = this->size()/2;
176  const labelUList& faceCells = cyclicPatch_.faceCells();
177 
178  for (label facei = 0; facei < sizeby2; ++facei)
179  {
180  pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
181  pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
182  }
183 
184  // Transform according to the transformation tensors
185  transformCoupleField(pnf, cmpt);
186 
187  // Multiply the field by coefficients and add into the result
188  if (add)
189  {
190  forAll(faceCells, elemI)
191  {
192  result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
193  }
194  }
195  else
196  {
197  forAll(faceCells, elemI)
198  {
199  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
200  }
201  }
202 }
203 
204 
205 template<class Type>
207 (
208  Field<Type>& result,
209  const bool add,
210  const Field<Type>& psiInternal,
211  const scalarField& coeffs,
212  const Pstream::commsTypes commsType
213 ) const
214 {
215  Field<Type> pnf(this->size());
216 
217  label sizeby2 = this->size()/2;
218  const labelUList& faceCells = cyclicPatch_.faceCells();
219 
220  for (label facei = 0; facei < sizeby2; ++facei)
221  {
222  pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
223  pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
224  }
225 
226  // Multiply the field by coefficients and add into the result
227  if (add)
228  {
229  forAll(faceCells, elemI)
230  {
231  result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
232  }
233  }
234  else
235  {
236  forAll(faceCells, elemI)
237  {
238  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
239  }
240  }
241 }
242 
243 
244 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::FatalIOError
IOerror FatalIOError
Foam::faPatchFieldMapper
Definition: faPatchFieldMapper.H:44
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:519
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::cyclicFaPatchField::cyclicFaPatchField
cyclicFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
Definition: cyclicFaPatchField.C:35
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::Field
Generic templated field type.
Definition: Field.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
cyclicFaPatchField.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::coupledFaPatchField
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Definition: coupledFaPatchField.H:57
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::cyclicFaPatchField::patchNeighbourField
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour coupled given internal cell data.
Definition: cyclicFaPatchField.C:124
Foam::cyclicLduInterfaceField
Abstract base class for cyclic coupled interfaces.
Definition: cyclicLduInterfaceField.H:52
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::UList< label >
Foam::direction
uint8_t direction
Definition: direction.H:52
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::cyclicFaPatchField
Foam::cyclicFaPatchField.
Definition: cyclicFaPatchField.H:59
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:68
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::stringOps::evaluate
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Definition: stringOpsEvaluate.C:37
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::cyclicFaPatchField::updateInterfaceMatrix
virtual void updateInterfaceMatrix(solveScalarField &result, const bool add, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
Definition: cyclicFaPatchField.C:164