如何在src文件中创建标量物理filed并且调用
-
@chengan-wang 在 如何在src文件中创建标量物理filed并且调用 中说:
const label cellIp = p.cell(); scalar PPC = summass.internalField() [cellIp]; PPC += p.nParticle()*p.mass();
这样只有PPC这个量在变,summass不跟着变。
我感觉如果是在src库中进行调用和操作,还是应该在库中创建这个量 -
@李东岳 还是不行
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];
-
@李东岳 李老师,还是不行
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();
-
@李东岳 李老师,这句命令
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");
-
@李东岳 非常感谢李老师,终于搞定,能输出数据了,但还需要进一步验证是否正确。差点放弃想升级新版本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();
希望对以后需要的朋友有点借鉴作用。特别感谢 @星星星星晴 不厌其烦的解答