【问题标题】:Problem when importing a mesh with Gmsh3D in Fipy在 Fipy 中使用 Gmsh3D 导入网格时出现问题
【发布时间】:2021-07-27 13:37:20
【问题描述】:

我正在尝试将先前使用 Gmsh3D 函数生成的 3D 网格导入 Fipy,如下所示:

mesh = Gmsh3D(join(output,'case_1.msh'),communicator=serialComm)

我收到与其他类似帖子相同的错误,但建议的解决方案似乎对我不起作用:

GmshException: Gmsh hasn't produced any cells! Check your Gmsh code.

Gmsh output:
Info    : Running 'gmsh C:\Users\pcnou\AppData\Local\Temp\tmppouz68km.geo -3 -nopopup -format msh2 -o C:\Users\pcnou\AppData\Local\Temp\tmp5es89ie5.msh' [Gmsh 4.6.0, 1 node, max. 1 thread]
Info    : Started on Wed May 05 10:22:49 2021
Info    : Reading 'C:\Users\pcnou\AppData\Local\Temp\tmppouz68km.geo'...
Info    : Done reading 'C:\Users\pcnou\AppData\Local\Temp\tmppouz68km.geo'
Info    : Meshing 1D...
Info    : Done meshing 1D (Wall 0s, CPU 0s)
Info    : Meshing 2D...
Info    : Done meshing 2D (Wall 0s, CPU 0s)
Info    : Meshing 3D...
Info    : Done meshing 3D (Wall 0s, CPU 0s)
Info    : 0 nodes 0 elements
Info    : Writing 'C:\Users\pcnou\AppData\Local\Temp\tmp5es89ie5.msh'...
Info    : Done writing 'C:\Users\pcnou\AppData\Local\Temp\tmp5es89ie5.msh'
Info    : Stopped on Wed May 05 10:22:49 2021 (From start: Wall 0.00999999s, CPU 0.03125s)

我正在使用 Fipy 3.4.2.1、Python 3.7.9 和 Gmsh 4.8.4 开发 Win10。

我尝试将 .msh 文件转换为 .msh2 文件,但随后出现以下错误:

IndexError                                Traceback (most recent call last)
<ipython-input-47-38097a945970> in <module>
----> 1 mesh = Gmsh3D(join(output,'case_1.msh2'),communicator=serialComm) # Doesn't work

~\Anaconda3\envs\Ansys\Lib\site-packages\fipy\meshes\gmshMesh.py in __init__(self, arg, communicator, 
overlap, background)
   1991          self.cellGlobalIDs,
   1992          self.gCellGlobalIDs,
-> 1993          self._orderedCellVertexIDs_data) = self.mshFile.read()
   1994 
   1995         self.mshFile.close()

~\Anaconda3\envs\Ansys\Lib\site-packages\fipy\meshes\gmshMesh.py in read(self)
    815             parprint("Recovering coords.")
    816             parprint("numcells %d" % numCellsTotal)
--> 817             vertexCoords, vertIDtoIdx = self._vertexCoordsAndMap(cellsToGmshVerts)
    818 
    819             # translate Gmsh IDs to `vertexCoord` indices

~\Anaconda3\envs\Ansys\Lib\site-packages\fipy\meshes\gmshMesh.py in _vertexCoordsAndMap(self, 
cellsToGmshVerts)
   1008         allVerts     = nx.unique(nx.array(allVerts, dtype=nx.INT_DTYPE)) # remove dups
   1009         allVerts     = nx.sort(allVerts)
-> 1010         maxVertIdx   = allVerts[-1] + 1 # add one to offset zero
   1011         vertGIDtoIdx = nx.ones(maxVertIdx, 'l') * -1 # gmsh ID -> vertexCoords idx
   1012         vertexCoords = nx.empty((len(allVerts), self.coordDimensions))

IndexError: index -1 is out of bounds for axis 0 with size 0

当我使用.geo 文件时也会发生同样的情况。是网格本身的问题还是我对 Gmsh3D 做错了什么?任何帮助将不胜感激。

我首先尝试使用这个网格link,这是我希望使用的网格,但我不确定网格本身没有任何问题。因此,我尝试使用以下 .msh 文件:link 和相应的 .geo 文件:link,但均无效。

谢谢。

【问题讨论】:

  • 请提供指向您的.geo.msh 文件的链接
  • 我第一次尝试使用这个网格:link 但我不确定网格本身没有任何问题。因此,我尝试使用以下 .msh 文件:link 和相应的 .geo 文件:link,但均无效。
  • 好的,谢谢。请将这些链接编辑到您的问题中。 StackExchange cmets 是短暂的。

标签: python mesh fipy gmsh


【解决方案1】:
  • 这一行输出

    Info    : Running 'gmsh C:\Users\pcnou\AppData\Local\Temp\tmppouz68km.geo -3 -nopopup -format msh2 -o C:\Users\pcnou\AppData\Local\Temp\tmp5es89ie5.msh' [Gmsh 4.6.0, 1 node, max. 1 thread]
    

    意味着 FiPy 将 join(output,'case_1.msh') 的结果解释为 GEO 脚本,或者更准确地说,它无法在该位置找到文件,因此它假定字符串必须是 GEO 脚本。因为它是文件路径而不是 GEO 脚本,所以事情从那里往南走。

    我不知道为什么join(output,'case_1.msh') 不被视为您现有文件的路径。 output 是绝对路径还是相对路径?我建议检查您启动脚本的工作目录。

  • 你提供的case_1_amplazer_pos10001.geo不是Gmsh geometry script,所以FiPy和Gmsh都无法读取。

  • test.mshcase_1.msh 都是 4.1 版的 MSH 文件。 FiPy 无法读取这些。

  • 你是如何转换成MSH2格式的?

    我用过

    gmsh -3 -format msh2 case_1.msh -o case_1.msh2
    

    FiPy 成功导入。

【讨论】:

  • 非常感谢!似乎使用此命令行转换为msh2 格式工作正常,FiPy 导入网格没有任何问题。
  • 很高兴听到这个消息。如果对您有帮助,请accept回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
  • 2018-12-04
相关资源
最近更新 更多