使用 NetGen 创建简单的网格

问题描述 投票:0回答:1

我正在尝试使用 NetGen 手动创建网格,但在进入

Ng_GenerateVolumeMesh
时出现访问冲突异常。这是我使用的 C++ 代码:

namespace nglib {
#include <nglib.h>
}

int main() {
    using namespace nglib;

    // NetGen initialization
    Ng_Init();

    // Creating Ng_Mesh object
    Ng_Mesh* mesh = Ng_NewMesh();

    // Adding vertices to the mesh
    double v0[] = { 0, 0, 0 };
    double v1[] = { 1, 0, 0 };
    double v2[] = { 1, 1, 0 };
    double v3[] = { 0, 1, 0 };
    double v00[] = { 0, 0, 1 };
    double v10[] = { 1, 0, 1 };
    double v20[] = { 1, 1, 1 };
    double v30[] = { 0, 1, 1 };
    Ng_AddPoint(mesh, v0);
    Ng_AddPoint(mesh, v1);
    Ng_AddPoint(mesh, v2);
    Ng_AddPoint(mesh, v3);
    Ng_AddPoint(mesh, v00);
    Ng_AddPoint(mesh, v10);
    Ng_AddPoint(mesh, v20);
    Ng_AddPoint(mesh, v30);

    // Creating faces (triangles)
    int trig0[] = { 0, 3, 2};
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig0);
    int trig1[] = { 0, 2, 1 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig1);

    int trig2[] = { 0, 5, 4 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig2);
    int trig3[] = { 0, 1, 5 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig3);

    int trig4[] = { 1, 6, 5 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig4);
    int trig5[] = { 1, 2, 6 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig5);

    int trig6[] = { 2, 7, 6 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig6);
    int trig7[] = { 2, 3, 7 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig7);

    int trig8[] = { 3, 4, 7 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig8);
    int trig9[] = { 3, 0, 4 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig9);

    int trig10[] = { 4, 6, 7 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig10);
    int trig11[] = { 4, 5, 6 };
    Ng_AddSurfaceElement(mesh, NG_TRIG, trig11);

    // Meshing options
    Ng_Meshing_Parameters mp;
    mp.maxh = .1;
    mp.second_order = 1;

    // Mesh generation
    Ng_Result res = Ng_GenerateVolumeMesh(mesh, &mp);

    // Shutdown
    Ng_Exit();

    return 0;
}

我已经从源代码构建了该库。 https://github.com/NGSolve/ngsolve.git 提交日期 2024 年 4 月 3 日星期三 09:16:29。

例外情况是(抱歉,这是意大利语):

TestNetGen.exe 中的 0x00007FFE894DEB45 (nglib.dll) 中的生成代码:0xC0000005:violazione di accesso durante la lettura del percorso 0x000001803583E410。

堆栈跟踪:

[Frame inline] nglib.dll!netgen::TABLE<int,1>::operator[](int) Riga 252 C++
nglib.dll!netgen::Mesh::CalcSurfacesOfNode() Riga 2250  C++
nglib.dll!netgen::Mesh::Compress() Riga 4172    C++
nglib.dll!netgen::MeshVolume(const netgen::MeshingParameters & mp, netgen::Mesh & mesh3d) Riga 590  C++
nglib.dll!nglib::Ng_GenerateVolumeMesh(void * * mesh, nglib::Ng_Meshing_Parameters * mp) Riga 373   C++
TestNetGen.exe!main() Riga 73   C++

编辑:

我发现这个问题似乎是同样的问题。

c++ visual-c++ mesh
1个回答
0
投票

我的示例是正确的,但顶点索引必须从 1 开始。

© www.soinside.com 2019 - 2024. All rights reserved.