PR

【OpenFOAM v2006】航空機の3次元解析

Fusion360で作成したモデルをもとに,OpenFOAMを使って航空機(QX-20)の3次元解析を行う

計算に使ったファイルはGithubにアップしてある
mtkbirdman.com/OpenFOAM/airplane/

スポンサーリンク

はじめに

参考にしたのは次の文献

【OpenFOAM】やっとレーシングカーボディを仮想風洞実験しました エアロダイナミクスチュートリアル【CFD】
Chapter6_Aircraft.pdf

参考にしたチュートリアルはこれ

/tutorials/incompressible/simpleFoam/motorBike

最終的にはこんな感じになる

概要

計算実行前のケースディレクトリairplaneの構成図を示す

airplane
├── 0.orig
│   ├── U
│   ├── k
│   ├── nut
│   ├── omega
│   └── p
├── constant
│   ├── triSurface
│   │   └── airplane.obj
│   ├── transportProperties
│   └── turbulenceProperties
├── system
│   ├── Qfunction
│   ├── blockMeshDict
│   ├── controlDict
│   ├── decomposeParDict
│   ├── forceCoeffs
│   ├── fvSchemes
│   ├── fvSolution
│   ├── pressure
│   ├── residuals
│   ├── snappyHexMeshDict
│   ├── surfaceFeatureExtractDict
│   └── vorticity
├── template
│   ├── U_template
│   ├── forceCoeffs_template
│   └── pressure_template
├── Allclean
├── Allrun
├── Allrun.py
├── gnuplot_coeffs.sh
├── gnuplot_coeffs.txt
├── gnuplot_residuals.sh
├── gnuplot_residuals.txt
├── plot_coeffs.py
└── plot_residuals.py

./constant/triSurface/airplane.objがFusion360で作成したobjファイルである

./templateの中に,速度や迎角が変わったときにそれぞれのファイルを書き直すために使用するためのテンプレートファイルが入っている

plot_coeffs.pyplot_residuals.pyは計算過程を可視化するためのプログラムで,Allrun.pyですべての処理が実行できる

モデル作成

QX-20をFusion360でモデリングして,.objファイルで出力する

QX-20がどんな機体かについてはこちら
QX-20設計資料③:概念設計

Fusion360で翼をモデリングするやり方はこちら
【Fusion360】連番CSVをインポートしてスプラインでつなぐPythonスクリプト

カウルのデータはカウル藩長からもらったデータを使用した

Fusion360でobjファイルを出力

Fusion360で主翼,胴体,水平尾翼,垂直尾翼がすべてつながっているモデルを用意して,Files→Exportをクリック

Name: airplane→Type: OBJ Files (*,obj)→Location: ~/airplane/constant/triSurface→Exportをクリック

これでobjファイルを出力できた

objファイルの修正

surfaceConvertを使ってobjファイルに修正を加える
OpenFOAM API Guide surfaceConvert.C File Reference

Fusion360で出力したobjファイルの単位を[㎜]から[m]に変換する

surfaceConvert -scale 0.001 airplane.obj airplane1.obj
mv airplane1.obj airplane.obj

surfaceCheckを使ってobjファイルの状態をチェックする
OpenFOAM API Guide surfaceCheck.C File Reference

surfaceCheck airplane.obj > log.surfaceCheck
grep 'illegal triangles' log.surfaceCheck

Surface has no illegal triangles.と出てくればOKだが,出てこなければ次のコマンドをたたく

surfaceConvert airplane.obj airplane-1.obj -clean > /dev/null
mv airplane-1.obj airplane.obj

これでairplane.objの準備が完了した

メッシュ作成

メッシュ作成は次の手順で行う

  • surfaceFeatureExtractでobjファイルから特徴線を抽出
  • blockMeshで背景のメッシュを作成
  • snappyHexMeshDictでobjファイルの特徴線と背景メッシュを良い感じに合成

これらの操作の設定を行うファイルを作成する

sysytem/surfaceFeatureExtractDict

airplane.objから特徴線を抽出するときの設定を行う

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      surfaceFeatureExtractDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

airplane.obj
{
    extractionMethod    extractFromSurface;
    includedAngle       180;

    subsetFeatures
    {    
        nonManifoldEdges       no;
        openEdges       yes;
    }

    writeObj            yes;
}


// ************************************************************************* //

このファイルを設定した後,次のコマンドを実行すればParaViewでobjファイルを開くことができる

surfaceFeatureExtract

system/blockMeshDict

blockMeshについてはここら辺の資料を見ればだいたいわかる
PENGUINITIS - blockMesh によるメッシュの作成
blockMeshコマンドを用いたメッシュ生成 (pdf)

航空機の伴流を解析するため,機体後ろ方向に大きめの領域を確保している

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

scale   1;

vertices
(
    (-10 -20 -10)
    (30 -20 -10)
    (30  20 -10)
    (-10  20 -10)
    (-10 -20 10)
    (30 -20 10)
    (30  20 10)
    (-10  20 10)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (32 32 16) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
    frontAndBack
    {
        type patch;
        faces
        (
            (3 7 6 2)
            (1 5 4 0)
        );
    }
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (2 6 5 1)
        );
    }
    lowerWall
    {
        type wall;
        faces
        (
            (0 3 2 1)
        );
    }
    upperWall
    {
        type patch;
        faces
        (
            (4 5 6 7)
        );
    }
);

// ************************************************************************* //

このファイルを設定した後,次のコマンドを実行すればメッシュが作成される

blockMesh

airplane.foamを作成して,airplane.objと同時にParaViewで開けば,背景メッシュの中に機体が含まれていることを確認できる

system/snappyHexMeshDict

snappyHexMeshについてはここら辺がわかりやすい
PENGUINITIS - snappyHexMesh によるメッシュの作成
snappyHexMeshで円柱周り流れのメッシュを作成する方法 - Qiita

公式のドキュメントはこちら
OpenFOAM User Guide snappyHexMesh

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      snappyHexMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

castellatedMesh true;
snap            true;
addLayers       true;

geometry
{
    airplane.obj
    {
        type triSurfaceMesh;
        name airplane;
    }

    refinementBox
    {
        type searchableBox;
        min  (-1.7 -14.2 -0.5);
        max  (30.0 14.2 2.8);
    }
}

castellatedMeshControls
{
    maxLocalCells           1500000;
    maxGlobalCells          3000000;
    minRefinementCells      10;
    maxLoadUnbalance        0.10;
    nCellsBetweenLevels     3;

    features
    (
        {
            file            "airplane.eMesh";
            level           6;
        }
    );

    refinementSurfaces
    {
        airplane
        {
            level           (6 6);
            patchInfo
            {
                type        wall;
                inGroups    (airplaneGroup);
            }
        }
    }

    resolveFeatureAngle     30;

    refinementRegions
    {
        refinementBox
        {
            mode            inside;
            levels          ((1E15 4));
        }
    }

    locationInMesh          (-1.0 0.0 -1.0);
    allowFreeStandingZoneFaces  true;
}

snapControls
{
    nSmoothPatch            3;
    tolerance               1.0;
    nSolveIter              30;
    nRelaxIter              5;

    nFeatureSnapIter        10;
    implicitFeatureSnap     false;
    explicitFeatureSnap     true;
    multiRegionFeatureSnap  false;
}

addLayersControls
{
    relativeSizes           true;

    layers
    {
        airplane
        {
            nSurfaceLayers  2;
        }
        maxY
        {
            nSurfaceLayers  2;

        }
        frozenPatches
        {
            nSurfaceLayers  0;
        }
    }

    expansionRatio          2.0;
    finalLayerThickness     0.4;
    minThickness            0.2;
    nGrow                   0;

    featureAngle            60;
    slipFeatureAngle        30;
    nRelaxIter              3;
    nSmoothSurfaceNormals   1;
    nSmoothNormals          3;
    nSmoothThickness        10;
    maxFaceThicknessRatio   0.5;
    maxThicknessToMedialRatio   0.3;
    minMedialAxisAngle      90;
    nBufferCellsNoExtrude   0;
    nLayerIter              50;
}

meshQualityControls
{
    maxNonOrtho             45;
    maxBoundarySkewness     20;
    maxInternalSkewness     4;
    maxConcave              80;
    minVol                  1e-13;
    minTetQuality           -1e+30;
    minArea                 -1;
    minTwist                0.05;
    minDeterminant          0.001;
    minFaceWeight           0.05;
    minVolRatio             0.01;    
    minTriangleTwist        -1;

    nSmoothScale            4;
    errorReduction          0.75;
}

writeFlags
(
    scalarLevels
    layerSets
    layerFields
);

mergeTolerance              1e-6;


// ************************************************************************* //

要点を説明する

最初の3行ではcastellatedMeshsnapaddLayersを実行するかどうかを設定している.今回はすべてtrueにしている

geometryのセクションの中で,airplanerefinementBoxを定義している.ここで定義した2つの領域に対してsnappyHexMeshが適用される

refinementBoxは主翼の翼端渦を計算できるような大きさにしてある

castellatedMeshControlsのセクションでは,最大のセル数(maxGlobalCells)を設定している.ここで指定したセル数を超えた時点で処理は中断される

また,refinementSurfacesrefinementRegionsのサブセクションの中で,airplanerefinementBoxそれぞれに対する細分化のレベルを指定している

snapControlsaddLayersControlsmeshQualityControlsのセクションの中の値は資料を見ながら適当に決めた

このファイルを設定した後,次のコマンドを実行すればメッシュが細分化される

snappyHexMesh

むちゃくちゃ時間とメモリを食うので覚悟して実行するといい

こんな感じのメッシュができる

refinementBoxの大きさの決定

paraViewでairplane.objを開き,View→Informationにチェックを入れると,Information→Boundsでx,y,zそれぞれの最大値と最小値が確認できる

refinementBoxはこれより少し大きくなるように決定する

条件設定

ここからは特に変わったことはしていない

いちおうファイルの内容を貼り付けておくが,特に説明したりもしないので計算実行まで飛んでもらって構わない

Boundary and initial conditions

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    location    "0";
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (9.6 0.0 0.0);

boundaryField
{
    #includeEtc "caseDicts/setConstraintTypes"

    inlet
    {
        type            freestream;
        freestreamValue uniform (9.6 0.0 0.0);
    }
    
    outlet
    {
        type            inletOutlet;
        inletValue      uniform (0 0 0);
        value           uniform (9.6 0.0 0.0);
    }

    airplane
    {
        type            noSlip;
    }

    lowerWall
    {
        type            slip;
    }
    
    upperWall
    {
        type            slip;
    }

    frontAndBack
    {
        type            slip;
    }
}


// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0.0;

boundaryField
{
    #includeEtc "caseDicts/setConstraintTypes"

    inlet
    {
        type            freestreamPressure;
        freestreamValue uniform 0.0;
    }
    
    outlet
    {
        type            freestreamPressure;
        freestreamValue uniform 0.0;
    }

    airplane
    {
        type            zeroGradient;
    }

    lowerWall
    {
        type            slip;
    }
    
    upperWall
    {
        type            slip;
    }

    frontAndBack
    {
        type            slip;
    }
}

// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 1.215;

boundaryField
{
    #includeEtc "caseDicts/setConstraintTypes"

    inlet
    {
        type            fixedValue;
        value           uniform 1.215;
    }
    
    outlet
    {
        type            inletOutlet;
        inletValue      uniform 1.215;
        value           uniform 1.215;
    }

    airplane
    {
        type            kqRWallFunction;
        value           uniform 1.215;
    }

    lowerWall
    {
        type            slip;
    }
    
    upperWall
    {
        type            slip;
    }

    frontAndBack
    {
        type            slip;
    }
}


// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0";
    object      nut;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -1 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    #includeEtc "caseDicts/setConstraintTypes"

    inlet
    {
        type            calculated;
        value           uniform 0;
    }
    
    outlet
    {
        type            calculated;
        value           uniform 0;
    }

    airplane
    {
        type            nutkWallFunction;
        value           uniform 0;
    }

    lowerWall
    {
        type            calculated;
        value           uniform 0;
    }
    
    upperWall
    {
        type            calculated;
        value           uniform 0;
    }

    frontAndBack
    {
        type            calculated;
        value           uniform 0;
    }
}


// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      omega;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 -1 0 0 0 0];

internalField   uniform 2147.745;

boundaryField
{
    #includeEtc "caseDicts/setConstraintTypes"

    inlet
    {
        type            fixedValue;
        value           uniform 2147.745;
    }
    
    outlet
    {
        type            inletOutlet;
        inletValue      uniform 2147.745;
        value           uniform 2147.745;
    }

    airplane
    {
        type            omegaWallFunction;
        value           uniform 2147.745;
    }

    lowerWall
    {
        type            slip;
    }
    
    upperWall
    {
        type            slip;
    }

    frontAndBack
    {
        type            slip;
    }
}


// ************************************************************************* //

Physical properties

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      turbulenceProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

simulationType RAS;

RAS
{
    RASModel            kOmegaSST;
    turbulence          on;
    printCoeffs         on;
}

// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

transportModel  Newtonian;
nu              1.5e-05;

// ************************************************************************* //

Control

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     simpleFoam;
startFrom       startTime;
startTime       0;
stopAt          endTime;
endTime         200;
deltaT          1;
writeControl    timeStep;
writeInterval   100;
purgeWrite      0;
writeFormat     binary;
writePrecision  6;
writeCompression off;
timeFormat      general;
timePrecision   6;
runTimeModifiable true;

functions
{
    #includeFunc    residuals
    #include        "forceCoeffs"
    #include        "pressure"
    #include        "Qfunction"
    #include        "vorticity"
}


// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Version:  v1912
    \\  /    A nd           | Website:  www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
Description
    For specified fields, writes out the initial residuals for the first
    solution of each time step; for non-scalar fields (e.g. vectors), writes
    the largest of the residuals for each component (e.g. x, y, z).

\*---------------------------------------------------------------------------*/

#includeEtc "caseDicts/postProcessing/numerical/residuals.cfg"

fields (p U);

// ************************************************************************* //

OpenFOAM User Guide Force coefficients

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

forceCoeffs1
{
    type            forceCoeffs;
    libs            ("libforces.so");
    writeControl    timeStep;
    timeInterval    1;
    log             yes;

    patches         (airplaneGroup);
    rho             rhoInf;
    rhoInf          1;
    liftDir         (-0.0 0.0 1.0);
    dragDir         (1.0 0.0 0.0);
    CofR            (0 0 0);
    pitchAxis       (0 1 0);
    magUInf         9.6;
    lRef            0.755;
    Aref            18.821;
}


// ************************************************************************* //

OpenFOAM User Guide pressure

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

pressure1
{
    type            pressure;
    libs            ("libfieldFunctionObjects.so");
    writeControl    onEnd;
    mode            staticCoeff;
    //calcTotal       false;  //v1812
    //calcCoeff       true;   //v1812

    p               p;
    U               U;
    rho             rhoInf;
    rhoInf          1.0;    
    pInf            0.0;
    UInf            (9.6 0.0 0.0);
}


// ************************************************************************* //

OpenFOAM User Guide Q

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

Q1
{
    type            Q;
    libs            ("libfieldFunctionObjects.so");
    writeControl    writeTime;
}

// ************************************************************************* //

OpenFOAM User Guide vorticity

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

vorticity1
{
    type            vorticity;
    libs            ("libfieldFunctionObjects.so");
    writeControl    writeTime;
}

// ************************************************************************* //

Parallel

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

numberOfSubdomains 4;

method          hierarchical;

coeffs
{
    n           (2 2 1);
}

// ************************************************************************* //

Run

Allrun.py

import os,math

import numpy as np
import time

start=time.time()

def rewriteBC(fsV,alpha):
    fsX=math.cos(alpha)*fsV
    fsY=0.
    fsZ=math.sin(alpha)*fsV

    inFile_list=["template/U_template","template/forceCoeffs_template","template/pressure_template"]
    outFile_list=["0.orig/U","system/forceCoeffs","system/pressure"]
    
    for inFile_name,outFile_name in zip(inFile_list,outFile_list):
        with open(inFile_name, "rt") as inFile:
            with open(outFile_name, "wt") as outFile:
                for line in inFile:
                    line = line.replace("VEC_Lift","({} {} {})".format(-math.sin(alpha),0.,math.cos(alpha)))
                    line = line.replace("VEC_Drag","({} {} {})".format(math.cos(alpha),0.,math.sin(alpha)))
                    line = line.replace("MAG_VEL","{}".format(fsV))
                    line = line.replace("VEC_VEL","({} {} {})".format(fsX,fsY,fsZ))
                    outFile.write(line)
    
    print("Resulting freestream vel x,y,z: {:.3f},{:.3f},{:.3f}".format(fsX,fsY,fsZ))

fsV=9.600 #V [m/s]
alpha=(math.pi/12.)*(0.) #AOA [rad]

print("Using velocity {:.3f} [m/s], alpha {:.3f} [deg]".format(fsV,alpha*(180/math.pi)))

rewriteBC(fsV,alpha)

os.system("./Allclean && ./Allrun")
os.system("touch airfoil.foam")

cpu_time=time.time()-start
print("done! > time:{:.3f} [s]".format(cpu_time))

Allrun

#!/bin/sh
cd "${0%/*}" || exit                                # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions        # Tutorial run functions
#------------------------------------------------------------------------------

runApplication blockMesh
runApplication surfaceFeatureExtract
runApplication decomposePar
runParallel snappyHexMesh -overwrite
restore0Dir -processor
runParallel $(getApplication)
runApplication reconstructParMesh -constant
runApplication reconstructPar -latestTime

exit

#------------------------------------------------------------------------------

Allclean

#!/bin/sh
cd "${0%/*}" || exit                                # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions      # Tutorial clean functions
#------------------------------------------------------------------------------

foamCleanPolyMesh
cleanCase0

# Remove surface and features
rm -f constant/triSurface/airplane.eMesh
rm -rf constant/extendedFeatureEdgeMesh
rm -rf processor*
rm -f Allrun_PJ.*

#------------------------------------------------------------------------------

計算実行

Allrun.pyを使って計算を実行してみる

だいたい数時間かかる

~/airplane$ python Allrun.py
Using velocity 9.600 [m/s], alpha 0.000 [deg]
Resulting freestream vel x,y,z: 9.600,0.000,0.000
Cleaning ./constant/polyMesh
Cleaning case /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Running blockMesh on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Running surfaceFeatureExtract on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Running decomposePar on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Running snappyHexMesh (4 processes) on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Restore 0/ from 0.orig/ for processor directories
Running simpleFoam (4 processes) on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Running reconstructParMesh on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
Running reconstructPar on /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/airplane
done! > time:9722.613 [s]
~/airplane$

ポスト処理

計算が終了したら,plot_residuals.pyplot_coeffs.pyを使って残差と空力係数を表示してみる

gnuplotを使うのでXmingの起動を忘れずに

どちらも収束していることが確認できる

結果

計算結果をParaViewで表示してみる

圧力係数 [-]

速度 [m/s]

速度勾配テンソルの第二不変量

※なにそれ?という人はこちら
パッと知りたい! 人と差がつく乱流と乱流モデル講座 第13回
乱流の渦構造可視化のためのQ値導出について - 気ままに塞翁が馬

空力係数 (AOA=0 [deg])

設計シートOpenFOAM
CL0.8250.721
CD0.0200.037
Cm0.0310.107

まとめ

OpenFOAMでQX-20の解析を行った

ノートPCでできる程度の計算にしてはそれなりの結果が出たんじゃないかと思う

他にもいろいろな機体の解析をやってみたい

おすすめ

OpenFOAM
質問・感想・意見などあれば気軽にTwitterのDMかコメントお願いします!
スポンサーリンク

コメント