CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Post-Processing

get values of a scalar in a matrix

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

Like Tree1Likes
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Display Modes
Old   November 8, 2013, 02:32
Default get values of a scalar in a matrix
  #1
Member
 
Join Date: Aug 2011
Posts: 81
Rep Power: 6
idefix is on a distinguished road
At the moment I am facing the following problem:

Ive 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 Ive got two rows of cells which are filled with liquid and three rows with gas above it. Ive 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
idefix is offline   Reply With Quote

Old   November 11, 2013, 13:33
Default
  #2
New Member
 
Adam
Join Date: Mar 2012
Location: St. Paul, MN
Posts: 12
Rep Power: 5
amwitt is on a distinguished road
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.
amwitt is offline   Reply With Quote

Old   November 23, 2013, 06:41
Default
  #3
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,507
Blog Entries: 34
Rep Power: 86
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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: sampling on cellSet
    • 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
hua1015 likes this.

Last edited by wyldckat; December 30, 2013 at 08:51. Reason: see "edit:"
wyldckat is offline   Reply With Quote

Old   November 28, 2013, 03:43
Default
  #4
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
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.
chrisb2244 is offline   Reply With Quote

Old   November 29, 2013, 15:53
Default
  #5
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,507
Blog Entries: 34
Rep Power: 86
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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
wyldckat is offline   Reply With Quote

Old   December 17, 2013, 05:09
Default
  #6
Member
 
Join Date: Aug 2011
Posts: 81
Rep Power: 6
idefix is on a distinguished road
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 dont 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
idefix is offline   Reply With Quote

Old   December 30, 2013, 09:27
Default
  #7
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,507
Blog Entries: 34
Rep Power: 86
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
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 View Post
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: sampling on cellSet
  • 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: irregular model simulation with chtMultiregionFoam post #22.

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   January 3, 2014, 06:20
Thumbs up
  #8
Member
 
Join Date: Aug 2011
Posts: 81
Rep Power: 6
idefix is on a distinguished road
Hello Bruno,

thats 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
idefix is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problems concerning mass conservativity in bubbleFoam with custom scalar transport cutter OpenFOAM Programming & Development 3 February 10, 2015 05:25
Ensight - node values -cell values leo FLUENT 1 May 12, 2010 08:47
strange node values @ solid/fluid interface - help JB FLUENT 2 November 1, 2008 13:04
solving passive scalar by user function in AVLFIRE huyp Main CFD Forum 0 September 4, 2008 10:21
STAR-CD user-defined scalar Murali CD-adapco 0 February 12, 2003 23:52


All times are GMT -4. The time now is 03:00.