|
[Sponsors] |
August 16, 2017, 17:59 |
erro: no match for operator[]
|
#1 | ||
Member
Vedamt Chittlangia
Join Date: Feb 2016
Posts: 64
Rep Power: 9 |
Hello,
I am modifying a turbulence model and for a part of the code I get an error: Quote:
Code:
tmp<volScalarField> myModel::rCm ( const volScalarField& tke ) { tmp<volScalarField> rC = tke/tke; tmp<volScalarField> FST = tke; const fvPatchScalarField* topTKE(tke.boundaryField()[2]); forAll(tke, cellI) { FST[cellI] = topTKE[3]; } return rC; } Quote:
Code:
forAll(FST,cellI) { FST[cellI] = topTKE[3]; } What should I change for FST such that I can access individual value of FST for each cell in the mesh and assign it some value? Thanks, |
|||
August 17, 2017, 12:42 |
|
#2 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Code:
FST()[cellI] = topTKE[3]; |
|
August 17, 2017, 13:49 |
|
#3 |
Member
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 10 |
Hi Vedamt,
As far as i know, the forAll(FST, cellI) means: for(int i=0; i< A; i++), with A is a integer which is the size of FST. However, you defined FST as a volScalarField which is a 2D or 3D matrix according to your mesh, and size of a matrix is mxn but not a scalar so you cannot use it for the "for" loop. The only solution I can come up with is using another scalarField: Code:
scalarField& FSTin_ = FST.internalField(); forAll(FSTin_, cellI) FSTin_[cellI] = topTKE[3]; Vu |
|
August 17, 2017, 16:13 |
|
#4 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Code:
scalarField& FSTin_ = FST.internalField(); Code:
scalarField& FSTin_ = FST().internalField(); |
|
August 25, 2017, 21:41 |
|
#5 |
Member
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14 |
Hi all,
I did a similar expression as below but got an error. error: Code:
error: invalid initialization of reference of type ‘Foam::scalarField& {aka Foam::Field<double>&}’ from expression of type ‘const Internal {aka const Foam::DimensionedField<double, Foam::volMesh>}’ scalarField& varNuIn_ = varNu_().internalField(); Code:
Foam::tmp<Foam::volScalarField> varNu_; scalarField& varNuIn_ = varNu_().internalField(); |
|
August 27, 2017, 12:23 |
|
#6 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
||
October 10, 2017, 12:57 |
|
#7 | ||
Member
sibo
Join Date: Oct 2016
Location: Chicago
Posts: 55
Rep Power: 10 |
Hi Sergel,
I have a similar error message when compiling a customized solver in OF_4.1. It is a dynamic solver and in order to assign my calculated displacement value "dispVals" to cellDisplacement boundary, I use this line: Quote:
Quote:
Do you know how to solve this problem? Any suggestion is welcome! Thanks a lot! |
|||
October 14, 2017, 07:58 |
|
#8 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Code:
PointDisplacement.boundaryField()[patchID] == dispVals; Code:
PointDisplacement.boundaryFieldRef()[patchID] == dispVals; |
|
October 14, 2017, 11:20 |
|
#9 |
Member
sibo
Join Date: Oct 2016
Location: Chicago
Posts: 55
Rep Power: 10 |
Thanks a lot! I solved this problem a few days ago, so I think in the new version they name the const and non-const function differently.
|
|
January 19, 2018, 08:00 |
|
#10 | ||
New Member
Nick
Join Date: Dec 2017
Location: UK
Posts: 7
Rep Power: 9 |
Hi guys I also have a similar problem... more specifically:
When I try to compile the following: Quote:
Quote:
I would really appreciate any help! Thanks! |
|||
January 19, 2018, 09:43 |
|
#11 | |
Member
sibo
Join Date: Oct 2016
Location: Chicago
Posts: 55
Rep Power: 10 |
HI Nick,
Try Quote:
|
||
January 19, 2018, 10:47 |
|
#12 |
New Member
Nick
Join Date: Dec 2017
Location: UK
Posts: 7
Rep Power: 9 |
Thanks Sibo,
I'll give it a try and see what comes out of it! |
|
February 6, 2018, 10:55 |
|
#13 |
New Member
Nick
Join Date: Dec 2017
Location: UK
Posts: 7
Rep Power: 9 |
Hi all,
I found this link which describes how to update older code versions to the newest... which also gives an answer to most of the questions posed in this thread. I hope you find it helpful! https://www.openfoam.com/documentati...rade-guide.php Regards, Nick |
|
April 25, 2018, 09:28 |
|
#14 | |
New Member
Join Date: Jul 2016
Posts: 1
Rep Power: 0 |
Hey everyone,
This thread already helped me a lot. Thanks for this guys! Now I would like to do something quite similar, just the other way round as the issue solved before here: Quote:
Code:
dispVals=PointDisplacement.boundaryFieldRef()[patchID]; Code:
error: no match for ‘operator=’ (operand types are ‘Foam::vectorField {aka Foam::Field<Foam::Vector<double> >}’ and ‘Foam::pointPatchField<Foam::Vector<double> >’) Thanks! |
||
March 30, 2020, 08:14 |
Problem in printing the values
|
#15 |
New Member
sujata
Join Date: Dec 2019
Posts: 10
Rep Power: 7 |
hello everyone.
I am using multiphaseEulerfoam solver. I am new to OpenFOAM and using version 4.1 . I am trying to print u velocity, Reynolds No in the phasepair.C file Foam::tmp<Foam::volScalarField> Foam:hasePair::magUr() const { return mag(phase1().U() - phase2().U()); Info<< "magUr =" <<magUr()[0] << endl; } Foam::tmp<Foam::volVectorField> Foam:hasePair::Ur() const { return dispersed().U() - continuous().U(); } Foam::tmp<Foam::volScalarField> Foam:hasePair::Re() const { return magUr()*dispersed().d()/continuous().nu(); Info<< "Re =" <<Re()[0] << endl; } The error I am getting is as follows phasePair/phasePair/phasePair.C(108): error: no operator "[]" matches these operands operand types are: Foam::tmp<Foam::GeometricField<Foam::scalar, Foam::fvPatchField, Foam::volMesh>> [ int ] Info<< "magUr =" <<magUr()[0] << endl; ^ phasePair/phasePair/phasePair.C(121): error: no operator "[]" matches these operands operand types are: Foam::tmp<Foam::GeometricField<Foam::scalar, Foam::fvPatchField, Foam::volMesh>> [ int ] Info<< "Re =" <<Re()[0] << endl; ^ I want to print it for 0th cell. Can anyone help me with this. |
|
March 30, 2020, 09:09 |
|
#16 |
Member
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 10 |
Hi Sujata,
the function mag() return a scalar, thus magUr() is a scalar and it doesn't have [] operator |
|
March 30, 2020, 10:19 |
|
#17 | |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Quote:
Code:
Foam::tmp<Foam::volScalarField> Foam:hasePair::magUr() const { tmp<volScalarField> ret = mag(phase1().U() - phase2().U()); Info<< "magUr =" << ret()[0] << endl; return ret; } |
||
March 30, 2020, 10:48 |
|
#18 | |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Quote:
Code:
dispVals=PointDisplacement.boundaryField()[patchID].primitiveField(); |
||
March 30, 2022, 08:21 |
|
#19 | |
New Member
Feng
Join Date: Apr 2017
Posts: 9
Rep Power: 9 |
Quote:
I also have this problem in OF5x, and I changed tsource().internalField() =... -> tsource().primitiveField() =... but it doesn't work, how to fix it? Thanks Feng |
||
March 30, 2022, 08:36 |
|
#20 | |
New Member
Feng
Join Date: Apr 2017
Posts: 9
Rep Power: 9 |
Quote:
|
||
Tags |
cell value, operator, size, tmp<volscalarfield> |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[ANSYS Meshing] Match Control, is this weird or am I stupid? | Moufle | ANSYS Meshing & Geometry | 2 | November 18, 2015 17:00 |
createPatch Segmentation Fault (CORE DUMPED) | sam.ho | OpenFOAM Pre-Processing | 2 | April 21, 2014 03:01 |
Match Control and Symmetry Boundary Condtions in a quasi 2D calculation | peterputer | ANSYS Meshing & Geometry | 0 | May 15, 2012 09:53 |
gmsh2ToFoam | sarajags_89 | OpenFOAM | 0 | November 24, 2009 23:50 |
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues | michele | OpenFOAM Meshing & Mesh Conversion | 2 | July 15, 2005 05:15 |