Face.h 6.37 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
////////////////////////////////////////////////////////////////////////////////
//
//  File: Face.h
//
//  For more information, please see: http://www.nektar.info/
//
//  The MIT License
//
//  Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
//  Department of Aeronautics, Imperial College London (UK), and Scientific
//  Computing and Imaging Institute, University of Utah (USA).
//
//  License for the specific language governing rights and limitations under
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included
//  in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
//  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
Michael Turner's avatar
Michael Turner committed
32
//  Description: Mesh face object.
33 34 35
//
////////////////////////////////////////////////////////////////////////////////

Michael Turner's avatar
Michael Turner committed
36 37 38
#ifndef NEKMESHUTILS_MESHELEMENTS_FACE
#define NEKMESHUTILS_MESHELEMENTS_FACE

39 40 41
#include <SpatialDomains/TriGeom.h>
#include <SpatialDomains/QuadGeom.h>

Michael Turner's avatar
Michael Turner committed
42
#include <NekMeshUtils/NekMeshUtilsDeclspec.h>
43
#include <NekMeshUtils/MeshElements/Edge.h>
44
#include <NekMeshUtils/MeshElements/Node.h>
45 46 47

namespace Nektar
{
48
namespace NekMeshUtils
49
{
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

class Element;
typedef boost::shared_ptr<Element> ElementSharedPtr;

/**
 * @brief Represents a face comprised of three or more edges.
 *
 * A face is defined by a list of vertices, a list of edges joining
 * these vertices, and a list of control nodes within the interior of
 * the face, defining the shape of the face.
 */
class Face
{
public:
    /// Create a new face.
Michael Turner's avatar
Michael Turner committed
65 66 67 68 69
    NEKMESHUTILS_EXPORT Face(std::vector<NodeSharedPtr> pVertexList,
                             std::vector<NodeSharedPtr> pFaceNodes,
                             std::vector<EdgeSharedPtr> pEdgeList,
                              LibUtilities::PointsType pCurveType)
                : m_vertexList(pVertexList), m_edgeList(pEdgeList),
70 71 72
                  m_faceNodes(pFaceNodes), m_curveType(pCurveType), m_geom()
    {
    }
73 74

    /// Copy an existing face.
Michael Turner's avatar
Michael Turner committed
75
    NEKMESHUTILS_EXPORT Face(const Face &pSrc)
76 77 78 79 80 81
        : m_id(pSrc.m_id), m_vertexList(pSrc.m_vertexList),
          m_edgeList(pSrc.m_edgeList), m_faceNodes(pSrc.m_faceNodes),
          m_curveType(pSrc.m_curveType), m_geom(pSrc.m_geom),
          m_parentCAD(pSrc.m_parentCAD)
    {
    }
Michael Turner's avatar
Michael Turner committed
82

Michael Turner's avatar
Michael Turner committed
83
    NEKMESHUTILS_EXPORT ~Face()
84 85 86 87
    {
    }

    /// Equality is defined by matching all vertices.
Michael Turner's avatar
Michael Turner committed
88
    NEKMESHUTILS_EXPORT bool operator==(Face &pSrc)
89 90 91
    {
        std::vector<NodeSharedPtr>::iterator it1, it2;
        for (it1 = m_vertexList.begin(); it1 != m_vertexList.end(); ++it1)
92
        {
93 94 95
            if (find(pSrc.m_vertexList.begin(),
                     pSrc.m_vertexList.end(),
                     *it1) == pSrc.m_vertexList.end())
96
            {
97
                return false;
98 99
            }
        }
100 101
        return true;
    }
102

103 104
    /// Returns the total number of nodes (vertices, edge nodes and
    /// face nodes).
Michael Turner's avatar
Michael Turner committed
105
    NEKMESHUTILS_EXPORT unsigned int GetNodeCount() const
106 107 108
    {
        unsigned int n = m_faceNodes.size();
        for (int i = 0; i < m_edgeList.size(); ++i)
109
        {
110
            n += m_edgeList[i]->GetNodeCount();
111
        }
112 113 114
        n -= m_vertexList.size();
        return n;
    }
115

116
    /// Assemble a list of nodes on curved face
117
    NEKMESHUTILS_EXPORT void GetCurvedNodes(
118
        std::vector<NodeSharedPtr> &nodeList);
119 120 121

    /// Generates a string listing the coordinates of all nodes
    /// associated with this face.
122
    NEKMESHUTILS_EXPORT std::string GetXmlCurveString();
123

124
    /// Make this face an order @p order face. @see Element::MakeOrder.
125 126 127 128
    void MakeOrder(int                                order,
                   SpatialDomains::GeometrySharedPtr  geom,
                   LibUtilities::PointsType           pType,
                   int                                coordDim,
129
                   int                               &id);
130

131 132
    /// Generate either SpatialDomains::TriGeom or
    /// SpatialDomains::QuadGeom for this element.
133
    NEKMESHUTILS_EXPORT SpatialDomains::Geometry2DSharedPtr GetGeom(int coordDim);
134 135 136 137 138 139 140 141 142 143 144 145

    /// ID of the face.
    unsigned int                         m_id;
    /// List of vertex nodes.
    std::vector<NodeSharedPtr>           m_vertexList;
    /// List of corresponding edges.
    std::vector<EdgeSharedPtr>           m_edgeList;
    /// List of face-interior nodes defining the shape of the face.
    std::vector<NodeSharedPtr>           m_faceNodes;
    /// Distribution of points in this face.
    LibUtilities::PointsType             m_curveType;
    /// Element(s) which are linked to this face.
146
    std::vector<std::pair<ElementSharedPtr, int> > m_elLink;
147 148
    /// Nektar++ representation of geometry
    SpatialDomains::Geometry2DSharedPtr  m_geom;
149

Michael Turner's avatar
Michael Turner committed
150
    CADObjectSharedPtr m_parentCAD;
151
};
Michael Turner's avatar
Michael Turner committed
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166
typedef boost::shared_ptr<Face> FaceSharedPtr;

NEKMESHUTILS_EXPORT bool operator==(FaceSharedPtr const &p1,
                                    FaceSharedPtr const &p2);
NEKMESHUTILS_EXPORT bool operator<(FaceSharedPtr const &p1,
                                   FaceSharedPtr const &p2);

struct FaceHash : std::unary_function<FaceSharedPtr, std::size_t>
{
    std::size_t operator()(FaceSharedPtr const &p) const
    {
        unsigned int nVert = p->m_vertexList.size();
        std::size_t seed = 0;
        std::vector<unsigned int> ids(nVert);
167

168 169 170
        for (int i = 0; i < nVert; ++i)
        {
            ids[i] = p->m_vertexList[i]->m_id;
171 172
        }

173 174 175 176 177 178 179
        std::sort(ids.begin(), ids.end());
        boost::hash_range(seed, ids.begin(), ids.end());

        return seed;
    }
};
typedef boost::unordered_set<FaceSharedPtr, FaceHash> FaceSet;
Michael Turner's avatar
Michael Turner committed
180

181 182 183 184
}
}

#endif