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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "solidBodyMotionSolver.H"
30 #include "transformField.H"
31 #include "cellZoneMesh.H"
32 #include "cellSet.H"
33 #include "boolList.H"
34 #include "syncTools.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(solidBodyMotionSolver, 0);
42  (
43  motionSolver,
44  solidBodyMotionSolver,
45  dictionary
46  );
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::solidBodyMotionSolver::solidBodyMotionSolver
53 (
54  const polyMesh& mesh,
55  const IOdictionary& dict
56 )
57 :
58  points0MotionSolver(mesh, dict, typeName),
59  SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())),
60  pointIDs_(),
61  moveAllCells_(false)
62 {
63  word cellZoneName =
64  coeffDict().lookupOrDefault<word>("cellZone", "none");
65 
66  word cellSetName =
67  coeffDict().lookupOrDefault<word>("cellSet", "none");
68 
69  if ((cellZoneName != "none") && (cellSetName != "none"))
70  {
71  FatalIOErrorInFunction(coeffDict())
72  << "Either cellZone OR cellSet can be supplied, but not both. "
73  << "If neither is supplied, all cells will be included"
74  << exit(FatalIOError);
75  }
76 
77  labelList cellIDs;
78  if (cellZoneName != "none")
79  {
80  Info<< "Applying solid body motion to cellZone " << cellZoneName
81  << endl;
82 
83  label zoneID = mesh.cellZones().findZoneID(cellZoneName);
84 
85  if (zoneID == -1)
86  {
88  << "Unable to find cellZone " << cellZoneName
89  << ". Valid cellZones are:"
90  << mesh.cellZones().names()
91  << exit(FatalError);
92  }
93 
94  cellIDs = mesh.cellZones()[zoneID];
95  }
96 
97  if (cellSetName != "none")
98  {
99  Info<< "Applying solid body motion to cellSet " << cellSetName
100  << endl;
101 
102  cellSet set(mesh, cellSetName);
103 
104  cellIDs = set.toc();
105  }
106 
107  label nCells = returnReduce(cellIDs.size(), sumOp<label>());
108  moveAllCells_ = nCells == 0;
109 
110  if (moveAllCells_)
111  {
112  Info<< "Applying solid body motion to entire mesh" << endl;
113  }
114  else
115  {
116  // collect point IDs of points in cell zone
117 
118  boolList movePts(mesh.nPoints(), false);
119 
120  forAll(cellIDs, i)
121  {
122  label celli = cellIDs[i];
123  const cell& c = mesh.cells()[celli];
124  forAll(c, j)
125  {
126  const face& f = mesh.faces()[c[j]];
127  forAll(f, k)
128  {
129  label pointi = f[k];
130  movePts[pointi] = true;
131  }
132  }
133  }
134 
135  syncTools::syncPointList(mesh, movePts, orEqOp<bool>(), false);
136 
137  DynamicList<label> ptIDs(mesh.nPoints());
138  forAll(movePts, i)
139  {
140  if (movePts[i])
141  {
142  ptIDs.append(i);
143  }
144  }
145 
146  pointIDs_.transfer(ptIDs);
147  }
148 }
149 
150 
151 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 
154 {}
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
160 {
161  if (moveAllCells_)
162  {
163  return transformPoints(SBMFPtr_().transformation(), points0_);
164  }
165  else
166  {
167  tmp<pointField> ttransformedPts(new pointField(mesh().points()));
168  pointField& transformedPts = ttransformedPts.ref();
169 
170  UIndirectList<point>(transformedPts, pointIDs_) = transformPoints
171  (
172  SBMFPtr_().transformation(),
173  pointField(points0_, pointIDs_)
174  );
175 
176  return ttransformedPts;
177  }
178 }
179 
180 
181 // ************************************************************************* //
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
boolList.H
cellZoneMesh.H
Foam::cellZoneMesh.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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::HashTable::toc
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:121
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
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:337
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:290
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::label
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:62
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:355
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:153
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:159
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:109
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
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