Skip to content
Snippets Groups Projects
Commit b65ad8c1 authored by Karsten Rink's avatar Karsten Rink
Browse files

added possible signature and allowing for different number of rows and columns

parent bb346cf3
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* http://www.opengeosys.org/project/license * http://www.opengeosys.org/project/license
* *
*/ */
#include "MeshGenerators\MeshGenerator.h"
#include "Configure.h" #include "Configure.h"
#include "mainwindow.h" #include "mainwindow.h"
...@@ -1284,6 +1285,8 @@ void MainWindow::showDataExplorerSettingsDialog() ...@@ -1284,6 +1285,8 @@ void MainWindow::showDataExplorerSettingsDialog()
void MainWindow::FEMTestStart() void MainWindow::FEMTestStart()
{ {
_meshModels->addMesh( MeshLib::MeshGenerator::generateRegularQuadMesh(10, 10) );
} }
......
...@@ -55,43 +55,49 @@ Mesh* MeshGenerator::generateRegularQuadMesh( ...@@ -55,43 +55,49 @@ Mesh* MeshGenerator::generateRegularQuadMesh(
const std::size_t subdivision, const std::size_t subdivision,
const GeoLib::Point& origin) const GeoLib::Point& origin)
{ {
const double dx = length / subdivision; return generateRegularQuadMesh(subdivision, subdivision, length/subdivision, origin);
}
Mesh* MeshGenerator::generateRegularQuadMesh(const unsigned n_x_cells,
const unsigned n_y_cells,
const double cell_size,
GeoLib::Point const& origin,
std::string const& mesh_name)
{
//nodes //nodes
const std::size_t n_nodes = subdivision + 1; const unsigned n_x_nodes (n_x_cells+1);
std::vector<Node*> nodes(n_nodes * n_nodes); const unsigned n_y_nodes (n_y_cells+1);
std::vector<Node*> nodes;
nodes.reserve(n_x_nodes * n_y_nodes);
for (std::size_t i = 0, node_id = 0; i < n_nodes; i++) for (std::size_t i = 0, node_id = 0; i < n_y_nodes; i++)
for (std::size_t j = 0; j < n_nodes; j++) {
{ const double x_offset (origin[0] + cell_size * i);
nodes[node_id] = new Node(origin[0] + dx * j, for (std::size_t j = 0; j < n_x_nodes; j++)
origin[1] + dx * i, nodes.push_back (new Node(origin[1] + cell_size * j, x_offset, origin[2]));
origin[2], }
node_id);
node_id++;
}
//elements //elements
std::size_t const n_eles = subdivision; std::vector<Element*> elements;
std::vector<Element*> elements(n_eles * n_eles); elements.reserve(n_x_cells * n_y_cells);
std::size_t elem_id = 0;
for (std::size_t j = 0; j < subdivision; j++) for (std::size_t j = 0; j < n_y_cells; j++)
{ {
const std::size_t offset_y1 = j * n_nodes; const std::size_t offset_y1 = j * n_x_nodes;
const std::size_t offset_y2 = (j + 1) * n_nodes; const std::size_t offset_y2 = (j + 1) * n_x_nodes;
for (std::size_t k = 0; k < subdivision; k++) for (std::size_t k = 0; k < n_x_cells; k++)
{ {
std::array<Node*, 4> element_nodes; std::array<Node*, 4> element_nodes;
element_nodes[0] = nodes[offset_y1 + k]; element_nodes[0] = nodes[offset_y1 + k];
element_nodes[1] = nodes[offset_y1 + k + 1]; element_nodes[1] = nodes[offset_y1 + k + 1];
element_nodes[2] = nodes[offset_y2 + k + 1]; element_nodes[2] = nodes[offset_y2 + k + 1];
element_nodes[3] = nodes[offset_y2 + k]; element_nodes[3] = nodes[offset_y2 + k];
elements[elem_id++] = new Quad(element_nodes); elements.push_back (new Quad(element_nodes));
} }
} }
return new Mesh("mesh", nodes, elements); return new Mesh(mesh_name, nodes, elements);
} }
Mesh* MeshGenerator::generateRegularHexMesh( Mesh* MeshGenerator::generateRegularHexMesh(
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#ifndef MESHGENERATOR_H_ #ifndef MESHGENERATOR_H_
#define MESHGENERATOR_H_ #define MESHGENERATOR_H_
#include <string>
#include "GeoLib/Point.h" #include "GeoLib/Point.h"
#include "MeshLib/Mesh.h" #include "MeshLib/Mesh.h"
...@@ -26,7 +28,7 @@ namespace MeshGenerator ...@@ -26,7 +28,7 @@ namespace MeshGenerator
* *
* \param length Mesh's length in x-direction. * \param length Mesh's length in x-direction.
* \param subdivision Number of subdivisions. * \param subdivision Number of subdivisions.
* \param origin Optional mesh's origin (the most left point) with GeoLib::ORIGIN default. * \param origin Optional mesh's origin (the left-most point) with GeoLib::ORIGIN default.
*/ */
Mesh* generateLineMesh(const double length, Mesh* generateLineMesh(const double length,
const std::size_t subdivision, const std::size_t subdivision,
...@@ -44,6 +46,21 @@ Mesh* generateRegularQuadMesh(const double length, ...@@ -44,6 +46,21 @@ Mesh* generateRegularQuadMesh(const double length,
const std::size_t subdivision, const std::size_t subdivision,
GeoLib::Point const& origin = GeoLib::ORIGIN); GeoLib::Point const& origin = GeoLib::ORIGIN);
/**
* Generate a regular 2D Quad-Element mesh. The mesh is generated in the
* x-y-plane.
*
* \param n_x_cells Number of cells in x-direction.
* \param n_y_cells Number of cells in y-direction.
* \param cell_size Edge length of Quad elements
* \param origin Optional mesh's origin (the lower left corner) with GeoLib::ORIGIN default.
*/
Mesh* generateRegularQuadMesh(const unsigned n_x_cells,
const unsigned n_y_cells,
const double cell_size,
GeoLib::Point const& origin = GeoLib::ORIGIN,
std::string const& mesh_name = "mesh");
/** /**
* Generate a regular 3D Hex-Element mesh. * Generate a regular 3D Hex-Element mesh.
* *
...@@ -54,6 +71,23 @@ Mesh* generateRegularQuadMesh(const double length, ...@@ -54,6 +71,23 @@ Mesh* generateRegularQuadMesh(const double length,
Mesh* generateRegularHexMesh(const double length, Mesh* generateRegularHexMesh(const double length,
const std::size_t subdivision, const std::size_t subdivision,
GeoLib::Point const& origin = GeoLib::ORIGIN); GeoLib::Point const& origin = GeoLib::ORIGIN);
/**
* Generate a regular 3D Hex-Element mesh.
*
* \param n_x_cells Number of cells in x-direction.
* \param n_y_cells Number of cells in y-direction.
* \param n_z_cells Number of cells in z-direction.
* \param cell_size Edge length of Hex elements
* \param origin Optional mesh's origin (the lower left corner) with GeoLib::ORIGIN default.
*/
Mesh* generateRegularQuadMesh(const unsigned n_x_cells,
const unsigned n_y_cells,
const unsigned n_z_cells,
const double cell_size,
GeoLib::Point const& origin = GeoLib::ORIGIN);
} //MeshGenerator } //MeshGenerator
} //MeshLib } //MeshLib
......
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