|
[Sponsors] |
March 20, 2017, 13:48 |
Code compiling in OF240 but not in OF4X
|
#1 |
Member
Lisandro Maders
Join Date: Feb 2013
Posts: 98
Rep Power: 13 |
Hello,
I programmed a code that is compiling fine in OpenFOAM 2.4.0. However, I tried to compile it in blue-cfd , which is based on OpenFOAM 4.x and I got an error, which is described as follows. I compiled the native OpenFOAM 4.x in my Ubuntu in order to test and I got the same error, so the error is not related to blue-cfd or Windows. The line which the error occurs is in bold red. Here is only a piece of the code: Code:
Foam::tmp<Foam::volVectorField> Foam::readSourceData::assignSourceValues ( const fvMesh& mesh ) { tmp<volVectorField> tsource ( new volVectorField ( IOobject ( "source", mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedVector("zero", dimensionSet(1,-2,-2,0,0,0,0),Foam::vector(0,0,0)) ) ); volVectorField& source = tsource(); forAll(source,celli) { .... .... Lot of stuff ..... .... source[celli] = Foam::vector(sourceData_[a][4],sourceData_[a][5],sourceData_[a][6]); } ... .... ...... Code:
readSourceData/readSourceData.C: In member function ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> > Foam::readSourceData::assignSourceValues(const Foam::fvMesh&)’: readSourceData/readSourceData.C:180:38: error: invalid initialization of reference of type ‘Foam::volVectorField& {aka Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>&}’ from expression of type ‘const Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>’ volVectorField& source = tsource(); ^ make: *** [Make/linux64GccDPInt64Opt/./readSourceData/readSourceData.o] Error 1 Code:
tsource(); Code:
volVectorField& source Any one that have any idea I would appreciate this. |
|
March 20, 2017, 17:17 |
|
#2 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Code:
volVectorField& source = tsource(); Code:
volVectorField& source = tsource.ref(); |
|
March 21, 2017, 14:04 |
|
#3 |
Member
Lisandro Maders
Join Date: Feb 2013
Posts: 98
Rep Power: 13 |
I am struggling to download OF4.x in another machine.. As soon as I do this I will check your suggestion and see if it works.
But anyway, my C++ is not the best in the world, but as far as I have read, and I quote now, "for tmp objects, non-const access uses a ref() function rather than the () dereferencing operator.". This was changed from OpenFOAM 4.0 version on, that's why it was compiling fine in OpenFOAM 2.4 version and not in OF4.X versions.. It will probably work now.. I let you know as soon as I verify it. Edit: Yes, it worked!! Thanks a lot! Lisandro Maders Last edited by Lisandro Maders; March 21, 2017 at 16:41. Reason: Tried the suggestion and it worked! |
|
Tags |
blue-cfd, compilation error, of4x |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] Comparing OpenFOAM to another code: advice on dealing with meshes? | SFr | OpenFOAM Meshing & Mesh Conversion | 1 | June 11, 2016 13:02 |
something wrong when compiling udf, however the code is correct when interpreting | richard ben | Fluent UDF and Scheme Programming | 7 | May 11, 2013 08:36 |
problem with compiling the source code | michel1988 | OpenFOAM Installation | 1 | April 17, 2013 18:19 |
The FOAM Documentation Project - SHUT-DOWN | holger_marschall | OpenFOAM | 242 | March 7, 2013 13:30 |
Small 3-D code | Zdravko Stojanovic | Main CFD Forum | 2 | July 19, 2010 11:11 |