白黒羊

OpenFOAMがコンパイルできないときの対処法

OpenFOAM-v1906が公開されていたのでダウンロードしてコンパイルしようとしたらエラーが出てしまいました。
本質的な問題は、仮想環境じゃなくて直に置いてしまったことなのですが、一応調べたのでメモ……。

コンパイル手順

WSLを使っているので/opt/直下に置いてあります。

source /opt/OpenFOAM/OpenFOAM-v1906/etc/bashrc
cd $WM_PROJECT_DIR
foamSystemCheck
foam
./Allwmake

エラー

In file included from /opt/OpenFOAM/OpenFOAM-v1906/src/OpenFOAM/lnInclude/postProcess.H:129:0,
                 from coldEngineFoam.C:47:
../XiFoam/createFields.H: In function ‘int main(int, char**)’:
../XiFoam/createFields.H:3:9: error: ‘psiuReactionThermo’ was not declared in this scope
 autoPtr<psiuReactionThermo> pThermo
         ^~~~~~~~~~~~~~~~~~
../XiFoam/createFields.H:3:27: error: template argument 1 is invalid
 autoPtr<psiuReactionThermo> pThermo
                           ^
../XiFoam/createFields.H:5:5: error: ‘psiuReactionThermo’ is not a class, namespace, or enumeration
     psiuReactionThermo::New(mesh)
     ^~~~~~~~~~~~~~~~~~
../XiFoam/createFields.H:7:21: error: ‘thermo’ was not declared in this scope
 psiuReactionThermo& thermo = pThermo();
                     ^~~~~~
../XiFoam/createFields.H:7:38: error: ‘pThermo’ cannot be used as a function
 psiuReactionThermo& thermo = pThermo();
                                      ^
../XiFoam/createFields.H:10:1: error: ‘basicMultiComponentMixture’ was not declared in this scope
 basicMultiComponentMixture& composition = thermo.composition();
 ^~~~~~~~~~~~~~~~~~~~~~~~~~
../XiFoam/createFields.H:10:29: error: ‘composition’ was not declared in this scope
 basicMultiComponentMixture& composition = thermo.composition();
                             ^~~~~~~~~~~
In file included from /opt/OpenFOAM/OpenFOAM-v1906/src/OpenFOAM/lnInclude/postProcess.H:129:0,
                 from coldEngineFoam.C:47:
../XiFoam/createFields.H:93:9: error: ‘laminarFlameSpeed’ was not declared in this scope
 autoPtr<laminarFlameSpeed> unstrainedLaminarFlameSpeed
         ^~~~~~~~~~~~~~~~~
../XiFoam/createFields.H:93:26: error: template argument 1 is invalid
 autoPtr<laminarFlameSpeed> unstrainedLaminarFlameSpeed
                          ^
../XiFoam/createFields.H:95:5: error: ‘laminarFlameSpeed’ is not a class, namespace, or enumeration
     laminarFlameSpeed::New(thermo)
     ^~~~~~~~~~~~~~~~~
../XiFoam/createFields.H:93:28: warning: unused variable ‘unstrainedLaminarFlameSpeed’ [-Wunused-variable]
 autoPtr<laminarFlameSpeed> unstrainedLaminarFlameSpeed
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/rules/General/transform:8: /opt/OpenFOAM/OpenFOAM-v1906/platforms/linux64GccDPInt32Opt/applications/solvers/combustion/coldEngineFoam/coldEngineFoam.o] Error 1
make[1]: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/apps:39: coldEngineFoam] Error 2
make: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/apps:39: combustion] Error 2
make: *** Waiting for unfinished jobs....
Making dependency list for source file rhoPimpleDyMFoam.C
Making dependency list for source file mdFoam.C
Making dependency list for source file rhoPorousSimpleFoam.C
+ wmake
Making dependency list for source file rhoCentralFoam.C
In file included from /opt/OpenFOAM/OpenFOAM-v1906/src/OpenFOAM/lnInclude/postProcess.H:129:0,
                 from rhoPorousSimpleFoam.C:44:
../createFields.H: In function ‘int main(int, char**)’:
../createFields.H:3:9: error: ‘psiThermo’ was not declared in this scope
 autoPtr<psiThermo> pThermo
         ^~~~~~~~~
../createFields.H:3:18: error: template argument 1 is invalid
 autoPtr<psiThermo> pThermo
                  ^
../createFields.H:5:5: error: ‘psiThermo’ is not a class, namespace, or enumeration
     psiThermo::New(mesh)
     ^~~~~~~~~
../createFields.H:7:12: error: ‘thermo’ was not declared in this scope
 psiThermo& thermo = pThermo();
            ^~~~~~
../createFields.H:7:29: error: ‘pThermo’ cannot be used as a function
 psiThermo& thermo = pThermo();
                             ^
make[3]: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/rules/General/transform:8: /opt/OpenFOAM/OpenFOAM-v1906/platforms/linux64GccDPInt32Opt/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/rhoPorousSimpleFoam.o] Error 1
make[2]: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/apps:39: rhoPorousSimpleFoam] Error 2
make[1]: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/apps:39: rhoSimpleFoam] Error 2
make[1]: *** Waiting for unfinished jobs....
Making dependency list for source file scalarTransportFoam.C
Making dependency list for source file rhoPimpleFoam.C
+ wmake rhoCentralDyMFoam
Making dependency list for source file rhoCentralDyMFoam.C
make: *** [/opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/apps:39: compressible] Error 2

解決方法

余計な環境変数を削除します。

unset C_INCLUDE_PATH CPLUS_INCLUDE_PATH G_BROKEN_FILENAMES G_FILENAME_ENCODING

参考

0002386: Cannot compile the code with error ” ‘psiuReactionThermo’ was not declared in this scope” – OpenFOAM Issue Tracking