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