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 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 #include "polySurfacePointFields.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class GeoMeshType>
36 (
37  const word& fieldName
38 ) const
39 {
40  // Face Data first (main registry)
41 
42  const objectRegistry& obr = *this;
43 
44  const auto* ioptr = obr.cfindObject<regIOobject>(fieldName);
45 
46  if (ioptr)
47  {
48  return ioptr;
49  }
50 
51  forAllConstIters(obr, iter)
52  {
53  const objectRegistry* subreg = isA<objectRegistry>(iter.val());
54 
55  if (subreg && (ioptr = subreg->cfindObject<regIOobject>(fieldName)))
56  {
57  return ioptr;
58  }
59  }
60 
61  return ioptr;
62 }
63 
64 
65 template<class GeoMeshType>
67 (
68  const word& fieldName
69 ) const
70 {
71  // Face Data first (main registry)
72 
73  const objectRegistry& obr = *this;
74 
75  if (obr.found(fieldName))
76  {
77  return this;
78  }
79 
80  forAllConstIters(obr, iter)
81  {
82  const objectRegistry* subreg = isA<objectRegistry>(iter.val());
83 
84  if (subreg && subreg->found(fieldName))
85  {
86  return subreg;
87  }
88  }
89 
90  return nullptr;
91 }
92 
93 
94 template<class Type, class GeoMeshType>
96 (
97  const word& fieldName,
98  const dimensionSet& dims,
99  const Field<Type>& values
100 )
101 {
102  // Force creates field database if needed.
103  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
104 
105  auto* dimfield =
107 
108  if (dimfield)
109  {
110  dimfield->dimensions() = dims;
111  dimfield->field() = values;
112  }
113  else
114  {
116  (
117  IOobject
118  (
119  fieldName,
120  fieldDb,
121  IOobject::NO_READ,
122  IOobject::NO_WRITE,
123  true
124  ),
125  *this,
126  dims,
127  values
128  );
129 
130  dimfield->store();
131  }
132 }
133 
134 
135 template<class Type, class GeoMeshType>
137 (
138  const word& fieldName,
139  const dimensionSet& dims,
141 )
142 {
143  // Force creates field database if needed.
144  const objectRegistry& fieldDb = this->fieldData<GeoMeshType>();
145 
146  auto* dimfield =
148 
149  if (dimfield)
150  {
151  dimfield->dimensions() = dims;
152  dimfield->field() = std::move(values);
153  }
154  else
155  {
157  (
158  IOobject
159  (
160  fieldName,
161  fieldDb,
162  IOobject::NO_READ,
163  IOobject::NO_WRITE,
164  true
165  ),
166  *this,
167  dims,
168  std::move(values)
169  );
170 
171  dimfield->store();
172  }
173 }
174 
175 
176 // ************************************************************************* //
Foam::objectRegistry::getObjectPtr
Type * getObjectPtr(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:423
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
polySurface.H
Foam::polySurface::findFieldObject
const regIOobject * findFieldObject(const word &fieldName, const FieldAssociation association) const
Definition: polySurface.C:242
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
polySurfaceFields.H
Fields for polySurface.
polySurfacePointFields.H
Point fields for polySurface.
Foam::polySurface::storeField
void storeField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values)
Copy/store named field as face or point data (template parameter).
Definition: polySurfaceTemplates.C:96
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:65
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::objectRegistry::found
bool found(const word &name, const bool recursive=false) const
Can the regIOobject object be found (by name).
Definition: objectRegistry.C:428
Foam::DimensionedField::dimensions
const dimensionSet & dimensions() const
Return dimensions.
Definition: DimensionedFieldI.H:49
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
Foam::objectRegistry::cfindObject
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:390
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::polySurface::whichRegistry
const objectRegistry * whichRegistry(const word &fieldName) const
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54