MRFZoneTemplates.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-2023 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 "MRFZone.H"
27 #include "fvMesh.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "fvMatrices.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class RhoFieldType>
35 void Foam::MRFZone::makeRelativeRhoFlux
36 (
37  const RhoFieldType& rho,
39 ) const
40 {
41  const surfaceVectorField& Cf = mesh_.Cf();
42  const surfaceVectorField& Sf = mesh_.Sf();
43 
44  const vector Omega = this->Omega();
45 
46  const vectorField& Cfi = Cf;
47  const vectorField& Sfi = Sf;
48  scalarField& phii = phi.primitiveFieldRef();
49 
50  // Internal faces
51  forAll(internalFaces_, i)
52  {
53  label facei = internalFaces_[i];
54  phii[facei] -= rho[facei]*(Omega ^ (Cfi[facei] - origin_)) & Sfi[facei];
55  }
56 
57  makeRelativeRhoFlux(rho.boundaryField(), phi.boundaryFieldRef());
58 }
59 
60 
61 template<class RhoFieldType>
62 void Foam::MRFZone::makeRelativeRhoFlux
63 (
64  const RhoFieldType& rho,
65  FieldField<fvsPatchField, scalar>& phiBf
66 ) const
67 {
68  const surfaceVectorField& Cf = mesh_.Cf();
69  const surfaceVectorField& Sf = mesh_.Sf();
70 
71  const vector Omega = this->Omega();
72 
73  forAll(patchFaces_, patchi)
74  {
75  if (!phiBf[patchi].fixesValue())
76  {
77  forAll(patchFaces_[patchi], i)
78  {
79  const label patchFacei = patchFaces_[patchi][i];
80 
81  phiBf[patchi][patchFacei] -=
82  rho[patchi][patchFacei]
83  *(Omega ^ (Cf.boundaryField()[patchi][patchFacei] - origin_))
84  & Sf.boundaryField()[patchi][patchFacei];
85  }
86  }
87  }
88 }
89 
90 
91 template<class RhoFieldType>
92 void Foam::MRFZone::makeRelativeRhoFlux
93 (
94  const RhoFieldType& rho,
95  Field<scalar>& phi,
96  const label patchi
97 ) const
98 {
99  const surfaceVectorField& Cf = mesh_.Cf();
100  const surfaceVectorField& Sf = mesh_.Sf();
101 
102  const vector Omega = this->Omega();
103 
104  forAll(patchFaces_[patchi], i)
105  {
106  const label patchFacei = patchFaces_[patchi][i];
107 
108  phi[patchFacei] -=
109  rho[patchFacei]
110  * (Omega ^ (Cf.boundaryField()[patchi][patchFacei] - origin_))
111  & Sf.boundaryField()[patchi][patchFacei];
112  }
113 }
114 
115 
116 template<class RhoFieldType>
117 void Foam::MRFZone::makeAbsoluteRhoFlux
118 (
119  const RhoFieldType& rho,
120  surfaceScalarField& phi
121 ) const
122 {
123  const surfaceVectorField& Cf = mesh_.Cf();
124  const surfaceVectorField& Sf = mesh_.Sf();
125 
126  const vector Omega = this->Omega();
127 
128  const vectorField& Cfi = Cf;
129  const vectorField& Sfi = Sf;
130  scalarField& phii = phi.primitiveFieldRef();
131 
132  // Internal faces
133  forAll(internalFaces_, i)
134  {
135  const label facei = internalFaces_[i];
136  phii[facei] += rho[facei]*(Omega ^ (Cfi[facei] - origin_)) & Sfi[facei];
137  }
138 
139  surfaceScalarField::Boundary& phiBf = phi.boundaryFieldRef();
140 
141  forAll(patchFaces_, patchi)
142  {
143  if (!phiBf[patchi].fixesValue())
144  {
145  forAll(patchFaces_[patchi], i)
146  {
147  const label patchFacei = patchFaces_[patchi][i];
148 
149  phiBf[patchi][patchFacei] +=
150  rho.boundaryField()[patchi][patchFacei]
151  *(Omega ^ (Cf.boundaryField()[patchi][patchFacei] - origin_))
152  & Sf.boundaryField()[patchi][patchFacei];
153  }
154  }
155  }
156 }
157 
158 
159 template<class Type>
161 (
162  SurfaceField<Type>& phi
163 ) const
164 {
165  Field<Type>& phii = phi.primitiveFieldRef();
166 
167  forAll(internalFaces_, i)
168  {
169  phii[internalFaces_[i]] = Zero;
170  }
171 
172  typename SurfaceField<Type>::Boundary& phibf =
173  phi.boundaryFieldRef();
174 
175  forAll(patchFaces_, patchi)
176  {
177  forAll(patchFaces_[patchi], i)
178  {
179  phibf[patchi][patchFaces_[patchi][i]] = Zero;
180  }
181  }
182 }
183 
184 
185 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Pre-declare SubField and related Field type.
Definition: Field.H:82
Generic GeometricBoundaryField class.
Generic GeometricField class.
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of the boundary field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
vector Omega() const
Return the current Omega vector.
Definition: MRFZone.C:187
void zero(SurfaceField< Type > &phi) const
Zero the MRF region of the given field.
const surfaceVectorField & Cf() const
Return face centres.
const surfaceVectorField & Sf() const
Return cell face area vectors.
A special matrix type and solver, designed for finite volume solutions of scalar equations.
label patchi
static const zero Zero
Definition: zero.H:97
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
SurfaceField< scalar > surfaceScalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Field< vector > vectorField
Specialisation of Field<T> for vector.
SurfaceField< vector > surfaceVectorField
Foam::surfaceFields.