Edge.h 5.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
////////////////////////////////////////////////////////////////////////////////
//
//  File: Edge.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 Edge.
33 34 35
//
////////////////////////////////////////////////////////////////////////////////

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

39 40
#include <SpatialDomains/SegGeom.h>

Michael Turner's avatar
Michael Turner committed
41
#include <NekMeshUtils/NekMeshUtilsDeclspec.h>
42
#include <NekMeshUtils/MeshElements/Node.h>
Michael Turner's avatar
Michael Turner committed
43

44 45
namespace Nektar
{
46
namespace NekMeshUtils
47
{
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

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

/**
 * @brief Represents an edge which joins two points.
 *
 * An edge is defined by two nodes (vertices) and, for high-order edges,
 * a set of control nodes defining the shape of the edge.
 */
class Edge
{
public:
    /// Creates a new edge.
    NEKMESHUTILS_EXPORT Edge(NodeSharedPtr              pVertex1,
                             NodeSharedPtr              pVertex2,
                             std::vector<NodeSharedPtr> pEdgeNodes,
                             LibUtilities::PointsType   pCurveType)
        : m_n1(pVertex1), m_n2(pVertex2), m_edgeNodes(pEdgeNodes),
67
          m_curveType(pCurveType), m_geom(){}
68 69 70 71

    /// Creates a new linear edge.
    NEKMESHUTILS_EXPORT Edge(NodeSharedPtr pVertex1, NodeSharedPtr pVertex2)
        : m_n1(pVertex1), m_n2(pVertex2), m_edgeNodes(), m_curveType(), m_geom()
72
    {}
73 74 75

    /// Copies an existing edge.
    NEKMESHUTILS_EXPORT Edge(const Edge &pSrc)
76 77 78
        : m_id(pSrc.m_id), m_n1(pSrc.m_n1), m_n2(pSrc.m_n2),
          m_edgeNodes(pSrc.m_edgeNodes), m_curveType(pSrc.m_curveType),
          m_elLink(pSrc.m_elLink), m_parentCAD(pSrc.m_parentCAD)
79 80
    {
    }
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    NEKMESHUTILS_EXPORT ~Edge()
    {
    }

    /// Returns the total number of nodes defining the edge.
    NEKMESHUTILS_EXPORT unsigned int GetNodeCount() const
    {
        return m_edgeNodes.size() + 2;
    }

    NEKMESHUTILS_EXPORT void GetCurvedNodes(
        std::vector<NodeSharedPtr> &nodeList) const
    {
        nodeList.push_back(m_n1);
        for (int k = 0; k < m_edgeNodes.size(); ++k)
Michael Turner's avatar
Michael Turner committed
97
        {
98
            nodeList.push_back(m_edgeNodes[k]);
Michael Turner's avatar
Michael Turner committed
99
        }
100 101
        nodeList.push_back(m_n2);
    }
Michael Turner's avatar
Michael Turner committed
102

103 104
    /// Creates a Nektar++ string listing the coordinates of all the
    /// nodes.
105
    NEKMESHUTILS_EXPORT std::string GetXmlCurveString();
Michael Turner's avatar
Michael Turner committed
106

107
    /// Generate a SpatialDomains::SegGeom object for this edge.
108
    NEKMESHUTILS_EXPORT SpatialDomains::SegGeomSharedPtr GetGeom(int coordDim);
109

110
    /// Make this edge an order @p order edge. @see Element::MakeOrder.
111 112 113 114
    void MakeOrder(int                                order,
                   SpatialDomains::GeometrySharedPtr  geom,
                   LibUtilities::PointsType           edgeType,
                   int                                coordDim,
115
                   int                               &id);
116

117 118 119 120 121 122 123 124 125 126 127
    /// ID of edge.
    unsigned int m_id;
    /// First vertex node.
    NodeSharedPtr m_n1;
    /// Second vertex node.
    NodeSharedPtr m_n2;
    /// List of control nodes between the first and second vertices.
    std::vector<NodeSharedPtr> m_edgeNodes;
    /// Distributions of points along edge.
    LibUtilities::PointsType m_curveType;
    /// Element(s) which are linked to this edge.
128
    std::vector<std::pair<ElementSharedPtr, int> > m_elLink;
129

Michael Turner's avatar
Michael Turner committed
130
    CADObjectSharedPtr m_parentCAD;
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
private:
    SpatialDomains::SegGeomSharedPtr m_geom;
};
/// Shared pointer to an edge.
typedef boost::shared_ptr<Edge> EdgeSharedPtr;

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

/**
 * @brief Defines a hash function for edges.
 *
 * The hash of an edge is defined using the IDs of the two nodes which
 * define it. First the minimum ID is hashed, then the maximum
 * ID, which takes the two possible orientations into account.
 */
struct EdgeHash : std::unary_function<EdgeSharedPtr, std::size_t>
{
    std::size_t operator()(EdgeSharedPtr const &p) const
153
    {
154 155 156 157 158 159 160 161 162
        std::size_t seed = 0;
        unsigned int id1 = p->m_n1->m_id;
        unsigned int id2 = p->m_n2->m_id;
        boost::hash_combine(seed, id1 < id2 ? id1 : id2);
        boost::hash_combine(seed, id2 < id1 ? id1 : id2);
        return seed;
    }
};
typedef boost::unordered_set<EdgeSharedPtr, EdgeHash> EdgeSet;
163 164 165 166
}
}

#endif