Loading...
Searching...
No Matches
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-2022 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 "hexCell.H"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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, origin_);
75 // boxPoints[0] = origin_;
76 boxPoints[1] += i_;
77 boxPoints[2] += i_ + j_;
78 boxPoints[3] += j_;
79 boxPoints[4] += k_;
80 boxPoints[5] += k_ + i_;
81 boxPoints[6] += k_ + i_ + j_;
82 boxPoints[7] += k_ + j_;
83
84 // Get outwards pointing faces.
85 faceList boxFaces(hexCell::modelFaces());
86
87 // Precalculate normals
88 vectorField boxFaceNormals(boxFaces.size());
89 forAll(boxFaces, i)
90 {
91 boxFaceNormals[i] = boxFaces[i].areaNormal(boxPoints);
92
93 //Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
94 // << " normal:" << boxFaceNormals[i] << endl;
95 }
96
97 // Check whether cell centre is inside all faces of box.
98
99 const tmp<pointField> tctrs(this->transform(mesh_.cellCentres()));
100 const pointField& ctrs = tctrs();
101
102 forAll(ctrs, celli)
103 {
104 bool inside = true;
105
106 forAll(boxFaces, i)
107 {
108 const face& f = boxFaces[i];
109
110 if (((ctrs[celli] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
111 {
112 inside = false;
113 break;
114 }
115 }
116
117 if (inside)
118 {
119 addOrDelete(set, celli, add);
121 }
122}
123
124
125// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126
128(
129 const polyMesh& mesh,
130 const vector& origin,
131 const vector& i,
132 const vector& j,
133 const vector& k
134)
135:
137 origin_(origin),
138 i_(i),
139 j_(j),
140 k_(k)
141{}
142
143
145(
146 const polyMesh& mesh,
147 const dictionary& dict
148)
149:
151 origin_(dict.get<point>("origin")),
152 i_(dict.get<vector>("i")),
153 j_(dict.get<vector>("j")),
154 k_(dict.get<vector>("k"))
155{}
156
157
159:
161 origin_(is),
162 i_(is),
163 j_(is),
164 k_(is)
165{}
166
167
168// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169
171(
172 const topoSetSource::setAction action,
173 topoSet& set
174) const
175{
176 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
177 {
178 if (verbose_)
179 {
180 Info<< " Adding cells with centre within rotated box"
181 << endl;
182 }
183
184 combine(set, true);
185 }
186 else if (action == topoSetSource::SUBTRACT)
187 {
188 if (verbose_)
189 {
190 Info<< " Removing cells with centre within rotated box"
191 << endl;
192 }
193
194 combine(set, false);
195 }
196}
197
198
199// ************************************************************************* //
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:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static const Foam::faceList & modelFaces()
Return the model faces.
Definition hexCell.C:64
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A topoSetCellSource to select cells based on cell centres inside a given parallopiped (i....
rotatedBoxToCell(const polyMesh &mesh, const vector &origin, const vector &i, const vector &j, const vector &k)
Construct from components.
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.
topoSetCellSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
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.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
Namespace for OpenFOAM.
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
Definition point.H:37
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
labelList f(nPoints)
dict add("bounds", meshBb)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299