Loading...
Searching...
No Matches
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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "pointConstraints.H"
30#include "emptyPointPatch.H"
31#include "polyMesh.H"
32#include "pointMesh.H"
34#include "twoDPointCorrector.H"
35
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
41}
42
43
44// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45
46void Foam::pointConstraints::makePatchPatchAddressing()
47{
48 if (debug)
49 {
50 Pout<< "pointConstraints::makePatchPatchAddressing() : "
51 << "constructing boundary addressing"
52 << endl << incrIndent;
53 }
54
55 const pointMesh& pMesh = mesh();
56 const polyMesh& mesh = pMesh();
57
58 const pointBoundaryMesh& pbm = pMesh.boundary();
59
60 // first count the total number of patch-patch points
61
62 label nPatchPatchPoints = 0;
63
64 forAll(pbm, patchi)
65 {
66 const auto* fpp = isA<facePointPatch>(pbm[patchi]);
67 if
68 (
69 fpp
70 && !isA<emptyPointPatch>(pbm[patchi])
71 && !pbm[patchi].coupled()
72 )
73 {
74 const labelList& bp = fpp->patch().boundaryPoints();
75
76 nPatchPatchPoints += bp.size();
77
78 if (debug)
79 {
80 Pout<< indent << "On patch:" << pbm[patchi].name()
81 << " nBoundaryPoints:" << bp.size() << endl;
82 }
83 }
84 }
85
86 if (debug)
87 {
88 Pout<< indent << "Found nPatchPatchPoints:" << nPatchPatchPoints
89 << endl;
90 }
91
92
93 // Go through all patches and mark up the external edge points
94 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
96 // From meshpoint to index in patchPatchPointConstraints_.
97 Map<label> patchPatchPointSet(2*nPatchPatchPoints);
98
99 // Constraints (initialised to unconstrained)
100 patchPatchPointConstraints_.setSize(nPatchPatchPoints);
101 patchPatchPointConstraints_ = pointConstraint();
102
103 // From constraint index to mesh point
104 labelList patchPatchPoints(nPatchPatchPoints);
105
106 label pppi = 0;
107
108 forAll(pbm, patchi)
109 {
110 const auto* fpp = isA<facePointPatch>(pbm[patchi]);
111 if
112 (
113 fpp
114 && !isA<emptyPointPatch>(pbm[patchi])
115 && !pbm[patchi].coupled()
116 )
117 {
118 const labelList& bp = fpp->patch().boundaryPoints();
119 const labelList& meshPoints = pbm[patchi].meshPoints();
120
121 forAll(bp, pointi)
122 {
123 const label ppp = meshPoints[bp[pointi]];
124
125 const auto iter = patchPatchPointSet.cfind(ppp);
126
127 label constraintI = -1;
128
129 if (iter.good())
130 {
131 constraintI = iter.val();
132 }
133 else
134 {
135 patchPatchPointSet.insert(ppp, pppi);
136 patchPatchPoints[pppi] = ppp;
137 constraintI = pppi++;
138 }
139
140 // Apply to patch constraints
141 pbm[patchi].applyConstraint
142 (
143 bp[pointi],
144 patchPatchPointConstraints_[constraintI]
145 );
146 }
147 }
148 }
149
150 if (debug)
151 {
152 Pout<< indent << "Have (local) constrained points:"
153 << nPatchPatchPoints << endl;
154 }
155
156
157 // Extend set with constraints across coupled points
158 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159
160 {
161 const globalMeshData& gd = mesh.globalData();
162 const labelListList& globalPointSlaves = gd.globalPointSlaves();
163 const mapDistribute& globalPointSlavesMap = gd.globalPointSlavesMap();
164 const Map<label>& cpPointMap = gd.coupledPatch().meshPointMap();
165 const labelList& cpMeshPoints = gd.coupledPatch().meshPoints();
166
167 // Constraints on coupled points
168 List<pointConstraint> constraints
169 (
170 globalPointSlavesMap.constructSize()
171 );
172
173 // Copy from patchPatch constraints into coupledConstraints.
174 forAll(pbm, patchi)
175 {
176 const auto* fpp = isA<facePointPatch>(pbm[patchi]);
177 if
178 (
179 fpp
180 && !isA<emptyPointPatch>(pbm[patchi])
181 && !pbm[patchi].coupled()
182 )
183 {
184 const labelList& bp = fpp->patch().boundaryPoints();
185 const labelList& meshPoints = pbm[patchi].meshPoints();
186
187 forAll(bp, pointi)
188 {
189 const label ppp = meshPoints[bp[pointi]];
190
191 const auto iter = cpPointMap.cfind(ppp);
192
193 if (iter.good())
194 {
195 // Can just copy (instead of apply) constraint
196 // will already be consistent across multiple patches.
197 constraints[iter.val()] = patchPatchPointConstraints_
198 [
199 patchPatchPointSet[ppp]
200 ];
201 }
202 }
203 }
204 }
205
206 // Exchange data
207 globalPointSlavesMap.distribute(constraints);
208
209 // Combine master with slave constraints
210 forAll(globalPointSlaves, pointi)
211 {
212 const labelList& slaves = globalPointSlaves[pointi];
213
214 // Combine master constraint with slave constraints
215 forAll(slaves, i)
216 {
217 constraints[pointi].combine(constraints[slaves[i]]);
218 }
219 // Duplicate master constraint into slave slots
220 forAll(slaves, i)
221 {
222 constraints[slaves[i]] = constraints[pointi];
223 }
224 }
225
226 // Send back
227 globalPointSlavesMap.reverseDistribute
228 (
229 cpMeshPoints.size(),
230 constraints
231 );
232
233 // Add back into patchPatch constraints
234 forAll(constraints, coupledPointi)
235 {
236 if (constraints[coupledPointi].first() != 0)
237 {
238 label meshPointi = cpMeshPoints[coupledPointi];
239
240 const auto iter = patchPatchPointSet.cfind(meshPointi);
241
242 label constraintI = -1;
243
244 if (iter.good())
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.val();
254 }
255 else
256 {
257 //Pout<< indent << "on meshpoint:" << meshPointi
258 // << " coupled:" << coupledPointi
259 // << " at:" << mesh.points()[meshPointi]
260 // << " have new constraint:"
261 // << constraints[coupledPointi]
262 // << endl;
263
264 // Allocate new constraint
265 if (patchPatchPoints.size() <= pppi)
266 {
267 // Check if not enough space. This
268 // can occasionally happen if -coupled points connect
269 // to the inside of a patch -these coupled points also
270 // carry a constraint
271 patchPatchPoints.setSize(pppi+100);
272 patchPatchPointConstraints_.setSize
273 (
274 pppi+100,
275 pointConstraint()
276 );
277 }
278 patchPatchPointSet.insert(meshPointi, pppi);
279 patchPatchPoints[pppi] = meshPointi;
280 constraintI = pppi++;
281 }
282
283 // Combine (new or existing) constraint with one
284 // on coupled.
285 patchPatchPointConstraints_[constraintI].combine
286 (
287 constraints[coupledPointi]
288 );
289 }
290 }
291 }
292
293
294
295 nPatchPatchPoints = pppi;
296 patchPatchPoints.setSize(nPatchPatchPoints);
297 patchPatchPointConstraints_.setSize(nPatchPatchPoints);
298
299
300 if (debug)
301 {
302 Pout<< indent << "Have (global) constrained points:"
303 << nPatchPatchPoints << endl;
304 }
305
306
307 // Copy out all non-trivial constraints
308 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
309
310 patchPatchPointConstraintPoints_.setSize(nPatchPatchPoints);
311 patchPatchPointConstraintTensors_.setSize(nPatchPatchPoints);
312
313 label nConstraints = 0;
314
315 forAll(patchPatchPointConstraints_, i)
316 {
317 // Note: check for more than zero constraints. (could check for
318 // more than one constraint but what about coupled points that
319 // inherit the constraintness)
320 if (patchPatchPointConstraints_[i].first() != 0)
321 {
322 patchPatchPointConstraintPoints_[nConstraints] =
323 patchPatchPoints[i];
324
325 patchPatchPointConstraintTensors_[nConstraints] =
326 patchPatchPointConstraints_[i].constraintTransformation();
327
328 nConstraints++;
329 }
330 }
331
332 if (debug)
333 {
334 Pout<< indent << "Have non-trivial constrained points:"
335 << nConstraints << endl;
336 }
337
338 patchPatchPointConstraints_.setSize(nConstraints);
339 patchPatchPointConstraintPoints_.setSize(nConstraints);
340 patchPatchPointConstraintTensors_.setSize(nConstraints);
341
342
343 if (debug)
344 {
346 << "pointConstraints::makePatchPatchAddressing() : "
347 << "finished constructing boundary addressing"
349 }
350}
351
352
353// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
354
355Foam::pointConstraints::pointConstraints(const pointMesh& pm)
356:
357 MeshObject_type(pm)
358{
359 if (debug)
360 {
361 Pout<< "pointConstraints::pointConstraints(const pointMesh&): "
362 << "Constructing from pointMesh " << pm.name()
363 << endl;
364 }
366 makePatchPatchAddressing();
367}
368
369
370// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
371
373{
374 if (debug)
375 {
376 Pout<< "pointConstraints::~pointConstraints()" << endl;
377 }
378}
379
380
381// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
384{
385 makePatchPatchAddressing();
386}
387
390{
391 return true;
392}
393
394
396(
398 const bool overrideFixedValue
399) const
400{
401 // Override constrained pointPatchField types with the constraint value.
402 // This relies on only constrained pointPatchField implementing the evaluate
403 // function
405
406 // Sync any dangling points
407 syncUntransformedData
408 (
409 pf.mesh()(),
412 );
413
414 // Apply multiple constraints on edge/corner points
415 constrainCorners(pf);
416
417 // Apply any 2D motion constraints (or should they go before
418 // corner constraints?)
420 (
421 mesh()().points(),
423 );
424
425 if (overrideFixedValue)
427 setPatchFields(pf);
428 }
429}
430
431
432template<>
433void Foam::pointConstraints::constrainCorners<Foam::scalar>
435 GeometricField<scalar, pointPatchField, pointMesh>& pf
436) const
437{}
438
439
440template<>
441void Foam::pointConstraints::constrainCorners<Foam::label>
442(
444) const
445{}
446
447
448// ************************************************************************* //
const polyBoundaryMesh & pbm
const Mesh & mesh() const noexcept
Return const reference to mesh.
Generic GeometricField class.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
void correctBoundaryConditions()
Correct boundary field.
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
virtual const fileName & name() const
The name of the stream.
Definition IOstream.C:33
void setSize(label n)
Alias for resize().
Definition List.H:536
static FOAM_NO_DANGLING_REFERENCE const twoDPointCorrector & New(const polyMesh &mesh, Args &&... args)
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name).
Definition OSstream.H:134
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Application of (multi-)patch point constraints.
bool movePoints()
Correct weighting factors for moving mesh.
static void setPatchFields(GeometricField< Type, pointPatchField, pointMesh > &)
Helper: set patchField values from internal values (on.
static void syncUntransformedData(const polyMesh &mesh, List< Type > &pointData, const CombineOp &cop)
Helper: sync data on collocated points only.
void constrainCorners(GeometricField< Type, pointPatchField, pointMesh > &pf) const
Apply patch-patch constraints only.
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
void updateMesh(const mapPolyMesh &)
Update mesh topology using the morph engine.
Mesh representing a set of points created from polyMesh.
Definition pointMesh.H:49
void correctDisplacement(const pointField &p, vectorField &disp) const
Correct motion displacements.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
bool coupled
dynamicFvMesh & mesh
const pointField & points
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299