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  template<class GeoFieldType>
40  (
41  const pointMesh::Mesh& mesh,
42  const IOobject* io
43  )
44  {
45  if (io && io->headerClassName() == GeoFieldType::typeName)
46  {
47  Info<< "Reading " << GeoFieldType::typeName
48  << ' ' << io->name() << endl;
49 
51  (
52  IOobject
53  (
54  io->name(),
55  io->instance(),
56  io->local(),
57  io->db(),
61  ),
62  mesh
63  );
64  }
65 
66  return nullptr;
67  }
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
75 (
76  const dictionary& dict,
77  quaternion::eulerOrder rotOrder,
78  bool degrees
79 )
80 {
81  quaternion::eulerOrderNames.readIfPresent
82  (
83  "rotationOrder",
84  dict,
85  rotOrder
86  );
87 
88  dict.readIfPresent("degrees", degrees);
89 
90  Info<<"Reading states\n";
91  List<dictionary> entries(dict.lookup("response"));
92 
93  DynamicList<Tuple2<scalar, lumpedPointState>> states(entries.size());
94 
95  for (const dictionary& subDict : entries)
96  {
97  states.append
98  (
100  (
101  subDict.get<scalar>("time"),
102  lumpedPointState(subDict)
103  )
104  );
105  }
107  return states.shrink();
108 }
109 
110 
113 (
114  Istream& is,
115  quaternion::eulerOrder rotOrder,
116  bool degrees
117 )
118 {
120  return lumpedPointStates(dict, rotOrder, degrees);
121 }
122 
123 
126 (
127  const fileName& file,
128  quaternion::eulerOrder rotOrder,
129  bool degrees
130 )
131 {
132  IFstream is(file);
133  return lumpedPointStates(is, rotOrder, degrees);
134 }
135 
136 
139 {
140  return pointIOField(points0MotionSolver::points0IO(mesh));
141 }
142 
143 
146 {
148 }
149 
150 
152 (
153  const polyMesh& mesh
154 )
155 {
156  IOobjectList objects0(mesh, "0");
157 
158  pointMesh pMesh(mesh);
159 
160  autoPtr<pointVectorField> displacePtr =
161  loadPointField<pointVectorField>
162  (
163  pMesh,
164  objects0.findObject("pointDisplacement")
165  );
166 
167  if (!displacePtr)
168  {
169  Info<< "No valid pointDisplacement" << endl;
170  return labelList();
171  }
173  return lumpedPointPatchList(*displacePtr);
174 }
175 
176 
177 Foam::label
179 (
180  const pointVectorField& pvf,
181  const pointField& points0
182 )
183 {
184  return
186  (
187  pvf,
188  points0
189  );
190 }
191 
192 
194 (
195  const fvMesh& mesh,
196  const pointField& points0
197 )
198 {
199  IOobjectList objects0(mesh, "0");
200 
201  pointMesh pMesh(mesh);
202 
203  autoPtr<pointVectorField> displacePtr =
204  loadPointField<pointVectorField>
205  (
206  pMesh,
207  objects0.findObject("pointDisplacement")
208  );
209 
210  if (!displacePtr)
211  {
212  Info<< "No valid pointDisplacement" << endl;
213  return 0;
214  }
215 
216  return setPatchControls(*displacePtr, points0);
217 }
218 
219 
221 (
222  const fvMesh& mesh
223 )
224 {
226 
227  return setPatchControls(mesh, points0);
228 }
229 
230 
232 (
233  const pointVectorField& pvf,
234  const pointField& points0
235 )
236 {
237  return
239  (
240  pvf,
241  points0
242  );
243 }
244 
245 
247 (
248  const fvMesh& mesh,
249  const pointField& points0
250 )
251 {
252  IOobjectList objects0(mesh, "0");
253 
254  pointMesh pMesh(mesh);
255 
256  autoPtr<pointVectorField> displacePtr =
257  loadPointField<pointVectorField>
258  (
259  pMesh,
260  objects0.findObject("pointDisplacement")
261  );
262 
263  if (!displacePtr)
264  {
265  Info<< "No valid pointDisplacement" << endl;
266  return 0;
267  }
268 
269  return setInterpolators(*displacePtr, points0);
270 }
271 
272 
274 (
275  const fvMesh& mesh
276 )
277 {
279 
280  return setInterpolators(mesh, points0);
281 }
282 
283 
284 // ************************************************************************* //
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:71
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:120
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:55
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
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:487
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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:441
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicList.H:558
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:221
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:168
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:79
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:73
List< label > labelList
A List of labels.
Definition: List.H:62
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:233
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
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.