multiSolidBody_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) 2011-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 
27 #include "syncTools.H"
28 #include "polyTopoChangeMap.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace pointMeshMovers
36 {
39  (
43  );
44 }
45 }
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::pointMeshMovers::multiSolidBody::updateZonePointIndices()
50 {
51  forAll(zoneIndices_, zonei)
52  {
53  const cellZone& zoneCells = poly().cellZones()[zoneIndices_[zonei]];
54 
55  boolList pointInZone(poly().nPoints(), false);
56 
57  forAll(zoneCells, zoneCelli)
58  {
59  const cell& c = poly().cells()[zoneCells[zoneCelli]];
60  forAll(c, cfi)
61  {
62  const face& f = poly().faces()[c[cfi]];
63  forAll(f, fpi)
64  {
65  pointInZone[f[fpi]] = true;
66  }
67  }
68  }
69 
70  syncTools::syncPointList(poly(), pointInZone, orEqOp<bool>(), false);
71 
72  DynamicList<label> zonePoints(poly().nPoints());
73  forAll(pointInZone, celli)
74  {
75  if (pointInZone[celli])
76  {
77  zonePoints.append(celli);
78  }
79  }
80 
81  zonePoints_[zonei].transfer(zonePoints);
82  }
83 
84  // Check that points are not in multiple zones
85  labelList pointZone(poly().nPoints(), -1);
86  forAll(zoneIndices_, zonei)
87  {
88  forAll(zonePoints_[zonei], zonePointi)
89  {
90  const label pointi = zonePoints_[zonei][zonePointi];
91  pointZone[pointi] =
92  pointZone[pointi] == -1 || pointZone[pointi] == zonei
93  ? zonei
94  : -2;
95  }
96  }
98  (
99  poly(),
100  pointZone,
101  [](label& x, const label& y) { x = x == -1 || x == y ? y : -2; },
102  label(-1)
103  );
104  const label errorPointi = findIndex(pointZone, -2);
105  if (errorPointi != -1)
106  {
108  << "Point " << errorPointi << " at " << poly().points()[errorPointi]
109  << " is in multiple moving zones. This is not allowed."
110  << exit(FatalError);
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
118 (
119  const polyMesh& mesh,
120  const dictionary& dict
121 )
122 :
124 {
125  zoneIndices_.setSize(dict.size());
126  SBMFs_.setSize(dict.size());
127  label zonei = 0;
129  {
130  if (!iter().isDict()) continue;
131 
132  zoneIndices_[zonei] = mesh.cellZones().findIndex(iter().keyword());
133 
134  if (zoneIndices_[zonei] == -1)
135  {
137  << "Cannot find cellZone named " << iter().keyword()
138  << ". Valid zones are " << mesh.cellZones().toc()
139  << exit(FatalIOError);
140  }
141 
142  const dictionary& subDict = iter().dict();
143 
144  SBMFs_.set
145  (
146  zonei,
148  );
149 
150  zonei ++;
151  }
152  zoneIndices_.setSize(zonei);
153  SBMFs_.setSize(zonei);
154 
155  zonePoints_.setSize(zonei);
156  updateZonePointIndices();
157 
158  transforms_.setSize(zonei);
159  forAll(zoneIndices_, zonei)
160  {
161  transforms_[zonei] = SBMFs_[zonei].transformation();
162  }
163 
164  forAll(zoneIndices_, zonei)
165  {
166  Info<< "Applying solid-body motion " << SBMFs_[zonei].type()
167  << " to cellZone " << mesh.cellZones()[zoneIndices_[zonei]].name()
168  << endl;
169  }
170 }
171 
172 
173 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
174 
176 {}
177 
178 
179 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
180 
182 {
183  tmp<pointField> ttransformedPts(new pointField(poly().points()));
184  pointField& transformedPts = ttransformedPts.ref();
185 
186  forAll(zoneIndices_, zonei)
187  {
188  transforms_[zonei] = SBMFs_[zonei].transformation();
189 
190  UIndirectList<point>(transformedPts, zonePoints_[zonei]) =
192  (
193  transforms_[zonei],
194  pointField(points0_, zonePoints_[zonei])
195  );
196  }
197 
198  return ttransformedPts;
199 }
200 
201 
203 (
204  const polyTopoChangeMap& map
205 )
206 {
207  updateZonePointIndices();
208 
209  // pointMesh already updates registered pointFields
210 
211  const pointField& points = poly().points();
212 
213  pointField newPoints0(points);
214 
215  forAll(zoneIndices_, zonei)
216  {
217  forAll(zonePoints_[zonei], zonePointi)
218  {
219  const label pointi = zonePoints_[zonei][zonePointi];
220 
221  const label oldPointi = map.pointMap()[pointi];
222 
223  if (oldPointi < 0)
224  {
226  << "Cannot determine co-ordinates of introduced points."
227  << " New point " << pointi << " at " << points[pointi]
228  << exit(FatalError);
229  }
230 
231  if (map.reversePointMap()[oldPointi] == pointi)
232  {
233  newPoints0[pointi] = points0_[oldPointi];
234  }
235  else
236  {
237  newPoints0[pointi] =
238  transforms_[zonei].invTransformPoint(points[pointi]);
239  }
240  }
241  }
242 
243  twoDCorrectPoints(newPoints0);
244 
245  // Move into base class storage and mark as to-be-written
246  points0_.transfer(newPoints0);
247  points0_.writeOpt() = IOobject::AUTO_WRITE;
248  points0_.instance() = poly().time().name();
249 }
250 
251 
253 (
254  const polyDistributionMap& map
255 )
256 {
258 
259  updateZonePointIndices();
260 }
261 
262 
264 {
266 
267  updateZonePointIndices();
268 
269  pointField& points0 = this->points0();
270 
271  forAll(zoneIndices_, zonei)
272  {
273  forAll(zonePoints_[zonei], zonePointi)
274  {
275  const label pointi = zonePoints_[zonei][zonePointi];
276 
277  points0[pointi] =
278  transforms_[zonei].invTransformPoint(points0[pointi]);
279  }
280  }
281 
282  twoDCorrectPoints(points0);
283 
284  points0_.writeOpt() = IOobject::AUTO_WRITE;
285  points0_.instance() = poly().time().name();
286 }
287 
288 
289 // ************************************************************************* //
scalar y
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
wordList toc() const
Return the table of contents.
const word & name() const
Return name.
Definition: IOobject.H:307
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void setSize(const label)
Reset size of List.
Definition: List.C:281
label findIndex(const word &key) const
Return the index of the given the key or -1 if not found.
A List with indirect addressing.
Definition: UIndirectList.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
Abstract base class for pointMesh movers.
const polyMesh & poly() const
Return reference to mesh.
virtual void distribute(const polyDistributionMap &)
Update corresponding to the given distribution map.
virtual void mapMesh(const polyMeshMap &)=0
Update from another mesh using the given map.
Solid-body motion of the mesh parts specified by a run-time selectable motion functions.
virtual void topoChange(const polyTopoChangeMap &)
Update local data for topology changes.
virtual void distribute(const polyDistributionMap &)
Update corresponding to the given distribution map.
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.
multiSolidBody(const polyMesh &, const dictionary &)
Construct from mesh and dictionary.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:438
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1308
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1295
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reversePointMap() const
Reverse point map.
const labelList & pointMap() const
Old point map.
const cellList & cells() const
static autoPtr< solidBodyMotionFunction > New(const dictionary &SBMFCoeffs, const Time &runTime, const word &name="solidBodyMotionFunction")
Select constructed from the SBMFCoeffs dictionary and Time.
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronise values on all mesh points.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
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 FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
label nPoints
const dimensionedScalar c
Speed of light in a vacuum.
addToRunTimeSelectionTable(pointMeshMover, externalDisplacement, dictionary)
defineTypeNameAndDebug(externalDisplacement, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< label > labelList
A List of labels.
Definition: labelList.H:56
void transformPoints(vectorField &, const spatialTransform &, const vectorField &)
Transform given vectorField of coordinates with the given spatialTransform.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
IOerror FatalIOError
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
labelList f(nPoints)
dictionary dict