Skip to content
Snippets Groups Projects
primitiveMeshPointCells.C 4.59 KiB
Newer Older
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
    Copyright (C) 2011-2016 OpenFOAM Foundation
-------------------------------------------------------------------------------
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 "primitiveMesh.H"
#include "cell.H"

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

Mark Olesen's avatar
Mark Olesen committed
void Foam::primitiveMesh::calcPointCells() const
{
    // Loop through cells and mark up points

    if (debug)
    {
        Pout<< "primitiveMesh::calcPointCells() : "
            << "calculating pointCells"
            << endl;
mattijs's avatar
mattijs committed

        if (debug == -1)
        {
            // For checking calls:abort so we can quickly hunt down
            // origin of call
mattijs's avatar
mattijs committed
                << abort(FatalError);
        }
    }

    // It is an error to attempt to recalculate pointCells
    // if the pointer is already set
    if (pcPtr_)
    {
            << "pointCells already calculated"
            << abort(FatalError);
    }
    else
    {
        const cellList& cf = cells();

        // Count number of cells per point

        labelList npc(nPoints(), Zero);
            const labelList curPoints = cf[celli].labels(faces());

                npc[ptI]++;
            }
        }


        // Size and fill cells per point

        pcPtr_ = new labelListList(npc.size());
        labelListList& pointCellAddr = *pcPtr_;

            pointCellAddr[pointi].setSize(npc[pointi]);
            const labelList curPoints = cf[celli].labels(faces());
                pointCellAddr[ptI][npc[ptI]++] = celli;
            }
        }
    }
}


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

Mark Olesen's avatar
Mark Olesen committed
const Foam::labelListList& Foam::primitiveMesh::pointCells() const
Mark Olesen's avatar
Mark Olesen committed
const Foam::labelList& Foam::primitiveMesh::pointCells
mattijs's avatar
mattijs committed
(
mattijs's avatar
mattijs committed
    DynamicList<label>& storage
) const
mattijs's avatar
mattijs committed
{
    if (hasPointCells())
    {
mattijs's avatar
mattijs committed
    }
    else
    {
        const labelList& own = faceOwner();
        const labelList& nei = faceNeighbour();
        const labelList& pFaces = pointFaces()[pointi];
mattijs's avatar
mattijs committed

mattijs's avatar
mattijs committed
        storage.clear();
mattijs's avatar
mattijs committed

        forAll(pFaces, i)
        {
            const label facei = pFaces[i];
mattijs's avatar
mattijs committed

            // Append owner
            storage.append(own[facei]);
mattijs's avatar
mattijs committed

            // Append neighbour
            if (facei < nInternalFaces())
mattijs's avatar
mattijs committed
            {
                storage.append(nei[facei]);
mattijs's avatar
mattijs committed
            }
        }

        // Filter duplicates
Mark Olesen's avatar
Mark Olesen committed
        if (storage.size() > 1)
mattijs's avatar
mattijs committed
        {
Mark Olesen's avatar
Mark Olesen committed
            sort(storage);

            label n = 1;
            for (label i = 1; i < storage.size(); i++)
mattijs's avatar
mattijs committed
            {
Mark Olesen's avatar
Mark Olesen committed
                if (storage[i-1] != storage[i])
                {
                    storage[n++] = storage[i];
                }
mattijs's avatar
mattijs committed
            }

Mark Olesen's avatar
Mark Olesen committed
            // truncate addressed list
            storage.setSize(n);
        }
mattijs's avatar
mattijs committed

mattijs's avatar
mattijs committed
        return storage;
const Foam::labelList& Foam::primitiveMesh::pointCells(const label pointi) const
mattijs's avatar
mattijs committed
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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