|
[Sponsors] |
August 21, 2023, 09:36 |
How to access registry from function1?
|
#1 |
Member
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16 |
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?
|
|
August 22, 2023, 01:52 |
|
#2 |
Member
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 64
Rep Power: 16 |
||
August 22, 2023, 04:13 |
|
#3 |
Member
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16 |
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"); 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 |
|
August 22, 2023, 06:06 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
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 |
||
August 22, 2023, 09:16 |
|
#5 |
Member
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16 |
Thank you, but as you might have guessed from the output I'm using the org-versions for this project.
|
|
August 23, 2023, 10:11 |
|
#6 |
Member
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 64
Rep Power: 16 |
||
August 23, 2023, 10:56 |
|
#7 |
Member
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16 |
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)); #}; } |
|
August 23, 2023, 22:07 |
|
#8 | |
Member
yijin Mao
Join Date: May 2010
Location: Columbia, MO
Posts: 64
Rep Power: 16 |
Quote:
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 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). |
||
August 24, 2023, 04:08 |
|
#9 |
Member
Join Date: Sep 2010
Location: Leipzig, Germany
Posts: 96
Rep Power: 16 |
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.
|
|
|
|
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 |