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-------------------------------------------------------------------------------
11License
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
36namespace Foam
37{
44 (
47 word,
48 rotatedBox
49 );
51 (
54 istream,
55 rotatedBox
56 );
57}
58
59
60Foam::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
71void 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// ************************************************************************* //
label k
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:225
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const vectorField & cellCentres() const
A topoSetCellSource to select cells based on cell centres inside a given parallopiped (i....
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
const polyMesh & mesh_
Reference to the mesh.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const cellModel & hex
dynamicFvMesh & mesh
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Field< vector > vectorField
Specialisation of Field<T> for vector.
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
labelList f(nPoints)
dict add("bounds", meshBb)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333