milestone_5_without_improvements
Oli 3 years ago
parent e01ef454b0
commit 2593883e22

@ -10,40 +10,20 @@
/* List of functions: */ /* List of functions: */
/* ------------------ */ /* ------------------ */
/* pgeneration, FFTPSim, FFTPressure, build_pressure, build_velocity,total_velocity, clean_real2 */ /* FFTPSim, FFTPressure, build_pressure, build_velocity, clean_real2 */
/*Functions */ /*Functions */
/*----------*/ /*----------*/
void pgeneration(int n[3],struct grid_mod grid,struct statistic_mod stat,struct vario_mod variogram,string filename[8],struct pressure_mod pression,struct realization_mod *Y,struct realization_mod *P,struct realization_mod *VX,struct realization_mod *VY,struct realization_mod *VZ, int solver);
void pgeneration2(int n[3],struct grid_mod grid,struct statistic_mod stat,
struct vario_mod variogram,string filename[8],struct pressure_mod pression,
struct realization_mod *Y,struct realization_mod *P,
struct realization_mod *VX,struct realization_mod *VY,struct realization_mod *VZ, int solver, int format_file);
void FFTPSim(struct vario_mod variogram,struct statistic_mod stat,struct grid_mod grid,int n[3],struct realization_mod *realin,struct pressure_mod gradient,struct realization_mod *realout,struct realization_mod *realout2,struct realization_mod *realout3,struct realization_mod *realout4,struct realization_mod *realout5); void FFTPSim(struct vario_mod variogram,struct statistic_mod stat,struct grid_mod grid,int n[3],struct realization_mod *realin,struct pressure_mod gradient,struct realization_mod *realout,struct realization_mod *realout2,struct realization_mod *realout3,struct realization_mod *realout4,struct realization_mod *realout5);
//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);
void build_pressure(int n[3],struct grid_mod grid,struct pressure_mod gradient,double *realization,double *ireal,double *pressure,double *ipressure); void build_pressure(int n[3],struct grid_mod grid,struct pressure_mod gradient,double *realization,double *ireal,double *pressure,double *ipressure);
void build_velocity(int n[3],struct grid_mod grid,struct statistic_mod stat,struct pressure_mod gradient,double *realization,double *ireal,double *xvelocity,double *ixvelocity,int direction); void build_velocity(int n[3],struct grid_mod grid,struct statistic_mod stat,struct pressure_mod gradient,double *realization,double *ireal,double *xvelocity,double *ixvelocity,int direction);
/* total_velocity */
/* Build total velocity in one direction */
/* grid: structure defining the grid */
/* mean: permeability mean */
/* dgradient: macroscopic pressure gradient in wanted direction */
/* realout: structure defining a X velocity realization */
void total_velocity(struct grid_mod grid,double mean,int direction,struct pressure_mod gradient,struct realization_mod *realout);
void normAxes(double *vec, double *normed); void normAxes(double *vec, double *normed);
void waveVectorCompute1D(int n,double *vec); void waveVectorCompute1D(int n,double *vec);
void waveVectorCompute3D(int nX,int nY, int nZ, /*float dX, float dY, float dZ,*/ double nDir[3], double *waveVect);
void mat_vec(double *C, double *x, double *b, int n); void mat_vec(double *C, double *x, double *b, int n);

@ -12,7 +12,7 @@
/* List of functions: */ /* List of functions: */
/* ------------------ */ /* ------------------ */
/* writefile,writefile_bin,readfile_bin,inputdata,inputfiledata,readdata,debuginput */ /* readfile_bin,inputdata,inputfiledata,debuginput */
/* testmemory, testopenfile */ /* testmemory, testopenfile */
@ -35,14 +35,6 @@ void inputdata(long *seed,struct grid_mod *grid,string filename[7],struct vario_
void inputfiledata(string inputfile,long *seed,struct grid_mod *grid,string filename[7],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression); void inputfiledata(string inputfile,long *seed,struct grid_mod *grid,string filename[7],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression);
/* void readdata(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,struct realization_mod *Kfield, char *argv[]); */
void readdata(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[]);
void readdata2(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, int *format_file, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[]);
void readdata3(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, int *format_file,int *Psolver, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[]);
/* readfile_bin */ /* readfile_bin */
/* */ /* */
/* read in the file "filename" the vector values of a */ /* read in the file "filename" the vector values of a */
@ -52,27 +44,6 @@ void readdata3(long *seed,struct grid_mod *grid,string filename[8],struct vario_
void readfile_bin(string filename, struct realization_mod *realin); void readfile_bin(string filename, struct realization_mod *realin);
/* Writefile */
/* */
/* write in the file "filename" the vector values of a */
/* realization_mod variable */
/* filename: explicit */
/* realin: structure defining a realization */
void writefile( string filename, struct realization_mod *realin);
/* Writefile_bin */
/* */
/* write in the file "filename" the vector values of a */
/* realization_mod variable */
/* filename: explicit */
/* realin: structure defining a realization */
void writefile_bin( string filename, struct realization_mod *realin);
/* DebugInput */ /* DebugInput */
/* */ /* */
/* Display the input data */ /* Display the input data */

@ -48,6 +48,8 @@ int Py_getvalues(PyObject* args, long* seed,struct grid_mod* grid,struct vario_m
PyObject* vgr; PyObject* vgr;
//char* gwnfilename; //char* gwnfilename;
printf("Py_getvalues\n");
stat->nblock_mean=1; stat->nblock_mean=1;
stat->nblock_var=1; stat->nblock_var=1;

@ -35,11 +35,6 @@ void Py_kgeneration(long seed,struct grid_mod grid,struct statistic_mod stat,st
generate(&seed,N,Z); generate(&seed,N,Z);
/*save the Gaussian white noise file*/
// if (*gwnwrite == 0)
// {
// writefile(filename[0],Z);
// }

@ -1,48 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
void pgeneration(int n[3],struct grid_mod grid,struct statistic_mod stat,struct vario_mod variogram,string filename[7],struct pressure_mod pression,struct realization_mod *Y,struct realization_mod *P,struct realization_mod *VX,struct realization_mod *VY,struct realization_mod *VZ, int solver)
{
int i,ntot;
struct realization_mod GP;
//FFTPressure(n,grid,Y,stat,pression,P,VX,VY,VZ,solver);
/*save the delta-pressure realization*/
writefile(filename[2],P);
//total_pressure(grid,pression,P);
total_velocity(grid,stat.mean[0],1,pression,VX);
total_velocity(grid,stat.mean[0],2,pression,VY);
total_velocity(grid,stat.mean[0],3,pression,VZ);
/*save the total pressure realization*/
writefile(filename[3],P);
/*save the x-velocity realization*/
writefile(filename[4],VX);
/*save the y-velocity realization*/
writefile(filename[5],VY);
/*save the z-velocity realization*/
writefile(filename[6],VZ);
ntot=grid.NX*grid.NY*grid.NZ;
GP.vector = (double *) malloc(ntot * sizeof(double));
testmemory(GP.vector);
GP.n= ntot-1;
for (i = 0; i < ntot-1; i++)
{
GP.vector[i]=(*P).vector[i]-(*P).vector[i-1];
}
/*save the pressure gradient realization*/
writefile(filename[7],&GP);
return;
}

@ -1,99 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
void pgeneration2(int n[3],struct grid_mod grid,struct statistic_mod stat,struct vario_mod variogram,string filename[7],struct pressure_mod pression,struct realization_mod *Y,struct realization_mod *P,struct realization_mod *VX,struct realization_mod *VY,struct realization_mod *VZ, int solver, int format_file)
{
int i,ntot;
struct realization_mod GP;
//FFTPressure(n,grid,Y,stat,pression,P,VX,VY,VZ,solver);
/*save the delta-pressure realization*/
switch (format_file)
{
case 0:
writefile(filename[2],P);
break;
case 1:
writefile_bin(filename[2],P);
break;
}
//total_pressure(grid,pression,P);
total_velocity(grid,stat.mean[0],1,pression,VX);
total_velocity(grid,stat.mean[0],2,pression,VY);
total_velocity(grid,stat.mean[0],3,pression,VZ);
/*save the total pressure realization*/
switch (format_file)
{
case 0:
writefile(filename[3],P);
break;
case 1:
writefile_bin(filename[3],P);
break;
}
/*save the x-velocity realization*/
switch (format_file)
{
case 0:
writefile(filename[4],VX);
break;
case 1:
writefile_bin(filename[4],VX);
break;
}
/*save the y-velocity realization*/
switch (format_file)
{
case 0:
writefile(filename[5],VY);
break;
case 1:
writefile_bin(filename[5],VY);
break;
}
/*save the z-velocity realization*/
switch (format_file)
{
case 0:
writefile(filename[6],VZ);
break;
case 1:
writefile_bin(filename[6],VZ);
break;
}
ntot=grid.NX*grid.NY*grid.NZ;
GP.vector = (double *) malloc(ntot * sizeof(double));
testmemory(GP.vector);
GP.n= ntot-1;
for (i = 0; i < ntot-1; i++)
{
GP.vector[i]=(*P).vector[i]-(*P).vector[i-1];
}
/*save the pressure gradient realization*/
switch (format_file)
{
case 0:
writefile(filename[7],&GP);
break;
case 1:
writefile_bin(filename[7],&GP);
break;
}
return;
}

@ -18,6 +18,7 @@
double ran2(long *idum, long *idum2, long *iy, long iv[NTAB]) double ran2(long *idum, long *idum2, long *iy, long iv[NTAB])
{ {
//printf("ran2\n");
int j; int j;
long k; long k;
double temp; double temp;

@ -1,204 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
void readdata(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[])
{
FILE *fp;
int i,j,n;
char *file1,*file2,*file3,*file4,*file5;
char *prog=argv[0];
double tmp;
file1=argv[1];
file2=argv[2];
/* Ouverture du fichier de donn<6E>es principal */
if ((fp=fopen(file1,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file1);
exit(1);
}
else
{
*Ksolver = atoi(ReadLine(fp));
*genere = atoi(ReadLine(fp));
*gwnwrite = atoi(ReadLine(fp));
if (*gwnwrite==0)
{
filename[0] = ReadLine(fp);
}
(*grid).NX = atoi(ReadLine(fp));
(*grid).NY = atoi(ReadLine(fp));
(*grid).NZ = atoi(ReadLine(fp));
(*grid).DX = atof(ReadLine(fp));
(*grid).DY = atof(ReadLine(fp));
(*grid).DZ = atof(ReadLine(fp));
fclose(fp);
}
n=(*grid).NX*(*grid).NY*(*grid).NZ;
/* Ouverture du fichier de donn<6E>es sur le champ de perm<72>abilit<69> */
if ((fp=fopen(file2,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file2);
exit(1);
}
else
{
*seed=atoi(ReadLine(fp));
(*variogram).Nvario = atoi(ReadLine(fp));
(*variogram).vario = (int *) malloc((*variogram).Nvario * sizeof(int));
(*variogram).alpha = (double *) malloc((*variogram).Nvario * sizeof(double));
(*variogram).ap = (double *) malloc(9*(*variogram).Nvario * sizeof(double));
(*variogram).scf = (double *) malloc(3*(*variogram).Nvario * sizeof(double));
(*variogram).var = (double *) malloc((*variogram).Nvario * sizeof(double));
for (i= 0; i < (*variogram).Nvario; i++) {
(*variogram).var[i] = atof(ReadLine(fp));
(*variogram).vario[i] = atoi(ReadLine(fp));
(*variogram).alpha[i] = atof(ReadLine(fp));
for (j = 0; j < 3; j++)
(*variogram).scf[i*3+j]= atof(ReadLine(fp));
for (j = 0; j < 6; j++)
(*variogram).ap[i*9+j] = atof(ReadLine(fp));
}
/*statistical data*/
(*stat).nblock_mean = 1;
(*stat).nblock_var = 1;
(*stat).mean = (double *)malloc((*stat).nblock_mean * sizeof(double));
if ((*stat).mean == NULL)
Error("No memory available");
(*stat).variance = (double *)malloc((*stat).nblock_var * sizeof(double));
if ((*stat).variance == NULL)
Error("No memory available");
(*stat).mean[0] = atof(ReadLine(fp));
(*stat).variance[0] = atof(ReadLine(fp));
(*stat).type = atoi(ReadLine(fp));
filename[1] = ReadLine(fp);
fclose(fp);
}
switch (*Ksolver)
{
case 0:
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
{
/* (*gwnoise).vector[i]=atof(ReadLine(fp)); */
/* sscanf(ReadLine(fp)," %Lf %c",gwnoise.vector[i],&merde); */
fscanf(fp,"%lf",&tmp);
(*gwnoise).vector[i]= tmp;
}
fclose(fp);
}
}
break;
case 1:
file3=argv[3];
/* Ouverture du fichier de donn<6E>es de pression*/
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du champ de permeabilite K */
(*Kfield).vector = (double *) malloc(n * sizeof(double));
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file4);
exit(1);
}
else
{
for (i=0;i<n;i++)
(*Kfield).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
break;
case 2:
/* Ouverture du fichier de donn<6E>es de pression */
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
(*gwnoise).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
}
break;
}
return;
}

@ -1,205 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
void readdata2(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, int *format_file, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[])
{
FILE *fp;
int i,j,n;
char *file1,*file2,*file3,*file4,*file5;
char *prog=argv[0];
double tmp;
file1=argv[1];
file2=argv[2];
/* Ouverture du fichier de donn<6E>es principal */
if ((fp=fopen(file1,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file1);
exit(1);
}
else
{
*Ksolver = atoi(ReadLine(fp));
*genere = atoi(ReadLine(fp));
*gwnwrite = atoi(ReadLine(fp));
if (*gwnwrite==0)
{
filename[0] = ReadLine(fp);
}
*format_file=atoi(ReadLine(fp));
(*grid).NX = atoi(ReadLine(fp));
(*grid).NY = atoi(ReadLine(fp));
(*grid).NZ = atoi(ReadLine(fp));
(*grid).DX = atof(ReadLine(fp));
(*grid).DY = atof(ReadLine(fp));
(*grid).DZ = atof(ReadLine(fp));
fclose(fp);
}
n=(*grid).NX*(*grid).NY*(*grid).NZ;
/* Ouverture du fichier de donn<6E>es sur le champ de perm<72>abilit<69> */
if ((fp=fopen(file2,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file2);
exit(1);
}
else
{
*seed=atoi(ReadLine(fp));
(*variogram).Nvario = atoi(ReadLine(fp));
(*variogram).vario = (int *) malloc((*variogram).Nvario * sizeof(int));
(*variogram).alpha = (double *) malloc((*variogram).Nvario * sizeof(double));
(*variogram).ap = (double *) malloc(9*(*variogram).Nvario * sizeof(double));
(*variogram).scf = (double *) malloc(3*(*variogram).Nvario * sizeof(double));
(*variogram).var = (double *) malloc((*variogram).Nvario * sizeof(double));
for (i= 0; i < (*variogram).Nvario; i++) {
(*variogram).var[i] = atof(ReadLine(fp));
(*variogram).vario[i] = atoi(ReadLine(fp));
(*variogram).alpha[i] = atof(ReadLine(fp));
for (j = 0; j < 3; j++)
(*variogram).scf[i*3+j]= atof(ReadLine(fp));
for (j = 0; j < 6; j++)
(*variogram).ap[i*9+j] = atof(ReadLine(fp));
}
/*statistical data*/
(*stat).nblock_mean = 1;
(*stat).nblock_var = 1;
(*stat).mean = (double *)malloc((*stat).nblock_mean * sizeof(double));
if ((*stat).mean == NULL)
Error("No memory available");
(*stat).variance = (double *)malloc((*stat).nblock_var * sizeof(double));
if ((*stat).variance == NULL)
Error("No memory available");
(*stat).mean[0] = atof(ReadLine(fp));
(*stat).variance[0] = atof(ReadLine(fp));
(*stat).type = atoi(ReadLine(fp));
filename[1] = ReadLine(fp);
fclose(fp);
}
switch (*Ksolver)
{
case 0:
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
{
/* (*gwnoise).vector[i]=atof(ReadLine(fp)); */
/* sscanf(ReadLine(fp)," %Lf %c",gwnoise.vector[i],&merde); */
fscanf(fp,"%lf",&tmp);
(*gwnoise).vector[i]= tmp;
}
fclose(fp);
}
}
break;
case 1:
file3=argv[3];
/* Ouverture du fichier de donn<6E>es de pression*/
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du champ de permeabilite K */
(*Kfield).vector = (double *) malloc(n * sizeof(double));
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file4);
exit(1);
}
else
{
for (i=0;i<n;i++)
(*Kfield).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
break;
case 2:
/* Ouverture du fichier de donn<6E>es de pression */
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
(*gwnoise).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
}
break;
}
return;
}

@ -1,206 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
void readdata3(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, int *format_file,int *Psolver, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[])
{
FILE *fp;
int i,j,n;
char *file1,*file2,*file3,*file4,*file5;
char *prog=argv[0];
double tmp;
file1=argv[1];
file2=argv[2];
/* Ouverture du fichier de donn<6E>es principal */
if ((fp=fopen(file1,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file1);
exit(1);
}
else
{
*Ksolver = atoi(ReadLine(fp));
*genere = atoi(ReadLine(fp));
*gwnwrite = atoi(ReadLine(fp));
if (*gwnwrite==0)
{
filename[0] = ReadLine(fp);
}
*format_file=atoi(ReadLine(fp));
*Psolver=atoi(ReadLine(fp));
(*grid).NX = atoi(ReadLine(fp));
(*grid).NY = atoi(ReadLine(fp));
(*grid).NZ = atoi(ReadLine(fp));
(*grid).DX = atof(ReadLine(fp));
(*grid).DY = atof(ReadLine(fp));
(*grid).DZ = atof(ReadLine(fp));
fclose(fp);
}
n=(*grid).NX*(*grid).NY*(*grid).NZ;
/* Ouverture du fichier de donn<6E>es sur le champ de perm<72>abilit<69> */
if ((fp=fopen(file2,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file2);
exit(1);
}
else
{
*seed=atoi(ReadLine(fp));
(*variogram).Nvario = atoi(ReadLine(fp));
(*variogram).vario = (int *) malloc((*variogram).Nvario * sizeof(int));
(*variogram).alpha = (double *) malloc((*variogram).Nvario * sizeof(double));
(*variogram).ap = (double *) malloc(9*(*variogram).Nvario * sizeof(double));
(*variogram).scf = (double *) malloc(3*(*variogram).Nvario * sizeof(double));
(*variogram).var = (double *) malloc((*variogram).Nvario * sizeof(double));
for (i= 0; i < (*variogram).Nvario; i++) {
(*variogram).var[i] = atof(ReadLine(fp));
(*variogram).vario[i] = atoi(ReadLine(fp));
(*variogram).alpha[i] = atof(ReadLine(fp));
for (j = 0; j < 3; j++)
(*variogram).scf[i*3+j]= atof(ReadLine(fp));
for (j = 0; j < 6; j++)
(*variogram).ap[i*9+j] = atof(ReadLine(fp));
}
/*statistical data*/
(*stat).nblock_mean = 1;
(*stat).nblock_var = 1;
(*stat).mean = (double *)malloc((*stat).nblock_mean * sizeof(double));
if ((*stat).mean == NULL)
Error("No memory available");
(*stat).variance = (double *)malloc((*stat).nblock_var * sizeof(double));
if ((*stat).variance == NULL)
Error("No memory available");
(*stat).mean[0] = atof(ReadLine(fp));
(*stat).variance[0] = atof(ReadLine(fp));
(*stat).type = atoi(ReadLine(fp));
filename[1] = ReadLine(fp);
fclose(fp);
}
switch (*Ksolver)
{
case 0:
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
{
/* (*gwnoise).vector[i]=atof(ReadLine(fp)); */
/* sscanf(ReadLine(fp)," %Lf %c",gwnoise.vector[i],&merde); */
fscanf(fp,"%lf",&tmp);
(*gwnoise).vector[i]= tmp;
}
fclose(fp);
}
}
break;
case 1:
file3=argv[3];
/* Ouverture du fichier de donn<6E>es de pression*/
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du champ de permeabilite K */
(*Kfield).vector = (double *) malloc(n * sizeof(double));
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file4);
exit(1);
}
else
{
for (i=0;i<n;i++)
(*Kfield).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
break;
case 2:
/* Ouverture du fichier de donn<6E>es de pression */
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
(*gwnoise).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
}
break;
}
return;
}

@ -19,6 +19,8 @@ void readfile_bin(string filename, struct realization_mod *realin)
int i; int i;
double prout; double prout;
printf("readfile_bin\n");
/*read the permeability realization*/ /*read the permeability realization*/

@ -70,6 +70,7 @@ void SetScannerString(scannerADT scanner, string str)
string ReadToken(scannerADT scanner) string ReadToken(scannerADT scanner)
{ {
printf("readtoken\n");
char ch; char ch;
string token; string token;
int start, finish; int start, finish;

@ -40,6 +40,8 @@ int GetInteger(void)
int value; int value;
char termch; char termch;
printf("getinteger\n");
while (TRUE) { while (TRUE) {
line = GetLine(); line = GetLine();
switch (sscanf(line, " %d %c", &value, &termch)) { switch (sscanf(line, " %d %c", &value, &termch)) {

@ -8,6 +8,8 @@ double spherical(double h)
{ {
double z; double z;
printf("spherical\n");
if (h >= 1.) { if (h >= 1.) {
z = 0.; z = 0.;
} else { } else {

@ -10,37 +10,20 @@
/* List of functions: */ /* List of functions: */
/* ------------------ */ /* ------------------ */
/* pgeneration, FFTPSim, FFTPressure, build_pressure, build_velocity,total_velocity, clean_real2 */ /* FFTPSim, FFTPressure, build_pressure, build_velocity, clean_real2 */
/*Functions */ /*Functions */
/*----------*/ /*----------*/
void pgeneration(int n[3],struct grid_mod grid,struct statistic_mod stat,struct vario_mod variogram,string filename[8],struct pressure_mod pression,struct realization_mod *Y,struct realization_mod *P,struct realization_mod *VX,struct realization_mod *VY,struct realization_mod *VZ, int solver);
void pgeneration2(int n[3],struct grid_mod grid,struct statistic_mod stat,struct vario_mod variogram,string filename[8],struct pressure_mod pression,struct realization_mod *Y,struct realization_mod *P,struct realization_mod *VX,struct realization_mod *VY,struct realization_mod *VZ, int solver, int format_file);
void FFTPSim(struct vario_mod variogram,struct statistic_mod stat,struct grid_mod grid,int n[3],struct realization_mod *realin,struct pressure_mod gradient,struct realization_mod *realout,struct realization_mod *realout2,struct realization_mod *realout3,struct realization_mod *realout4,struct realization_mod *realout5); void FFTPSim(struct vario_mod variogram,struct statistic_mod stat,struct grid_mod grid,int n[3],struct realization_mod *realin,struct pressure_mod gradient,struct realization_mod *realout,struct realization_mod *realout2,struct realization_mod *realout3,struct realization_mod *realout4,struct realization_mod *realout5);
//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);
void build_pressure(int n[3],struct grid_mod grid,struct pressure_mod gradient,double *realization,double *ireal,double *pressure,double *ipressure); void build_pressure(int n[3],struct grid_mod grid,struct pressure_mod gradient,double *realization,double *ireal,double *pressure,double *ipressure);
void build_velocity(int n[3],struct grid_mod grid,struct statistic_mod stat,struct pressure_mod gradient,double *realization,double *ireal,double *xvelocity,double *ixvelocity,int direction); void build_velocity(int n[3],struct grid_mod grid,struct statistic_mod stat,struct pressure_mod gradient,double *realization,double *ireal,double *xvelocity,double *ixvelocity,int direction);
/* total_velocity */
/* Build total velocity in one direction */
/* grid: structure defining the grid */
/* mean: permeability mean */
/* dgradient: macroscopic pressure gradient in wanted direction */
/* realout: structure defining a X velocity realization */
void total_velocity(struct grid_mod grid,double mean,int direction,struct pressure_mod gradient,struct realization_mod *realout);
void normAxes(double *vec, double *normed); void normAxes(double *vec, double *normed);
void waveVectorCompute1D(int n,double *vec); void waveVectorCompute1D(int n,double *vec);
void waveVectorCompute3D(int nX,int nY, int nZ, /*float dX, float dY, float dZ,*/ double nDir[3], double *waveVect);
void mat_vec(double *C, double *x, double *b, int n); void mat_vec(double *C, double *x, double *b, int n);

@ -12,7 +12,7 @@
/* List of functions: */ /* List of functions: */
/* ------------------ */ /* ------------------ */
/* writefile,writefile_bin,readfile_bin,inputdata,inputfiledata,readdata,debuginput */ /* readfile_bin,inputdata,inputfiledata,readdata,debuginput */
/* testmemory, testopenfile */ /* testmemory, testopenfile */
@ -52,27 +52,6 @@ void readdata3(long *seed,struct grid_mod *grid,string filename[8],struct vario_
void readfile_bin(string filename, struct realization_mod *realin); void readfile_bin(string filename, struct realization_mod *realin);
/* Writefile */
/* */
/* write in the file "filename" the vector values of a */
/* realization_mod variable */
/* filename: explicit */
/* realin: structure defining a realization */
void writefile( string filename, struct realization_mod *realin);
/* Writefile_bin */
/* */
/* write in the file "filename" the vector values of a */
/* realization_mod variable */
/* filename: explicit */
/* realin: structure defining a realization */
void writefile_bin( string filename, struct realization_mod *realin);
/* DebugInput */ /* DebugInput */
/* */ /* */
/* Display the input data */ /* Display the input data */

@ -1,50 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdlib.h>
#include "geostat.h"
#include "pressure.h"
/* total_velocity */
/* Build total velocity */
/* grid: structure defining the grid */
/* mean: permeability mean */
/* dgradient: macroscopic pressure gradient in wanted direction */
/* realout: structure defining a X velocity realization */
void total_velocity(struct grid_mod grid,double mean,int direction,struct pressure_mod gradient,struct realization_mod *realout)
{
int i,j,k,maille0,maille1;
double temp,grad;
switch(direction)
{
case 1:
grad = gradient.x/(grid.NX*grid.DX);
break;
case 2:
grad = gradient.y/(grid.NY*grid.DY);/* *grid.NY*grid.DY; */
break;
case 3:
grad = gradient.z/(grid.NZ*grid.DZ); /* *grid.NZ*grid.DZ; */
break;
default :
printf("build_velocity.c: wrong velocity direction!!! direction: %d\n",direction);
break;
}
/* x velocity reconstruction */
for ( k = 0; k < grid.NZ; k++) {
for (j = 0; j < grid.NY; j++) {
for (i = 0; i < grid.NX; i++) {
maille1 = i+(j+k*grid.NY)*grid.NX;
temp=mean*grad+(*realout).vector[maille1];
/* temp=mean*grad; */
(*realout).vector[maille1]=temp;
}
}
}
return;
}

@ -1,156 +0,0 @@
//#include <fstream.h>
//#include <iostream>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
//using namespace std;
/*Private functions */
void waveVectorCompute1D(int n,double *vec);
void waveVectorCompute3D(int nX,int nY, int nZ, /*double dX, double dY, double dZ,*/ double nDir[3], double *waveVect) {
int nTot;
double *vecX,*vecY,*vecZ;
double *waveVect3DX, *waveVect3DY, *waveVect3DZ;
int i, j, k, maille;
nTot = nX*nY*nZ;
// printf("nX = %d, nY = %d, nZ = %d, nTot = %d\n",nX,nY,nZ,nTot);
// printf("Entering waveVectorCompute3D\n");
/*Memory allocation */
waveVect3DX = (double *)malloc(nTot * sizeof(double));
if (waveVect3DX == NULL) {
printf("waveVectCompute.cpp : No memory available for waveVect3DX\n");
return;
}
waveVect3DY = (double *)malloc(nTot * sizeof(double));
if (waveVect3DY == NULL) {
printf("waveVectCompute.cpp : No memory available for waveVect3DY\n");
return;
}
waveVect3DZ = (double *)malloc(nTot * sizeof(double));
if (waveVect3DZ == NULL) {
printf("waveVectCompute.cpp : No memory available for waveVect3DZ\n");
return;
}
vecX = (double *)malloc(nX * sizeof(double));
if (vecX == NULL) {
printf("waveVectCompute.cpp : No memory available for vecX\n");
return;
}
vecY = (double *)malloc(nY * sizeof(double));
if (vecY == NULL) {
printf("waveVectCompute.cpp : No memory available for vecY\n");
return;
}
vecZ = (double *)malloc(nZ * sizeof(double));
if (vecZ == NULL) {
printf("waveVectCompute.cpp : No memory available for vecZ\n");
return;
}
// printf("memory allocation done.\n");
waveVectorCompute1D(nX,vecX);
waveVectorCompute1D(nY,vecY);
waveVectorCompute1D(nZ,vecZ);
// printf("waveVectorCompute1D: done!\n");
for(k = 0; k < nZ; k++) {
// printf("k=%d\n",k);
for(j = 0; j < nY; j++) {
// printf("j=%d: ",j);
for(i = 0; i < nX; i++) {
maille = i + (j + (k)*nY)*nX;
// waveVect3DX[maille] = vecX[i]/(nX*dX);
// waveVect3DY[maille] = vecY[j]/(nY*dY);
// waveVect3DZ[maille] = vecZ[k]/(nZ*dZ);
waveVect3DX[maille] = vecX[i];
waveVect3DY[maille] = vecY[j];
waveVect3DZ[maille] = vecZ[k];
// printf("i=%d: %f ",i,vecZ[k]);
}
// printf("\n");
}
}
// printf("waveVector3DX, Y and Z rearanged\n");
free(vecX);
free(vecY);
free(vecZ);
if (waveVect == NULL) {
printf("allocate memory for waveVect\n");
waveVect = (double *) malloc((nTot+1)*sizeof(double));
if (waveVect == NULL) {
printf("waveVectCompute.cpp : No memory available for waveVect\n");
return;
}
printf("after allocate memory for waveVect\n");
}
for (i=1;i<=nTot;i++) {
waveVect[i] = nDir[0]*waveVect3DX[i-1] + nDir[1]*waveVect3DY[i-1] + nDir[2]*waveVect3DZ[i-1];
// printf("waveVect[%d] = %f\n",i,waveVect[i]);
}
// printf("waveVector rearanged\n");
free(waveVect3DX);
free(waveVect3DY);
free(waveVect3DZ);
}
void waveVectorCompute1D(int n,double *vec){
int midPoint,k;
if(ceil(n/2) - floor(n/2) < 1.) {
// printf("coucou\n");
/*n is even */
midPoint = (int) floor(n/2);
vec[midPoint] = (double) midPoint;
} else {
/*n is odd */
midPoint = (int) floor(n/2)-1;
vec[midPoint] = (double) midPoint+1;
}
for (k=1;k<midPoint;k++) {
vec[k] = (double) k;
vec[n-k] = (double) -(k);
}
vec[0] = (double) 0;
}
/*int main() {
double *vecX;
int k;
vecX = (double *)malloc(10 * sizeof(double));
if (vecX == NULL) {
printf("waveVectCompute.cpp : No memory available for vecX\n");
return(0);
}
printf("avant\n");
waveVectorCompute1D(10,vecX);
printf("apres\n");
ofstream vec;
vec.open("waveVect1D.pol");
for (k=0;k<10;k++)
vec << vecX[k] << "\n";
vec.close();
return(1);
}*/

@ -1,32 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include "genlib.h"
#include "geostat.h"
/*writefile */
/* write in the file "filename" the vector values of a */
/* realization_mod variable */
/* filename: explicit */
/* realin: structure defining a realization */
void writefile(string filename, struct realization_mod *realin)
{
FILE *fp;
int i;
/* string filename;*/
/*struct realization_mod *realin;*/
/*save the permeability realization*/
fp = fopen(filename, "w");
/* printf("writefile.c : (*realin).vector[0] %f\n",(*realin).vector[0]); */
/* (*realin).vector[0]=1.1; */
for (i=0;i<(*realin).n;i++)
fprintf(fp,"%15.10f\n",(*realin).vector[i]);
fclose(fp);
return;
}

@ -1,33 +0,0 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include "genlib.h"
#include "geostat.h"
/*writefile */
/* write in the file "filename" the vector values of a */
/* realization_mod variable */
/* filename: explicit */
/* realin: structure defining a realization */
void writefile_bin(string filename, struct realization_mod *realin)
{
FILE *fp;
int i;
double *prout;
/*save the permeability realization*/
fp = fopen(filename, "w");
for (i=0;i<(*realin).n;i++)
{
prout=(*realin).vector;
fwrite(&prout[i],sizeof(double),1,fp);
}
fclose(fp);
return;
}

@ -39,23 +39,15 @@ module_FFTMA = Extension(
"./lib_src/prebuild_gwn.c", "./lib_src/prebuild_gwn.c",
"./lib_src/build_real.c", "./lib_src/build_real.c",
"./lib_src/clean_real.c", "./lib_src/clean_real.c",
"./lib_src/pgeneration.c",
"./lib_src/pgeneration2.c",
"./lib_src/build_pressure.c", "./lib_src/build_pressure.c",
"./lib_src/build_velocity.c", "./lib_src/build_velocity.c",
"./lib_src/total_velocity.c",
"./lib_src/waveVectorCompute3D.c",
"./lib_src/mat_vec.c", "./lib_src/mat_vec.c",
"./lib_src/inputdata.c", "./lib_src/inputdata.c",
"./lib_src/inputfiledata.c", "./lib_src/inputfiledata.c",
"./lib_src/debuginput.c", "./lib_src/debuginput.c",
"./lib_src/readdata.c",
"./lib_src/readfile_bin.c", "./lib_src/readfile_bin.c",
"./lib_src/writefile.c",
"./lib_src/writefile_bin.c",
"./lib_src/testmemory.c", "./lib_src/testmemory.c",
"./lib_src/testopenfile.c", "./lib_src/testopenfile.c",
"./lib_src/readdata3.c",
"./lib_src/genlib.c", "./lib_src/genlib.c",
], ],
) )

Loading…
Cancel
Save