|
[Sponsors] |
How to interface a Fortran thermodynamic tool with OpenFOAM? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 29, 2010, 10:18 |
How to interface a Fortran thermodynamic tool with OpenFOAM?
|
#1 |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Hi everybody!
I am looking to interface a specific thermodynamic tool with OpenFOAM. This program is written in Fortran. From a Pressure, a temperature and a composition it can provide a density : rho=f(P,T,x) I wonder how to bound these different programs. I would like to keep the OpenFOAM structure and evaluate the density at each time step with a command as : thermo.rho(); Is anybody already performed such an interfacing ? Can you give some hints to start ? from which thermophysicalModels can I be inspired? Regards, Cyp |
|
November 1, 2010, 06:13 |
|
#2 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
Hi,
compile the fortran programm as a dynamic library. Then, use that library in OpenFoam. Is the programm you want the use in OpenFoam Refprop (NIST)? Regards, Christian |
|
November 1, 2010, 11:44 |
|
#3 |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Hi Chris!
Thank you for your answer!! Indeed it is exactly the NIST REFPROP I want to use with OpenFOAM! Did you already experienced to call REFPROP from OpenFOAM ? For the moment, I compiled the Fortran subroutine as a shared object (.so). How can I call it from OF ?? Best regards, Cyp |
|
November 1, 2010, 11:53 |
|
#4 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
Hi,
yes, I have implemented Refprop in OpenFoam. However, I noticed that Refprop is far too slow to be used in OpenFOAM. The simulation time will increase in order of many magnitudes. Regards, Christian |
|
November 1, 2010, 12:03 |
|
#5 |
Member
kshitij neroorkar
Join Date: Mar 2009
Location: Michigan, USA
Posts: 32
Rep Power: 17 |
Hi
another way to do this (we use this with REFPROP) is to create a lookup table using REFPROP with rho as a function of (P,T,x). Then write a class called, say, thermoprops. when you call thermo.rho(P,T,x) (where thermo is of type thermoprops) , it would interpolate in this table and return the required rho. Hope this helps Kshitij |
|
November 2, 2010, 05:18 |
|
#6 | ||
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Hi!
Quote:
Quote:
I think my main problem is either I chose a direct call of REFPROP or an interpolation from a table, is the creation of the thermoprops class... From which existed class can I start ?? Regards, Cyp |
|||
November 2, 2010, 09:47 |
|
#7 |
Member
kshitij neroorkar
Join Date: Mar 2009
Location: Michigan, USA
Posts: 32
Rep Power: 17 |
yes. so you would have something like
#P T x rho 1000 273 0.01 900 1200 273 0.01 890 ..... and you would interpolate to get rho=f(P,T,x). another idea you could try ( I dont know if this is feasible in your case), instead of using P, T and x, you could use P,H. This way the interpolation would be simplified. I dont know of any existing class that does this interpolation. We had to write our own. |
|
November 2, 2010, 10:37 |
|
#8 |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Thank you for your answers! For the moment, I would like to test to implement a direct call from REFPROP instead of a reading in a table.
As a first test, and to become familiar with the thermodynamic class programmation in OpenFOAM, I try to create my own class from basicRhoThermo : rho=f(T,P). However, when I read the .C and .H files, I can't where rho is calculated... Do you have any idea ? Regards, Cyp |
|
November 2, 2010, 11:38 |
|
#9 |
Member
kshitij neroorkar
Join Date: Mar 2009
Location: Michigan, USA
Posts: 32
Rep Power: 17 |
basicRhoThermo is a base class. since rho() is a virtual function, it would be calculated in some class that is derived from basicRhoThermo. If you look at some class that is derived from basicRhoThermo, you might get an idea.
I am still using 1.5-dev so I dont have basicRhoThermo. Sorry that I cant be of more help |
|
November 2, 2010, 16:55 |
|
#10 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
Hi,
might I ask, what exactly you want to simulated? Ok, here is what you have to do to implement refprop in OpenFoam. This is not the best way to do it, but it works. Start from the file hPsiThermo (or hRhoThermo). In this file, you have to call the Refprop functions. In the constuctor, you have to create the Refprop object. You also need a second "rho" field. This is needed because rho not directly connected to psi anymore (as it is for perfect gases). In this class, all the functions have to be changed so that the Refprop functions are called. Now comes the tricky part. Firstly, you have to change the enthalpy BC's. The "normal" BC are programmed for perfect gases, so we have h(T) instead of h(T,p). You also need to change the functions in basicThermo called by the enthalpy BC. As I said, Refprop is very slow and you have to solve the fundamental equations for each grid point (without changing refprop even more than once). About using tables, it is a possibility. But one problem is that you get an error and I don't mean the "normal" interpolation error. The problem is that thermo physical properties are connected to each other e.g. c_p=dh/dT. So, the interpolated value of c_p might not correspond correctly with you enthalpy. Regards, Christian Last edited by Chris Lucas; November 3, 2010 at 04:42. |
|
November 3, 2010, 06:12 |
|
#11 |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Hi Christian!
Thank you for your extended answer! In my investigation fields, the final step will be to simulate a two-phase multicomponent flow. I already have developed models for the mass fractions in each phase and I need to obtain the density of each phase from REFPROP. For each phase, density depends on Temperature, Pressure and Composition. It is my final objectives. I will consider a rough mesh. So I hope that the use of REFPROP will not have a consequent impact on my CPU time... For the moment, to become familiar with OpenFoam/REFPROP interfacing, I tried the implementation on a simpler model : just one phase is considered. There is no question of enthalpy, Cp and other thermodynamic properties. Just the density (I call the TPRHO() Refprop subroutine). As you advised me, I started from hPsiThermo. I saw enthalpy, Cp and Cv variables. Since I not consider such variables, I suppose I can rid of them ? And so I can rid of the part where I should change the enthalpy BC, can't I ? I am not sure to well understand the part with the second density. Do you mean I have to create a rho2 variable in hPsiThermo.H file ? Moreover, if I understand well, it is in the hPsiThermo.C file that I call the REFPROP function ? Thank you very much for your help. |
|
November 3, 2010, 06:48 |
|
#12 |
Senior Member
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18 |
Hi,
I'm also interested in multiphase flow. So you have phase change in your application? How did you get your pressure equation? But back to your question: "As you advised me, I started from hPsiThermo. I saw enthalpy, Cp and Cv variable. Since I not consider such variables, I suppose I can rid of them ?" For now, yes. But for a real compressible flow, no, you need this functions like "template<class MixtureType> Foam::tmp<Foam::scalarField> Foam::hPsiThermo<MixtureType>::Cp" even so the variables given to the function have to be changed. Within, this function, you must call the refprop routines. "I am not sure to well understand the part with the second density. Do you mean I have to create a rho2 variable in hPsiThermo.H file?" About the second density field. If you look at the rho function in basicPsiThermo.C ( virtual tmp<volScalarField> rho() const { return p_*psi(); }) You see that rho is connected to psi for perfect gases, so that no rho field has to be defined to save the results for rho. For real fluids, there is no relationship as the one above between rho and psi, so you have the save the results for rho separately. "And so I can rid of the part where I should change the enthalpy BC, can't I ?" If you don't have a energy equation, yes, you bypass the BC problem. However this is not correct for compressible flows This BC functions are in different classes (within a subsubfolder of the basic folder). This classes call functions in basicThermo, which are later overwriten by the functions in your new "hPsiThermo". "(I call the TPRHO() Refprop subroutine)". Unless you rewrite the energy equations (I would not use energy equations based on temperature for real fluids), you need a function like rho(p,h) and rho(p,T) (for BC's). "Moreover, if I understand well, it is in the hPsiThermo.C file that I call the REFPROP function?" Yes, you can. Regards, Christian |
|
November 3, 2010, 10:38 |
|
#13 | |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Yes I have phase change in my application. For the pressure equation, since I work in a porous medium, I developed an IMPES method (Implicit Pressure, Explicit Saturation). Pressures within each phase are related by a capillary pressure which depends on the saturation.
I was thinking about the creation of a second rho to rid of the perfect gas law. I tried to define a new base class which is a copy of basicPsiThermo (I called it testThermo1). In the equivalent of the makeBasicPsiThermo.H file, I could precised only two function : the Cthermo and the Mixture. So I could have only one rho variable. What do you think about that ? In a second step, I defined a new class deriving from the previous class and MixtureType. (exactly what have been done for the hPsiThermo class, I called it testThermo2). Then I modify the equivalent of the hPsiThermos.C file in order to define only Cthermo and pureMixture.... but it doesn't compile..... I get : Code:
cyp@cyp-laptop:~/OpenFOAM/cyp-1.7.1/applications/lib$ wmake libso Making dependency list for source file testThermo2/testThermos2.C SOURCE=testThermo2/testThermos2.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-40 -I/opt/openfoam171/src/finiteVolume/lnInclude -I/opt/openfoam171/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam171/src/thermophysicalModels/basic/lnInclude -IlnInclude -I. -I/opt/openfoam171/src/OpenFOAM/lnInclude -I/opt/openfoam171/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/testThermos2.o testThermo2/testThermos2.C:49: error: type/value mismatch at argument 1 in template parameter list for ‘template<class MixtureType> class Foam::testThermo2’ testThermo2/testThermos2.C:49: error: expected a type, got ‘pureMixture’ testThermo2/testThermos2.C:49: error: invalid type in declaration before ‘;’ token testThermo2/testThermos2.C:49: error: ‘testThermo2pureMixture’ is not a class or namespace testThermo2/testThermos2.C:49: error: ‘testThermo2pureMixture’ is not a class or namespace testThermo2/testThermos2.C:49: warning: unused variable ‘Foam::debug’ testThermo2/testThermos2.C: In constructor ‘Foam::testThermo1::addfvMeshConstructorToTable<testThermo1Type>::addfvMeshConstructorToTable(const Foam::word&) [with testThermo1Type = int]’: testThermo2/testThermos2.C:56: error: ‘typeName’ is not a member of ‘int’ In file included from lnInclude/makeTestThermo1.H:35, from testThermo2/testThermos2.C:28: lnInclude/testThermo1.H: In static member function ‘static Foam::autoPtr<Foam::testThermo1> Foam::testThermo1::addfvMeshConstructorToTable<testThermo1Type>::New(const Foam::fvMesh&) [with testThermo1Type = int]’: lnInclude/testThermo1.H:78: instantiated from ‘Foam::testThermo1::addfvMeshConstructorToTable<testThermo1Type>::addfvMeshConstructorToTable(const Foam::word&) [with testThermo1Type = int]’ testThermo2/testThermos2.C:56: instantiated from here lnInclude/testThermo1.H:71: error: cannot convert ‘const Foam::fvMesh’ to ‘int’ in initialization I think it should come from my makeTestThermo.H file : Quote:
Best Regards, Cyp Last edited by Cyp; November 3, 2010 at 11:36. |
||
January 20, 2011, 04:49 |
Basicthermo.H
|
#15 |
New Member
karthik
Join Date: Dec 2010
Location: munich
Posts: 16
Rep Power: 16 |
hello everyone,
I am new to the OpenFoam software. Can anyone tell me how I can make use of Basicthermo.H while using Interfoam as solver?? |
|
January 20, 2011, 05:23 |
|
#16 |
Senior Member
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25 |
may be its good to open new thread for ur issue, however you should look at user guide chapter 3 but a brief description can be like that:
in interfoam.C u should include ur new class: # include "Basicthermo.H" then in case directory use "wmake" to compile it. |
|
January 24, 2011, 09:43 |
|
#17 |
New Member
karthik
Join Date: Dec 2010
Location: munich
Posts: 16
Rep Power: 16 |
hey nimasam,
Thank you for your reply, i tried that. Any idea how to vary density with pressure change?? |
|
March 7, 2011, 15:15 |
|
#19 |
New Member
Evren
Join Date: Mar 2010
Posts: 20
Rep Power: 16 |
Hi,
I have couple of fortran.90 subroutines which I would like to call from OpenFOAM1.6. What I know direct call of fortran subroutine from c++ is not good. Thus, one has to have C interface to routines and some more technical difficulties as, fortran stores rowwise C stores columnwise Whatever, these are general problems of C++ and Fortran mixing. My questions are more OpenFOAM specific: 1) What should be the compiled fortran source codes, dynamic library, shared objects (.so), objects (.o) ... ? If more than one is good, which one performs better? 2) How should be this "executables" (compiled files) linked to OpenFOAM, let's say scalarFoam? How should the <file> and <options> in Make folder be modified? Please no suggestion like "why don't you rewrite your subroutines in C++" ;-) All the best, @ Cyp: You see, I am chasing you ;-) |
|
March 9, 2011, 06:15 |
|
#20 |
Senior Member
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18 |
Hi!
To link a library with OpenFOAM you can follow this 2 steps : - First ,you create a *.so file using "wmake libso" - Then you link this *.so file to OpenFOAM by including the following command in your controlDict file : Code:
libs ( "*.so " ); Cyp |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Call Fortran program from OpenFoam | tsjb00 | OpenFOAM Running, Solving & CFD | 6 | April 22, 2013 16:26 |
[Gmsh] 2D Mesh Generation Tutorial for GMSH | aeroslacker | OpenFOAM Meshing & Mesh Conversion | 12 | January 19, 2012 04:52 |
Native OpenFOAM interface in Pointwise | Chris Sideroff | Main CFD Forum | 0 | January 16, 2009 13:37 |
Convective Heat Transfer - Heat Exchanger | Mark | CFX | 6 | November 15, 2004 16:55 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 21:09 |