CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

fields not auto written when stored in a HashTable

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By hjasak
  • 3 Post By hjasak

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 17, 2019, 01:40
Default fields not auto written when stored in a HashTable
  #1
Member
 
Join Date: Oct 2013
Posts: 92
Rep Power: 13
fedvasu is on a distinguished road
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)         
            )
        );
    }
The VolScalarFields in indScalarFields_ (PtrList) are witten every write timeStep but fields in depScalarFields_ are not written.

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
fedvasu is offline   Reply With Quote

Old   October 18, 2019, 13:42
Default
  #2
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
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...
Mowgli likes this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   October 18, 2019, 17:08
Default
  #3
Member
 
Join Date: Oct 2013
Posts: 92
Rep Power: 13
fedvasu is on a distinguished road
Quote:
Originally Posted by hjasak View Post
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...
Yeah I checked the db, none of the fields are in there. I have also checked that none of my fields have same name.

That is NOT a problem at all.

I have explicitly written those fields using .write(), It writes them just fine.
fedvasu is offline   Reply With Quote

Old   November 13, 2019, 08:21
Default
  #4
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
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
olesen, Daniel_Khazaei and fedvasu like this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   November 29, 2019, 11:36
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
@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.
olesen is offline   Reply With Quote

Old   December 3, 2019, 16:28
Default
  #6
Member
 
Join Date: Oct 2013
Posts: 92
Rep Power: 13
fedvasu is on a distinguished road
Quote:
Originally Posted by hjasak View Post
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
Thanks for the clear explanation. I will use HashPtrTable from here on.
fedvasu is offline   Reply With Quote

Reply

Tags
hashtable, iodictionary, openfoam-6


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 18:01.