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

Introducing the IOReferencer

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   August 12, 2011, 14:54
Default Introducing the IOReferencer
  #1
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
Hi Foamers,

I've thrown together a simple piece of code that allows you to look up non-IOobjects from the objectRegistry.

It's fairly straightforward:

  • The installation involves copying two files (no compiling);
  • The example of how to use it is in the header description.

Download it from:

http://openfoam-extend.svn.sourcefor...ject/?view=tar

The wiki page is currently down, but once it's up again, I'll upload the more detailed instructions to:

http://openfoamwiki.net/index.php/Contrib_IOReferencer
marupio is offline   Reply With Quote

Old   August 12, 2011, 15:27
Default Introducing the IOReferencer
  #2
New Member
 
Brent Craven
Join Date: Mar 2009
Location: University Park, PA, USA
Posts: 21
Rep Power: 8
brent_craven is on a distinguished road
Very nice! Thanks for the contribution.
brent_craven is offline   Reply With Quote

Old   August 13, 2011, 11:38
Default
  #3
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
Wiki instructions uploaded.
marupio is offline   Reply With Quote

Old   December 7, 2012, 11:33
Default
  #4
Member
 
Björn Windén
Join Date: Feb 2012
Location: University of Southampton UK
Posts: 37
Rep Power: 5
winden is on a distinguished road
Hi.

Thanks for a great contribution. I'm having some trouble and I was wondering if it is the IOReferencer or if I have done something else that is stupid

I would like to keep a pointer to a class (which class gets decided in the solver based on a dictionary) in the registry to access its member functions in other parts of the code.

In the solver I have:

Code:
autoPtr<myClass> pPtr = myClass::New(dict);


IOReferencer< autoPtr<myClass> > myObject
    (
        IOobject
            (
        "pControl",
        runTime.constant(),
        mesh,
        IOobject::NO_READ,
                IOobject::NO_WRITE
        ),
    pPtr
    );
And I access and use it elsewhere as:
Code:
pC = db.lookupObject<IOReferencer<autoPtr<myClass> > >("pControl")();

pForce_ = (pC->myMemberFunction(*this,deltaT));
I'm getting some weird behaviour from this. Sometimes the lookup works fine and the pC->myMemberFunction works fine but when the solver reaches a timestep where the write command is executed, it crashes. On the other hand, if I recompile the same code and run it again I sometimes instead get the following error in the first timestep:
Code:
--> FOAM FATAL ERROR: 

    lookup of pControl from objectRegistry region0 successful
    but it is not a regIOobject, it is a regIOobject

    From function objectRegistry::lookupObject<Type>(const word&) const
    in file /opt/openfoam171/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 120.

FOAM aborting
At first I didn't think it would work at all to send an autoPtr like this but I was surprised to see that it actually worked only to eventually be disappointed that it doesn't seem to be a stable way of doing it.

//Björn
winden is offline   Reply With Quote

Old   December 7, 2012, 11:47
Default
  #5
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
I've encountered this before... it's ugly. That last error you get occurs during an object registry lookup when the type name is correct, but the dynamic_cast still fails. This is one of those compiler issues. If I recall, the cast fails because the object is not the correct size. I can only guess that this occurs when "myClass" is complex. Is it templated, by chance?

The IOReferencer was mostly designed for primitives. If you have a complex custom class, it may be easier to just make it an IOobject, if you can.

However, you may find that it still fails the object lookup even without IOReferencer... in which case I'd suggest trying to change the class structure.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   December 7, 2012, 12:08
Default
  #6
Member
 
Björn Windén
Join Date: Feb 2012
Location: University of Southampton UK
Posts: 37
Rep Power: 5
winden is on a distinguished road
Hi. Thanks for the quick reply. myClass is indeed complex. It is a base class for selecting different propeller modelling techniques. (I modified it from the way constraints are selected for sixdofrigidbodymotion and I can't say I fully understand what all of it does.)

Hopefully, I can find another solution. There is always the possibility to change the structure so that I have direct access to the class where I wanted to use it. However that would mean having to create a lot of custom solutions for many of the base classes that lie above the class where I want to access it so I was hoping to avoid that. Anyway, thanks for letting me know what the problem was.

//Björn
winden is offline   Reply With Quote

Old   September 3, 2014, 12:54
Default why not using scalarIOField?
  #7
New Member
 
Andreas Ruopp
Join Date: Aug 2009
Location: Stuttgart / Germany
Posts: 29
Rep Power: 8
andyru is on a distinguished road
Hi,

maybe too late but why not using for example in main solver:
Code:
scalarIOField test
(
        IOobject
        (
            "test",
        runTime.constant(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
        ),
        <sizeOfWishedScalarList<
);
test = <valuesToBePutIntotest>;
then in boundary condition, for instance:
Code:
scalarIOField test =
        const_cast<scalarIOField&>
        (
        db().lookupObject<scalarIOField>("test")
        );
Works also for vectorIOField.

If you want to get only one scalar, then you have to use scalarIOField with size one, since there is no scalarIO.H...

I hope this helps!

Andy
andyru is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Discreate Particle Method: Introducing solids kris FLUENT 3 August 18, 2010 02:39
introducing angle of attack on ICEMCFD HEXA icem beginner Main CFD Forum 3 December 17, 2008 06:05
introducing angle of attack on ICEMCFD HEXA icem beginner FLUENT 2 December 6, 2008 16:34
Introducing Tracer jan FLUENT 0 December 2, 2005 10:17
Introducing revolutionary product MBAEdge- smarter surya_mba CD-adapco 0 February 16, 2005 05:20


All times are GMT -4. The time now is 17:56.