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(FatalError);
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  const 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 lduAddressing& lduAddr,
168  const label patchId,
169  const solveScalarField& psiInternal,
170  const scalarField& coeffs,
171  const direction cmpt,
172  const Pstream::commsTypes commsType
173 ) const
174 {
175  solveScalarField pnf(this->size());
176 
177  const label sizeby2 = this->size()/2;
178  const labelUList& faceCells = cyclicPatch_.faceCells();
179 
180  for (label facei = 0; facei < sizeby2; ++facei)
181  {
182  pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
183  pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
184  }
185 
186  // Transform according to the transformation tensors
187  transformCoupleField(pnf, cmpt);
188 
189  // Multiply the field by coefficients and add into the result
190  if (add)
191  {
192  forAll(faceCells, elemI)
193  {
194  result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
195  }
196  }
197  else
198  {
199  forAll(faceCells, elemI)
200  {
201  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
202  }
203  }
204 }
205 
206 
207 template<class Type>
209 (
210  Field<Type>& result,
211  const bool add,
212  const lduAddressing& lduAddr,
213  const label patchId,
214  const Field<Type>& psiInternal,
215  const scalarField& coeffs,
216  const Pstream::commsTypes commsType
217 ) const
218 {
219  Field<Type> pnf(this->size());
220 
221  const label sizeby2 = this->size()/2;
222  const labelUList& faceCells = cyclicPatch_.faceCells();
223 
224  for (label facei = 0; facei < sizeby2; ++facei)
225  {
226  pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
227  pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
228  }
229 
230  // Multiply the field by coefficients and add into the result
231  if (add)
232  {
233  forAll(faceCells, elemI)
234  {
235  result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
236  }
237  }
238  else
239  {
240  forAll(faceCells, elemI)
241  {
242  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
243  }
244  }
245 }
246 
247 
248 // ************************************************************************* //
Foam::lduAddressing
The class contains the addressing required by the lduMatrix: upper, lower and losort.
Definition: lduAddressing.H:114
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:521
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:227
Foam::Field
Generic templated field type.
Definition: Field.H:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
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::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::coupledFaPatchField
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Definition: coupledFaPatchField.H:57
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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:473
patchId
label patchId(-1)
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:69
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::cyclicFaPatchField::updateInterfaceMatrix
virtual void updateInterfaceMatrix(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, 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
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::stringOps::evaluate
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
Definition: stringOpsEvaluate.C:37