solidBody_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) 2016-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  (
41  solidBody,
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::pointMeshMovers::solidBody::updateZonePointIndices()
51 {
52  zone_.regenerate();
53 
54  if (zone_.all())
55  {
56  zonePoints_.clear();
57  return;
58  }
59 
60  boolList pointInZone(poly().nPoints(), false);
61 
62  forAll(zone_.zone(), zoneCelli)
63  {
64  const cell& c = poly().cells()[zone_.zone()[zoneCelli]];
65  forAll(c, cfi)
66  {
67  const face& f = poly().faces()[c[cfi]];
68  forAll(f, fpi)
69  {
70  pointInZone[f[fpi]] = true;
71  }
72  }
73  }
74 
75  syncTools::syncPointList(poly(), pointInZone, orEqOp<bool>(), false);
76 
77  zonePoints_.resize(count(pointInZone, true));
78 
79  label zonePointi = 0;
80  forAll(pointInZone, pointi)
81  {
82  if (pointInZone[pointi])
83  {
84  zonePoints_[zonePointi ++] = pointi;
85  }
86  }
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 (
94  const polyMesh& mesh,
95  const dictionary& dict
96 )
97 :
99  SBMFPtr_(solidBodyMotionFunction::New(dict, mesh.time())),
100  zone_(mesh, dict),
101  zonePoints_(),
102  transform_(SBMFPtr_().transformation())
103 {
104  if (zone_.all())
105  {
106  Info<< "Applying solid body motion to entire mesh" << endl;
107  }
108 
109  updateZonePointIndices();
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
123  transform_ = SBMFPtr_().transformation();
124 
125  if (zone_.all())
126  {
127  return transformPoints(transform_, points0_);
128  }
129  else
130  {
131  tmp<pointField> ttransformedPts(new pointField(poly().points()));
132  pointField& transformedPts = ttransformedPts.ref();
133 
134  UIndirectList<point>(transformedPts, zonePoints_) = transformPoints
135  (
136  transform_,
137  pointField(points0_, zonePoints_)
138  );
139 
140  return ttransformedPts;
141  }
142 }
143 
144 
146 {
147  zone_.topoChange(map);
148  updateZonePointIndices();
149 
150  // pointMesh already updates pointFields
151 
152  const pointField& points = poly().points();
153 
154  pointField newPoints0(points);
155 
156  const label nZonePoints =
157  zone_.all() ? poly().nPoints() : zonePoints_.size();
158 
159  for (label zonePointi = 0; zonePointi < nZonePoints; ++ zonePointi)
160  {
161  const label pointi =
162  zone_.all() ? zonePointi : zonePoints_[zonePointi];
163 
164  const label oldPointi = map.pointMap()[pointi];
165 
166  if (oldPointi < 0)
167  {
169  << "Cannot determine co-ordinates of introduced points."
170  << " New point " << pointi << " at " << points[pointi]
171  << exit(FatalError);
172  }
173 
174  if (map.reversePointMap()[oldPointi] == pointi)
175  {
176  newPoints0[pointi] = points0_[oldPointi];
177  }
178  else
179  {
180  newPoints0[pointi] =
181  transform_.invTransformPoint(points[pointi]);
182  }
183  }
184 
185  twoDCorrectPoints(newPoints0);
186 
187  // Move into base class storage and mark as to-be-written
188  points0_.transfer(newPoints0);
189  points0_.writeOpt() = IOobject::AUTO_WRITE;
190  points0_.instance() = poly().time().name();
191 }
192 
193 
195 (
196  const polyDistributionMap& map
197 )
198 {
200 
201  zone_.distribute(map);
202  updateZonePointIndices();
203 }
204 
205 
207 {
209 
210  zone_.mapMesh(map);
211  updateZonePointIndices();
212 
213  pointField& points0 = this->points0();
214 
215  const label nZonePoints =
216  zone_.all() ? poly().nPoints() : zonePoints_.size();
217 
218  for (label zonePointi = 0; zonePointi < nZonePoints; ++ zonePointi)
219  {
220  const label pointi =
221  zone_.all() ? zonePointi : zonePoints_[zonePointi];
222 
223  points0[pointi] = transform_.invTransformPoint(points0[pointi]);
224  }
225 
226  twoDCorrectPoints(points0);
227 
228  points0_.writeOpt() = IOobject::AUTO_WRITE;
229  points0_.instance() = poly().time().name();
230 }
231 
232 
233 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
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 cellZone & zone() const
Return const access to the cell set.
bool all() const
Return true if the set comprises all the cells.
bool regenerate()
Regenerate the cellZone if the regenerate switch is set true.
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 specified by a run-time selectable motion function.
solidBody(const polyMesh &, const dictionary &)
Construct from mesh and dictionary.
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.
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
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1308
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
Base class for defining solid-body motions.
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 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.
const dimensionSet time
addToRunTimeSelectionTable(pointMeshMover, externalDisplacement, dictionary)
defineTypeNameAndDebug(externalDisplacement, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
error FatalError
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
labelList f(nPoints)
dictionary dict