layeredDisplacement_pointMeshMover.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024-2026 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 
28 #include "PointEdgeWave.H"
29 #include "pointConstraints.H"
30 #include "polyTopoChangeMap.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace pointMeshMovers
38 {
40 
42  (
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 
53 void Foam::pointMeshMovers::layeredDisplacement::walkLayers
54 (
55  const polyPatch& startPatch,
56  scalarField& distance,
57  vectorField& displacement
58 ) const
59 {
60  // Get the start mesh points from the start patch
61  const labelList& startMeshPoints = startPatch.meshPoints();
62 
63  // Set the displacement of the start points
64  const vectorField startDisplacement
65  (
66  pointDisplacement_.boundaryField()[startPatch.index()]
67  .patchInternalField()
68  );
69 
70  // Set the wave info for the start patch
71  List<pointEdgeStructuredWalk> startInfo(startMeshPoints.size());
72  forAll(startMeshPoints, i)
73  {
74  startInfo[i] = pointEdgeStructuredWalk
75  (
76  points0()[startMeshPoints[i]], // Location of start point
77  points0()[startMeshPoints[i]], // Previous location
78  0,
79  startDisplacement[i] // Displacement of the start point
80  );
81  }
82 
83  // Initialise the wave info for all the points
84  List<pointEdgeStructuredWalk> allPointInfo(poly().nPoints());
85  forAll(allPointInfo, pointi)
86  {
87  allPointInfo[pointi] = pointEdgeStructuredWalk
88  (
89  points0()[pointi], // Mesh point location
90  vector::max, // No valid previous location
91  0,
92  Zero // Initial displacement = 0
93  );
94  }
95 
96  // Initialise the wave info for all edges
97  List<pointEdgeStructuredWalk> allEdgeInfo(poly().nEdges());
98  forAll(allEdgeInfo, edgei)
99  {
100  allEdgeInfo[edgei] = pointEdgeStructuredWalk
101  (
102  poly().edges()[edgei].centre(points0()), // Edge centre location
103  vector::max, // No valid previous location
104  0,
105  Zero // Initial displacement = 0
106  );
107  }
108 
109  // Walk the distance and displacement from the startPatch
110  PointEdgeWave<pointEdgeStructuredWalk> walk
111  (
112  poly(),
113  startMeshPoints,
114  startInfo,
115  allPointInfo,
116  allEdgeInfo,
117  poly().globalData().nTotalPoints() // Max number of iterations
118  );
119 
120  // Extract distance and displacement from the wave info
121  forAll(allPointInfo, pointi)
122  {
123  distance[pointi] = allPointInfo[pointi].dist();
124  displacement[pointi] = allPointInfo[pointi].data();
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 (
133  const polyMesh& mesh,
134  const dictionary& dict
135 )
136 :
138  oppositePatchNames_(dict.lookup("oppositePatches")),
139  oppositePatches_
140  (
141  mesh.boundary().findIndex(oppositePatchNames_.first()),
142  mesh.boundary().findIndex(oppositePatchNames_.second())
143  )
144 {}
145 
146 
147 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
148 
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
157 {
158  // The points have moved so before interpolation update the pointMeshMover
159  movePoints(poly().points());
160 
161  // Update the displacement boundary conditions
162  pointDisplacement_.boundaryFieldRef().updateCoeffs();
163 
164  // Walk the layers from patch0 to patch1
165  const polyPatch& patch0 = poly().boundary()[oppositePatches_.first()];
166  scalarField patchDist0(poly().nPoints());
167  vectorField patchDisp0(pointDisplacement_);
168  walkLayers(patch0, patchDist0, patchDisp0);
169 
170  // Walk the layers from patch1 to patch0
171  const polyPatch& patch1 = poly().boundary()[oppositePatches_.second()];
172  scalarField patchDist1(poly().nPoints());
173  vectorField patchDisp1(pointDisplacement_);
174  walkLayers(patch1, patchDist1, patchDisp1);
175 
176  // Calculate the interpolation factor from the distance to the
177  // opposite patches
178  const scalarField w(patchDist0/(patchDist0 + patchDist1 + small));
179 
180  // Linearly interpolate the displacements of the opposite patches
181  pointDisplacement_.primitiveFieldRef() = (1 - w)*patchDisp0 + w*patchDisp1;
182 
183  // Constrain the pointDisplacement field
184  pointConstraints::New(pointDisplacement_.mesh())
185  .constrainDisplacement(pointDisplacement_, false);
186 
187  return points();
188 }
189 
190 
192 {
194  << "Mesh-to-mesh mapping in not implemented for displacement solvers"
195  << nl
196  << " velocity based motion solvers are preferable for cases in which"
197  " the mesh is reset periodically avoiding accumulation of error."
198  << exit(FatalError);
199 }
200 
201 
202 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
static pointConstraints & New(const word &name, const pointMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
static const Form max
Definition: VectorSpace.H:120
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
Abstract base class for pointMesh movers.
const polyMesh & poly() const
Return reference to mesh.
Motion of the mesh specified as a list of pointMeshMovers.
pointField & points0()
Return reference to the reference field.
Abstract base class for displacement pointMesh movers.
pointVectorField pointDisplacement_
Point motion field.
displacement(const polyMesh &, const dictionary &, const word &type)
Construct from mesh and dictionary.
Interpolating motion solver for extruded/layered meshes.
layeredDisplacement(const polyMesh &, const dictionary &)
Construct from polyMesh and dictionary.
virtual tmp< pointField > newPoints()
Return point location obtained from the current motion field.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map (not implemented)
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:71
A class for managing temporary objects.
Definition: tmp.H:55
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
volScalarField scalarField(fieldObject, mesh)
volVectorField vectorField(fieldObject, mesh)
const pointField & points
label nPoints
addToRunTimeSelectionTable(pointMeshMover, externalDisplacement, dictionary)
defineTypeNameAndDebug(externalDisplacement, 0)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
List< label > labelList
A List of labels.
Definition: labelList.H:56
labelList second(const UList< labelPair > &p)
Definition: patchToPatch.C:49
labelList first(const UList< labelPair > &p)
Definition: patchToPatch.C:39
Field< vector > vectorField
Specialisation of Field<T> for vector.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
static const char nl
Definition: Ostream.H:297
faceListList boundary(nPatches)
dictionary dict