|
[Sponsors] |
November 6, 2018, 09:35 |
Compilation fails under OF1806+
|
#1 |
Senior Member
Join Date: Mar 2018
Posts: 115
Rep Power: 8 |
Hello,
I have an OpenFOAM code that compiles and runs properly under OpenFOAM 6. Now I switched to OpenFOAM V1806 but unfortunately the code doesn't compile. After reading the errors reported by the compiler, I understand that the problem is caused by hashtable, so I decided to isolate the problem and I created the sample code below that produces the same error: The code: Code:
#include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // void fillHashTable(HashTable<List<label>, label>& hashTable, label maxN); int main(int argc, char *argv[]) { HashTable<List<label>, label> table1; fillHashTable(table1, 5); Info << table1 << endl; Info<< "End\n" << endl; return 0; } void fillHashTable(HashTable<List<label>, label>& hashTable, label maxN) { List<label> tmpList; for(int i=0; i < maxN; ++i) { tmpList.clear(); tmpList = {2*i, i*i, i*i*i}; hashTable.insert(i , tmpList); } } Code:
... /home/evren/OpenFOAM/OpenFOAM-v1806/src/OpenFOAM/lnInclude/HashTableI.H:35: error: no match for call to ‘(Foam::string::hash) (const int&)’ return Hash()(key) & (capacity_ - 1); ~~~~~~^~~~~ ... Could you please help me debug this problem, is it a bug? Update: After changing the type of key to word it works, Could you please confirm that hashtables in OpenFOAM v1806 work only with string keys? Last edited by anon_q; November 6, 2018 at 13:45. |
|
November 6, 2018, 17:46 |
|
#2 |
Senior Member
Join Date: Mar 2018
Posts: 115
Rep Power: 8 |
Problem solved!
using: Code:
HashTable<List<label>, label, Hash<label>> |
|
November 11, 2018, 21:49 |
|
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Your posted solution is correct
Code:
HashTable<List<label>, label, Hash<label>> Code:
HashTable<List<label>, label> As you've discovered, the HashTable uses a 'word' as its default key, and hashes on that accordingly. If you change the type of the key used in the HashTable, you should be careful that the hashing method also matches. With Code:
HashTable<List<label>, label> myHash; myHash.insert(10, list1); myHash.insert(200, list2); myHash.insert(3000, list3); ... Code:
/home/evren/OpenFOAM/OpenFOAM-v1806/src/OpenFOAM/lnInclude/HashTableI.H:35: error: no match for call to ‘(Foam::string::hash) (const int&)’ return Hash()(key) & (capacity_ - 1); ~~~~~~^~~~~ Since using a 'label' as the key for a HashTable is fairly useful, you would expect that it must be easier than all of this (with much less typing). Indeed it is. The updated code that you should actually be using would be a Map: Code:
Map<labelList> myHash; myHash.insert(200, list2); /mark |
|
November 11, 2018, 21:53 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
Could also use something this Code:
void fillHashTable(Map<labelList>& hashTable, label maxN) { for(int i=0; i < maxN; ++i) { hashTable.insert(i , labelList({2*i, i*i, i*i*i})); } } |
||
November 12, 2018, 08:30 |
|
#5 |
Senior Member
Join Date: Mar 2018
Posts: 115
Rep Power: 8 |
Thank you very much for the detailed answer
|
|
Tags |
openfoam, openfoam 1806 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM.org] OpenFOAM 4.0 compilation fails with latest Intel compiler | mstud | OpenFOAM Installation | 3 | October 6, 2016 17:01 |
Modified interFoam compilation fails | voingiappone | OpenFOAM Programming & Development | 6 | October 1, 2013 04:47 |
OpenFOAM compilation fails on applicationsutilitiesmesh | geoffjay | OpenFOAM Installation | 12 | April 29, 2008 16:26 |
Compilation fails on Linuxx86 | agrahn | OpenFOAM Bugs | 21 | August 31, 2007 05:10 |
Compilation fails on suse linux 101 | su_junwei | OpenFOAM Bugs | 2 | July 20, 2007 05:56 |