View Full Version : Including data from other programs

08-21-2007, 12:30 PM
I had a question regarding passing on array values from my CFD code to one of the PDEs solved by PDE2D. In my set of 6 simultaneous PDEs, for Equation F1, I need to pass on the temperature variable as a coefficient to one of the terms. The temperature variable is available as an array, temp(nx,ny,nz). How can I include it?

08-21-2007, 02:16 PM
You need to reference the temperature in F1 as "temper(x,y,z)" and then
write a Fortran function temper which interpolates your array to the point
(x,y,z). I have written a function which does tri-linear interpolation to
your array, which I assume can be passed through COMMON to this
function. If you want to read the array temp from a file, you can do this
also (but you don't want to read the file everytime temper is called, so
I usually have a variable "INIT" set to 0 in a data statement, then I check
to see if INIT=0, if so, I open the file and read in the array, and set INIT=1,
so next time the file reading will be skipped.)

I haven't tested this function, so it may have a bug or two in it, but should
be minor.

function temper(x,y,z)
implicit double precision (a-h,o-z)
parameters (nx=?,ny=?,nz=?)
c pass temperature array in through common
common /block1/ temp(nx,ny,nz)
data xa,xb,ya,yb,xa,xb/ ?? /
hx = (xb-xa)/(nx-1)
hy = (yb-ya)/(ny-1)
hz = (zb-za)/(nz-1)
c ix will be between 0 and nx-2, etc.
ix = (x-xa)/hx - 0.001
iy = (y-ya)/hy - 0.001
iz = (z-za)/hz - 0.001
rx = (x - (xa+ix*hx))/hx
ry = (y - (ya+iy*hy))/hy
rz = (z - (za+iz*hz))/hz
u000 = temp(nx+1,ny+1,nz+1)
u001 = temp(nx+1,ny+1,nz+2)
u010 = temp(nx+1,ny+2,nz+1)
u011 = temp(nx+1,ny+2,nz+2)
u100 = temp(nx+2,ny+1,nz+1)
u101 = temp(nx+2,ny+1,nz+2)
u110 = temp(nx+2,ny+2,nz+1)
u111 = temp(nx+2,ny+2,nz+2)
c do tri-linear interpolation for temp at (x,y,z)
ux00 = u000 + rx*(u100-u000)
ux10 = u010 + rx*(u110-u010)
uxy0 = ux00 + ry*(ux10-ux00)
ux01 = u001 + rx*(u101-u001)
ux11 = u011 + rx*(u111-u011)
uxy1 = ux01 + ry*(ux11-ux01)
uxyz = uxy0 + rz*(uxy1-uxy0)
temper = uxyz