laplacianConstraintPointSmoother.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) 2024 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 
30 #include "meshPointPatch.H"
31 #include "processorPointPatch.H"
32 #include "pointConstraint.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace pointSmoothers
39 {
40  defineTypeNameAndDebug(laplacianConstraintPointSmoother, 0);
42  (
43  pointSmoother,
44  laplacianConstraintPointSmoother,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
55 (
56  const polyMesh& mesh,
57  const dictionary& dict
58 )
59 :
61 {}
62 
63 
64 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
65 
67 (
68  const labelList& facesToMove,
69  const pointField& oldPoints,
70  const pointField& currentPoints,
71  const pointField& faceCentres,
72  const vectorField& faceAreas,
73  const pointField& cellCentres,
74  const scalarField& cellVolumes,
75  vectorField& pointDisplacement
76 ) const
77 {
78  // Get pointMesh so we can get at the constraints
79  const auto& pMesh = pointMesh::New(mesh());
80 
81  // Number of points used in each average
82  labelField counts(mesh().nPoints(), 0);
83 
84  // Reset the displacements which are about to be calculated
85  reset(facesToMove, counts, pointDisplacement);
86 
87  // Get affected points
88  const bitSet isMovingPoint(pointsToMove(facesToMove, true));
89 
90 
91  // Set constraints:
92  // - internal points : 0
93  // - normal boundary points : 1
94  // - meshPointPatch : 1 (surface)
95  // 2 (feat-edge)
96  // 3 (feat-point)
97  labelList nConstraints(mesh().nPoints(), Zero);
98 
99  for (const auto& pp : pMesh.boundary())
100  {
101  const auto& mp = pp.meshPoints();
102  const auto* mppPtr = isA<meshPointPatch>(pp);
103  if (mppPtr)
104  {
105  const auto& pc = mppPtr->constraints();
106  forAll(mp, i)
107  {
108  nConstraints[mp[i]] = pc[i].first();
109  }
110  }
111  else //if (!isA<processorPointPatch>(pp)) // what about cyclic? AMI?
112  {
113  forAll(mp, i)
114  {
115  // Indirectly detect any constraint
116  pointConstraint pc;
117  pp.applyConstraint(i, pc);
118  nConstraints[mp[i]] = pc.first();
119  }
120  }
121  }
122 
123 
124  // Average from equally constrained points
125 
126  const auto& edges = mesh().edges();
127  const auto& pointEdges = mesh().pointEdges();
128  forAll(pointEdges, pointi)
129  {
130  if (isMovingPoint[pointi])
131  {
132  const auto& pEdges = pointEdges[pointi];
133  for (const label edgei : pEdges)
134  {
135  const label otherPointi = edges[edgei].otherVertex(pointi);
136  if (nConstraints[otherPointi] >= nConstraints[pointi])
137  {
138  pointDisplacement[pointi] +=
139  currentPoints[otherPointi]
140  - oldPoints[pointi];
141 
142  ++ counts[pointi];
143  }
144  }
145  }
146  }
147 
148  // Average
149  average(facesToMove, counts, pointDisplacement);
150 
151 
152  // Make sure to set any unconnected points (or boundary feature points)
153  // since otherwise they never see the effect of the boundary conditions
154  forAll(counts, pointi)
155  {
156  if (isMovingPoint[pointi] && !counts[pointi])
157  {
158  pointDisplacement[pointi] = currentPoints[pointi]-oldPoints[pointi];
159  }
160  }
161 }
162 
163 
164 // ************************************************************************* //
dictionary dict
virtual void calculate(const labelList &facesToMove, const pointField &oldPoints, const pointField &currentPoints, const pointField &faceCentres, const vectorField &faceAreas, const pointField &cellCentres, const scalarField &cellVolumes, vectorField &pointDisplacement) const
Calculate the point displacement.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Abstract base class for point smoothing methods. Handles parallel communication via reset and average...
Definition: pointSmoother.H:50
const labelListList & pointEdges() const
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
bitSet pointsToMove(const labelList &facesToMove, const bool moveInternalFaces) const
Get list of the points to be moved.
Definition: pointSmoother.C:62
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
dynamicFvMesh & mesh
const polyMesh & mesh() const noexcept
Access the mesh.
addToRunTimeSelectionTable(pointSmoother, equipotentialPointSmoother, dictionary)
label nPoints
laplacianConstraintPointSmoother(const polyMesh &mesh, const dictionary &dict)
Construct from a dictionary and a polyMesh.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
void reset(const labelList &facesToMove, Field< weightType > &weights, vectorField &pointDisplacement, const bool resetInternalFaces=true) const
Reset the relevant weights and displacements to zero.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
void average(const labelList &facesToMove, Field< weightType > &weights, vectorField &pointDisplacement) const
Average the displacements using the weights provided.
const dimensionedScalar mp
Proton mass.
defineTypeNameAndDebug(equipotentialPointSmoother, 0)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127