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.
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
#include "Py_py-api.h"
|
|
#include "condor.h"
|
|
#include "genlib.h"
|
|
#include "geostat.h"
|
|
#include "pressure.h"
|
|
#include "simpio.h"
|
|
#include "toolsFFTMA.h"
|
|
#include "toolsFFTPSIM.h"
|
|
#include "toolsIO.h"
|
|
#include <Python.h>
|
|
#include <math.h>
|
|
#include <numpy/arrayobject.h>
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#define NDIMENSIONS 3
|
|
|
|
/* 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) {
|
|
int n[3];
|
|
struct realization_mod Z, Y;
|
|
struct grid_mod grid;
|
|
struct vario_mod variogram;
|
|
long seed;
|
|
struct statistic_mod stat;
|
|
PyObject* out_array;
|
|
npy_intp out_dims[NPY_MAXDIMS];
|
|
|
|
if (!Py_getvalues(args, &seed, &grid, &variogram, &stat))
|
|
return NULL;
|
|
|
|
Py_kgeneration(seed, grid, stat, variogram, &Z, &Y, n);
|
|
|
|
out_dims[0] = grid.NZ;
|
|
out_dims[1] = grid.NY;
|
|
out_dims[2] = grid.NX;
|
|
|
|
out_array = PyArray_SimpleNewFromData(NDIMENSIONS, out_dims, NPY_DOUBLE, Y.vector);
|
|
if (out_array == NULL)
|
|
return NULL;
|
|
|
|
PyArray_ENABLEFLAGS(out_array, NPY_ARRAY_OWNDATA);
|
|
|
|
free(stat.mean);
|
|
free(stat.variance);
|
|
free(variogram.var);
|
|
free(variogram.alpha);
|
|
free(variogram.scf);
|
|
free(variogram.ap);
|
|
|
|
return out_array;
|
|
}
|
|
|
|
static PyMethodDef FFTMAMethods[] = {
|
|
{ "gen", genFunc, METH_VARARGS, "Generates a permeability 3D field." },
|
|
{ NULL, NULL, 0, NULL }
|
|
};
|
|
|
|
static struct PyModuleDef cFFTMADef = {
|
|
PyModuleDef_HEAD_INIT,
|
|
"FFTMA", "",
|
|
-1,
|
|
FFTMAMethods
|
|
};
|
|
|
|
PyMODINIT_FUNC
|
|
PyInit_FFTMA(void)
|
|
{
|
|
import_array();
|
|
return PyModule_Create(&cFFTMADef);
|
|
}
|