void fluid_detection::ghostProcess(fluid_particle* i, fluid_particle* j) { size_t hash = 0; double QSq = 0.0; double df = 0.0; double dg = 0.0; VEC3D j_pos = j->position(); VEC3D k_pos, posDif, mp; VEC3I start = cellPos(j_pos - sph->kernelSupportRadius()); VEC3I end = cellPos(j_pos + sph->kernelSupportRadius()); if (sph->dimension() == DIM2){ for (cellJ.y = loopStart.y; cellJ.y <= loopEnd.y; cellJ.y++){ for (cellJ.x = loopStart.x; cellJ.x <= loopEnd.x; cellJ.x++){ hash = cellHash(cellJ); size_t cs = cell_start[hash]; if (cs != 0xffffffff){ for (VEC2UI particleJ = hashes[cs]; hash == particleJ.x; particleJ = hashes[++cs]){ fluid_particle *k = sph->particle(particleJ.y); if (i == k) continue; k_pos = k->position();// : parj->auxPosition(); posDif = j_pos - k_pos; QSq = posDif.dot() * sph->smoothingKernel().h_inv_sq; if (QSq >= sph->kernelFunction()->KernelSupprotSq()) continue; //i->Ghosts()-> //i->Ghosts()-> //std::map<size_t, fluid_particle::ghostParticleInfo>::iterator it = i->Ghosts()->count(1000000); // if (i->Ghosts()->find(particleJ.y)){ // continue; // } fluid_particle::ghostParticleInfo ng; ng.baseIdx = particleJ.y; VEC3D lp1 = j_pos - j->tangent(); VEC3D lp2 = j_pos + j->tangent(); // if (!j_pos.x && !j_pos.y) // j_pos.x = 0.f; ng.pos = utils::calcMirrorPosition2Line(lp1, lp2, k_pos, mp); mp = 0.5 * (k_pos + ng.pos);// VEC3D(0.5f*(k_pos.x + ng.pos.x), 0.5f * (k_pos.y + ng.pos.y), 0.f); ng.df = (k_pos - mp).length(); ng.dg = (ng.pos - mp).length(); ng.press = k->pressure(); ng.W = sph->kernelFunction()->sphKernel(QSq); ng.gradW = sph->kernelFunction()->sphKernelGrad(QSq, posDif); i->Ghosts()->insert(std::pair<size_t, fluid_particle::ghostParticleInfo>(ng.baseIdx, ng));// = ng; //i->Ghosts()->push_back(ng); //r = fpos.y - ng.pos.y;//(ng.auxPosition() - mp).dot(VEC3D(0.f, -1.f, 0.f)); //ng.setPressure(parj->pressure() + sph->density()*sph->gravity().length()*r); } } } } } }
void TCacheResource::release2(const TRect &rect) { //DIAGNOSTICS_NUMBEREDSTRSET(prefix + QString::number((UINT) this) + " | Stack | ", //"crStack", "release", ::traduce(rect)); if (m_locksCount > 0) return; std::map<PointLess, CellData>::iterator it; for (it = m_cellDatas.begin(); it != m_cellDatas.end();) { if (!it->second.m_referenced) { ++it; continue; } TPoint cellPos(getCellPos(it->first)); TRect cellRect(cellPos, TDimension(latticeStep, latticeStep)); if (isEmpty(cellRect * rect)) { ++it; continue; } QRect cellQRect(toQRect(cellRect)); if (--it->second.m_refsCount <= 0) { releaseCell(cellQRect, it->first, it->second.m_modified); std::map<PointLess, CellData>::iterator jt = it++; m_cellDatas.erase(jt); } else ++it; } }
void ArrayCtrl::scrollSelectionVisible() { if(!parent) return; if(selectedCell.x == -1) return; Point2I parentExtent = parent->getExtent(); Point2I cellPos(position.x + selectedCell.x * cellSize.x, position.y + selectedCell.y * cellSize.y); Point2I delta(0,0); if(cellPos.x <= 0) delta.x = -cellPos.x; else if(cellPos.x + cellSize.x > parentExtent.x) delta.x = parentExtent.x - (cellPos.x + cellSize.x); if(cellPos.y <= 0) delta.y = -cellPos.y; else if(cellPos.y + cellSize.y > parentExtent.y) delta.y = parentExtent.y - (cellPos.y + cellSize.y); if(delta.x || delta.y) { Point2I newPosition = position; newPosition += delta; resize(newPosition, extent); } }
QPoint FoTableCellView::calculatePosition() { int width=foTableCellDoc()->widthValue(); int celNum=foTableCellDoc()->cellNumber(); //get topleft of row (we need y axis) QPoint pointTopLeft = m_pTableRowView->calculateTopLeftPosition(); //create qpoint position QPoint cellPos(celNum*width,pointTopLeft.y()); //return position return cellPos; }
void fluid_detection::forEachSetup(fluid_particle* parI) { VEC3D posI = parI->position();// : parI->auxPosition(); cellI = cellPos(posI); if (sph->dimension() == DIM3){ loopStart.x = max(cellI.x - 1, 0); loopStart.y = max(cellI.y - 1, 0); loopStart.z = max(cellI.z - 1, 0); loopEnd.x = min(cellI.x + 1, cellCount_1.x); loopEnd.y = min(cellI.y + 1, cellCount_1.y); loopEnd.z = min(cellI.z + 1, cellCount_1.z); } else{ loopStart = cellPos(posI - sph->kernelSupportRadius()); loopEnd = cellPos(posI + sph->kernelSupportRadius()); } // if (loopEnd.x == cellCount_1.x) // loopEnd.x = 0; //if (sph->) if (parI->ID() == 3080) bool dd = true; if (parI->Neighbors()->size()) parI->Neighbors()->clear(); }
SparseMatrix<float> createInteractionMatrix(int dim){ std::vector<MatrixElement<float>> elems; int nCells = dim * dim; for (int i = 0; i < nCells; ++i){ //In the matrix all diagonal entires are 4 and neighbor cells are -1 elems.push_back(MatrixElement<float>(i, i, 4)); int x, y; cellPos(i, x, y, dim); elems.push_back(MatrixElement<float>(i, cellNumber(x - 1, y, dim), -1)); elems.push_back(MatrixElement<float>(i, cellNumber(x + 1, y, dim), -1)); elems.push_back(MatrixElement<float>(i, cellNumber(x, y - 1, dim), -1)); elems.push_back(MatrixElement<float>(i, cellNumber(x, y + 1, dim), -1)); } return SparseMatrix<float>(elems, dim, true); }
SparseMatrix SimpleFluid::generateMatrix(){ std::vector<Element> elements; int cells = std::pow(dim, 2); //All diagonal entries of the matrix are 4 for (int i = 0; i < cells; ++i){ elements.push_back(Element(i, i, 4)); //Set the cell-cell interaction values for the cells up/down/left/right of our cell //note that this simulation is currently using wrapping boundaries so we just wrap edges //in cellNumber int x, y; cellPos(i, x, y); elements.push_back(Element(i, cellNumber(x - 1, y), -1)); elements.push_back(Element(i, cellNumber(x + 1, y), -1)); elements.push_back(Element(i, cellNumber(x, y - 1), -1)); elements.push_back(Element(i, cellNumber(x, y + 1), -1)); } return SparseMatrix(elements, dim, true); }
void TCacheResource::releaseLock() { //DIAGNOSTICS_NUMBEREDSTR(prefix + QString::number((UINT) this) + " | Stack | ", //"crStack", "releaseLock"); m_locksCount = std::max(m_locksCount - 1, 0); if (m_locksCount > 0) return; //Check for released cells std::map<PointLess, CellData>::iterator it; for (it = m_cellDatas.begin(); it != m_cellDatas.end();) if (it->second.m_referenced) { TPoint cellPos(getCellPos(it->first)); QRect cellQRect(cellPos.x, cellPos.y, latticeStep, latticeStep); releaseCell(cellQRect, it->first, it->second.m_modified); std::map<PointLess, CellData>::iterator jt = it++; m_cellDatas.erase(jt); } else ++it; }
void fluid_detection::sort(bool isf) { //sph->runPeriodicBoundary(); _isf = isf; if(sph->boundaryTreatment() == GHOST_PARTICLE_METHOD) sph->initializeGhostMap(); fluid_particle *parI; size_t rnp = sph->nParticle(); if(sph->getPeriodicParticles()) rnp += sph->getPeriodicParticles()->nParticle(); VEC3D pos; VEC3I cpos; for (size_t i = 0; i < rnp; i++){ parI = sph->particle(i); pos = parI->position(); cpos = cellPos(pos); hashes[i] = VEC2UI(cellHash(cpos), i); cell_id[i] = hashes[i].x; } memset(cell_start, 0xffffffff, sizeof(size_t)*cells); thrust::sort_by_key(cell_id, cell_id + rnp, hashes); size_t hash_start = hashes[0].x; cell_start[hash_start] = 0; for (size_t i = 1; i < rnp; i++){ if (hash_start != hashes[i].x){ hash_start = hashes[i].x; if (hash_start > cells){ VEC3D p = sph->particle(hashes[i].y)->position(); std::cout << ".....error : hash_start is " << hash_start << std::endl; std::cout << ".....error position : [ " << p.x << ", " << p.y << ", " << p.z << " ]" << std::endl; } cell_start[hash_start] = i; } } // if (sph->correction() == GRADIENT_CORRECTION){ // sph->clearMatKgc(); // } // if (sph->boundaryTreatment() == GHOST_PARTICLE_METHOD){ // size_t nGhost = 0; // for (size_t i = sph->nParticleByType(FLUID); i < sph->nRealParticle(); i++){ // forEachSetup(sph->particle(i)); // nGhost += createGhostParticles(i, true); // } // //resizeDetectionData(sph->nRealParticle(), nGhost); // sph->resizeParticle(nGhost); // sph->transferGhostParticle(); // // sph->exportParticlePosition(); // VEC2UI *_hs = new VEC2UI[sph->nRealParticle() + nGhost]; // size_t *_ci = new size_t[sph->nRealParticle() + nGhost]; // for (size_t i = 0; i < sph->nParticle(); i++){ // parI = sph->particle(i); // _hs[i] = VEC2UI(cellHash(cellPos(parI->auxPosition())), i); // _ci[i] = _hs[i].x; // } // memset(cell_start, 0xffffffff, sizeof(size_t)*cells); // thrust::sort_by_key(_ci, _ci + sph->nParticle(), _hs); // // size_t hash_start = hashes[0].x; // cell_start[hash_start] = 0; // for (size_t i = 1; i < sph->nParticle(); i++){ // if (hash_start != _hs[i].x){ // hash_start = _hs[i].x; // if (hash_start > cells){ // VEC3D p = sph->particle(_hs[i].y)->position(); // std::cout << ".....error : hash_start is " << hash_start << std::endl; // std::cout << ".....error position : [ " << p.x << ", " << p.y << ", " << p.z << " ]" << std::endl; // } // cell_start[hash_start] = i; // } // // } // for (size_t i = 0; i < sph->nParticle(); i++){ // // if (i == 38) // // i = 38; // forEachSetup(sph->particle(i)); // forEachNeighbor(sph->particle(i), _hs); // } // return; // } //std::cout << "done" << std::endl; for (size_t i = 0; i < sph->nParticle(); i++){ forEachSetup(sph->particle(i)); forEachNeighbor(sph->particle(i)); } }