Turbulent moving immersed boundary fixes. Inno Gatin
[foam-extend-3.2.git] / src / immersedBoundary / immersedBoundaryTurbulence / wallFunctions / immersedBoundaryWallFunctions / immersedBoundaryWallFunctionFvPatchField.C
blobd54f025b6f78ccb43236e1fe538415cbf4288e53
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 "immersedBoundaryWallFunctionFvPatchField.H"
27 #include "fvPatchFieldMapper.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "wallFvPatch.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
35 namespace incompressible
37 namespace RASModels
40 // * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
44 template<class Type>
45 void immersedBoundaryWallFunctionFvPatchField<Type>::setIbCellValues
47     const Field<Type>& ibcValues
48 ) const
50     const labelList& ibc = this->ibPatch().ibCells();
52     if (ibcValues.size() != ibc.size())
53     {
54         FatalErrorIn
55         (
56             "template<class Type>\n"
57             "void immersedBoundaryWallFunctionFvPatchField<Type>::"
58             "setIbCellValues\n"
59             "(\n"
60             "    const Field<Type>& ibcValues\n"
61             ") const"
62         )   << "Size of ibcValues field not equal to the number of IB cells."
63             << nl << "ibcValues: " << ibcValues.size()
64             << " ibc: " << ibc.size()
65             << abort(FatalError);
66     }
68     // Get non-const access to internal field
69     Field<Type>& psiI = const_cast<Field<Type>&>(this->internalField());
71     if (wallValue_.empty() || wallMask_.empty())
72     {
73         immersedBoundaryFvPatchField<Type>::setIbCellValues(ibcValues);
74     }
75     else
76     {
77         forAll (ibcValues, cellI)
78         {
79             // If mask is set use the wall value, otherwise use the
80             // fitted value
81             if (wallMask_[cellI])
82             {
83                 psiI[ibc[cellI]] = wallValue_[cellI];
84             }
85             else
86             {
87                 psiI[ibc[cellI]] = ibcValues[cellI];
88             }
89         }
90     }
94 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
96 template<class Type>
97 immersedBoundaryWallFunctionFvPatchField<Type>::
98 immersedBoundaryWallFunctionFvPatchField
100     const fvPatch& p,
101     const DimensionedField<Type, volMesh>& iF
104     immersedBoundaryFvPatchField<Type>(p, iF),
105     wallValue_(),
106     wallMask_()
110 template<class Type>
111 immersedBoundaryWallFunctionFvPatchField<Type>::
112 immersedBoundaryWallFunctionFvPatchField
114     const fvPatch& p,
115     const DimensionedField<Type, volMesh>& iF,
116     const dictionary& dict
119     immersedBoundaryFvPatchField<Type>(p, iF, dict),
120     wallValue_(),
121     wallMask_()
125 template<class Type>
126 immersedBoundaryWallFunctionFvPatchField<Type>::
127 immersedBoundaryWallFunctionFvPatchField
129     const immersedBoundaryWallFunctionFvPatchField& ptf,
130     const fvPatch& p,
131     const DimensionedField<Type, volMesh>& iF,
132     const fvPatchFieldMapper& mapper
135     immersedBoundaryFvPatchField<Type>(ptf, p, iF, mapper),
136     wallValue_(),
137     wallMask_()
141 template<class Type>
142 immersedBoundaryWallFunctionFvPatchField<Type>::
143 immersedBoundaryWallFunctionFvPatchField
145     const immersedBoundaryWallFunctionFvPatchField& tkqrwfpf
148     immersedBoundaryFvPatchField<Type>(tkqrwfpf),
149     wallValue_(),
150     wallMask_()
154 template<class Type>
155 immersedBoundaryWallFunctionFvPatchField<Type>::
156 immersedBoundaryWallFunctionFvPatchField
158     const immersedBoundaryWallFunctionFvPatchField& tkqrwfpf,
159     const DimensionedField<Type, volMesh>& iF
162     immersedBoundaryFvPatchField<Type>(tkqrwfpf, iF),
163     wallValue_(),
164     wallMask_()
168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
170 template<class Type>
171 Foam::Field<Type>& immersedBoundaryWallFunctionFvPatchField<Type>::wallValue() const
173     // Note: on a moving mesh, the intersection has changed and
174     // wallValue fields should be cleared and recalculated.
175     // This should happen only once, but I cannot see the mechanism
176     // HJ, 17/Oct/2012
177     // Bugfix 30/OCT/2015 - check if the mesh is moving
179     const immersedBoundaryFvPatch& ibFvP =
180         immersedBoundaryFvPatchField<Type>::ibPatch();
182     if 
183     (
184         wallValue_.empty() 
185      || (ibFvP.movingIb() || ibFvP.boundaryMesh().mesh().moving())
186     )
187     {
188         wallValue_.setSize
189         (
190             this->ibPatch().ibCells().size(),
191             pTraits<Type>::zero
192         );
193     }
194     
195     return wallValue_;
199 template<class Type>
200 Foam::boolList& immersedBoundaryWallFunctionFvPatchField<Type>::wallMask() const
202     // Note: on a moving mesh, the intersection has changed and
203     // wallValue fields should be cleared and recalculated.
204     // This should happen only once, but I cannot see the mechanism
205     // HJ, 17/Oct/2012
206     // Bugfix 30/OCT/2015 - check if the mesh is moving
207     const immersedBoundaryFvPatch& ibFvP =
208         immersedBoundaryFvPatchField<Type>::ibPatch();
210     if 
211     (
212         wallMask_.empty() 
213      || (ibFvP.movingIb() || ibFvP.boundaryMesh().mesh().moving())
214     )
215     {
216         wallMask_.setSize
217         (
218             this->ibPatch().ibCells().size(),
219             false
220         );
221     }
222     
223     return wallMask_;
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 } // End namespace RASModels
230 } // End namespace incompressible
231 } // End namespace Foam
233 // ************************************************************************* //