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-2022 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 objectRegistry* 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.found(fieldName))
75  {
76  return this;
77  }
78 
79  forAllConstIters(obr, iter)
80  {
81  const objectRegistry* subreg = isA<objectRegistry>(iter.val());
82 
83  if (subreg && subreg->found(fieldName))
84  {
85  return subreg;
86  }
87  }
88 
89  return nullptr;
90 }
91 
92 
93 template<class Type, class GeoMeshType>
95 (
96  const word& fieldName,
97  const dimensionSet& dims,
98  const Field<Type>& values
99 )
100 {
101  // Force creates field database if needed.
102  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
103 
104  auto* dimfield =
106 
107  if (dimfield)
108  {
109  dimfield->dimensions().reset(dims); // Dimensions may have changed
110  dimfield->field() = values;
111  }
112  else
113  {
114  dimfield = new DimensionedField<Type, GeoMeshType>
115  (
116  IOobject
117  (
118  fieldName,
119  fieldDb,
123  ),
124  *this,
125  dims,
126  values
127  );
128 
129  dimfield->store();
130  }
131 }
132 
133 
134 template<class Type, class GeoMeshType>
136 (
137  const word& fieldName,
138  const dimensionSet& dims,
139  Field<Type>&& values
140 )
141 {
142  // Force creates field database if needed.
143  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
144 
145  auto* dimfield =
146  fieldDb.getObjectPtr<DimensionedField<Type, GeoMeshType>>(fieldName);
147 
148  if (dimfield)
149  {
150  dimfield->dimensions().reset(dims); // Dimensions may have changed
151  dimfield->field() = std::move(values);
152  }
153  else
154  {
155  dimfield = new DimensionedField<Type, GeoMeshType>
156  (
157  IOobject
158  (
159  fieldName,
160  fieldDb,
164  ),
165  *this,
166  dims,
167  std::move(values)
168  );
169 
170  dimfield->store();
171  }
172 }
173 
174 
175 // ************************************************************************* //
Fields (face and point) for polySurface.
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).
void reset(const dimensionSet &ds)
Copy assign the exponents from the dimensionSet.
Definition: dimensionSet.C:142
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:235
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
Nothing to be read.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
bool found(const word &name, bool recursive=false) const
Same as contains()
Registry of regIOobjects.
void storeField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values)
Copy/store named field as face or point data (template parameter).
Request registration (bool: true)
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
const dimensionSet & dimensions() const noexcept
Return dimensions.