CFD中文网

    CFD中文网

    • 登录
    • 搜索
    • 最新

    关于相邻cell

    OpenFOAM
    3
    8
    671
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 星
      星星星星晴 最后由 编辑

      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 呢 跪求已有的轮子~

      m.sui20@foxmail.com

      1 条回复 最后回复 回复 引用
      • 李东岳
        李东岳 管理员 最后由 编辑

        目前想到的只能是把第一层cell,再次进行抽取,取其中不是第一层cells的cells当做第二层cell

        CFD高性能服务器 http://dyfluid.com/servers.html

        星 1 条回复 最后回复 回复 引用
        • 星
          星星星星晴 @李东岳 最后由 编辑

          @李东岳 这样感觉好麻烦。。 能不能说以某个cell为圆心或者质心将方圆几公里的cell都选中呢,并给出cell id:143:

          m.sui20@foxmail.com

          T 1 条回复 最后回复 回复 引用
          • T
            Tens 讲师 @星星星星晴 最后由 编辑

            @星星星星晴 看到之前师兄的程序,好像就是像东岳老师说的一层一层提取。我有个想法,是不是可以借鉴topoSet中的sphereToCell的思路,不过我看这个代码好像是遍历所有网格,感觉可能效率还不如上面的方法:143:

            星 1 条回复 最后回复 回复 引用
            • 星
              星星星星晴 @Tens 最后由 编辑

              @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
                      }
                  }
              

              m.sui20@foxmail.com

              李东岳 星 2 条回复 最后回复 回复 引用
              • 李东岳
                李东岳 管理员 @星星星星晴 最后由 编辑

                看起来是一个center_遍历一次网格

                CFD高性能服务器 http://dyfluid.com/servers.html

                星 1 条回复 最后回复 回复 引用
                • 星
                  星星星星晴 @李东岳 最后由 编辑

                  @李东岳 是的 因为我用那个相邻网格,导出id后 在paraview中看到的不是一团点,这个方法得到的是一团点

                  m.sui20@foxmail.com

                  1 条回复 最后回复 回复 引用
                  • 星
                    星星星星晴 @星星星星晴 最后由 编辑

                    @星星星星晴 本来没想到这么慢,结果发现假如我有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);
                    

                    m.sui20@foxmail.com

                    1 条回复 最后回复 回复 引用
                    • Referenced by  I ir77 
                    • Referenced by  I ir77 
                    • Referenced by  I ir77 
                    • First post
                      Last post