solidBodyMotionSolver.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-2024 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 
26 #include "solidBodyMotionSolver.H"
27 #include "polyCellSet.H"
28 #include "transformField.H"
29 #include "syncTools.H"
30 #include "polyTopoChangeMap.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
39  (
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::solidBodyMotionSolver::updateSetPointIndices()
50 {
52  {
53  setPointIndices_.clear();
54  return;
55  }
56 
57  boolList pointInSet(mesh().nPoints(), false);
58 
59  forAll(set_.cells(), setCelli)
60  {
61  const cell& c = mesh().cells()[set_.cells()[setCelli]];
62  forAll(c, cfi)
63  {
64  const face& f = mesh().faces()[c[cfi]];
65  forAll(f, fpi)
66  {
67  pointInSet[f[fpi]] = true;
68  }
69  }
70  }
71 
72  syncTools::syncPointList(mesh(), pointInSet, orEqOp<bool>(), false);
73 
74  setPointIndices_.resize(count(pointInSet, true));
75 
76  label setPointi = 0;
77  forAll(pointInSet, pointi)
78  {
79  if (pointInSet[pointi])
80  {
81  setPointIndices_[setPointi ++] = pointi;
82  }
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const word& name,
92  const polyMesh& mesh,
93  const dictionary& dict
94 )
95 :
96  points0MotionSolver(name, mesh, dict, typeName),
97  SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())),
98  set_(mesh, dict),
99  setPointIndices_(),
100  transform_(SBMFPtr_().transformation())
101 {
103  {
104  Info<< "Applying solid body motion to entire mesh" << endl;
105  }
106 
107  updateSetPointIndices();
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
112 
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 {
121  transform_ = SBMFPtr_().transformation();
122 
123  if (set_.selectionType() == polyCellSet::selectionTypes::all)
124  {
125  return transformPoints(transform_, points0_);
126  }
127  else
128  {
129  tmp<pointField> ttransformedPts(new pointField(mesh().points()));
130  pointField& transformedPts = ttransformedPts.ref();
131 
132  UIndirectList<point>(transformedPts, setPointIndices_) = transformPoints
133  (
134  transform_,
135  pointField(points0_, setPointIndices_)
136  );
137 
138  return ttransformedPts;
139  }
140 }
141 
142 
144 {
145  set_.topoChange(map);
146  updateSetPointIndices();
147 
148  boolList pointInSet
149  (
150  mesh().nPoints(),
151  set_.selectionType() == polyCellSet::selectionTypes::all
152  );
153  UIndirectList<bool>(pointInSet, setPointIndices_) = true;
154 
155  // pointMesh already updates pointFields
156 
157  // Get the new points either from the map or the mesh
158  const pointField& points = mesh().points();
159 
160  pointField newPoints0(map.pointMap().size());
161 
162  forAll(newPoints0, pointi)
163  {
164  const label oldPointi = map.pointMap()[pointi];
165 
166  if (oldPointi < 0)
167  {
169  << "Cannot determine co-ordinates of introduced vertices."
170  << " New vertex " << pointi << " at co-ordinate "
171  << points[pointi] << exit(FatalError);
172  }
173 
174  if (map.reversePointMap()[oldPointi] == pointi)
175  {
176  newPoints0[pointi] = points0_[oldPointi];
177  }
178  else
179  {
180  newPoints0[pointi] =
181  pointInSet[pointi]
182  ? transform_.invTransformPoint(points[pointi])
183  : points[pointi];
184  }
185  }
186 
187  twoDCorrectPoints(newPoints0);
188 
189  // Move into base class storage and mark as to-be-written
190  points0_.transfer(newPoints0);
191  points0_.writeOpt() = IOobject::AUTO_WRITE;
192  points0_.instance() = mesh().time().name();
193 }
194 
195 
197 {
199 
200  set_.distribute(map);
201  updateSetPointIndices();
202 }
203 
204 
206 {
208 
209  set_.mapMesh(map);
210  updateSetPointIndices();
211 }
212 
213 
214 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
A List with indirect addressing.
Definition: UIndirectList.H:60
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Virtual base class for mesh motion solver.
Definition: motionSolver.H:57
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:137
Virtual base class for displacement motion solvers.
virtual void distribute(const polyDistributionMap &)
Update corresponding to the given distribution map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
labelUList cells() const
Return const access to the cell set.
Definition: polyCellSetI.H:43
const selectionTypes & selectionType() const
Return const access to the cell selection type.
Definition: polyCellSetI.H:31
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:80
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1326
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.
Solid-body motion of the mesh specified by a run-time selectable motion function.
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
solidBodyMotionSolver(const word &name, 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 void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
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:181
A class for handling words, derived from string.
Definition: word.H:62
#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.
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
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
defineTypeNameAndDebug(combustionModel, 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
error FatalError
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
labelList f(nPoints)
dictionary dict
Spatial transformation functions for primitive fields.