关于相邻cell
-
https://www.cfd-online.com/Forums/openfoam-meshing/61906-how-identify-cell-neighbours.html
根据这个帖子,我可以得到一个cell周围的相邻cell id。
进而可以得到这些cell中的相关信息。
这个命令可以称之为目标cell外面的一层cell,假设是结构网格,那么就会有26个cell id。那假如想得到第2层相邻cell呢?应该第二层有25+25+15+15个,如何获得这些cell id 呢 跪求已有的轮子~
-
@tens https://www.cfd-online.com/Forums/openfoam-meshing/61906-how-identify-cell-neighbours-3.html
根据这个思路做出来了,我尝试了一层一层提取,感觉一层一层提取的id 有问题,不是我想要的那种结果,只能用这种方法跑了。
看起来成功了//This gets all cell centres of all mesh cells const pointField& ctrs = mesh_.cellCentres(); //This calculates the radius of your sphere const scalar radSquared = radius_*radius_; //Loop over all cells forAll(ctrs, cellI) { //calculates the distance between the cell centre and the current cell //with the index cellI scalar offset = magSqr(centre_ - ctrs[cellI]); if (offset <= radSquared) { //Do something, e.g. store the current cell id in a list } }
-
@星星星星晴 本来没想到这么慢,结果发现假如我有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);
-
-
-