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