mesh_.C()[celli]编译报错
-
各位前辈大家好,
我在使用
const vector cellCentre = mesh_.C()[celli]
收集网格中心坐标时,编译器出现报错:In file included from cfdTools/general/porosityModel/floatingDarcyForchheimer/floatingDarcyForchheimer.H:216, from cfdTools/general/porosityModel/floatingDarcyForchheimer/floatingDarcyForchheimer.C:30: cfdTools/general/porosityModel/floatingDarcyForchheimer/floatingDarcyForchheimerTemplates.C: In member function ‘void Foam::porosityModels::floatingDarcyForchheimer::applyInCalcForce(Foam::scalarField&, Foam::vectorField&, const scalarField&, const RhoFieldType&, const scalarField&, const vectorField&, Foam::vectorField&) const’: cfdTools/general/porosityModel/floatingDarcyForchheimer/floatingDarcyForchheimerTemplates.C:119:48: error: no match for ‘operator[]’ (operand types are ‘const volVectorField’ {aka ‘const Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>’} and ‘const label’ {aka ‘const int’}) 119 | const vector cellCentre = mesh_.C()[celli]; |
貌似
mesh_.C()
返回的数据类型不支持使用[]符号,可是为什么在其他代码中就可以这样使用mesh_.C()[celli]
呢?后期,我通过使用
const vector cellCentre = mesh_.C().primitiveField()[celli]
通过编译。不过尚不清楚其与mesh_.C()
返回的结果是否存在差异。烦请各位老师解答~
-
@liujm 试了下确实没问题,
mesh.C()[celli]
效果跟mesh.C().primitiveField()[celli]
效果是一样的。#include "fvCFD.H" int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" label celli = 0; const vector cellCentre = mesh.C()[celli]; const vector cellCentre2 = mesh.C().primitiveField()[celli]; Info << "cellCentre = " << cellCentre << endl; Info << "cellCentre2 = " << cellCentre2 << endl; Info<< "End\n" << endl; return 0; }