MeshIO.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:discretize 作者: simpeg 项目源码 文件源码
def writeUBC(mesh, fileName, models=None):
        """Writes a TensorMesh to a UBC-GIF format mesh file.

        :param string fileName: File to write to
        :param dict models: A dictionary of the models

        """
        assert mesh.dim == 3
        s = ''
        s += '{0:d} {1:d} {2:d}\n'.format(*tuple(mesh.vnC))
        # Have to it in the same operation or use mesh.x0.copy(),
        # otherwise the mesh.x0 is updated.
        origin = mesh.x0 + np.array([0, 0, mesh.hz.sum()])
        origin.dtype = float

        s += '{0:.6f} {1:.6f} {2:.6f}\n'.format(*tuple(origin))
        s += ('%.6f '*mesh.nCx+'\n')%tuple(mesh.hx)
        s += ('%.6f '*mesh.nCy+'\n')%tuple(mesh.hy)
        s += ('%.6f '*mesh.nCz+'\n')%tuple(mesh.hz[::-1])
        f = open(fileName, 'w')
        f.write(s)
        f.close()

        if models is None: return
        assert type(models) is dict, 'models must be a dict'
        for key in models:
            assert type(key) is str, 'The dict key is a file name'
            mesh.writeModelUBC(key, models[key])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号