BUGFIX: Seg-fault in multiphaseInterFoam. Author: Henrik Rusche. Merge: Hrvoje Jasak
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / fvPatchVectorNFields / cyclicFvPatchVectorNFields.C
blob7964c104bdfb0a082939a75a091ca99b76e2c948
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cyclicFvPatchVectorNFields.H"
27 #include "addToRunTimeSelectionTable.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 #define VectorNMatrixInterfaceFunc(Type)                                      \
37 template<>                                                                    \
38 void cyclicFvPatchField<Type>::updateInterfaceMatrix                          \
39 (                                                                             \
40     const Field<Type>& psiInternal,                                           \
41     Field<Type>& result,                                                      \
42     const BlockLduMatrix<Type>&,                                              \
43     const CoeffField<Type>& coeffs,                                           \
44     const Pstream::commsTypes commsType,                                      \
45     const bool switchToLhs                                                    \
46 ) const                                                                       \
47 {                                                                             \
48     Field<Type> pnf(this->size());                                            \
49                                                                               \
50     label sizeby2 = this->size()/2;                                           \
51     const unallocLabelList& faceCells = cyclicPatch_.faceCells();             \
52                                                                               \
53     for (label facei=0; facei<sizeby2; facei++)                               \
54     {                                                                         \
55         pnf[facei] = psiInternal[faceCells[facei + sizeby2]];                 \
56         pnf[facei + sizeby2] = psiInternal[faceCells[facei]];                 \
57     }                                                                         \
58                                                                               \
59     if (coeffs.activeType() == blockCoeffBase::SCALAR)                        \
60     {                                                                         \
61         pnf = coeffs.asScalar() * pnf;                                        \
62     }                                                                         \
63     else if (coeffs.activeType() == blockCoeffBase::LINEAR)                   \
64     {                                                                         \
65         pnf = cmptMultiply(coeffs.asLinear(), pnf);                           \
66     }                                                                         \
67     else if (coeffs.activeType() == blockCoeffBase::SQUARE)                   \
68     {                                                                         \
69         pnf = coeffs.asSquare() & pnf;                                        \
70     }                                                                         \
71                                                                               \
72     if (switchToLhs)                                                          \
73     {                                                                         \
74         forAll(faceCells, elemI)                                              \
75         {                                                                     \
76             result[faceCells[elemI]] += pnf[elemI];                           \
77         }                                                                     \
78     }                                                                         \
79     else                                                                      \
80     {                                                                         \
81         forAll(faceCells, elemI)                                              \
82         {                                                                     \
83             result[faceCells[elemI]] -= pnf[elemI];                           \
84         }                                                                     \
85     }                                                                         \
89 #define doMakePatchTypeField(type, Type, args...)                             \
90                                                                               \
91 VectorNMatrixInterfaceFunc(type)                                              \
92                                                                               \
93 makeTemplatePatchTypeField                                                    \
94 (                                                                             \
95     fvPatch##Type##Field,                                                     \
96     cyclicFvPatch##Type##Field                                                \
99 forAllVectorNTypes(doMakePatchTypeField)
101 #undef doMakePatchTypeField
103 #undef VectorNMatrixInterfaceFunc
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 } // End namespace Foam
109 // ************************************************************************* //