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

Creating a new variable in a .C file?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 27, 2011, 09:31
Default Creating a new variable in a .C file?
  #1
Member
 
Greg Givogue
Join Date: Aug 2010
Location: Ottawa Canada
Posts: 57
Rep Power: 15
Greg Givogue is on a distinguished road
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
Greg Givogue is offline   Reply With Quote

Old   April 28, 2011, 04:18
Default
  #2
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
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.
akidess is offline   Reply With Quote

Old   April 28, 2011, 09:47
Default
  #3
Member
 
Greg Givogue
Join Date: Aug 2010
Location: Ottawa Canada
Posts: 57
Rep Power: 15
Greg Givogue is on a distinguished road
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:ow()?

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

Last edited by Greg Givogue; April 28, 2011 at 10:13.
Greg Givogue is offline   Reply With Quote

Old   April 28, 2011, 09:49
Default
  #4
Member
 
Greg Givogue
Join Date: Aug 2010
Location: Ottawa Canada
Posts: 57
Rep Power: 15
Greg Givogue is on a distinguished road
Here are the files...forces.C

wmake error message.gz
Greg Givogue is offline   Reply With Quote

Old   April 28, 2011, 17:10
Default
  #5
Senior Member
 
Pablo
Join Date: Mar 2009
Posts: 102
Rep Power: 17
pablodecastillo is on a distinguished road
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
pablodecastillo 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
emag beta feature: charge density charlotte CFX 4 March 22, 2011 09:14
Working directory via command line Luiz CFX 4 March 6, 2011 20:02
OpenFOAM Install Script ljsh OpenFOAM Installation 82 October 12, 2009 11:47
[OpenFOAM] ParaView 33 canbt open OpenFoam file hariya03 ParaView 7 September 25, 2008 17:33
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51


All times are GMT -4. The time now is 08:28.