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. 如何在src文件中创建标量物理filed并且调用

如何在src文件中创建标量物理filed并且调用

已定时 已固定 已锁定 已移动 OpenFOAM
27 帖子 3 发布者 17.4k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • 李 离线
    李 离线
    李东岳 管理员
    写于2022年10月11日 03:55 最后由 编辑
    #16

    @chengan-wang 在 如何在src文件中创建标量物理filed并且调用 中说:

    volScalarField summass
    (
    IOobject
    (
    "summass",
    runTime.timeName(),
    mesh,
    IOobject::NO_READ,
    IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar ("zero", dimMass, 0.0)
    );

    把这个提前

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    C 1 条回复 最后回复 2022年10月11日 06:49
  • C 离线
    C 离线
    chengan.wang
    在 2022年10月11日 06:49 中回复了 李东岳 最后由 编辑
    #17

    @李东岳 李老师,按照下列代码

            const label cellIp = p.cell(); 
            scalar PPC = summass.internalField() [cellIp]; 
            PPC += p.nParticle()*p.mass();
    

    编译通过了,也能算了,但是好像没有赋值进去,结果是0

    FoamFile
    {
        version     2.0;
        format      binary;
        class       volScalarField;
        location    "0.0002";
        object      summass;
    }
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    
    dimensions      [1 0 0 0 0 0 0];
    
    internalField   uniform 0;
    
    boundaryField
    {
        walls
        {
            type            calculated;
            value           uniform 0;
        }
    }
    
    
    
    T 1 条回复 最后回复 2022年10月11日 07:38
  • T 离线
    T 离线
    Tens 神
    在 2022年10月11日 07:38 中回复了 chengan.wang 最后由 编辑
    #18

    @chengan-wang 在 如何在src文件中创建标量物理filed并且调用 中说:

        const label cellIp = p.cell(); 
        scalar PPC = summass.internalField() [cellIp]; 
        PPC += p.nParticle()*p.mass();
    

    这样只有PPC这个量在变,summass不跟着变。
    我感觉如果是在src库中进行调用和操作,还是应该在库中创建这个量

    C 1 条回复 最后回复 2022年10月11日 07:44
  • C 离线
    C 离线
    chengan.wang
    在 2022年10月11日 07:44 中回复了 Tens 最后由 编辑
    #19

    @tens 应该是这样的,感觉应该带个指针啥的

    1 条回复 最后回复
  • 李 离线
    李 离线
    李东岳 管理员
    写于2022年10月11日 08:02 最后由 编辑
    #20

    scalar& PPC = summass.internalField().ref() [cellIp]

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    C 1 条回复 最后回复 2022年10月11日 08:09
  • C 离线
    C 离线
    chengan.wang
    在 2022年10月11日 08:09 中回复了 李东岳 最后由 编辑
    #21

    @李东岳 还是不行

    lnInclude/ParticleCollector.C: In member function ‘virtual void Foam::ParticleCollector<CloudType>::postMove(Foam::ParticleCollector<CloudType>::parcelType&, Foam::label, Foam::scalar, const point&, bool&)’:
    lnInclude/ParticleCollector.C:746:43: error: ‘const InternalField {aka const class Foam::Field<double>}’ has no member named ‘ref’
         scalar& PPC = summass.internalField().ref() [cellIp]; 
                                               ^
    lnInclude/ParticleCollector.C: In member function ‘virtual void Foam::ParticleCollector<CloudType>::postMove(Foam::ParticleCollector<CloudType>::parcelType&, Foam::label, Foam::scalar, const point&, bool&)’:
    lnInclude/ParticleCollector.C:746:43: error: ‘const InternalField {aka const class Foam::Field<double>}’ has no member named ‘ref’
         scalar& PPC = summass.internalField().ref() [cellIp]; 
    
    1 条回复 最后回复
  • 李 离线
    李 离线
    李东岳 管理员
    写于2022年10月12日 07:31 最后由 编辑
    #22

    你不声明PPC,直接用summass呢?

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    C 1 条回复 最后回复 2022年10月13日 10:10
  • C 离线
    C 离线
    chengan.wang
    在 2022年10月13日 10:10 中回复了 李东岳 最后由 编辑
    #23

    @李东岳 李老师,还是不行

        const volScalarField& summass = p.mesh().objectRegistry::lookupObject<volScalarField>("summass");
        const label cellIp = p.cell();  
        summass.internalField() [cellIp] += p.nParticle()*p.mass();
    

    编译出错

    lnInclude/ParticleCollector.C:749:38: error: assignment of read-only location ‘(&(& summass)->Foam::GeometricField<Type, PatchField, GeoMesh>::internalField<double, Foam::fvPatchField, Foam::volMesh>())->Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[]<double>(((Foam::label)cellIp))’
         summass.internalField() [cellIp] += p.nParticle()*p.mass();
                                          ^
    lnInclude/ParticleCollector.C: In instantiation of ‘void Foam::ParticleCollector<CloudType>::postMove(Foam::ParticleCollector<CloudType>::parcelType&, Foam::label, Foam::scalar, const point&, bool&) [with CloudType = Foam::KinematicCloud<Foam::Cloud<Foam::CollidingParcel<Foam::KinematicParcel<Foam::particle> > > >; Foam::ParticleCollector<CloudType>::parcelType = Foam::CollidingParcel<Foam::KinematicParcel<Foam::particle> >; Foam::label = int; Foam::scalar = double; Foam::point = Foam::Vector<double>]’:
    parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C:53:1:   required from here
    lnInclude/ParticleCollector.C:749:38: error: assignment of read-only location ‘(&(& summass)->Foam::GeometricField<Type, PatchField, GeoMesh>::internalField<double, Foam::fvPatchField, Foam::volMesh>())->Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[]<double>(((Foam::label)cellIp))’
         summass.internalField() [cellIp] += p.nParticle()*p.mass();
    
    
    1 条回复 最后回复
  • 李 离线
    李 离线
    李东岳 管理员
    写于2022年10月13日 12:19 最后由 编辑
    #24

    volScalarField& summass = p.mesh().objectRegistry::lookupObjectRef<volScalarField>("summass");

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    C 1 条回复 最后回复 2022年10月17日 07:54
  • C 离线
    C 离线
    chengan.wang
    在 2022年10月17日 07:54 中回复了 李东岳 最后由 编辑
    #25

    @李东岳 李老师,这句命令

    volScalarField& summass = p.mesh().objectRegistry::lookupObjectRef<volScalarField>("summass");
    

    又报错了

    lnInclude/ParticleCollector.C:745:71: error: ‘class Foam::objectRegistry’ has no member named ‘lookupObjectRef’
         volScalarField& summass = p.mesh().objectRegistry::lookupObjectRef<volScalarField>("summass");
    
    
    1 条回复 最后回复
  • 李 离线
    李 离线
    李东岳 管理员
    写于2022年10月17日 11:50 最后由 编辑
    #26

    2.4版本太老了,你试下这个

    volScalarField& summass = const_cast<voScalarField&>(p.mesh().objectRegistry::lookupObject<volScalarField>("summass"));
    

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    C 1 条回复 最后回复 2022年10月20日 01:13
  • C 离线
    C 离线
    chengan.wang
    在 2022年10月20日 01:13 中回复了 李东岳 最后由 编辑
    #27

    @李东岳 非常感谢李老师,终于搞定,能输出数据了,但还需要进一步验证是否正确。差点放弃想升级新版本of。

        volScalarField& summass = const_cast<volScalarField&>(p.mesh().objectRegistry::lookupObject<volScalarField>("summass")); 
        const label cellIp = p.cell();  
        scalar& PPC = summass.internalField() [cellIp]; 
        PPC += p.nParticle()*p.mass();
    

    希望对以后需要的朋友有点借鉴作用。特别感谢 @星星星星晴 不厌其烦的解答:146:

    1 条回复 最后回复
2022年10月6日 08:51

25/27

2022年10月17日 07:54

2022年10月20日 01:13
  • 登录

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