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"
33#include "globalMeshData.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 const polyBoundaryMesh& bm = mesh.boundaryMesh();
60
61
62 // first count the total number of patch-patch points
63
64 label nPatchPatchPoints = 0;
65
66 forAll(pbm, patchi)
67 {
68 if (!isA<emptyPointPatch>(pbm[patchi]) && !pbm[patchi].coupled())
69 {
70 const labelList& bp = bm[patchi].boundaryPoints();
71
72 nPatchPatchPoints += bp.size();
73
74 if (debug)
75 {
76 Pout<< indent << "On patch:" << pbm[patchi].name()
77 << " nBoundaryPoints:" << bp.size() << endl;
78 }
79 }
80 }
81
82 if (debug)
83 {
84 Pout<< indent << "Found nPatchPatchPoints:" << nPatchPatchPoints
85 << endl;
86 }
87
88
89 // Go through all patches and mark up the external edge points
90 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91
92 // From meshpoint to index in patchPatchPointConstraints_.
93 Map<label> patchPatchPointSet(2*nPatchPatchPoints);
94
95 // Constraints (initialised to unconstrained)
96 patchPatchPointConstraints_.setSize(nPatchPatchPoints);
97 patchPatchPointConstraints_ = pointConstraint();
98
99 // From constraint index to mesh point
100 labelList patchPatchPoints(nPatchPatchPoints);
101
102 label pppi = 0;
103
104 forAll(pbm, patchi)
105 {
106 if (!isA<emptyPointPatch>(pbm[patchi]) && !pbm[patchi].coupled())
107 {
108 const labelList& bp = bm[patchi].boundaryPoints();
109 const labelList& meshPoints = pbm[patchi].meshPoints();
110
111 forAll(bp, pointi)
112 {
113 const label ppp = meshPoints[bp[pointi]];
114
115 const auto iter = patchPatchPointSet.cfind(ppp);
116
117 label constraintI = -1;
118
119 if (iter.found())
120 {
121 constraintI = iter.val();
122 }
123 else
124 {
125 patchPatchPointSet.insert(ppp, pppi);
126 patchPatchPoints[pppi] = ppp;
127 constraintI = pppi++;
128 }
129
130 // Apply to patch constraints
131 pbm[patchi].applyConstraint
132 (
133 bp[pointi],
134 patchPatchPointConstraints_[constraintI]
135 );
136 }
137 }
138 }
139
140 if (debug)
141 {
142 Pout<< indent << "Have (local) constrained points:"
143 << nPatchPatchPoints << endl;
144 }
145
146
147 // Extend set with constraints across coupled points
148 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150 {
151 const globalMeshData& gd = mesh.globalData();
152 const labelListList& globalPointSlaves = gd.globalPointSlaves();
153 const mapDistribute& globalPointSlavesMap = gd.globalPointSlavesMap();
154 const Map<label>& cpPointMap = gd.coupledPatch().meshPointMap();
155 const labelList& cpMeshPoints = gd.coupledPatch().meshPoints();
156
157 // Constraints on coupled points
158 List<pointConstraint> constraints
159 (
160 globalPointSlavesMap.constructSize()
161 );
162
163 // Copy from patchPatch constraints into coupledConstraints.
164 forAll(pbm, patchi)
165 {
166 if (!isA<emptyPointPatch>(pbm[patchi]) && !pbm[patchi].coupled())
167 {
168 const labelList& bp = bm[patchi].boundaryPoints();
169 const labelList& meshPoints = pbm[patchi].meshPoints();
170
171 forAll(bp, pointi)
172 {
173 const label ppp = meshPoints[bp[pointi]];
174
175 const auto iter = cpPointMap.cfind(ppp);
176
177 if (iter.found())
178 {
179 // Can just copy (instead of apply) constraint
180 // will already be consistent across multiple patches.
181 constraints[iter.val()] = patchPatchPointConstraints_
182 [
183 patchPatchPointSet[ppp]
184 ];
185 }
186 }
187 }
188 }
189
190 // Exchange data
191 globalPointSlavesMap.distribute(constraints);
192
193 // Combine master with slave constraints
194 forAll(globalPointSlaves, pointi)
195 {
196 const labelList& slaves = globalPointSlaves[pointi];
197
198 // Combine master constraint with slave constraints
199 forAll(slaves, i)
200 {
201 constraints[pointi].combine(constraints[slaves[i]]);
202 }
203 // Duplicate master constraint into slave slots
204 forAll(slaves, i)
205 {
206 constraints[slaves[i]] = constraints[pointi];
207 }
208 }
209
210 // Send back
211 globalPointSlavesMap.reverseDistribute
212 (
213 cpMeshPoints.size(),
214 constraints
215 );
216
217 // Add back into patchPatch constraints
218 forAll(constraints, coupledPointi)
219 {
220 if (constraints[coupledPointi].first() != 0)
221 {
222 label meshPointi = cpMeshPoints[coupledPointi];
223
224 const auto iter = patchPatchPointSet.cfind(meshPointi);
225
226 label constraintI = -1;
227
228 if (iter.found())
229 {
230 //Pout<< indent << "on meshpoint:" << meshPointi
231 // << " coupled:" << coupledPointi
232 // << " at:" << mesh.points()[meshPointi]
233 // << " have possibly extended constraint:"
234 // << constraints[coupledPointi]
235 // << endl;
236
237 constraintI = iter.val();
238 }
239 else
240 {
241 //Pout<< indent << "on meshpoint:" << meshPointi
242 // << " coupled:" << coupledPointi
243 // << " at:" << mesh.points()[meshPointi]
244 // << " have new constraint:"
245 // << constraints[coupledPointi]
246 // << endl;
247
248 // Allocate new constraint
249 if (patchPatchPoints.size() <= pppi)
250 {
251 // Check if not enough space. This
252 // can occasionally happen if -coupled points connect
253 // to the inside of a patch -these coupled points also
254 // carry a constraint
255 patchPatchPoints.setSize(pppi+100);
256 patchPatchPointConstraints_.setSize
257 (
258 pppi+100,
259 pointConstraint()
260 );
261 }
262 patchPatchPointSet.insert(meshPointi, pppi);
263 patchPatchPoints[pppi] = meshPointi;
264 constraintI = pppi++;
265 }
266
267 // Combine (new or existing) constraint with one
268 // on coupled.
269 patchPatchPointConstraints_[constraintI].combine
270 (
271 constraints[coupledPointi]
272 );
273 }
274 }
275 }
276
277
278
279 nPatchPatchPoints = pppi;
280 patchPatchPoints.setSize(nPatchPatchPoints);
281 patchPatchPointConstraints_.setSize(nPatchPatchPoints);
282
283
284 if (debug)
285 {
286 Pout<< indent << "Have (global) constrained points:"
287 << nPatchPatchPoints << endl;
288 }
289
290
291 // Copy out all non-trivial constraints
292 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293
294 patchPatchPointConstraintPoints_.setSize(nPatchPatchPoints);
295 patchPatchPointConstraintTensors_.setSize(nPatchPatchPoints);
296
297 label nConstraints = 0;
298
299 forAll(patchPatchPointConstraints_, i)
300 {
301 // Note: check for more than zero constraints. (could check for
302 // more than one constraint but what about coupled points that
303 // inherit the constraintness)
304 if (patchPatchPointConstraints_[i].first() != 0)
305 {
306 patchPatchPointConstraintPoints_[nConstraints] =
307 patchPatchPoints[i];
308
309 patchPatchPointConstraintTensors_[nConstraints] =
310 patchPatchPointConstraints_[i].constraintTransformation();
311
312 nConstraints++;
313 }
314 }
315
316 if (debug)
317 {
318 Pout<< indent << "Have non-trivial constrained points:"
319 << nConstraints << endl;
320 }
321
322 patchPatchPointConstraints_.setSize(nConstraints);
323 patchPatchPointConstraintPoints_.setSize(nConstraints);
324 patchPatchPointConstraintTensors_.setSize(nConstraints);
325
326
327 if (debug)
328 {
330 << "pointConstraints::makePatchPatchAddressing() : "
331 << "finished constructing boundary addressing"
332 << endl;
333 }
334}
335
336
337// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
338
340:
342{
343 if (debug)
344 {
345 Pout<< "pointConstraints::pointConstraints(const pointMesh&): "
346 << "Constructing from pointMesh " << pm.name()
347 << endl;
348 }
349
350 makePatchPatchAddressing();
351}
352
353
354// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
355
357{
358 if (debug)
359 {
360 Pout<< "pointConstraints::~pointConstraints()" << endl;
361 }
362}
363
364
365// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
366
368{
369 makePatchPatchAddressing();
370}
371
372
374{
375 return true;
376}
377
378
380(
382 const bool overrideFixedValue
383) const
384{
385 // Override constrained pointPatchField types with the constraint value.
386 // This relies on only constrained pointPatchField implementing the evaluate
387 // function
389
390 // Sync any dangling points
391 syncUntransformedData
392 (
393 pf.mesh()(),
396 );
397
398 // Apply multiple constraints on edge/corner points
399 constrainCorners(pf);
400
401 // Apply any 2D motion constraints (or should they go before
402 // corner constraints?)
403 twoDPointCorrector::New(mesh()()).correctDisplacement
404 (
405 mesh()().points(),
407 );
408
409 if (overrideFixedValue)
410 {
411 setPatchFields(pf);
412 }
413}
414
415
416template<>
418(
419 GeometricField<scalar, pointPatchField, pointMesh>& pf
420) const
421{}
422
423
424template<>
426(
427 GeometricField<label, pointPatchField, pointMesh>& pf
428) const
429{}
430
431
432// ************************************************************************* //
const Mesh & mesh() const
Return mesh.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field.
void correctBoundaryConditions()
Correct boundary field.
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.C:40
void setSize(const label n)
Alias for resize()
Definition: List.H:218
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:91
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
void updateMesh()
Update for new mesh topology.
Application of (multi-)patch point constraints.
bool movePoints()
Correct weighting factors for moving mesh.
~pointConstraints()
Destructor.
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:55
const globalMeshData & globalData() const
Return parallel info.
Definition: pointMesh.H:120
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
dynamicFvMesh & mesh
const pointField & points
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
void Foam::pointConstraints::constrainCorners< Foam::label >(GeometricField< label, pointPatchField, pointMesh > &pf) const
void Foam::pointConstraints::constrainCorners< Foam::scalar >(GeometricField< scalar, pointPatchField, pointMesh > &pf) const
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333