cloudFlux.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) 2025 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 "cloudFlux.H"
27 #include "cloud.H"
28 #include "CompactListList.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::functionObjects::cloudFlux::crossPatchFaces
45 (
46  const LagrangianSubScalarSubField& fraction,
47  const label sign
48 )
49 {
50  const Foam::cloud& c = cloud();
51 
52  const SubField<label> facei = fraction.mesh().sub(c.mesh().facei());
53 
54  const LagrangianSubScalarField dqdt(q(fraction)/time_.deltaT());
55 
57 
58  forAll(fraction, subi)
59  {
60  const LagrangianState state =
61  c.mesh().state(subi + fraction.mesh().start());
62 
63  if (sign < 0 && state == LagrangianState::toBeRemoved) continue;
64 
65  const label bFacei = facei[subi] - mesh().nInternalFaces();
66 
67  const labelUList patchis = mesh().polyBFacePatches()[bFacei];
68  const labelUList patchFaceis = mesh().polyBFacePatchFaces()[bFacei];
69 
70  forAll(patchis, i)
71  {
72  phi_.boundaryFieldRef()[patchis[i]][patchFaceis[i]] +=
73  sign
74  *dqdt[subi]
75  *magSfb[patchis[i]][patchFaceis[i]]
76  /mesh().magFaceAreas()[facei[subi]];
77  }
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
85 (
86  const word& name,
87  const Time& runTime,
88  const dictionary& dict,
89  const word& qName,
90  const dimensionSet& qDims
91 )
92 :
94  phi_
95  (
96  IOobject
97  (
98  cloud().mesh().name()
99  + ":phi"
100  + (qName.size() == 1 ? qName : qName.capitalise()),
101  runTime.name(),
102  mesh(),
103  IOobject::NO_READ,
104  IOobject::AUTO_WRITE
105  ),
106  mesh(),
107  dimensionedScalar(qDims/dimTime, scalar(0))
108  )
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
113 
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 {
122  return wordList::null();
123 }
124 
125 
127 {
128  return false;
129 }
130 
131 
133 {
134  phi_ == Zero;
135 }
136 
137 
139 {
140  return true;
141 }
142 
143 
145 (
146  const LagrangianSubScalarSubField& fraction
147 )
148 {
149  if (fraction.mesh().group() != LagrangianGroup::inInternalMesh)
150  {
151  crossPatchFaces(fraction, +1);
152  }
153  else
154  {
155  const Foam::cloud& c = cloud();
156 
157  const labelList& owner = mesh().owner();
158 
159  const SubList<LagrangianState> states =
160  fraction.mesh().sub(c.mesh().states());
161  const SubField<label> celli = fraction.mesh().sub(c.mesh().celli());
162  const SubField<label> facei = fraction.mesh().sub(c.mesh().facei());
163 
164  const LagrangianSubScalarField dqdt(q(fraction)/time_.deltaT());
165 
166  forAll(fraction, subi)
167  {
168  if (states[subi] != LagrangianState::onInternalFace) continue;
169 
170  phi_.internalFieldRef()[facei[subi]] +=
171  (owner[facei[subi]] == celli[subi] ? +1 : -1)
172  *dqdt[subi]
173  /mesh().time().deltaTValue();
174  }
175  }
176 }
177 
178 
180 (
181  const LagrangianSubScalarSubField& fraction
182 )
183 {
184  if (fraction.mesh().group() != LagrangianGroup::inInternalMesh)
185  {
186  crossPatchFaces(fraction, -1);
187  }
188 }
189 
190 
192 {
193  return true;
194 }
195 
196 
198 {
199  return true;
200 }
201 
202 
203 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const
Return mesh.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
GeometricBoundaryField< Type, GeoMesh, PrimitiveField > Boundary
Type of the boundary field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
Pre-declare related SubField type.
Definition: SubField.H:63
A List obtained as a section of another List.
Definition: SubList.H:56
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
dimensionedScalar deltaT() const
Return time step.
Definition: TimeStateI.H:46
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
Base class for clouds. Provides a basic evolution algorithm, models, and a database for caching deriv...
Definition: cloud.H:63
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
const Time & time_
Reference to time.
Base class for functions which generate the flux of a cloud.
Definition: cloudFlux.H:55
cloudFlux(const word &name, const Time &runTime, const dictionary &dict, const word &phiName, const dimensionSet &qDims)
Construct from Time and dictionary.
Definition: cloudFlux.C:85
virtual ~cloudFlux()
Destructor.
Definition: cloudFlux.C:114
virtual wordList fields() const
Return the list of fields required.
Definition: cloudFlux.C:120
virtual bool executeAtStart() const
Return false so this function does not execute at the start.
Definition: cloudFlux.C:126
virtual void postCrossFaces(const LagrangianSubScalarSubField &fraction)
Hook following face crossings of a specific sub-mesh.
Definition: cloudFlux.C:180
virtual bool clear()
Clear the number flux.
Definition: cloudFlux.C:197
virtual void preSolve()
Hook before solution steps.
Definition: cloudFlux.C:132
virtual bool execute()
Do nothing. Everything happens in faces crossing hooks.
Definition: cloudFlux.C:138
virtual void preCrossFaces(const LagrangianSubScalarSubField &fraction)
Hook before face crossings of a specific sub-mesh.
Definition: cloudFlux.C:145
virtual bool write()
Write the number flux.
Definition: cloudFlux.C:191
const Cloud & cloud() const
Get a reference to the cloud.
Base class for function objects that refer to an fvMesh and a cloud. Used, for example,...
Function object that solves for the evolution of a cloud. Only provides one-way coupling with a finit...
const fvMesh & mesh() const
Return a reference to the mesh.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:471
const UCompactListList< label > & polyBFacePatches() const
Return poly-bFace-patch addressing.
Definition: fvMesh.C:1016
const UCompactListList< label > & polyBFacePatchFaces() const
Return poly-bFace-patch-face addressing.
Definition: fvMesh.C:1092
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
label nInternalFaces() const
const scalarField & magFaceAreas() const
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const dimensionedScalar c
Speed of light in a vacuum.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
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
LagrangianState
Lagrangian state enumeration.
const dimensionSet dimTime
LagrangianSubSubField< scalar > LagrangianSubScalarSubField
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
LagrangianSubField< scalar > LagrangianSubScalarField
UList< label > labelUList
Definition: UList.H:65
dictionary dict