CloudStateFieldRef.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 "CloudStateFieldRef.H"
27 #include "toSubField.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
35 )
36 :
37  ref_(ref),
38  psiAllPtr_(ref_.mesh().subAll().sub(ref_).ptr())
39 {}
40 
41 
42 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
43 
44 template<class Type>
46 {
47  return ref_.name();
48 }
49 
50 
51 template<class Type>
53 {
54  return ref_.mesh();
55 }
56 
57 
58 template<class Type>
60 {
61  return ref_.dimensions();
62 }
63 
64 
65 template<class Type>
67 (
68  const LagrangianSubMesh& subMesh
69 ) const
70 {
71  // Error if this is the all-mesh
72  if (&subMesh == &subMesh.mesh().subAll())
73  {
75  << "Non-constant access is not provided to the all-mesh sub-field"
76  << exit(FatalError);
77  }
78 
79  // Evaluate and store if it doesn't already exist for the sub-mesh
80  if (!psiSubSubPtr_.valid() || psiSubSubMeshIndex_ != subMesh.index())
81  {
82  psiSubSubPtr_.reset(subMesh.sub(ref_).ptr());
83 
84  psiSubSubMeshIndex_ = subMesh.index();
85  }
86 
87  return psiSubSubPtr_();
88 }
89 
90 
91 template<class Type>
93 (
94  const LagrangianSubMesh& subMesh
95 )
96 {
97  // Evaluate and store if it doesn't already exist for the sub-mesh
98  static_cast<const CloudStateFieldRef<Type>&>(*this).ref(subMesh);
99 
100  return psiSubSubPtr_();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
105 
106 template<class Type>
109 {
110  return ref_;
111 }
112 
113 
114 template<class Type>
117 {
118  return ref_;
119 }
120 
121 
122 template<class Type>
125 {
126  return ref_;
127 }
128 
129 
130 template<class Type>
133 (
134  const LagrangianSubMesh& subMesh
135 ) const
136 {
137  // Update and return the all-mesh field
138  if (&subMesh == &subMesh.mesh().subAll())
139  {
140  psiAllPtr_->UList<Type>::shallowCopy(ref_);
141 
142  return psiAllPtr_();
143  }
144 
145  // Evaluate and store if it doesn't already exist for the sub-mesh
146  if (!psiSubSubPtr_.valid() || psiSubSubMeshIndex_ != subMesh.index())
147  {
148  psiSubSubPtr_.reset(subMesh.sub(ref_).ptr());
149 
150  psiSubSubMeshIndex_ = subMesh.index();
151  }
152 
153  return psiSubSubPtr_();
154 }
155 
156 
157 template<class Type>
160 (
161  const LagrangianModelRef& model,
162  const LagrangianSubMesh& subMesh
163 ) const
164 {
165  if (model.isSource())
166  {
167  return
168  toSubField
169  (
170  ref_.sources()[model.source().name()].value
171  (
172  model.source(),
173  subMesh // !!! <-- Replace with model.S()
174  )
175  );
176  }
177 
178  if (model.isInjection())
179  {
180  return
181  toSubField
182  (
183  ref_.sources()[model.injection().name()].value
184  (
185  model.injection(),
186  subMesh
187  )
188  );
189  }
190 
191  return tmp<LagrangianSubSubField<Type>>(operator()(subMesh));
192 }
193 
194 
195 // ************************************************************************* //
Wrapper for a reference to a dynamic Lagrangian field. It provides convenient access consistent with ...
const dimensionSet & dimensions() const
Access the field's dimensions.
const LagrangianDynamicField< Type > & operator()(const LagrangianMesh &) const
Access the entire field.
CloudStateFieldRef(LagrangianDynamicField< Type > &)
Construct from a field reference.
const LagrangianMesh & mesh() const
Access the field's mesh.
const LagrangianSubSubField< Type > & ref(const LagrangianSubMesh &) const
Access a part of the field.
const word & name() const
Access the field's name.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
Class containing Lagrangian geometry and topology.
const LagrangianSubMesh & subAll() const
Return a sub-mesh for all elements.
Simple wrapper to provide an optional reference to a Lagrangian model.
bool isInjection() const
Check if the injection reference is valid.
const LagrangianInjection & injection() const
Access the injection model.
const LagrangianSource & source() const
Access the source model.
bool isSource() const
Check if the source reference is valid.
const word & name() const
The source name.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
uint64_t index() const
Return the index.
const LagrangianMesh & mesh() const
Return the mesh.
word sub(const word &fieldName) const
Return the name of a field corresponding to this sub-mesh.
Dimension set for the base types.
Definition: dimensionSet.H:125
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
trAU ref().rename("rAU")
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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
error FatalError
tmp< DimensionedField< Type, GeoMesh, SubField > > toSubField(const DimensionedField< Type, GeoMesh, Field > &)
Return a temporary sub-field from a reference to a field.
Functions to cast/convert dimensioned field references and temporaries based on a primitive field to ...