以下のMWEを参照すると、Point
とCell
を含むMesh
があります。今度はMETISでメッシュを2つに分割し、2つの新しいメッシュを作成したいと思います。メッシュ内の循環ポインタの方向を考慮すると、新しいメッシュのポイントとセルのポインタを新しいアドレスに簡単に更新できますか?コピー後のポインタのアドレスを更新する
#include <iostream>
#include <vector>
struct Point;
struct Cell;
struct Mesh
{
std::vector<Point> point;
std::vector<Cell> cell;
};
struct Point
{
Cell* parent_cell;
int partition;
};
struct Cell
{
std::vector<Point*> vertex;
int partition;
};
int main()
{
Mesh mesh;
mesh.cell.resize(2); // create two triangles.
mesh.point.resize(4); // 4 points instead of 6 because two of them will be shared.
// let vertices know their parent cell.
mesh.point[0].parent_cell = &mesh.cell[0];
mesh.point[1].parent_cell = &mesh.cell[0]; mesh.point[1].parent_cell = &mesh.cell[1];
mesh.point[2].parent_cell = &mesh.cell[0]; mesh.point[2].parent_cell = &mesh.cell[1];
mesh.point[3].parent_cell = &mesh.cell[1];
// let cells know their vertices.
mesh.cell[0].vertex.push_back(&mesh.point[0]);
mesh.cell[0].vertex.push_back(&mesh.point[1]);
mesh.cell[0].vertex.push_back(&mesh.point[2]);
mesh.cell[1].vertex.push_back(&mesh.point[1]);
mesh.cell[1].vertex.push_back(&mesh.point[2]);
mesh.cell[1].vertex.push_back(&mesh.point[3]);
// partition mesh into two.
// give partition number to points.
// all but one of the vertices belong to partition 0.
mesh.point[0].partition = 0;
mesh.point[1].partition = 0;
mesh.point[2].partition = 0;
mesh.point[3].partition = 1; // only this vertex belongs to partition 1.
// give partition number to cells.
mesh.cell[0].partition = 0;
mesh.cell[1].partition = 1;
// create two new meshes.
// filter points and cells according to partition number.
// but how to update pointers?
return 0;
}