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

Accessing adjacent cells and cell vertices

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 14, 2021, 10:27
Default Accessing adjacent cells and cell vertices
  #1
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Hello everybody,

I am currently trying to implement a new hybrid turbulence model in OpenFOAM (An Enhanced Version of DES with Rapid Transition from RANS to LES in Separated Flows) but unfortunately got stuck.

At the moment I have two questions.

1)
For calculating the new length scale for the model I first need to access for each cell the cell vertices and the cell center and build the corresponding vectors. Then I need to do calculations with these vectors and the vorticity vector. I guess I need a for-loop for this. How can I do this in OpenFOAM in an efficient way (accessing the center and vertices of the cell and do the calculations)?

2)
For another quantity I need to build the average over the cell and its closest neighbours. How can I access the closest neighbours of a cell in OpenFOAM? This function should also work in parallel computing (If I have to access a neighbour cell from another subdomain for example).

I really appreciate your help. If you need additional information please ask.

Many thanks for your help!
Daniel
CFDanielGER is offline   Reply With Quote

Old   April 14, 2021, 10:56
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
I think I can help with the 2nd question, at least. You can access cell neighbours with cellCells(). I remember seeing/using something like that long ago... here's a good thread with straightforward usage : How to identify cell neighbours.

As for the first question, I'm not quite sure. I imagine that you could get a list of points associated with each cell in a similar way to the way you get the cell neighbours. A quick search and it looks like you can make a list of points, and use indices obtained from cellPoints to pull the coordinates of specific points from that list : Point labels associated with a cell. The cell coordinates are mesh.C() if I remember correctly.

You might also check out what's done in for the IDDESDelta -- it may provide some clues/be a good reference for your implementation.

Hope this helps,
Caelan
__________________
Public git repository : https://github.com/clapointe2011/public
clapointe is offline   Reply With Quote

Old   April 18, 2021, 07:40
Default
  #3
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Thank you very much for your help.

I decided now to first implement an easier version of the new length scale which is based on deltax, deltay and deltaz. I saw from the maxDeltaxyz.C that the maximum delta is already calculated. I also think that it is used in the cubeRootVolDelta.C file.
My question is, do I have to code and calculate the delta in each direction from the beginning or is it also possible to import it?

Many thanks for you help.

Best regards,
CFDaniel
CFDanielGER is offline   Reply With Quote

Old   April 18, 2021, 10:41
Default
  #4
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
I imagine that if your delta is sufficiently similar to an existing one, it'd be easiest to adapt existing code to suit your needs. Building off the preexisting code structure will also help ensure that your DES model will be able to access the new delta as well.

Caelan
__________________
Public git repository : https://github.com/clapointe2011/public
clapointe is offline   Reply With Quote

Old   April 18, 2021, 11:03
Default
  #5
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
What I am currently doing is to adapt the SpalartAllmarasDDES.C file since for calculating the new delta I also need some flow properties and it seemed "easier" to work directly in the turbulence model file than working in a new delta file (I am very unexperienced by coding in OpenFOAM but I got some tipps that working directly in the turbulence model file may be more convenient since I can access easier the flow variables I need).

I am now wondering if I can access the deltas in each direction or if I have to calculate them by myself? For example when I want to access the viscosity or velocity I just write this->nu() or this->U(). Now I am wondering if the same is possible with the deltax/deltay/deltaz.
CFDanielGER is offline   Reply With Quote

Old   April 18, 2021, 11:27
Default
  #6
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
In les turb models, the delta is accessed in a similar way :

Code:
this->delta()
To start, you could probably assume (at the expense of generality) the use of one delta type. Then its calculation is already coded -- you'd probably just need to access it (like above) and then augment the delta in your les model.

Caelan
__________________
Public git repository : https://github.com/clapointe2011/public
clapointe is offline   Reply With Quote

Old   April 18, 2021, 11:58
Default
  #7
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Yes, I also saw this. I think this delta then is dependent on the input you select in the turbulenceProperties file. Since there is only maxDeltaxyz and cubeRootVolDelt available I guess I then have to implement some line of codes to get deltax, deltay and deltaz?

Probably something like this (found in the IDDESDelta.C) but for each direction in x, y and z:

Code:
    scalarField& faceToFacenMax = tfaceToFacenMax.ref().primitiveFieldRef();

    const cellList& cells = mesh.cells();
    const vectorField& faceCentres = mesh.faceCentres();

    forAll(cells, celli)
    {
        scalar maxDelta = 0.0;
        const labelList& cFaces = cells[celli];
        const vector nci = n[celli];

        forAll(cFaces, cFacei)
        {
            label facei = cFaces[cFacei];
            const point& fci = faceCentres[facei];

            forAll(cFaces, cFacej)
            {
                label facej = cFaces[cFacej];
                const point& fcj = faceCentres[facej];
                scalar ndfc = nci & (fcj - fci);

                if (ndfc > maxDelta)
                {
                    maxDelta = ndfc;
                }
            }
        }

        faceToFacenMax[celli] = maxDelta;
    }
CFDanielGER is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
[snappyHexMesh] snappyHexMesh stuck when snap is turned on yukuns OpenFOAM Meshing & Mesh Conversion 3 February 2, 2021 13:05
SimpleFoam & Theater jipai OpenFOAM Running, Solving & CFD 3 June 18, 2019 10:11
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 05:50
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 04:15


All times are GMT -4. The time now is 05:48.