如何在src文件中创建标量物理filed并且调用
- 
							
							
							
							
@chengan-wang 在 如何在src文件中创建标量物理filed并且调用 中说: volScalarField summass 
 (
 IOobject
 (
 "summass",
 runTime.timeName(),
 mesh,
 IOobject::NO_READ,
 IOobject::AUTO_WRITE
 ),
 mesh,
 dimensionedScalar ("zero", dimMass, 0.0)
 );把这个提前 
- 
							
							
							
							
@李东岳 李老师,按照下列代码 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; } }
- 
							
							
							
							
@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();希望对以后需要的朋友有点借鉴作用。特别感谢 @星星星星晴 不厌其烦的解答  
 
			

