贴个对volSymmTensorField进行操作的代码
-
首先对volSymmTensorField进行声明:
Info<< "Creating field alphaUPrimeij and rhoUPrimeij\n" << endl; volSymmTensorField alphaUPrimeij ( IOobject ( "alphaUPrimeij", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh ); volSymmTensorField rhoUPrimeij ( IOobject ( "rhoUPrimeij", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh ); volScalarField myepsilon ( IOobject ( "myepsilon", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh );
然后计算,UMean是通过controlDict-functionObject的fieldAverage算的,然后alphaUPrimeij和rhoUPrimeij也会使用fieldAverage进行时间平均。
if (mesh.thisDb().foundObject<volVectorField>("UMean")) { const volVectorField& UMean_ = mesh.thisDb().lookupObject<volVectorField>("UMean"); const volVectorField UPrime = U - UMean_; const volTensorField gradUPrime(fvc::grad( UPrime )); myepsilon = gradUPrime && gradUPrime; rhoUPrimeij.component(symmTensor::XX)=rho*UPrime.component(vector::X)*UPrime.component(vector::X); rhoUPrimeij.component(symmTensor::XY)=rho*UPrime.component(vector::X)*UPrime.component(vector::Y); rhoUPrimeij.component(symmTensor::XZ)=rho*UPrime.component(vector::X)*UPrime.component(vector::Z); rhoUPrimeij.component(symmTensor::YY)=rho*UPrime.component(vector::Y)*UPrime.component(vector::Y); rhoUPrimeij.component(symmTensor::YZ)=rho*UPrime.component(vector::Y)*UPrime.component(vector::Z); rhoUPrimeij.component(symmTensor::ZZ)=rho*UPrime.component(vector::Z)*UPrime.component(vector::Z); alphaUPrimeij.component(symmTensor::XX)=alpha1*UPrime.component(vector::X)*UPrime.component(vector::X); alphaUPrimeij.component(symmTensor::XY)=alpha1*UPrime.component(vector::X)*UPrime.component(vector::Y); alphaUPrimeij.component(symmTensor::XZ)=alpha1*UPrime.component(vector::X)*UPrime.component(vector::Z); alphaUPrimeij.component(symmTensor::YY)=alpha1*UPrime.component(vector::Y)*UPrime.component(vector::Y); alphaUPrimeij.component(symmTensor::YZ)=alpha1*UPrime.component(vector::Y)*UPrime.component(vector::Z); alphaUPrimeij.component(symmTensor::ZZ)=alpha1*UPrime.component(vector::Z)*UPrime.component(vector::Z); }
目的是计算下面帖子提到的这个多相流的雷诺应力
@学流体的小明 在 如何在controlDict中创建一个场,不需要修改求解器 中说:话说这个latex代码怎么转义不了
使用LES计算气泡槽道流,因为是多相流,某一点可能会有气泡经过,解析的雷诺应力$u\prime_i u\prime_j$会受到很大影响,所以我想对 $u\prime_i u\prime_j$ 进行加权处理。
具体方法是:生成张量场,计算每一个cell每一个瞬时的$\alpha u\prime_i u\prime_j$,$(1-\alpha) u\prime_i u\prime_j$,$\rho u\prime_i u\prime_j$,然后使用fieldAverage进行系综平均。
我想在controlDict中生成场$\rho u\prime_i u\prime_j$,然后每个时刻计算一下这个场,怎样通过functions{ }操作呢?因为是要每一个时间步都计算以获得正确的值,所以不太想按一定时间间隔输出数据之后再进行后处理。
当然也可以直接在solver的createFields.H中创建,我就是想找一个更通用的不用修改求解器的方法,直接很简便地在controlDict - functions{ }中实现。
毕竟functions{ }可以用writeObjects输出/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Version: v2012 \\ / A nd | Website: www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Description Writes out specified objects, e.g. fields, stored on the case database. \*---------------------------------------------------------------------------*/ type writeObjects; libs (utilityFunctionObjects); objects (<object names>); writeControl writeTime; // ************************************************************************* //
-
新代码长这样子:
创造场变量时需要设置初始值,否则程序调用的构造函数一定会去文件中找,会报错说找不到该变量文件。Info<< "Creating field alphaUPrimeij and rhoUPrimeij\n" << endl; volSymmTensorField alphaUPrimeij ( IOobject ( "alphaUPrimeij", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedSymmTensor(dimensionSet(0, 2, -2, 0, 0, 0, 0), symmTensor(0., 0., 0., 0., 0., 0.)) ); volSymmTensorField rhoUPrimeij ( IOobject ( "rhoUPrimeij", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedSymmTensor(dimensionSet(1, -1, -2, 0, 0, 0, 0), symmTensor(0., 0., 0., 0., 0., 0.)) ); volScalarField myepsilon ( IOobject ( "myepsilon", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar(dimensionSet(0, 2, -3, 0, 0, 0, 0), 0.) ); if (mesh.thisDb().foundObject<volVectorField>("UMean")) { const volVectorField& UMean_ = mesh.thisDb().lookupObject<volVectorField>("UMean"); const volVectorField UPrime = U - UMean_; // const volScalarField UPrimeX = UPrime.component(0); // const volScalarField UPrimeY = UPrime.component(1); // const volScalarField UPrimeZ = UPrime.component(2); const volTensorField gradUPrime(fvc::grad( UPrime )); myepsilon = mixture.nu()*gradUPrime && gradUPrime; scalar rhoCell,alphaCell,UPrimeX,UPrimeY,UPrimeZ; forAll(rhoUPrimeij,celli) { rhoCell=rho[celli]; alphaCell=alpha1[celli]; UPrimeX=UPrime[celli][0]; UPrimeY=UPrime[celli][1]; UPrimeZ=UPrime[celli][2]; rhoUPrimeij[celli]=symmTensor( rhoCell*UPrimeX*UPrimeX, rhoCell*UPrimeX*UPrimeY, rhoCell*UPrimeX*UPrimeZ, rhoCell*UPrimeY*UPrimeY, rhoCell*UPrimeY*UPrimeZ, rhoCell*UPrimeZ*UPrimeZ ); alphaUPrimeij[celli]=symmTensor( alphaCell*UPrimeX*UPrimeX, alphaCell*UPrimeX*UPrimeY, alphaCell*UPrimeX*UPrimeZ, alphaCell*UPrimeY*UPrimeY, alphaCell*UPrimeY*UPrimeZ, alphaCell*UPrimeZ*UPrimeZ ); } }