groupPropertyFvScalarField.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) 2024-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 
27 #include "populationBalanceModel.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
34 )
35 :
36  internalField_(iF),
37  popBalPtr_(nullptr),
38  i_(-1)
39 {}
40 
41 
42 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
43 
46 {
47  // Use the cached pointer if we have it
48  if (popBalPtr_ != nullptr) return *popBalPtr_;
49 
50  // Look up the phase system
51  const phaseSystem& fluid =
52  internalField_.db().lookupObject<phaseSystem>
53  (
55  );
56 
57  // Get the diameter model for this phase and check its type
58  const diameterModel& diameter =
59  fluid.phases()[internalField_.group()].diameter();
60  if (!isA<diameterModels::populationBalance>(diameter))
61  {
63  << "Phase " << internalField_.group() << " does not have a "
64  << " diameter model associated with a population balance model"
65  << exit(FatalError);
66  }
67 
68  // Cast the diameter model and extract the population balance model
69  popBalPtr_ =
70  &refCast<const diameterModels::populationBalance>(diameter).popBal();
71 
72  return *popBalPtr_;
73 }
74 
75 
77 {
78  // Use the cached index if we have it
79  if (i_ != -1) return i_;
80 
81  // Remove the phase suffix
82  const word member = internalField_.member();
83 
84  // Determine the number of trailing digits
85  string::size_type memberChari = member.size();
86  while (memberChari && isdigit(member[memberChari - 1]))
87  {
88  memberChari --;
89  }
90 
91  // Check that we have something
92  if (memberChari == member.size())
93  {
95  << "Could not determine the group index for the property field "
96  << internalField_.name() << exit(FatalError);
97  }
98 
99  // Convert the trailing digits to an integer
100  i_ = atoi(member(memberChari, member.size()).c_str());
101 
102  // Check that the index is in bounds
103  if (i_ < 0 || i_ >= popBal().nGroups())
104  {
106  << "Group index for property field " << internalField_.name()
107  << " is out of range" << exit(FatalError);
108  }
109 
110  return i_;
111 }
112 
113 
114 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:309
Abstract base-class for dispersed-phase particle diameter models.
Definition: diameterModel.H:52
groupPropertyFvScalarField(const DimensionedField< scalar, fvMesh > &)
Construct from internal field.
const populationBalanceModel & popBal() const
Return the population balance.
label i() const
Return the index of this group.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
Class to represent a system of phases.
Definition: phaseSystem.H:74
static const word propertiesName
Default name of the phase properties dictionary.
Definition: phaseSystem.H:252
const phaseModelList & phases() const
Return the phase models.
Definition: phaseSystemI.H:104
Model for tracking the evolution of a dispersed phase size distribution due to coalescence (synonymou...
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
error FatalError