// C++ tests go here int test1(){ int N = 8; vector< Point > A(N, vector<double>(3,0)); A[0][0] = 200; A[0][1] = 300; A[0][2] = 400; A[1][0] = 100; A[1][1] = 200; A[1][2] = 300; A[2][0] = 600; A[2][1] = 100; A[2][2] = 500; A[3][0] = 100; A[3][1] = 100; A[3][2] = 300; A[4][0] = 700; A[4][1] = 50; A[4][2] = 300; A[5][0] = 700; A[5][1] = 110; A[5][2] = 500; A[6][0] = 699; A[6][1] = 51; A[6][2] = 301; A[7][0] = 701; A[7][1] = 50; A[7][2] = 305; KDTree* tree = new KDTree( A ); vector<double> Xq( 3, 0 ); Xq[0] = 201; Xq[1] = 301; Xq[2] = 400; cout << "In test\n"; //return 0; // for (int i=0; i < N; i++) // cout << "expected: " << i << " obtained: " << tree -> closest_point( A[i] ) << endl; cout << "%.2f\n" << tree->kde(Xq); return 0; }
bool PdfTransfer::NDPdfTransfer(float *input, float *palette, float **rotations) { clock_t start, end; FILE *fp = fopen("time.txt", "w"); unsigned long int var_time = 0; float *finalPic = new float[_projections * _inputSize]; for (unsigned int i = 0; i < _iterations; ++i) { start = clock(); float * ptrRotation = rotations[i]; assert(ptrRotation); float *inputRotation = new float[_projections * _inputSize]; float *paletteRotation = new float[_projections * _paletteSize]; _matrixModule->matrix_multiply(ptrRotation, _projections, NUM_CHANNELS, input, NUM_CHANNELS, _inputSize, inputRotation, _projections, _inputSize); #ifdef DEBUG if (!i) { printMatrix(ptrRotation, _projections, NUM_CHANNELS, "ptrRotation", _height, _width); printMatrix(input, NUM_CHANNELS, _inputSize, "input", _height, _width); printMatrix(inputRotation, _projections, _inputSize, "inputRotation", _height, _width); } #endif _matrixModule->matrix_multiply(ptrRotation, _projections, NUM_CHANNELS, palette, NUM_CHANNELS, _paletteSize, paletteRotation, _projections, _paletteSize); #ifdef DEBUG if (!i) { printMatrix(palette, NUM_CHANNELS, _paletteSize, "palette", _height, _width); printMatrix(paletteRotation, _projections, _paletteSize, "paletteRotation", _height, _width); } #endif Histogram ** histogramsInput = new Histogram*[_projections]; Histogram ** histogramsPalette = new Histogram*[_projections]; //Step1: Creation of Histograms CreateHistograms(inputRotation, _inputSize, paletteRotation, _paletteSize, _projections, histogramsInput, histogramsPalette); #ifdef DEBUG printHistogr(histogramsInput, i); #endif std::vector<float> *inter = new std::vector<float>[_projections]; for (unsigned int j = 0; j < _projections; ++j) { std::vector<float> ptr = SinglePdfTransfer(histogramsInput[j], histogramsPalette[j]); std::vector<float> newPtr(ptr.begin() + 1, ptr.end() - 1); float scale = bin_count / (histogramsInput[j]->GetOverallMax() - histogramsInput[j]->GetOverallMin()); //populate X points before interpolation std::vector<float> X(newPtr.size()); for (unsigned int k = 0; k < X.size(); ++k) { X[k] = (float) k; } std::vector<float> Xq(_inputSize); unsigned int itr = 0; for (unsigned k = j * _inputSize; k < (j + 1) * _inputSize; ++k, ++itr) { Xq[itr] = inputRotation[k]; Xq[itr] = (Xq[itr] - histogramsInput[j]->GetOverallMin()) * scale; } inter[j] = linearInterpolation(X, newPtr, Xq); for (unsigned int k = 0; k < inter[j].size(); ++k) { inter[j][k] = inter[j][k] / scale + histogramsInput[j]->GetOverallMin(); inter[j][k] -= matrix_access(inputRotation, _projections, _inputSize, j, k); matrix_access(finalPic, _projections, _inputSize, j, k) = inter[j][k]; } } #ifdef DEBUG char filename2[10]; sprintf(filename2, "finalPic%d", i); printMatrix(finalPic, _projections, _inputSize, filename2, _height, _width); #endif //resolve linear system of ptrRotation*x = inter _matrixModule->matrix_inverse(ptrRotation, _projections, NUM_CHANNELS); float *aux = new float[ _projections * _inputSize ]; _matrixModule->matrix_multiply(ptrRotation, _projections, NUM_CHANNELS, finalPic, _projections, _inputSize, aux, _projections, _inputSize); _matrixModule->matrix_add(input, aux, input, _projections, _inputSize); #ifdef DEBUG //if(!i) //{ char filename[10]; sprintf(filename, "iter%d", i); printMatrix(input, _projections, _inputSize, filename, _height, _width); //} #endif end = clock(); var_time = (end - start) / (CLOCKS_PER_SEC); fprintf(fp, "It took %lu seconds to complete %d iteration\n", var_time, i); //freeing memory delete [] inputRotation; delete [] paletteRotation; } //freeing heap delete [] finalPic; //used for logging time fclose(fp); return true; }
void Foam::SprayCloud<CloudType>::motion(TrackData& td) { const scalar dt = this->solution().trackTime(); td.part() = TrackData::tpLinearTrack; CloudType::move(td, dt); this->updateCellOccupancy(); if (stochasticCollision().active()) { const liquidMixtureProperties& liqMix = this->composition().liquids(); label i = 0; forAllIter(typename SprayCloud<CloudType>, *this, iter) { label j = 0; forAllIter(typename SprayCloud<CloudType>, *this, jter) { if (j > i) { parcelType& p = iter(); scalar Vi = this->mesh().V()[p.cell()]; scalarField X1(liqMix.X(p.Y())); scalar sigma1 = liqMix.sigma(p.pc(), p.T(), X1); scalar mp = p.mass()*p.nParticle(); parcelType& q = jter(); scalar Vj = this->mesh().V()[q.cell()]; scalarField X2(liqMix.X(q.Y())); scalar sigma2 = liqMix.sigma(q.pc(), q.T(), X2); scalar mq = q.mass()*q.nParticle(); bool updateProperties = stochasticCollision().update ( dt, this->rndGen(), p.position(), mp, p.d(), p.nParticle(), p.U(), p.rho(), p.T(), p.Y(), sigma1, p.cell(), Vi, q.position(), mq, q.d(), q.nParticle(), q.U(), q.rho(), q.T(), q.Y(), sigma2, q.cell(), Vj ); // for coalescence we need to update the density and // the diameter cause of the temp/conc/mass-change if (updateProperties) { if (mp > VSMALL) { scalarField Xp(liqMix.X(p.Y())); p.rho() = liqMix.rho(p.pc(), p.T(), Xp); p.Cp() = liqMix.Cp(p.pc(), p.T(), Xp); p.d() = cbrt ( 6.0*mp /( p.nParticle() *p.rho() *constant::mathematical::pi ) ); } if (mq > VSMALL) { scalarField Xq(liqMix.X(q.Y())); q.rho() = liqMix.rho(q.pc(), q.T(), Xq); q.Cp() = liqMix.Cp(q.pc(), q.T(), Xq); q.d() = cbrt ( 6.0*mq /( q.nParticle() *q.rho() *constant::mathematical::pi ) ); } } } j++; } i++; } // remove coalesced particles (diameter set to 0) forAllIter(typename SprayCloud<CloudType>, *this, iter) { parcelType& p = iter(); if (p.mass() < VSMALL) { this->deleteParticle(p); } } } }