緩和係数を反復ステップに依存させる方法

543 views
Skip to first unread message

M.TANAKA

unread,
Jan 7, 2021, 6:56:24 AM1/7/21
to OpenFOAM
初めまして.CFD初心者の田中と申します.
以下に述べる問題について,何かアドバイスを戴ければと思い投稿しました.

[状況と目標]
1. 対象とするのは,淀み圧力で駆動され,途中にノズル様の細い流路を含むような流れ.
2. OpenFOAMでこの流れの定常解を発散させず,かつなるべく早く収束させたい.
3. 最終的にはrhoSimpleFoam & RASで計算したいが,まずはsimpleFoam & laminarで収束する解を得たい.

[考えられる策]
1. 初期条件において勾配のある圧力分布を与える(internalField #codeStreamで実現できた).
2. 緩和係数を反復ステップに対し徐々に増加するように与える.

[今回相談したい点]
方策2.の緩和係数の制御についてです.反復ステップnに対して (緩和係数) = a/(1+exp(-(n-0.5b)/0.1b) といった風にシグモイド関数で緩和係数を与えたいと考えています.
試みに,system/fvSolutionにてUの緩和係数を#codeStreamを用いて下記"fvSolution"のように書き換えてみましたが,同じく下記"log.simpleFoam"に示すようなエラーを得ました(なぜか添付するとエラーで投稿できなかったので直打ちで失礼します).

 原因として考えているのは,以下の2通りです.
1. もしかすると計算実行時にfvSolutionが参照されるのは最初の1回だけで,反復ステップと結び付けること自体がナンセンスなのではないか.
2. codeInclude等の記述に誤りがあるのではないか.依存関係の漏れなど.

上記緩和係数の制御について,またそれ以外のお気づきの点についてご意見戴けると幸いです.宜しくお願いします.


****************** 以下,"fvSolution" ******************

/*--------------------------------*- 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      fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

solvers
{
    p
    {
        solver          GAMG;
        tolerance       1e-06;
        relTol          0.1;
        smoother        GaussSeidel;
    }

    U
    {
        solver          smoothSolver;
        smoother        symGaussSeidel;
        tolerance       1e-05;
        relTol          0.1;
    }

    Phi
    {
        solver          GAMG;
        smoother        DIC;
        tolerance       1e-06;
        relTol          0.01;
    }
}

potentialFlow
{
    nNonOrthogonalCorrectors 10;
}

SIMPLE
{
    nNonOrthogonalCorrectors 1;
    consistent      yes;

    residualControl
    {
        p               1e-3;
        U               1e-4;
    }
}

relaxationFactors
{
    equations
    {
        U               #codeStream
        {
            codeInclude
            #{
                #include "fvCFD.H"
            #};

            codeOptions
            #{
            -I$(LIB_SRC)/finiteVolume/lnInclude \
            -I$(LIB_SRC)/meshTools/lnInclude
            #};

            codeLibs
            #{
            -lmeshTools \
            -lfiniteVolume
            #};

            code
            #{
            const IOdictionary& d = static_cast<const IOdictionary&>(dict);
            const scalar t = d.db().time().timeOutputValue();
        const scalar N = 1000.;
            scalar relax = 0.001;

                relax = 0.8 / ( 1. + exp(-(t-N/2.)*10/N) );

            os << relax;
            #};
    };
        ".*"            0.002; // 
    }
}

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


****************** 以上,"fvSolution" ******************

**************** 以下,"log.simpleFoam" ****************


/*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2006                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : v2006 OPENFOAM=2006
Arch   : "LSB;label=32;scalar=64"
Exec   : simpleFoam -parallel
Date   : Jan 07 2021
Time   : 00:39:39
Host   : 94a34c429a4d
PID    : 713
I/O    : uncollated
Case   : /mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run
nProcs : 4
Hosts  :
(
    (94a34c429a4d 4)
)
Pstream initialized with:
    floatTransfer      : 0
    nProcsSimpleSum    : 0
    commsType          : nonBlocking
    polling iterations : 0
trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20)
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Using #codeStream at line 65 in file "/mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/system/fvSolution.relaxationFactors.equations"
Using #codeStream with "/mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444.so"
Could not load "/mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444.so"
/mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444.so: cannot open shared object file: No such file or directory
Creating new library in "dynamicCode/_99d2e90d9645a19e3a54f4f1b9350a139906a444/platforms/linux64GccDPInt32Opt/lib/libcodeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444.so"
Invoking wmake libso /mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/_99d2e90d9645a19e3a54f4f1b9350a139906a444
wmake libso /mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/_99d2e90d9645a19e3a54f4f1b9350a139906a444
make: Warning: File `Make/options' has modification time 0.1 s in the future
make: Warning: File `Make/linux64GccDPInt32Opt/options' has modification time 0.13 s in the future
make: warning:  Clock skew detected.  Your build may be incomplete.
make: Warning: File `Make/linux64GccDPInt32Opt/options' has modification time 0.097 s in the future
make: warning:  Clock skew detected.  Your build may be incomplete.
make: Warning: File `Make/linux64GccDPInt32Opt/sourceFiles' has modification time 0.11 s in the future
    ln: ./lnInclude
make: warning:  Clock skew detected.  Your build may be incomplete.
make: Warning: File `Make/linux64GccDPInt32Opt/sourceFiles' has modification time 0.048 s in the future
    dep: codeStreamTemplate.C
make: Warning: File `Make/linux64GccDPInt32Opt/codeStreamTemplate.C.dep' has modification time 0.12 s in the future
    Ctoo: codeStreamTemplate.C
/mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/system/fvSolution.relaxationFactors.equations.#codeStream: In function 'void Foam::codeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444(Foam::Ostream&, const Foam::dictionary&)':
/mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/system/fvSolution.relaxationFactors.equations.#codeStream:88:21: warning: variable 'relax' set but not used [-Wunused-but-set-variable]
    ld: /mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/_99d2e90d9645a19e3a54f4f1b9350a139906a444/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444.so
make: warning:  Clock skew detected.  Your build may be incomplete.
[0] #0  Foam::error::printStack(Foam::Ostream&) at ??:?
[0] #1  Foam::sigSegv::sigHandler(int) at ??:?
[0] #2  ? in /lib64/libpthread.so.0
[0] #3  codeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444 at /opt/OpenFOAM/OpenFOAM-v2006/src/OpenFOAM/lnInclude/TimeStateI.H:32
[0] #4  Foam::functionEntries::codeStream::evaluate(Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #5  Foam::functionEntries::codeStream::execute(Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) at ??:?
[0] #6  Foam::functionEntry::execute(Foam::word const&, Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) at ??:?
[0] #7  Foam::primitiveEntry::acceptToken(Foam::token const&, Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #8  Foam::primitiveEntry::read(Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #9  Foam::primitiveEntry::readEntry(Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #10  Foam::primitiveEntry::primitiveEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #11  Foam::entry::New(Foam::dictionary&, Foam::Istream&, Foam::entry::inputMode, int) at ??:?
[0] #12  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
[0] #13  Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&, bool) at ??:?
[0] #14  Foam::dictionaryEntry::dictionaryEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #15  Foam::entry::New(Foam::dictionary&, Foam::Istream&, Foam::entry::inputMode, int) at ??:?
[0] #16  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
[0] #17  Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&, bool) at ??:?
[0] #18  Foam::dictionaryEntry::dictionaryEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
[0] #19  Foam::entry::New(Foam::dictionary&, Foam::Istream&, Foam::entry::inputMode, int) at ??:?
[0] #20  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
[0] #21  Foam::operator>>(Foam::Istream&, Foam::dictionary&) at ??:?
[0] #22  Foam::baseIOdictionary::readData(Foam::Istream&) at ??:?
[0] #23  Foam::fileOperations::uncollatedFileOperation::read(Foam::regIOobject&, bool, Foam::IOstreamOption::streamFormat, Foam::word const&) const at ??:?
[0] #24  Foam::regIOobject::readHeaderOk(Foam::IOstreamOption::streamFormat, Foam::word const&) at ??:?
[0] #25  Foam::IOdictionary::IOdictionary(Foam::IOobject const&) at ??:?
[0] #26  Foam::solution::solution(Foam::objectRegistry const&, Foam::fileName const&) at ??:?
[0] #27  Foam::fvMesh::fvMesh(Foam::IOobject const&) at ??:?
[0] #28  ? at ??:?
[0] #29  __libc_start_main in /lib64/libc.so.6
[0] #30  ? at ??:?
[94a34c429a4d:00713] *** Process received signal ***
[94a34c429a4d:00713] Signal: Segmentation fault (11)
[94a34c429a4d:00713] Signal code:  (-6)
[94a34c429a4d:00713] Failing at address: 0x3e8000002c9
[94a34c429a4d:00713] [ 0] /lib64/libpthread.so.0(+0xf5e0)[0x7fc90c5e45e0]
[94a34c429a4d:00713] [ 1] /lib64/libpthread.so.0(raise+0x2b)[0x7fc90c5e44ab]
[94a34c429a4d:00713] [ 2] /lib64/libpthread.so.0(+0xf5e0)[0x7fc90c5e45e0]
[94a34c429a4d:00713] [ 3] /mnt/d/OpenFOAM/STAR-CCM+training/0101_MSNozzleIncompressibleLaminar/2_run/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444.so(codeStream_99d2e90d9645a19e3a54f4f1b9350a139906a444+0x15)[0x7fc8efa519e5]
[94a34c429a4d:00713] [ 4] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam15functionEntries10codeStream8evaluateERKNS_10dictionaryERNS_7IstreamE+0x398)[0x7fc90d7150d8]
[94a34c429a4d:00713] [ 5] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam15functionEntries10codeStream7executeERKNS_10dictionaryERNS_14primitiveEntryERNS_7IstreamE+0x5a)[0x7fc90d715bea]
[94a34c429a4d:00713] [ 6] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam13functionEntry7executeERKNS_4wordERKNS_10dictionaryERNS_14primitiveEntryERNS_7IstreamE+0x229)[0x7fc90d719319]
[94a34c429a4d:00713] [ 7] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam14primitiveEntry11acceptTokenERKNS_5tokenERKNS_10dictionaryERNS_7IstreamE+0x1b7)[0x7fc90d70c7c7]
[94a34c429a4d:00713] [ 8] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam14primitiveEntry4readERKNS_10dictionaryERNS_7IstreamE+0xeb)[0x7fc90d70cdcb]
[94a34c429a4d:00713] [ 9] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam14primitiveEntry9readEntryERKNS_10dictionaryERNS_7IstreamE+0x2d)[0x7fc90d70d9ad]
[94a34c429a4d:00713] [10] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam14primitiveEntryC2ERKNS_7keyTypeERKNS_10dictionaryERNS_7IstreamE+0x2d9)[0x7fc90d70e2e9]
[94a34c429a4d:00713] [11] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam5entry3NewERNS_10dictionaryERNS_7IstreamENS0_9inputModeEi+0x1104)[0x7fc90d708814]
[94a34c429a4d:00713] [12] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam10dictionary4readERNS_7IstreamEb+0x143)[0x7fc90d6ff913]
[94a34c429a4d:00713] [13] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam10dictionaryC1ERKNS_8fileNameERKS0_RNS_7IstreamEb+0x112)[0x7fc90d700f82]
[94a34c429a4d:00713] [14] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam15dictionaryEntryC2ERKNS_7keyTypeERKNS_10dictionaryERNS_7IstreamE+0x45)[0x7fc90d70ee65]
[94a34c429a4d:00713] [15] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam5entry3NewERNS_10dictionaryERNS_7IstreamENS0_9inputModeEi+0x1564)[0x7fc90d708c74]
[94a34c429a4d:00713] [16] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam10dictionary4readERNS_7IstreamEb+0x143)[0x7fc90d6ff913]
[94a34c429a4d:00713] [17] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam10dictionaryC1ERKNS_8fileNameERKS0_RNS_7IstreamEb+0x112)[0x7fc90d700f82]
[94a34c429a4d:00713] [18] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam15dictionaryEntryC2ERKNS_7keyTypeERKNS_10dictionaryERNS_7IstreamE+0x45)[0x7fc90d70ee65]
[94a34c429a4d:00713] [19] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam5entry3NewERNS_10dictionaryERNS_7IstreamENS0_9inputModeEi+0x1564)[0x7fc90d708c74]
[94a34c429a4d:00713] [20] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam10dictionary4readERNS_7IstreamEb+0x143)[0x7fc90d6ff913]
[94a34c429a4d:00713] [21] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4FoamrsERNS_7IstreamERNS_10dictionaryE+0x3e)[0x7fc90d7001ae]
[94a34c429a4d:00713] [22] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam16baseIOdictionary8readDataERNS_7IstreamE+0x20)[0x7fc90d724d00]
[94a34c429a4d:00713] [23] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZNK4Foam14fileOperations23uncollatedFileOperation4readERNS_11regIOobjectEbNS_14IOstreamOption12streamFormatERKNS_4wordE+0x13a)[0x7fc90d5b05fa]
[94a34c429a4d:00713] [24] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam11regIOobject12readHeaderOkENS_14IOstreamOption12streamFormatERKNS_4wordE+0x62)[0x7fc90d734f42]
[94a34c429a4d:00713] [25] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam12IOdictionaryC1ERKNS_8IOobjectE+0x37)[0x7fc90d725057]
[94a34c429a4d:00713] [26] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam8solutionC1ERKNS_14objectRegistryERKNS_8fileNameE+0x95)[0x7fc90d79db15]
[94a34c429a4d:00713] [27] /opt/OpenFOAM/OpenFOAM-v2006/platforms/linux64GccDPInt32Opt/lib/libfiniteVolume.so(_ZN4Foam6fvMeshC2ERKNS_8IOobjectE+0x97)[0x7fc9109c6ee7]
[94a34c429a4d:00713] [28] simpleFoam[0x41b8a7]
[94a34c429a4d:00713] [29] /lib64/libc.so.6(__libc_start_main+0xf5)[0x7fc90c233c05]
[94a34c429a4d:00713] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 713 on node 94a34c429a4d exited on signal 11 (Segmentation fault).
--------------------------------------------------------------------------


**************** 以上,"log.simpleFoam" ****************

sariew8

unread,
Jan 12, 2021, 8:43:54 PM1/12/21
to OpenFOAM
こんちには
質問2について回答します。下記の2行を変更すれば動作するようです(simpleCar で検証済)。

 //const IOdictionary& d = static_cast<const IOdictionary&>(dict);
 //const scalar t = d.db().time().timeOutputValue();

const IOdictionary& d = static_cast<const IOdictionary&>
(
     dict.parent().parent()
);
scalar t = d.db().time().value();

2021年1月7日木曜日 20:56:24 UTC+9 M.TANAKA:

M.TANAKA

unread,
Jan 15, 2021, 12:26:13 AM1/15/21
to OpenFOAM
sariew8さん

田中です.回答ありがとうございます.
戴いたアドバイスを元にfvSolutionの記述を下記のように変えて,std::coutでいつ実行されるか確かめてみました.
なお,テスト用に$FOAM_TUTORIALS/compressible/rhoSimpleFoam/squareBendを対象としています.

========== 以下,fvSolution.relaxationFactors ==========
relaxationFactors
{
    fields
    {
        p               1;
    }
    equations
    {
        default #codeStream
        {
            codeInclude
            #{
                #include "fvCFD.H"
            #};

            codeOptions
            #{
                -I$(LIB_SRC)/finiteVolume/lnInclude \
                -I$(LIB_SRC)/meshTools/lnInclude
            #};

            codeLibs
            #{
                -lmeshTools \
                -lfiniteVolume
            #};

            code
            #{
                const IOdictionary& d = static_cast<const IOdictionary&>(dict.parent().parent());
                const Time& time = static_cast<const Time&>(d.db());
                scalar t = time.timeIndex();
                const scalar N = 100.;
                scalar relax = 0.001;

                std::cout << "I am HERE! and the timeIndex is " << t << std::endl;
                relax = 0.8 / ( 1. + exp(-(t-N/2.)*10./N) );

                os << relax;
            #};
        };
    }
}
========== 以上,fvSolution.relaxationFactors ==========

もし期待する通りに各タイムステップで緩和係数が再設定されるならば,"I am HERE! and the timeIndex is $timeIndex"がステップ毎に記述されるはずです.
しかしlog.rhoSimpleFoamの内容は以下のようでした."Starting time loop"より前に一度だけ記述されているのが分かります.

========== 以下,log.rhoSimpleFoamより抜粋 ==========
・・・(前略)・・・

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Using #codeStream at line 64 in file "/mnt/d/OpenFOAM/run/laminar/rhoSimpleFoam/squareBend/system/fvSolution.relaxationFactors.equations"
Using #codeStream with "/mnt/d/OpenFOAM/run/laminar/rhoSimpleFoam/squareBend/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_752ebaec05e061db316b5e533af67203ce907467.so"
I am HERE! and the timeIndex is 0

・・・(中略)・・・

Starting time loop

Time = 1

GAMG:  Solving for Ux, Initial residual = 1, Final residual = 1.55405e-12, No Iterations 1
GAMG:  Solving for Uy, Initial residual = 1, Final residual = 8.51016e-14, No Iterations 1
GAMG:  Solving for Uz, Initial residual = 1, Final residual = 1.21201e-11, No Iterations 1
GAMG:  Solving for e, Initial residual = 1, Final residual = 1.49349e-13, No Iterations 1
GAMG:  Solving for p, Initial residual = 1, Final residual = 1.7928e-10, No Iterations 1
time step continuity errors : sum local = 283.584, global = -283.584, cumulative = -283.584
GAMG:  Solving for epsilon, Initial residual = 0.546191, Final residual = 1.06399e-10, No Iterations 1
GAMG:  Solving for k, Initial residual = 1, Final residual = 1.45787e-11, No Iterations 1
ExecutionTime = 0.88 s  ClockTime = 2 s

Time = 2

GAMG:  Solving for Ux, Initial residual = 0.400165, Final residual = 1.90772e-16, No Iterations 1
GAMG:  Solving for Uy, Initial residual = 0.950683, Final residual = 5.34973e-15, No Iterations 1
GAMG:  Solving for Uz, Initial residual = 0.950683, Final residual = 7.13174e-13, No Iterations 1
GAMG:  Solving for e, Initial residual = 0.00261189, Final residual = 1.3412e-14, No Iterations 1
GAMG:  Solving for p, Initial residual = 0.0669143, Final residual = 3.09436e-12, No Iterations 1
time step continuity errors : sum local = 284.8, global = -284.8, cumulative = -568.385
GAMG:  Solving for epsilon, Initial residual = 0.682656, Final residual = 1.59855e-15, No Iterations 1
GAMG:  Solving for k, Initial residual = 0.312101, Final residual = 1.48479e-15, No Iterations 1
ExecutionTime = 1.18 s  ClockTime = 2 s

Time = 3

・・・(後略)・・・
========== 以上,log.rhoSimpleFoamより抜粋 ==========

このことから,やはりfvSolutionはタイムループが始まる前の一度しか読み込まれないようになっていることが分かります.
タイムステップ毎に緩和係数を更新するには,ソルバ自体の動きを変える必要がありそうです.
この場合は,$FOAM_APP/solvers/compressible/rhoSimpleFoamフォルダをコピーして,ソースコードを編集・コンパイルして新たなソルバを作れば実現できそうではあります.
なんだか目的に対して手段が大げさな(もっと上手い手がありそうな)感じもしますが,この方向でもう少し探索してみようと思います.

2021年1月13日水曜日 10:43:54 UTC+9 sariew8:

Hiroaki Fujio

unread,
Jan 15, 2021, 12:41:48 PM1/15/21
to open...@googlegroups.com
controlDict, fvSchemes, fvSolution 等は、ファイルが更新されるとタイムステップの終わりに再読み込みされます。
readIfModified() を改造してファイルが更新されていなくても再読み込みするようにすれば、コードが動くようになるかもしれません。

しかしそれよりはログを監視して、一定数のタイムステップを経過したところでfvSolutionを書き換える方が筋が良いように思います。

--
このメールは Google グループのグループ「OpenFOAM」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには openfoam+u...@googlegroups.com にメールを送信してください。
このディスカッションをウェブ上で閲覧するには https://groups.google.com/d/msgid/openfoam/1675340d-6f1e-4c0e-8452-92ad6becd2a0n%40googlegroups.com にアクセスしてください。

M.TANAKA

unread,
Jan 18, 2021, 10:18:00 PM1/18/21
to OpenFOAM
Hiroaki Fujioさん

田中です.回答ありがとうございます.
system/内の設定ファイルは実行中も変更がないか監視されているのですね(constant/という名前はそれに対するものでしょうか).勉強になります.
今後FOCUSなどの外部環境で計算する場合などを考えると,regIOobjectクラスのようなOpenFOAMの根本に関わるクラスを編集してしまうのは仰る通り好ましくないと思います.

アドバイス戴いたログファイル監視の線で探索してみた所,ある程度狙い通りの効果が得られたのでこちらに投稿します.概要を以下に記します.


テストケース: $FOAM_TUTORIALS/compressible/rhoSimpleFoam/squareBend

作成ファイル: initializeRelaxationFactors
        (fvSolutionの緩和係数の項を初期化するシェルスクリプト)
      : varyRelaxationFactorsEveryStep 
        (logを即時に読み取り1ステップ毎にfvSolutionの緩和係数を書き換えるシェルスクリプト)
      : Allrun
        (一連の計算を実行するシェルスクリプト)

実験内容  : 作成したスクリプトに効果があるか確かめるため,
       上記ケースにおいて以下の3条件で計算を行い,solverInfoの結果を比較する.
       1. 緩和係数をステップに関わらず最小値で固定
       2. 緩和係数をステップに応じて最小値から最大値へ変化させる
       3. 緩和係数をステップに関わらず最大値で固定

(作成したスクリプトを含めたケースフォルダはzipファイルで添付しています.)


その結果が,添付する3枚の画像です.条件順に並べています.

01fixedMin0_0067.png
02varyingMinToMax.png
03fixedMax0_7000.png

3枚とも異なるグラフとなることから,実行中に緩和係数の変更が反映されていることが確認できました.
また,緩和係数を変更した場合,残差が階段状に変化しています.
ログと見比べたところ,この変化は実行時間5秒毎に発生しているようです.このタイミングでfvSolutionの再読み込みが行われているものと思われます.
単純なテストケースなので計算が速く,階段状の変化が目立ちますが,実際に計算するケースの場合は特に問題ないものと考えています.今後本題のケースで収束解が得られるか試していくつもりです.

スクリプトの作り込み(tailfから抜けられない...)など課題は残ってますが,当初実現したかった機能は概ね実現できました.
sariew8さん,Hiroaki Fujioさん,ありがとうございました.
2021年1月16日土曜日 2:41:48 UTC+9 hiroak...@gmail.com:
squareBend.zip

M.TANAKA

unread,
Jul 16, 2021, 9:51:11 AM7/16/21
to OpenFOAM
お世話になっています、田中です。以前投稿した緩和係数の制御についていくらか実用的なスクリプトが出来てきましたので、何かの参考になればと思い共有します。

前回とはアプローチを変え、残差に上下の閾値を設けて、その閾値を超えた場合緩和係数を減少/増加させるようにしています。$FOAM_TUTORIALS/incompressible/simpleFoam/motorBikeチュートリアルに適用した際のforceCoefficientのプロットが以下です。緩和係数の制御がある場合、より早く収束することが確認できました。

制御なし↓
forceCoeff_withoutRegulating.png

制御あり↓
forceCoeff_withRegulating.png

ケースフォルダをtar.gzファイルとして添付します。
半分備忘録として投稿していますが、「ここはこうした方が良い」といったアドバイスを戴ければ望外の喜びです。

2021年1月19日火曜日 12:18:00 UTC+9 M.TANAKA:
motorBike_regulatingRelaxationFactors.tar.gz

eiji yokota

unread,
Jul 18, 2021, 4:58:15 PM7/18/21
to open...@googlegroups.com
M.TANAKA 様へ
すみませんが、本件心あたりがなく、
ご確認いただければ幸いです。
よろしくお願いいたします。

yokota

2021年7月16日(金) 22:51 M.TANAKA <tanaka19m...@gmail.com>:
このディスカッションをウェブ上で閲覧するには https://groups.google.com/d/msgid/openfoam/31958084-35cf-4bd0-82f0-3a3efb665509n%40googlegroups.com にアクセスしてください。
Reply all
Reply to author
Forward
0 new messages