原有的湍流模型加上非线性项雷诺应力的问题
-
@李东岳 在 原有的湍流模型加上非线性项雷诺应力的问题 中说:
每个步长首先通过pytorch获取g(i),g(i)是一些列的标量
把g(i)的数值传输到OpenFOAM的非线性湍流模型里
每个时间步封闭,速度压力耦合求解
进入到下一个时间步,回归到第一步所以这是机器学习+CFD的一种方法。但是因为每一步都要训练出来一个g(i),所以速度慢。
一个有关g(i)隐式的公式,若能被OF识别并有效输出,那我就不用每次迭代计算调用pytorch来进行计算
你们打算找出来g(i)的一个公式,写成$g(i)=f(\bfU)$类似的函数,然后流程就变成了:
- 最开始训练出$g(i)=f(\bfU)$函数表达式
- 进行CFD求解(在这一步里面,不需要花时间训练找参数)
我这样理解对么?
-
@李东岳 李老师,我遇到一个wmake的问题。我把我训练完成的神经网络写成一个reynoldsNet库,打算在linearViscousStrees中调用,但是显示了无法识别的问题这是什么导致的?
wmakeLnIncludeAll: running wmakeLnInclude on dependent libraries: unknown option: '-I/home/user3/OpenFOAM/user3-9/reynoldsNet/lnInclude' Usage: wmakeLnInclude [OPTION] [dir] options: -update | -u update -silent | -s use 'silent' mode (do not echo command) -help | -h print the usage Link all the source files in the <dir> into <dir>/lnInclude Note The '-u' option forces an update when the lnInclude directory already exists and changes the default linking from 'ln -s' to 'ln -sf'.
-
@李东岳 上面的步骤是在编译MomentumTransportModels文件夹时候的。同时,我在simpleNNFoam中修改了我的需要连接的linearViscousStrees中的divDevTau(U, S, R),S跟R都已经在 createFields.H中创建了。
// Momentum predictor MRF.correctBoundaryVelocity(U); tmp<fvVectorMatrix> tUEqn ( fvm::div(phi, U) + MRF.DDt(U) + turbulence->divDevTau(U, S, R) // Data driven R-S + viscous component == fvModels.source(U) ); fvVectorMatrix& UEqn = tUEqn.ref(); UEqn.relax(); fvConstraints.constrain(UEqn); if (simple.momentumPredictor()) { solve(UEqn == -fvc::grad(p)); fvConstraints.constrain(U); }
但是我在wmake我的simpleNNFoam中出现了,数据类型不对的问题。
In file included from /home/user3/libtorch/include/c10/util/Exception.h:7, from /home/user3/libtorch/include/ATen/core/Generator.h:11, from /home/user3/libtorch/include/ATen/CPUGeneratorImpl.h:3, from /home/user3/libtorch/include/ATen/Context.h:3, from /home/user3/libtorch/include/ATen/ATen.h:7, from /home/user3/libtorch/include/torch/csrc/api/include/torch/types.h:3, from /home/user3/libtorch/include/torch/script.h:3, from /home/user3/OpenFOAM/user3-9/reynoldsNet/lnInclude/reynoldsNet.H:42, from /home/user3/OpenFOAM/user3-9/src/MomentumTransportModels/momentumTransportModels/lnInclude/linearViscousStress.H:38, from /home/user3/OpenFOAM/user3-9/src/MomentumTransportModels/momentumTransportModels/lnInclude/Stokes.H:39, from /home/user3/OpenFOAM/user3-9/src/MomentumTransportModels/momentumTransportModels/lnInclude/laminarModel.C:27, from /home/user3/OpenFOAM/user3-9/src/MomentumTransportModels/momentumTransportModels/lnInclude/laminarModel.H:193, from /home/user3/OpenFOAM/user3-9/src/MomentumTransportModels/incompressible/lnInclude/kinematicMomentumTransportModel.H:47, from simpleNNFoam.C:66: /home/user3/libtorch/include/c10/util/variant.h:1204:11: error: no matching function for call to 'Foam::data::data(const c10::detail_::impl<c10::SmallVector<c10::SymInt, 5>, at::Tensor>&)' 1204 | data(lib::forward<V>(v)), | ^~~~~~~~~~~~~~~~~~~~~~~~
我查看了 Foam::data::data(const objectRegistry& obr),要的是objectRegistry类,但是在我的reynoldsNet库中已经将libtorch输出的torch::Tensor转换成std::vector<float>然后带入输出,没有将是torch的数据直接带入OF中。这是有数据没按要求来转换吗?
-
-
@SHUKK 老铁这个工作做的怎么样了
另外我这段时间也关注这些东西。初步有个这个结论,这个是我自己想的:
目前都是openfoam+pytorch而不是openfoam+libtorch,但是我测试openfoam+libtorch完全可以混编,并且编译起来很简单。如果openfoam+pytorch,这里面等于添加了个python的API。我就没太理解大家为什么用的都是openfoam+pytorch而不是openfoam+libtorch。后来我捉摸应该是机器学习那面好多人都是python程序员,然后就专门写了个python版本的pytorch,对于他们那一圈人,pytorch比较好用... 只有这一个原因。
因为我最近要试一下PINN求解PDE。对于那面来说,用纯粹的pytorch就可以。但是pytorch写起来比较麻烦。好多人就用了个接口交deepxde。
那对于为什么用的都是openfoam+pytorch而不是openfoam+libtorch,纯粹是用户习惯的原因,不知道我理解的对不对。
-
If you would prefer to write Python, and can afford to write Python, we recommend using the Python interface to PyTorch. However, if you would prefer to write C++, or need to write C++ (because of multithreading, latency or deployment requirements), the C++ frontend to PyTorch provides an API that is approximately as convenient, flexible, friendly and intuitive as its Python counterpart. The two frontends serve different use cases, work hand in hand, and neither is meant to unconditionally replace the other.
我理解的应该是对的。pytorch,libtorch看个人爱好