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/)
-   -   use ‘-fpermissive’. How to do it (https://www.cfd-online.com/Forums/openfoam-programming-development/150274-use-fpermissive-how-do.html)

13msmemusman March 18, 2015 23:26

use ‘-fpermissive’. How to do it
 
I have a scalar CoMx which is value of x component of center of mass. i wanted to find its acceleration. For this purpose i wrote following code
scalar Ax = (CoMx(i)-2*CoMx(i-1)+CoMx(i-2))/(dt^2);
Info << "Accelleration in x direction = " << Ax << nl << endl;


But i got following error

myInterFoamDDTNumerical.C:123:19: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
scalar Ax = (CoMx(i)-2*CoMx(i-1)+CoMx(i-2))/(dt^2);
^
myInterFoamDDTNumerical.C:123:19: note: (if you use ‘-fpermissive’ G++ will accept your code)
myInterFoamDDTNumerical.C:123:20: error: ‘CoMx’ cannot be used as a function
scalar Ax = (CoMx(i)-2*CoMx(i-1)+CoMx(i-2))/(dt^2);
^
myInterFoamDDTNumerical.C:123:32: error: ‘CoMx’ cannot be used as a function
scalar Ax = (CoMx(i)-2*CoMx(i-1)+CoMx(i-2))/(dt^2);
^
myInterFoamDDTNumerical.C:123:42: error: ‘CoMx’ cannot be used as a function
scalar Ax = (CoMx(i)-2*CoMx(i-1)+CoMx(i-2))/(dt^2);
^
myInterFoamDDTNumerical.C:123:46: error: ‘dt’ was not declared in this scope
scalar Ax = (CoMx(i)-2*CoMx(i-1)+CoMx(i-2))/(dt^2);
^

Plz guide me how to use ‘-fpermissive’

kebsiali March 19, 2015 03:14

Hello again,

You are presuming that OpenFoam is saving your CoMx at each time step in an array, well, he does not.

you are also accessing your array with something called i, if you did some programing before you should understand that this variable should be declared and given a value.

and why do you pass from one post to another, if you keep your work in one post people will understand your problems better.

I advice you to either create an array to save your CoMx at each time step or save the three ones you need and replace them through each step.

13msmemusman March 19, 2015 08:49

Sir you are right i should not switch between posts. sir i am new in openfoam with no or little interaction with programming. Can you guide me how to write an array in openfoam????.

kebsiali March 19, 2015 09:14

if you send your case it would be better and easier

but in general you can declare 3 variables (double) called CoMx1, CoMx2, and CoMx3
and define an int i=0; before the time loop

and then inside the loop do the following

i++;
if (i==1){ CoMx1=CoMx}
else if (i==2){CoMx2=CoMx}
else
{
CoMx3=CoMx;
Ax=(CoMx3-2.0*CoMx2+CoMx1)/(well this is also a problem dt^2);
CoMx1=CoMx2;
CoMx2=CoMx3;
}

The problem above is that the program does not know your dt like this

13msmemusman March 19, 2015 10:52

:-) thank you so much sir for your precious time. At last now i am thinking about using Libre Office :-D

13msmemusman March 20, 2015 10:45

Sir kebsiali please give me your email id i want to send you my case

kebsiali March 20, 2015 10:48

HI Muhammad
stop saying sir sir, im just helping with what i can,
my email is kebsiali@gmail.com

13msmemusman March 20, 2015 10:53

Ok sorry bro i have sent you mail plz have a look on it

13msmemusman March 20, 2015 12:32

please watch your mail bro


All times are GMT -4. The time now is 06:53.