diff --git a/MeshLib/Elements/Elements.h b/MeshLib/Elements/Elements.h index 7e699cd0e3d99fc155a81f00d01df62c0811a994..b8e8395a370b63d6bd4aacb723c53cfe93d2fc42 100644 --- a/MeshLib/Elements/Elements.h +++ b/MeshLib/Elements/Elements.h @@ -16,6 +16,7 @@ #include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Line.h" #include "MeshLib/Elements/Hex.h" +#include "MeshLib/Elements/Point.h" #include "MeshLib/Elements/Prism.h" #include "MeshLib/Elements/Pyramid.h" #include "MeshLib/Elements/Quad.h" diff --git a/MeshLib/Elements/Point.h b/MeshLib/Elements/Point.h new file mode 100644 index 0000000000000000000000000000000000000000..02d50734c224e0d215e3e731e84ccb8fa128dbc1 --- /dev/null +++ b/MeshLib/Elements/Point.h @@ -0,0 +1,23 @@ +/** + * \copyright + * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef MESHLIB_POINT_H_ +#define MESHLIB_POINT_H_ + +#include "TemplateElement.h" +#include "PointRule1.h" + +extern template class MeshLib::TemplateElement<MeshLib::PointRule1>; + +namespace MeshLib +{ + using Point = TemplateElement<PointRule1>; +} + +#endif // MESHLIB_POINT_H_ diff --git a/MeshLib/Elements/PointRule1.cpp b/MeshLib/Elements/PointRule1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a952320f8f77c4c8d50f6e45143832b727b0a8f --- /dev/null +++ b/MeshLib/Elements/PointRule1.cpp @@ -0,0 +1,47 @@ +/** + * \copyright + * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include "PointRule1.h" + +#include "MathLib/Point3d.h" +#include "MeshLib/Node.h" + +namespace MeshLib { + +const unsigned PointRule1::edge_nodes[1][1] = +{ + {0} +}; + +double PointRule1::computeVolume(Node const* const* _nodes) +{ + return 0; +} + +bool PointRule1::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps) +{ + double const dist = MathLib::sqrDist(*_nodes[0], pnt); + return (dist < eps); +} + +unsigned PointRule1::identifyFace(Node const* const* _nodes, Node* nodes[1]) +{ + if (nodes[0] == _nodes[0]) + return 0; + return std::numeric_limits<unsigned>::max(); +} + +ElementErrorCode PointRule1::validate(const Element* e) +{ + ElementErrorCode error_code; + error_code[ElementErrorFlag::ZeroVolume] = e->hasZeroVolume(); + return error_code; +} + +} // end namespace MeshLib diff --git a/MeshLib/Elements/PointRule1.h b/MeshLib/Elements/PointRule1.h new file mode 100644 index 0000000000000000000000000000000000000000..eb6c63f20d9c09cc7ae7b20ab23fb9a0ff5c6aae --- /dev/null +++ b/MeshLib/Elements/PointRule1.h @@ -0,0 +1,66 @@ +/** + * \copyright + * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef MESHLIB_POINTRULE1_H_ +#define MESHLIB_POINTRULE1_H_ + +#include "MeshLib/MeshEnums.h" +#include "Element.h" +#include "VertexRule.h" +#include "EdgeReturn.h" + +namespace MeshLib +{ + +/// A 0d point element. +class PointRule1 : public VertexRule +{ +public: + /// Constant: The number of base nodes for this element + static const unsigned n_base_nodes = 1u; + + /// Constant: The number of all nodes for this element + static const unsigned n_all_nodes = 1u; + + /// Constant: The geometric type of the element + static const MeshElemType mesh_elem_type = MeshElemType::POINT; + + /// Constant: The FEM type of the element + static const CellType cell_type = CellType::POINT1; + + /// Constant: The number of neighbors + static const unsigned n_neighbors = 2; + + /// Constant: Local node index table for edge + static const unsigned edge_nodes[1][1]; + + /// Edge rule + typedef NoEdgeReturn EdgeReturn; + + /// Checks if a point is inside the element. + /// \param pnt a 3D MathLib::Point3d object + /// \param eps tolerance for numerical algorithm used or computing the + /// property + /// \return true if the point is not outside the element, false otherwise + static bool isPntInElement(Node const* const* _nodes, + MathLib::Point3d const& pnt, double eps); + + /// Tests if the element is geometrically valid. + static ElementErrorCode validate(const Element* e); + + /// Returns the ID of a face given an array of nodes. + static unsigned identifyFace(Node const* const*, Node* nodes[1]); + + /// Calculates the length of a line + static double computeVolume(Node const* const* _nodes); +}; +} + +#endif // MESHLIB_POINTRULE1_H_ + diff --git a/MeshLib/Elements/TemplateElement.cpp b/MeshLib/Elements/TemplateElement.cpp index 0934918e068b02610287e8e907dea8119543751e..dc07468f3d0facf2caced53c4c698134eeb69480 100644 --- a/MeshLib/Elements/TemplateElement.cpp +++ b/MeshLib/Elements/TemplateElement.cpp @@ -10,6 +10,7 @@ #include "TemplateElement.h" #include "MeshLib/Elements/Hex.h" +#include "MeshLib/Elements/Point.h" #include "MeshLib/Elements/Line.h" #include "MeshLib/Elements/Prism.h" #include "MeshLib/Elements/Pyramid.h" @@ -33,6 +34,7 @@ template class MeshLib::TemplateElement<MeshLib::HexRule20>; template class MeshLib::TemplateElement<MeshLib::HexRule8>; template class MeshLib::TemplateElement<MeshLib::LineRule2>; template class MeshLib::TemplateElement<MeshLib::LineRule3>; +template class MeshLib::TemplateElement<MeshLib::PointRule1>; template class MeshLib::TemplateElement<MeshLib::PrismRule15>; template class MeshLib::TemplateElement<MeshLib::PrismRule6>; template class MeshLib::TemplateElement<MeshLib::PyramidRule13>; diff --git a/MeshLib/Elements/VertexRule.h b/MeshLib/Elements/VertexRule.h new file mode 100644 index 0000000000000000000000000000000000000000..79a899172a36d355b153aced7ddcd5ce3c772e85 --- /dev/null +++ b/MeshLib/Elements/VertexRule.h @@ -0,0 +1,51 @@ +/** + * \copyright + * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef MESHLIB_VERTEX_RULE_H +#define MESHLIB_VERTEX_RULE_H + +namespace MeshLib +{ + +class Element; + +class VertexRule +{ +public: + /// Constant: Dimension of this mesh element + static const unsigned dimension = 0u; + + /// Constant: The number of faces + static const unsigned n_faces = 0; + + /// Constant: The number of edges + static const unsigned n_edges = 0; + + /// Get the number of nodes for face i. + static unsigned getNFaceNodes(unsigned /*i*/) + { + return 0; + } + + /// Returns the i-th face of the element. + static const Element* getFace(const Element* /*e*/, unsigned /*i*/) + { + return nullptr; + } + + /// Checks if the node order of an element is correct by testing surface + /// normals. For 0D elements this always returns true. + static bool testElementNodeOrder(const Element* /*e*/) { return true; } + +}; + +} + +#endif // MESHLIB_VERTEX_RULE_H + diff --git a/MeshLib/MeshEnums.cpp b/MeshLib/MeshEnums.cpp index 76320d3646c69161f6791d93e1e47a7f803a0dde..b045cb3262a6577f8b415cacdf40092e96c73015 100644 --- a/MeshLib/MeshEnums.cpp +++ b/MeshLib/MeshEnums.cpp @@ -18,6 +18,8 @@ namespace MeshLib { const std::string MeshElemType2String(const MeshElemType t) { + if (t == MeshElemType::POINT) + return "Point"; if (t == MeshElemType::LINE) return "Line"; if (t == MeshElemType::QUAD) @@ -37,6 +39,8 @@ const std::string MeshElemType2String(const MeshElemType t) const std::string MeshElemType2StringShort(const MeshElemType t) { + if (t == MeshElemType::POINT) + return "point"; if (t == MeshElemType::LINE) return "line"; if (t == MeshElemType::QUAD) @@ -56,6 +60,8 @@ const std::string MeshElemType2StringShort(const MeshElemType t) MeshElemType String2MeshElemType(const std::string &s) { + if ((s.compare("point") == 0) || (s.compare("Point") == 0)) + return MeshElemType::POINT; if ((s.compare("line") == 0) || (s.compare("Line") == 0)) return MeshElemType::LINE; if ((s.compare("quad") == 0) || (s.compare("Quadrilateral") == 0)) @@ -76,6 +82,7 @@ MeshElemType String2MeshElemType(const std::string &s) std::vector<MeshElemType> getMeshElemTypes() { std::vector<MeshElemType> vec; + vec.push_back(MeshElemType::POINT); vec.push_back(MeshElemType::LINE); vec.push_back(MeshElemType::QUAD); vec.push_back(MeshElemType::HEXAHEDRON); @@ -100,6 +107,7 @@ const std::string CellType2String(const CellType t) if (t == CellType::type)\ return #type; + RETURN_CELL_TYPE_STR(t, POINT1); RETURN_CELL_TYPE_STR(t, LINE2); RETURN_CELL_TYPE_STR(t, LINE3); RETURN_CELL_TYPE_STR(t, QUAD4); diff --git a/MeshLib/MeshEnums.h b/MeshLib/MeshEnums.h index 3a08a551d6b7a27f4e66083af60079f51db52fc1..dfa775ef8f49a2a535d17f34202ca9061bb3fce5 100644 --- a/MeshLib/MeshEnums.h +++ b/MeshLib/MeshEnums.h @@ -27,6 +27,7 @@ namespace MeshLib { enum class MeshElemType { INVALID = 0, + POINT = 1, LINE = 3, QUAD = 9, HEXAHEDRON = 12, @@ -42,6 +43,7 @@ enum class MeshElemType enum class CellType { INVALID, + POINT1, LINE2, LINE3, TRI3,