Skip to content

githubgrasp/genran

Repository files navigation

genran

Random field generator


GenRan: Non-Gaussian Random field generator. Copyright (C) 2006 Peter Grassl Version 1.0-Devel MIT licence


The code was used internally for some student projects. Below are instructions from an email exchange:

The code is written as a combination of code from three sources:

  1. Articles by Shinozuka and Jan (1972) and Shinozuka and Deodatis (1991, 1996).
  2. Routines from Numerical Recipee's
  3. Routines from John Burkardt's webpage https://people.sc.fsu.edu/~jburkardt/

The program is started on the command line by for instance: genran.exe test1D.in field1D.dat

"test1D.in" is the input file and "field1D.dat" is the output file in which the random field is stored.

Lets have a look at the 1D input file (test1D.in) for instance:

numberOfDimensions = 1 (A one-dimensional field is generated. 2 for 2D and 3 for 3D)

typeOfCDF = 1 (1 stands for Gaussian CDF. 2 for Weibull and 3 for Combined Weibull and Gaussian. But so far only Gaussian is debugged.)

realNumber1 = 524288 (This gives the number of data points generated in this direction. For 3D there is also realNumber2 and realNumber3 for the other two directions. Note, realNumbers must be of the form 2^N, where N is a integer. This is the price that I pay for using Fourier transforms.)

autoLength1 = 0.5 (This is the autocorrelation length la. The autocorrelation function has the form e^(-(|x|/b)^2). The parameter b is related to la as "b=(2*la)/sqrt(pi)". The geometrical meaning of la is explained in my Euro-C presentation.

converter = 200 (this converter determines the size of the field (l1l2l3). Here for 1D l1 = (realNumber1-1)/converter. So if you want to generate one meter random field (l1=1.0) and want to use 64 points (remember 2^N!) then determine converter as converter = (realNumber-1)/l1 = 63.)

mean = 1. (this is the mean of the Gaussian field) cov = 1. (And this is the coefficient of variation)

That's it concerning the input file.

The format of the output-file is the following:

in 1D:
xCoordinate1 fieldValue xCoordinate2 fieldValue xCoordinate3 fieldValue

in 2D:
xCoordinate1 yCoordinate1 fieldValue xCoordinate1 yCoordinate2 fieldValue xCoordinate1 yCoordinate3 fieldValue . . xCoordinate2 yCoordinate1 fieldValue xCoordinate2 yCoordinate2 fieldValue xCoordinate2 yCoordinate3 fieldValue . . .

The corresponding in 3D. (I guess you get the idea).

I guess, the first step would be to compile it on your system. I used a Makefile and compiled it with gcc on ubuntu just by typing make, but Visual C++ should works as well.

It might be a good starting point to look at the 1D case first since you can generate long fields. Furthermore, for all dimensions, I output the statistical info in stat.dat (mean and coefficient of variation).

I have attached three input files (test1D.in, test2D.in and test3D.in) and the corresponding output files (field1D.dat, field2D.dat and field3D.dat).

Here is a list of all source and header files:

-rwx------ 1 peter peter 3992 2006-08-14 20:04 fourier.C -rwx------ 1 peter peter 10647 2006-08-14 20:05 gaussianfieldgenerator.C -rw-r--r-- 1 peter peter 7166 2006-08-14 20:59 genran.C -rwx------ 1 peter peter 9333 2006-08-14 20:06 help.C -rw-r--r-- 1 peter peter 6633 2006-08-11 01:52 randomfield.C -rw-r--r-- 1 peter peter 17349 2006-08-14 20:06 randomfieldgenerator.C

The "main"-file is genran.C. Here the input is read in the randomfieldgenerator is called and the ouptut is written in the corresponding file. In the file "gaussianfieldgenerator.C" the gaussian field is generated using the spectral representation. The file "randomfieldgenrator.C" implements the generation of non-gaussian fields using a iterative approach. The other "C"-files contain several help functions for reading the input, different cdfs and the fourier transforms. "random.h" is header file for the whole program.

About

Random field generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published