粒子与网格归属问题
-
我现在用的最笨的方法弄得:
- 网格遍历
- 粒子遍历
- 如果粒子恰好在网格内,就把label存储在当前网格的DynamicList
forAll(U_, cell) { DynamicList<label> pL(0); scalar pN = 0; forAllConstIter(typename MomentumCloud<CloudType>, *this, iter) { const parcelType& p = iter(); if (p.cell() == cell) { pN += 1; pL.append(p.origId()); } } if (pN != 0) { Info<< "Cell[" << cell << "] has " << pN << " particles, " << "particle label is " << pL << nl; } }
输出结果还可以:
Cell[2295] has 2 particles, particle label is 2(20 21) Cell[2297] has 2 particles, particle label is 2(4 7) Cell[2298] has 1 particles, particle label is 1(3) Cell[2340] has 3 particles, particle label is 3(17 18 19) Cell[2341] has 5 particles, particle label is 5(11 13 14 15 16) Cell[2342] has 4 particles, particle label is 4(5 6 8 9) Cell[2343] has 1 particles, particle label is 1(1) Cell[2386] has 1 particles, particle label is 1(12) Cell[2387] has 1 particles, particle label is 1(10) Cell[2388] has 2 particles, particle label is 2(0 2)
但是这里面遍历网格+遍历粒子。肯定是要慢。
-
@李东岳 这么写呢?
List<DynamicList<label>> pL(U_.size()); forAllConstIter(typename MomentumCloud<CloudType>, *this, iter) { const parcelType& p = iter(); pL[p.cell()].append(p.origId()); }
或者
std::Multimap<label,label> Lp; forAllConstIter(typename MomentumCloud<CloudType>, *this, iter) { const parcelType& p = iter(); Lp.insert(std::pair<label,label>(p.cell(), p.origId())); }
都是我云的