diff --git a/GeoLib/Point.h b/GeoLib/Point.h index 47fce4f94a9a1504807c276a23ce5afc74429203..91e9b1d035084b75a06da8d9a34d9b7f95d68a02 100644 --- a/GeoLib/Point.h +++ b/GeoLib/Point.h @@ -48,6 +48,8 @@ public: typedef GeoLib::GeoPoint<double> Point; +static const Point ORIGIN(0, 0, 0); + /** * lexicographic comparison of points */ @@ -58,7 +60,7 @@ bool operator<= (GeoLib::Point const & p0, GeoLib::Point const & p1); * @param p0 first input Point * @param p1 first input Point * @param tol tolerance (if in the comparison operation the property fabs(p0[k] - p1[k]) < tol - * holds for the k-th coordinate the points are assumed the be equal in this coordinate) + * holds for the k-th coordinate the points are assumed the be equal in this coordinate) * @return true, if p0 is lexicographically smaller than p1 */ bool lessEq(const GeoLib::Point& p0, diff --git a/MeshLib/Elements/TemplateEdge.h b/MeshLib/Elements/TemplateEdge.h index c4662ff019c8f6ec4acf23ad54ab4015fdfcf0ae..0a6d35265d9f7c554a5ee46d06dac9f5bda7d327 100644 --- a/MeshLib/Elements/TemplateEdge.h +++ b/MeshLib/Elements/TemplateEdge.h @@ -15,6 +15,7 @@ #ifndef TEMPLATEEDGE_H_ #define TEMPLATEEDGE_H_ +#include <array> #include <limits> #include "MshEnums.h" @@ -39,6 +40,9 @@ public: /// Constructor with an array of mesh nodes. TemplateEdge(Node* nodes[NNODES], unsigned value = 0); + /// Constructs an edge from array of Node pointers. + TemplateEdge(std::array<Node*, NNODES> const& nodes, unsigned value = 0); + /// Copy constructor TemplateEdge(const TemplateEdge &edge); diff --git a/MeshLib/Elements/TemplateEdge.tpp b/MeshLib/Elements/TemplateEdge.tpp index 1fe174047bcf2824685445d021fbff2ecbc0b7aa..0b31fed5de5819eb281bdaf4e9c842380e092430 100644 --- a/MeshLib/Elements/TemplateEdge.tpp +++ b/MeshLib/Elements/TemplateEdge.tpp @@ -12,7 +12,18 @@ * */ -namespace MeshLib { +namespace MeshLib +{ +template<unsigned NNODES, CellType::type CELLEDGETYPE> +TemplateEdge<NNODES,CELLEDGETYPE>::TemplateEdge(std::array<Node*, NNODES> const& nodes, + unsigned value) + : Element(value) +{ + _nodes = new Node*[NNODES]; + std::copy(nodes.begin(), nodes.end(), _nodes); + + this->_length = this->computeVolume(); +} template<unsigned NNODES, CellType::type CELLEDGETYPE> TemplateEdge<NNODES,CELLEDGETYPE>::TemplateEdge(Node* nodes[NNODES], unsigned value) : diff --git a/MeshLib/Elements/TemplateQuad.h b/MeshLib/Elements/TemplateQuad.h index 6e1e5320a5b778b7b90923f7e66248ed420b46d2..528fd5ea52ec65b0843dedf27ed79ae663a8b82a 100644 --- a/MeshLib/Elements/TemplateQuad.h +++ b/MeshLib/Elements/TemplateQuad.h @@ -42,6 +42,13 @@ public: /// Constructor with an array of mesh nodes. TemplateQuad(Node* nodes[NNODES], unsigned value = 0); + /// Constructs an edge from array of Node pointers. + TemplateQuad(std::array<Node*, NNODES> const& nodes, unsigned value = 0); + + /// Constructs a quad from NNODES of Nodes initializing Face with + // value = 0. + TemplateQuad(Node* n0, Node* n1, Node* n2, Node* n3, ...); + /// Copy constructor TemplateQuad(const TemplateQuad &quad); diff --git a/MeshLib/Elements/TemplateQuad.tpp b/MeshLib/Elements/TemplateQuad.tpp index e79a85a2d87eaee9e7ffbd7077b7bbcc4cf5ba4f..fcd938744c5eb6dff8c2af6052363464539dad4e 100644 --- a/MeshLib/Elements/TemplateQuad.tpp +++ b/MeshLib/Elements/TemplateQuad.tpp @@ -12,6 +12,8 @@ * */ +#include <array> + #include "Node.h" #include "Tri.h" @@ -19,7 +21,21 @@ #include "MathTools.h" #include "AnalyticalGeometry.h" -namespace MeshLib { +namespace MeshLib +{ +template<unsigned NNODES, CellType::type CELLQUADTYPE> +TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(std::array<Node*, NNODES> const& nodes, + unsigned value) + : Face(value) +{ + _nodes = new Node*[NNODES]; + std::copy(nodes.begin(), nodes.end(), _nodes); + + _neighbors = new Element*[4]; + std::fill(_neighbors, _neighbors + 4, nullptr); + + this->_area = this->computeVolume(); +} template <unsigned NNODES, CellType::type CELLQUADTYPE> TemplateQuad<NNODES,CELLQUADTYPE>::TemplateQuad(Node* nodes[NNODES], unsigned value) diff --git a/MeshLib/MeshGenerator.cpp b/MeshLib/MeshGenerator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ae98a6f72b13f8a6e6e02688f51b3d1d157681e --- /dev/null +++ b/MeshLib/MeshGenerator.cpp @@ -0,0 +1,88 @@ +/** + * \file + * \author Norihiro Watanabe + * \date 2012-08-03 + * \brief + * + * \copyright + * Copyright (c) 2013, 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 "MeshGenerator.h" +#include "Node.h" + +#include "Elements/Edge.h" +#include "Elements/Quad.h" + +#include <vector> + +namespace MeshLib +{ +Mesh* MeshGenerator::generateLineMesh( + const double length, + const std::size_t subdivision, + const GeoLib::Point& origin) +{ + const double dx = length / subdivision; + + //nodes + const std::size_t n_nodes = subdivision + 1; + std::vector<Node*> nodes(n_nodes); + for (std::size_t i = 0; i < n_nodes; i++) + nodes[i] = new Node(origin[0] + dx * i, origin[1], origin[2], i); + + //elements + const std::size_t n_eles = subdivision; + std::vector<Element*> elements(n_eles); + for (std::size_t i = 0; i < n_eles; i++) + elements[i] = new Edge({{ nodes[i], nodes[i + 1] }}); + + return new Mesh("mesh", nodes, elements); +} + +Mesh* MeshGenerator::generateRegularQuadMesh( + const double length, + const std::size_t subdivision, + const GeoLib::Point& origin) +{ + const double dx = length / subdivision; + + //nodes + const std::size_t n_nodes = subdivision + 1; + std::vector<Node*> nodes(n_nodes * n_nodes); + + for (std::size_t i = 0, node_id = 0; i < n_nodes; i++) + for (std::size_t j = 0; j < n_nodes; j++) + { + nodes[node_id] = new Node(origin[0] + dx * j, + origin[1] + dx * i, + origin[2], + node_id); + node_id++; + } + + //elements + std::size_t const n_eles = subdivision; + std::vector<Element*> elements(n_eles * n_eles); + std::size_t elem_id = 0; + + for (std::size_t j = 0; j < subdivision; j++) + { + const std::size_t offset_y1 = j * n_nodes; + const std::size_t offset_y2 = (j + 1) * n_nodes; + for (std::size_t k = 0; k < subdivision; k++) + { + elements[elem_id++] = new Quad({{ nodes[offset_y1 + k], + nodes[offset_y1 + k + 1], + nodes[offset_y2 + k + 1], + nodes[offset_y2 + k]}}); + } + } + + return new Mesh("mesh", nodes, elements); +} +} diff --git a/MeshLib/MeshGenerator.h b/MeshLib/MeshGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..8a193c175d624d1149cc7f439d799fa69fec5e8e --- /dev/null +++ b/MeshLib/MeshGenerator.h @@ -0,0 +1,49 @@ +/** + * \file + * \author Norihiro Watanabe + * \date 2012-08-03 + * + * \copyright + * Copyright (c) 2013, 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 MESHGENERATOR_H_ +#define MESHGENERATOR_H_ + +#include "GeoLib/Point.h" +#include "MeshLib/Mesh.h" + +namespace MeshLib +{ +namespace MeshGenerator +{ +/** + * Generate an 1D Line-Element mesh. The mesh is generated in x-direction. + * + * \param length Mesh's length in x-direction. + * \param subdivision Number of subdivisions. + * \param origin Optional mesh's origin with GeoLib::ORIGIN default. + */ +Mesh* generateLineMesh(const double length, + const std::size_t subdivision, + GeoLib::Point const& origin = GeoLib::ORIGIN); + +/** + * Generate a regular 2D Quad-Element mesh. The mesh is generated in the + * x-y-plane. + * + * \param length Mesh's dimensions in x- and y-directions. + * \param subdivision Number of subdivisions. + * \param origin Optional mesh's origin with GeoLib::ORIGIN default. + */ +Mesh* generateRegularQuadMesh(const double length, + const std::size_t subdivision, + GeoLib::Point const& origin = GeoLib::ORIGIN); +} //MeshGenerator +} //MeshLib + +#endif //MESHGENERATOR_H_