ladybug-tools / butterfly

:butterfly: A light python API for creating and running OpenFoam cases for CFD simulation.
http://ladybug-tools.github.io/butterfly.html
GNU General Public License v3.0
246 stars 70 forks source link

[BUG] ? Function Objects #304

Open gamemakerh opened 6 years ago

gamemakerh commented 6 years ago

I'm investigating function object block because I want to make automatic post-process.

Please look at these comparison code. The first one is from input panel block

streamLines
                    {
                            type            streamLine;     //8
                            writeControl    writeTime;      //5
                            setFormat       vtk;            //6
                            trackForward    true;           //4
                            fields          (p U);          //2
                            lifeTime        10000;          //3
                            nSubCycle       5;              //1
                            cloud           particleTracks; //7
                                    seedSampleSet
                                            {
                                                    type            uniform;                //3
                                                    axis            x;                      //1
                                                    start           (-1.001 1e-07 0.0011);  //4
                                                    end             (-1.001 1e-07 1.0011);  //2
                                                    nPoints         20;                     //5
                                            }
                    }

            cuttingPlane
                    {
                            type            surfaces;                                       //
                            libs            ("libsampling.so");                             //
                            writeControl    writeTime;                                      //
                            surfaceFormat   vtk;                                            //
                            fields          (p U);                                          //
                            interpolationScheme cellPoint;                                  //
                                    surfaces
                                    (
                                            yNormal
                                            {
                                                    type cuttingPlane;                      //
                                                    planeType pointAndNormal;               //
                                                            pointAndNormalDict
                                                                    {
                                                                        point   (0 0 0.5);  //
                                                                        normal  (0 0 1);    //
                                                                    }
                                                            interpolate true;               //
                                            }
                                    );
                    }
    forces
    {
        type            forceCoeffs;
        libs            ("libforces.so");
        writeControl    timeStep;
        writeInterval   1;
        patches         ("motorBike.*");
        rho             rhoInf;
        log             true;
        rhoInf          1;
        liftDir         (0 0 1);
        dragDir         (1 0 0);
        CofR            (0.72 0 0);
        pitchAxis       (0 1 0);
        magUInf         20;
        lRef            1.42;
        Aref            0.75;
    }

And the second is from controlDict.

functions
{
    streamLines
    {
        nSubCycle       5;
        fields      (p U);
        lifeTime        10000;
        trackForward        true;
        writeControl        writeTime;
        setFormat       vtk;
        cloud       particleTracks;
        type        streamLine;
        seedSampleSet
        {
            axis        x;
            end     (-1.001 1e-07 1.0011);
            type        uniform;
            start       (-1.001 1e-07 0.0011);
            nPoints     20;
        }
    }
    cuttingPlane
    {
        libs        ("libsampling.so");
        surfaces         (             yNormal    // ------- ?????????????????? there is no second bracket [BUG] ? //
        {
            interpolate     true;
            type        cuttingPlane;
            planeType       pointAndNormal;
            pointAndNormalDict
            {
                normal      (0 0 1);
                point       (0 0 0.5);
            }
        }
        fields      (p U);
        surfaceFormat       vtk;
        writeControl        writeTime;
        type        surfaces;
        interpolationScheme     cellPoint;
    }
    forces
    {
        CofR        (0.72 0 0);
        libs        ("libforces.so");
        magUInf     20;
        rhoInf      1;
        patches     ("motorBike.*");
        writeInterval       1;
        lRef        1.42;
        log     true;
        rho     rhoInf;
        writeControl        timeStep;
        liftDir     (0 0 1);
        type        forceCoeffs;
        Aref        0.75;
        dragDir     (1 0 0);
        pitchAxis       (0 1 0);
    }
}

The lines are swiched and some parts of code is not transfered into controlDict. Maybe someone can fix this bug ?

I'm using these files from $FOAM_TUTORIALS/incompresible/pisoFoam/LES/motorBike/motorBike/

image

gamemakerh commented 6 years ago

I've managed successfully implement this script manually using console and I can confirm that this is [BUG].

Take a look at functionObject block. I think there is something wrong with text parsing.

mostaphaRoudsari commented 6 years ago

@gamemakerh. The order in dictionaries is not important. Missing lines is a problem. Can you upload the function as a file. What is the purpose of // at the end of the line? Do you have any comments after the line? I assume that is what confuses the parser.

mostaphaRoudsari commented 6 years ago

I did a side by side comparison and seems what is missing is the closing ). Disregard my previous comment. It is a bug and doesn't have to do with //

gamemakerh commented 6 years ago

This is fully working code. You can use for reference. I was unable to use this in GH but it was working like a charm using linux/OpenFOAM console.


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1706+                                |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
/* Butterfly 0.0.4                https://github.com/ladybug-tools/butterfly *\
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     4.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}

#include        "probes";

application     buoyantBoussinesqSimpleFoam;

startFrom       latestTime;

startTime       0;

stopAt      endTime;

endTime     10000;

deltaT      1;

writeControl        timeStep;

writeInterval       1000;

purgeWrite      0;

writeFormat     ascii;

writePrecision      7;

writeCompression        off;

timeFormat      general;

timePrecision       6;

runTimeModifiable       true;

functions
{
//  #include "cuttingPlane"
 //   #include "streamLines"
  //  #include "forceCoeffs"  // nereikai sito sitam case
 //   #include "runtimePostProcessing"

 cuttingPlane
{
    type            surfaces;    //jei enveikai tada pakeisti atgal i surfaces. jei veikai palikti i surface
    libs            ("libsampling.so");
    writeControl    onEnd; // writeTime; // buvo visada write time. db pakeiciau. viskas veikia
    //writeInterval   100;
    surfaceFormat   vtk;
    fields          (p U);

    interpolationScheme cellPoint;

    surfaces
    (
        yNormal
        {
            type            cuttingPlane;
            planeType       pointAndNormal;
            pointAndNormalDict
            {
                point   (-0.7625002861022949 -3.380999982357025 0.5);
                normal  (0 0 1);   // 0 0 1 
            }
            interpolate     true;
        }
    );
}
// ************************************************************************* //

streamLines
{
    type            streamLine;                         // pakeisti i streamlines. jei neveikai palikti streamline
    libs            ("libfieldFunctionObjects.so");     //  arba dar gali buti //   libOpenFOAM.so
    writeControl    onEnd; //writeTime;                         // Output every // buvo visada write time. db pakeiciau. viskas veikia
    //writeInterval 100;
    setFormat       vtk;                                //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight;
    U               U;                                  // Velocity field to use for tracking.
    trackForward    true;                               // Tracked forwards (+U) or backwards (-U)
    fields          (p U);                              // Names of fields to sample. Should contain above velocity field!
    lifeTime        10000;                              // Steps particles can travel before being removed
    nSubCycle       5;                                  // Number of steps per cell (estimate). Set to 1 to disable subcycling.
    cloud           particleTracks;                     // Cloud name to use
    seedSampleSet                                       // Seeding method.
    {
        type        uniform;
        axis        x;                                  //distance;
        start       (-1.001 1e-7 0.0011);               // Note: tracks slightly offset so as not to be on a face
        end         (-1.001 1e-7 1.0011);
        nPoints     200;
    }
}
// ************************************************************************* //

postPro1
{
    type            runTimePostProcessing;
    libs            ("librunTimePostProcessing.so");
    writeControl    onEnd; // writeTime; // buvo visada write time. db pakeiciau. viskas veikia
    output
    {
        name            image;
        width           1554;
        height          853;
    }
    camera
    {
                                                                                    // If camera is moving, optionally provide start and end times
                                                                                    // startPosition    0.2;
                                                                                    // endPosition      0.75;

                                                                                    // Total number of frames to generate
        nFrameTotal         1;

                                                                                    // Parallel projection flag
        parallelProjection  no;

        clipBox         (-5.9 1.8 0.5)(5.1 -8.5 0.5);

        focalPoint      (-0.3352214945524962 -3.452300687073489 0.5);
        up              (0 1 0);
        position        (-0.3352214945524962 -3.452300687073489 20.370306316457867);
    }
                                                                                    // Default colours
                                                                                    // - If select to colourBy colour, these values are used unless
                                                                                    // they are locally overriden
    colours
    {
        background      (0.81 0.87 1);
       // background2     (0 0 1);
        text            (0 0 0);
        edge            (1 0 0);
        surface         (0.5 0.5 0.5);
        line            (1 0 0);
    }
                                                                                    // Line data
    lines
    {
        streamline
        {
            type            functionObjectLine;
            functionObject  streamLines;
            representation  tube;
            visible         yes;
            tubeRadius      0.01;
            colourBy        field;
            field           U;
            range           (0 14);
            opacity         1;
            scalarBar
            {
                visible         no;               
            }
        }
    }
                                                                                    // Surface data
    surfaces
    {
        cuttingPlane1
        {
            type            functionObjectSurface;
            functionObject  cuttingPlane;
            colourMap       rainbow;                                                // blueWhiteRed;
            representation  surface;                                                //glyph;   //maxGlyphLength  0.1;
            edgeColour      (0 0 0);
            visible         yes;
            featureEdges    no;
            colourBy        field;
            field           U;
            range           (0 14);
            opacity         1;
            scalarBar
            {
                visible         yes;
                position        (0.875 0.12);
                vertical        yes;
                fontSize        10;
                title           "Velocity / [m/s]";
                labelFormat     "%6.2f";
                numberOfLabels  10;
            }
        }
    }
                                                                                        // Text data
    text
    {
        text1
        {
            string          "TEST";
            position         (0.1 0.03);                                                //(0.1 0.05);
            size            20;
            bold            yes;
            visible         yes;
        }
    }
}

}
sarahmokhtar commented 5 years ago

I am experiencing the same problem with the function object component. The lines' order is changing and there is a missing bracket too. Any way to bypass that problem within GH?

vtk