CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Error passing <variable> as 'this' argument discards qualifiers [-fpermissive] (https://www.cfd-online.com/Forums/openfoam-programming-development/227571-error-passing-variable-argument-discards-qualifiers-fpermissive.html)

Swirl June 2, 2020 09:09

Error passing <variable> as 'this' argument discards qualifiers [-fpermissive]
 
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!

PositronCascade June 2, 2020 10:05

This kind of problem is mostly related to
Code:

const
. Somewhere in your definition, you miss it.

I suggest you refer to this post .

crubio.abujas June 2, 2020 10:23

tmp files are not for direct manipulation
 
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!

Swirl June 2, 2020 11:18

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 June 2, 2020 12:39

Alternative method
 
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?

crubio.abujas June 2, 2020 13:07

Try ref instead of ()
 
Quote:

Originally Posted by Swirl (Post 773059)
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];
 }


Swirl June 2, 2020 13:29

Thank you!!!
 
Thank you so much! it worked and now I get a perfect Rankine-Vortex.

crubio.abujas June 2, 2020 13:59

Quote:

Originally Posted by Swirl (Post 773095)
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! :D:D


You will sleep better tonight ;)


All times are GMT -4. The time now is 19:41.