pointConstraints.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 | Copyright (C) 2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointConstraints.H"
27 #include "emptyPointPatch.H"
28 #include "polyMesh.H"
29 #include "pointMesh.H"
30 #include "globalMeshData.H"
31 #include "twoDPointCorrector.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 defineTypeNameAndDebug(pointConstraints, 0);
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
46 {
47  if (debug)
48  {
49  Pout<< "pointConstraints::makePatchPatchAddressing() : "
50  << "constructing boundary addressing"
51  << endl << incrIndent;
52  }
53 
54  const pointMesh& pMesh = mesh();
55  const polyMesh& mesh = pMesh();
56 
57  const pointBoundaryMesh& pbm = pMesh.boundary();
58  const polyBoundaryMesh& bm = mesh.boundaryMesh();
59 
60 
61  // first count the total number of patch-patch points
62 
63  label nPatchPatchPoints = 0;
64 
65  forAll(pbm, patchi)
66  {
67  if (!isA<emptyPointPatch>(pbm[patchi]) && !pbm[patchi].coupled())
68  {
69  const labelList& bp = bm[patchi].boundaryPoints();
70 
71  nPatchPatchPoints += bp.size();
72 
73  if (debug)
74  {
75  Pout<< indent << "On patch:" << pbm[patchi].name()
76  << " nBoundaryPoints:" << bp.size() << endl;
77  }
78  }
79  }
80 
81  if (debug)
82  {
83  Pout<< indent << "Found nPatchPatchPoints:" << nPatchPatchPoints
84  << endl;
85  }
86 
87 
88  // Go through all patches and mark up the external edge points
89  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90 
91  // From meshpoint to index in patchPatchPointConstraints_.
92  Map<label> patchPatchPointSet(2*nPatchPatchPoints);
93 
94  // Constraints (initialised to unconstrained)
95  patchPatchPointConstraints_.setSize(nPatchPatchPoints);
97 
98  // From constraint index to mesh point
99  labelList patchPatchPoints(nPatchPatchPoints);
100 
101  label pppi = 0;
102 
103  forAll(pbm, patchi)
104  {
105  if (!isA<emptyPointPatch>(pbm[patchi]) && !pbm[patchi].coupled())
106  {
107  const labelList& bp = bm[patchi].boundaryPoints();
108  const labelList& meshPoints = pbm[patchi].meshPoints();
109 
110  forAll(bp, pointi)
111  {
112  label ppp = meshPoints[bp[pointi]];
113 
114  Map<label>::iterator iter = patchPatchPointSet.find(ppp);
115 
116  label constraintI = -1;
117 
118  if (iter == patchPatchPointSet.end())
119  {
120  patchPatchPointSet.insert(ppp, pppi);
121  patchPatchPoints[pppi] = ppp;
122  constraintI = pppi++;
123  }
124  else
125  {
126  constraintI = iter();
127  }
128 
129  // Apply to patch constraints
130  pbm[patchi].applyConstraint
131  (
132  bp[pointi],
133  patchPatchPointConstraints_[constraintI]
134  );
135  }
136  }
137  }
138 
139  if (debug)
140  {
141  Pout<< indent << "Have (local) constrained points:"
142  << nPatchPatchPoints << endl;
143  }
144 
145 
146  // Extend set with constraints across coupled points
147  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148 
149  {
150  const globalMeshData& gd = mesh.globalData();
151  const labelListList& globalPointSlaves = gd.globalPointSlaves();
152  const mapDistribute& globalPointSlavesMap = gd.globalPointSlavesMap();
153  const Map<label>& cpPointMap = gd.coupledPatch().meshPointMap();
154  const labelList& cpMeshPoints = gd.coupledPatch().meshPoints();
155 
156  // Constraints on coupled points
157  List<pointConstraint> constraints
158  (
159  globalPointSlavesMap.constructSize()
160  );
161 
162  // Copy from patchPatch constraints into coupledConstraints.
163  forAll(pbm, patchi)
164  {
165  if (!isA<emptyPointPatch>(pbm[patchi]) && !pbm[patchi].coupled())
166  {
167  const labelList& bp = bm[patchi].boundaryPoints();
168  const labelList& meshPoints = pbm[patchi].meshPoints();
169 
170  forAll(bp, pointi)
171  {
172  label ppp = meshPoints[bp[pointi]];
173 
174  Map<label>::const_iterator fnd = cpPointMap.find(ppp);
175  if (fnd != cpPointMap.end())
176  {
177  // Can just copy (instead of apply) constraint
178  // will already be consistent across multiple patches.
179  constraints[fnd()] = patchPatchPointConstraints_
180  [
181  patchPatchPointSet[ppp]
182  ];
183  }
184  }
185  }
186  }
187 
188  // Exchange data
189  globalPointSlavesMap.distribute(constraints);
190 
191  // Combine master with slave constraints
192  forAll(globalPointSlaves, pointI)
193  {
194  const labelList& slaves = globalPointSlaves[pointI];
195 
196  // Combine master constraint with slave constraints
197  forAll(slaves, i)
198  {
199  constraints[pointI].combine(constraints[slaves[i]]);
200  }
201  // Duplicate master constraint into slave slots
202  forAll(slaves, i)
203  {
204  constraints[slaves[i]] = constraints[pointI];
205  }
206  }
207 
208  // Send back
209  globalPointSlavesMap.reverseDistribute
210  (
211  cpMeshPoints.size(),
212  constraints
213  );
214 
215  // Add back into patchPatch constraints
216  forAll(constraints, coupledPointI)
217  {
218  if (constraints[coupledPointI].first() != 0)
219  {
220  label meshPointI = cpMeshPoints[coupledPointI];
221 
222  Map<label>::iterator iter = patchPatchPointSet.find(meshPointI);
223 
224  label constraintI = -1;
225 
226  if (iter == patchPatchPointSet.end())
227  {
228  //Pout<< indent << "on meshpoint:" << meshPointI
229  // << " coupled:" << coupledPointI
230  // << " at:" << mesh.points()[meshPointI]
231  // << " have new constraint:"
232  // << constraints[coupledPointI]
233  // << endl;
234 
235  // Allocate new constraint
236  if (patchPatchPoints.size() <= pppi)
237  {
238  patchPatchPoints.setSize(pppi+100);
239  }
240  patchPatchPointSet.insert(meshPointI, pppi);
241  patchPatchPoints[pppi] = meshPointI;
242  constraintI = pppi++;
243  }
244  else
245  {
246  //Pout<< indent << "on meshpoint:" << meshPointI
247  // << " coupled:" << coupledPointI
248  // << " at:" << mesh.points()[meshPointI]
249  // << " have possibly extended constraint:"
250  // << constraints[coupledPointI]
251  // << endl;
252 
253  constraintI = iter();
254  }
255 
256  // Combine (new or existing) constraint with one
257  // on coupled.
258  patchPatchPointConstraints_[constraintI].combine
259  (
260  constraints[coupledPointI]
261  );
262  }
263  }
264  }
265 
266 
267 
268  nPatchPatchPoints = pppi;
269  patchPatchPoints.setSize(nPatchPatchPoints);
270  patchPatchPointConstraints_.setSize(nPatchPatchPoints);
271 
272 
273  if (debug)
274  {
275  Pout<< indent << "Have (global) constrained points:"
276  << nPatchPatchPoints << endl;
277  }
278 
279 
280  // Copy out all non-trivial constraints
281  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282 
283  patchPatchPointConstraintPoints_.setSize(nPatchPatchPoints);
284  patchPatchPointConstraintTensors_.setSize(nPatchPatchPoints);
285 
286  label nConstraints = 0;
287 
289  {
290  // Note: check for more than zero constraints. (could check for
291  // more than one constraint but what about coupled points that
292  // inherit the constraintness)
293  if (patchPatchPointConstraints_[i].first() != 0)
294  {
295  patchPatchPointConstraintPoints_[nConstraints] =
296  patchPatchPoints[i];
297 
298  patchPatchPointConstraintTensors_[nConstraints] =
299  patchPatchPointConstraints_[i].constraintTransformation();
300 
301  nConstraints++;
302  }
303  }
304 
305  if (debug)
306  {
307  Pout<< indent << "Have non-trivial constrained points:"
308  << nConstraints << endl;
309  }
310 
311  patchPatchPointConstraints_.setSize(nConstraints);
313  patchPatchPointConstraintTensors_.setSize(nConstraints);
314 
315 
316  if (debug)
317  {
318  Pout<< decrIndent
319  << "pointConstraints::makePatchPatchAddressing() : "
320  << "finished constructing boundary addressing"
321  << endl;
322  }
323 }
324 
325 
326 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
327 
329 :
331 {
332  if (debug)
333  {
334  Pout<< "pointConstraints::pointConstraints(const pointMesh&): "
335  << "Constructing from pointMesh " << pm.name()
336  << endl;
337  }
338 
340 }
341 
342 
343 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
344 
346 {
347  if (debug)
348  {
349  Pout<< "pointConstraints::~pointConstraints()" << endl;
350  }
351 }
352 
353 
354 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
355 
357 {
359 }
360 
361 
363 {
364  return true;
365 }
366 
367 
369 (
370  pointVectorField& pf,
371  const bool overrideFixedValue
372 ) const
373 {
374  // Override constrained pointPatchField types with the constraint value.
375  // This relies on only constrained pointPatchField implementing the evaluate
376  // function
378 
379  // Sync any dangling points
380  syncUntransformedData
381  (
382  pf.mesh()(),
383  pf.internalField(),
385  );
386 
387  // Apply multiple constraints on edge/corner points
388  constrainCorners(pf);
389 
390  // Apply any 2D motion constraints (or should they go before
391  // corner constraints?)
393  (
394  mesh()().points(),
395  pf.internalField()
396  );
397 
398  if (overrideFixedValue)
399  {
400  setPatchFields(pf);
401  }
402 }
403 
404 
405 // Specialisation of constrainCorners for scalars because
406 // no constraint need be applied
407 template<>
408 void pointConstraints::constrainCorners<scalar>
409 (
411 ) const
412 {}
413 
414 
415 template<>
416 void pointConstraints::constrainCorners<label>
417 (
419 ) const
420 {}
421 
422 
423 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
424 
425 } // End namespace Foam
426 
427 // ************************************************************************* //
Foam::pointMesh::boundary
const pointBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: pointMesh.H:106
Foam::globalMeshData::globalPointSlaves
const labelListList & globalPointSlaves() const
Definition: globalMeshData.C:2170
Foam::pointConstraints::~pointConstraints
~pointConstraints()
Destructor.
Definition: pointConstraints.C:345
Foam::pointConstraints::pointConstraints
pointConstraints(const pointConstraints &)
Disallow default bitwise copy construct.
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
globalMeshData.H
Foam::twoDPointCorrector::correctDisplacement
void correctDisplacement(const pointField &p, vectorField &disp) const
Correct motion displacements.
Definition: twoDPointCorrector.C:311
Foam::pointMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: pointMesh.H:112
Foam::pointConstraint
Accumulates point constraints through successive applications of the applyConstraint function.
Definition: pointConstraint.H:56
Foam::Map< label >
Foam::maxMagSqrEqOp
Definition: ops.H:80
Foam::pointConstraints::patchPatchPointConstraintPoints_
labelList patchPatchPointConstraintPoints_
Mesh points on which to apply special constraints.
Definition: pointConstraints.H:71
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::pointConstraints::constrainDisplacement
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
Definition: pointConstraints.C:369
Foam::globalMeshData::globalPointSlavesMap
const mapDistribute & globalPointSlavesMap() const
Definition: globalMeshData.C:2191
polyMesh.H
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Foam::UpdateableMeshObject
Definition: MeshObject.H:258
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::MeshObject< polyMesh, UpdateableMeshObject, twoDPointCorrector >::New
static const twoDPointCorrector & New(const polyMesh &mesh)
Definition: MeshObject.C:44
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::MeshObject< pointMesh, UpdateableMeshObject, pointConstraints >::mesh
const pointMesh & mesh() const
Definition: MeshObject.H:144
pointConstraints.H
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:152
Foam::GeometricField::internalField
InternalField & internalField()
Return internal field.
Definition: GeometricField.C:724
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::pointConstraints::movePoints
bool movePoints()
Correct weighting factors for moving mesh.
Definition: pointConstraints.C:362
Foam::mapDistribute::distribute
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Definition: mapDistributeTemplates.C:155
Foam::globalMeshData
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
Definition: globalMeshData.H:106
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
Foam::pointConstraints::patchPatchPointConstraintTensors_
tensorField patchPatchPointConstraintTensors_
Special constraints (as tensors)
Definition: pointConstraints.H:73
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
emptyPointPatch.H
Foam::pointBoundaryMesh
Foam::pointBoundaryMesh.
Definition: pointBoundaryMesh.H:52
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:885
Foam::pointConstraints
Application of (multi-)patch point contraints.
Definition: pointConstraints.H:62
Foam::mapDistributeBase::constructSize
label constructSize() const
Constructed data size.
Definition: mapDistributeBase.H:244
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::pointConstraints::updateMesh
void updateMesh(const mapPolyMesh &)
Update mesh topology using the morph engine.
Definition: pointConstraints.C:356
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::pointConstraints::patchPatchPointConstraints_
List< pointConstraint > patchPatchPointConstraints_
Special constraints (raw)
Definition: pointConstraints.H:75
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:59
Foam::globalMeshData::coupledPatch
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
Definition: globalMeshData.C:2046
patchi
label patchi
Definition: getPatchFieldScalar.H:1
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::mapDistribute::reverseDistribute
void reverseDistribute(const label constructSize, List< T > &, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Definition: mapDistributeTemplates.C:187
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:81
twoDPointCorrector.H
Foam::pointConstraints::makePatchPatchAddressing
void makePatchPatchAddressing()
Make patch-patch constraints.
Definition: pointConstraints.C:45
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::PrimitivePatch::meshPointMap
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
Definition: PrimitivePatchTemplate.C:412
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatchTemplate.C:392
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
pointMesh.H