milestone_5_without_improvements-logs
chortas 4 years ago
parent e52630f86d
commit 1e9aefebf0

@ -1,5 +1,6 @@
#include "Py_py-api.h"
#include "genlib.h"
#include "log.h"
#include "geostat.h"
#include "pressure.h"
#include "simpio.h"
@ -40,8 +41,8 @@
#endif
#endif
int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat)
{
int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat) {
log_info("RESULT = in progress");
int i, varioNargs = 12, j = 0;
PyObject* listvario;
PyObject* vgr;
@ -55,6 +56,7 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
stat->variance = (double*)malloc(stat->nblock_var * sizeof(double));
if (stat->variance == NULL) {
free(stat->mean);
log_error("RESULT = failed");
return 0;
}
@ -73,6 +75,7 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
&(stat->type))) {
free(stat->mean);
free(stat->variance);
log_error("RESULT = failed");
return 0;
}
@ -82,6 +85,7 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
if (variogram->var == NULL) {
free(stat->mean);
free(stat->variance);
log_error("RESULT = failed");
return 0;
}
variogram->vario = (int*)malloc(variogram->Nvario * sizeof(int));
@ -89,6 +93,7 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(stat->mean);
free(stat->variance);
free(variogram->var);
log_error("RESULT = failed");
return 0;
}
variogram->alpha = (double*)malloc(variogram->Nvario * sizeof(double));
@ -97,6 +102,7 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(stat->variance);
free(variogram->var);
free(variogram->vario);
log_error("RESULT = failed");
return 0;
}
variogram->scf = (double*)malloc(3 * variogram->Nvario * sizeof(double));
@ -106,6 +112,7 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(variogram->var);
free(variogram->vario);
free(variogram->alpha);
log_error("RESULT = failed");
return 0;
}
variogram->ap = (double*)malloc(9 * variogram->Nvario * sizeof(double));
@ -116,12 +123,15 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(variogram->vario);
free(variogram->alpha);
free(variogram->scf);
log_error("RESULT = failed");
return 0;
}
for (i = 0; i < variogram->Nvario; i++) {
vgr = PyList_GetItem(listvario, i);
if (PyTuple_Size(vgr) != 12)
if (PyTuple_Size(vgr) != 12) {
log_error("RESULT = failed");
return 0;
}
(variogram->var)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
(variogram->vario)[i] = (int)PyInt_AsLong(PyTuple_GetItem(vgr, j++));
(variogram->alpha)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
@ -136,5 +146,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
(variogram->ap)[i * 9 + 5] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
}
log_info("RESULT = success");
return 1;
}

@ -4,6 +4,7 @@
#include "simpio.h"
#include "toolsFFTMA.h"
#include "toolsIO.h"
#include "log.h"
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdarg.h>
@ -17,7 +18,7 @@
/* Y is the realization with mean and variance wanted */
void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat, struct vario_mod variogram, struct realization_mod* Z, struct realization_mod* Y, int n[3])
{
{
int i, N;
int typelog;
@ -27,6 +28,8 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
n[1] = 0;
n[2] = 0;
log_info("RESULT = in progress, N = %d", N);
generate(&seed, N, Z);
/*FFTMA*/
@ -37,4 +40,6 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
typelog = stat.type + 2;
nor2log(Y, typelog, Y);
}
log_info("RESULT = success");
}

@ -1,4 +1,5 @@
#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
@ -18,10 +19,10 @@
/*realization: vector defining the real part */
/*ireal: vector defining the i-part */
void build_real(int n[3], int NTOT, double* covar, double* realization, double* ireal)
{
void build_real(int n[3], int NTOT, double* covar, double* realization, double* ireal) {
int i, j, k, maille1;
double temp;
log_info("RESULT = in progress, NTOT = %d, covar = %f, n[0] = %d, n[1] = %d, n[2] = %d", NTOT, *covar, n[0], n[1], n[2]);
/*decomposition and multiplication in the spectral domain*/
for (k = 1; k <= n[2]; k++) {
@ -40,5 +41,5 @@ void build_real(int n[3], int NTOT, double* covar, double* realization, double*
}
}
return;
log_info("RESULT = success, realization = %f, ireal = %f", *realization, *ireal);
}

@ -1,10 +1,12 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*cardsin covariance function*/
double cardsin(double h)
{
double cardsin(double h) {
log_info("RESULT = in progress, h = %f", h);
float delta = 20.371;
double z;
@ -14,5 +16,8 @@ double cardsin(double h)
} else {
z = 1.;
}
return (z);
log_info("RESULT = success, z = %f", z);
return z;
}

@ -1,4 +1,5 @@
#include "geostat.h"
#include "log.h"
#include <stdlib.h>
/*computes the size of the grid for FFTs*/
@ -9,10 +10,11 @@
/*n: vector with the number of cells along the */
/* X, Y and Z axes for the underlying grid */
/* i = [0 1 2] */
void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3])
{
void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3]) {
int i, N;
double D;
log_info("RESULT = in progress");
if (n == NULL || n[0] == 0 || n[1] == 0 || n[2] == 0) {
for (i = 0; i < 3; i++) {
@ -34,9 +36,10 @@ void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3])
}
} else {
if ((n[0] < grid.NX) || (n[1] < grid.NY) || (n[2] < grid.NZ)) {
printf("Indicated dimensions are inappropriate in cgrid");
log_error("RESULT = failed - Indicated dimensions are inappropriate in cgrid");
exit;
}
}
return;
log_info("RESULT = success, n[0] = %d, n[1] = %d, n[2] = %d", n[0], n[1], n[2]);
}

@ -1,4 +1,5 @@
#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
@ -6,8 +7,7 @@
#include <stdlib.h>
#include <string.h>
void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* vectorresult, struct realization_mod* realout)
{
void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* vectorresult, struct realization_mod* realout) {
int i, j, k, maille0, maille1;
double NTOT;
@ -15,10 +15,12 @@ void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid,
/*is the output realization already allocated?*/
/*if not, memory allocation*/
log_info("RESULT = in progress, NTOT = %f", NTOT);
if (realout->vector == NULL || realout->n != realin->n) {
realout->vector = (double*)malloc(realin->n * sizeof(double));
if (realout->vector == NULL) {
printf("Clean_real.c: No memory available\n");
log_error("RESULT = failed - No memory available");
exit;
}
}
@ -37,5 +39,5 @@ void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid,
}
}
return;
log_info("RESULT = success");
}

@ -1,10 +1,12 @@
#include "genlib.h"
#include "geostat.h"
#include "log.h"
#include <math.h>
/*selection of model covariance*/
double cov_value(struct vario_mod variogram, double di, double dj, double dk)
{
double cov_value(struct vario_mod variogram, double di, double dj, double dk) {
log_info("RESULT = in progress, di = %f, dj = %f, dk = %f", di, dj, dk);
double hx, hy, hz, h;
double cov;
int k;
@ -49,5 +51,7 @@ double cov_value(struct vario_mod variogram, double di, double dj, double dk)
}
}
return (cov);
log_info("RESULT = success, hx = %f, hy = %f, hz = %f, h = %f, cov = %f", hx, hy, hz, h, cov);
return cov;
}

@ -1,13 +1,14 @@
#include "geostat.h"
#include "log.h"
/*builds the sampled covariance function*/
/*dimensions are even*/
void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3])
{
void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3]) {
int i, j, k, maille, n2[3], symmetric;
double di, dj, dk;
log_info("RESULT = in progress");
for (i = 0; i < 3; i++)
n2[i] = n[i] / 2;
@ -76,5 +77,5 @@ void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh,
}
}
return;
log_info("RESULT = success, di = %f, dj = %f, dk = %f", di, dj, dk);
}

@ -1,10 +1,12 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*cubic covariance function*/
double cubic(double h)
{
double cubic(double h) {
log_info("RESULT = in progress, h = %f", h);
double z;
if (h >= 1.) {
@ -12,5 +14,8 @@ double cubic(double h)
} else {
z = 1. - 7. * (double)(h * h) + (35. / 4.) * (double)(h * h * h) - 3.5 * (double)(h * h * h * h * h) + .75 * (double)(h * h * h * h * h * h * h);
}
return (z);
log_info("RESULT = success, z = %f");
return z;
}

@ -1,9 +1,11 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*exponential covariance function*/
double exponential(double h)
{
double exponential(double h) {
log_info("RESULT = in progress, h = %f", h);
return (exp(-3. * (double)h));
}

@ -1,4 +1,5 @@
#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
@ -21,9 +22,10 @@
/*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 NTOT, i, j, k, NMAX, NDIM, ntot, nmax, NXYZ, nxyz, maille0, maille1;
void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout) {
log_info("RESULT = in progress");
int NTOT, i, j, k, NMAX, NDIM, ntot, nmax, NXYZ, nxyz;
int solver;
double temp;
double *ireal, *covar, *workr, *worki, *realization;
@ -94,4 +96,6 @@ void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct r
clean_real(realin, n, grid, realization, realout);
free(realization);
log_info("RESULT = success, NTOT = %d, NMAX = %d, NDIM = %d, ntot = %d, nmax = %d, NXYZ = %d, nxyz = %d", NTOT, NMAX, NDIM, ntot, nmax, NXYZ, nxyz);
}

@ -1,3 +1,4 @@
#include "log.h"
#include <math.h>
#include <stdio.h>
@ -89,8 +90,8 @@
/* PROGRAM MODIFIED FROM A SUBROUTINE OF BRENNER */
/* 10-06-2000, MLR */
void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki)
{
void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki) {
log_info("RESULT = in progress");
int ifact[21], ntot, idim, np1, n, np2, m, ntwo, iff, idiv, iquot, irem, inon2, non2p, np0, nprev, icase, ifmin, i, j, jmax, np2hf, i2, i1max, i3, j3, i1, ifp1, ifp2, i2max, i1rng, istep, imin, imax, mmax, mmin, mstep, j1, j2max, j2, jmin, j3max, nhalf;
double theta, wstpr, wstpi, wminr, wmini, wr, wi, wtemp, thetm, wmstr, wmsti, twowr, sr, si, oldsr, oldsi, stmpr, stmpi, tempr, tempi, difi, difr, sumr, sumi, TWOPI = 6.283185307179586476925286766559;
@ -583,5 +584,6 @@ void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icp
nprev = n;
}
L920:
log_info("RESULT = succes");
return;
}

@ -1,14 +1,18 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*gamma covariance function*/
double gammf(double h, double alpha)
{
double gammf(double h, double alpha) {
log_info("RESULT = in progress, h = %f, alpha = %f", h, alpha);
float delta;
double z;
delta = pow(20., 1. / alpha) - 1.;
z = 1. / (double)(pow(1. + h * delta, alpha));
return (z);
log_info("RESULT = success, delta = %f, z = %f", delta, z);
return z;
}

@ -1,13 +1,15 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#define NTAB 32
double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB])
/*returns a normally distributed deviate with 0 mean*/
/*and unit variance, using ran2(idum) as the source */
/*of uniform deviates */
{
double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB]) {
/*returns a normally distributed deviate with 0 mean*/
/*and unit variance, using ran2(idum) as the source */
/*of uniform deviates */
log_info("RESULT = in progress, idum = %f, idum2 = %f, iy = %f", *idum, *idum2, *iy);
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]);
static int iset = 0;
static double gset;
@ -23,9 +25,11 @@ double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB])
fac = sqrt(-2.0 * log(rsq) / rsq);
gset = v1 * fac;
iset = 1;
log_info("RESULT = success, gset = %f, fac = %f, v1 = %f", gset, fac, v1);
return (v2 * fac);
} else {
iset = 0;
return (gset);
log_info("RESULT = success, gset = %f", gset);
return gset;
}
}

@ -1,9 +1,10 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*gaussian covariance function*/
double gaussian(double h)
{
double gaussian(double h) {
log_info("RESULT = in progress, h = %f", h);
return (exp(-3. * (double)(h * h)));
}

@ -1,6 +1,7 @@
#include "geostat.h"
#include <math.h>
#include <stdlib.h>
#include "log.h"
/* GENERATION OF A GAUSSIAN WHITE NOISE VECTOR */
/*input: */
@ -9,8 +10,9 @@
/*output: */
/* realization: structure defining the realization*/
void generate(long* seed, int n, struct realization_mod* realization)
{
void generate(long* seed, int n, struct realization_mod* realization) {
log_info("RESULT = in progress, n = %d", n);
int i;
long idum2 = 123456789, iy = 0;
long* iv;
@ -27,7 +29,7 @@ void generate(long* seed, int n, struct realization_mod* realization)
(*realization).code = 0;
(*realization).vector = (double*)malloc(n * sizeof(double));
if ((*realization).vector == NULL) {
printf("No memory available in generate");
log_error("RESULT = failed - No memory available in generate");
exit;
}
@ -35,5 +37,6 @@ void generate(long* seed, int n, struct realization_mod* realization)
for (i = 0; i < n; i++)
(*realization).vector[i] = gasdev(seed, &idum2, &iy, iv, &iset);
log_info("RESULT = success");
free(iv);
}

@ -1,8 +1,10 @@
#include "log.h"
#include <math.h>
/* compute the length for one dimension*/
int length(int N, int i, double* scf, double* ap, double D, int Nvari)
{
int length(int N, int i, double* scf, double* ap, double D, int Nvari) {
log_info("RESULT = in progress, N = %d, i = %d, D = %f, Nvari = %d", N, i, D, Nvari);
int maxfactor(int n);
double temp1, temp2;
int n, j, k, nmax;
@ -35,5 +37,7 @@ int length(int N, int i, double* scf, double* ap, double D, int Nvari)
nmax = maxfactor(n);
}
}
return (n);
log_info("RESULT = success, n = %d", n);
return n;
}

@ -1,8 +1,10 @@
#include "genlib.h"
#include "log.h"
/*determines the greatest prime factor of an integer*/
int maxfactor(int n)
{
int maxfactor(int n) {
log_info("RESULT = in progress, n = %d", n);
int test_fact(int* pnum, int fact, int* pmaxfac);
int lnum, fact;
int maxfac;
@ -31,5 +33,7 @@ int maxfactor(int n)
maxfac = lnum;
}
}
return (maxfac);
log_info("RESULT = success, maxfac = %d", maxfac);
return maxfac;
}

@ -1,4 +1,5 @@
#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdlib.h>
@ -12,9 +13,8 @@
/*realout: structure defining a realization - */
/* lognormal numbers */
void nor2log(struct realization_mod* realin, int typelog, struct realization_mod* realout)
{
printf("Estoy en nor2log\n");
void nor2log(struct realization_mod* realin, int typelog, struct realization_mod* realout) {
log_info("RESULT = in progress");
int i;
double coeff;
@ -63,11 +63,11 @@ void nor2log(struct realization_mod* realin, int typelog, struct realization_mod
(*realout).vector[i] = exp((*realin).vector[i] * coeff);
break;
default:
printf("Unexpected case in nor2log");
log_error("RESULT = failed - Unexpected case in nor2log");
return;
break;
}
}
return;
log_info("RESULT = success");
}

@ -1,10 +1,12 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*nugget covariance function*/
double nugget(double h)
{
double nugget(double h) {
log_info("RESULT = in progress, h = %f", h);
if (h == 0) {
return (1.);
} else {

@ -1,9 +1,10 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*power covariance function*/
double power(double h, double alpha)
{
return (pow(h, alpha));
double power(double h, double alpha) {
log_info("RESULT = in progress, h = %f, alpha = %f", h, alpha);
return pow(h, alpha);
}

@ -1,4 +1,5 @@
#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
@ -19,12 +20,12 @@
/* 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)
{
void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, double* realization, int solver) {
int i, j, k, maille0, maille1;
int ntot;
log_info("RESULT = in progress, n[0] = %d, n[1] = %d, n[2] = %d, solver = %d", n[0], n[1], n[2], solver);
ntot = n[0] * n[1] * n[2];
realization[0] = 0.;
if (solver == 1) {
@ -46,5 +47,5 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin
}
}
}
return;
log_info("RESULT = success");
}

@ -1,4 +1,5 @@
#include "genlib.h"
#include "log.h"
#define IM1 2147483563
#define IM2 2147483399
@ -15,13 +16,13 @@
#define EPS 1.2e-7
#define RNMX (1.0 - EPS)
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB])
{
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]) {
int j;
long k;
double temp;
log_info("RESULT = in progress");
if (*idum <= 0) {
if (-(*idum) < 1)
*idum = 1;
@ -52,8 +53,12 @@ double ran2(long* idum, long* idum2, long* iy, long iv[NTAB])
iv[j] = *idum;
if (*iy < 1)
(*iy) += IMM1;
if ((temp = AM * (*iy)) > RNMX)
if ((temp = AM * (*iy)) > RNMX) {
log_info("RESULT = success");
return (RNMX);
else
return (temp);
}
else {
log_info("RESULT = success, temp = %f, temp");
return temp;
}
}

@ -1,16 +1,19 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*spherical covariance function*/
double spherical(double h)
{
double spherical(double h) {
double z;
log_info("RESULT = in progress, h = %f", h);
if (h >= 1.) {
z = 0.;
} else {
z = 1. - 1.5 * (double)h + 0.5 * (double)(h * h * h);
}
return (z);
log_info("RESULT = success, z = %f", z);
return z;
}

@ -3,7 +3,6 @@
#include <stdio.h>
/*stable covariance function*/
double stable(double h, double alpha)
{
double stable(double h, double alpha) {
return (exp(-3. * (double)pow(h, alpha)));
}

@ -7,6 +7,7 @@
#include "toolsFFTMA.h"
#include "toolsFFTPSIM.h"
#include "toolsIO.h"
#include "lib_src/log.h"
#include <Python.h>
#include <math.h>
#include <numpy/arrayobject.h>
@ -20,8 +21,8 @@
/* Z is the GWN with 0-mean and 1-variance */
/* Y is the realization with mean and variance wanted */
static PyObject* genFunc(PyObject* self, PyObject* args)
{
static PyObject* genFunc(PyObject* self, PyObject* args) {
log_info("RESULT = in progress");
int n[3];
struct realization_mod Z, Y;
struct grid_mod grid;
@ -53,6 +54,8 @@ static PyObject* genFunc(PyObject* self, PyObject* args)
free(variogram.scf);
free(variogram.ap);
free(Z.vector);
log_info("RESULT = success");
return out_array;
}

@ -42,6 +42,7 @@ module_FFTMA = Extension(
"./lib_src/clean_real.c",
"./lib_src/testmemory.c",
"./lib_src/genlib.c",
"./lib_src/log.c"
],
)

@ -2,7 +2,7 @@ from FFTMA import gen
import numpy as np
import gc
N=512
N=16
nx, ny, nz = N,N,N
dx, dy, dz = 1.0, 1.0, 1.0
@ -27,7 +27,7 @@ mean=15.3245987
variance=3.5682389
typ=3
for i in range(2):
for i in range(1):
k=gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ)
np.save(f"out_{i}.npy",k)

Loading…
Cancel
Save