|
[Sponsors] |
fields not auto written when stored in a HashTable |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 17, 2019, 01:40 |
fields not auto written when stored in a HashTable
|
#1 |
Member
Join Date: Oct 2013
Posts: 92
Rep Power: 13 |
Hi,
I have two data structures Code:
PtrList<volScalarField> indScalarFields_; HashTable<volScalarField,word> depScalarFields_; forAll(indScalarNames_, i) { indScalarFields_.set ( i, new volScalarField ( IOobject ( indScalarNames_[i]+"PDF", mesh_.time().timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ) ); } forAll(depScalarNames_, i) { depScalarFields_.insert ( depScalarNames_[i], volScalarField ( IOobject ( depScalarNames_[i]+"PDF", mesh_.time().timeName(), mesh_, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh_, dimensionedScalar(depScalarNames_[i]+"PDF", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0) ) ); } I have verified that the hashtable indeed contains correct fields and values calculated are correct. This is quite unexpected and puzzling. Last edited by fedvasu; October 20, 2019 at 00:30. Reason: edit correct name for depScalarFields |
|
October 18, 2019, 13:42 |
|
#2 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
You probably have multiple fields with the same name, and your hash table is messed up.
At the moment, the error of checking in multiple fields with the same name is not flagged, but you should not do it. You can check the contents of the database before writing - this will tell you what is going on...
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
October 18, 2019, 17:08 |
|
#3 | |
Member
Join Date: Oct 2013
Posts: 92
Rep Power: 13 |
Quote:
That is NOT a problem at all. I have explicitly written those fields using .write(), It writes them just fine. |
||
November 13, 2019, 08:21 |
|
#4 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
Well:
- when you insert a pointer to a field to the PtrList, it will take the field ptr as it stands and put it in. All is well. Field is registered in db when you made a pointer and never tampered with - When you insert a field into a HashTable - as opposed to the HashPtrTable - it will MAKE A COPY. The first (given) field is registered; you make the copy, try to register it, but fail, because there is already a field under the same name. Then you delete the first one, but you lost the position in db (the copied field was not registered) for the one that is actually in HashTable and on autoWrite it is not written. So, I was right. How to fix it: - use a HashPtrTable and all will be well - see above. - create the first field without registering (there is a construcvtor flag) and then the second field willl register - use a proper move construvtor for a field if possible. I did not look at the code; this kind of thing should happen quite often... (temper, temper...) Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
November 29, 2019, 11:36 |
|
#5 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
@Hrv: A good succinct explanation!
Another possibility would be to just put everything onto the objectRegistry for storage and lookup (since it is also just a HashPtrTable anyhow), but this might start being too complicated for a less experienced user. |
|
December 3, 2019, 16:28 |
|
#6 | |
Member
Join Date: Oct 2013
Posts: 92
Rep Power: 13 |
Quote:
|
||
Tags |
hashtable, iodictionary, openfoam-6 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Does sampleDict have limitation in number of fields? | reza2031 | OpenFOAM Post-Processing | 3 | April 22, 2020 14:24 |
Utilities: post average turbulence fields and create turbulence fields for LES | Hanzo | OpenFOAM Running, Solving & CFD | 10 | August 18, 2017 19:33 |
several fields modified by single boundary condition | schröder | OpenFOAM Programming & Development | 3 | April 21, 2015 06:09 |
Not all fields written as part of solution | adhiraj | OpenFOAM | 2 | April 23, 2011 12:16 |
PHI file structure | Eugene | Phoenics | 9 | November 2, 2001 23:00 |