OpenFOAM小代码
-
fvOption小工具
根据GitHub上一个python脚本改写了一个生成fvOption的小工具 https://github.com/Veenxz/fvSchemes
用Foam没有多久,各位大佬可以多提提意见。# version 2.0 # Based on https://github.com/Carlopasquinucci/fvSchemes # Generation by Veenxz # relaesed under license GPL GNU 3.0 steady = True pseudo_transient = False precision = 2 # First order 1 or Second order 2 unbounded = False LUST = False secondorder = True maxOrtho = 80 maxSkew = 20 # Header and Footer h = [ "/*--------------------------------*- C++ -*----------------------------------*|", "| ========= | |", "| \\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |", "| \\\ / O peration | Website: https://openfoam.org |", "| \\\ / A nd | Version: 7 |", "| \\\/ M anipulation | |", "\*---------------------------------------------------------------------------*/", "FoamFile", "{", " version 2.0;", " format ascii;", " class dictionary;", ' location "system";', " object fvSchemes;", "}", "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //", "" ] footer = '\n// ************************************************************************* //' nonOrthogonalCorrectors = 1 if (maxOrtho) > 80: print( 'Warning: mesh is not so nice. Use 3 nonOrthogonalCorrectors in fvSolution file' ) nonOrthogonalCorrectors = 3 if (maxSkew) > 8: print('Warning: mesh is not so nice') if (maxOrtho) > 80: gradSchemes = ( '{\n default cellLimited Gauss linear 0.5;\n' ' grad(U) faceLimited Gauss linear 1.0;\n}' ) divSchemes = ( '{\n div(phi,U) Gauss linearUpwind grad(U);\n' ' div(phi,omega) Gauss upwind;\n' ' div(phi,k) Gauss upwind;\n' ' div(phi,e) Gauss upwind;\n' ' div((nuEff*dev(T(grad(U))))) Gauss linear;\n}' ) laplacianSchemes = ( '{\n default Gauss linear limited 0.333;\n}' ) snGradSchemes = ( '{\n default Gauss linear limited 0.333;\n}' ) blending = 0.2 nonOrthogonalCorrectors = 3 if (maxOrtho) > 70: gradSchemes = ( '{\n default cellLimited Gauss linear 0.5;\n' ' grad(U) cellLimited Gauss linear 1.0;\n}' ) divSchemes = ( '{\n div(phi,U) Gauss linearUpwind grad(U);\n' ' div(phi,omega) Gauss linearUpwind grad(omega);\n' ' div(phi,k) Gauss linearUpwind grad(k);\n' ' div(phi,e) Gauss linearUpwind grad(e);\n' ' div((nuEff*dev(T(grad(U))))) Gauss linear;\n}' ) laplacianSchemes = ( '{\n default Gauss linear limited 0.5;\n}' ) snGradSchemes = ( '{\n default Gauss linear limited 0.5;\n}' ) blending = 0.5 nonOrthogonalCorrectors = 3 if (maxOrtho) > 60: gradSchemes = ( '{\n default cellMDLimited Gauss linear 0.5;\n' ' grad(U) cellMDLimited Gauss linear 0.5;\n}' ) divSchemes = ( '{\n div(phi,U) Gauss linearUpwind grad(U);\n' ' div(phi,omega) Gauss linearUpwind grad(omega);\n' ' div(phi,k) Gauss linearUpwind grad(k);\n' ' div(phi,e) Gauss linearUpwind grad(e);\n' ' div((nuEff*dev(T(grad(U))))) Gauss linear;\n}' ) laplacianSchemes = ( '{\n default Gauss linear limited 0.777;\n} ' ) snGradSchemes = ( '{\n default Gauss linear limited 0.777;\n} ' ) blending = 0.7 nonOrthogonalCorrectors = 2 if (maxOrtho) > 0: gradSchemes = ( '{\n default cellMDLimited Gauss linear 0;\n' ' grad(U) cellMDLimited Gauss linear 0.333;\n}' ) divSchemes = ( '{\n div(phi,U) Gauss linearUpwind grad(U);\n' ' div(phi,omega) Gauss linearUpwind grad(omega);\n' ' div(phi,k) Gauss linearUpwind grad(k);\n' ' div(phi,e) Gauss linearUpwind grad(e);\n' ' div((nuEff*dev(T(grad(U))))) Gauss linear;\n}' ) laplacianSchemes = ( '{\n default Gauss linear limited 0.95;\n}' ) snGradSchemes = ( '{\n default Gauss linear limited 0.95;\n}' ) blending = 0.8 nonOrthogonalCorrectors = 1 if (LUST): gradSchemes = ( '{\n default Gauss linear;\n' ' grad(U) cellMDLimited leastSquares 1;\n}' ) divSchemes = ( '{\n div(phi,U) Gauss LUST grad(U);\n' ' div(phi,omega) Gauss LUST grad(omega);\n' ' div(phi,k) Gauss LUST grad(k);\n' ' div(phi,e) Gauss LUST grad(e);\n' ' div((nuEff*dev(T(grad(U))))) Gauss linear;\n}' ) laplacianSchemes = ( '{\n default Gauss linear corrected;\n}' ) snGradSchemes = ( '{\n default Gauss linear corrected;\n}' ) blending = 0.9 nonOrthogonalCorrectors = 1 if (steady): ddtSchemes = ( '{\n default steadyState;\n}' ) if (pseudo_transient): ddtSchemes = ( '{\n default localEuler;\n}' ) else: ddtSchemes = ( '{\n default CrankNicolson ' + str(blending) + ' ;\n}' ) if precision == 1: ddtSchemes = ( '{\n default Euler;\n}' ) if (unbounded): ddtSchemes = ( '{\n default backward;\n}' ) wallDist = ( "{\n method meshWave;\n}" ) #open fvSchemes and write inside f = open("fvSchemes", "w") for i in h: f.write(i + "\n") f.write("ddtSchemes" + "\n") f.write(ddtSchemes + "\n") f.write("\n") f.write("gradSchemes" + "\n") f.write(gradSchemes + "\n") f.write("\n") f.write("divSchemes" + "\n") f.write(divSchemes + "\n") f.write("\n") f.write("laplacianSchemes" + "\n") f.write(laplacianSchemes + "\n") f.write("\n") f.write("snGradSchemes" + "\n") f.write(snGradSchemes + "\n") f.write("\n") f.write("wallDist" + "\n") f.write(wallDist + "\n") f.write(footer) f.close() print('File fvSchemes created')
-
@李东岳 在 OpenFOAM小代码 中说:
IOField<scalar> utau
(
IOobject
(
"utau",
runTime.constant(),
"../postProcessing",
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
scalarField(totalFSize,0.0)
);请问老师,如果我想要在postProcessing中输出一个标量,他只是一个数,并不是场量,我应该怎么定义他的类型。上面这种方法是不是只适应于场量的输出。我想输出的是下面c的数值。
const volScalarField& b = mesh().lookupObject<volScalarField>("alpha.liquid"); scalar c= b.weightedAverage(mesh().V()).value();
-
IOList<scalar> utau ( IOobject ( "utau", runTime.constant(), "../postProcessing", mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), 1 ); utau[0] = b.weightedAverage(mesh().V()).value();
-
totalLiquid { libs (utilityFunctionObjects); type coded; name totalLiquid; enabled true; writeControl timeStep; writeInterval 1; codeOptions #{ -I$(LIB_SRC)/meshTools/lnInclude #}; codeExecute #{ const volScalarField& b = mesh().lookupObject<volScalarField>("alpha.liquid"); IOList<scalar> liquidFraction ( IOobject ( "liquidFraction", mesh().time().constant(), "../postProcessing", mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), 1 ); liquidFraction[0] = b.weightedAverage(mesh().V()).value(); #}; }
东岳老师,我这样添加到controlDict里,运行后postProcessing里并没有出现liquidFraction的值。
-
@hongjiewang 在 OpenFOAM小代码 中说:
totalLiquid { libs (utilityFunctionObjects); type coded; name totalLiquid; enabled true; writeControl timeStep; writeInterval 1; codeOptions #{ -I$(LIB_SRC)/meshTools/lnInclude #}; codeExecute #{ const volScalarField& b = mesh().lookupObject<volScalarField>("alpha.liquid"); IOList<scalar> liquidFraction ( IOobject ( "liquidFraction", mesh().time().constant(), "../postProcessing", mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), 1 ); liquidFraction[0] = b.weightedAverage(mesh().V()).value(); #}; }
东岳老师,我这样添加到controlDict里,运行后postProcessing里并没有出现liquidFraction的值。
需要修改两个部分,
1.在下方添加 .write()
2.将codeExecute改为codeWrite
之后就可以得到想要的相含量结果。 -
meanDiameter { type coded; libs ("libutilityFunctionObjects.so"); name error; codeExecute #{ const volScalarField& d = mesh().lookupObject<volScalarField>("d.alpha.oil"); scalar d32 = d.weightedAverage(mesh().V()).value(); if (Pstream::master()) { std::ofstream file; file.open ("d32", std::ofstream::out | std::ofstream::app); file << mesh().time().timeName() << " " << d32 << "\n"; file.close(); } #}; }
我最近也凑巧要用这个,我用的上面这种方式。
-
@hongjiewang 在 OpenFOAM小代码 中说:
@李东岳 目前我需要将温度边界和压力边界定义为随相含量变化的一个场。我只可以做到变化之后的也是同一类边界条件,但是像下图中的气相区压力是第一类边界条件,液相区温度是第二类边界条件。请问这种变边界类型的边界应该怎么定义~
已解决压力的~但是温度的第二类和第三类的转换还没有解决~
-