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

Sample a volume field

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By olesen
  • 1 Post By Agavi
  • 1 Post By lukasf
  • 1 Post By Luiz

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 9, 2010, 04:47
Default Sample a volume field
  #1
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Dear all,

I would like to "sample a volume", i.e. write out a volumetric field as raw data. I normally use the sample utility, but that samples points, lines, and surfaces. Does anyone know a trick to write out a volumetric field in the same way sample writes out e.g. a surface? Is the only option writing a "volume function" in the sample utility or python scripting with paraview? Thanks in advance!
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   November 10, 2010, 10:42
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by gwierink View Post
Dear all,

I would like to "sample a volume", i.e. write out a volumetric field as raw data. I normally use the sample utility, but that samples points, lines, and surfaces. Does anyone know a trick to write out a volumetric field in the same way sample writes out e.g. a surface? Is the only option writing a "volume function" in the sample utility or python scripting with paraview? Thanks in advance!

"foamToVTK -cellSet" might help.
lukasf likes this.
olesen is offline   Reply With Quote

Old   November 10, 2010, 11:36
Default
  #3
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Hi Mark,

Thanks for your reply.

I would like to get the alpha field with xyz coordinates out of a twoPhaseEulerFoam case. So, what I now tried is to run cellSet with the following cellSetDict:

Code:
// Name of set to operate on
name alpha;//c0;

// One of clear/new/invert/add/delete|subset/list
action new;

// Actions to apply to cellSet. These are all the topoSetSource's ending
// in ..ToCell (see the meshTools library).

topoSetSources
(
    // Cells with cell centre within box
    boxToCell
    {
       box   (0 0 0) (1 1.5 1);
    }

    // values of field within certain range
    fieldToCell
    {
        fieldName   alpha;//U;      // Note: uses mag(U) since volVectorField
        min         0.0;
        max         1.0;
    }
);
This created a list of cellID's (?) in constant/polyMesh/sets/alpha. Then I did
Code:
foamToVTK -cellSet alpha
which seemingly created the same VTK case but named alpha. Am I doing something wrong here to get out xyz-alpha or overlooking something? Many thanks in advance!
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   May 8, 2014, 08:18
Default Sampling data in twoPhaseEulerFoam
  #4
Member
 
Gitesh
Join Date: Jan 2010
Location: Finland
Posts: 73
Rep Power: 16
Gitesh P is on a distinguished road
Hello,

I want to store volume averaged values of some fields (i.e., alpha, k and epsilon) only in particular area of interest (around the interface region) in twoPhaseEulerFoam.

Does we have any utility in OpenFOAM which can be useful to achieve the data?

Thanks in advanced!

With regards,
GP
Gitesh P is offline   Reply With Quote

Old   June 5, 2014, 07:54
Default topoSet and foamToVtk
  #5
New Member
 
Renato Sousa
Join Date: Jul 2013
Posts: 2
Rep Power: 0
renatogsousa is on a distinguished road
take a look at topoSet utility with topoSetDict, I'm still exploring it but it might create a set with the cells that you want according to different filter options.
then use the foamToVtk with the -cellSet option to extract the values from your set.
renatogsousa is offline   Reply With Quote

Old   March 11, 2021, 07:01
Default Sample volumes instead of only surfaces or points
  #6
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Hi,

there are functions to sample data from points and surfaces.


However, is there a libsampling function which can sample volumes in my domain during runtime?


There are 6 Valid function types :
patchProbes
probes
psiReactionThermoMoleFractions
rhoReactionThermoMoleFractions
sets
surfaces

I tried to use "sets".
Moreover, I used a topoSetDict to define the cell volume of interest:


Code:
actions
(
    {
        name volume_of_interest;
        type cellSet;
        action new;
        source boxToCell;
        sourceInfo
        {
        box (0.1 -0.06 -0.06) (0.16 0.06 0.06);
        }
    }
  );
How can I tell OpenFoam to use this set and sample the cell data?

I tried this but it is not working so far.


Code:
    sample_volume //Name of the sample plane folder in /postprocessing
    {
            type sets;         
            libs (sampling);
            writeControl timeStep;
            timeStart 0;
            writeInterval 1;
            surfaceFormat vtk;
             interpolationScheme cell;

            fields
            (
                U
            );

            sets
             (volume_of_interest);
        }
lukasf is offline   Reply With Quote

Old   June 30, 2021, 17:23
Default
  #7
New Member
 
Join Date: Aug 2020
Posts: 20
Rep Power: 6
Agavi is on a distinguished road
Hi lukasf,

any luck with that?

Thank you
Agavi is offline   Reply With Quote

Old   July 1, 2021, 03:48
Default
  #8
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Unfortunately not, any suggestions?
lukasf is offline   Reply With Quote

Old   July 1, 2021, 11:57
Default
  #9
New Member
 
Join Date: Aug 2020
Posts: 20
Rep Power: 6
Agavi is on a distinguished road
Hi Lukas,

I couldn't figure a staightforward way. The volFieldValue solution posted in this thread ( sampling on cellSet ) produced an empty file in latestTime/ instead of the values at the cells of the cellSet. I'm using OF 2006 so maybe there are some differences there.

I ended up making a coded function object that reads the field and the cellSet Id list and prints just the field values of the cells in the cellSet.

Here is the function object:


sampleCellSet
{
type coded;
libs (utilityFunctionObjects);
name sampleCellSet;
writeControl timeStep;
writeInterval 1;
codeWrite
#{
Info << " Sampling cellSet..." ;

const Time& runTime = mesh().time();

cellSet sampleSet(mesh(), "wakeSet");
volVectorField U = mesh().lookupObject<volVectorField>("U");

fileName timeDir = runTime.path()/runTime.timeName();

if (!isDir(timeDir))
{
mkDir(timeDir);
}

OFstream file(timeDir/"U_wake.dat");

forAll(mesh().C(), id)
{
if (sampleSet[id])
{
file << U[id] << endl;

}
}
Info << "done. " <<endl;

#};
codeInclude
#{
#include "cellSet.H"
#};
codeOptions
#{
#};
}


Surely there are better ways to go about it but for me this is a simple way to avoid interpolations of data, as long as I need the values at the cell centres.

Best
lukasf likes this.
Agavi is offline   Reply With Quote

Old   July 6, 2021, 03:44
Default
  #10
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Hi Agavi,

thanks for sharing.

You are right that the following code returns emtpy fields (OF v1912).

Code:
volFieldValue2
{
    // Mandatory entries (unmodifiable)
    type            volFieldValue;
    libs            (fieldFunctionObjects);

    // Mandatory entries (runtime modifiable)
    fields          (U);
    operation       none;
    regionType      cellZone;
    name               box;

    // Optional entries (runtime modifiable)
    postOperation   none;
    //weightField     alpha1;

    // Optional (inherited) entries

    writeFields     true; //false;

    scalingFactor   1.0;
    region          region0;
    enabled         true;
    log             true;
    writePrecision  8;
    writeToFile     true;
    useUserTime     true;

    timeStart       0;
    timeEnd         1000;

    executeControl  timeStep;
    executeInterval 1;
    writeControl    timeStep; //adjustableRunTime;
    writeInterval   1;
}
The following code from "(sampling on cellSet)" works for OF 4,5... but not for the ESI OF because "type volRegion" does not exist.

Code:
cellObj1
    {
        type            volRegion;
        libs ("libfieldFunctionObjects.so");
        enabled         true;
        writeControl    adjustableRunTime;
        writeInterval   0.01;
        log             true;
        writeFields     true;
        regionType      cellZone;
        name      d0z;
        operation       none;

        fields
        (
            p
            U
        );
    }
One could probably move this Code from OF 4,5 to the OF ESI Versions (v1912, v2106...)

Your code does work to create .dat files with the field content. Thank you! How do you post process this format to visualize it in ParaView or load it into Matlab / Python? How do you read the matching coordinates of the cells from the cellSet (or cellZone?)
lukasf is offline   Reply With Quote

Old   January 21, 2022, 07:29
Default
  #11
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Hi,

I am planing to do the following to sample volumes and apply the DMD.

1. I need to sample a volume within my simulation. I could not find a function which does this for me. So there are 2 options:
Option1: use a topoSetDict to define a cellSet. Export the cellCenters with paraview to a .csv file. I could read this file and create probe points at those locations of the cellSet. I am not sure how good this idea is if your region of interest has e.g. 10 million cells which would lead to 10 million files.

Option2 is which I prefer. I just save the whole 3D field. Afterwards I use the function foamToVTK to create VTK files which are readable by ParaView:
Code:
foamToVTK -cellSet DMD_cellset -time '0.1:0.2' -useTimeName -ascii -excludePatches '(".*")' -noFaceZones
Then I need a e.g. python script which reads the VTK files into it. Then I will adjust a DMD code from e.g.
https://github.com/mathLab/PyDMD#readme.

Afterwards, I need to save the postprocessing result of the DMD into the VTK format again so that I can postprocess the solution further with Paraview.

I am happy for any ideas to improve this approach.


Lukas
lukasf is offline   Reply With Quote

Old   February 2, 2022, 10:23
Default
  #12
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
The problem was using v1912. v2112 does not have a problem using the volFieldValue function.


Code:
    volFieldValue1
    {
        type                volFieldValue;
        libs                 ("libfieldFunctionObjects.so");
        log                  false; //true;
        writeControl adjustableRunTime;
        writeFormat     ascii; //binary;
        writeInterval 1e-5;
        writeFields       true;//writes the fields of the volume
        //timeStart       0;
        //timeEnd         1000;
        regionType       cellSet; //cellZone;
        name               box; // box is the cellSet or cellZone defined by the topoSetDict
        operation         none; 
        fields
        (
            U T p
        );
    }
This code did not work for the ESI version v1912. The fields where just empty. However, using version V2112 (same code) results in all values written into the files.

One receives a file in postProcessing/volFieldValue1 which is not important.
The volume field is directly written to the time directories or time directories of the processor0.

In this directory I run this command.

Code:
                         foamToVTK -cellSet box -useTimeName -excludePatches '(".*")' -noFaceZones
This way I get .vtk files which are visualized more nicely in ParaView.
Moreover, I source a non ESI openfoam Version for the foamToVTK command because this way the "-useTimeName" is available which I prefer.
lukasf is offline   Reply With Quote

Old   September 19, 2022, 12:45
Default
  #13
New Member
 
Luiz Oliveira
Join Date: Aug 2018
Location: Napoli, Italy
Posts: 24
Rep Power: 8
Luiz is on a distinguished road
I confirm that this solution also works for v2206, with a small change into the last step, because -useTimeName and -excludePatches entries are now deprecated.
Code:
foamToVTK -cellSet extendedPorousZone -exclude-patches '(".*")' -noFaceZones
However, w
hile OpenFOAM is writing the variable values at the specified writeInterval, foamToVTK is ignoring the variable specific to the volFieldValue (U_cellSet-box). The write intervals are different, the whole simulation is save in a bigger interval than the volFieldValue function, and I hypothesise that this might be the main issue. So far I tried to:
  1. Change -exclude-patches '(".*")' to -no-boundary
  2. Change from cellSet to cellZone
  3. Rename the created variable U_cellSet-box to U
  4. Suppress time 0, as this one has extra variables
Does anyone know how to convert this data into vtk?
__________________
Luiz Oliveira
PhD. Student in Environmental Fluid Dynamics
University of Napoli: Federico II
Luiz is offline   Reply With Quote

Old   September 20, 2022, 04:34
Default
  #14
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Hi Luiz,

I ended up not using the sample volume field method because of this problem.

My Workflow right now:

1. Saving the whole flow field (Downside: One has to stop the simulation before the sampling interval, to adjust PurgeWrite and the WriteInterval in the controlDict)
2. Reconstructing of the time range of interest
3. Formatting the OpenFOAM solution to VTK and selecting specific volume region (cellSet)
foamToVTK -cellSet DMDVolume -no-point-data -fields '(T U)' -time '0.164960439:0.1699812643'

I think I used "no point data" to reduce the file size.
4. Remove reconstructed fields with foamListTimes -time ‘:’ -rm .. (save disk space)

I am happy if you find a better solution and share it here.
Luiz likes this.
lukasf is offline   Reply With Quote

Old   September 22, 2022, 11:23
Default
  #15
New Member
 
Luiz Oliveira
Join Date: Aug 2018
Location: Napoli, Italy
Posts: 24
Rep Power: 8
Luiz is on a distinguished road
Hi Lukas,


This sounds like a good workflow, at the end this is what I've doing in the past as well to increase the saving frequency. I did not think about exporting into vtk for long storage, although I will certainly give it a try. I would only suggest a small change into your first step. You can automate changes into any OF file using the following procedure, this implies that you do not have to stop the simulation if you have runTimeModifiable option as yes in controlDict:

Code:
functions
 {
     saveFrequencyUpdate
     {
         type                      timeActivatedFileUpdate;
        libs                        ("libutilityFunctionObjects.so");
         writeControl            timeStep;
        writeInterval           1;
        fileToUpdate            "$FOAM_CASE/system/controlDict";
        timeVsFile
        (
            (-1 "$FOAM_CASE/system/controlDict.0")    // Initial time
            (150 "$FOAM_CASE/system/controlDict.150")  // Begin sampling
        );
    }
}
This command will substitute the controlDict file on the run. You only need to specify what is the name of the file (source) and when you want to substitute it.


PS: Since we are both interested into saving disk space. I recommend saving all the data into binary instead of ASCII. This saved a great amount of space in all my simulations, even if I was using compressed ASCII before.
lukasf likes this.
__________________
Luiz Oliveira
PhD. Student in Environmental Fluid Dynamics
University of Napoli: Federico II

Last edited by Luiz; September 22, 2022 at 11:31. Reason: Disk spacing tips
Luiz is offline   Reply With Quote

Old   September 22, 2022, 12:49
Default
  #16
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
I think the good thing about vtk format is that:

1. you could reduce your domain further to save disk space

-cellSet DMDVolume

2. you can only extract the fields of interest

-fields '(T U)'

3. python can read and manipulate the files easily

4. paraview can visualize the files

lukasf is offline   Reply With Quote

Reply


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
How to compare volume scalar field with constant values sachin OpenFOAM Running, Solving & CFD 4 April 11, 2019 04:34
FloWorks (Flow Express) Volume Goal Setting Issue rbigelow FloEFD, FloWorks & FloTHERM 1 November 16, 2009 02:32
FloWorks (Flow Express) Volume Goal Setting rbigelow Main CFD Forum 0 November 13, 2009 15:28
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51
fluent add additional zones for the mesh file SSL FLUENT 2 January 26, 2008 12:55


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