CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How can I access the updated coordinates on a rotating region from a functionObject (https://www.cfd-online.com/Forums/openfoam-programming-development/239036-how-can-i-access-updated-coordinates-rotating-region-functionobject.html)

NotOverUnderated October 17, 2021 13:47

How can I access the updated coordinates on a rotating region from a functionObject
 
Hello,


I have tried both the coded function object, and implemented a custom function object using foamNewFunctionObject to print the coordinates of a cell on a rotating cellZone. When I invoke the function object, the Velocity is returned correctly and changes with time, however, the coordinates printed of the cell do not change with time, even though the cellZone is correctly rotating.

How can I solve that? in other words; how can I get the updated coordinates of cells in a rotating cellZone from within a functionObject?

I am stuck, and can't progress further without solving that issue.
Could you please provide me some insights?

(I am using OpenFOAM7)

Thank you

brammekeuh987 October 18, 2021 09:02

Hi D.Frank

Could you post your code?
The simple answer is: you'll need to update the mesh or load the updated mesh. Most probably your reading the 'constant/polyMesh" over and over instead of the updated mesh

regards

s1291 October 18, 2021 17:45

Use writeCellCentres function object then use readFields Function object to read the centers as volVectorField.

NotOverUnderated October 18, 2021 17:49

Here is a minimal example:

Code:

type coded;
libs ("libutilityFunctionObjects.so");

name printMovingCoordinates;

codeWrite
#{

        // The velocity field
        const volVectorField& U = mesh().lookupObject<volVectorField>("U");

        // the id of myZone
        label zoneId = mesh().cellZones().findIndex("myZone");

        label cell_id = -1;

        if (zoneId != -1)
        {
                const cellZone& zone = mesh().cellZones()[zoneId];
                const cellZoneMesh& zoneMesh = zone.zoneMesh();
                const labelList& cellsZone = zoneMesh[zoneId];

                forAll(cellsZone, i)
                {
                        cell_id = cellsZone[i];
                       
                        Info << "The velocity is changing " << U[cell_id] << endl;
                        Info << "But the cells are not changing over time: " C[cell_id] << endl;
                }
        }

#}


brammekeuh987 October 19, 2021 02:48

Hi D.Frank

The code is correct: your cell_id isn't changing, and it shouldn't change. These ID's are the reference towards your cells. As per your code: your cell_id is a 'label' not a 'vector'. So your code is correct, but you're missing the link between the cell_id and the calculation of the cell centre.

You can do as s1291 suggests, or manipulate the source code of the writeCellCenters function into your custom function.
Or depending on what you're doing this thread could also help: https://www.cfd-online.com/Forums/op...ngly-file.html

Hope this helps!


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