【问题标题】:Python tools to perform interpolation of values at mesh centroids to mesh vertices?Python工具在网格质心到网格顶点执行值的插值?
【发布时间】:2021-06-29 02:44:56
【问题描述】:

我有一个 (n, m) 数组,它代表真实世界属性(例如高程)的网格,其中每一行和每一列代表所进行的测量之间的等距距离。 n 和 m 的值可能相当大。例如,较小的 6x6 版本看起来像这样(每个单元可能有 10 m 宽):

我想使用 Python 对网格顶点的所有值进行插值(并外推到网格边缘的顶点。即计算所有红点上的值:

我有每个单元的质心坐标,以及所有顶点的坐标。 Python 中是否有任何包或工具可以使这项任务变得简单?

【问题讨论】:

    标签: python mesh


    【解决方案1】:

    一种可能性是通过我的一个项目smoothfit 来实现。您首先创建一个四边形网格(meshzoo 可能会有所帮助),然后使用值 y0 定义目标位置 x0,然后使用 smoothfit 求解。

    import meshzoo
    import smoothfit
    
    points, cells = meshzoo.rectangle_quad((0.0, 0.0), (7.0, 7.0), n=7)
    
    
    x0 = [
        [0.5, 0.5],
        [1.5, 0.5],
        [2.5, 0.5],
        [3.5, 0.5],
        [4.5, 0.5],
        [5.5, 0.5],
        # ...
        [0.5, 5.5],
        # ...
        [5.5, 5.5],
    ]
    y0 = [8.0, 8.0, 9.0, 8.0, 7.0, 6.0, 10.0, 9.0]
    
    basis, u = smoothfit.fit(x0, y0, points, cells, lmbda=1.0e-4, solver="dense-direct")
    
    # Write the function to a file
    basis.mesh.save("out.vtu", point_data={"u": u})
    

    这将为您提供整个域上的函数,该函数平滑且大致满足您的目标值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 2019-12-31
      • 2021-09-09
      • 2020-10-06
      相关资源
      最近更新 更多