solidBodyMotionSolver.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "solidBodyMotionSolver.H"
31 #include "transformField.H"
32 #include "cellZoneMesh.H"
33 #include "cellSet.H"
34 #include "boolList.H"
35 #include "syncTools.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(solidBodyMotionSolver, 0);
43  (
44  motionSolver,
45  solidBodyMotionSolver,
46  dictionary
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
53 Foam::solidBodyMotionSolver::solidBodyMotionSolver
54 (
55  const polyMesh& mesh,
56  const IOdictionary& dict
57 )
58 :
59  points0MotionSolver(mesh, dict, typeName),
60  SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())),
61  pointIDs_(),
62  moveAllCells_(false)
63 {
64  word cellZoneName =
65  coeffDict().getOrDefault<word>("cellZone", "none");
66 
67  word cellSetName =
68  coeffDict().getOrDefault<word>("cellSet", "none");
69 
70  if ((cellZoneName != "none") && (cellSetName != "none"))
71  {
72  FatalIOErrorInFunction(coeffDict())
73  << "Either cellZone OR cellSet can be supplied, but not both. "
74  << "If neither is supplied, all cells will be included"
75  << exit(FatalIOError);
76  }
77 
78  labelList cellIDs;
79  if (cellZoneName != "none")
80  {
81  Info<< "Applying solid body motion to cellZone " << cellZoneName
82  << endl;
83 
84  label zoneID = mesh.cellZones().findZoneID(cellZoneName);
85 
86  if (zoneID == -1)
87  {
89  << "Unable to find cellZone " << cellZoneName
90  << ". Valid cellZones are:"
91  << mesh.cellZones().names()
92  << exit(FatalError);
93  }
94 
95  cellIDs = mesh.cellZones()[zoneID];
96  }
97 
98  if (cellSetName != "none")
99  {
100  Info<< "Applying solid body motion to cellSet " << cellSetName
101  << endl;
102 
103  cellSet set(mesh, cellSetName);
104 
105  cellIDs = set.toc();
106  }
107 
108  label nCells = returnReduce(cellIDs.size(), sumOp<label>());
109  moveAllCells_ = nCells == 0;
110 
111  if (moveAllCells_)
112  {
113  Info<< "Applying solid body motion to entire mesh" << endl;
114  }
115  else
116  {
117  // collect point IDs of points in cell zone
118 
119  boolList movePts(mesh.nPoints(), false);
120 
121  forAll(cellIDs, i)
122  {
123  label celli = cellIDs[i];
124  const cell& c = mesh.cells()[celli];
125  forAll(c, j)
126  {
127  const face& f = mesh.faces()[c[j]];
128  forAll(f, k)
129  {
130  label pointi = f[k];
131  movePts[pointi] = true;
132  }
133  }
134  }
135 
136  syncTools::syncPointList(mesh, movePts, orEqOp<bool>(), false);
137 
138  DynamicList<label> ptIDs(mesh.nPoints());
139  forAll(movePts, i)
140  {
141  if (movePts[i])
142  {
143  ptIDs.append(i);
144  }
145  }
146 
147  pointIDs_.transfer(ptIDs);
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 {
162  if (moveAllCells_)
163  {
164  return transformPoints(SBMFPtr_().transformation(), points0_);
165  }
166  else
167  {
168  tmp<pointField> ttransformedPts(new pointField(mesh().points()));
169  pointField& transformedPts = ttransformedPts.ref();
170 
171  UIndirectList<point>(transformedPts, pointIDs_) = transformPoints
172  (
173  SBMFPtr_().transformation(),
174  pointField(points0_, pointIDs_)
175  );
176 
177  return ttransformedPts;
178  }
179 }
180 
181 
182 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::points0MotionSolver
Virtual base class for displacement motion solvers, where the point motion is relative to a set of fi...
Definition: points0MotionSolver.H:57
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
boolList.H
cellZoneMesh.H
Foam::cellZoneMesh.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList< label >
Foam::orEqOp
Definition: ops.H:86
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
transformField.H
Spatial transformation functions for primitive fields.
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::transformPoints
void transformPoints(vectorField &, const septernion &, const vectorField &)
Transform given vectorField of coordinates with the given septernion.
Definition: transformField.C:73
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
f
labelList f(nPoints)
solidBodyMotionSolver.H
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::solidBodyMotionSolver::~solidBodyMotionSolver
~solidBodyMotionSolver()
Destructor.
Definition: solidBodyMotionSolver.C:154
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::solidBodyMotionSolver::curPoints
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
Definition: solidBodyMotionSolver.C:160
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
cellSet.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54