rayShooting.C 6.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2013 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "rayShooting.H"
#include "addToRunTimeSelectionTable.H"
#include "triSurfaceMesh.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

defineTypeNameAndDebug(rayShooting, 0);
addToRunTimeSelectionTable(initialPointsMethod, rayShooting, dictionary);

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

rayShooting::rayShooting
(
    const dictionary& initialPointsDict,
    const Time& runTime,
    Random& rndGen,
    const conformationSurfaces& geometryToConformTo,
    const cellShapeControl& cellShapeControls,
    const autoPtr<backgroundMeshDecomposition>& decomposition
)
:
    initialPointsMethod
    (
        typeName,
        initialPointsDict,
        runTime,
        rndGen,
        geometryToConformTo,
        cellShapeControls,
        decomposition
    ),
    randomiseInitialGrid_(detailsDict().lookup("randomiseInitialGrid")),
    randomPerturbationCoeff_
    (
        readScalar(detailsDict().lookup("randomPerturbationCoeff"))
    )
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

List<Vb::Point> rayShooting::initialPoints() const
{
    // Loop over surface faces
    const searchableSurfaces& surfaces = geometryToConformTo().geometry();
    const labelList& surfacesToConformTo = geometryToConformTo().surfaces();

78
79
    const scalar maxRayLength = surfaces.bounds().mag();

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    // Initialise points list
    label initialPointsSize = 0;
    forAll(surfaces, surfI)
    {
        initialPointsSize += surfaces[surfI].size();
    }

    DynamicList<Vb::Point> initialPoints(initialPointsSize);

    forAll(surfacesToConformTo, surfI)
    {
        const searchableSurface& s = surfaces[surfacesToConformTo[surfI]];

        tmp<pointField> faceCentresTmp(s.coordinates());
        const pointField& faceCentres = faceCentresTmp();

        Info<< "    Shoot rays from " << s.name() << nl
            << "    nRays = " << faceCentres.size() << endl;


        forAll(faceCentres, fcI)
        {
            const Foam::point& fC = faceCentres[fcI];

            if
            (
                Pstream::parRun()
             && !decomposition().positionOnThisProcessor(fC)
            )
            {
                continue;
            }

            const scalar pert =
                randomPerturbationCoeff_
               *cellShapeControls().cellSize(fC);

            pointIndexHit surfHitStart;
            label hitSurfaceStart;

            // Face centres should be on the surface so search distance can be
            // small
            geometryToConformTo().findSurfaceNearest
            (
                 fC,
125
                 sqr(pert),
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
                 surfHitStart,
                 hitSurfaceStart
            );

            vectorField normStart(1, vector::min);
            geometryToConformTo().getNormal
            (
                hitSurfaceStart,
                List<pointIndexHit>(1, surfHitStart),
                normStart
            );

            pointIndexHit surfHitEnd;
            label hitSurfaceEnd;

            geometryToConformTo().findSurfaceNearestIntersection
            (
143
                fC - normStart[0]*pert,
144
                fC - normStart[0]*maxRayLength,
145
146
147
148
                surfHitEnd,
                hitSurfaceEnd
            );

149
            if (surfHitEnd.hit())
150
            {
151
152
153
154
155
156
157
                vectorField normEnd(1, vector::min);
                geometryToConformTo().getNormal
                (
                    hitSurfaceEnd,
                    List<pointIndexHit>(1, surfHitEnd),
                    normEnd
                );
158

159
                if ((normStart[0] & normEnd[0]) < 0)
160
                {
161
162
163
                    line<point, point> l(fC, surfHitEnd.hitPoint());

                    if (Pstream::parRun())
164
                    {
165
166
167
                        // Clip the line in parallel
                        pointIndexHit procIntersection =
                            decomposition().findLine
168
                            (
169
170
                                l.start(),
                                l.end()
171
                            );
172
173
174
175
176
177
178
179
180
181

                        if (procIntersection.hit())
                        {
                            l =
                                line<point, point>
                                (
                                    l.start(),
                                    procIntersection.hitPoint()
                                );
                        }
182
183
                    }

184
                    Foam::point midPoint(l.centre());
185

186
187
188
                    const scalar minDistFromSurfaceSqr =
                        minimumSurfaceDistanceCoeffSqr_
                       *sqr(cellShapeControls().cellSize(midPoint));
189

190
191
192
193
194
195
196
                    if (randomiseInitialGrid_)
                    {
                        midPoint.x() += pert*(rndGen().scalar01() - 0.5);
                        midPoint.y() += pert*(rndGen().scalar01() - 0.5);
                        midPoint.z() += pert*(rndGen().scalar01() - 0.5);
                    }

197
198
199
200
201
                    if
                    (
                        magSqr(midPoint - l.start()) > minDistFromSurfaceSqr
                     && magSqr(midPoint - l.end()) > minDistFromSurfaceSqr
                    )
202
                    {
203
                        initialPoints.append(toPoint(midPoint));
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
                    }
                }
            }
        }
    }

    return initialPoints.shrink();
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// ************************************************************************* //