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-2026 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 (
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 
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  const scalar fraction =
73  magSfb[patchis[i]][patchFaceis[i]]
74  /mesh().magFaceAreas()[facei[subi]];
75 
76  phi_.boundaryFieldRef()[patchis[i]][patchFaceis[i]] +=
77  sign*fraction*dqdt[subi];
78  }
79  }
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
86 (
87  const word& name,
88  const Time& runTime,
89  const dictionary& dict,
90  const word& qName,
91  const dimensionSet& qDims
92 )
93 :
95  phi_
96  (
97  IOobject
98  (
99  cloud().mesh().name()
100  + ":phi"
101  + (qName.size() == 1 ? qName : qName.capitalise()),
102  runTime.name(),
103  mesh(),
104  IOobject::NO_READ,
105  IOobject::AUTO_WRITE
106  ),
107  mesh(),
108  dimensionedScalar(qDims/dimTime, scalar(0))
109  )
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
123  return wordList::null();
124 }
125 
126 
128 {
129  return false;
130 }
131 
132 
134 {
135  phi_ == Zero;
136 }
137 
138 
140 {
141  return true;
142 }
143 
144 
146 (
148 )
149 {
150  if (fraction.mesh().group() != LagrangianGroup::inInternalMesh)
151  {
152  crossPatchFaces(fraction, +1);
153  }
154  else
155  {
156  const Foam::cloud& c = cloud();
157 
158  const labelList& owner = mesh().owner();
159 
160  const SubList<LagrangianState> states =
161  fraction.mesh().sub(c.mesh().states());
162  const SubField<label> celli = fraction.mesh().sub(c.mesh().celli());
163  const SubField<label> facei = fraction.mesh().sub(c.mesh().facei());
164 
165  const LagrangianSubScalarField dqdt(q(fraction)/time_.deltaT());
166 
167  forAll(fraction, subi)
168  {
169  if (states[subi] != LagrangianState::onInternalFace) continue;
170 
171  const label sign = owner[facei[subi]] == celli[subi] ? +1 : -1;
172 
173  phi_.internalFieldRef()[facei[subi]] += sign*dqdt[subi];
174  }
175  }
176 }
177 
178 
180 (
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:449
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 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
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:61
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:86
virtual ~cloudFlux()
Destructor.
Definition: cloudFlux.C:115
virtual wordList fields() const
Return the list of fields required.
Definition: cloudFlux.C:121
virtual bool executeAtStart() const
Return false so this function does not execute at the start.
Definition: cloudFlux.C:127
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:133
virtual bool execute()
Do nothing. Everything happens in faces crossing hooks.
Definition: cloudFlux.C:139
virtual void preCrossFaces(const LagrangianSubScalarSubField &fraction)
Hook before face crossings of a specific sub-mesh.
Definition: cloudFlux.C:146
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 labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:490
const UCompactListList< label > & polyBFacePatches() const
Return poly-bFace-patch addressing.
Definition: fvMesh.C:986
const UCompactListList< label > & polyBFacePatchFaces() const
Return poly-bFace-patch-face addressing.
Definition: fvMesh.C:1062
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:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const dimensionedScalar c
Speed of light in a vacuum.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
const unitSet fraction
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
Definition: dimensions.C:142
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