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  label statei = 0;
96 
97  // List<lumpedPointStateTuple>
98  List<Tuple2<scalar, lumpedPointState>> states(entries.size());
99 
100  for (const dictionary& subDict : entries)
101  {
102  states[statei] =
104  (
105  subDict.get<scalar>("time"),
106  lumpedPointState(subDict)
107  );
108 
109  ++statei;
110  }
112  return states;
113 }
114 
115 
118 (
119  Istream& is,
120  quaternion::eulerOrder rotOrder,
121  bool degrees
122 )
123 {
125  return lumpedPointStates(dict, rotOrder, degrees);
126 }
127 
128 
131 (
132  const fileName& file,
133  quaternion::eulerOrder rotOrder,
134  bool degrees
135 )
136 {
137  IFstream is(file);
138  return lumpedPointStates(is, rotOrder, degrees);
139 }
140 
141 
144 {
145  return pointIOField(points0MotionSolver::points0IO(mesh));
146 }
147 
148 
151 {
153 }
154 
155 
157 (
158  const polyMesh& mesh
159 )
160 {
161  IOobjectList objects0(mesh, "0");
162 
163  pointMesh pMesh(mesh);
164 
165  autoPtr<pointVectorField> displacePtr =
166  loadPointField<pointVectorField>
167  (
168  pMesh,
169  objects0.findObject("pointDisplacement")
170  );
171 
172  if (!displacePtr)
173  {
174  Info<< "No valid pointDisplacement" << endl;
175  return labelList();
176  }
178  return lumpedPointPatchList(*displacePtr);
179 }
180 
181 
182 Foam::label
184 (
185  const pointVectorField& pvf,
186  const pointField& points0
187 )
188 {
189  return
191  (
192  pvf,
193  points0
194  );
195 }
196 
197 
199 (
200  const fvMesh& mesh,
201  const pointField& points0
202 )
203 {
204  IOobjectList objects0(mesh, "0");
205 
206  pointMesh pMesh(mesh);
207 
208  autoPtr<pointVectorField> displacePtr =
209  loadPointField<pointVectorField>
210  (
211  pMesh,
212  objects0.findObject("pointDisplacement")
213  );
214 
215  if (!displacePtr)
216  {
217  Info<< "No valid pointDisplacement" << endl;
218  return 0;
219  }
220 
221  return setPatchControls(*displacePtr, points0);
222 }
223 
224 
226 (
227  const fvMesh& mesh
228 )
229 {
231 
232  return setPatchControls(mesh, points0);
233 }
234 
235 
237 (
238  const pointVectorField& pvf,
239  const pointField& points0
240 )
241 {
242  return
244  (
245  pvf,
246  points0
247  );
248 }
249 
250 
252 (
253  const fvMesh& mesh,
254  const pointField& points0
255 )
256 {
257  IOobjectList objects0(mesh, "0");
258 
259  pointMesh pMesh(mesh);
260 
261  autoPtr<pointVectorField> displacePtr =
262  loadPointField<pointVectorField>
263  (
264  pMesh,
265  objects0.findObject("pointDisplacement")
266  );
267 
268  if (!displacePtr)
269  {
270  Info<< "No valid pointDisplacement" << endl;
271  return 0;
272  }
273 
274  return setInterpolators(*displacePtr, points0);
275 }
276 
277 
279 (
280  const fvMesh& mesh
281 )
282 {
284 
285  return setInterpolators(mesh, points0);
286 }
287 
288 
289 // ************************************************************************* //
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
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:529
Tuple2< scalar, lumpedPointState > lumpedPointStateTuple
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
dynamicFvMesh & mesh
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
eulerOrder
Euler-angle rotation order.
Definition: quaternion.H:115
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
Definition: IFstream.H:51
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:75
List< label > labelList
A List of labels.
Definition: List.H:61
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:180
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