如何在src文件中创建标量物理filed并且调用
-
@李东岳 感谢李老师回复。
我先在求解器中的createFields.H建立过这个field:Euler-Lagrange的一些解析,sprayFoam之后在ParticleCollector.C文件添加了
cellI = p.cell(); scalar& PPC = summass_->primitiveFieldRef() [cellI]; PPC += p.nParticle()*p.mass();
但我编译时候出现错误,找不到summass
所以我猜应该是把这个field建立到ParticleCollector.H,ParticleCollector.C等文件中吧?!瞎猜的。
李老师能指点一下吗?
-
@chengan-wang 你在库文件里面要使用求解器层面的volScalarField是调用不起来的。你可以试一下用这个:
const volScalarField& summass = p.mesh().lookupObject<volScalarField>("summass"); scalar& PPC = summass.primitiveFieldRef() [cellI];
-
@李东岳 谢谢李老师帮忙!
我我的是2.4.0版本,这样写的:const volScalarField& summass = p.mesh().lookupObject<volScalarField>("summass"); const label cellIp = p.cell(); scalar& PPC = summass.primitiveFieldRef() [cellIp]; PPC += p.nParticle()*p.mass();
运行出现如下错误
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:748:77: error: expected primary-expression before ‘>’ token const volScalarField& summass = p.mesh().lookupObject<volScalarField>("summass"); ^ lnInclude/ParticleCollector.C:750:31: error: ‘const volScalarField {aka const class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘primitiveFieldRef’ scalar& PPC = summass.primitiveFieldRef() [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:748:77: error: expected primary-expression before ‘>’ token const volScalarField& summass = p.mesh().lookupObject<volScalarField>("summass"); ^ lnInclude/ParticleCollector.C:750:31: error: ‘const volScalarField {aka const class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘primitiveFieldRef’ scalar& PPC = summass.primitiveFieldRef() [cellIp];
不知道从哪里入手,麻烦李老师了
-
@chengan-wang 在 如何在src文件中创建标量物理filed并且调用 中说:
mesh().lookupObject<volScalarField>
p.mesh().objectRegistry::lookupObject<volScalarField>("summass")
这个可以么 -
@李东岳 在 如何在src文件中创建标量物理filed并且调用 中说:
p.mesh().objectRegistry::lookupObject<volScalarField>("summass")
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 ‘primitiveFieldRef’ scalar& PPC = summass.primitiveFieldRef() [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 ‘primitiveFieldRef’ scalar& PPC = summass.primitiveFieldRef() [cellIp];
好像是没有 member named ‘primitiveFieldRef’,我用的是of2.4.0
-
@李东岳 麻烦李老师了。
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];