PrimitiveOldTimePatch.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) 2022-2023 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 "PrimitiveOldTimePatch.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class FaceList, class PointField>
32 (
33  const FaceList& faces,
34  const Field<PointType>& points,
35  const Field<PointType>& points0
36 )
37 :
38  PrimitivePatch<FaceList, PointField>(faces, points),
39  points0Ptr_(isRef<PointField> ? nullptr : new Field<PointType>(points0)),
40  points0_(isRef<PointField> ? points0 : points0Ptr_()),
41  patch0Ptr_(new patch0Type(faces, points0_)),
42  localPoints0Ptr_(nullptr)
43 {}
44 
45 
46 template<class FaceList, class PointField>
48 (
50  const Field<PointType>& points0
51 )
52 :
53  PrimitivePatch<FaceList, PointField>(patch),
54  points0_(points0),
55  patch0Ptr_(new patch0Type(patch, points0_)),
56  localPoints0Ptr_(nullptr)
57 {}
58 
59 
60 template<class FaceList, class PointField>
62 (
63  const FaceList& faces,
65 )
66 :
67  PrimitivePatch<FaceList, PointField>(faces, points),
68  points0Ptr_(nullptr),
69  points0_(NullObjectRef<Field<PointType>>()),
70  patch0Ptr_(nullptr),
71  localPoints0Ptr_(nullptr)
72 {}
73 
74 
75 template<class FaceList, class PointField>
77 (
79 )
80 :
81  PrimitivePatch<FaceList, PointField>(patch),
82  points0_(NullObjectRef<Field<PointType>>()),
83  patch0Ptr_(nullptr),
84  localPoints0Ptr_(nullptr)
85 {}
86 
87 
88 template<class FaceList, class PointField>
90 (
92 )
93 :
94  PrimitivePatch<FaceList, PointField>(patch),
95  points0_(patch.points0_),
96  patch0Ptr_(patch.patch0Ptr_, false),
97  localPoints0Ptr_(nullptr)
98 {}
99 
100 
101 template<class FaceList, class PointField>
103 (
104  PrimitiveOldTimePatch<FaceList, PointField>&& patch
105 )
106 :
107  PrimitivePatch<FaceList, PointField>(move(patch)),
108  points0_(move(patch.points0_)),
109  patch0Ptr_(patch.patch0Ptr_),
110  localPoints0Ptr_(nullptr)
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
115 
116 template<class FaceList, class PointField>
118 {
119  clearOut();
120 }
121 
122 
123 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
124 
125 template<class FaceList, class PointField>
126 const Foam::Field
127 <
130 {
131  // !!! Cannot just call patch0Ptr_->localPoints() as this would generate
132  // topology in patch0Ptr_() that is already available in the base class.
133  // For now, we just duplicate the implementation in PrimitivePatch.
134 
135  if (!localPoints0Ptr_)
136  {
137  const labelList& meshPts = this->meshPoints();
138 
139  localPoints0Ptr_ = new Field<PointType>(meshPts.size());
140 
141  Field<PointType>& locPts = *localPoints0Ptr_;
142 
143  forAll(meshPts, pointi)
144  {
145  locPts[pointi] = points0_[meshPts[pointi]];
146  }
147  }
148 
149  // But, it would be preferable to add a method to PrimitivePatch which
150  // calculates the local points given a list of points different to those
151  // that are stored. Then the implementations could be shared and we could
152  // do this:
153  /*
154  if (!localPoints0Ptr_)
155  {
156  localPoints0Ptr_ = this->calcLocalPoints(points0_);
157  }
158  */
159 
160  return *localPoints0Ptr_;
161 }
162 
163 
164 template<class FaceList, class PointField>
165 const Foam::Field
166 <
169 {
170  return patch0Ptr_->faceCentres();
171 }
172 
173 
174 template<class FaceList, class PointField>
175 const Foam::Field
176 <
179 {
180  return patch0Ptr_->faceAreas();
181 }
182 
183 
184 template<class FaceList, class PointField>
185 const Foam::Field
186 <
189 {
190  return patch0Ptr_->faceNormals();
191 }
192 
193 
194 template<class FaceList, class PointField>
195 const Foam::Field
196 <
199 {
200  // !!! See comments in localPoints0. This isn't needed for now.
201 
203  return NullObjectRef<Field<PointType>>();
204 }
205 
206 
207 template<class FaceList, class PointField>
209 {
211  if (has0()) patch0Ptr_->clearOut();
212 
213  deleteDemandDrivenData(localPoints0Ptr_);
214 }
215 
216 
217 template<class FaceList, class PointField>
219 {
221  if (has0()) patch0Ptr_->clearGeom();
222 
223  deleteDemandDrivenData(localPoints0Ptr_);
224 }
225 
226 
227 template<class FaceList, class PointField>
229 (
230  const Field<PointType>&
231 )
232 {
233  if (has0()) patch0Ptr_->clearGeom();
234 }
235 
236 
237 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const Field< PointType > & pointNormals0() const
Return old-time point normals for patch.
const Field< PointType > & faceAreas0() const
Return old-time face areas for patch.
virtual void movePoints0(const Field< PointType > &)
Correct patch after moving points.
virtual ~PrimitiveOldTimePatch()
Destructor.
const Field< PointType > & faceCentres0() const
Return old-time face centres for patch.
PrimitiveOldTimePatch(const FaceList &faces, const Field< PointType > &points, const Field< PointType > &points0)
Construct from components.
const Field< PointType > & faceNormals0() const
Return old-time face normals for patch.
const Field< PointType > & localPoints0() const
Return pointField of old-time points in patch.
A list of faces which address into the list of points.
std::remove_reference< PointField >::type::value_type PointType
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
const pointField & points
void deleteDemandDrivenData(DataType *&dataPtr)
constexpr bool isRef
Determine whether a type is a reference.
Definition: typeInfo.H:184
const T & NullObjectRef()
Return const reference to the nullObject of type T.
Definition: nullObjectI.H:27
GeometricField< Type, pointPatchField, pointMesh > PointField