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

How to access cellSet elements?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 8, 2018, 18:35
Default How to access cellSet elements?
  #1
Senior Member
 
Join Date: Mar 2018
Posts: 115
Rep Power: 8
anon_q is on a distinguished road
In my code, I can add cell IDs to a cellSet


Code:
cellSet myCellSet
(
   IOobject
    (

    "myCellSet",
    runTime.timeName(),
    runTime,
    IOobject::MUST_READ,
    IOobject::AUTO_WRITE

    )

);
myCellSet.clear();

const volVectorField& C = mesh.C();
const vector origin(0.0,0.0,0.0);

forAll(C, i)
{
      if((mag(C[i] - origin) < 0.6) && (mag(C[i] - origin) > 0.5) )
      {
           myCellSet.insert(i);

      }

}
The problem is that I cannot retrieve elements from the cellSet (I mean it is obvious to use the following syntax to get the first element: myCellSet[0], but this gives something irrelevant. As far as I know I use only the following syntax (exmple to retrieve the first element):
Code:
Info << myCellSet.sortedToc()[0] << endl;
Can you please tell me what is the correct way to retrieve elements from a cellSet.
NOTE: The code works very well and the myCellSet is written to the directories (the remaining code is not shown here).

In summary the question is very simple:
Why the following syntax doesn't give the expected result:
Code:
myCellSet[0]
[COLOR=inherit !important]


#s3gt_translate_tooltip_mini { display: none !important; }
[/COLOR]
anon_q is offline   Reply With Quote

Old   October 10, 2018, 01:04
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

the object myCellSet is based on the class cellSet (https://cpp.openfoam.org/v6/classFoam_1_1cellSet.html). As you can see, there is no operator defined in that class that overloads/defines the operator[] operator. Additionally, you see the inherited functions (from inherited classes). While checking these functions, you can see that the operator[] is defined in the HashSet< label, Hash<label>> class. The operator will do the following:
Code:
bool operator[] (const label &) const
Return true if the entry exists, same as found() More...
Thatīs why you should either get true or false rather than what you expect to get.
Thanks for using code-tags.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   October 10, 2018, 06:22
Default
  #3
Senior Member
 
Join Date: Mar 2018
Posts: 115
Rep Power: 8
anon_q is on a distinguished road
Thank you Tobi.
So
Code:
 myCellSet.sortedToc(i)
is the only way to retrive element with index i?
anon_q is offline   Reply With Quote

Old   October 10, 2018, 07:12
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,
the function you recently added does not exist. This following would be correct
Code:
myObject.sortedToc()[i]
or
Code:
myObject.toc()[i]
However, just check the code (via Doxygen) to see what you can do. The method above will give you the entries inside the hash. However, if you have more entries, you should make sure you get the correct one. I would prefer to use a more convenient method for searching:
Code:
iterator 	find (const label &)
Find and return an iterator set at the hashedEntry. More...
, but out of the box, I cannot give you a suggestion.
__________________
Keep foaming,
Tobias Holzmann
Tobi 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
Access to cellid in cellSet Tobi OpenFOAM Programming & Development 5 April 16, 2017 21:05
Access (x y z) coordinates of cellSet hxaxtma OpenFOAM Programming & Development 1 January 21, 2016 05:40
Ansys SIG$ILL error loth ANSYS 3 December 24, 2015 05:31
How can I access to a volTensorField elements? urgent!!! adambarfi OpenFOAM Running, Solving & CFD 6 May 14, 2013 16:28
CFX4.3 -build analysis form Chie Min CFX 5 July 12, 2001 23:19


All times are GMT -4. The time now is 06:22.