arraySet.C 4.58 KB
Newer Older
Henry's avatar
Henry committed
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
Henry's avatar
Henry committed
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
-------------------------------------------------------------------------------
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 "arraySet.H"
#include "sampledSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "word.H"

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

namespace Foam
{
    defineTypeNameAndDebug(arraySet, 0);
    addToRunTimeSelectionTable(sampledSet, arraySet, word);
}


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

void Foam::arraySet::calcSamples
(
    DynamicList<point>& samplingPts,
    DynamicList<label>& samplingCells,
    DynamicList<label>& samplingFaces,
    DynamicList<label>& samplingSegments,
    DynamicList<scalar>& samplingCurveDist
) const
{
    const meshSearch& queryMesh = searchEngine();

56 57 58
    const scalar dx = spanBox_.x()/(pointsDensity_.x() + 1);
    const scalar dy = spanBox_.y()/(pointsDensity_.y() + 1);
    const scalar dz = spanBox_.z()/(pointsDensity_.z() + 1);
Henry's avatar
Henry committed
59

60
    label sampleI(0);
Henry's avatar
Henry committed
61

62
    for (label k=1; k<=pointsDensity_.z(); ++k)
Henry's avatar
Henry committed
63
    {
64
        for (label j=1; j<=pointsDensity_.y(); ++j)
Henry's avatar
Henry committed
65
        {
66
            for (label i=1; i<=pointsDensity_.x(); ++i)
Henry's avatar
Henry committed
67
            {
68
                // Local Cartesian
69
                point pt(i*dx, j*dy, k*dz);
70 71 72 73 74 75 76 77 78 79 80 81 82 83

                // Global Cartesian
                pt = csys_.globalPosition(pt);

                const label celli = queryMesh.findCell(pt);

                if (celli != -1)
                {
                    samplingPts.append(pt);
                    samplingCells.append(celli);
                    samplingFaces.append(-1);
                    samplingSegments.append(0);
                    samplingCurveDist.append(1.0 * sampleI);
                }
Henry's avatar
Henry committed
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
            }
        }
    }
}


void Foam::arraySet::genSamples()
{
    // Storage for sample points
    DynamicList<point> samplingPts;
    DynamicList<label> samplingCells;
    DynamicList<label> samplingFaces;
    DynamicList<label> samplingSegments;
    DynamicList<scalar> samplingCurveDist;

    calcSamples
    (
        samplingPts,
        samplingCells,
        samplingFaces,
        samplingSegments,
        samplingCurveDist
    );

    samplingPts.shrink();
    samplingCells.shrink();
    samplingFaces.shrink();
    samplingSegments.shrink();
    samplingCurveDist.shrink();

114
    // Move into *this
Henry's avatar
Henry committed
115 116
    setSamples
    (
117 118 119 120 121
        std::move(samplingPts),
        std::move(samplingCells),
        std::move(samplingFaces),
        std::move(samplingSegments),
        std::move(samplingCurveDist)
Henry's avatar
Henry committed
122
    );
123 124 125 126 127

    if (debug)
    {
        write(Info);
    }
Henry's avatar
Henry committed
128 129 130 131 132 133 134 135 136 137 138
}


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

Foam::arraySet::arraySet
(
    const word& name,
    const polyMesh& mesh,
    const meshSearch& searchEngine,
    const word& axis,
139
    const coordSystem::cartesian& csys,
Henry's avatar
Henry committed
140 141 142 143 144
    const Vector<label>& pointsDensity,
    const Vector<scalar>& spanBox
)
:
    sampledSet(name, mesh, searchEngine, axis),
145
    csys_(csys),
Henry's avatar
Henry committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    pointsDensity_(pointsDensity),
    spanBox_(spanBox)
{
    genSamples();
}


Foam::arraySet::arraySet
(
    const word& name,
    const polyMesh& mesh,
    const meshSearch& searchEngine,
    const dictionary& dict
)
:
    sampledSet(name, mesh, searchEngine, dict),
162
    csys_(dict),  // Note: no indirect cs with this constructor
163 164
    pointsDensity_(dict.get<labelVector>("pointsDensity")),
    spanBox_(dict.get<vector>("spanBox"))
Henry's avatar
Henry committed
165 166 167 168 169 170
{
    genSamples();
}


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