|
[Sponsors] |
How to get a reference to field from objectRegistry in foam-extend4 |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 8, 2019, 09:45 |
How to get a reference to field from objectRegistry in foam-extend4
|
#1 |
Member
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 41
Rep Power: 10 |
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_; Code:
const volScalarField& k = mesh_.db().lookupObject<volScalarField>("K"); 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. |
|
April 12, 2019, 05:05 |
|
#2 |
Member
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 41
Rep Power: 10 |
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") Code:
mesh.objectRegistry::lookupObject<volScalarField>("K") Last edited by ELwardi; April 13, 2019 at 09:51. |
|
Tags |
mesh, objectregistry |
|
|
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 09:16 |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 07:20 |
[blockMesh] non-orthogonal faces and incorrect orientation? | nennbs | OpenFOAM Meshing & Mesh Conversion | 7 | April 17, 2013 06:42 |
OpenFOAM 1.6-ext git installation on Ubuntu 11.10 x64 | Attesz | OpenFOAM Installation | 45 | January 13, 2012 13:38 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |