CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[swak4Foam] Writing a class to use in a groovyBC expression?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 22, 2014, 08:53
Default Writing a class to use in a groovyBC expression?
  #1
Member
 
Olie
Join Date: Oct 2013
Posts: 51
Rep Power: 12
odellar is on a distinguished road
Hi,

I wish to write my own classwith functions that I can call from within an expression in a groovyBC boundary declaration in the 0/U file of a case.

Can I write this class, compile it, then put it in a particular directory where OpenFOAM can access it when called from the 0/U file? And if so, what is the correct location? If not, what is the correct way of adding my own class/functions?

Thanks,
Olie
odellar is offline   Reply With Quote

Old   July 22, 2014, 17:27
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by odellar View Post
Hi,

I wish to write my own classwith functions that I can call from within an expression in a groovyBC boundary declaration in the 0/U file of a case.

Can I write this class, compile it, then put it in a particular directory where OpenFOAM can access it when called from the 0/U file? And if so, what is the correct location? If not, what is the correct way of adding my own class/functions?

Thanks,
Olie
That is known as function-plugins (or plugin-functions I keep forgetting how I named it): adding your own functions to the swak-parsers. Have a look at http://openfoamwiki.net/index.php/Co...er_information (the presentation http://openfoamwiki.net/images/c/c0/...rogrammers.pdf starting at slide 102 - of course you'll need to write a PatchValuePluginFunction instead of the FieldValue in that example). Also have a look at the Libraries/functionPlugins in the swak-sources for examples
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   July 25, 2014, 10:02
Default
  #3
New Member
 
Join Date: Sep 2013
Location: Germany
Posts: 18
Rep Power: 12
MangoMango is on a distinguished road
Hi Bernhard,

great feature and a good presentation. I want to make use of this to call an external function from an older cpp file. How can I access the function? (to be correct it is a Fortran 77 based Database I managed it access it by a cpp wrapper. Now I want to implement it to a functionPlugin so that I m able to read out e.g.: Cv by giving the Temp .....I'm not really deep into c++ strukture classes. So it is quite difficult for me. Maybe some little advices would help me to find the right direction.

Best regards,

Alex

...I allready got your game of life sample through. And I try to understand the sample functions in the swak source..but still I don't know where to begin.
MangoMango is offline   Reply With Quote

Old   July 26, 2014, 10:14
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by MangoMango View Post
Hi Bernhard,

great feature and a good presentation. I want to make use of this to call an external function from an older cpp file. How can I access the function? (to be correct it is a Fortran 77 based Database I managed it access it by a cpp wrapper. Now I want to implement it to a functionPlugin so that I m able to read out e.g.: Cv by giving the Temp .....I'm not really deep into c++ strukture classes. So it is quite difficult for me. Maybe some little advices would help me to find the right direction.

Best regards,

Alex

...I allready got your game of life sample through. And I try to understand the sample functions in the swak source..but still I don't know where to begin.
I assume that you want to use your Cv(T) only for postprocessing. If you want to program a new set of thermodynamics to be used during the simulation: then swak doesn't help you.

Anyway: You say you've already got a C++ function that wraps the fortran stuff. So the hard part is already done and the rest can be tackled with a "Talent imitates, genius steals"-approach: Take the sources of the original "Game of life"-function and adapt them:

1. Rename the class to fit your application (also change the name of your function)
2. #Include the header to your wrapper
Code:
#include "myCV.h"
3. Assuming that your wrapper function has a signature similar to
Code:
double myCV(double CV,int modelParameter1,double modelParameter2);
rewrite in the doStep-method so that the actual action part (leave the administrative-stuff) is something like (I leave the variable names from the original):
Code:
forAll(field,cellI) {
    field[cellI]=myCV(old[cellI],42,666.6);
}
4. Throw out all stuff from the original that you don't understand/are obviously useless. Compile often to check that you don't go overboard. The undo of your text-editor is your friend
5. Change the Contributor/Copyright appropriately if you want to pass the result around
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   July 28, 2014, 04:45
Default
  #5
New Member
 
Join Date: Sep 2013
Location: Germany
Posts: 18
Rep Power: 12
MangoMango is on a distinguished road
Thank you very much !! . I will try to implement it and will keep you updated.

Kind regards
Alex
MangoMango is offline   Reply With Quote

Old   July 28, 2014, 05:15
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by MangoMango View Post
Thank you very much !! . I will try to implement it and will keep you updated.
Of course that is if you're interested in the field (it just occurred to me that the title of the thread has "groovyBC". In that case you'd have to write a Plugin for the Patch-Driver. Which is slightly different)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   July 30, 2014, 11:03
Default
  #7
New Member
 
Join Date: Sep 2013
Location: Germany
Posts: 18
Rep Power: 12
MangoMango is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Of course that is if you're interested in the field (it just occurred to me that the title of the thread has "groovyBC". In that case you'd have to write a Plugin for the Patch-Driver. Which is slightly different)
...just figured out that I need to modify the thermophysicalModels to implement a new library. So unfortunatly I can't use swak. Sorry that I bothered you with my request. But your advice is still usefull in my currrent issues. Thanks anyway
MangoMango is offline   Reply With Quote

Reply

Tags
class, compile


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
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 05:38
Problem About Running Fluent In Linux mitra FLUENT 18 June 20, 2019 02:11
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 18:44
CGNS lib and Fortran compiler manaliac Main CFD Forum 2 November 29, 2010 06:25
Writing an expression for fully developed flow! Usman CFX 12 December 20, 2007 11:26


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