【发布时间】:2019-12-14 19:42:36
【问题描述】:
我正在开发一个有限元程序,其中我的输入是节点列表(ListNodes double[node_index, x, y, z] 其中(x,y,z) 是笛卡尔坐标系中节点的坐标),元素列表(ListElements double[element_index, node1_index, node2_index, etc]) 和每个元素的一些数据(double[element_index]).
我必须不断地在有限元模型中的某个给定区域搜索数据,一个区域由某个边界 [xmin, xmax, ymin, ymax, zmin, zmax] 定义。为了检索这个区域的数据,我首先查找它的节点(搜索节点,使(x,y,z) 在边界内)然后查找它的元素,最后检索这些元素的数据。
功能1:检查节点是否在区域内
private static bool IsBounded(double[] node, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
{
return ((node[1] >= xmin) && (node[1] <= xmax) && (node[2] >= ymin) && (node[2] <= ymax) && (node[3] >= zmin) && (node[3] <= zmax));
}
功能2:检查所有节点以找到区域内的节点并将它们添加到zoneNodes
ListPoint.Where(node => IsBounded(node, xmin, ymin, zmin, xmax, ymax, zmax)).ToList().ForEach(node => zoneNodes.Add(Convert.ToInt32(node[0])));
功能3:在区域内查找元素
// Loop over all elements
for (int j = 0; j < ListElement.Count; j++)
{
int status = 0;
for (int i = 1; i < ElementList[j].Count; i++)
{
// For each element, check how many nodes are inside the zone
if (zoneNodes.Contains(Convert.ToInt32(ListElement[j][i])))
{
status++;
}
}
// If all the nodes of this element are inside the zone then the element is inside the zone
if (status == ListElement[j].Count - 1)
{
zoneElements.Add(Convert.ToInt32(ElementList[j][0]));
}
}
功能4:对于区域内的每个元素,我们可以检索数据
然而,这个过程非常缓慢。有什么方法可以改进这个过程以获得更快的性能?
谢谢,
【问题讨论】:
-
请看一下 R-tree en.wikipedia.org/wiki/R-tree
-
您好,感谢您的建议,但为什么选择 Rtree?如果我使用 Rtree,我必须重新索引我的所有元素编号?
-
R-Tree 是我们用于空间数据的典型数据结构。据我从您提供的代码中可以看出,从技术上讲,不要使用元素编号:相反,您正在解决“如果元素在区域中”的问题 - R-Tree 的任务就是为