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-2021 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 #include "hexCell.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 int Foam::blockDescriptor::calcEdgePointsWeights
37 (
38  pointField& edgePoints,
39  scalarList& edgeWeights,
40  const Foam::edge& cellModelEdge,
41  const label nDiv,
42  const gradingDescriptors& expand
43 ) const
44 {
45  // The topological edge on the block
46  const Foam::edge thisEdge(blockShape_, cellModelEdge);
47 
48  if (blockEdge::debug && !thisEdge.good())
49  {
50  Info<< "Collapsed edge:" << thisEdge;
51  if (index_ >= 0)
52  {
53  Info << " block:" << index_;
54  }
55  Info<< " model edge:" << cellModelEdge << nl;
56  }
57 
58  // FUTURE: skip point generation for collapsed edge
59 
60 
61  // Set the edge points/weights
62  // The edge is a straight-line if it is not in the list of blockEdges
63 
64  for (const blockEdge& cedge : blockEdges_)
65  {
66  const int cmp = cedge.compare(thisEdge);
67 
68  if (cmp > 0)
69  {
70  // Curve has the same orientation
71 
72  // Divide the line
73  const lineDivide divEdge(cedge, nDiv, expand);
74 
75  edgePoints = divEdge.points();
76  edgeWeights = divEdge.lambdaDivisions();
77 
78  return 1; // Found curved-edge: done
79  }
80  else if (cmp < 0)
81  {
82  // Curve has the opposite orientation
83 
84  // Divide the line
85  const lineDivide divEdge(cedge, nDiv, expand.inv());
86 
87  const pointField& p = divEdge.points();
88  const scalarList& d = divEdge.lambdaDivisions();
89 
90  edgePoints.resize(p.size());
91  edgeWeights.resize(d.size());
92 
93  // Copy in reverse order
94  const label pn = (p.size() - 1);
95  forAll(p, pi)
96  {
97  edgePoints[pi] = p[pn - pi];
98  edgeWeights[pi] = 1 - d[pn - pi];
99  }
100 
101  return 1; // Found curved-edge: done
102  }
103  }
104 
105  // Not curved-edge: divide the edge as a straight line
106 
107  // Get list of points for this block
108  const pointField blockPoints(blockShape_.points(vertices_));
109 
110  lineDivide divEdge
111  (
112  blockEdges::lineEdge(blockPoints, cellModelEdge),
113  nDiv,
114  expand
115  );
116 
117  edgePoints = divEdge.points();
118  edgeWeights = divEdge.lambdaDivisions();
119 
120  return 0;
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 (
128  pointField (&edgesPoints)[12],
129  scalarList (&edgesWeights)[12]
130 ) const
131 {
132  int nCurved = 0;
133 
134  for (label edgei = 0; edgei < 12; ++edgei) //< hexCell::nEdges()
135  {
136  nCurved += calcEdgePointsWeights
137  (
138  edgesPoints[edgei],
139  edgesWeights[edgei],
140  hexCell::modelEdges()[edgei],
141 
142  sizes()[edgei/4], // 12 edges -> 3 components (x,y,z)
143  expand_[edgei]
144  );
145  }
146 
147  return nCurved;
148 }
149 
150 
152 (
153  const label edgei,
154  pointField& edgePoints,
155  scalarList& edgeWeights,
156  const label nDiv,
157  const gradingDescriptors& gd
158 ) const
159 {
160  if (edgei < 0 || edgei >= 12) //< hexCell::nEdges()
161  {
163  << "Edge label " << edgei
164  << " out of range 0..11"
165  << exit(FatalError);
166  }
167 
168  const int nCurved = calcEdgePointsWeights
169  (
170  edgePoints,
171  edgeWeights,
172  hexCell::modelEdges()[edgei],
173 
174  nDiv,
175  gd
176  );
177 
178  return nCurved;
179 }
180 
181 
183 (
184  const label edgei,
185  pointField& edgePoints,
186  scalarList& edgeWeights
187 ) const
188 {
189  if (edgei < 0 || edgei >= 12) //< hexCell::nEdges()
190  {
192  << "Edge label " << edgei
193  << " out of range 0..11"
194  << exit(FatalError);
195  }
196 
197  const int nCurved = calcEdgePointsWeights
198  (
199  edgePoints,
200  edgeWeights,
201  hexCell::modelEdges()[edgei],
202 
203  sizes()[edgei/4], // 12 edges -> 3 components (x,y,z)
204  expand_[edgei]
205  );
206 
207  return nCurved;
208 }
209 
210 
211 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
static const Foam::edgeList & modelEdges()
Return the model edges.
Definition: hexCell.C:87
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
int edgesPointsWeights(pointField(&edgesPoints)[12], scalarList(&edgesWeights)[12]) const
Calculate the points and weights for all edges.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
bool edgePointsWeights(const label edgei, pointField &edgePoints, scalarList &edgeWeights, const label nDiv, const gradingDescriptors &gd=gradingDescriptors()) const
Calculate points and weights for specified edge, using the specified number of divisions and grading...
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition: edge.H:59
constexpr scalar pi(M_PI)
pointField points(const UList< point > &meshPoints) const
The points corresponding to this shape.
Definition: cellShapeI.H:178
int debug
Static debugging option.
messageStream Info
Information stream (stdout output on master, null elsewhere)
volScalarField & p
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping and return the expanded string.
Definition: stringOps.C:705