Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace pointSmoothers
39{
42 (
46 );
47}
48}
49
50
51// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52
55(
56 const polyMesh& mesh,
57 const dictionary& dict
58)
60 pointSmoother(mesh, dict)
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
const T1 & first() const noexcept
Access the first element.
Definition Tuple2.H:132
T & first()
Access first element of the list, position [0].
Definition UList.H:957
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Accumulates point constraints through successive applications of the applyConstraint function.
Abstract base class for point smoothing methods. Handles parallel communication via reset and average...
void reset(const labelList &facesToMove, Field< weightType > &weights, vectorField &pointDisplacement, const bool resetInternalFaces=true) const
Reset the relevant weights and displacements to zero.
bitSet pointsToMove(const labelList &facesToMove, const bool moveInternalFaces) const
Get list of the points to be moved.
void average(const labelList &facesToMove, Field< weightType > &weights, vectorField &pointDisplacement) const
Average the displacements using the weights provided.
const polyMesh & mesh() const noexcept
Access the mesh.
laplacianConstraintPointSmoother(const polyMesh &mesh, const dictionary &dict)
Construct from a dictionary and a polyMesh.
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.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const labelListList & pointEdges() const
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
dynamicFvMesh & mesh
label nPoints
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
Field< vector > vectorField
Specialisation of Field<T> for vector.
Field< label > labelField
Specialisation of Field<T> for label.
Definition labelField.H:48
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
vectorField pointField
pointField is a vectorField.
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299