|
[Sponsors] |
February 3, 2019, 04:05 |
Question about lookupObject function
|
#1 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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)? |
|
February 3, 2019, 07:06 |
|
#2 | |
Senior Member
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13 |
Quote:
"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 ); |
||
February 3, 2019, 10:13 |
|
#3 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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! |
|
February 3, 2019, 11:34 |
|
#4 | |
Senior Member
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13 |
Quote:
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> |
||
February 10, 2019, 22:34 |
|
#5 |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12 |
Did you try this:
Code:
const basicSprayCloud & cloud = dynamic_cast<const basicSprayCloud&>(this->mesh_.objectRegistry::lookupObject<sprayCloud>("sprayCloud"));
__________________
https://openfoam.top |
|
February 12, 2019, 05:24 |
|
#6 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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]; |
|
February 12, 2019, 22:55 |
|
#7 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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. |
|
February 12, 2019, 23:21 |
|
#8 | |
Senior Member
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13 |
Quote:
|
||
February 13, 2019, 15:48 |
|
#9 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
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.
|
|
February 13, 2019, 16:12 |
|
#10 |
Senior Member
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13 |
It must be a list then, like a STL list with an iterator?
|
|
February 13, 2019, 23:31 |
|
#11 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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 03:23. |
|
February 14, 2019, 00:09 |
|
#12 | |
Senior Member
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13 |
Quote:
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. |
||
February 14, 2019, 03:45 |
|
#13 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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()? |
|
February 14, 2019, 04:32 |
Thanks!!! Seems solved!
|
#14 |
Senior Member
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15 |
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 |
|
Tags |
interaction, lookupobject, spraycloud, template |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] mesh airfoil NACA0012 | anand_30 | OpenFOAM Meshing & Mesh Conversion | 13 | March 7, 2022 18:22 |
[blockMesh] non-orthogonal faces and incorrect orientation? | nennbs | OpenFOAM Meshing & Mesh Conversion | 7 | April 17, 2013 06:42 |
is internalField(U) equivalent to zeroGradient? | immortality | OpenFOAM Running, Solving & CFD | 7 | March 29, 2013 02:27 |
[blockMesh] error message with modeling a cube with a hold at the center | hsingtzu | OpenFOAM Meshing & Mesh Conversion | 2 | March 14, 2012 10:56 |
ParaView for OF-1.6-ext | Chrisi1984 | OpenFOAM Installation | 0 | December 31, 2010 07:42 |