0.11875

发布日期:2024-07-03 17:38    点击次数:160

0.11875

工商

本案例演示诈欺OpenFOAM编程达成颗粒追踪并绘画颗粒轨迹。

1 文献结构

诈欺底下的号令创建文献结构。

runfoamNewApp demo16

文献结构如下图所示。

首页-盛 泰玉麻类有限公司

图片

2 技术源码

本案例只需要一个源文献demo16.C,其践诺如下。

 #include "fvCFD.H" /*界说一个函数,用于写入包含由点列表界说的单条多段线的vtk文献。关系vtk文献风光模范,请参阅:https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf*/void saveTrajectoryToVtk(DynamicList<point> &path, fvMesh &mesh){    Info << endl         << "将颗粒旅途写入到VTK文献" << endl;     // 创建一个文献夹用于存放VTK文献    fileName VTK_dir = mesh.time().path() / "VTK";    mkDir(VTK_dir);     // 创建文献指针    autoPtr<OFstream> vtkFilePtr;    vtkFilePtr.reset(new OFstream(VTK_dir / "particle_path.vtk"));     // 写入文献头    vtkFilePtr() << "# vtk DataFile Version 2.0" << endl                 << "particle_path" << endl                 << "ASCII" << endl                 << "DATASET POLYDATA" << endl;    vtkFilePtr() << nl;     // 写入点头部    vtkFilePtr() << "POINTS " << path.size() << " DOUBLE" << endl;    //  写入点坐标    forAll(path, ipt)    {        vtkFilePtr() << path[ipt].x() << "  " << path[ipt].y() << "  " << path[ipt].z() << endl;    }    vtkFilePtr() << nl;     // 写入线的头部与列表    vtkFilePtr() << "LINES 1 " << path.size() + 1 << endl;    vtkFilePtr() << path.size() << endl;    forAll(path,青铜峡市尊辛石膏有限公司 ipt)    {        vtkFilePtr() << ipt << endl;    }     Info << tab << "vtk文献写入完成!" << endl;} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc,
巴彦淖尔市大忠商贸有限公司 char *argv[]){#include "setRootCase.H"#include "createTime.H"#include "createMesh.H"     instantList times = runTime.times(); //取得通盘的时刻    runTime.setTime(times.last(),
首页-达嘉奋皮革有限公司 0);    //建立现常常刻为终末一个时刻点    Info << nl << "使用的数据时刻为:" << runTime.timeName() << endl;     // 读取速率场U    Info << nl << "读取速率场" << endl;    volVectorField U(        IOobject(            "U",            runTime.timeName(),            mesh,            IOobject::MUST_READ,工商            IOobject::NO_WRITE),        mesh);     // 界说颗粒的启动位置,这里简便起见界说了一个固定坐标    point particle(0.01, 0.11875, 0);     //准备粒子位置列表和几个标量变量来存储其总行程时刻和距离    DynamicList<point> particlePositions;    scalar timeTaken(0);    scalar distanceTravelled(0);     // 添加启动化位置到颗粒位置列表中    particlePositions.append(particle);    // 找到无质料颗粒场所的网格,诈欺网格流速来细目颗粒的下一个位置    label cellID = mesh.findCell(particle);    Info << nl << "启动颗粒位于网格 " << cellID << " 中" << endl;     // 描写其他的变量    vector curPos = particle;    vector newPos(0, 0, 0);    label iterCount(1);    const label maxIters(100);     Info << nl << "动手颗粒追踪" << endl;    while (cellID != -1)    {        vector velocity = U[cellID];                   //取得网格的速率        scalar charLen = Foam::cbrt(mesh.V()[cellID]); //取得网格的特征尺寸        scalar dt = charLen / mag(velocity);           //取得特征时刻步长         newPos = curPos + velocity * dt; //揣摸取得新的颗粒位置         scalar dist = mag(newPos - curPos); //取得颗粒在现常常刻步的位移         // 输出信息        Info << nl << "Lagrangian time step: " << iterCount << nl             << tab << "current position = " << curPos << nl             << tab << "new position = " << newPos << nl             << tab << "local distance travelled = " << dist << nl             << tab << "local time taken = " << dt << nl             << tab << "currently reciding cell no. = " << cellID << endl;         // 将数据添加到列表中        distanceTravelled += dist;        timeTaken += dt;        particlePositions.append(newPos);        curPos = newPos;        iterCount++;         cellID = mesh.findCell(curPos);        if (iterCount > maxIters)        {            FatalErrorInFunction << "达到最大的追踪时刻步数!" << abort(FatalError);        }    }     if (cellID == -1) //颗粒离开揣摸域    {        Info << "颗粒离开揣摸区域!" << endl             << "颗粒运行的总距离:" << distanceTravelled << nl             << "颗粒停留时刻:" << timeTaken << endl;    }     // 写入文献    saveTrajectoryToVtk(particlePositions, mesh);     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //     Info << nl;    runTime.printExecutionTime(Info);     Info << "End\n"         << endl;     return 0;} 
3 测试技术

本技术是一个后治理技术,在案例求解收场后使用。

测试案例揣摸取得的速率场。

图片

在案例根旅途下实践技术demo16,恶果如下图所示。

图片

此时在根目次下创建了一个VTK文献夹,其中包含文献particle_path.vtk。

图片

诈欺paraview读取vtk文献搜检轨迹,如下图所示。

图片

(收场)

本站仅提供存储干事,通盘践诺均由用户发布,如发现存害或侵权践诺,请点击举报。

上一篇:出现7个:03、09、15、57、63、69、78

下一篇:没有了