如何在src文件中创建标量物理filed并且调用
-
@李东岳 麻烦李老师了。
const volScalarField& summass = p.mesh().objectRegistry::lookupObject<volScalarField>("summass"); const label cellIp = p.cell(); scalar& PPC = summass.internalField()[cellIp]; PPC += p.nParticle()*p.mass();
还是有错误如下
lnInclude/ParticleCollector.C:750:53: error: binding ‘const double’ to reference of type ‘Foam::scalar& {aka double&}’ discards qualifiers scalar& PPC = summass.internalField()[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:750:31: error: ‘const volScalarField {aka const class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘internalFieldRef’ scalar& PPC = summass.internalFieldRef() [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:750:31: error: ‘const volScalarField {aka const class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘internalFieldRef’ scalar& PPC = summass.internalFieldRef() [cellIp];
我用grep查了一下,有些函数中用的是internalField()而查不到internalFieldRef(),但如果采用
scalar& PPC = summass.internalField() [cellIp]
错误如下
lnInclude/ParticleCollector.C:750:53: error: binding ‘const double’ to reference of type ‘Foam::scalar& {aka double&}’ discards qualifiers scalar& PPC = summass.internalField()[cellIp];
-
@李东岳 编译倒是能通过了,但是运行算例log文件显示错误
[12] [12] [12] --> FOAM FATAL ERROR: [12] request for volScalarField summass from objectRegistry region0 failed available objects of type volScalarField are 19 ( thermo:mu thermo:psi K h kappa air rho k Cp dpdt thermo:psi_0 alphat dQ p T mut H2O epsilon thermo:alpha ) [12] [12] [12] From function objectRegistry::lookupObject<Type>(const word&) const [12] in file /home/chengan/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 198. [12]
-
@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();
希望对以后需要的朋友有点借鉴作用。特别感谢 @星星星星晴 不厌其烦的解答