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>
39  static autoPtr<GeoFieldType> loadPointField
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(),
60  io->registerObject()
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  }
106 
107  return states.shrink();
108 }
109 
110 
113 (
114  Istream& is,
115  quaternion::eulerOrder rotOrder,
116  bool degrees
117 )
118 {
119  dictionary dict(is);
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  }
172 
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 // ************************************************************************* //
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::lumpedPointTools::setPatchControls
label setPatchControls(const pointVectorField &pvf, const pointField &points0)
Return the patch-ids associated with a "lumpedPointDisplacement" type.
Definition: lumpedPointTools.C:179
Foam::IOobject::registerObject
bool registerObject() const noexcept
Should object created with this IOobject be registered?
Definition: IOobjectI.H:107
Foam::IOobject::instance
const fileName & instance() const noexcept
Definition: IOobjectI.H:196
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::IOobjectList::findObject
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:270
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::IOobject::headerClassName
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:83
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::lumpedPointState
The state of lumped points corresponds to positions and rotations.
Definition: lumpedPointState.H:112
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
Foam::loadPointField
static autoPtr< GeoFieldType > loadPointField(const pointMesh::Mesh &mesh, const IOobject *io)
Definition: lumpedPointTools.C:40
lumpedPointTools.H
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
points0MotionSolver.H
Foam::IOobject::local
const fileName & local() const noexcept
Definition: IOobjectI.H:208
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::lumpedPointTools::lumpedPointStates
List< lumpedPointStateTuple > lumpedPointStates(const dictionary &dict, quaternion::eulerOrder rotOrder=quaternion::eulerOrder::ZXZ, bool degrees=false)
Load a list of states from a dictionary.
Definition: lumpedPointTools.C:75
Foam::quaternion::eulerOrder
eulerOrder
Euler-angle rotation order.
Definition: quaternion.H:102
IFstream.H
Foam::lumpedPointTools::setInterpolators
label setInterpolators(const pointVectorField &pvf, const pointField &points0)
Return the patch-ids associated with a "lumpedPointDisplacement" type.
Definition: lumpedPointTools.C:232
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
points0
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::lumpedPointTools::points0Field
pointIOField points0Field(const polyMesh &mesh)
Return the 0 or constant points field.
Definition: lumpedPointTools.C:138
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60
lumpedPointDisplacementPointPatchVectorField.H
Foam::GeometricField< vector, pointPatchField, pointMesh >
Foam::lumpedPointTools::lumpedPointPatchList
labelList lumpedPointPatchList(const pointVectorField &pvf)
Return the patch-ids associated with a "lumpedPointDisplacement" type.
Definition: lumpedPointTools.C:145
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
Foam::IOobject::db
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:487