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/)
-   -   Post processing an internal plane/surface (https://www.cfd-online.com/Forums/openfoam-post-processing/239736-post-processing-internal-plane-surface.html)

CallumG November 22, 2021 05:18

Post processing an internal plane/surface
 
Hi Foamers,

I know there are a few threads on this but I am incredibly confused with them all and I know some of the information is outdated so I'm going to ask again.

I'm generating very large case files on our server and I want to postProcess single planes of data for export.

I have a very simple rectangular domain and I would like to "slice/cut plane/internal surface" (whatever you want to call it!) so I am taking the field data from central y-normal and x-normal planes and later view them in ParaView.

Could anyone clarify (for dummies!) how to do this?

I should mention I'm on v1912.

Cheers,
Callum

tomf November 24, 2021 05:15

Hi Callum,

There is a tutorial that uses the surfaces functionObject for this.

Please have a look at:

$FOAM_TUTORIALS/incompressible/pimpleFoam/RAS/propeller/

The relevant files are the controlDict and the surfaces files in the system folder. As you see, the surfaces file is read in the functions subDict of the controlDict. The example usage of the surfaces functionObject is described in the surfaces file.

You would need to modify it towards your needs, but I think you should get it from there.

Cheers,
Tom

CallumG December 14, 2021 04:22

Hi Tom,

thanks very much for your reply and the advice!

For the benefit of others I ended up adding the following to my controlDict:

Code:

functions
{   
    cuttingPlanes
    {
        type              surfaces;
        outputControl    timeStep;
        outputInterval    1;
        surfaceFormat    vtk;
        fields  (U alpha.water);
        interpolationScheme          cellPoint;
        surfaces
            (
                yplane
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    point (0 -5.5 0);
                    normal (0 -1 0);
                }
                interpolate true;
                }
                xplane
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    point (5 0 0);
                    normal (1 0 0);
                }
                interpolate true;
                }
            );
    }
}

This made vtk's for each plane I created (xplane and yplane) in my postProcessing directory for each timestep. After that I needed to make a series file to view the vtk's continuosly in Paraview. I did this in python and the code looked something like this:

Code:

import os

def main():
    cutPlanesDir = "postProcessing/cuttingPlanes/"

    directories = os.listdir(cutPlanesDir)
    directories.sort()
    directories = [d for d in directories if "series" not in d]

    with open(cutPlanesDir+"yplane.vtp.series", 'w') as yf:
        yf.write("{\n")
        yf.write("  \"file-series-version\" : \"1.0\",\n")
        yf.write("  \"files\" : [\n")
    with open(cutPlanesDir+"yplane.vtp.series", 'a') as yf:
        for time in directories:
            if time != directories[-1]:
                yf.write("    { \"name\" : \""+time+"/yplane.vtp\", \"time\" : "+time+" },\n")
            else:
                yf.write("    { \"name\" : \""+time+"/yplane.vtp\", \"time\" : "+time+" }\n")
        yf.write("  ]\n")
        yf.write("}")

    with open(cutPlanesDir+"xplane.vtp.series", 'w') as yf:
        yf.write("{\n")
        yf.write("  \"file-series-version\" : \"1.0\",\n")
        yf.write("  \"files\" : [\n")
    with open(cutPlanesDir+"xplane.vtp.series", 'a') as yf:
        for time in directories:
            if time != directories[-1]:
                yf.write("    { \"name\" : \""+time+"/xplane.vtp\", \"time\" : "+time+" },\n")
            else:
                yf.write("    { \"name\" : \""+time+"/xplane.vtp\", \"time\" : "+time+" }\n")
        yf.write("  ]\n")
        yf.write("}")
    return

if __name__ == "__main__":
    main()

Thanks again community, hope this is useful for others!

Callum

tomf December 14, 2021 04:29

Hi Callum,

Glad you got it working.

Just a final hint (also for others) as there is a utility in OpenFOAM that can do the 'series' for you. It is called foamSequenceVTKFiles. If you have the .vtp extension it is invoked as:

Code:

foamSequenceVTKFiles -vtp
This will create a folder sequencedVTK with links inside that folder to the original files and the naming is sequential, such that ParaView can interpret this as a series of files. May safe some additional disk space/time.

Cheers,
Tom

CallumG December 14, 2021 05:29

Excellent Tom!

I only wrote my own script because when I tried the command foamSequenceVTKFiles it didn't work, which I'm assuming is because I didn't use the flag '-vtp'.

Brilliant! Merry Christmas Foamers!!

olesen December 16, 2021 03:49

Quote:

Originally Posted by CallumG (Post 818474)
Hi Tom,

thanks very much for your reply and the advice!

For the benefit of others I ended up adding the following to my controlDict:

Code:

functions
{   
    cuttingPlanes
    {
        type              surfaces;
        outputControl    timeStep;
        outputInterval    1;
        surfaceFormat    vtk;
        fields  (U alpha.water);
        interpolationScheme          cellPoint;
        surfaces
            (
                yplane
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    point (0 -5.5 0);
                    normal (0 -1 0);
                }
                interpolate true;
                }
                xplane
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    point (5 0 0);
                    normal (1 0 0);
                }
                interpolate true;
                }
            );
    }
}

This made vtk's for each plane I created (xplane and yplane) in my postProcessing directory for each timestep. After that I needed to make a series file to view the vtk's continuosly in Paraview.
....

I am a bit surprised at your result. I know that the Ensight and VTK surface writers both add time-collation to their output, but the VTK writers should ideally also be creating the series file. This is either an oversight, or not feasible for some other reason - it could be worthwhile adding an issue on develop.openfoam.com - if nothing else, at least to document why it is that way.

BTW: all of the machinery for generating vtk.series files is already in there (src/fileFormats) and it is most certainly being used for foamToVTK, for example.

farzadmech September 24, 2023 14:57

Thanks a lot for your explanation, it was helpful.

Farzad
Quote:

Originally Posted by CallumG (Post 818474)
Hi Tom,

thanks very much for your reply and the advice!

For the benefit of others I ended up adding the following to my controlDict:

Code:

functions
{   
    cuttingPlanes
    {
        type              surfaces;
        outputControl    timeStep;
        outputInterval    1;
        surfaceFormat    vtk;
        fields  (U alpha.water);
        interpolationScheme          cellPoint;
        surfaces
            (
                yplane
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    point (0 -5.5 0);
                    normal (0 -1 0);
                }
                interpolate true;
                }
                xplane
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    point (5 0 0);
                    normal (1 0 0);
                }
                interpolate true;
                }
            );
    }
}

This made vtk's for each plane I created (xplane and yplane) in my postProcessing directory for each timestep. After that I needed to make a series file to view the vtk's continuosly in Paraview. I did this in python and the code looked something like this:

Code:

import os

def main():
    cutPlanesDir = "postProcessing/cuttingPlanes/"

    directories = os.listdir(cutPlanesDir)
    directories.sort()
    directories = [d for d in directories if "series" not in d]

    with open(cutPlanesDir+"yplane.vtp.series", 'w') as yf:
        yf.write("{\n")
        yf.write("  \"file-series-version\" : \"1.0\",\n")
        yf.write("  \"files\" : [\n")
    with open(cutPlanesDir+"yplane.vtp.series", 'a') as yf:
        for time in directories:
            if time != directories[-1]:
                yf.write("    { \"name\" : \""+time+"/yplane.vtp\", \"time\" : "+time+" },\n")
            else:
                yf.write("    { \"name\" : \""+time+"/yplane.vtp\", \"time\" : "+time+" }\n")
        yf.write("  ]\n")
        yf.write("}")

    with open(cutPlanesDir+"xplane.vtp.series", 'w') as yf:
        yf.write("{\n")
        yf.write("  \"file-series-version\" : \"1.0\",\n")
        yf.write("  \"files\" : [\n")
    with open(cutPlanesDir+"xplane.vtp.series", 'a') as yf:
        for time in directories:
            if time != directories[-1]:
                yf.write("    { \"name\" : \""+time+"/xplane.vtp\", \"time\" : "+time+" },\n")
            else:
                yf.write("    { \"name\" : \""+time+"/xplane.vtp\", \"time\" : "+time+" }\n")
        yf.write("  ]\n")
        yf.write("}")
    return

if __name__ == "__main__":
    main()

Thanks again community, hope this is useful for others!

Callum



All times are GMT -4. The time now is 19:56.