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 | Copyright (C) 2013-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "searchableBoxFeatures.H"
28 #include "treeBoundBox.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 defineTypeNameAndDebug(searchableBoxFeatures, 0);
37 (
38  searchableSurfaceFeatures,
39  searchableBoxFeatures,
40  dict
41 );
42 
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const searchableSurface& surface,
51  const dictionary& dict
52 )
53 :
54  searchableSurfaceFeatures(surface, dict),
55  mode_
56  (
57  extendedFeatureEdgeMesh::sideVolumeTypeNames_
58  [
59  dict.lookupOrDefault<word>("meshableSide", "inside")
60  ]
61  )
62 {
63  Info<< indent
64  << " Meshable region = "
66  << endl;
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
71 
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
80 {
81  autoPtr<extendedFeatureEdgeMesh> features;
82 
83  List<vector> faceNormalsList(treeBoundBox::faceNormals);
84  vectorField faceNormals(faceNormalsList);
85 
86  vectorField edgeDirections(12);
87  labelListList normalDirections(12);
88 
89  labelListList edgeNormals(12);
90  forAll(edgeNormals, eI)
91  {
92  edgeNormals[eI].setSize(2, 0);
93  }
94  edgeNormals[0][0] = 2; edgeNormals[0][1] = 4;
95  edgeNormals[1][0] = 1; edgeNormals[1][1] = 4;
96  edgeNormals[2][0] = 3; edgeNormals[2][1] = 4;
97  edgeNormals[3][0] = 0; edgeNormals[3][1] = 4;
98  edgeNormals[4][0] = 2; edgeNormals[4][1] = 5;
99  edgeNormals[5][0] = 1; edgeNormals[5][1] = 5;
100  edgeNormals[6][0] = 3; edgeNormals[6][1] = 5;
101  edgeNormals[7][0] = 0; edgeNormals[7][1] = 5;
102  edgeNormals[8][0] = 0; edgeNormals[8][1] = 2;
103  edgeNormals[9][0] = 2; edgeNormals[9][1] = 1;
104  edgeNormals[10][0] = 1; edgeNormals[10][1] = 3;
105  edgeNormals[11][0] = 3; edgeNormals[11][1] = 0;
106 
107  tmp<pointField> surfacePointsTmp(surface().points());
108  pointField& surfacePoints = surfacePointsTmp();
109 
110  forAll(edgeDirections, eI)
111  {
112  edgeDirections[eI] =
113  surfacePoints[treeBoundBox::edges[eI].end()]
114  - surfacePoints[treeBoundBox::edges[eI].start()];
115 
116  normalDirections[eI] = labelList(2, label(0));
117  for (label j = 0; j < 2; ++j)
118  {
119  const vector cross =
120  (faceNormals[edgeNormals[eI][j]] ^ edgeDirections[eI]);
121  const vector fC0tofE0 =
122  0.5*(max(surfacePoints + min(surfacePoints)))
123  - surfacePoints[treeBoundBox::edges[eI].start()];
124 
125  normalDirections[eI][j] =
126  (
127  (
128  (cross/(mag(cross) + VSMALL))
129  & (fC0tofE0/(mag(fC0tofE0)+ VSMALL))
130  )
131  > 0.0
132  ? 1
133  : -1
134  );
135  }
136  }
137 
138  labelListList featurePointNormals(8);
139  labelListList featurePointEdges(8);
140  forAll(featurePointNormals, pI)
141  {
142  labelList& ftPtEdges = featurePointEdges[pI];
143  ftPtEdges.setSize(3, 0);
144 
145  label edgeI = 0;
147  {
148  const edge& e = treeBoundBox::edges[eI];
149 
150  if (e.start() == pI)
151  {
152  ftPtEdges[edgeI++] = eI;
153  }
154  else if (e.end() == pI)
155  {
156  ftPtEdges[edgeI++] = eI;
157  }
158  }
159 
160  labelList& ftPtNormals = featurePointNormals[pI];
161  ftPtNormals.setSize(3, 0);
162 
163  ftPtNormals[0] = edgeNormals[ftPtEdges[0]][0];
164  ftPtNormals[1] = edgeNormals[ftPtEdges[0]][1];
165  ftPtNormals[2] = edgeNormals[ftPtEdges[1]][0];
166  }
167 
168  labelList regionEdges;
169 
170  features.set
171  (
172  new extendedFeatureEdgeMesh
173  (
174  IOobject
175  (
176  surface().name() + ".extendedFeatureEdgeMesh",
177  surface().instance(),
178  "extendedFeatureEdgeMesh",
179  surface().db(),
182  ),
183  surface().points(),
185  8, 8, 8,
186  12, 12, 12, 12,
187  faceNormals,
189  edgeDirections,
190  normalDirections,
191  edgeNormals,
192  featurePointNormals,
193  featurePointEdges,
194  regionEdges
195  )
196  );
197 
198  return features;
199 }
200 
201 
202 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::searchableBoxFeatures::~searchableBoxFeatures
virtual ~searchableBoxFeatures()
Destructor.
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::searchableBoxFeatures::searchableBoxFeatures
searchableBoxFeatures(const searchableBoxFeatures &)
Disallow default bitwise copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::treeBoundBox::edges
static const edgeList edges
Edge to point addressing.
Definition: treeBoundBox.H:157
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::treeBoundBox::faceNormals
static const FixedList< vector, 6 > faceNormals
Per face the unit normal.
Definition: treeBoundBox.H:160
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:49
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:59
treeBoundBox.H
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::Info
messageStream Info
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: combustionModel.C:30
Foam::extendedEdgeMesh::sideVolumeTypeNames_
static const Foam::NamedEnum< sideVolumeType, 4 > sideVolumeTypeNames_
Definition: extendedEdgeMesh.H:123
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Foam::searchableBoxFeatures::features
virtual autoPtr< extendedFeatureEdgeMesh > features() const
Return an extendedFeatureEdgeMesh containing the features.
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
points
const pointField & points
Definition: gmvOutputHeader.H:1
List
Definition: Test.C:19
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:874
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47