【源码】将二维多相图像转换为FEM网格的Im2mesh工具箱

640?wx_fmt=jpeg

工具的使用包括几个步骤,例如,图像转换为多边形,标记多边形之间的相交顶点(=网格控制点),简化多边形,多边形转换为三角形网格,在交会处搜索节点,导出为Inp文件。

This tool consists of a few steps, like, image to polygon, mark intersecting vertex (=control point for meshing) between polygons, simplify polygon, polygon to triangular meshes, search nodes at interface, export as Inp file. 


Inp文件可以被导出到Abaqus软件中

The Inp file can be imported into software Abaqus. 


该工具最初撰写于2018年3月,用于含空隙的颗粒材料研究。

This tool was originally written in March 2018 for particle material with air void. 


2019年,作者将代码改写为多相材料的应用。

In 2019, the code was rewritten so it can work for multi-phase materials


能够准确保留不同相位之间的接触细节

Exactly reserve the contact detail between different phases.


为了保证代码的正常运行,需要从https://github.com/dengwirda/mesh2d下载MESH2D软件,同时将文件夹(mesh2d-master)加入到对应的运行路径中。

To make this code run (especially for poly2mesh), you need to download MESH2D from https://github.com/dengwirda/mesh2d, and add the folder (mesh2d-master) to your path. 


然后就可以启动demo()函数了。测试用例的图片位于文件夹(im2mesh\examples\...)。

After that, you can start with demo(). Try out the images in the folder (im2mesh\examples\...).


如果有任何问题,可以与作者联系:mjx0799@gmail.com。

If you have any questions or suggestions, feel free to send me an email. Email:mjx0799@gmail.com


完整源码下载请点击“阅读原文”


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是将CSharp FEM文件转换为GMSH网格文件的源代码: ```csharp using System; using System.IO; namespace CSharpToGMSH { class Program { static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: CSharpToGMSH.exe input.fem output.msh"); return; } string inputPath = args[0]; string outputPath = args[1]; // Read input file string[] inputLines = File.ReadAllLines(inputPath); // Extract nodes, elements and element types int numNodes = 0; int numElements = 0; string[] nodeLines = null; string[] elementLines = null; string[] elementTypeLines = null; foreach (string line in inputLines) { if (line.StartsWith("Nodes:")) { numNodes = int.Parse(line.Substring(6)); nodeLines = new string[numNodes]; for (int i = 0; i < numNodes; i++) { nodeLines[i] = inputLines[i + 1]; } } else if (line.StartsWith("Elements:")) { numElements = int.Parse(line.Substring(9)); elementLines = new string[numElements]; elementTypeLines = new string[numElements]; for (int i = 0; i < numElements; i++) { elementLines[i] = inputLines[i + numNodes + 2]; elementTypeLines[i] = inputLines[i + numNodes + numElements + 3]; } } } // Write output file using (StreamWriter writer = new StreamWriter(outputPath)) { // Write header writer.WriteLine("$MeshFormat"); writer.WriteLine("2.2 0 8"); writer.WriteLine("$EndMeshFormat"); // Write nodes writer.WriteLine("$Nodes"); writer.WriteLine(numNodes); for (int i = 0; i < numNodes; i++) { string[] tokens = nodeLines[i].Split(' '); writer.WriteLine($"{i + 1} {tokens[0]} {tokens[1]} {tokens[2]}"); } writer.WriteLine("$EndNodes"); // Write elements writer.WriteLine("$Elements"); writer.WriteLine(numElements); for (int i = 0; i < numElements; i++) { string[] tokens = elementLines[i].Split(' '); int numNodesPerElement = int.Parse(tokens[1]); writer.Write($"{i + 1} {elementTypeLines[i]} 2 0 {numNodesPerElement}"); for (int j = 0; j < numNodesPerElement; j++) { writer.Write($" {int.Parse(tokens[j + 2])}"); } writer.WriteLine(); } writer.WriteLine("$EndElements"); } } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值