polySurfaceTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "polySurface.H"
29 #include "polySurfaceFields.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<class GeoMeshType>
35 (
36  const word& fieldName
37 ) const
38 {
39  // Face Data first (main registry)
40 
41  const objectRegistry& obr = *this;
42 
43  const auto* ioptr = obr.cfindObject<regIOobject>(fieldName);
44 
45  if (ioptr)
46  {
47  return ioptr;
48  }
49 
50  forAllConstIters(obr, iter)
51  {
52  const auto* subreg = isA<objectRegistry>(iter.val());
53 
54  if (subreg && (ioptr = subreg->cfindObject<regIOobject>(fieldName)))
55  {
56  return ioptr;
57  }
58  }
59 
60  return ioptr;
61 }
62 
63 
64 template<class GeoMeshType>
66 (
67  const word& fieldName
68 ) const
69 {
70  // Face Data first (main registry)
71 
72  const objectRegistry& obr = *this;
73 
74  if (obr.contains(fieldName))
75  {
76  return this;
77  }
78 
79  forAllConstIters(obr, iter)
80  {
81  const auto* subreg = isA<objectRegistry>(iter.val());
82 
83  if (subreg && subreg->contains(fieldName))
84  {
85  return subreg;
86  }
87  }
88 
89  return nullptr;
90 }
91 
92 
93 template<class Type, class GeoMeshType>
96 (
97  const word& fieldName,
98  const dimensionSet& dims
99 )
100 {
101  typedef DimensionedField<Type, GeoMeshType> fieldType;
102 
103  // Force creates field database if needed.
104  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
105 
106  auto* fldptr = fieldDb.getObjectPtr<fieldType>(fieldName);
107 
108  if (fldptr)
109  {
110  fldptr->dimensions().reset(dims); // Dimensions may have changed
111  fldptr->field() = Foam::zero{};
112  }
113  else
114  {
115  fldptr = new fieldType
116  (
117  fieldDb.newIOobject
118  (
119  fieldName,
123  ),
124  *this,
125  Foam::zero{},
126  dims
127  );
128 
129  regIOobject::store(fldptr);
130  }
131 
132  return *fldptr;
133 }
134 
135 
136 template<class Type, class GeoMeshType>
139 (
140  const word& fieldName,
141  const dimensionSet& dims,
142  const Field<Type>& values
143 )
144 {
145  typedef DimensionedField<Type, GeoMeshType> fieldType;
146 
147  // Force creates field database if needed.
148  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
149 
150  auto* fldptr = fieldDb.getObjectPtr<fieldType>(fieldName);
151 
152  if (fldptr)
153  {
154  fldptr->dimensions().reset(dims); // Dimensions may have changed
155  fldptr->field() = values;
156  }
157  else
158  {
159  fldptr = new fieldType
160  (
161  fieldDb.newIOobject
162  (
163  fieldName,
167  ),
168  *this,
169  dims,
170  values
171  );
172 
173  regIOobject::store(fldptr);
174  }
175 
176  return *fldptr;
177 }
178 
179 
180 template<class Type, class GeoMeshType>
183 (
184  const word& fieldName,
185  const dimensionSet& dims,
187 )
188 {
189  typedef DimensionedField<Type, GeoMeshType> fieldType;
190 
191  // Force creates field database if needed.
192  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
193 
194  auto* fldptr = fieldDb.getObjectPtr<fieldType>(fieldName);
195 
196  if (fldptr)
197  {
198  fldptr->dimensions().reset(dims); // Dimensions may have changed
199  fldptr->field() = std::move(values);
200  }
201  else
202  {
203  fldptr = new fieldType
204  (
205  fieldDb.newIOobject
206  (
207  fieldName,
211  ),
212  *this,
213  dims,
214  std::move(values)
215  );
216 
217  regIOobject::store(fldptr);
218  }
219 
220  return *fldptr;
221 }
222 
223 
224 // ************************************************************************* //
bool contains(const word &name, const bool recursive=false) const
Does the registry contain the regIOobject object (by name).
Fields (face and point) for polySurface.
bool store()
Register object with its registry and transfer ownership to the registry.
Definition: regIOobjectI.H:36
DimensionedField< Type, GeoMeshType > & storeField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values)
Copy/store named field as face or point data (template parameter).
Ignore writing from objectRegistry::writeObject()
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
const objectRegistry * whichRegistry(const word &fieldName) const
General finding of the registry with the field object (FACE or POINT).
const regIOobject * findFieldObject(const word &fieldName, const FieldAssociation association) const
Find the field object with the given name and required FieldAssociation (FACE or POINT).
Definition: polySurface.C:260
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Nothing to be read.
DimensionedField< Type, GeoMeshType > & newField(const word &fieldName, const dimensionSet &dims)
Create/store named zero field as face or point data (template parameter).
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
Registry of regIOobjects.
Request registration (bool: true)
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28