如何在程序中累加不同时刻流场
-
各位前辈好!
我有一个volScalarField场c_flow,现在想累加每一个时刻的c_flow流场,在一段时间后输出c_flow_total
我写的程序如下:
初始化设置c_flow_total流场为0Info<< "Initializing c_flow_total" << endl; volScalarField c_flow_total ( IOobject ( "c_flow_total", mesh.time().timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), mesh, dimensionedScalar("c_flow_total", dimensionSet(0,1,-1,0,0,0,0), 0) );
然后在主程序中计算c_flow和c_flow_total
Info<< "Calculating erosion index c_flow\n" << endl; volScalarField c_flow ( IOobject ( "c_flow", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), 8.97pos(p_rgh - pSat)*sqrt(mag(p_rgh - pSat)/rho1) ); Info<< "Calculating c_flow_total" << endl; volScalarField c_flow_total ( IOobject ( "c_flow_total", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), c_flow_total.oldTime() + c_flow );
程序编译没有问题,但用interPhaseChangeFoam计算case报错如下:
Calculating c_flow_total #0 Foam::error::printStack(Foam::Ostream&) at ??:? #1 Foam::sigSegv::sigHandler(int) at ??:? #2 ? in "/lib64/libc.so.6" #3 Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::storeOldTimes() const at ??:? #4 Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::oldTime() const at ??:? #5 ? at ??:? #6 __libc_start_main in "/lib64/libc.so.6" #7 ? at ??:? Segmentation fault
我感觉可能是oldTime()的使用出现了问题,请问一下大家,在程序中 累加每一个时刻的流场有什么好的办法呢?
-
@小考拉
在createFields.H添加volScalarField c_flow ( IOobject ( "c_flow", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("c_flow", dimensionSet(0,1,-1,0,0,0,0), 0) ); volScalarField c_flow_total ( IOobject ( "c_flow_total", mesh.time().timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), mesh, dimensionedScalar("c_flow_total", dimensionSet(0,1,-1,0,0,0,0), 0) );
然后在主程序里添加
c_flow = 8.97pos(p_rgh - pSat)*sqrt(mag(p_rgh - pSat)/rho1); c_flow_total += c_flow;
我个人认为这样是可以实现的