CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Creating a new variable in a .C file? (http://www.cfd-online.com/Forums/openfoam-programming-development/87717-creating-new-variable-c-file.html)

Greg Givogue April 27, 2011 09:31

Creating a new variable in a .C file?
 
Hi Everyone,

I'm relatively new with OpenFOAM and C++ programming. I'd like to modify the Forces.C file to include the following calc;

vector CP = sum(Md^(vf+pf))/sum(vf+pf);

I believe I have to update the forces.H file as well to define CP... but I'm not sure how.

When I ran wmake in the forces folder I got:

forces/forces.C:469: warning: unused variable ‘CP’
make: *** [Make/linux64GccDPOpt/forces.o] Error 1

Thanks for the help!

Greg

akidess April 28, 2011 04:18

A "Warning" is not the same as an "Error". Ergo, you didn't include all messages from the compiler. Anyway, it's fine to define the variable in the .C file. I believe your problem is that "^" is not the operator you'd expect - use the Foam::pow() function instead.

Greg Givogue April 28, 2011 09:47

Thanks for the response. I tried a couple things and now I'm left with the following questions;

1) How do I declare CP within the scope of the write command at ln 374?
2) It doesn't seem to like my equation for CP at ln 467. I think it's the divide (/) that it doesn't like because I'm trying to divide 2 vector quantities. I think ^ is ok in this context. How would I use Foam::pow()?

Thanks so much for your help! Apologies for the simple questions but I'm just starting to learn C++.
Greg

Greg Givogue April 28, 2011 09:49

2 Attachment(s)
Here are the files...Attachment 7432

Attachment 7433

pablodecastillo April 28, 2011 17:10

you are declarating CP just in calcForcesMoment() function, if you want to use in other functions you need to declarate at the class (forces.h), or send like an argument


All times are GMT -4. The time now is 15:50.