Skip to content
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(不使用皮肤)
  • 不使用皮肤
折叠
CFD中文网

CFD中文网

  1. CFD中文网
  2. OpenFOAM
  3. mesh_.C()[celli]编译报错

mesh_.C()[celli]编译报错

已定时 已固定 已锁定 已移动 OpenFOAM
6 帖子 2 发布者 632 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • liujmL 离线
    liujmL 离线
    liujm
    写于 最后由 编辑
    #1

    各位前辈大家好,

    我在使用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()返回的结果是否存在差异。

    烦请各位老师解答~

    1 条回复 最后回复
  • liujmL 离线
    liujmL 离线
    liujm
    写于 最后由 编辑
    #2

    mesh_.C()
    mesh_.C().primitiveField()
    mesh_.C().internalField()
    mesh_.C().boundaryField()
    这四个返回值之间的区别是什么呢?

    1 条回复 最后回复
  • C 离线
    C 离线
    coolhhh 神
    写于 最后由 编辑
    #3

    @liujm
    primitiveField() 和 internalField() 是新老版本的区别,都是表示内部场,见链接。
    boundaryField()返回的是边界场,对边界进行操作。
    mesh_.C() 包含了内部场和边界场,估计不能直接操作

    liujmL 1 条回复 最后回复
  • liujmL 离线
    liujmL 离线
    liujm
    在 中回复了 coolhhh 最后由 编辑
    #4

    @coolhhh
    感谢解答,我之所以直接操作mesh.C(),是因为我在源码中搜到了这种用法,OF2012

    a1b14142-f9bc-4f61-bedf-57f7f70174c1-image.png

    C 1 条回复 最后回复
  • C 离线
    C 离线
    coolhhh 神
    在 中回复了 liujm 最后由 编辑
    #5

    @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;
    }
    
    
    liujmL 1 条回复 最后回复
  • liujmL 离线
    liujmL 离线
    liujm
    在 中回复了 coolhhh 最后由 编辑
    #6

    @coolhhh 厉害,测试代码copy了。不过,这里直接操作就又可以了:wocao:

    1 条回复 最后回复

  • 登录

  • 登录或注册以进行搜索。
  • 第一个帖子
    最后一个帖子
0
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]