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

Question about lookupObject function

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By zhangyan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 3, 2019, 03:05
Question Question about lookupObject function
  #1
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Hi, everyone.
To investigate the interactions between the gas and the injected liquid, I just modified one turbulence model source file. In this source file, I must read every parcel of the spray cloud to calculate the interaction. Therefore, lookupObject function may be called as follows.
const basicSprayCloud & cloud = (this->mesh_.objectRegistry.template lookupObject<basicSprayCloud>("sprayCloud"));
Anyway, the compiling message says:
error: reference to 'Foam::SprayCloud<Foam::ReactingCloud<Foam::Thermo Cloud<Foam::KinematicCloud<Foam::Cloud<Foam::Spray Parcels<Foam::ReactingParcel<Foam::ThermoParcel<Fo am::KinmaticParcel<Foam::Parcel>>>>>>>>>::typeName is ambiguous'
where basicSprayCloud and sprayCloud are declared in createClouds.H as follows:
Info<<"\nConstructing reacting cloud" << endl;
basicSprayCloud parcels
(
"sprayCloud",
rho,
U,
g,
slgThermo
);
So how to call lookupObject function properly to get the sprayCloud in turbulence model (k function)?
NewKid is offline   Reply With Quote

Old   February 3, 2019, 06:06
Default
  #2
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by NewKid View Post
Hi, everyone.
To investigate the interactions between the gas and the injected liquid, I just modified one turbulence model source file. In this source file, I must read every parcel of the spray cloud to calculate the interaction. Therefore, lookupObject function may be called as follows.
const basicSprayCloud & cloud = (this->mesh_.objectRegistry.template lookupObject<basicSprayCloud>("sprayCloud"));
Anyway, the compiling message says:
error: reference to 'Foam::SprayCloud<Foam::ReactingCloud<Foam::Thermo Cloud<Foam::KinematicCloud<Foam::Cloud<Foam::Spray Parcels<Foam::ReactingParcel<Foam::ThermoParcel<Fo am::KinmaticParcel<Foam::Parcel>>>>>>>>>::typeName is ambiguous'
where basicSprayCloud and sprayCloud are declared in createClouds.H as follows:
Info<<"\nConstructing reacting cloud" << endl;
basicSprayCloud parcels
(
"sprayCloud",
rho,
U,
g,
slgThermo
);
So how to call lookupObject function properly to get the sprayCloud in turbulence model (k function)?
This might help inject particles of different densities - kinematiccloud

"What i did so far is to just add a second cloud in the createClouds.C:"

Code:
Info<< "\nConstructing bubble cloud" << endl;
basicSprayCloud bubbles
(
    "bubbles",
    rho,
    U,
    g,
    slgThermo
);

Info<< "\nConstructing catalysator cloud" << endl;
basicSprayCloud cat
(
    "cat",
    rho,
    U,
    g,
    slgThermo
);
Did you try doing this with createClouds.C, because you said you did it in createClouds.H? Maybe that's all?
massive_turbulence is offline   Reply With Quote

Old   February 3, 2019, 09:13
Default
  #3
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Hi, massive_turbulence,
Thanks a lots!
The createClouds.H is one original file of the source files of solver "sprayFoam", what I'm trying to do is to get the "sprayCloud" in the turbulence model file with lookupObject function instead of to declare it in createClouds.H.
Thanks for your kindest helps!
NewKid is offline   Reply With Quote

Old   February 3, 2019, 10:34
Default
  #4
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by NewKid View Post
Hi, massive_turbulence,
Thanks a lots!
The createClouds.H is one original file of the source files of solver "sprayFoam", what I'm trying to do is to get the "sprayCloud" in the turbulence model file with lookupObject function instead of to declare it in createClouds.H.
Thanks for your kindest helps!
You mean inside the /constant/turbulenceProperties file?

I think you could compile a .so file and call it from "/constant/turbulenceProperties" instead as a type but I'm guessing and it's far fetched in terms of the coding. You would still need to declare it in the createClouds.H and then you create a new library file to your liking and place it in the lib folder, something like "OpenFOAM-v1806/platforms/linux64GccDPInt32Opt/lib/"

Either that or this might help objectRegistry::lookupObject<scalar>
massive_turbulence is offline   Reply With Quote

Old   February 10, 2019, 21:34
Default
  #5
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12
zhangyan is on a distinguished road
Did you try this:
Code:
const basicSprayCloud & cloud = dynamic_cast<const basicSprayCloud&>(this->mesh_.objectRegistry::lookupObject<sprayCloud>("sprayCloud"));
Tobermory likes this.
__________________
https://openfoam.top
zhangyan is offline   Reply With Quote

Old   February 12, 2019, 04:24
Default
  #6
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Hi, ZhangYan, your code works! Thanks very much!
And what's the parcelType of every parcel in this cloud if I have to access every parcel's parameters, such like velocity, mu, density or something like that.
const parcelType& droplet=cloud[index];
NewKid is offline   Reply With Quote

Old   February 12, 2019, 21:55
Question
  #7
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
After getting "cloud" as mentioned above, to traverse the parcels in the cloud, a forAll macro is called as follows:
forAll(cloud,parcelI)
{
const basicSprayParcel& droplet=dynamic_cast<const basicSprayParcel&>(cloud[parcelI]);
}//Compiling error: cloud has no operator []
where parcelI is the "index" in const parcelType& droplet=cloud[index];
Or another macro
forAllConstIter(typename SprayCloud<CloudType>,*cloud,iter)
{
...
}
The latter shows compiling errors too.
NewKid is offline   Reply With Quote

Old   February 12, 2019, 22:21
Default
  #8
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by NewKid View Post
After getting "cloud" as mentioned above, to traverse the parcels in the cloud, a forAll macro is called as follows:
forAll(cloud,parcelI)
{
const basicSprayParcel& droplet=dynamic_cast<const basicSprayParcel&>(cloud[parcelI]);
}//Compiling error: cloud has no operator []
where parcelI is the "index" in const parcelType& droplet=cloud[index];
Or another macro
forAllConstIter(typename SprayCloud<CloudType>,*cloud,iter)
{
...
}
The latter shows compiling errors too.
The bracket operator is probably not overloaded for that type but there might be a function call that returns what you need, otherwise you'll need to write your own overloaded [] and return whatever cloud has at that index.
massive_turbulence is offline   Reply With Quote

Old   February 13, 2019, 14:48
Default
  #9
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
You cannot use a [] operator since a cloud is not a random access array. You can use an iterator access with begin/end. If you are using OpenFOAM-v1712 or newer, the iterators are properly defined and you can use a for-range as well.
olesen is offline   Reply With Quote

Old   February 13, 2019, 15:12
Default
  #10
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by olesen View Post
You cannot use a [] operator since a cloud is not a random access array. You can use an iterator access with begin/end. If you are using OpenFOAM-v1712 or newer, the iterators are properly defined and you can use a for-range as well.
It must be a list then, like a STL list with an iterator?
massive_turbulence is offline   Reply With Quote

Old   February 13, 2019, 22:31
Question
  #11
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Olsen and massive_turbulence, thank both of you!
I tried forAllConstIter macro, anyway, the proper type of iterator, or the parameters of forAllConstIter(typename SprayCloud<CloudType>,*cloud,iter) confuse me since "cloud" is retrieved via "const basicSprayCloud & cloud = dynamic_cast<const basicSprayCloud&>(this->mesh_.objectRegistry::lookupObject<sprayCloud>("s prayCloud"));"
Any clues?
I use OF 4.0.

Last edited by NewKid; February 14, 2019 at 02:23.
NewKid is offline   Reply With Quote

Old   February 13, 2019, 23:09
Default
  #12
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Quote:
Originally Posted by NewKid View Post
Olsen and massive_turbulence, thank both of you!
I tried forAllConstIter macro, anyway, the proper type of iterator, or the parameters of forAllConstIter(typename SprayCloud<CloudType>,*cloud,iter) confuse me since "cloud" is retrieved via "const basicSprayCloud & cloud = dynamic_cast<const basicSprayCloud&>(this->mesh_.objectRegistry::lookupObject<sprayCloud>("s prayCloud"));"
Any clues?
This typename SprayCloud<CloudType> is somehow equivalent to this dynamic_cast<const basicSprayCloud&>(this->mesh_.objectRegistry::lookupObject<sprayCloud>("s prayCloud"))

Dynamic casting works by going up a "tree" of sorts in the object hierarchy and somehow that gets created at runtime. I'm not too clear on the process either.
massive_turbulence is offline   Reply With Quote

Old   February 14, 2019, 02:45
Question
  #13
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
I agree with Olesen, it is impossible to traverse the parcels with operator [], iterator is a good choice!
Therefore, the question is how to traverse the parcels of the "cloud" via iterator, i.e. the parameters of forAllConstIter() macro.
And what is the difference between forAllConstIter() and forAllIter()?
NewKid is offline   Reply With Quote

Old   February 14, 2019, 03:32
Smile Thanks!!! Seems solved!
  #14
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Thanks all the contributors to this thread!
It seems this problem is solved, details come as follows:
1. Get the cloud
const basicSprayCloud & cloud = dynamic_cast<const basicSprayCloud&>(this->mesh_.objectRegistry::lookupObject<sprayCloud>("s prayCloud"));
2. Traverse all the parcels
forAllConstIter(typename basicSprayCloud, cloud, iter)
3. Access every parcel in the cloud
const basciSprayParcel & d =iter();
d has many attributes, enjoy it!
After all the steps above, write your code in turbulence model source file!
Once there is something wrong or not complete/proper, please let me know or email me: swust_lt@sina.com
NewKid is offline   Reply With Quote

Reply

Tags
interaction, lookupobject, spraycloud, template


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
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 17:22
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 05:42
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 01:27
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 09:56
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 06:42


All times are GMT -4. The time now is 11:13.