searchableBoxFeatures.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) 2013-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 "searchableBoxFeatures.H"
31 #include "treeBoundBox.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 defineTypeNameAndDebug(searchableBoxFeatures, 0);
40 (
41  searchableSurfaceFeatures,
42  searchableBoxFeatures,
43  dict
44 );
45 
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::searchableBoxFeatures::searchableBoxFeatures
52 (
53  const searchableSurface& surface,
54  const dictionary& dict
55 )
56 :
57  searchableSurfaceFeatures(surface, dict),
58  mode_
59  (
60  extendedFeatureEdgeMesh::sideVolumeTypeNames_
61  [
62  dict.getOrDefault<word>("meshableSide", "inside")
63  ]
64  )
65 {
66  Info<< indent
67  << " Meshable region = "
69  << endl;
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
83 {
84  autoPtr<extendedFeatureEdgeMesh> features;
85 
86  List<vector> faceNormalsList(treeBoundBox::faceNormals);
87  vectorField faceNormals(faceNormalsList);
88 
89  vectorField edgeDirections(12);
90  labelListList normalDirections(12);
91 
92  labelListList edgeNormals(12);
93  forAll(edgeNormals, eI)
94  {
95  edgeNormals[eI].setSize(2, 0);
96  }
97  edgeNormals[0][0] = 2; edgeNormals[0][1] = 4;
98  edgeNormals[1][0] = 1; edgeNormals[1][1] = 4;
99  edgeNormals[2][0] = 3; edgeNormals[2][1] = 4;
100  edgeNormals[3][0] = 0; edgeNormals[3][1] = 4;
101  edgeNormals[4][0] = 2; edgeNormals[4][1] = 5;
102  edgeNormals[5][0] = 1; edgeNormals[5][1] = 5;
103  edgeNormals[6][0] = 3; edgeNormals[6][1] = 5;
104  edgeNormals[7][0] = 0; edgeNormals[7][1] = 5;
105  edgeNormals[8][0] = 0; edgeNormals[8][1] = 2;
106  edgeNormals[9][0] = 2; edgeNormals[9][1] = 1;
107  edgeNormals[10][0] = 1; edgeNormals[10][1] = 3;
108  edgeNormals[11][0] = 3; edgeNormals[11][1] = 0;
109 
110  tmp<pointField> surfacePointsTmp(surface().points());
111  pointField& surfacePoints = surfacePointsTmp.ref();
112 
113  forAll(edgeDirections, eI)
114  {
115  edgeDirections[eI] =
116  surfacePoints[treeBoundBox::edges[eI].end()]
117  - surfacePoints[treeBoundBox::edges[eI].start()];
118 
119  normalDirections[eI] = labelList(2, Zero);
120  for (label j = 0; j < 2; ++j)
121  {
122  const vector cross =
123  (faceNormals[edgeNormals[eI][j]] ^ edgeDirections[eI]);
124  const vector fC0tofE0 =
125  0.5*(max(surfacePoints + min(surfacePoints)))
126  - surfacePoints[treeBoundBox::edges[eI].start()];
127 
128  normalDirections[eI][j] =
129  (
130  (
131  (cross/(mag(cross) + VSMALL))
132  & (fC0tofE0/(mag(fC0tofE0)+ VSMALL))
133  )
134  > 0.0
135  ? 1
136  : -1
137  );
138  }
139  }
140 
141  labelListList featurePointNormals(8);
142  labelListList featurePointEdges(8);
143  forAll(featurePointNormals, pI)
144  {
145  labelList& ftPtEdges = featurePointEdges[pI];
146  ftPtEdges.setSize(3, 0);
147 
148  label edgeI = 0;
150  {
151  const edge& e = treeBoundBox::edges[eI];
152 
153  if (e.start() == pI)
154  {
155  ftPtEdges[edgeI++] = eI;
156  }
157  else if (e.end() == pI)
158  {
159  ftPtEdges[edgeI++] = eI;
160  }
161  }
162 
163  labelList& ftPtNormals = featurePointNormals[pI];
164  ftPtNormals.setSize(3, 0);
165 
166  ftPtNormals[0] = edgeNormals[ftPtEdges[0]][0];
167  ftPtNormals[1] = edgeNormals[ftPtEdges[0]][1];
168  ftPtNormals[2] = edgeNormals[ftPtEdges[1]][0];
169  }
170 
171  labelList regionEdges;
172 
173  features.reset
174  (
175  new extendedFeatureEdgeMesh
176  (
177  IOobject
178  (
179  surface().name() + ".extendedFeatureEdgeMesh",
180  surface().instance(),
181  "extendedFeatureEdgeMesh",
182  surface().db(),
185  ),
186  surface().points(),
188  8, 8, 8,
189  12, 12, 12, 12,
190  faceNormals,
191  List<extendedFeatureEdgeMesh::sideVolumeType>(12, mode_),
192  edgeDirections,
193  normalDirections,
194  edgeNormals,
195  featurePointNormals,
196  featurePointEdges,
197  regionEdges
198  )
199  );
200 
201  return features;
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::searchableBoxFeatures::~searchableBoxFeatures
virtual ~searchableBoxFeatures()
Destructor.
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::treeBoundBox::edges
static const edgeList edges
Edge to point addressing.
Definition: treeBoundBox.H:154
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::extendedEdgeMesh::sideVolumeTypeNames_
static const Enum< sideVolumeType > sideVolumeTypeNames_
Definition: extendedEdgeMesh.H:125
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
faceNormals
surfaceVectorField faceNormals(mesh.Sf()/mesh.magSf())
treeBoundBox.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
searchableBoxFeatures.H
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::searchableBoxFeatures::features
virtual autoPtr< extendedFeatureEdgeMesh > features() const
Return an extendedFeatureEdgeMesh containing the features.
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::boundBox::faceNormals
static const FixedList< vector, 6 > faceNormals
The unit normal per face.
Definition: boundBox.H:92
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::cross
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:943
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)