Using the JHU Turbulence Database with C & Fortran

Downloads

C and Fortran Code
turblib-20090809.tar.gz
This downloads a directory with a sample Fortran (turbf.f90) and a sample C (turbc.c) code. These can be adapted to user needs.
        The directory also includes several gSOAP wrapper functions that need not be modified.   
        'make' will build both the Fortran and C sample code.
The README file contains more information if needed.

Overview

We have written several routines which use the gSOAP library to call the JHU Turbulence Database.

Limitations

Fortran Specific Notes

Character arrays (such as authkey and dataset) need to be passed as C-style strings. This requires the addition of a NULL character at the end of the string, for example:

character*100 :: dataset = 'isotropic1024fine' // CHAR(0)

Interpolation Flags

Note: Detailed descriptions of the underlying functions can be found in the analysis tools documentation.

Fortran
! ---- Temporal Interpolation Options ----
integer, parameter :: NoTInt = 0 ! No temporal interpolation
integer, parameter :: PCHIPInt = 1 ! Piecewise cubic Hermit interpolation in time

! ---- Spatial Interpolation Flags for GetVelocity & GetVelocityAndPressure ----
integer, parameter :: NoSInt = 0 ! No spatial interpolation
integer, parameter :: Lag4 = 4 ! 4th order Lagrangian interpolation in space
integer, parameter :: Lag6 = 6 ! 6th order Lagrangian interpolation in space
integer, parameter :: Lag8 = 8 ! 8th order Lagrangian interpolation in space

! ---- Spatial Differentiation & Interpolation Flags for GetVelocityGradient & GetPressureGradient ----
integer, parameter :: FD4NoInt = 40 ! 4th order finite differential scheme for grid values, no spatial interpolation
integer, parameter :: FD6NoInt = 60 ! 6th order finite differential scheme for grid values, no spatial interpolation
integer, parameter :: FD8NoInt = 80 ! 8th order finite differential scheme for grid values, no spatial interpolation
integer, parameter :: FD4Lag4 = 44 ! 4th order finite differential scheme for grid values, 4th order Lagrangian interpolation in space


Interpolation flags from Fortran are passed in as integer values, but we include these parameters at the top of turbf.f90 for reference.

C
enum SpatialInterpolation {
  /* Spatial Interpolation Flags for GetVelocity & GetVelocityAndPressure */
  NoSInt = 0, /* No spatial interpolatio */
  Lag4 = 4, /* 4th order Lagrangian interpolation in space */
  Lag6 = 6, /* 4th order Lagrangian interpolation in space */
  Lag8 = 8, /* 4th order Lagrangian interpolation in space */

  /* Spatial Differentiation & Interpolation Flags for GetVelocityGradient & GetPressureGradient */
  FD4NoInt = 40, /* 4th order finite differential scheme for grid values, no spatial interpolation */
  FD6NoInt = 60, /* 6th order finite differential scheme for grid values, no spatial interpolation */
  FD8NoInt = 80, /* 8th order finite differential scheme for grid values, no spatial interpolation */
  FD4Lag4 = 44, /* 4th order finite differential scheme for grid values, 4th order Lagrangian interpolation in space */
};

enum TemporalInterpolation {
  NoTInt = 0, /* No temporal interpolation */
  PCHIPInt = 1, /* Piecewise cubic Hermit interpolation in time *
};

Function Descriptions

soapinit & soapdestroy

Fortran
CALL soapinit()
...
CALL soapdestroy()

C
void soapinit()
...
void soapdestroy()

soapinit() must be called before any WebService call can be run. soapdestroy() may be called at the end to release these resources.

GetVelocity

Fortran
CALL getvelocity(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(3,count) output)

Input
do i = 1, count, 1
  input(1, i) = 0.1*i ! x
  input(2, i) = 0.3*i ! y
  input(3, i) = 0.2*i ! z
end do
Output
do i = 1, count, 1
  WRITE (*,*) output(1, i) ! Vx
  WRITE (*,*) output(2, i) ! Vy
  WRITE (*,*) output(3, i) ! Vz
end do

C
int getVelocity (char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][3])

Input
for (int i = 0, i < count; i++) {
  input[i][0] = 0.1*i ! x
  input[i][1] = 0.3*i ! y
  input[i][2] = 0.2*i ! z
}

Output
for (int i = 0, i < count; i++)
  printf("Vx=%f Vy=%f Vz=%f\n", output[i][0], output[i][1], output[i][2]);

GetForce

Fortran
CALL getforce(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(3,count) output)

Input
do i = 1, count, 1
  input(1, i) = 0.1*i ! x
  input(2, i) = 0.3*i ! y
  input(3, i) = 0.2*i ! z
end do
Output
do i = 1, count, 1
  WRITE (*,*) output(1, i) ! fx
  WRITE (*,*) output(2, i) ! fy
  WRITE (*,*) output(3, i) ! fz
end do

C
int getForce (char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][3])

Input
for (int i = 0, i < count; i++) {
  input[i][0] = 0.1*i ! x
  input[i][1] = 0.3*i ! y
  input[i][2] = 0.2*i ! z
}

Output
for (int i = 0, i < count; i++)
  printf("fx=%f fy=%f fz=%f\n", output[i][0], output[i][1], output[i][2]);

GetVelocityAndPressure

Fortran
CALL getvelocityandpressure(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(4,count) output)

Example
do i = 1, count, 1
  WRITE (*,*) output(1, i) ! Vx
  WRITE (*,*) output(2, i) ! Vy
  WRITE (*,*) output(3, i) ! Vz
  WRITE (*,*) output(4, i) ! Pressure
end do

C
int getVelocityAndPressure (char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][4])

Example
for (int i = 0, i < count; i++)
  printf("Vx=%f Vy=%f Vz=%f P=%f\n", output[i][0], output[i][1], output[i][2], output[i][3]);

This function is the same as GetVelocity except for the extra return value for pressure.

GetVelocityGradient

Fortran
CALL getvelocityandpressure(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(9,count) output)

Example
write(*, *) 'Velocity gradient at 10 particle locations'
CALL getvelocitygradient(authkey, dataset, time, FD4Lag4, NoTInt, 10, points, dataout9)
do i = 1, 10, 1
  write(*,*) i, ': (duxdx=', dataout9(1,i), ', duxdy=', dataout9(2,i), &
    ', duxdz=', dataout9(3,i), ', duydx=', dataout9(4,i), &
    ', duydy=', dataout9(5,i), ', duydz=', dataout9(6,i), &
    ', duzdx=', dataout9(7,i), ', duzdy=', dataout9(8,i), &
    ', duzdz=', dataout9(9,i), ')'
end do

C
int getVelocityGradient (char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][9])

Example
getVelocityGradient (authtoken, dataset, time, FD4Lag4, temporalInterp, 10, points, result9);
for (p = 0; p < 10; p++) {
  printf("%d: duxdx=%f, duxdy=%f, duxdz=%f, duydx=%f, duydy=%f, duydz=%f, duzdx=%f, duzdy=%f, duzdz=%f\n", p, result9[p][0], result9[p][1], result9[p][2], result9[p][3], result9[p][4], result9[p][5], result9[p][6], result9[p][7], result9[p][8]);
}

GetVelocityHessian

Fortran
CALL getvelocityhessian(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(18,count) output)

Example
write(*, *) 'Velocity Hessian at 10 particle locations'
CALL getvelocityhessian(authkey, dataset, time, FD4Lag4, NoTInt, 10, points, dataout18)
do i = 1, 10, 1
  write(*,*) i, ': (d2uxdxdx=', dataout18(1,i), &
    ', d2uxdxdy=', dataout18(2,i), &
    ', d2uxdxdz=', dataout18(3,i), &
    ', d2uxdydy=', dataout18(4,i), &
    ', d2uxdydz=', dataout18(5,i), &
    ', d2uxdzdz=', dataout18(6,i), &
    ', d2uydxdx=', dataout18(7,i), &
    ', d2uydxdy=', dataout18(8,i), &
    ', d2uydxdz=', dataout18(9,i), &
    ', d2uydydy=', dataout18(10,i), &
    ', d2uydydz=', dataout18(11,i), &
    ', d2uydzdz=', dataout18(12,i), &
    ', d2uzdxdx=', dataout18(13,i), &
    ', d2uzdxdy=', dataout18(14,i), &
    ', d2uzdxdz=', dataout18(15,i), &
    ', d2uzdydy=', dataout18(16,i), &
    ', d2uzdydz=', dataout18(18,i), &
    ', d2uzdzdz=', dataout18(18,i), ')'
end do

C
int getVelocityHessian(char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][18])

Example
getVelocityHessian (authtoken, dataset, time, FD4Lag4, temporalInterp, 10, points, result18);
for (p = 0; p < 10; p++) {
  printf("%d: d2uxdxdx=%f, d2uxdxdy=%f, d2uxdxdz=%f, d2uxdydy=%f, d2uxdydz=%f, d2uxdzdz=%f, d2uydxdx=%f, d2uydxdy=%f, d2uydxdz=%f, d2uydydy=%f, d2uydydz=%f, d2uydzdz=%f, d2uzdxdx=%f, d2uzdxdy=%f, d2uzdxdz=%f, d2uzdydy=%f, d2uzdydz=%f, d2uzdzdz=%f\n", p, result18[p][0], result18[p][1], result18[p][2], result18[p][3], result18[p][4], result18[p][5], result18[p][6], result18[p][7], result18[p][8], result18[p][9], result18[p][10], result18[p][11], result18[p][12], result18[p][13], result18[p][14], result18[p][15], result18[p][16], result18[p][17]);
}

GetVelocityLaplacian

Fortran
CALL getvelocitylaplacian(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(3,count) output)

Example
write(*, *) 'Velocity Laplacian at 10 particle locations'
CALL getvelocitylaplacian(authkey, dataset, time, FD4Lag4, NoTInt, 10, points, dataout3)
do i = 1, 10, 1
  write(*,*) i, ': (grad2ux=', dataout3(1,i), ', grad2uy=', dataout3(2,i), ', grad2uz=', dataout3(3,i), ')'
end do
C
int getVelocityHessian(char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][18])

Example
getVelocityLaplacian (authtoken, dataset, time, FD4Lag4, temporalInterp, 10, points, result3); for (p = 0; p < 10; p++) {
  printf("%d: grad2ux=%f, grad2uy=%f, grad2uz=%f\n", p, result3[p][0], result3[p][1], result3[p][2]);
}

GetPressureGradient

Fortran
CALL getpressuregradient(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(3,count) output)

Example
write(*, *) 'Pressure gradient at 10 particle locations'
CALL getpressuregradient(authkey, dataset, time, FD4Lag4, NoTInt, 10, points, dataout3)
do i = 1, 10, 1
  write(*,*) i, ': (dpdx=', dataout3(1,i), ', dpdy=', dataout3(2,i), ', dpdz=', dataout3(3,i), ')'
end do

C
int getPressureGradient(char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][3])

Example
getPressureGradient (authtoken, dataset, time, FD4Lag4, temporalInterp, 10, points, result3);
for (p = 0; p < 10; p++) {
  printf("%d: dpdx=%f,dpdy=%f,dpdz=%f\n", p, result3[p][0], result3[p][1], result3[p][2]);
}

GetPressureHessian

Fortran
CALL getpressurehessian(character*N authkey, character*N dataset, real time, spatial interpolation option, temporal interpolation option, integer count, real(3,count) input, real(6,count) output)

Example
write(*, *) 'Velocity hessian at 10 particle locations'
CALL getpressurehessian(authkey, dataset, time, FD4Lag4, NoTInt, 10, points, dataout6)
do i = 1, 10, 1
  write(*,*) i, ': (d2pdxdx=', dataout6(1,i), ', d2pdxdy=', dataout6(2,i), &
    ', d2pdxdz=', dataout6(3,i), ', d2pdydy=', dataout6(4,i), &
    ', d2pdydz=', dataout6(5,i), ', d2pdzdz', dataout6(6,i), ')'
end do

C
int getPressureHessian(char *authkey, char *dataset, float time, enum SpatialInterpolation spatial, enum TemporalInterpolation temporal, int count, float input[count][3], float output[count][6])

Example
getPressureHessian(authtoken, dataset, time, FD4Lag4, temporalInterp, 10, points, result6);
for (p = 0; p < 10; p++) {   printf("%d: d2pdxdx=%f,d2pdxdy=%f,d2pdxdz=%f, d2pdydy=%f, d2pdydz=%f, d2pdzdz=%f\n", p, result6[p][0], result6[p][1], result6[p][2], result6[p][3], result6[p][4], result6[p][5]);
}