Skip to content
Snippets Groups Projects
Commit 918efd50 authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge pull request #96 from endJunction/MeshGenerators

Mesh generators
parents 4c3e1ac4 b12ee223
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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);
......
......@@ -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) :
......
......@@ -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);
......
......@@ -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)
......
/**
* \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);
}
}
/**
* \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_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment