searchableBoxFeatures.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2018 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.ref();
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;
146  forAll(treeBoundBox::edges, eI)
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(),
184  treeBoundBox::edges,
185  8, 8, 8,
186  12, 12, 12, 12,
187  faceNormals,
188  List<extendedFeatureEdgeMesh::sideVolumeType>(12, mode_),
189  edgeDirections,
190  normalDirections,
191  edgeNormals,
192  featurePointNormals,
193  featurePointEdges,
194  regionEdges
195  )
196  );
197 
198  return features;
199 }
200 
201 
202 // ************************************************************************* //
static const FixedList< vector, 6 > faceNormals
Per face the unit normal.
Definition: treeBoundBox.H:181
searchableBoxFeatures(const searchableSurface &surface, const dictionary &dict)
Construct from searchable surface and dictionary.
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:226
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static const Foam::NamedEnum< sideVolumeType, 4 > sideVolumeTypeNames_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Macros for easy insertion into run-time selection tables.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
const pointField & points
virtual autoPtr< extendedFeatureEdgeMesh > features() const
Return an extendedFeatureEdgeMesh containing the features.
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void setSize(const label)
Reset size of List.
Definition: List.C:281
virtual ~searchableBoxFeatures()
Destructor.
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Namespace for OpenFOAM.