Skip to content

OpenFOAM

OpenFOAM交流区

5.2k 主题 30.6k 帖子
  • source pack在unbuntu安装问题

    2
    2 帖子
    2k 浏览
    李东岳

    我猜测你这个是源代码没写对,或者拷贝复制的时候丢了代码,undefined reference这种错误只是在编译类后捆绑到求解器的时候函数没定义导致。可能你代码里面有些函数代码块丢失了。

    以上只是猜测,因为不清楚你安装的详细过程不能确诊。

  • MULES, CMULES and IMULES 测试

    13
    13 帖子
    13k 浏览
    李东岳

    @金石为开
    等回德国我回复你。MULES这个2018年应该可以写个解析出来。2016年就在计划中,但是有别的事情要搞。

  • 算例初始条件设置求助!

    10
    10 帖子
    9k 浏览
    tidedrinkerT

    @txwwbz 建议你把错误信息贴上来,你的图片我只能看见一张,另外C指的是什么?

  • solveSegragated的问题?

    2
    2 帖子
    3k 浏览

    哦,

    diag() = saveDiag;//恢复diag

    是在括号之前的,所以每次的修改不会叠加。

    之前理解错误的一点是所有的边界有关的系数都是放在internalCoeffs和boundaryCoeffs中的,不仅仅是coupled BC。从初始化时候的size可以看出来。

    template<class Type> Foam::fvMatrix<Type>::fvMatrix ( const GeometricField<Type, fvPatchField, volMesh>& psi, const dimensionSet& ds ) : lduMatrix(psi.mesh()), psi_(psi), dimensions_(ds), source_(psi.size(), Zero), internalCoeffs_(psi.mesh().boundary().size()), //和边界的face数大小一样。 boundaryCoeffs_(psi.mesh().boundary().size()), faceFluxCorrectionPtr_(nullptr) { //...

    不过非耦合的应该是internalCoeffs放比例系数,boundaryCoeffs放源项,而耦合的BC是internalCoeffs放owner的系数,boundaryCoeffs放的另一侧单元的系数。从addBoundarySource()的源代码可以看出。

    template<class Type> void Foam::fvMatrix<Type>::addBoundarySource ( Field<Type>& source, const bool couples ) const { forAll(psi_.boundaryField(), patchi) { const fvPatchField<Type>& ptf = psi_.boundaryField()[patchi]; const Field<Type>& pbc = boundaryCoeffs_[patchi]; if (!ptf.coupled())//非耦合边界,只有owner,另一侧没有单元,pbc存的是边界源项。 { addToInternalField(lduAddr().patchAddr(patchi), pbc, source); } else if (couples)//耦合边界,如果couples==true, 另一侧有单元,pbc存的是另一侧单元的系数。 { const tmp<Field<Type>> tpnf = ptf.patchNeighbourField(); const Field<Type>& pnf = tpnf(); const labelUList& addr = lduAddr().patchAddr(patchi); forAll(addr, facei) { source[addr[facei]] += cmptMultiply(pbc[facei], pnf[facei]); } } } }
  • Lagrangian怎么求得面上的粒子速度?

    2
    2 帖子
    3k 浏览
    O

    好吧,既然没有人回答,我就把我的笨办法贴出来
    foamToVTK-->paraview-->打开算例文件和粒子Cloud文件-->File/Save Data-->得到每个时间步每个粒子信息.csv-->用python提取有用信息

  • 1 帖子
    2k 浏览
    use OpenFOAM in docker

    OS: windows 10

    Install docker for windows

    site: https://www.docker.com/

    download: Docker for Windows Installer.exe

    edition: most recent stable, for me, it is Docker version 17.09.0, community edition

    installation instructions: https://docs.docker.com/docker-for-windows/

    test

    after completion of the installation, run Docker for Windows. It will cost some time to start the docker engine.

    right click "Start" button, choose "Windows Powershell"

    docker --version ## Docker version 17.09.0-ce, build afdb6d4 docker-compose --version ## docker-compose version 1.16.1, build 6d1ac219 docker-machine --version ## docker-machine.exe version 0.12.2, build 9371605 docker run hello-world ## ## Hello from Docker! ## This message shows that your installation appears to be working correctly. ## ## To generate this message, Docker took the following steps: ## 1. The Docker client contacted the Docker daemon. ## 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. ## (amd64) ## 3. The Docker daemon created a new container from that image which runs the ## executable that produces the output you are currently reading. ## 4. The Docker daemon streamed that output to the Docker client, which sent it ## to your terminal. ## ## To try something more ambitious, you can run an Ubuntu container with: ## $ docker run -it ubuntu bash ## ## Share images, automate workflows, and more with a free Docker ID: ## https://cloud.docker.com/ ## ## For more examples and ideas, visit: ## https://docs.docker.com/engine/userguide/ docker ps -a ## CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ## 32a621d46d34 hello-world "/hello" 24 seconds ago Exited (0) 23 seconds ago clever_agnesi docker rm 32a621d46d34 #change it to your container ID ## 32a621d46d34 docker ps -a ## CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES download OpenFOAM image

    right click "Start" button, choose "Windows Powershell"

    docker pull openfoamplus/of_v1706_centos73 # OF+ # or docker pull openfoam/openfoam5-paraview54 # OF5 # list images docker image ls run OpenFOAM

    Right click on the "Docker" icon in the system tray, choose "settings"

    Click "Shared drives"

    choose any drive you want to share, in my case, I choose C, then click "apply"

    you may need to input credentials

    use openfoam+1706 as example.

    press "WIN+R", input cmd and enter

    rem test docker run --rm -v c:/Users:/data alpine ls /data rem ONLY `C:/Users` and its subfolders can be mounted docker run ^ -i -t ^ --name myOFplus_1706 ^ -v c:/Users/dic17007/OpenFOAM:/OF ^ openfoamplus/of_v1706_centos73 ^ bash rem press `Ctrl+p`, `Ctrl+q` to return without stop the container docker attach myOFplus_1706 rem press `Ctrl+c` or input `exit` to return and stop the container

    Note: you are root user in docker and the password is ofuser2017. Reference

    setup the environment:

    alias of1706="HOME=/OF source $DOCKER_OPENFOAM_PATH" # add to `~/.bashrc` # echo 'alias of1706="HOME=/OF source $DOCKER_OPENFOAM_PATH"'>>~/.bashrc

    run testcase

    of1706 #activate openfoam mkdir -p $FOAM_RUN run pwd #/OF/OpenFOAM/-v1706/run cp $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity -r . cd cavity foamJob -screen blockMesh foamJob -screen icoFoam touch a.foam ## use Ctrl+P, Ctrl+Q to return to `cmd` ## use `docker attach myOFplus_1706`

    return to windows, use paraview to do post-process.

    0_1513906857278_cavity.png

    modify OpenFOAM solver replication run cd .. mkdir -p applications/solvers cd applications/solvers # I put my solver here. pwd # /OF/OpenFOAM/-v1706/applications/solvers cp $FOAM_SOLVERS/incompressible/icoFoam -r . mv icoFoam myIcoFoam cd myIcoFoam mv icoFoam.C myIcoFoam.C sed -i s/icoFoam/myIcoFoam/g myIcoFoam.C sed -i s/icoFoam/myIcoFoam/g Make/files sed -i s/FOAM_APPBIN/FOAM_USER_APPBIN Make/files

    make

    wmake

    test

    run cd cavity which myIcoFoam foamJob -screen myIcoFoam modification

    I am trying to output the matrix in COO format ( Coordinate Format). It will be consists of three parts:

    AA: non-zero values JR: row index JC: column index

    According to the definition of Foam::lduMatrix::Amul() function, there are 4 part of scalar matrix:

    diagonal terms: JC, JR=1 ... nCells, AA = matrix.diag();

    upper terms: JC > JR

    JR=matrix.lduAddr().upperAddr()[0...mFaces-1]+1 JC=matrix.lduAddr().lowerAddr()[0...mFaces-1]+1 AA=matrix.upper()

    lower terms: JR > JC

    JR=matrix.lduAddr().lowerAddr()[0...mFaces-1]+1 JC=matrix.lduAddr().upperAddr()[0...mFaces-1]+1 AA=matrix.lower()

    boundary term, only considering single processor problem here. There are 3 types of patch types:

    geometric (constraint) type. basic derived

    In the following program, I assume there is not coupled interface such as processor patch or cyclic patch.

    reference: Matrix coupling of different processors

    Here is the code.

    A c++ library cnpy is used to generate npy or npz file for numpy.

    site: https://github.com/rogersce/cnpy command: git clone https://github.com/rogersce/cnpy.git cd cnpy mkdir build cd build cmake .. -DENABLE_STATIC=ON make make install

    dumpFvMatrix.H

    #pragma once // added by CatDog #include<iostream> #include<fstream> #include<string> #include"cnpy.h" void dumpFvMatrix(string path, const fvScalarMatrix& EqnPtr) { const label nCells = EqnPtr.diag().size(); const label nFaces = EqnPtr.lower().size(); const scalar* const __restrict__ diagPtr = EqnPtr.diag().begin(); const label* const __restrict__ uPtr = EqnPtr.lduAddr().upperAddr().begin(); const label* const __restrict__ lPtr = EqnPtr.lduAddr().lowerAddr().begin(); const scalar* const __restrict__ upperPtr = EqnPtr.upper().begin(); const scalar* const __restrict__ lowerPtr = EqnPtr.lower().begin(); std::vector<scalar> AA(nCells+2*nFaces); std::vector<label> JR(nCells+2*nFaces); std::vector<label> JC(nCells+2*nFaces); // diag for(label cell=0;cell<nCells;cell++) { AA[cell]=diagPtr[cell]; JR[cell]=cell; JC[cell]=cell; } for(label face=0;face<nFaces;face++) { AA[face]=upperPtr[face]; JR[face]=lPtr[face]; JC[face]=uPtr[face]; } for(label face=0;face<nFaces;face++) { AA[face]=lowerPtr[face]; JR[face]=uPtr[face]; JC[face]=lPtr[face]; } cnpy::npz_save(path,"nCells",&nCells,{1},"w"); cnpy::npz_save(path,"nFaces",&nFaces,{1},"a"); cnpy::npz_save(path,"AA",&AA[0],{nCells+2*nFaces},"a"); cnpy::npz_save(path,"JR",&JR[0],{nCells+2*nFaces},"a"); cnpy::npz_save(path,"JC",&JC[0],{nCells+2*nFaces},"a"); return; } in myIcoFoam.C // ... #include "fvCFD.H" #include "pisoControl.H" #include "dumpFvMatrix.H" // ... // Non-orthogonal pressure corrector loop while (piso.correctNonOrthogonal()) { // Pressure corrector fvScalarMatrix pEqn ( fvm::laplacian(rAU, p) == fvc::div(phiHbyA) ); pEqn.setReference(pRefCell, pRefValue); pEqn.solve(mesh.solver(p.select(piso.finalInnerIter()))); if (piso.finalNonOrthogonalIter()) { phi = phiHbyA - pEqn.flux(); } if (runTime.timeIndex()==2) { Info<< "TimeIndex = 2, output matrix pEqn"<<endl; dumpFvMatrix("/OF/OpenFOAM/-v1706/run/cavity/pEqn.npz",pEqn); } } // ... options file: EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I/usr/local/include EXE_LIBS = \ -lfiniteVolume \ -lmeshTools \ -Wl,-rpath -Wl,/usr/local/lib -lcnpy python script to read the matrix and find LU-SGS's effectiveness. import numpy as np import scipy as sp from scipy.sparse import coo_matrix,tril,triu,diags from scipy.linalg import norm data=np.load('pEqn.npz') nCells=data["nCells"][0] nFaces=data["nFaces"][0] AA=data['AA'] JR=data['JR'] JC=data['JC'] A=coo_matrix((AA,(JR,JC)),shape=(nCells,nCells)) L=tril(A,-1) U=triu(A,1) D=diags(AA[0:nCells],0) Dinv=diags(1.0/AA[0:nCells],0) delta= L.dot(Dinv).dot(U) print "norm of error of LU-SGS: norm(L*Dinv*U)=", norm(delta.toarray())/norm(A.toarray()) # a Laplacian operator # proof of diagonally dominance print abs(np.abs((L+U).toarray()).sum(1)/np.abs(D.toarray()).sum(1)-1).max() # proof of symmetry print abs(L-U.T).sum() ## reference: Jisheng Kou, Yitian Li, A uniparametric LU-SGS method for systems of nonlinear equations, In Applied Mathematics and Computation, Volume 189, Issue 1, 2007, Pages 235-240, ISSN 0096-3003, f=lambda w:norm(((1-w)*(L+U)-w*w*L.dot(Dinv).dot(U)).toarray())/norm(A.toarray()) for w in np.linspace(0,1,100): print f(w)

    最后结果:

    >>> >>> print "norm of error of LU-SGS: norm(L*Dinv*U)=", norm(delta.toarray())/norm(A.toarray()) relative norm of error of LU-SGS: norm(L*Dinv*U)= 0.141875980931 >>> ... # a Laplacian operator ... # proof of diagonally dominance ... print abs(np.abs((L+U).toarray()).sum(1)/np.abs(D.toarray()).sum(1)-1).max() 0.5 >>> # proof of symmetry ... print abs(L-U.T).sum() 0.0
  • reactingEulerfoam的组分输运方程

    2
    2 帖子
    3k 浏览
    李东岳

    18年我会搞这个...

    在输运方程里加源相

    在传输方程里面加源相?不就是加个字符么?还是怎么了

    fvm::ddt(T) == S
  • ESI openfoam 安装问题

    2
    2 帖子
    3k 浏览
    李东岳

    并没有尝试过这个安装包。我推荐你采用bash自己装。http://dyfluid.com/install.html 在windows10中安装OpenFOAM

  • sampleDict 提取圆柱边界速度啊

    1
    1 帖子
    2k 浏览

    sampleDict 如何提取一个圆柱固壁上的所有速度啊

  • interPhaseFoam中物性参数设置?

    2
    2 帖子
    3k 浏览
    李东岳

    sigma是表面张力

  • OF中的绝对压力和相对压力?

    4
    4 帖子
    5k 浏览
    李东岳

    需要给真实的压力,可以从单位判别出来,如果是压力/密度的,就不需要,如果是压力的单位,建议给真实的压力。

  • 相对通量和通量的区别?

    2
    2 帖子
    3k 浏览
    李东岳

    请问下这两者是不是同一种东西两个写法呢?

    fvc::flux(U)可以选定各种格式,如果你指定他的格式是linear,那么fvc::flux(U)=linearInterpolate(U) & mesh.Sf()

  • OpenFOAM5.0计算速度比4.1更慢?

    6
    6 帖子
    6k 浏览
    tidedrinkerT

    @100yearsalone 我只试了一个算例,就这个算例来看,pimpleDyMFoam两个版本没有明显的速度差别

  • Integrate Variable进行内部面积分

    1
    1 帖子
    2k 浏览
    J

    paraview对计算区域内部的一个面进行积分求平均流速
    选了一个面slice
    然后用plot Overline
    最后用了integrateVariable积分,发现求得的平均流速差很多, 所以怀疑这个工具是否靠谱?有用过这个的吗?

  • 无源项更新变量

    1
    1 帖子
    2k 浏览
    李东岳
    //- Update moments manually //{ //const scalar& deltaT = mesh_.time().deltaTValue(); //scalarField& MIf = M_[kth]; //const scalarField& M0 = M_[kth].oldTime(); //MIf = 0.0; //fvc::surfaceIntegrate(MIf, mFlux_[kth]); //MIf = M0 - deltaT*MIf; //M_[kth].correctBoundaryConditions(); //}
  • 紊流模型,周期性边界条件

    2
    2 帖子
    3k 浏览
    李东岳

    但是这样没法驱动流动

    如果开始就有速度的话,并且壁面没有摩擦力,可以一直流下去

    可以通过在求解器中加一个源项在进口驱动流动

    可以添加一个固定的压力梯度项

    但是如果加入了紊流模型,紊动能在进口的的这个边界怎么给呢?仅仅是周期性边界好像不行吧?

    给不了。周期性边界条件给不了随即的湍流波动。

  • 关于OpenFOAM可压缩流求解压力方程的问题

    6
    6 帖子
    6k 浏览
    昝磊

    @dzw05 好的,谢谢你的建议!我再试一试。

  • paraview显示面场?

    5
    5 帖子
    4k 浏览
    李东岳

    um. I dont understand. 我这是个2为网格,每个网格单元应该有4个内部面面,但是两个empty边界面上却具有通量?

  • outlet设为速度出口,压力为固定值结果很奇怪

    2
    2 帖子
    3k 浏览
    李东岳

    你用的什么进口条件?你的设置符合常规设置么?see Ferziger and Peric page 315

  • compressibleinterfoam能够计算激波吗?

    9
    9 帖子
    9k 浏览
    Y

    @mohui 谢谢哈,