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

Code compiling in OF240 but not in OF4X

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

Like Tree3Likes
  • 1 Post By Lisandro Maders
  • 2 Post By Zeppo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 20, 2017, 12:48
Default Code compiling in OF240 but not in OF4X
  #1
Member
 
Lisandro Maders
Join Date: Feb 2013
Posts: 98
Rep Power: 13
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.
ykanani likes this.
Lisandro Maders is offline   Reply With Quote

Old   March 20, 2017, 16:17
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
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, 13:04
Default
  #3
Member
 
Lisandro Maders
Join Date: Feb 2013
Posts: 98
Rep Power: 13
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 15:41. Reason: Tried the suggestion and it worked!
Lisandro Maders is offline   Reply With Quote

Reply

Tags
blue-cfd, compilation error, of4x

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


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 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 12: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 23:10.