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

Error passing <variable> as 'this' argument discards qualifiers [-fpermissive]

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Swirl

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 2, 2020, 09:09
Default Error passing <variable> as 'this' argument discards qualifiers [-fpermissive]
  #1
Member
 
Join Date: Jun 2020
Posts: 49
Rep Power: 5
Swirl is on a distinguished road
Hi everyone,

I am currently developing a custom boundary condition based on swirlFlowRateInletVelocity, which extends it to a Rankine-Vortex type. Therefore I Need to assign values based on a solidbody Vortex for certain regions of the inlet patch, and a potential Vortex for areas with larger distance from the center. For this I have two separate Vector Fields, which contain the Velocity data for each type of Vortex respectively. In the final step, using the ForAll-Command, I want to pass the values from the tangentialVelocity_pos() field to tangentialVelocity(), for those faces that contain the solid body Vortex.

the Code Looks loke this:

Code:
tmp<vectorField> tangentialVelocity( <Code describing a potential Vortex>);

tmp<vectorField> tangentialVelocity_pos( <Code describing a solid body Vortex>);

forAll(tangentialVelocity(), i)
{
if radius(current face <= critical radius)
{
tangentialVelocity()[i] = tangentialVelocity_pos()[i];
}
}
this gives me the error message:

error: passing 'const Foam::Vector<double>' as 'this' Argument discards qualifiers [-fpermissive]
tangentialVelocity()[i] = tangentialVelocity_pos()[i];

As far as my search has brought me, it has something to do with the Vector fields being defined as constants, but I dont know how to get around it. An attempt to use a conditional Operator within the tangentialVelocity() did not wirk, as the Operator was not known.

Does anyone have an idea how to fix this? Thank you very much in advance!

Last edited by Swirl; June 2, 2020 at 09:26. Reason: Corrected vector field names
Swirl is offline   Reply With Quote

Old   June 2, 2020, 10:05
Default
  #2
Member
 
Hasan Celik
Join Date: Sep 2016
Posts: 64
Rep Power: 9
PositronCascade is on a distinguished road
This kind of problem is mostly related to
Code:
const
. Somewhere in your definition, you miss it.

I suggest you refer to this post .
PositronCascade is offline   Reply With Quote

Old   June 2, 2020, 10:23
Default tmp files are not for direct manipulation
  #3
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
Hi Swirl,

I think that the instantiation of tangengialVelocity_pos as a temporal field is associated with the problem. Right now it is treating it as a temporal field, and therefore the assignament operation (operator=) is not calling what you're expecting.
You have to tell OF to treat this object as a vectorField. f.e:
Code:
tmp<vectorField> tmp_tangentialVelocity( ... );
tmp<vectorField> tmp_tangentialVelocity_pos( ... );


vectorField& tangentialVelocity = tmp_tangentialVelocity();
vectorField& tangentialVelocity_pos  = tmp_tangentialVelocity_pos();


forAll(tangentialVelocity, i) {
     tangentialVelocity[i] = tangentialVelocity_pos[i];

}
When you call the operator() of a temporal field it returns the pointer to the real data. Assign that pointer to a reference object and you shall be good to go.


I hope that helps you!
crubio.abujas is offline   Reply With Quote

Old   June 2, 2020, 11:18
Default
  #4
Member
 
Join Date: Jun 2020
Posts: 49
Rep Power: 5
Swirl is on a distinguished road
Quote:
Code:
vectorField& tangentialVelocity = tmp_tangentialVelocity();
vectorField& tangentialVelocity_pos  = tmp_tangentialVelocity_pos();
First of all, thank your for your reply! when applying your changes, I get a similar error for the Code lines quoted above.
It says:

error: binding reference of type 'Foam::vectorField& … ' to 'const Foam::Field<Foam::Vector<double> >' discards qualifiers

and same error for the second line.
Swirl is offline   Reply With Quote

Old   June 2, 2020, 12:39
Default Alternative method
  #5
Member
 
Join Date: Jun 2020
Posts: 49
Rep Power: 5
Swirl is on a distinguished road
It appears to me, that the data inside the vectorField cannot be changed at all, once it has been set. Another way to implement the Rankine Vortex would be, to use a piecewise Definition inside the
Code:
tmp<vectorField>tangentialVelocity
(
Piecewise definition here
)
However, neither an if-else Statement nor the xxx ? yyy : zzz Option worked so far. Does anyone know, if this is possible at all?
Swirl is offline   Reply With Quote

Old   June 2, 2020, 13:07
Default Try ref instead of ()
  #6
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
Quote:
Originally Posted by Swirl View Post
First of all, thank your for your reply! when applying your changes, I get a similar error for the Code lines quoted above.
It says:

error: binding reference of type 'Foam::vectorField& … ' to 'const Foam::Field<Foam::Vector<double> >' discards qualifiers

and same error for the second line.
Ok, ok. I still think is related with the temporal field reference. I've seen the way of refering a field from previous versions of OF, but checking the new ones it seems that it have changed to "tmpObject.ref()" instead of "tmpObject()". Although the last one still exists it will not return the object I was expecting.

Code:
tmp<vectorField> tmp_tangentialVelocity( ... );
tmp<vectorField> tmp_tangentialVelocity_pos( ... );


vectorField& tangentialVelocity = tmp_tangentialVelocity.ref();
vectorField& tangentialVelocity_pos  = tmp_tangentialVelocity_pos.ref();

forAll(tangentialVelocity, i) {
     tangentialVelocity[i] = tangentialVelocity_pos[i];
  }
I've tried this code in OF7 and it compiled, so that is some advances. Try it and lets hope that now you can get rid of this problem. Let me know if that worked!


EDIT: Just while writing this reply I thought about another way to access. The operator () is returning a pointer, not a reference. That why its not working properly, but you can use instead the following code and should work as welll.


Code:
tmp<vectorField> tmp_tangentialVelocity( ... );
tmp<vectorField> tmp_tangentialVelocity_pos( ... );


// without the & sign!
vectorField tangentialVelocity = tmp_tangentialVelocity();
 vectorField tangentialVelocity_pos  = tmp_tangentialVelocity_pos();

forAll(tangentialVelocity, i) {
     tangentialVelocity[i] = tangentialVelocity_pos[i];
 }

Last edited by crubio.abujas; June 2, 2020 at 13:12. Reason: Other way to work around
crubio.abujas is offline   Reply With Quote

Old   June 2, 2020, 13:29
Lightbulb Thank you!!!
  #7
Member
 
Join Date: Jun 2020
Posts: 49
Rep Power: 5
Swirl is on a distinguished road
Thank you so much! it worked and now I get a perfect Rankine-Vortex.
crubio.abujas likes this.

Last edited by Swirl; June 4, 2020 at 15:22.
Swirl is offline   Reply With Quote

Old   June 2, 2020, 13:59
Default
  #8
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
Quote:
Originally Posted by Swirl View Post
Thank you so much! it worked and now I get a perfect Rankine-Vortex. I really canīt describe how much I thank you! This issue cost me some sleep.
Glad to know it worked!


You will sleep better tonight
crubio.abujas is offline   Reply With Quote

Reply


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
CFD by anderson, chp 10.... supersonic flow over flat plate varunjain89 Main CFD Forum 18 May 11, 2018 07:31
[Commercial meshers] star-ccm mesh to O\/F DLC OpenFOAM Meshing & Mesh Conversion 77 September 19, 2016 09:25
meshing of a compound volume in GMSH shawn3531 OpenFOAM 4 March 12, 2015 10:45


All times are GMT -4. The time now is 01:51.