Johns Hopkins Turbulence Databases

Using JHTDB with C & Fortran

Download

C and Fortran Code: turblib-20150108 (Download tar.gz here) (Download zip here)

This downloads a directory with sample Fortran (turbf.f90, mhdf.f90, channelf.f90, mixingf.f90) and C (turbc.c, mhdc.c, channelc.c, mixingc.c) code, and has been tested under various versions of Mac OS X, Linux, FreeBSD and Windows (under Cygwin). The directory also includes several gSOAP wrapper functions that need not be modified. Executing 'make' will build both the Fortran and C sample code.
Please take a look at the README file platform-specific notes.

Overview

We have written several routines which use the gSOAP library to call JHTDB.

Limitations and Notes

  • Starting with the 2010-03 release, the library will automatically exit upon any network or database failure. This change was made to prevent accidental use of invalid data. See the included README for instructions on how to override this behavior.

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 Get[Field] functions ----
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 Get[Field]Gradient, Get[Field]Laplacian & Get[Field]Hessian ----
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

! ---- Spatial Differentiation & Interpolation Flags for Get[Field], Get[Field]Gradient, Get[Field]Laplacian & Get[Field]Hessian ----
integer, parameter :: M1Q4 = 104 ! Splines with smoothness 1 (3rd order) over 4 data points. Not applicable for Hessian.
integer, parameter :: M2Q8 = 208 ! Splines with smoothness 2 (5th order) over 8 data points.
integer, parameter :: M2Q14 = 214 ! Splines with smoothness 2 (5th order) over 14 data points.


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

C
enum SpatialInterpolation {
  /* Spatial Interpolation Flags for Get[Field] */
  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 Get[Field]Gradient, Get[Field]Laplacian, Get[Field]Hessian */
  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 */
};

  /* Spatial Differentiation & Interpolation Flags for Get[Field], Get[Field]Gradient, Get[Field]Laplacian, Get[Field]Hessian */
  M1Q4 = 104, /* Splines with smoothness 1 (3rd order) over 4 data points. Not applicable for Hessian. */
  M2Q8 = 208, /* Splines with smoothness 2 (5th order) over 8 data points. */
  M2Q14 = 214, /* Splines with smoothness 2 (5th order) over 14 data points. */
};

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]);
}

And similarly for GetPosition, GetMagneticField, GetVectorPotential, GetMagneticFieldGradient, GetBoxFilter, GetThreshold etc.

Disclaimer: While many efforts have been made to ensure that these data are accurate and reliable within the limits of the current state of the art, neither JHU nor any other party involved in creating, producing or delivering the website shall be liable for any damages arising out of users' access to, or use of, the website or web services. Users use the website and web services at their own risk. JHU does not warrant that the functional aspects of the website will be uninterrupted or error free, and may make changes to the site without notice.

Last update: 8/28/2015 11:01:00 AM