blockDescriptorEdges.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) 2011-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 "blockDescriptor.H"
27 #include "lineEdge.H"
28 #include "lineDivide.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 Foam::label Foam::blockDescriptor::edgePointsWeights
33 (
34  pointField (&edgePoints)[12],
35  scalarList (&edgeWeights)[12],
36  const label edgei,
37  const label start,
38  const label end,
39  const label nDiv
40 ) const
41 {
42  // Set reference to the list of labels defining the block
43  const labelList& blockLabels = blockShape_;
44 
45  // Get list of points for this block
46  const pointField blockPoints = blockShape_.points(vertices_);
47 
48  // Set the edge points/weights
49  // The edge is a straight-line if it is not in the list of blockEdges
50 
51  forAll(edges_, cedgei)
52  {
53  const blockEdge& cedge = edges_[cedgei];
54 
55  const int cmp = cedge.compare(blockLabels[start], blockLabels[end]);
56 
57  if (cmp)
58  {
59  if (cmp > 0)
60  {
61  // Curve has the same orientation
62 
63  // Divide the line
64  const lineDivide divEdge(cedge, nDiv, expand_[edgei]);
65 
66  edgePoints[edgei] = divEdge.points();
67  edgeWeights[edgei] = divEdge.lambdaDivisions();
68  }
69  else
70  {
71  // Curve has the opposite orientation
72 
73  // Divide the line
74  const lineDivide divEdge(cedge, nDiv, expand_[edgei].inv());
75 
76  const pointField& p = divEdge.points();
77  const scalarList& d = divEdge.lambdaDivisions();
78 
79  edgePoints[edgei].setSize(p.size());
80  edgeWeights[edgei].setSize(d.size());
81 
82  label pn = p.size() - 1;
83  forAll(p, pi)
84  {
85  edgePoints[edgei][pi] = p[pn - pi];
86  edgeWeights[edgei][pi] = 1 - d[pn - pi];
87  }
88  }
89 
90  // Found curved-edge: done
91  return 1;
92  }
93  }
94 
95 
96  // Not curved-edge: divide the edge as a straight line
97  lineDivide divEdge
98  (
99  blockEdges::lineEdge(blockPoints, start, end),
100  nDiv,
101  expand_[edgei]
102  );
103 
104  edgePoints[edgei] = divEdge.points();
105  edgeWeights[edgei] = divEdge.lambdaDivisions();
106 
107  return 0;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
114 (
115  pointField (&edgePoints)[12],
116  scalarList (&edgeWeights)[12]
117 ) const
118 {
119  label nCurvedEdges = 0;
120 
121  // X-direction
122  const label ni = density_.x();
123  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 0, 0, 1, ni);
124  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 1, 3, 2, ni);
125  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 2, 7, 6, ni);
126  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 3, 4, 5, ni);
127 
128  // Y-direction
129  const label nj = density_.y();
130  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 4, 0, 3, nj);
131  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 5, 1, 2, nj);
132  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 6, 5, 6, nj);
133  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 7, 4, 7, nj);
134 
135  // Z-direction
136  const label nk = density_.z();
137  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 8, 0, 4, nk);
138  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 9, 1, 5, nk);
139  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 10, 2, 6, nk);
140  nCurvedEdges += edgePointsWeights(edgePoints, edgeWeights, 11, 3, 7, nk);
141 
142  return nCurvedEdges;
143 }
144 
145 
146 // ************************************************************************* //
label edgesPointsWeights(pointField(&edgePoints)[12], scalarList(&edgeWeights)[12]) const
Calculate the points and weights for all edges.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
pointField points(const pointField &meshPoints) const
Return the points corresponding to this cellShape.
Definition: cellShapeI.H:87
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
List< label > labelList
A List of labels.
Definition: labelList.H:56
const Cmpt & x() const
Definition: VectorI.H:75
void setSize(const label)
Reset size of List.
Definition: List.C:281