lumpedPointDisplacementPointPatchVectorField.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 
29 #include "lumpedPointMovement.H"
30 #include "lumpedPointIOMovement.H"
32 #include "pointFields.H"
33 #include "surfaceFields.H"
34 #include "volFields.H"
35 #include "Time.H"
36 #include "polyMesh.H"
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
44  (
46  lumpedPointDisplacementPointPatchVectorField
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
52 
55 (
56  const pointVectorField& pvf
57 )
58 {
59  const pointVectorField::Boundary& bf = pvf.boundaryField();
60 
61  DynamicList<label> patchLst(bf.size());
62  forAll(bf, patchi)
63  {
64  // All patches of this type
65  if (isA<patchType>(bf[patchi]))
66  {
67  patchLst.append(patchi);
68  // or patchLst.append(bf[patchi].patch().index());
69  }
70  }
71 
72  return patchLst.shrink();
73 }
74 
75 
76 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
77 
78 const Foam::pointField&
80 {
81  const objectRegistry& obr = this->patch().boundaryMesh().mesh().db();
82 
83  // Obtain starting locations from the motionSolver
85  (
86  "dynamicMeshDict"
87  ).points0();
88 }
89 
90 
93 {
94  const objectRegistry& obr = this->patch().boundaryMesh().mesh().db();
95  const lumpedPointIOMovement* ptr =
97 
98  if (ptr)
99  {
100  return *ptr; // Already exists
101  }
102 
103  // create and register with this patch as the owner
105  (
106  obr,
107  this->patch().index()
108  );
109 
110  return objectRegistry::store(obj);
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
115 
118 (
119  const pointPatch& p,
121 )
122 :
124 {}
125 
126 
129 (
130  const pointPatch& p,
132  const dictionary& dict
133 )
134 :
136 {}
137 
138 
141 (
143  const pointPatch& p,
145  const pointPatchFieldMapper& mapper
146 )
147 :
148  fixedValuePointPatchField<vector>(pf, p, iF, mapper)
149 {}
150 
151 
154 (
157 )
158 :
160 {}
161 
162 
163 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164 
167 {
168  // de-register movement if in use and managed by this patch
170  (
171  this->patch().boundaryMesh().mesh().db()
172  );
173 
174  if (ptr && ptr->ownerId() == this->patch().index())
175  {
176  movement().coupler().shutdown();
177 
178  const_cast<lumpedPointIOMovement*>(ptr)->checkOut();
179  }
180 }
181 
182 
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 
186 {
187  if (this->updated())
188  {
189  return;
190  }
191 
192  enum Time::stopAtControls action = Time::stopAtControls::saUnknown;
193 
194  const bool masterPatch = (movement().ownerId() == this->patch().index());
195  if (masterPatch)
196  {
198  {
199  Pout<<"masterPatch: " << this->patch().index() << endl;
200  }
201 
202  const polyMesh& mesh = this->patch().boundaryMesh().mesh().mesh();
203 
204  // need face 'zones' for calculating forces
205  // likely need bounding box for the movement
206  // -> do both now if required
207  if (!movement().hasMapping())
208  {
209  const_cast<lumpedPointMovement&>(movement()).setMapping
210  (
211  mesh,
212  // All patches of this type
213  patchIds
214  (
215  static_cast<const pointVectorField&>
216  (
217  this->internalField()
218  )
219  ),
220  this->points0()
221  );
222  }
223 
224 
225  if
226  (
227  movement().coupler().initialized()
228  || !movement().coupler().slaveFirst()
229  )
230  {
231  // Synchronized for all processes
232  List<vector> forces, moments;
233  movement().forcesAndMoments(mesh, forces, moments);
234 
236  {
237  Pout<<"gatherForces: " << forces << " called from patch "
238  << this->patch().index() << endl;
239 
240  if (Pstream::master())
241  {
242  Pout<<"output forces to file: "
243  << movement().locations() << " called from patch "
244  << this->patch().index() << nl
245  <<"# " << forces.size() << " force entries" << nl
246  <<"# fx fy fz" << nl
247  <<"output forces to file: "
248  << forces << " called from patch "
249  << this->patch().index() << endl;
250  }
251  }
252 
253  if (Pstream::master())
254  {
255  movement().writeData(forces, moments, &(db().time()));
256 
257  // Signal external source to execute
258  movement().coupler().useSlave();
259  }
260  }
261 
262  // Wait for slave to provide data (includes MPI barrier)
263  // and catch any abort information sent from slave
264  action = movement().coupler().waitForSlave();
265 
266  // Read data passed back from external source - includes MPI barrier
267  const_cast<lumpedPointMovement&>(movement()).readState();
268  }
269 
270  tmp<pointField> tdisp = movement().displacePoints
271  (
272  this->points0(),
273  this->patch().meshPoints()
274  );
275 
276  this->operator==(tdisp);
277 
279 
280  // Process any abort information sent from slave
281  if
282  (
283  action != this->db().time().stopAt()
284  && action != Time::stopAtControls::saUnknown
285  )
286  {
287  this->db().time().stopAt(action);
288  }
289 }
290 
291 
293 const
294 {
296  writeEntry("value", os);
297 }
298 
299 
300 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
volFields.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::lumpedPointIOMovement
IO-registered version of lumpedPointMovement.
Definition: lumpedPointIOMovement.H:57
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::DynamicList< label >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceFields.H
Foam::surfaceFields.
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
Foam::lumpedPointMovement::ownerId
label ownerId() const
An owner Id, if needed for bookkeeping purposes.
Definition: lumpedPointMovementI.H:58
polyMesh.H
Foam::lumpedPointDisplacementPointPatchVectorField::patchIds
static labelList patchIds(const pointVectorField &pvf)
The ids for all patches of this type.
Definition: lumpedPointDisplacementPointPatchVectorField.C:55
Foam::lumpedPointDisplacementPointPatchVectorField
This is the point-patch responsible for managing the force integration on a 'lumped-point' basis,...
Definition: lumpedPointDisplacementPointPatchVectorField.H:76
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::pointPatchField< vector >::patch
const pointPatch & patch() const
Return patch.
Definition: pointPatchField.H:268
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:432
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::fixedValuePointPatchField< vector >
Foam::makePointPatchTypeField
makePointPatchTypeField(pointPatchVectorField, solidBodyMotionDisplacementPointPatchVectorField)
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
Foam::Field< vector >
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::valuePointPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: valuePointPatchField.C:135
Foam::pointPatchField::write
virtual void write(Ostream &) const
Write.
Definition: pointPatchField.C:116
Foam::lumpedPointIOMovement::lookupInRegistry
static const lumpedPointIOMovement * lookupInRegistry(const objectRegistry &obr)
Lookup pointer to object in the object-registry,.
Definition: lumpedPointIOMovement.C:42
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
Foam::pointBoundaryMesh::mesh
const pointMesh & mesh() const
Return the mesh reference.
Definition: pointBoundaryMesh.H:96
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
Foam::displacementMotionSolver
Virtual base class for displacement motion solver.
Definition: displacementMotionSolver.H:53
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
lumpedPointIOMovement.H
Foam::lumpedPointDisplacementPointPatchVectorField::~lumpedPointDisplacementPointPatchVectorField
virtual ~lumpedPointDisplacementPointPatchVectorField()
Destructor. De-register movement if in use and managed by this patch.
Definition: lumpedPointDisplacementPointPatchVectorField.C:166
displacementMotionSolver.H
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::lumpedPointDisplacementPointPatchVectorField::lumpedPointDisplacementPointPatchVectorField
lumpedPointDisplacementPointPatchVectorField(const pointPatch &p, const DimensionedField< vector, pointMesh > &iF)
Construct from patch and internal field.
Definition: lumpedPointDisplacementPointPatchVectorField.C:118
Time.H
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::regIOobject::store
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:37
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::lumpedPointDisplacementPointPatchVectorField::write
virtual void write(Ostream &os) const
Write.
Definition: lumpedPointDisplacementPointPatchVectorField.C:292
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::lumpedPointMovement
The movement driver that describes initial point locations, the segmentation for pressure integration...
Definition: lumpedPointMovement.H:260
Foam::pointPatch::boundaryMesh
const pointBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: pointPatch.H:135
Foam::lumpedPointDisplacementPointPatchVectorField::points0
const pointField & points0() const
The starting locations (obtained from the motionSolver).
Definition: lumpedPointDisplacementPointPatchVectorField.C:79
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:61
Foam::pointPatchVectorField
pointPatchField< vector > pointPatchVectorField
Definition: pointPatchFieldsFwd.H:43
Foam::Time::stopAtControls
stopAtControls
Definition: Time.H:97
Foam::lumpedPointDisplacementPointPatchVectorField::movement
const lumpedPointMovement & movement() const
The auto-vivifying singleton for movement.
Definition: lumpedPointDisplacementPointPatchVectorField.C:92
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
lumpedPointDisplacementPointPatchVectorField.H
Foam::GeometricField< vector, pointPatchField, pointMesh >
lumpedPointMovement.H
pointFields.H
Foam::lumpedPointDisplacementPointPatchVectorField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: lumpedPointDisplacementPointPatchVectorField.C:185
Foam::lumpedPointIOMovement::New
static autoPtr< lumpedPointIOMovement > New(const objectRegistry &obr, label ownerId=-1)
Create a new object in the registry by reading system dictionary.
Definition: lumpedPointIOMovement.C:53
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54