CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Code compiling in OF240 but not in OF4X

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By Zeppo

Reply
 
LinkBack Thread Tools Display Modes
Old   March 20, 2017, 13:48
Default Code compiling in OF240 but not in OF4X
  #1
Member
 
Lisandro Maders
Join Date: Feb 2013
Posts: 75
Rep Power: 6
Lisandro Maders is on a distinguished road
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]);
    }

...
....
......
The error which is shown in the terminal is:
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
I thought that the
Code:
 tsource();
was returning a const reference and the
Code:
volVectorField& source
was not constant, but apparently it is not this.

Any one that have any idea I would appreciate this.
Lisandro Maders is offline   Reply With Quote

Old   March 20, 2017, 17:17
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 199
Rep Power: 13
Zeppo will become famous soon enough
Code:
volVectorField& source = tsource();
->
Code:
volVectorField& source = tsource.ref();
Tobi and Lisandro Maders like this.
Zeppo is offline   Reply With Quote

Old   March 21, 2017, 14:04
Default
  #3
Member
 
Lisandro Maders
Join Date: Feb 2013
Posts: 75
Rep Power: 6
Lisandro Maders is on a distinguished road
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!
Lisandro Maders is offline   Reply With Quote

Reply

Tags
blue-cfd, compilation error, of4x

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing OpenFOAM to another code: advice on dealing with meshes? SFr Open Source Meshers: Gmsh, Netgen, CGNS, ... 1 June 11, 2016 12:02
something wrong when compiling udf, however the code is correct when interpreting richard ben Fluent UDF and Scheme Programming 7 May 11, 2013 07:36
problem with compiling the source code michel1988 OpenFOAM Installation 1 April 17, 2013 17: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 10:11


All times are GMT -4. The time now is 16:23.