void ModelGeneral::Complete4DBackground(const int nx, const int ny, const int nz, const int nxPad, const int nyPad, const int nzPad,NRLib::Vector &initial_mean,NRLib::Matrix &initial_cov) { // Static grids (3 + 6) are set in process4DBackground. // Dynamic grids (3 + 6 + 9) are set here. FFTGrid * dynamicVp; FFTGrid * dynamicVs; FFTGrid * dynamicRho; FFTGrid * dynamicVpVp; FFTGrid *dynamicVpVs; FFTGrid *dynamicVpRho; FFTGrid *dynamicVsVs; FFTGrid *dynamicVsRho; FFTGrid *dynamicRhoRho; FFTGrid *staticDynamicVpVp; FFTGrid *staticDynamicVpVs; FFTGrid *staticDynamicVpRho; FFTGrid *staticDynamicVsVp; FFTGrid *staticDynamicVsVs; FFTGrid *staticDynamicVsRho; FFTGrid *staticDynamicRhoVp; FFTGrid *staticDynamicRhoVs; FFTGrid *staticDynamicRhoRho; dynamicVp = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVp->fillInConstant(0.0); dynamicVp->setType(FFTGrid::PARAMETER); dynamicVs = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVs->fillInConstant(0.0); dynamicVs->setType(FFTGrid::PARAMETER); dynamicRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicRho->fillInConstant(0.0); dynamicRho->setType(FFTGrid::PARAMETER); state4d_.setDynamicMu(dynamicVp, dynamicVs, dynamicRho); initial_mean=state4d_.GetFullMean000(); dynamicVpVp = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVpVp->fillInConstant(0.0); dynamicVpVp->setType(FFTGrid::COVARIANCE); dynamicVpVs = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVpVs->fillInConstant(0.0); dynamicVpVs->setType(FFTGrid::COVARIANCE); dynamicVpRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVpRho->fillInConstant(0.0); dynamicVpRho->setType(FFTGrid::COVARIANCE); dynamicVsVs = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVsVs->fillInConstant(0.0); dynamicVsVs->setType(FFTGrid::COVARIANCE); dynamicVsRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicVsRho->fillInConstant(0.0); dynamicVsRho->setType(FFTGrid::COVARIANCE); dynamicRhoRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); dynamicRhoRho->fillInConstant(0.0); dynamicRhoRho->setType(FFTGrid::COVARIANCE); state4d_.setDynamicSigma(dynamicVpVp, dynamicVpVs, dynamicVpRho, dynamicVsVs, dynamicVsRho, dynamicRhoRho); staticDynamicVpVp = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicVpVp->fillInConstant(0.0); staticDynamicVpVp->setType(FFTGrid::COVARIANCE); staticDynamicVpVs = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicVpVs->fillInConstant(0.0); staticDynamicVpVs->setType(FFTGrid::COVARIANCE); staticDynamicVpRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicVpRho->fillInConstant(0.0); staticDynamicVpRho->setType(FFTGrid::COVARIANCE); staticDynamicVsVp = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicVsVp->fillInConstant(0.0); staticDynamicVsVp->setType(FFTGrid::COVARIANCE); staticDynamicVsVs = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicVsVs->fillInConstant(0.0); staticDynamicVsVs->setType(FFTGrid::COVARIANCE); staticDynamicVsRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicVsRho->fillInConstant(0.0); staticDynamicVsRho->setType(FFTGrid::COVARIANCE); staticDynamicRhoVp = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicRhoVp->fillInConstant(0.0); staticDynamicRhoVp->setType(FFTGrid::COVARIANCE); staticDynamicRhoVs = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicRhoVs->fillInConstant(0.0); staticDynamicRhoVs->setType(FFTGrid::COVARIANCE); staticDynamicRhoRho = ModelGeneral::CreateFFTGrid(nx, ny, nz, nxPad, nyPad, nzPad, false); staticDynamicRhoRho->fillInConstant(0.0); staticDynamicRhoRho->setType(FFTGrid::COVARIANCE); state4d_.setStaticDynamicSigma(staticDynamicVpVp, staticDynamicVpVs, staticDynamicVpRho, staticDynamicVsVp, staticDynamicVsVs, staticDynamicVsRho, staticDynamicRhoVp, staticDynamicRhoVs, staticDynamicRhoRho); initial_cov=state4d_.GetFullCov(); state4d_.FFT(); state4d_.setRelativeGridBase(nx, ny, nz, nxPad, nyPad, nzPad); }
PosteriorElasticPDF3D::PosteriorElasticPDF3D(const std::vector<double> & d1, // first dimension of data points const std::vector<double> & d2, // second dimension of data points const std::vector<double> & d3, // third dimension of data points const std::vector<int> & t1, // trend data points const std::vector<std::vector<double> > & v, // Transformation of elastic variables from 3D to 2D const double *const*const sigma, // Gaussian smoothing kernel in 2D int n1, // resolution of density grid in elastic dimension 1 int n2, // resolution of density grid in elastic dimension 2 int n3, // resolution of density grid in the trend dimension double d1_min, double d1_max, double d2_min, double d2_max, double t1_min, double t1_max, int ind) : n1_(n1), n2_(n2), n3_(n3), x_min_(d1_min), x_max_(d1_max), y_min_(d2_min), y_max_(d2_max), z_min_(t1_min), z_max_(t1_max) { // We assume that the input vectors are of the same length if (d1.size()!=d2.size() || d2.size()!=d3.size() || d3.size()!=t1.size()) throw NRLib::Exception("Facies probabilities: Size of input vectors do not match."); if (v.size()>2 || static_cast<int>(v[0].size()) != 3 || static_cast<int>(v[1].size()) != 3) throw NRLib::Exception("Facies probabilities: Transformation matrix v does not have the right dimensions"); v1_.resize(3); v2_.resize(3); for(int i=0; i<3; i++) { v1_[i] = v[0][i]; v2_[i] = v[1][i]; } int dim = static_cast<int>(d1.size()); std::vector<std::vector<double> > x(2); x[0].resize(dim); x[1].resize(dim); //computes x and y from d1, d2 and d3 CalculateTransform2D(d1, d2, d3, x, v); histogram_ = new FFTGrid(n1_, n2_, n3_, n1_, n2_, n3_); histogram_->createRealGrid(false); int rnxp = histogram_->getRNxp(); histogram_->setType(FFTGrid::PARAMETER); histogram_->setAccessMode(FFTGrid::WRITE); for(int l=0; l<n3_; l++) { for(int k=0; k<n2_; k++) { for(int j=0; j<rnxp; j++) histogram_->setNextReal(0.0f); } } histogram_->endAccess(); // Spacing variables in the density grid dx_ = (x_max_ - x_min_)/n1_; dy_ = (y_max_ - y_min_)/n2_; dz_ = (z_max_ - z_min_)/n3_; // Go through data points and place in bins in histogram for (int i = 0; i < dim; i++) { //volume->getIndexes(d1[i], d2[i], d3[i], i_tmp, j_tmp, k_tmp); int i_tmp = static_cast<int>(floor((x[0][i]-x_min_)/dx_)); int j_tmp = static_cast<int>(floor((x[1][i]-y_min_)/dy_)); int k_tmp = t1[i]; // Counting data points in index (i,j,k) histogram_->setAccessMode(FFTGrid::RANDOMACCESS); histogram_->setRealValue(i_tmp, j_tmp, k_tmp, histogram_->getRealValue(i_tmp,j_tmp,k_tmp) + 1.0f); histogram_->endAccess(); } //multiply by normalizing constant for the PDF - dim is the total number of entries histogram_->setAccessMode(FFTGrid::READANDWRITE); histogram_->multiplyByScalar(float(1.0f/dim)); histogram_->endAccess(); if(ModelSettings::getDebugLevel() >= 1) { std::string baseName = "Hist_" + NRLib::ToString(ind) + IO::SuffixAsciiFiles(); std::string fileName = IO::makeFullFileName(IO::PathToDebug(), baseName); histogram_->writeAsciiFile(fileName); } histogram_->fftInPlace(); double **sigma_tmp = new double *[2]; for (int i=0; i<2; i++) { sigma_tmp[i] = new double[2]; } for(int i=0; i<2; i++) { for(int j=0; j<2; j++) sigma_tmp[i][j] = sigma[i][j]; } // Matrix inversion of the covariance matrix sigma // SINGULAR MATRIX ?! double **sigma_inv = new double *[2]; for(int i=0; i<2; i++) sigma_inv[i] = new double [2]; InvertSquareMatrix(sigma_tmp,sigma_inv,2); FFTGrid *smoother = new FFTGrid(n1, n2, n3, n1, n2, n3); smoother->createRealGrid(false); smoother->setType(FFTGrid::PARAMETER); smoother->setAccessMode(FFTGrid::WRITE); for(int l=0; l<n3_; l++) { for(int k=0; k<n2_; k++) { for(int j=0; j<static_cast<int>(smoother->getRNxp()); j++) smoother->setNextReal(0.0f); } } smoother->endAccess(); //SetupSmoothingGaussian2D(smoother, sigma_inv, n1, n2, n3, dx_, dy_); if(ModelSettings::getDebugLevel() >= 1) { std::string baseName = "Smoother" + IO::SuffixAsciiFiles(); std::string fileName = IO::makeFullFileName(IO::PathToDebug(), baseName); smoother->writeAsciiFile(fileName); } // Carry out multiplication of the smoother with the density grid (histogram) in the Fourier domain smoother->fftInPlace(); histogram_->multiply(smoother); histogram_->invFFTInPlace(); histogram_->multiplyByScalar(sqrt(float(n1_*n2_*n3_))); histogram_->endAccess(); delete smoother; for(int i=0; i<2; i++) { delete [] sigma_inv[i]; delete [] sigma_tmp[i]; } delete [] sigma_tmp; delete [] sigma_inv; }