lumpedPointTools.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) 2016-2020 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 #include "lumpedPointTools.H"
28 #include "IFstream.H"
29 #include "IOobjectList.H"
30 #include "volFields.H"
31 #include "points0MotionSolver.H"
33 
34 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 template<class GeoFieldType>
41 (
42  const pointMesh::Mesh& mesh,
43  const IOobject* io
44 )
45 {
46  if (io && io->isHeaderClass<GeoFieldType>())
47  {
48  Info<< "Reading " << io->headerClassName()
49  << ' ' << io->name() << endl;
50 
52  (
53  IOobject
54  (
55  io->name(),
56  io->instance(),
57  io->local(),
58  io->db(),
62  ),
63  mesh
64  );
65  }
66 
67  return nullptr;
68 }
69 
70 } // End namespace Foam
71 
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
77 (
78  const dictionary& dict,
79  quaternion::eulerOrder rotOrder,
80  bool degrees
81 )
82 {
83  quaternion::eulerOrderNames.readIfPresent
84  (
85  "rotationOrder",
86  dict,
87  rotOrder
88  );
89 
90  dict.readIfPresent("degrees", degrees);
91 
92  Info<<"Reading states\n";
93  List<dictionary> entries(dict.lookup("response"));
94 
95  DynamicList<Tuple2<scalar, lumpedPointState>> states(entries.size());
96 
97  for (const dictionary& subDict : entries)
98  {
99  states.append
100  (
102  (
103  subDict.get<scalar>("time"),
104  lumpedPointState(subDict)
105  )
106  );
107  }
109  return states.shrink();
110 }
111 
112 
115 (
116  Istream& is,
117  quaternion::eulerOrder rotOrder,
118  bool degrees
119 )
120 {
122  return lumpedPointStates(dict, rotOrder, degrees);
123 }
124 
125 
128 (
129  const fileName& file,
130  quaternion::eulerOrder rotOrder,
131  bool degrees
132 )
133 {
134  IFstream is(file);
135  return lumpedPointStates(is, rotOrder, degrees);
136 }
137 
138 
141 {
142  return pointIOField(points0MotionSolver::points0IO(mesh));
143 }
144 
145 
148 {
150 }
151 
152 
154 (
155  const polyMesh& mesh
156 )
157 {
158  IOobjectList objects0(mesh, "0");
159 
160  pointMesh pMesh(mesh);
161 
162  autoPtr<pointVectorField> displacePtr =
163  loadPointField<pointVectorField>
164  (
165  pMesh,
166  objects0.findObject("pointDisplacement")
167  );
168 
169  if (!displacePtr)
170  {
171  Info<< "No valid pointDisplacement" << endl;
172  return labelList();
173  }
175  return lumpedPointPatchList(*displacePtr);
176 }
177 
178 
179 Foam::label
181 (
182  const pointVectorField& pvf,
183  const pointField& points0
184 )
185 {
186  return
188  (
189  pvf,
190  points0
191  );
192 }
193 
194 
196 (
197  const fvMesh& mesh,
198  const pointField& points0
199 )
200 {
201  IOobjectList objects0(mesh, "0");
202 
203  pointMesh pMesh(mesh);
204 
205  autoPtr<pointVectorField> displacePtr =
206  loadPointField<pointVectorField>
207  (
208  pMesh,
209  objects0.findObject("pointDisplacement")
210  );
211 
212  if (!displacePtr)
213  {
214  Info<< "No valid pointDisplacement" << endl;
215  return 0;
216  }
217 
218  return setPatchControls(*displacePtr, points0);
219 }
220 
221 
223 (
224  const fvMesh& mesh
225 )
226 {
228 
229  return setPatchControls(mesh, points0);
230 }
231 
232 
234 (
235  const pointVectorField& pvf,
236  const pointField& points0
237 )
238 {
239  return
241  (
242  pvf,
243  points0
244  );
245 }
246 
247 
249 (
250  const fvMesh& mesh,
251  const pointField& points0
252 )
253 {
254  IOobjectList objects0(mesh, "0");
255 
256  pointMesh pMesh(mesh);
257 
258  autoPtr<pointVectorField> displacePtr =
259  loadPointField<pointVectorField>
260  (
261  pMesh,
262  objects0.findObject("pointDisplacement")
263  );
264 
265  if (!displacePtr)
266  {
267  Info<< "No valid pointDisplacement" << endl;
268  return 0;
269  }
270 
271  return setInterpolators(*displacePtr, points0);
272 }
273 
274 
276 (
277  const fvMesh& mesh
278 )
279 {
281 
282  return setInterpolators(mesh, points0);
283 }
284 
285 
286 // ************************************************************************* //
labelList patchIds
dictionary dict
List< lumpedPointStateTuple > lumpedPointStates(const dictionary &dict, quaternion::eulerOrder rotOrder=quaternion::eulerOrder::ZXZ, bool degrees=false)
Load a list of states from a dictionary.
A class for handling file names.
Definition: fileName.H:72
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:38
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
pointIOField points0Field(const polyMesh &mesh)
Return the 0 or constant points field.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
dynamicFvMesh & mesh
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
labelList lumpedPointPatchList(const pointVectorField &pvf)
Return the patch-ids associated with a "lumpedPointDisplacement" type.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:450
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicList.H:584
eulerOrder
Euler-angle rotation order.
Definition: quaternion.H:115
Input from file stream, using an ISstream.
Definition: IFstream.H:49
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:266
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER)))
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:213
label setPatchControls(const pointVectorField &pvf, const pointField &points0)
Return the patch-ids associated with a "lumpedPointDisplacement" type.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
bool registerObject() const noexcept
Should objects created with this IOobject be registered?
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
const fileName & local() const noexcept
Read access to local path component.
Definition: IOobjectI.H:278
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
label setInterpolators(const pointVectorField &pvf, const pointField &points0)
Return the patch-ids associated with a "lumpedPointDisplacement" type.
A primitive field of type <T> with automated input and output.
static autoPtr< GeoFieldType > loadPointField(const pointMesh::Mesh &mesh, const IOobject *io)
The state of lumped points corresponds to positions and rotations.
Namespace for OpenFOAM.
bool isHeaderClass() const
Check if headerClassName() equals Type::typeName.
Definition: IOobjectI.H:258