Merge pull request #5 from medios-porosos-fiuba/removing-vector-2

Removing vector 2
milestone_5
Cecilia Hortas 3 years ago committed by GitHub
commit 36e64fa03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,7 +7,7 @@
#include <string.h>
#include <stdbool.h>
#define MAX_CHUNK_SIZE 32
#define MAX_CHUNK_SIZE 512
typedef struct chunk_array {
size_t init_pos;

@ -36,7 +36,7 @@
/*realout4: structure defining a yvelocity field */
/*realout5: structure defining a zvelocity field */
void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout, int cores);
void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout, int cores, long* seed);
/* prebuild_gwn */
/* Produce a first construction in real space of the Gaussian white noise */
@ -51,7 +51,7 @@ void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct r
/* 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, double* realization, int solver, int cores);
void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, double* realization, int solver, int cores, long* seed);
/* build_real */
/* build a realization in the spectral domain */

@ -46,7 +46,9 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
generate(&seed, N, Z, cores);
/*FFTMA*/
FFTMA2(variogram, grid, n, Z, Y, cores);
printf("pre fftma2\n");
FFTMA2(variogram, grid, n, Z, Y, cores, &seed);
printf("post fftma2\n");
/* make a log normal realization */
if (stat.type == 1 || stat.type == 2) {
@ -54,6 +56,8 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
nor2log(Y, typelog, Y);
}
printf("termino nor2log\n");
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
@ -70,6 +74,7 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
log_info("RESULT = success, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", time_taken, *used_ram_tf - *used_ram_t0);
printf("termino pykgeneration\n");
free(used_ram_t0);
free(used_ram_tf);
}

@ -8,6 +8,7 @@ void chunk_array_free(chunk_array_t* chunk_array) {
}
bool chunk_array_update_read(chunk_array_t* chunk_array) {
printf("Llame a chunk array update\n");
size_t newLen = fread(chunk_array->data, sizeof(double), chunk_array->chunk_size, chunk_array->fp);
chunk_array->init_pos += newLen;
}

@ -24,7 +24,7 @@
/*output: */
/*realout: structure defining a realization - */
void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout, int cores) {
void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout, int cores, long* seed) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
@ -88,8 +88,10 @@ void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct r
fourt(covar, ireal, n, NDIM, 1, 0, workr, worki, cores);
/*organization of the input Gaussian white noise*/
printf("pre prebuild_gwn\n");
solver = 0;
prebuild_gwn(grid, n, realin, realization, solver, cores);
prebuild_gwn(grid, n, realin, realization, solver, cores, seed);
printf("post prebuild_gwn\n");
/*forward fourier transform of the GWN*/
fourt(realization, ireal, n, NDIM, 1, 0, workr, worki, cores);

@ -41,19 +41,19 @@ void generate(long* seed, int n, struct realization_mod* realization, int cores)
/*realization definition*/
(*realization).n = n;
(*realization).code = 0;
(*realization).vector_2 = chunk_array_create("realization1.txt", n, 32);
/*(*realization).vector_2 = chunk_array_create("realization1.txt", n, 512);
if ((*realization).vector_2 == NULL) {
log_error("RESULT = failed - No memory available in generate");
exit(1);
}
}*/
/*Gaussian white noise generation*/
for (i = 0; i < n; i++) {
/*for (i = 0; i < n; i++) {
double value = gasdev(seed, &idum2, &iy, iv, cores);
chunk_array_save((*realization).vector_2, i, value);
}
chunk_array_flush((*realization).vector_2);
chunk_array_flush((*realization).vector_2);*/
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time

@ -22,7 +22,7 @@
/* 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, double* realization, int solver, int cores) {
void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, double* realization, int solver, int cores, long* seed) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
@ -31,6 +31,13 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin
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);
log_info("RESULT = in progress, n[0] = %d, n[1] = %d, n[2] = %d, solver = %d", n[0], n[1], n[2], solver);
struct cpustat initial[cores];
@ -42,10 +49,14 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin
ntot = n[0] * n[1] * n[2];
realization[0] = 0.;
/*printf("Antes de llamar a chunkarray read\n");
chunk_array_read((*realin).vector_2);
printf("Despues de llamar a chunkarray read\n");*/
if (solver == 1) {
for (i = 0; i < ntot; i++) {
chunk_array_get((*realin).vector_2, i, &realization[i + 1]);
double value = gasdev(seed, &idum2, &iy, iv, cores);
realization[i+1] = value;
//chunk_array_get((*realin).vector_2, i, &realization[i + 1]);
}
} else {
for (k = 1; k <= n[2]; k++) {
@ -53,8 +64,11 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin
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) {
maille0 = i - 1 + (j - 1 + (k - 1) * grid.NY) * grid.NX;
chunk_array_get((*realin).vector_2, maille0, &realization[maille1]);
//maille0 = i - 1 + (j - 1 + (k - 1) * grid.NY) * grid.NX;
//printf("Maille0 es %d", maille0);
double value = gasdev(seed, &idum2, &iy, iv, cores);
realization[maille1] = value;
//chunk_array_get((*realin).vector_2, maille0, &realization[maille1]);
} else {
realization[maille1] = 0.;
}

@ -37,6 +37,7 @@ static PyObject* genFunc(PyObject* self, PyObject* args) {
if (!Py_getvalues(args, &seed, &grid, &variogram, &stat, &cores))
return NULL;
printf("deberia imprimir\n");
Py_kgeneration(seed, grid, stat, variogram, &Z, &Y, n, cores);
out_dims[0] = grid.NZ;
@ -49,16 +50,32 @@ static PyObject* genFunc(PyObject* self, PyObject* args) {
PyArray_ENABLEFLAGS(out_array, NPY_ARRAY_OWNDATA);
printf("me localizo\n");
free(stat.mean);
free(stat.variance);
printf("termino stat\n");
free(variogram.var);
free(variogram.vario);
printf("1\n");
printf("2\n");
free(variogram.alpha);
printf("3\n");
free(variogram.scf);
printf("4\n");
free(variogram.ap);
chunk_array_free(Z.vector_2);
remove("realization1.txt");
//free(variogram.vario);
printf("Termino variogram\n");
printf("aca no deberia llegar\n");
/*chunk_array_free(Z.vector_2);
remove("realization1.txt");*/
log_info("RESULT = success");
return out_array;

Loading…
Cancel
Save