将gmsh生成的三维网格导入fipy时出现点坐标错误

2024-04-27 16:28:09 发布

您现在位置:Python中文网/ 问答频道 /正文

帮助将gmsh文件导入fipy,我已经在这个论坛上阅读了关于gmsh和fipy的所有问题,但不幸的是,我没有发现类似的错误。 我正在将GMSH3.0.6(推荐)生成的3D网格导入FiPy(3.3)。我目前使用的是Python3.7,我的操作系统是Windows10,64位。 我的slope1.geo文件是:

Point(1) = {0, 0, 0, 1.0};
Point(2) = {1, 0, 0, 1.0};
Point(3) = {0.3, 0.7, 0, 1.0};
Point(4) = {0, 0.7, 0, 1.0};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Line Loop(1) = {3, 4, 1, 2};
Plane Surface(1) = {1};
Extrude {0, 0, 0.8} {Surface{1}; Layers{8}; Recombine;}

我使用Gmsh命令gmsh.exe D:\gmsh\slope1.geo -3 -nopopup -format msh3 -o D:\gmsh\slope1.msh来生成slope1.msh文件,然后写:

import fipy as fp 
import numpy as np 
import os
mesh = fp.Gmsh3D(os.path.splitext("D:\\gmsh\\slope1")[0] + '.msh', communicator=fipy.serialComm)
np.savetxt("E:\\transfer_data\\gp.txt", mesh.vertexCoords.T,fmt='%f, %f, %f', newline='\n')
np.savetxt("E:\\transfer_data\\ele.txt", mesh._cellVertexIDs.T,fmt='%d, %d, %d,%d, %d, %d, %d, %d', newline='\n')

生成以下警告:

C:\Users\yang\python\python.exe "E:/python projects/data_file/1.py"
C:\Users\yang\python\lib\site-packages\fipy\meshes\gmshMesh.py:781: SyntaxWarning: Partition count 8 does not agree with number of remaining tags 0.
  facesData) = self._parseElementFile()
C:\Users\yang\python\lib\site-packages\fipy\meshes\mesh.py:201: RuntimeWarning: invalid value encountered in true_divide
  norm = norm / numerix.sqrtDot(norm, norm)
C:\Users\yang\python\lib\site-packages\fipy\meshes\mesh.py:205: RuntimeWarning: invalid value encountered in less
  orientation = 1 - 2 * (numerix.dot(faceNormals, self.cellDistanceVectors) < 0)
C:\Users\yang\python\lib\site-packages\fipy\meshes\mesh.py:219: RuntimeWarning: invalid value encountered in less
  orientation = 1 - 2 * (numerix.dot(self.faceNormals, faceCellToCellNormals) < 0)
C:\Users\yang\python\lib\site-packages\fipy\meshes\mesh.py:256: RuntimeWarning: invalid value encountered in true_divide
  faceTangents1 = tmp / numerix.sqrtDot(tmp, tmp)
C:\Users\yang\python\lib\site-packages\fipy\meshes\mesh.py:363: RuntimeWarning: invalid value encountered in true_divide
  return self._scaledFaceAreas / self._cellDistances

最后,我检查了slope1.msh{}和ele.txt发现gp.txt中的许多点坐标是0,0,0,而slope1.msh{}是很好的,我认为这是一个导入错误,但我无法找出它。 任何一个指针都很感激。非常感谢


Tags: pyselflibpackageslinesiteusersyang