# get values of a scalar in a matrix

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

 November 8, 2013, 02:32 get values of a scalar in a matrix #1 Member   Join Date: Aug 2011 Posts: 74 Rep Power: 5 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

 November 11, 2013, 13:33 #2 New Member   Adam Join Date: Mar 2012 Location: St. Paul, MN Posts: 12 Rep Power: 5 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.

 November 23, 2013, 06:41 #3 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,301 Blog Entries: 34 Rep Power: 84 Greetings to all! What comes to mind is the following procedure: Use OpenFOAM to write the cell centres, by running: Code: `writeCellCentres` Use setSet or topoSet to select the cells that are in the desired section cut. 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 cellSetIn post #8 on that other thread, there is a nice description how topoSet and foamToVTK can be used. Use LibreOffice Calc to load the CSV file and sort the positions, if they are not in the desired order. 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) );``` Last but not least, finally run sample again with the new dictionary. Best regards, Bruno hua1015 likes this. __________________ OpenFOAM: Frequently Asked Questions | Useful links for building and using Forum: How to ask for help | Posting code and output with [CODE] My to-do list and when I'll be able to come to the forum: http://wyldckat.github.io And please: Read this before sending private messages to me Last edited by wyldckat; December 30, 2013 at 08:51. Reason: see "edit:"

 November 28, 2013, 03:43 #4 Member   Christian Butcher Join Date: Jul 2013 Location: Japan Posts: 84 Rep Power: 4 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.

 November 29, 2013, 15:53 #5 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 8,301 Blog Entries: 34 Rep Power: 84 Greetings Christian, AFAIK, there are at least two ways to extract the surface interface between 2 fluids, as defined in the field "alpha": In ParaView, as explained here: http://openfoamwiki.net/index.php/Ho...iphase_results - namely step #4. 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 __________________ OpenFOAM: Frequently Asked Questions | Useful links for building and using Forum: How to ask for help | Posting code and output with [CODE] My to-do list and when I'll be able to come to the forum: http://wyldckat.github.io And please: Read this before sending private messages to me

 December 17, 2013, 05:09 #6 Member   Join Date: Aug 2011 Posts: 74 Rep Power: 5 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

December 30, 2013, 09:27
#7
Super Moderator

Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,301
Blog Entries: 34
Rep Power: 84
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 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

 January 3, 2014, 06:20 #8 Member   Join Date: Aug 2011 Posts: 74 Rep Power: 5 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

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post cutter OpenFOAM Programming & Development 3 February 10, 2015 05:25 leo FLUENT 1 May 12, 2010 08:47 JB FLUENT 2 November 1, 2008 13:04 huyp Main CFD Forum 0 September 4, 2008 10:21 Murali CD-adapco 0 February 12, 2003 23:52

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