rotatedBoxToCell.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018 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 "rotatedBoxToCell.H"
30 #include "polyMesh.H"
31 #include "cellModel.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(rotatedBoxToCell, 0);
39  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, word);
40  addToRunTimeSelectionTable(topoSetSource, rotatedBoxToCell, istream);
41  addToRunTimeSelectionTable(topoSetCellSource, rotatedBoxToCell, word);
42  addToRunTimeSelectionTable(topoSetCellSource, rotatedBoxToCell, istream);
44  (
45  topoSetCellSource,
46  rotatedBoxToCell,
47  word,
48  rotatedBox
49  );
51  (
52  topoSetCellSource,
53  rotatedBoxToCell,
54  istream,
55  rotatedBox
56  );
57 }
58 
59 
60 Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToCell::usage_
61 (
62  rotatedBoxToCell::typeName,
63  "\n Usage: rotatedBoxToCell (originx originy originz)"
64  " (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
65  " Select all cells with cellCentre within parallelopiped\n\n"
66 );
67 
68 
69 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70 
71 void Foam::rotatedBoxToCell::combine(topoSet& set, const bool add) const
72 {
73  // Define a cell for the box
74  pointField boxPoints(8);
75  boxPoints[0] = origin_;
76  boxPoints[1] = origin_ + i_;
77  boxPoints[2] = origin_ + i_ + j_;
78  boxPoints[3] = origin_ + j_;
79  boxPoints[4] = origin_ + k_;
80  boxPoints[5] = origin_ + k_ + i_;
81  boxPoints[6] = origin_ + k_ + i_ + j_;
82  boxPoints[7] = origin_ + k_ + j_;
83 
84  labelList boxVerts(identity(8));
85 
86  const cellModel& hex = cellModel::ref(cellModel::HEX);
87 
88  // Get outwards pointing faces.
89  faceList boxFaces(cellShape(hex, boxVerts).faces());
90 
91  // Precalculate normals
92  vectorField boxFaceNormals(boxFaces.size());
93  forAll(boxFaces, i)
94  {
95  boxFaceNormals[i] = boxFaces[i].areaNormal(boxPoints);
96 
97  //Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
98  // << " normal:" << boxFaceNormals[i] << endl;
99  }
100 
101  // Check whether cell centre is inside all faces of box.
102 
103  const pointField& ctrs = mesh_.cellCentres();
104 
105  forAll(ctrs, celli)
106  {
107  bool inside = true;
108 
109  forAll(boxFaces, i)
110  {
111  const face& f = boxFaces[i];
112 
113  if (((ctrs[celli] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
114  {
115  inside = false;
116  break;
117  }
118  }
119 
120  if (inside)
121  {
122  addOrDelete(set, celli, add);
123  }
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
131 (
132  const polyMesh& mesh,
133  const vector& origin,
134  const vector& i,
135  const vector& j,
136  const vector& k
137 )
138 :
140  origin_(origin),
141  i_(i),
142  j_(j),
143  k_(k)
144 {}
145 
146 
148 (
149  const polyMesh& mesh,
150  const dictionary& dict
151 )
152 :
154  (
155  mesh,
156  dict.get<point>("origin"),
157  dict.get<vector>("i"),
158  dict.get<vector>("j"),
159  dict.get<vector>("k")
160  )
161 {}
162 
163 
165 :
167  origin_(is),
168  i_(is),
169  j_(is),
170  k_(is)
171 {}
172 
173 
174 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 
177 (
178  const topoSetSource::setAction action,
179  topoSet& set
180 ) const
181 {
182  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
183  {
184  if (verbose_)
185  {
186  Info<< " Adding cells with centre within rotated box"
187  << endl;
188  }
189 
190  combine(set, true);
191  }
192  else if (action == topoSetSource::SUBTRACT)
193  {
194  if (verbose_)
195  {
196  Info<< " Removing cells with centre within rotated box"
197  << endl;
198  }
199 
200  combine(set, false);
201  }
202 }
203 
204 
205 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::cellModel::HEX
hex
Definition: cellModel.H:81
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
cellModel.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::rotatedBoxToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: rotatedBoxToCell.C:177
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::cellModel::ref
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition: cellModels.C:157
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::hex
IOstream & hex(IOstream &io)
Definition: IOstream.H:446
Foam::rotatedBoxToCell
A topoSetCellSource to select cells based on cell centres inside a given parallopiped (i....
Definition: rotatedBoxToCell.H:173
rotatedBoxToCell.H
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
f
labelList f(nPoints)
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::Vector< scalar >
Foam::topoSetCellSource
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Definition: topoSetCellSource.H:54
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:171
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::rotatedBoxToCell::rotatedBoxToCell
rotatedBoxToCell(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.
Definition: rotatedBoxToCell.C:131