CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   get values of a scalar in a matrix (https://www.cfd-online.com/Forums/openfoam-post-processing/126102-get-values-scalar-matrix.html)

idefix November 8, 2013 01:32

get values of a scalar in a matrix
 
At the moment I am facing the following problem:

Iīve got a cut plane from my 3d grid.
At this plane I have liquid at the bottom (alpha = 1) and gas above (alpha = 0). What I want to have is the value of alpha in every cell in a matrix and the matrix has the form of the cut plane.

For example, my cut plane is a square. At the bottom Iīve got two rows of cells which are filled with liquid and three rows with gas above it. Iīve got 5 columns. The array looks like this:

0 0 0 0 0 Gas
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1 Liquid
1 1 1 1 1

Is it possible to get those matrix of a cut plane calculated with OpenFOAM?

I only get a list of coordinates (x,y,z) and alpha after it with sample.

Can anybody help? Or has an idea how to get to this point?

Thanks a lot

amwitt November 11, 2013 12:33

Is this for post-processing? I had to get the "matrix" look a few months ago the only way that worked for me was to manipulate the data from the list of coordinates using Matlab. First I exported the data, using either a slice in paraView or the alpha1 value and cell centers (using the writeCellCentres utility) from the time directory. Then arrange the x values in ascending order, ensuring that all other columns follow the same arrangement. Then arrange y values in ascending order. Determine the # of x values, and that will be the # of columns in your matrix. Build a matrix that creates a new row each time you reach the final # of x values. Each row corresponds with a y value. Assign your alpha1 values to the matrix. It's a work around, but if you want to do this for many time steps it's easy to import them all and run them through this program since they all have the same format.

wyldckat November 23, 2013 05:41

Greetings to all!

What comes to mind is the following procedure:
  1. Use OpenFOAM to write the cell centres, by running:
    Code:

    writeCellCentres
  2. Use setSet or topoSet to select the cells that are in the desired section cut.
  3. Use sample to write out the values for the cell centres from the selected cells, into CSV format. -- edit: Nope, this doesn't work, because sample is not able to dump values inside "cellSet"s. Nonetheless, there is already a thread on this topic: http://www.cfd-online.com/Forums/ope...g-cellset.html
    • In post #8 on that other thread, there is a nice description how topoSet and foamToVTK can be used.
  4. Use LibreOffice Calc to load the CSV file and sort the positions, if they are not in the desired order.
  5. Use LibreOffice Calc to use the array of cell centres and reformat the data into a format that OpenFOAM can use in sampleDict, namely for point cloud: https://github.com/OpenFOAM/OpenFOAM...ampleDict#L118
    Code:

        somePoints
        {
            type cloud;
            axis xyz;
            points ((0.049 0.049 0.00501)(0.051 0.049 0.00501));
        }

    The format can like this:
    Code:

    points (
    (0.049 0.049 0.00501)
    (0.051 0.049 0.00501)
    );

  6. Last but not least, finally run sample again with the new dictionary.
Best regards,
Bruno

chrisb2244 November 28, 2013 02:43

Is it possible to use this idea to generate a much smaller data set recording the position of just the interface? (if this is already what this thread describes, apologies for misunderstanding)

What I mean is to output a file which lists for example, the coordinate positions of all the cells whose value of alpha1 lies between 0.01 and 0.99 or something.

My guess is that this would be much more quickly rendered in paraview/visit/other post-processing software than the whole dataset, coloured by alpha1, and the only loss would be some pretty colour for the regions with alpha1 =0 or =1.

wyldckat November 29, 2013 14:53

Greetings Christian,

AFAIK, there are at least two ways to extract the surface interface between 2 fluids, as defined in the field "alpha":
  1. In ParaView, as explained here: http://openfoamwiki.net/index.php/Ho...iphase_results - namely step #4.
  2. In OpenFOAM, using the utility sample or the function object "sampling", to extract an isosurface for the 0.5 value of "alpha".
Both of these isosurfaces are usually interpolated surfaces. Therefore, beyond this, it really depends on what exactly you need to extract.


Best regards,
Bruno

idefix December 17, 2013 04:09

Hello Bruno,

I tried to follow your description, but I have some problems.
As far as I understand you I need to create a list of points so that sample can extract the values at these points. (step 6)
This list is created with writeCellCentre and topoSet.
But I donīt get it.
When I did writeCellCentre (step 1), I have in every time-folder the files ccx, ccy and ccz.
Do they have to "communicate" with topoSet (step 2)?
But what is sample doing then there? (step 3)

Could you explain me the steps a bit in detail?

Thanks a lot
idefix

wyldckat December 30, 2013 08:27

Hi idefix,

Sorry about that. I didn't mange to get it a test myself, so I didn't confirm if sample could handle "cellSet"s.

I've edited the other post and added the following information:
Quote:

Originally Posted by wyldckat (Post 463182)
3. [...]edit: Nope, this doesn't work, because sample is not able to dump values inside "cellSet"s. Nonetheless, there is already a thread on this topic: http://www.cfd-online.com/Forums/ope...g-cellset.html
  • In post #8 on that other thread, there is a nice description how topoSet and foamToVTK can be used.


Now that I think about it, sample could use the feature to export data from a "cellSet", "faceSet" and/or "pointSet". I'll see what I can do in the next few days.

Nonetheless, in the meantime, you can rely on using this command, as explained in post #8 on that other thread:
Code:

foamToVTK -cellSet c0 -latestTime -poly
The option "-poly" will enforce that cells are exported as they are. Then open with ParaView the "cellSet" now located in the VTK folder, and then you can export the values in the cell data to CSV.

As for what topoSet does, you can see and example here: http://www.cfd-online.com/Forums/ope...tml#post467934 post #22.

Best regards,
Bruno

idefix January 3, 2014 05:20

Hello Bruno,

thatīs very interesting to know but I have many time steps for which I want to do this postprocessing.

So I start to program a little tool which is based on your ideas:
The main thing is the following (at the moment I am only interesting in the coordinates and alpha1):
Code:


    forAll(timeDirs, timeI)
    {
        // timeI > 0 is necessary to ignore the constant folder
        if (timeI > 0)
        {
            Info << "time: " << timeDirs[timeI].name() << endl;
           
            volScalarField alpha1                               
            (
                IOobject
                (
                    "alpha1",
                    timeDirs[timeI].name(),
                    mesh,
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE
                ),
                mesh       
            );

                 
            forAll(alpha1, cellI)
            {
                               
                // only the celll centres in this box are considered
                if ((mesh.cellCentres()[cellI][0] > xMin) && (mesh.cellCentres()[cellI][0] < xMax) && (mesh.cellCentres()[cellI][1] > yMin) && (mesh.cellCentres()[cellI][1] < yMax) && (mesh.cellCentres()[cellI][2] > zMin) && (mesh.cellCentres()[cellI][2] < zMax) )
                {           
                    // x,y,z-values und alpha1 are saved in the vector data
                    data[zeileDaten][0] = mesh.cellCentres()[cellI][0];
                    data[zeileDaten][1] = mesh.cellCentres()[cellI][1];
                    data[zeileDaten][2] = mesh.cellCentres()[cellI][2];
                    data[zeileDaten][3] = alpha1[cellI];   
                }
            }
    }
}

After this I sort it like I wish the data to be.

Thanks again for your help.
Idefix


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