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

How to access registry from function1?

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By alundilong
  • 1 Post By olesen
  • 1 Post By alundilong

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 21, 2023, 09:36
Question How to access registry from function1?
  #1
Member
 
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16
oswald is on a distinguished road
I am trying to use a coded function1 for the position of an injector in a particle simulation. Does anybody have an idea how I can access the object registry from there?
oswald is offline   Reply With Quote

Old   August 22, 2023, 01:52
Default
  #2
Member
 
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 64
Rep Power: 16
alundilong is on a distinguished road
Quote:
Originally Posted by oswald View Post
I am trying to use a coded function1 for the position of an injector in a particle simulation. Does anybody have an idea how I can access the object registry from there?
something like this?

this->db().objectRegistry::template lookupObject<surfaceScalarField>
oswald likes this.
alundilong is offline   Reply With Quote

Old   August 22, 2023, 04:13
Default
  #3
Member
 
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16
oswald is on a distinguished road
Thanks, but unfortunately not. It seems like the function1 has not builtin functionalities like this. Here is my line of code with your suggestion:
Code:
const scalar velh = this->db().objectRegistry::template lookupObject<scalar>("Hs");
And this is the error I get:
Code:
In file included from codedFunction1Template.C:26:
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position: In member function ‘virtual Foam::vector Foam::Function1s::linIntRampFunction1vector::value(Foam::scalar) const’:
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:47: error: ‘const class Foam::Function1s::linIntRampFunction1vector’ has no member named ‘db’
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:52: error: request for member ‘objectRegistry’ in non-class type ‘<type error>’
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:96: error: expected primary-expression before ‘>’ token
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:34: warning: unused variable ‘velh’ [-Wunused-variable]
make: *** [/opt/openfoam10/wmake/rules/General/transform:26: Make/linux64GccDPInt32Opt/codedFunction1Template.o] Error 1
oswald is offline   Reply With Quote

Old   August 22, 2023, 06:06
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by oswald View Post
Thanks, but unfortunately not. It seems like the function1 has not builtin functionalities like this. Here is my line of code with your suggestion:
Code:
const scalar velh = this->db().objectRegistry::template lookupObject<scalar>("Hs");
And this is the error I get:
Code:
In file included from codedFunction1Template.C:26:
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position: In member function ‘virtual Foam::vector Foam::Function1s::linIntRampFunction1vector::value(Foam::scalar) const’:
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:47: error: ‘const class Foam::Function1s::linIntRampFunction1vector’ has no member named ‘db’
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:52: error: request for member ‘objectRegistry’ in non-class type ‘<type error>’
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:96: error: expected primary-expression before ‘>’ token
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:34: warning: unused variable ‘velh’ [-Wunused-variable]
make: *** [/opt/openfoam10/wmake/rules/General/transform:26: Make/linux64GccDPInt32Opt/codedFunction1Template.o] Error 1

It doesn't help you with the openfoam.org versions, but if you (or someone else) is using the openfoam.com version it will generally work with obr() access. Here is a link:


https://www.openfoam.com/documentati...e.html#details
oswald likes this.
olesen is offline   Reply With Quote

Old   August 22, 2023, 09:16
Default
  #5
Member
 
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16
oswald is on a distinguished road
Thank you, but as you might have guessed from the output I'm using the org-versions for this project.
oswald is offline   Reply With Quote

Old   August 23, 2023, 10:11
Default
  #6
Member
 
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 64
Rep Power: 16
alundilong is on a distinguished road
Quote:
Originally Posted by oswald View Post
Thank you, but as you might have guessed from the output I'm using the org-versions for this project.
can you share what you are trying to do and a snippet of your code?
It might help to develop a working solution for you.
alundilong is offline   Reply With Quote

Old   August 23, 2023, 10:56
Default
  #7
Member
 
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16
oswald is on a distinguished road
Of course. Here is a snippet from inside the cloudProperties file. It is inside the injection model:
Code:
            position    // position of the injector
            {
                type        coded;
                name        linIntRamp;

                libs        ();

                codeInclude
                #{
                #};

                code
                #{
                    const vector startPos(-0.0005, -0.001, 0.003);  // initial location of the injector
                    const vector vel(0, 0, 0.01);                   // velocity of the injector
                    const scalar startTime = 0.0;                   // starting time of injector

                    return startPos + vel*(max(x-startTime,0.0));
                #};
            }
The injector should move with a velocity that is given within another dictionary outside of this scope.
oswald is offline   Reply With Quote

Old   August 23, 2023, 22:07
Default
  #8
Member
 
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 64
Rep Power: 16
alundilong is on a distinguished road
Quote:
Originally Posted by oswald View Post
Of course. Here is a snippet from inside the cloudProperties file. It is inside the injection model:
Code:
            position    // position of the injector
            {
                type        coded;
                name        linIntRamp;

                libs        ();

                codeInclude
                #{
                #};

                code
                #{
                    const vector startPos(-0.0005, -0.001, 0.003);  // initial location of the injector
                    const vector vel(0, 0, 0.01);                   // velocity of the injector
                    const scalar startTime = 0.0;                   // starting time of injector

                    return startPos + vel*(max(x-startTime,0.0));
                #};
            }
The injector should move with a velocity that is given within another dictionary outside of this scope.
oswald,

I'd recommend write a new InjectionModel where the customized position varying injector applied. In the InjectionModel(btw, I am referring to OpenFOAM v11), you have access to mesh through which you can do what ever needed.

Code:
In file included from codedFunction1Template.C:26:
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position: In member function ‘virtual Foam::vector Foam::Function1s::linIntRampFunction1vector::value(Foam::scalar) const’:
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:47: error: ‘const class Foam::Function1s::linIntRampFunction1vector’ has no member named ‘db’
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:52: error: request for member ‘objectRegistry’ in non-class type ‘<type error>’
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:96: error: expected primary-expression before ‘>’ token
/home/user/OpenFOAM/user-10/run/plate2d/constant/cloudProperties/subModels/injectionModels/model1/position:102:34: warning: unused variable ‘velh’ [-Wunused-variable]
make: *** [/opt/openfoam10/wmake/rules/General/transform:26: Make/linux64GccDPInt32Opt/codedFunction1Template.o] Error 1
Regarding Function1s::linIntRampFunction1vector, as hinted above, Function1s is just namespace, and linIntRampFunction1vector is a simple function derived from nowhere, it explain why the line of 'this->db()...' does not work.

Any I am gonna prepare a write-up on how to implement a new injection model of your kind recently to have your problem solved(finger crossed).
oswald likes this.
alundilong is offline   Reply With Quote

Old   August 24, 2023, 04:08
Default
  #9
Member
 
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16
oswald is on a distinguished road
Thank you very much for you input, I totally appreciate it! I tried to avoid writing a new injection model, as I thought it might be nice to use builtin capabilities. With a new model, I'm able to implement what I need, so please don't "waste" your time, unless you are also interested in it. And maybe others can still benefit from it.
oswald is offline   Reply With Quote

Reply


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
Getting access to mesh (fvMesh) via object registry Chris Lucas OpenFOAM Programming & Development 18 January 15, 2024 03:57
Is there a global container where all Function1 are stored? Siassei OpenFOAM Programming & Development 0 September 10, 2020 05:32
Why is access to turbulence fields provided as const? mrishi OpenFOAM Programming & Development 3 January 23, 2020 13:51
Is there a way to access the gradient limiter in Fluent ? CFDYourself FLUENT 1 February 16, 2016 06:49
using the object registry to access a particle cloud gregor OpenFOAM 1 June 8, 2011 06:58


All times are GMT -4. The time now is 04:20.