@星星星星晴 本来没想到这么慢,结果发现假如我有1M parcel,1M cell 就要搞1M x 1M次, 实在有点笨。然后现在改为之前那个方法了。。 可能是当时不知道怎么回事有点脑残吧,搞错了,相邻cell一层一层搞出来快很多。。 下面是code, 编程能力有限,想搞成个function,总觉得麻烦。。不过改成function的话应该可以弄n层了吧。。
还是python好写。。。
if (neighbor_) {
//Info << "cellI = " <<cellI<<nl;
//- first layer
List<int> first = this->owner().mesh().cellCells()[cellI];
first.append(cellI);
sort(first);
all_neighbor.append(first);
int first_size = first.size();
//Info << "cellI = " << first <<nl;
//- second layer
List<int> second_all;
for (int i1 = 0; i1<first_size; i1++){
List<int> second = this->owner().mesh().cellCells()[first[i1]];
//Info << "cellI second = " << second <<nl;
second_all.append(second);
}
List<int> order,second_unique;
uniqueOrder(second_all, order);
forAll(order,kk)
{
second_unique.append(second_all[order[kk]]);
}
sort(second_unique);
all_neighbor.append(second_unique);
//- third layer
List<int> third_all;
for (int i1 = 0; i1<second_unique.size(); i1++){
List<int> third = this->owner().mesh().cellCells()[second_unique[i1]];
//Info << "cellI third = " << third <<nl;
third_all.append(third);
}
List<int> order3,third_unique;
uniqueOrder(third_all, order3);
forAll(order3,kk)
{
third_unique.append(third_all[order3[kk]]);
}
sort(third_unique);
all_neighbor.append(third_unique);
//- Fourth layer
List<int> fourth_all;
for (int i1 = 0; i1<third_unique.size(); i1++){
List<int> fourth = this->owner().mesh().cellCells()[third_unique[i1]];
fourth_all.append(fourth);
}
List<int> order4,fourth_unique;
uniqueOrder(fourth_all, order4);
forAll(order4,kk)
{
fourth_unique.append(fourth_all[order4[kk]]);
}
sort(fourth_unique);
all_neighbor.append(fourth_unique);
//- collect all
List<int> order_all;
uniqueOrder(all_neighbor, order_all);
forAll(order_all,kk)
{
all_neighbor_unique.append(all_neighbor[order_all[kk]]);
}
sort(all_neighbor_unique);