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

Passing ScalarField from OpenFoam to Fortran

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   April 16, 2013, 05:12
Default Passing ScalarField from OpenFoam to Fortran
  #1
New Member
 
Ivana
Join Date: Feb 2012
Posts: 16
Rep Power: 5
IvanaS is on a distinguished road
Hello,

I want to couple Fortran code with OpenFoam.
From OpenFoam I want to send velocity field to the Fortran code.
I found that I can access the entire field using this scalarField u = U.component(0);.

But I don't know how to pass scalarFied or volScalarField from OF to Fortran.

Can someone please give me advice on this?

Thank you very much.

Regards,

I.
IvanaS is offline   Reply With Quote

Old   April 16, 2013, 05:52
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by IvanaS View Post
Hello,

I want to couple Fortran code with OpenFoam.
From OpenFoam I want to send velocity field to the Fortran code.
I found that I can access the entire field using this scalarField u = U.component(0);.

But I don't know how to pass scalarFied or volScalarField from OF to Fortran.
How? With caution

Quote:
Originally Posted by IvanaS View Post
Can someone please give me advice on this?
The method data() returns a raw C-pointer to the actual array with the items. Together with that and size() you've got enough information to google some recipe "calling Fortran-routines with C-arrays" or so. From then on you're on your own. You have my deepest sympathy for having to use Fortran
__________________
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   April 17, 2013, 15:38
Default
  #3
Senior Member
 
Paulo Vatavuk
Join Date: Mar 2009
Location: Campinas, Brasil
Posts: 106
Rep Power: 8
vatavuk is on a distinguished road
Hi Ivana,
A long time ago I did something like this, but not with OpenFOAM. I was able to transfer information between the programs by writing to and reading from a file. This is not a beautiful solution but it worked.
Best Regards,
Paulo
vatavuk is offline   Reply With Quote

Old   April 17, 2013, 17:48
Default
  #4
Senior Member
 
Join Date: Nov 2012
Posts: 168
Rep Power: 4
hz283 is on a distinguished road
Hello IvanaS,

When you send the velocity field to fortran code, will this "sending" action be performed by the root processor or all the processors if I want to consider the parallel computations? If yes I think we need to also pass the logical variable ROOT and the rank number to the fortran side. So how can we extract the information about the ROOT and the rank number from OF?

Thanks.

Quote:
Originally Posted by IvanaS View Post
Hello,

I want to couple Fortran code with OpenFoam.
From OpenFoam I want to send velocity field to the Fortran code.
I found that I can access the entire field using this scalarField u = U.component(0);.

But I don't know how to pass scalarFied or volScalarField from OF to Fortran.

Can someone please give me advice on this?

Thank you very much.

Regards,

I.
hz283 is offline   Reply With Quote

Old   April 17, 2013, 22:44
Default
  #5
New Member
 
Dan Kokron
Join Date: Dec 2012
Posts: 23
Rep Power: 4
dkokron is on a distinguished road
I haven't used the feature myself, but the newer fortran standards (either 2003 or 2008) include some fortran/C interoperability features that may help you.
dkokron is offline   Reply With Quote

Old   April 19, 2013, 09:32
Default
  #6
New Member
 
Ivana
Join Date: Feb 2012
Posts: 16
Rep Power: 5
IvanaS is on a distinguished road
Hi,

I think I found something, I am checking if it works but it looks promising. This helped: http://www.cfd-online.com/Forums/ope...-openfoam.html

I am not up to reading and writing from/to the file because I would need to do it every time step and it could be time consuming....

Regarding parallel computations, I am not there yet but indeed I will have to pass information about that as well. Maybe you should check this: UPstream::myProcNo() and UPstream::nProcs(). I don't know if it helps...

Thanks.

Ivana
IvanaS is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input data from Fortran into OpenFOAM rsanders20 OpenFOAM 4 June 12, 2012 17:36
Comparison between C/C++ and Fortran? rick Main CFD Forum 45 September 6, 2011 00:52
OpenFOAM 1.6.x, 1.7.0 and 1.7.x are not fully prepared to work with gcc-4.5.x wyldckat OpenFOAM Bugs 18 October 21, 2010 05:51
Cross-compiling OpenFOAM 1.6 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 7 January 19, 2010 16:39
Fortran 90 faster than C/C++ B. R. Guirguis Main CFD Forum 48 March 6, 2006 14:49


All times are GMT -4. The time now is 13:20.