CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Passing ScalarField from OpenFoam to Fortran (https://www.cfd-online.com/Forums/openfoam/116257-passing-scalarfield-openfoam-fortran.html)

IvanaS April 16, 2013 05:12

Passing ScalarField from OpenFoam to Fortran
 
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.

gschaider April 16, 2013 05:52

Quote:

Originally Posted by IvanaS (Post 420853)
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 (Post 420853)
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

vatavuk April 17, 2013 15:38

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

hz283 April 17, 2013 17:48

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 (Post 420853)
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.


dkokron April 17, 2013 22:44

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.

IvanaS April 19, 2013 09:32

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


All times are GMT -4. The time now is 14:26.