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.
217 lines
5.3 KiB
C
217 lines
5.3 KiB
C
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "condor.h"
|
|
#include "geostat.h"
|
|
|
|
/* Private functions */
|
|
void normAxes(double *vec, double *normed);
|
|
|
|
|
|
void derivReal(struct realization_mod *Z, struct realization_mod *dZ, double *dir, struct grid_mod *grid, struct vario_mod vario) {
|
|
|
|
int n[3],i,j,k,maille,extMaille;
|
|
int NTOT,ntot,NMAX,nmax,NDIM;
|
|
// int NXYZ,nxyz;
|
|
double nDir[3];
|
|
double *table,*workr,*worki,*realization,*waveVect;
|
|
|
|
|
|
int Ngrid;
|
|
double tmp;
|
|
double *ExtendedWaveVect;
|
|
|
|
/* Test the input real*/
|
|
/* if ((*Z).code != 1) { */
|
|
/* printf("Realization should be Standard Normal\n"); */
|
|
/* return; */
|
|
/* } */
|
|
|
|
printf("grid.Nx = %d\n",(*grid).NX);
|
|
printf("grid.Ny = %d\n",(*grid).NY);
|
|
printf("grid.Nz = %d\n",(*grid).NZ);
|
|
|
|
printf("vario.Nvario = %d\n",vario.Nvario);
|
|
for(i=0; i<vario.Nvario;i++) {
|
|
printf("Component %d:\n",i);
|
|
printf("Type: %d\n",vario.vario[i]);
|
|
printf("Exponent: %f\n",vario.alpha[i]);
|
|
printf("Anisotropy axes:");
|
|
for(j=0; j<6; j++) {
|
|
printf(" %f",vario.ap[6*i+j]);
|
|
}
|
|
printf("\nCorrelation length:\n");
|
|
for(j=0;j<3;j++) {
|
|
printf("axe%d :%f\n",j+1,vario.scf[3*i+j]);
|
|
}
|
|
printf("Variance: %f\n",vario.var[i]);
|
|
}
|
|
|
|
/* covariance axis normalisation */
|
|
axes(vario.ap,vario.scf,vario.Nvario);
|
|
|
|
n[0]=0;
|
|
n[1]=0;
|
|
n[2]=0;
|
|
|
|
/* pseudo-grid definition */
|
|
cgrid(vario,*grid,n);
|
|
|
|
printf("n[0] = %d\n", n[0]);
|
|
printf("n[1] = %d\n", n[1]);
|
|
printf("n[2] = %d\n", n[2]);
|
|
|
|
/* constants definition */
|
|
NTOT = n[0]*n[1]*n[2];
|
|
ntot = NTOT + 1;
|
|
NDIM = 3;
|
|
NMAX = n[0];
|
|
|
|
Ngrid = (*grid).NX*(*grid).NY*(*grid).NZ;
|
|
|
|
for (i=1;i<3;i++) {
|
|
if (n[i] > NMAX) NMAX = n[i];
|
|
if (n[i] == 1) NDIM = NDIM-1;
|
|
}
|
|
nmax = NMAX+1;
|
|
|
|
printf("NTOT = %d, ntot = %d, NMAX = %d\n",NTOT,ntot,NMAX);
|
|
|
|
/* wave vector computation */
|
|
normAxes(dir,nDir);
|
|
printf("Derivation direction (normed) %f %f %f\n",nDir[0],nDir[1],nDir[2]);
|
|
waveVect = (double *) malloc(Ngrid*sizeof(double));
|
|
if (waveVect == NULL) {
|
|
printf("waveVectCompute.cpp : No memory available for waveVect\n");
|
|
return;
|
|
}
|
|
waveVectorCompute3D((*grid).NX,(*grid).NY,(*grid).NZ,nDir,waveVect);
|
|
|
|
/* memory allocation */
|
|
table = (double *) malloc(ntot * sizeof(double));
|
|
if (table == NULL) {
|
|
printf("derivReal.cpp: No memory availble for table\n");
|
|
return;
|
|
}
|
|
|
|
realization = (double *) malloc(ntot * sizeof(double));
|
|
if (realization == NULL) {
|
|
printf("derivReal.cpp: No memory availble for realization\n");
|
|
return;
|
|
}
|
|
|
|
ExtendedWaveVect = (double *) malloc(ntot * sizeof(double));
|
|
if (ExtendedWaveVect == NULL) {
|
|
printf("derivReal.cpp: No memory availble for realization\n");
|
|
return;
|
|
}
|
|
|
|
workr = (double *) malloc(nmax * sizeof(double));
|
|
if (workr == NULL) {
|
|
printf("derivReal.cpp: No memory available for workr\n");
|
|
return;
|
|
}
|
|
|
|
worki = (double *) malloc(nmax * sizeof(double));
|
|
if (worki == NULL) {
|
|
printf("derivReal.cpp: No memory available for worki\n");
|
|
return;
|
|
}
|
|
|
|
extMaille =0;
|
|
/* organization of the extended realization */
|
|
for (k=1;k<=n[2];k++) {
|
|
for (j=1;j<=n[1];j++) {
|
|
for (i=1;i<=n[0];i++) {
|
|
extMaille = i + ((j-1) + (((k-1) * n[1]) * n[0]));
|
|
if (i <= (*grid).NX && j <= (*grid).NY && k <= (*grid).NZ) {
|
|
maille = i-1 + ((j-1) + ((k-1) * (*grid).NY) * (*grid).NX);
|
|
realization[extMaille] = (*Z).vector[maille];
|
|
ExtendedWaveVect[extMaille] = waveVect[maille];
|
|
} else {
|
|
realization[extMaille] = 0.0;
|
|
ExtendedWaveVect[extMaille] = 0.0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* forward fourier transform of the realization */
|
|
fourt(realization,table,n,NDIM,1,0,workr,worki);
|
|
FILE *wave;
|
|
wave = fopen("/home/irsrvshare1/R03/UPS_FLEX/waveVector.eas","w");
|
|
|
|
for (i=1;i<ntot;i++) {
|
|
tmp = realization[i];
|
|
realization[i] = - ExtendedWaveVect[i]*table[i];
|
|
table[i] = - ExtendedWaveVect[i]*tmp;
|
|
fprintf(wave,"%f\n", ExtendedWaveVect[i]);
|
|
}
|
|
fclose(wave);
|
|
free(waveVect);
|
|
|
|
/* backward fourier tranform */
|
|
fourt(realization,table,n,NDIM,0,1,workr,worki);
|
|
|
|
/* free the memory */
|
|
free(table);
|
|
free(workr);
|
|
free(worki);
|
|
|
|
printf("after second fourt \n");
|
|
|
|
(*dZ).n = (*Z).n;
|
|
(*dZ).code = (*Z).code;
|
|
(*dZ).vector = (double *) malloc(Ngrid*sizeof(double));
|
|
|
|
FILE *real;
|
|
FILE *derReal;
|
|
|
|
real = fopen("/home/irsrvshare1/R03/UPS_FLEX/realization.eas","w");
|
|
derReal = fopen("/home/irsrvshare1/R03/UPS_FLEX/derivative.eas","w");
|
|
|
|
printf("before saving file \n");
|
|
|
|
for(k=1;k<=(*grid).NZ;k++) {
|
|
for(j=1;j<=(*grid).NY;j++) {
|
|
for(i=1;i<=(*grid).NX;i++) {
|
|
extMaille = i+(j-1+(k-1)*n[1])*n[0];
|
|
maille = i-1+(j-1+(k-1)*(*grid).NY)*(*grid).NX;
|
|
(*dZ).vector[maille] = realization[extMaille]/(double)NTOT;
|
|
// printf("Z[%d] = %f, dZ[%d] = %f\n",maille,(*Z).vector[maille],maille,(*dZ).vector[maille]);
|
|
fprintf(real,"%f\n",(*Z).vector[maille]);
|
|
fprintf(derReal,"%f\n",(*dZ).vector[maille]);
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("after saving file \n");
|
|
|
|
fclose(real);
|
|
fclose(derReal);
|
|
free(realization);
|
|
}
|
|
|
|
|
|
|
|
void normAxes(double *vec, double *normed) {
|
|
|
|
int i;
|
|
double r;
|
|
|
|
r = sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
|
|
|
|
if (normed == NULL) {
|
|
normed = (double *)malloc(3*sizeof(double));
|
|
if (normed == NULL) {
|
|
printf("derivReal.c: No memory available for normed\n");
|
|
}
|
|
}
|
|
|
|
for (i=0;i<3;i++) {
|
|
normed[i] = vec[i]/r;
|
|
}
|
|
|
|
}
|
|
|