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-2022 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const word& name,
52  const polyMesh& mesh,
53  const dictionary& dict
54 )
55 :
56  points0MotionSolver(name, mesh, dict, typeName),
57  SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())),
58  pointIDs_(),
59  moveAllCells_(false),
60  transform_(SBMFPtr_().transformation())
61 {
62  const labelList cellIDs(polyCellSet(mesh, dict).cells());
63 
64  moveAllCells_ =
65  returnReduce(cellIDs.size() == mesh.nCells(), andOp<bool>());
66 
67  if (moveAllCells_)
68  {
69  Info<< "Applying solid body motion to entire mesh" << endl;
70  }
71  else
72  {
73  // collect point IDs of points in cell zone
74 
75  boolList movePts(mesh.nPoints(), false);
76 
77  forAll(cellIDs, i)
78  {
79  const cell& c = mesh.cells()[cellIDs[i]];
80  forAll(c, j)
81  {
82  const face& f = mesh.faces()[c[j]];
83  forAll(f, k)
84  {
85  movePts[f[k]] = true;
86  }
87  }
88  }
89 
90  syncTools::syncPointList(mesh, movePts, orEqOp<bool>(), false);
91 
93  forAll(movePts, i)
94  {
95  if (movePts[i])
96  {
97  ptIDs.append(i);
98  }
99  }
100 
101  pointIDs_.transfer(ptIDs);
102  }
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 {
116  transform_ = SBMFPtr_().transformation();
117 
118  if (moveAllCells_)
119  {
120  return transformPoints(transform_, points0_);
121  }
122  else
123  {
124  tmp<pointField> ttransformedPts(new pointField(mesh().points()));
125  pointField& transformedPts = ttransformedPts.ref();
126 
127  UIndirectList<point>(transformedPts, pointIDs_) = transformPoints
128  (
129  transform_,
130  pointField(points0_, pointIDs_)
131  );
132 
133  return ttransformedPts;
134  }
135 }
136 
137 
139 {
140  // pointMesh already updates pointFields
141 
142  // Get the new points either from the map or the mesh
143  const pointField& points =
144  (
145  map.hasMotionPoints()
146  ? map.preMotionPoints()
147  : mesh().points()
148  );
149 
150  pointField newPoints0(map.pointMap().size());
151 
152  forAll(newPoints0, pointi)
153  {
154  label oldPointi = map.pointMap()[pointi];
155 
156  if (oldPointi >= 0)
157  {
158  const label masterPointi = map.reversePointMap()[oldPointi];
159 
160  if (masterPointi == pointi)
161  {
162  newPoints0[pointi] = points0_[oldPointi];
163  }
164  else
165  {
166  newPoints0[pointi] =
167  transform_.invTransformPoint(points[pointi]);
168  }
169  }
170  else
171  {
173  << "Cannot determine co-ordinates of introduced vertices."
174  << " New vertex " << pointi << " at co-ordinate "
175  << points[pointi] << exit(FatalError);
176  }
177  }
178 
179  twoDCorrectPoints(newPoints0);
180 
181  points0_.transfer(newPoints0);
182 }
183 
184 
185 // ************************************************************************* //
label k
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A List with indirect addressing.
Definition: UIndirectList.H:60
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:60
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
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.
General run-time selected cell set selection class for polyMesh.
Definition: polyCellSet.H:82
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1374
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const pointField & preMotionPoints() const
Pre-motion point positions.
const labelList & reversePointMap() const
Reverse point map.
const labelList & pointMap() const
Old point map.
bool hasMotionPoints() const
Has valid preMotionPoints?
label nCells() const
label nPoints() const
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.
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:306
const pointField & points
const cellShapeList & cells
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
labelList f(nPoints)
dictionary dict
Spatial transformation functions for primitive fields.