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

How to get a reference to field from objectRegistry in foam-extend4

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By ELwardi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 8, 2019, 08:45
Default How to get a reference to field from objectRegistry in foam-extend4
  #1
Member
 
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 40
Rep Power: 9
ELwardi is on a distinguished road
Hi all,


I'm developing an independent library of classes to do various tasks, and often I find myself in need of a reference to a field the solver operates on/with.


As far as I can tell there are two options:
- Pass the reference to the class through its constructor.
- If the field is registered, get it from the object registry.



I do prefer the second option, but I'm facing a weird problem:


Assume I have a pure virtual class MyModel with a static ::New method that selects and constructs a "model" class. MyModel creates some volScalarFields and instantiates a handful of MyObject (also virtual) children.




MyModel, MyObject and their child classes constructors take a reference to the mesh as an argument, which is then used to initialize a member variable. It's like a habit of mine :
Code:
const fvMesh& mesh_;
The following code, in a member function of a child of MyObject, should get a (local) reference to K field:

Code:
const volScalarField& k = mesh_.db().lookupObject<volScalarField>("K");
but it doesn't. When the case is run, only volScalarFields generated by MyModel class are available!!!


The weird part is that MyModel takes only a "reference" to the mesh but it can't find some fields that are registered with that mesh object???

Do MyModel and/or MyObject need to inherit from some other class?



This being a bug in foam-extend 4 has low probability but I can't get my head around it! Any help/thoughts is appreciated.
ELwardi is offline   Reply With Quote

Old   April 12, 2019, 04:05
Default
  #2
Member
 
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 40
Rep Power: 9
ELwardi is on a distinguished road
It seems I was looking at the wrong place again:


Before starting the library, I decided to register everything to mesh (fvMesh inherits from objectRegistry) but after a while I got confused and started to register things to mesh.db() member.


So,
Code:
mesh.db().lookupObject<volScalarField>("K")
wouldn't work but
Code:
mesh.objectRegistry::lookupObject<volScalarField>("K")
would .
mrishi and FelixFebrian like this.

Last edited by ELwardi; April 13, 2019 at 08:51.
ELwardi is offline   Reply With Quote

Reply

Tags
mesh, objectregistry


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
Sig Density Based Solver installation with FOAM Extend 3.2 qjh888 OpenFOAM Bugs 0 September 21, 2016 08:16
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 05:42
OpenFOAM 1.6-ext git installation on Ubuntu 11.10 x64 Attesz OpenFOAM Installation 45 January 13, 2012 12:38
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 06:51


All times are GMT -4. The time now is 12:41.