// netgen-2010.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "../meshgene/netgenmesh.h" #include "windows.h" std::vector calculateRectangleVertices( Point p1, // 起点 Point p2, // 终点 double width // 矩形宽度 ) { double dx = p2.x - p1.x; double dy = p2.y - p1.y; double length = std::sqrt(dx * dx + dy * dy); if (length == 0) { // 起点和终点重合,无法生成矩形 return std::vector(); } // 单位法向量(左侧) double nx = -dy / length; double ny = dx / length; // 半宽偏移 double half_width = width / 2; double offset_x = half_width * nx; double offset_y = half_width * ny; // 计算四个顶点(逆时针顺序) std::vector vertices(4); vertices[0] = Point(p1.x + offset_x, p1.y + offset_y); // 起点左侧 vertices[1] = Point(p1.x - offset_x, p1.y - offset_y); // 起点右侧 vertices[2] = Point(p2.x - offset_x, p2.y - offset_y); // 终点右侧 vertices[3] = Point(p2.x + offset_x, p2.y + offset_y); // 终点左侧 return vertices; } int _tmain(int argc, _TCHAR *argv[]) { HMODULE hMod = LoadLibrary("meshgene.dll"); if (NULL == hMod) { std::cout << "meshgene.dll加载失败!\n"; return 1; } CBoundShape shape; shape.boundShape = POLYGON; shape.nNumSegs = 4; Segment seg1; seg1.p1 = Point(-1000, -1000); seg1.p2 = Point(1000, -1000); Segment seg2; seg2.p1 = Point(1000, -1000); seg2.p2 = Point(1000, 1000); Segment seg3; seg3.p1 = Point(1000, 1000); seg3.p2 = Point(-1000, 1000); Segment seg4; seg4.p1 = Point(-1000, 1000); seg4.p2 = Point(-1000, -1000); shape.vecSegments.push_back(seg1); shape.vecSegments.push_back(seg2); shape.vecSegments.push_back(seg3); shape.vecSegments.push_back(seg4); shape.cCenter = Point(0, 0); shape.dRadius = 1000; CBoundWell w1, w2; w1.cCenter = Point(-10, 0); w1.dRadius = 0.1; w2.wellType=VERTICAL_FRACTURED; w2.dHf=10; w2.dTheata=30; w2.cCenter = Point(50, 0); w2.dRadius = 0.1; CBoundWell w3; w3.wellType=MULTI_FRACED_HORIZONTAL; w3.cCenter=Point(142,-226); w3.dBeta=20; w3.dLength=200; w3.nFracNum=10; w3.dHf=10; std::vector wells; wells.push_back(w1); wells.push_back(w2); wells.push_back(w3); CBoundPolygon limit; limit.boundShape = POLYGON; limit.nNumSegs = 5; limit.vecSegments.push_back(Segment(Point(-516.2335347838829, -58.37577524138442), Point(-592.72401802758, -180.9965861656542))); limit.vecSegments.push_back(Segment(Point(-592.72401802758, -180.9965861656542), Point(-485.12090993338666, -280.2195626173259))); limit.vecSegments.push_back(Segment(Point(-485.12090993338666, -280.2195626173259), Point(-328.9162066043042, -229.04373034669038))); limit.vecSegments.push_back(Segment(Point(-328.9162066043042, -229.04373034669038), Point(-376.36137535544276, -90.33591813134171))); limit.vecSegments.push_back(Segment(Point(-376.36137535544276, -90.33591813134171), Point(-516.2335347838829, -58.37577524138442))); std::vector limits; limits.push_back(limit); CBoundPolygon fault; std::vector faults; Point fp1(-267.3, 174.8); Point fp2(316.7, 178.6); std::vector vertices = calculateRectangleVertices(fp1, fp2, 0.2); fault.boundShape = POLYGON; fault.nNumSegs = 4; for (int i = 0; i < 3; ++i) { fault.vecSegments.push_back(Segment(vertices[i], vertices[i + 1])); } fault.vecSegments.push_back(Segment(vertices[3], vertices[0])); faults.push_back(fault); std::vector fracs; // fracs.push_back(Frac(Point(-295.4590458689436, 135.24645349343746), Point(161.25020791914517, 312.55990051563924))); fracs.push_back(Frac(Point(-326.1597927937205, 460.0597222992292), Point(165.83631020744383, 459.08547259031593))); fracs.push_back(Frac(Point(37.37000102969455, -657.4918218469559), Point(358.8407220536865, -289.8115658489835))); typedef Ng_Mesh *(*NgMeshGen2DByIn2d)(std::vector wells, std::vector limits, std::vector faults, std::vector fracs, CBoundShape shape); // Get the address of the Ng_Mesh function NgMeshGen2DByIn2d meshgene1 = (NgMeshGen2DByIn2d)GetProcAddress(hMod, "NgMeshGen2DByIn2d"); if (NULL == meshgene1) { FreeLibrary(hMod); std::cout << "meshgene文件加载函数地址获取失败!\n"; return 1; } Ng_Mesh *mesh = meshgene1(wells, limits, faults, fracs, shape); typedef void *(*Ng2VTK)(Ng_Mesh *); Ng2VTK mesh2vtk = (Ng2VTK)GetProcAddress(hMod, "Ng2VTK"); if (NULL == mesh2vtk) { FreeLibrary(hMod); std::cout << "Ng2VTK文件加载函数地址获取失败!\n"; return 1; } mesh2vtk(mesh); FreeLibrary(hMod); }