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

Using boxtocell in custom solver to obtain a list of cells

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Severus

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 8, 2024, 08:09
Default Using boxtocell in custom solver to obtain a list of cells
  #1
Member
 
Divyaprakash
Join Date: Jun 2014
Posts: 74
Rep Power: 12
Divyaprakash is on a distinguished road
I have read that boxtocell is a utility that is used to select cells in a bounding box during preprocessing.

I need the same functionality but inside the custom solver that I am writing. In it, at every time step the origin of the bounding box would change. I looked at the source code of boxtocell.C but I am unable to make sense of it since I am only a beginner in C++.

Can someone please provide some pointers on how I would be able to access boxtocell as a function inside a C++ program?


Some background information:

Basically what I need is to get a list of cells in the neighborhood of a point. The method I am using now only gives me a list of the immediate neighbours.


Code:
const Foam:point rr(0.05, 0.05, 0.005); // Define the point

        label cellIndex = mesh.findCell(rr);

        // Get the neighboring cells
        const Foam::labelList& neighbors = mesh.cellCells()[cellIndex];

I can use neighbours of neighbours to get more cells, but then that would lead to repition of cells. I am therefore thinking of using boxtocell as a function if that is possible.
However if another method exists to solve this problem, then please do suggest.

Last edited by Divyaprakash; March 8, 2024 at 08:20. Reason: more information
Divyaprakash is offline   Reply With Quote

Old   March 10, 2024, 08:40
Default
  #2
Member
 
Shravan
Join Date: Mar 2017
Posts: 75
Rep Power: 9
Severus is on a distinguished road
Hello,
I will try to explain to you how the boxToCell code works, with this you can fit the logic inside your solver.
I will use Foundation version 9 for an example here
https://cpp.openfoam.org/v9/boxToCell_8H_source.html
https://cpp.openfoam.org/v9/boxToCell_8C_source.html

In order to understand the meaning of the variables and member functions in the .C file, take a look at the .H file carefully. These variables are initialized or assigned values using the Constructors (in the .C file). Here you have 2 public member functions and 1 private member function.

The public member function that does the operation of setting the values to the desired box is applyToSet(). So first take a look at that member function applyToSet(). It basically adds or removes cell centers by calling the private member function combine(). And the combine() member function basically chooses the necessary box which you would like to patch using setFields.

So the combine() member function is the one that you should be looking carefully into, for your purpose.


So, now lets try to understand what combine() does. I have commented the lines below for you to understand better
Code:
void Foam::boxToCell::combine(topoSet& set, const bool add) const
 {
     const pointField& ctrs = mesh_.cellCentres(); // Store the cell centres in your mesh in ctrs
 
     forAll(ctrs, celli) // Loop over the cell centres
     {
         forAll(bbs_, i) // Loop over the coordinates that you intend to patch inside (which has been specified in setFields - see that bbs_ is read from the dictionary, so it takes the coordinate values from setFields file)
         {
             if (bbs_[i].contains(ctrs[celli])) // If your cell centre from the mesh (ctrs) lies inside the block that you like to patch (bbs_)
             {
                 addOrDelete(set, celli, add); // Defined in class topoSetSource
                 break;
             }
         }
     }
 }
Note: In order to use this in your code you also have to understand all the dependent classes and so check the dependency graphs. So you have to include the correct files so that you are able to compile without errors.
https://cpp.openfoam.org/v9/boxToCell_8H.html
https://cpp.openfoam.org/v9/boxToCell_8C.html

I see that it is a little different for the ESI version, but if you try to understand along the lines I have mentioned, you should be able understand how it is implemented in the ESI version, and eventually put it in your code. Also look at the ESI user guide to understand better: https://www.openfoam.com/documentati...boxToCell.html

Good luck!
Divyaprakash likes this.
Severus is offline   Reply With Quote

Reply

Tags
boxtocell, setfields, toposet


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
foam-extend-4.1 release hjasak OpenFOAM Announcements from Other Sources 19 July 16, 2021 06:02
Compiling custom solver for profiling rku OpenFOAM Programming & Development 0 June 24, 2021 05:12
Error with custom solver simulation heitorvitorc OpenFOAM Running, Solving & CFD 0 April 21, 2019 14:05
[ANSYS Meshing] Help with element size sandri_92 ANSYS Meshing & Geometry 14 November 14, 2018 08:54
Problems with running a custom solver: "Unknown psiCombustionModel" AlexKam OpenFOAM Programming & Development 25 November 23, 2015 21:51


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