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 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 :
39  points0_(points0),
40  patch0Ptr_(new patch0Type(faces, points0_)),
41  localPoints0Ptr_(nullptr)
42 {}
43 
44 
45 template<class FaceList, class PointField>
47 (
49  const Field<PointType>& points0
50 )
51 :
53  points0_(points0),
54  patch0Ptr_(new patch0Type(patch, points0_)),
55  localPoints0Ptr_(nullptr)
56 {}
57 
58 
59 template<class FaceList, class PointField>
61 (
62  const FaceList& faces,
63  const Field<PointType>& points
64 )
65 :
67  points0_(NullObjectRef<Field<PointType>>()),
68  patch0Ptr_(nullptr),
69  localPoints0Ptr_(nullptr)
70 {}
71 
72 
73 template<class FaceList, class PointField>
75 (
77 )
78 :
80  points0_(NullObjectRef<Field<PointType>>()),
81  patch0Ptr_(nullptr),
82  localPoints0Ptr_(nullptr)
83 {}
84 
85 
86 template<class FaceList, class PointField>
88 (
90 )
91 :
93  points0_(patch.points0_),
94  patch0Ptr_(patch.patch0Ptr_, false),
95  localPoints0Ptr_(nullptr)
96 {}
97 
98 
99 template<class FaceList, class PointField>
101 (
103 )
104 :
106  points0_(move(patch.points0_)),
107  patch0Ptr_(patch.patch0Ptr_),
108  localPoints0Ptr_(nullptr)
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
113 
114 template<class FaceList, class PointField>
116 {
117  clearOut();
118 }
119 
120 
121 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
122 
123 template<class FaceList, class PointField>
124 const Foam::Field
125 <
128 {
129  // !!! Cannot just call patch0Ptr_->localPoints() as this would generate
130  // topology in patch0Ptr_() that is already available in the base class.
131  // For now, we just duplicate the implementation in PrimitivePatch.
132 
133  if (!localPoints0Ptr_)
134  {
135  const labelList& meshPts = this->meshPoints();
136 
137  localPoints0Ptr_ = new Field<PointType>(meshPts.size());
138 
139  Field<PointType>& locPts = *localPoints0Ptr_;
140 
141  forAll(meshPts, pointi)
142  {
143  locPts[pointi] = points0_[meshPts[pointi]];
144  }
145  }
146 
147  // But, it would be preferable to add a method to PrimitivePatch which
148  // calculates the local points given a list of points different to those
149  // that are stored. Then the implementations could be shared and we could
150  // do this:
151  /*
152  if (!localPoints0Ptr_)
153  {
154  localPoints0Ptr_ = this->calcLocalPoints(points0_);
155  }
156  */
157 
158  return *localPoints0Ptr_;
159 }
160 
161 
162 template<class FaceList, class PointField>
163 const Foam::Field
164 <
167 {
168  return patch0Ptr_->faceCentres();
169 }
170 
171 
172 template<class FaceList, class PointField>
173 const Foam::Field
174 <
177 {
178  return patch0Ptr_->faceAreas();
179 }
180 
181 
182 template<class FaceList, class PointField>
183 const Foam::Field
184 <
187 {
188  return patch0Ptr_->faceNormals();
189 }
190 
191 
192 template<class FaceList, class PointField>
193 const Foam::Field
194 <
197 {
198  // !!! See comments in localPoints0. This isn't needed for now.
199 
201  return NullObjectRef<Field<PointType>>();
202 }
203 
204 
205 template<class FaceList, class PointField>
207 {
209  if (has0()) patch0Ptr_->clearOut();
210 
211  deleteDemandDrivenData(localPoints0Ptr_);
212 }
213 
214 
215 template<class FaceList, class PointField>
217 {
219  if (has0()) patch0Ptr_->clearGeom();
220 
221  deleteDemandDrivenData(localPoints0Ptr_);
222 }
223 
224 
225 template<class FaceList, class PointField>
227 (
228  const Field<PointType>&
229 )
230 {
231  if (has0()) patch0Ptr_->clearGeom();
232 }
233 
234 
235 // ************************************************************************* //
#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 > & faceAreas0() const
Return old-time face areas for patch.
A list of faces which address into the list of points.
const pointField & points
virtual ~PrimitiveOldTimePatch()
Destructor.
const Field< PointType > & pointNormals0() const
Return old-time point normals for patch.
const Field< PointType > & localPoints0() const
Return pointField of old-time points in patch.
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.
std::remove_reference< PointField >::type::value_type PointType
const T & NullObjectRef()
Return reference to the nullObject of type T.
Definition: nullObjectI.H:27
void deleteDemandDrivenData(DataPtr &dataPtr)
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
virtual void movePoints0(const Field< PointType > &)
Correct patch after moving points.
const Field< PointType > & faceNormals0() const
Return old-time face normals for patch.