在 OpenFOAM 中,我可以訪問我的模擬時間串列,如下所示:
const auto& tlist = mesh.time().times(); //or runTime.times();
只需在自定義函式物件的背景關系中考慮這一點,您就可以在其中訪問時間串列。
當我列印該串列時:
Foam::Info << tlist << Foam::endl;
然后通過postProcess命令運行函式物件,我得到:
9
(
0 constant
0 0
0.001 0.001
0.002 0.002
0.003 0.003
0.004 0.004
0.005 0.005
0.006 0.006
0.007 0.007
)
End
我想洗掉該串列中的前兩個元素,即(0 constant)和(0 0)。但是我找不到任何方法來做到這一點,我發現的是,如果物件是一個 HashTable,那么有一種erase方法可以通過它的鍵洗掉元素。
任何想法如何從我的時間串列中洗掉前兩個元素tlist?或者至少我怎樣才能將該串列轉換為另一種允許我這樣做的資料結構?
謝謝
編輯:
這是 OpenFOAM 背景關系中 List 定義的鏈接:https : //cpp.openfoam.org/v9/classFoam_1_1List.html
uj5u.com熱心網友回復:
免責宣告,我從未使用過 OpenFOAM。看起來List有迭代器。 https://cpp.openfoam.org/v9/classFoam_1_1UList.html。所以你可以嘗試這樣的事情(假設迭代器像我從其他庫中習慣的那樣作業):
const auto& tlist = mesh.time().times(); //or runTime.times();
// assuming operator available on iterator. this will copy data
auto sublist = List<instant>(tlist.begin() 2,tlist.end());
Foam::Info << sublist << Foam::endl;
// or you could try to loop over the elements manually, this won't copy data
for (auto it = tlist.begin() 2; it != tlist.end(); it )
{
std::cout << *it << "\n";
}
std::cout << std::endl;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/332696.html
