You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
C
58 lines
1.9 KiB
C
#include "geostat.h"
|
|
#include "chunk_array.h"
|
|
#include <math.h>
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
/* prebuild_gwn */
|
|
/* Produce a first construction in real space of the Gaussian white noise */
|
|
/* grid: structure defining the grid */
|
|
/*n: vector with the number of cells along the */
|
|
/* X, Y and Z axes for the underlying grid */
|
|
/* i = [0 1 2] */
|
|
/* --> 0 0 0 : n will be computed and */
|
|
/* updated as output */
|
|
/* --> nx ny nz: these dimensions are used */
|
|
/*realin: structure defining a realization - */
|
|
/* must be a Gaussian white noise */
|
|
/*realization: structure defining a realization*/
|
|
|
|
void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, chunk_array_t* realization, int solver, long* seed) {
|
|
int i, j, k, maille0, maille1;
|
|
int ntot;
|
|
|
|
long idum2 = 123456789, iy = 0;
|
|
long* iv = (long*)malloc(NTAB * sizeof(long));
|
|
|
|
/*negative seed*/
|
|
if (*seed > 0.0)
|
|
*seed = -(*seed);
|
|
|
|
ntot = n[0] * n[1] * n[2];
|
|
chunk_array_save(realization, 0, 0.);
|
|
if (solver == 1) {
|
|
for (i = 0; i < ntot; i++) {
|
|
double value = gasdev(seed, &idum2, &iy, iv);
|
|
chunk_array_save(realization, i+1, value);
|
|
}
|
|
} else {
|
|
for (k = 1; k <= n[2]; k++) {
|
|
for (j = 1; j <= n[1]; j++) {
|
|
for (i = 1; i <= n[0]; i++) {
|
|
maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0];
|
|
if (i <= grid.NX && j <= grid.NY && k <= grid.NZ) {
|
|
double value = gasdev(seed, &idum2, &iy, iv);
|
|
chunk_array_save(realization, maille1, value);
|
|
} else {
|
|
chunk_array_save(realization, maille1, 0.);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|