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-2017 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 
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  // file-scope
39  template<class GeoFieldType>
40  static autoPtr<GeoFieldType> loadPointField
41  (
42  const pointMesh::Mesh& mesh,
43  const IOobject* io
44  )
45  {
46  if (io && io->headerClassName() == GeoFieldType::typeName)
47  {
48  Info<< "Reading " << GeoFieldType::typeName
49  << ' ' << io->name() << endl;
50 
52  (
53  IOobject
54  (
55  io->name(),
56  io->instance(),
57  io->local(),
58  io->db(),
61  io->registerObject()
62  ),
63  mesh
64  );
65  }
66 
67  return nullptr;
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
76 {
77  dictionary contents(is);
78  List<dictionary> entries(contents.lookup("response"));
79 
80  DynamicList<Tuple2<scalar, lumpedPointState>> states(entries.size());
81 
82  for (const dictionary& dict : entries)
83  {
84  states.append
85  (
87  (
88  dict.get<scalar>("time"),
90  )
91  );
92  }
93 
94  return states.shrink();
95 }
96 
97 
100 {
101  IFstream is(file);
102  return lumpedPointStates(is);
103 }
104 
105 
108 {
109  pointIOField pts
110  (
111  IOobject
112  (
113  "points",
114  mesh.time().constant(),
115  polyMesh::meshSubDir,
116  mesh,
117  IOobject::MUST_READ,
118  IOobject::NO_WRITE,
119  false // Do not re-register
120  )
121  );
122 
123  return pts;
124 }
125 
126 
127 
130 {
132 }
133 
134 
136 (
137  const polyMesh& mesh
138 )
139 {
140  IOobjectList objects0(mesh, "0");
141 
142  pointMesh pMesh(mesh);
143 
144  autoPtr<pointVectorField> displacePtr = loadPointField<pointVectorField>
145  (
146  pMesh,
147  objects0.findObject("pointDisplacement")
148  );
149 
150  if (!displacePtr.valid())
151  {
152  Info<< "no valid pointDisplacement" << endl;
153  return labelList();
154  }
155 
156  return lumpedPointPatchList(displacePtr());
157 }
158 
159 
160 // ************************************************************************* //
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:74
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:97
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:57
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobjectI.H:167
Foam::IOobjectList::findObject
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:270
Foam::autoPtr::valid
bool valid() const noexcept
True if the managed pointer is non-null.
Definition: autoPtrI.H:107
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:432
Foam::lumpedPointTools::lumpedPointStates
List< lumpedPointStateTuple > lumpedPointStates(Istream &is)
Load a list of states from an Istream.
Definition: lumpedPointTools.C:75
Foam::lumpedPointState
The state of lumped points corresponds to positions and rotations.
Definition: lumpedPointState.H:111
Foam::IOobject::registerObject
bool registerObject() const
Should object created with this IOobject be registered?
Definition: IOobjectI.H:88
Foam::IOobject::local
const fileName & local() const
Definition: IOobjectI.H:179
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
Foam::loadPointField
static autoPtr< GeoFieldType > loadPointField(const pointMesh::Mesh &mesh, const IOobject *io)
Definition: lumpedPointTools.C:41
lumpedPointTools.H
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 (uses stdout - output is on the master only)
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
IFstream.H
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:419
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:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:50
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobjectI.H:64
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::lumpedPointTools::points0Field
pointIOField points0Field(const polyMesh &mesh)
Return the 0 or constant points field.
Definition: lumpedPointTools.C:107
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:57
lumpedPointDisplacementPointPatchVectorField.H
Foam::GeometricField< vector, pointPatchField, pointMesh >
Foam::lumpedPointTools::lumpedPointPatchList
labelList lumpedPointPatchList(const pointVectorField &pvf)
Return the patch-ids associated a "lumpedPointDisplacement" type.
Definition: lumpedPointTools.C:129
Foam::IOobject::MUST_READ
Definition: IOobject.H:120