searchablePlateFeatures.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-2015 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 
31 #include "treeBoundBox.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 defineTypeNameAndDebug(searchablePlateFeatures, 0);
40 (
41  searchableSurfaceFeatures,
42  searchablePlateFeatures,
43  dict
44 );
45 
47 const Foam::label edgesArray[4][2] =
48 {
49  {0, 1}, // 0
50  {0, 3},
51  {2, 1}, // 2
52  {2, 3}
53 };
55 
56 const edgeList searchablePlateFeatures::edges(calcEdges(edgesArray));
57 
58 }
59 
60 
61 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
62 
63 Foam::edgeList Foam::searchablePlateFeatures::calcEdges
64 (
65  const label edgesArray[4][2]
66 )
67 {
68  edgeList edges(4);
69  forAll(edges, edgeI)
70  {
71  edges[edgeI][0] = edgesArray[edgeI][0];
72  edges[edgeI][1] = edgesArray[edgeI][1];
73  }
74  return edges;
75 }
76 
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
80 Foam::searchablePlateFeatures::searchablePlateFeatures
81 (
83  const dictionary& dict
84 )
85 :
87  mode_
88  (
89  extendedFeatureEdgeMesh::sideVolumeTypeNames_
90  [
91  dict.getOrDefault<word>("meshableSide", "inside")
92  ]
93  )
94 {
95  Info<< indent
96  << " Meshable region = "
98  << endl;
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
103 
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
112 {
114 
115  vectorField faceNormals(1);
116  surface().getNormal(List<pointIndexHit>(1), faceNormals);
117 
118  vectorField edgeDirections(4);
119  labelListList normalDirections(4);
120 
121  labelListList edgeNormals(4);
122  forAll(edgeNormals, eI)
123  {
124  edgeNormals[eI].setSize(2, 0);
125  }
126  edgeNormals[0][0] = 0; edgeNormals[0][1] = 0;
127  edgeNormals[1][0] = 0; edgeNormals[1][1] = 0;
128  edgeNormals[2][0] = 0; edgeNormals[2][1] = 0;
129  edgeNormals[3][0] = 0; edgeNormals[3][1] = 0;
130 
131  forAll(edgeDirections, eI)
132  {
133  edgeDirections[eI] =
134  surface().points()()[edges[eI].end()]
135  - surface().points()()[edges[eI].start()];
136 
137  normalDirections[eI] = labelList(2, Zero);
138  for (label j = 0; j < 2; ++j)
139  {
140  const vector cross =
141  (faceNormals[edgeNormals[eI][j]] ^ edgeDirections[eI]);
142  const vector fC0tofE0 =
143  0.5*(max(surface().points()() + min(surface().points()())))
144  - surface().points()()[edges[eI].start()];
145 
146  normalDirections[eI][j] =
147  (
148  (
149  (cross/(mag(cross) + VSMALL))
150  & (fC0tofE0/(mag(fC0tofE0)+ VSMALL))
151  )
152  > 0.0
153  ? 1
154  : -1
155  );
156  }
157  }
158 
159  labelListList featurePointNormals(4);
160  labelListList featurePointEdges(4);
161  forAll(featurePointNormals, pI)
162  {
163  labelList& ftPtEdges = featurePointEdges[pI];
164  ftPtEdges.setSize(2, 0);
165 
166  label edgeI = 0;
167  forAll(edges, eI)
168  {
169  const edge& e = edges[eI];
170 
171  if (e.start() == pI)
172  {
173  ftPtEdges[edgeI++] = eI;
174  }
175  else if (e.end() == pI)
176  {
177  ftPtEdges[edgeI++] = eI;
178  }
179  }
180 
181  labelList& ftPtNormals = featurePointNormals[pI];
182  ftPtNormals.setSize(1, 0);
183 
184  ftPtNormals[0] = edgeNormals[ftPtEdges[0]][0];
185  }
186 
187  labelList regionEdges;
188 
189  features.reset
190  (
191  new extendedFeatureEdgeMesh
192  (
193  IOobject
194  (
195  surface().name() + ".extendedFeatureEdgeMesh",
196  surface().instance(),
197  "extendedFeatureEdgeMesh",
198  surface().db(),
201  ),
202  surface().points(),
203  edges,
204  4, 4, 4,
205  0, 0, 4, 4, // 4 flat edges
206  faceNormals,
207  List<extendedFeatureEdgeMesh::sideVolumeType>(4, mode_),
208  edgeDirections,
209  normalDirections,
210  edgeNormals,
211  featurePointNormals,
212  featurePointEdges,
213  regionEdges
214  )
215  );
216 
217  return features;
218 }
219 
220 
221 // ************************************************************************* //
dictionary dict
static const Enum< sideVolumeType > sideVolumeTypeNames_
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
Decorator that returns the features of a searchable surface.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
virtual ~searchablePlateFeatures()
Destructor.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:37
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
void setSize(const label n)
Alias for resize()
Definition: List.H:316
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const pointField & points
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const edgeList edges
Edge to point addressing.
Vector< scalar > vector
Definition: vector.H:57
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
const wordList surface
Standard surface field types (scalar, vector, tensor, etc)
virtual autoPtr< extendedFeatureEdgeMesh > features() const
Return an extendedFeatureEdgeMesh containing the features.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
defineTypeNameAndDebug(combustionModel, 0)
Nothing to be read.
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
List< label > labelList
A List of labels.
Definition: List.H:62
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127