Skip to content
Snippets Groups Projects
Commit b12ee223 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Rewrite MeshGenerators for Line and Quad meshes.

Using ORIGIN and variadic constructors added before.
parent 8fb97b14
No related branches found
No related tags found
No related merge requests found
......@@ -22,66 +22,67 @@
namespace MeshLib
{
Mesh* MeshGenerator::generateLineMesh(const double length, const std::size_t subdivision, const double origin_x, const double origin_y, const double origin_z)
Mesh* MeshGenerator::generateLineMesh(
const double length,
const std::size_t subdivision,
const GeoLib::Point& origin)
{
const double unit_length = length / subdivision;
const std::size_t n_nodes_per_axis = subdivision+1;
const std::size_t n_eles = subdivision;
const double dx = length / subdivision;
//nodes
std::vector<Node*> nodes;
std::size_t node_id(0);
for (std::size_t i_z=0; i_z<n_nodes_per_axis; i_z++) {
const double x = unit_length*i_z;
nodes.push_back(new Node(x+origin_x, origin_y, origin_z, node_id++));
}
//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
std::vector<Element*> elements;
for (std::size_t i_z=0; i_z<n_eles; i_z++) {
Node** e_nodes=new Node*[2];
e_nodes[0] = nodes[i_z];
e_nodes[1] = nodes[i_z+1];
elements.push_back(new Edge(e_nodes));
}
//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);
return new Mesh("mesh", nodes, elements);
}
Mesh* MeshGenerator::generateRegularQuadMesh(const double length, const std::size_t subdivision, const double origin_x, const double origin_y, const double origin_z)
Mesh* MeshGenerator::generateRegularQuadMesh(
const double length,
const std::size_t subdivision,
const GeoLib::Point& origin)
{
const double unit_length = length / subdivision;
const std::size_t n_nodes_per_axis = subdivision+1;
const double dx = length / subdivision;
//nodes
const std::size_t n_nodes = subdivision + 1;
std::vector<Node*> nodes(n_nodes * n_nodes);
//nodes
std::vector<Node*> nodes;
std::size_t node_id(0);
const double z = origin_z;
for (std::size_t j_y=0; j_y<n_nodes_per_axis; j_y++) {
const double y = unit_length*j_y + origin_y;
for (std::size_t k_x=0; k_x<n_nodes_per_axis; k_x++) {
const double x = unit_length*k_x + origin_x;
nodes.push_back(new Node(x, y, z, node_id++));
}
}
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::vector<Element*> elements;
for (std::size_t j=0; j<subdivision; j++) {
const std::size_t offset_y1 = j*n_nodes_per_axis;
const std::size_t offset_y2 = (j+1)*n_nodes_per_axis;
for (std::size_t k=0; k<subdivision; k++) {
Node** e_nodes=new Node*[4];
e_nodes[0] = nodes[offset_y1+k];
e_nodes[1] = nodes[offset_y1+k+1];
e_nodes[2] = nodes[offset_y2+k+1];
e_nodes[3] = nodes[offset_y2+k];
elements.push_back(new Quad(e_nodes));
}
}
//elements
std::size_t const n_eles = subdivision;
std::vector<Element*> elements(n_eles * n_eles);
std::size_t elem_id = 0;
return new Mesh("mesh", nodes, elements);
};
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);
}
}
......@@ -2,7 +2,6 @@
* \file
* \author Norihiro Watanabe
* \date 2012-08-03
* \brief
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
......@@ -15,38 +14,36 @@
#ifndef MESHGENERATOR_H_
#define MESHGENERATOR_H_
#include "GeoLib/Point.h"
#include "MeshLib/Mesh.h"
namespace MeshLib
{
namespace MeshGenerator
{
/**
* generate a line mesh
* Generate an 1D Line-Element mesh. The mesh is generated in x-direction.
*
* \param length
* \param subdivision
* \param origin_x
* \param origin_y
* \param origin_z
* \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, const double origin_x, const double origin_y, const double origin_z);
Mesh* generateLineMesh(const double length,
const std::size_t subdivision,
GeoLib::Point const& origin = GeoLib::ORIGIN);
/**
* generate a regular quad mesh
* Generate a regular 2D Quad-Element mesh. The mesh is generated in the
* x-y-plane.
*
* \param length
* \param subdivision
* \param origin_x
* \param origin_y
* \param origin_z
* \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, const double origin_x, const double origin_y, const double origin_z);
}; //MeshGenerator
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