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.
simulacion-permeabilidad/fftma_module/gen/sources/FFTPressure.c

158 lines
4.8 KiB
C

#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include "geostat.h"
#include "pressure.h"
/*FAST FOURIER TRANSFORM Pressure Simulation */
/*Turns a Gaussian white noise vector into a */
/*spatially correlated vector */
/*input: */
/*variogram: structure defining the variogram */
/* model */
/*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 */
/*gradient: macroscopic gradient pression vector */
/*output: */
/*realout: structure defining a realization - */
/*realout2: structure defining a pressure field */
/*realout3: structure defining a xvelocity field */
/*realout4: structure defining a yvelocity field */
/*realout5: structure defining a zvelocity field */
void FFTPressure(int n[3],struct grid_mod grid,struct realization_mod *realin,struct statistic_mod stat,struct pressure_mod gradient,struct realization_mod *realout,struct realization_mod *realout2,struct realization_mod *realout3,struct realization_mod *realout4,int solver)
{
int NTOT,i,j,k,NMAX,NDIM,ntot,nmax,NXYZ,nxyz,maille0,maille1;
double *workr,*worki,temp,temp2,coeff;
double *realization,*pressure;
double *ireal,*ipressure;
double *xvelocity,*ixvelocity,*yvelocity,*iyvelocity,*zvelocity,*izvelocity;
double ki,kj,kk;
FILE *fp;
/* string nomfichier; */
/*constant definition*/
NTOT = n[0]*n[1]*n[2];
ntot = NTOT+1;
NMAX = n[0];
NDIM = 3;
for (i=1;i<3;i++) {
if (n[i] > NMAX)
NMAX = n[i];
if (n[i] == 1)
NDIM--;
}
nmax = NMAX+1;
NXYZ = grid.NX*grid.NY*grid.NZ;
nxyz = NXYZ+1;
realization = (double *) malloc(ntot * sizeof(double));
testmemory(realization);
ireal = (double *) malloc(ntot * sizeof(double));
testmemory(ireal);
pressure = (double *) malloc(ntot * sizeof(double));
testmemory(pressure);
ipressure = (double *) malloc(ntot * sizeof(double));
testmemory(ipressure);
xvelocity = (double *) malloc(ntot * sizeof(double));
testmemory(xvelocity);
ixvelocity = (double *) malloc(ntot * sizeof(double));
testmemory(ixvelocity);
yvelocity = (double *) malloc(ntot * sizeof(double));
testmemory(yvelocity);
iyvelocity = (double *) malloc(ntot * sizeof(double));
testmemory(iyvelocity);
zvelocity = (double *) malloc(ntot * sizeof(double));
testmemory(zvelocity);
izvelocity = (double *) malloc(ntot * sizeof(double));
testmemory(izvelocity);
workr = (double *) malloc(nmax * sizeof(double));
testmemory(workr);
worki = (double *) malloc(nmax * sizeof(double));
testmemory(worki);
/*organization of the realization*/
prebuild_gwn(grid,n,realin,realization,solver);
/*forward fourier transform of the GWN*/
fourt(realization,ireal,n,NDIM,1,0,workr,worki);
/* pressure calculation in the spectral domain*/
build_pressure(n,grid,gradient,realization,ireal,pressure,ipressure);
build_velocity(n,grid,stat,gradient,realization,ireal,xvelocity,ixvelocity,1);
build_velocity(n,grid,stat,gradient,realization,ireal,yvelocity,iyvelocity,2);
build_velocity(n,grid,stat,gradient,realization,ireal,zvelocity,izvelocity,3);
/*backward fourier transform*/
fourt(realization,ireal,n,NDIM,0,1,workr,worki);
fourt(pressure,ipressure,n,NDIM,0,1,workr,worki);
fourt(xvelocity,ixvelocity,n,NDIM,0,1,workr,worki);
fourt(yvelocity,iyvelocity,n,NDIM,0,1,workr,worki);
fourt(zvelocity,izvelocity,n,NDIM,0,1,workr,worki);
free(ireal);
free(ipressure);
free(ixvelocity);
free(iyvelocity);
free(izvelocity);
free(workr);
free(worki);
for (i=1;i<=NTOT;i++)
realization[i]=realization[i]/(double) NTOT;
fp = fopen("realization.test", "w");
for (i=1;i<=NTOT;i++)
fprintf(fp,"%f\n",realization[i]);
fclose(fp);
/* nomfichier="pression.test"; */
fp = fopen("pression.test", "w");
for (i=1;i<=NTOT;i++)
fprintf(fp,"%f\n",pressure[i]);
fclose(fp);
/*output realization*/
/*is the output realization already allocated?*/
/*if not, memory allocation*/
clean_real2(realin,n,grid,solver,pressure,realout);
clean_real2(realin,n,grid,solver,xvelocity,realout2);
clean_real2(realin,n,grid,solver,yvelocity,realout3);
clean_real2(realin,n,grid,solver,zvelocity,realout4);
/* free(realization); */
/* free(pressure); */
/* free(xvelocity); */
/* free(yvelocity); */
/* free(zvelocity); */
return;
}