Flux.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) 2022-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 "Flux.H"
27 
28 // * * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * //
29 
30 template<class CloudType>
33 
34 template<class CloudType>
37 
38 template<class CloudType>
41 
42 
43 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
44 
45 template<class CloudType, class Derived>
47 {
48  if (write_)
49  {
50  phi_.write();
51  }
52 }
53 
54 
55 template<class CloudType, class Derived>
57 (
58  const parcelType& p,
59  const bool isPre
60 )
61 {
62  const polyMesh& mesh = this->owner().mesh();
63  const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
64 
65  const bool isInternal = p.onInternalFace(mesh);
66 
67  const label facei = p.face();
68  const label bFacei = isInternal ? -1 : facei - mesh.nInternalFaces();
69  const label patchi = isInternal ? -1 : bMesh.patchIndices()[bFacei];
70  const label patchFacei = isInternal ? -1 : bMesh.patchFaceIndices()[bFacei];
71 
72  const bool own = mesh.faceOwner()[facei] == p.cell();
73 
74  const scalar sign = own == isPre ? +1 : -1;
75 
76  scalar& phif =
77  isInternal
78  ? phi_[facei]
79  : phi_.boundaryFieldRef()[patchi][patchFacei];
80 
81  phif += sign*Derived::dPhiDeltaT(p)/mesh.time().deltaTValue();
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
87 template<class CloudType, class Derived>
89 (
90  const dictionary& dict,
91  CloudType& owner,
92  const word& modelName
93 )
94 :
95  CloudFunctionObject<CloudType>(dict, owner, modelName, Derived::typeName),
96  write_(dict.lookupOrDefault<bool>("write", true)),
97  phi_
98  (
99  IOobject
100  (
101  this->owner().name() + ":" + Derived::typeName,
102  this->owner().mesh().time().name(),
103  this->owner().mesh()
104  ),
105  this->owner().mesh(),
107  )
108 {}
109 
110 
111 template<class CloudType, class Derived>
113 (
114  const Flux<CloudType, Derived>& ppm
115 )
116 :
118  write_(ppm.write_),
119  phi_(ppm.phi_)
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
124 
125 template<class CloudType, class Derived>
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
132 template<class CloudType, class Derived>
134 {
136 }
137 
138 
139 template<class CloudType, class Derived>
141 {
142  accumulate(p, true);
143 }
144 
145 
146 template<class CloudType, class Derived>
148 {
149  if (p.onBoundaryFace(this->owner().mesh()))
150  {
151  accumulate(p, false);
152  }
153 }
154 
155 
156 // ************************************************************************* //
Templated cloud function object base class.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
const fvMesh & mesh() const
Return references to the mesh.
Definition: DSMCCloudI.H:41
Function objects which generate the number, volume or mass flux of particles in a cloud.
Definition: Flux.H:65
virtual void preFace(const parcelType &p)
Pre-face hook.
Definition: Flux.C:140
Flux(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: Flux.C:89
void write()
Write post-processing info.
Definition: Flux.C:46
virtual void postFace(const parcelType &p)
Post-face hook.
Definition: Flux.C:147
virtual ~Flux()
Destructor.
Definition: Flux.C:126
void accumulate(const parcelType &p, const bool isPre)
Accumulate the particle into the flux.
Definition: Flux.C:57
virtual void preEvolve()
Pre-evolve hook.
Definition: Flux.C:133
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
const Time & time() const
Return time.
Foam::polyBoundaryMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1339
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
label nInternalFaces() const
A class for handling words, derived from string.
Definition: word.H:62
const polyBoundaryMesh & bMesh
label patchi
dimensionedScalar sign(const dimensionedScalar &ds)
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
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const dimensionSet dimless
const dimensionSet dimTime
const dimensionSet dimVolume
const dimensionSet dimMass
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dictionary dict
volScalarField & p