//------------------------------------------------------------------------------ void Solver::Advance (float timeStep) { Timer t; t.Start(); updateBlendValues(); mFluidHashTable[LOW]->Fill(mFluidParticles[LOW]->ActiveIDs); mFluidHashTable[HIGH]->Fill(mFluidParticles[HIGH]->ActiveIDs); computeDensity(LOW); computeDensity(HIGH); computeAcceleration(LOW); computeAcceleration(HIGH); integrate(HIGH, timeStep/2.0f); mFluidHashTable[HIGH]->Fill(mFluidParticles[HIGH]->ActiveIDs); computeDensity(HIGH); computeAcceleration(HIGH); integrate(HIGH, timeStep/2.0f); integrate(LOW, timeStep); inject(); t.Stop(); std::cout << "#LOW " << mFluidParticles[LOW]->ActiveIDs.size() << " #HIGH " << mFluidParticles[HIGH]->ActiveIDs.size() << " #TOTAL: " << mFluidParticles[LOW]->ActiveIDs.size() + mFluidParticles[HIGH]->ActiveIDs.size() << "TIME: " << t.GetElapsed() << std::endl; }
/* NOTE: We output only the fluid cells */ void writeVtkOutput(const double * const collideField, const int * const flagField, const char * filename, unsigned int t, int xlength, int rank, int x_proc) { int i, j, k; double velocity[3], density; /* len is used to set values in lexicographic order "[ Q * ( z*len*len + y*len + x) + i ]" */ int len = xlength + 2; char szFileName[80]; FILE *fp=NULL; sprintf( szFileName, "%s-rank%i.%i.vtk", filename, rank, t ); fp = fopen( szFileName, "w"); if( fp == NULL ){ char szBuff[80]; sprintf( szBuff, "Failed to open %s", szFileName ); ERROR( szBuff ); return; } write_vtkHeader(fp, xlength); write_vtkPointCoordinates(fp,xlength,rank,x_proc); fprintf(fp,"POINT_DATA %i \n", xlength*xlength*xlength ); fprintf(fp,"\n"); fprintf(fp, "VECTORS velocity float\n"); for(k = 1; k < xlength+1; k++) { for(j = 1; j < xlength+1; j++) { for(i = 1; i < xlength+1; i++) { computeDensity (&collideField[ 19 * ( k*len*len + j*len + i) ], &density); computeVelocity(&collideField[ 19 * ( k*len*len + j*len + i) ], &density, velocity); fprintf(fp, "%f %f %f\n", velocity[0], velocity[1], velocity[2]); } } } fprintf(fp,"\n"); fprintf(fp, "SCALARS density float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(k = 1; k < xlength+1; k++) { for(j = 1; j < xlength+1; j++) { for(i = 1; i < xlength+1; i++) { computeDensity (&collideField[ 19 * ( k*len*len + j*len + i) ], &density); fprintf(fp, "%f\n", density); } } } if(fclose(fp)){ char szBuff[80]; sprintf( szBuff, "Failed to close %s", szFileName ); ERROR( szBuff ); } }
int main(int argc, char **argv) { char *merylName = 0L; char *fastaName = 0L; char *outputPrefix = 0L; uint32 onlySeqIID = ~uint32ZERO; bool doDensity = false; bool doRescue = false; mateRescueData lib[MAX_COVERAGE]; uint32 libLen = 0; int arg=1; int err=0; while (arg < argc) { if (strcmp(argv[arg], "-mers") == 0) { merylName = argv[++arg]; } else if (strcmp(argv[arg], "-seq") == 0) { fastaName = argv[++arg]; } else if (strcmp(argv[arg], "-only") == 0) { onlySeqIID = atoi(argv[++arg]); } else if (strcmp(argv[arg], "-output") == 0) { outputPrefix = argv[++arg]; } else if (strcmp(argv[arg], "-d") == 0) { doDensity = true; } else if (strcmp(argv[arg], "-r") == 0) { if (atoi(argv[arg+3]) > 0) { doRescue = true; lib[libLen++].init(atoi(argv[arg+1]), atoi(argv[arg+2]), atoi(argv[arg+3])); } arg += 3; } else { fprintf(stderr, "unknown option '%s'\n", argv[arg]); err++; } arg++; } if ((err) || (merylName == 0L) || (fastaName == 0L) || (outputPrefix == 0L)) { fprintf(stderr, "usage: %s -mers mers -seq fasta -output prefix [-d] [-r mean stddev coverage]\n", argv[0]); exit(1); } merMaskedSequence *S = new merMaskedSequence(fastaName, merylName, onlySeqIID); if (doDensity) computeDensity(S, outputPrefix); if (doRescue) computeMateRescue(S, outputPrefix, lib, libLen); return(0); }
void doCollision(double *collideField, int *flagField, const double * const tau,int xlength){ double density; double velocity[3]; double feq[Q]; double* currentCell; int currentIndex; /* Set pointer to first cell that is not a boundary */ currentIndex = (xlength+3); /* Last row is a border */ while(currentIndex < (xlength+2)*(xlength+2)*(xlength+2) - (xlength+2)) { /* No left and right border, only inner cells */ if(flagField[currentIndex] == FLUID) { currentCell = &collideField[currentIndex*Q]; computeDensity(currentCell, &density); computeVelocity(currentCell, &density, velocity); computeFeq(&density, velocity, feq); computePostCollisionDistributions(currentCell, tau, feq); } currentIndex++; } }
void doCollision(double *collideField, int *flagField, const double * const tau, int * length){ /* * For each inner grid cell in collideField, compute the post-collide * distribution */ double density; double velocity[D]; double feq[Q]; double * currentCell; int x,y,z; int node[3]; int n[3] = { length[0] + 2, length[1] + 2, length[2] + 2 }; // Loop over inner cells: compare to streaming.c for (z = 1; z <= length[2]; z++) { node[2] = z; for (y = 1; y <= length[1]; y++) { node[1] = y; for (x = 1; x <= length[0]; x++) { node[0] = x; currentCell = getEl(collideField, node, 0, n); computeDensity(currentCell, &density); computeVelocity(currentCell, &density, velocity); computeFeq(&density, velocity, feq); computePostCollisionDistributions(currentCell, tau, feq); } } } }
//do neighbor search //compute density //compute force //integrate //scene interaction //visualization void particleSystem::LeapfrogIntegrate(float dt){ float halfdt = 0.5f * dt; particleGrid target = particles;// target is a copy! particleGrid& source = particles;//source is a ptr! for (int i=0; i < target.size(); i++){ target[i].pos = source[i].pos + source[i].vel * dt + halfdt * dt * source[i].force / source[i].actual_density; } //calculate actual density /*particleGrid nghrs; for (int i=0; i < target.size(); i++){ if( !checkIfOutOfBoundry(target[i]) ){ nghrs = gridcells.getNeighbors(target[i]); target[i].actual_density = computeDensity(nghrs, target[i]); target[i].pressure = target[i].gas_constant * (target[i].actual_density - target[i].rest_density); } } for (int i=0; i < target.size(); i++){ if( !checkIfOutOfBoundry(target[i]) ){ nghrs = gridcells.getNeighbors(target[i]); target[i].force = computeForce(nghrs, target[i]); } }*/ //calculate actual density for (int i=0; i < target.size(); i++){ target[i].actual_density = computeDensity(target, target[i]); target[i].pressure = target[i].gas_constant * (target[i].actual_density - target[i].rest_density); } for (int i=0; i < target.size(); i++){ target[i].force = computeForce(target, target[i]); } glm::vec3 collision_normal = glm::vec3(0.f); for (int i=0; i < target.size(); i++){ if( CollisionDectection(target[i], collision_normal) ){ glm::vec3 vn = (source[i].vel * collision_normal) * collision_normal;//decompose v along normal glm::vec3 vt = source[i].vel - vn; source[i].vel = 0.9f * vt - 0.8f * vn;//flip normal direction speed }else{ source[i].vel += halfdt * (target[i].force/target[i].actual_density + source[i].force /source[i].actual_density); source[i].pos = target[i].pos; source[i].force = target[i].force; source[i].actual_density = target[i].actual_density; } } //gridcells.refillGrid(source); }
void SPHSystem::normalizeMass() { mass = 1.0; computeDensity(); float rho0 = params.rho0; float rho2s = 0; float rhos = 0; for (int i = 0; i < n; ++i) { rho2s += density[i]*density[i]; rhos += density[i]; } mass *= ( rho0*rhos / rho2s ); }
void WriteVtk::perform(MultiBlockLattice2D<T,DESCRIPTOR> &lattice, plint nStep) { T dx = controller->getParams().getDeltaX(); T physU = controller->getUnits().physVelocity(); std::string fname = createFileName(prefix, nStep, fileNameLength); VtkImageOutput2D<T> vtkOut(fname, dx); std::auto_ptr<MultiScalarField2D<T> > density = computeDensity(lattice); PressureFromRho p(controller); apply(p,*density); vtkOut.writeData<float>(*density, "pressure", 1); vtkOut.writeData<2,float>(*computeVelocity(lattice), "velocity", physU); pcout << "vtk file " << fname << " written" << std::endl; };
const Calc::Output& Calc::operator()(const Input& frames) { cv::Mat old, current; cv::cvtColor(frames.old, old, CV_BGR2GRAY); cv::cvtColor(frames.current, current, CV_BGR2GRAY); frames.current.copyTo(_out.original); old = 255 + (old - _background); current = 255 + (current - _background); computeDensity(current); computeDensityMask(current); computeAlignment(current); computeVelocity(old, current); return _out; }
void doCollision(double *collideField, int *flagField, const double * const tau, const int * const sublength) { for (int z = 1; z < sublength[0] + 1; ++z) { for (int y = 1; y < sublength[1] + 1; ++y) { for (int x = 1; x < sublength[2] + 1; ++x) { double *currentCell = &collideField[idx(sublength, x, y, z, 0)]; /*Updating values for velocity, density and Feq for Current cell*/ double density; computeDensity(currentCell, &density); double velocity[D]; computeVelocity(currentCell, &density, velocity); double feq[Q]; computeFeq(&density, velocity, feq); computePostCollisionDistributions(currentCell, tau, feq); } } } }
void updatePressures(fluid_particle *fluid_particles, param *params) { int num_particles = params->number_fluid_particles; // Hint: Parallelize this loop for(int i=0; i<num_particles; i++) { double3 p_pos = fluid_particles[i].pos; double3 p_v = fluid_particles[i].v; double density = fluid_particles[i].density; for(int j=0; j<num_particles; j++) { double3 q_pos = fluid_particles[j].pos; double3 q_v = fluid_particles[j].v; density += computeDensity(p_pos,p_v,q_pos,q_v, params); } fluid_particles[i].density = density; fluid_particles[i].pressure = computePressure(density, params); } }
void updatePressures(fluid_particle *fluid_particles, param *params) { int num_particles = params[0].number_fluid_particles; #pragma acc parallel loop default(present) for(int i=0; i<num_particles; i++) { double3 p_pos = fluid_particles[i].pos; double3 p_v = fluid_particles[i].v; double density = fluid_particles[i].density; for(int j=0; j<num_particles; j++) { double3 q_pos = fluid_particles[j].pos; double3 q_v = fluid_particles[j].v; density += computeDensity(p_pos,p_v,q_pos,q_v, params[0].mass_particle,params[0].smoothing_radius,params[0].time_step); } fluid_particles[i].density = density; fluid_particles[i].pressure = computePressure(density, params[0].rest_density,params[0].speed_sound); } }
void updatePressures(fluid_particle *fluid_particles, param *params) { int num_particles = params->number_fluid_particles; #pragma omp parallel for firstprivate(num_particles) shared(fluid_particles, params) default(none) for(int i=0; i<num_particles; i++) { double3 p_pos = fluid_particles[i].pos; double3 p_v = fluid_particles[i].v; double density = fluid_particles[i].density; for(int j=0; j<num_particles; j++) { double3 q_pos = fluid_particles[j].pos; double3 q_v = fluid_particles[j].v; density += computeDensity(p_pos,p_v,q_pos,q_v, params); } fluid_particles[i].density = density; fluid_particles[i].pressure = computePressure(density, params); } }
void SPHSystem::computeAcceleration() { // Unpack basic parameters const float mu = params.mu; const float g = params.g; // Compute density and color computeDensity(); // Start with gravity and surface forces for (int i = 0; i < n; ++i) { a[i] = Vec(0, -g, 0); } // Now compute interaction forces for (int i = 0; i < n; ++i) { float w0i = mass * invrho[i]; for(int nidx=0;nidx<nid[i].size();nidx++) { const Grid::cell_t& ncell = pgrid.getcell(nid[i][nidx]); for (int j : ncell) { if( i >= j ) continue; Vec dp = p[i] - p[j]; float r = glm::length(dp); //Vec fp = mass / rhoj / rhoi * 0.5f * (pressure[i] + pressure[j]) * spiky_grad(h, r) * dp; float w0ij = w0i * invrho[j]; Vec fp = w0ij * 0.5f * (pressure[i] + pressure[j]) * kern.spiky_grad(r) * dp; Vec dv = v[j] - v[i]; Vec fv = mu * w0ij * dv * kern.viscosity_lap(r); Vec ftotal = fp + fv; a[i] += ftotal; a[j] -= ftotal; } } } }
void ConsolidateHome::proceed(component::World& world, utils::Team& team) { computeGoals(team); if(computeDensity(world, team) < kDensityAim) { for(auto &blob : team) { if(blob.busy == true) continue; sf::Vector2i loc = findTask(world, {component::World::Cell::kNothing, component::World::Cell::kFood}, world.getHome(team.id), blob.position, 30); if(loc.x != -1) { goals_.push_back(loc); blob.job = std::make_shared<utils::BuildBlock>(loc); blob.busy = true; } } } }
void doCollision(double *collideField, int *flagField,const double * const tau, int *subdomain){ double density; double velocity[D]; double feq[Q]; double *currentCell = NULL; // currentCell points to the first distribution function within the respective cell for (int iz=1; iz<=subdomain[2]; iz++){ for (int iy=1; iy<=subdomain[1]; iy++){ for (int ix=1; ix<=subdomain[0]; ix++){ // set pointer to current cell currentCell = collideField + Q * compute_index(ix, iy, iz, subdomain); // compute density, velocity and equilibrium prob. distrib. for this cell computeDensity ( currentCell, &density ); computeVelocity ( currentCell, &density, velocity ); computeFeq ( &density, velocity, feq ); computePostCollisionDistributions ( currentCell, tau, feq ); } } } }
void CiraExponentialDrag::test() { cout<<"testing CiraExponentialDrag"<<endl; Vector<double> r(3),v(3); r(0)=-4453783.586; r(1)=-5038203.756; r(2)=-426384.456; v(0) = 3831.888; v(1) = -2887.221; v(2) = -6.018232; EarthBody body; UTCTime t; Spacecraft sc; (void)computeDensity(t,body,r,v); doCompute(t,body,sc); (void)getAccel(); }
/** carries out the whole local collision process. Computes density and velocity and * equilibrium distributions. Carries out BGK update. */ void doCollision(double *collideField, int *flagField,const double * const tau,int xlength){ int x,y,z ; int counter; double density; double velocity[3] ; double feq[Q] ; /* we loop over all the inner cells i.e. fluid cells */ for (z = 1; z < xlength+1; z++) { for (y = 1; y < xlength+1; y++) { for (x = 1; x < xlength+1; x++) { /* get the current index */ counter = Q*(z*(xlength+2)*(xlength+2) + y * (xlength+2) + x ); /* Compute density, velocity, f_eq to finally get the postcollision distribution */ computeDensity (&collideField[counter], &density) ; computeVelocity(&collideField[counter], &density,velocity) ; computeFeq(&density,velocity,feq) ; computePostCollisionDistributions(&collideField[counter],tau,feq); } } } }
void MainWindow::setDensityMax() { m_max_density = computeDensity(m_max_level, m_max_rank, m_spaceSize, m_sampler->tiling().subdivFactor()); optionDensityMax->setText(QString().setNum((float)m_max_density, 'g', 3)); }
/* treatBoundary Carries out the boundary treatment. Therefore, we loop over the outer boundary cells, check each cell for its state (NO SLIP or MOVING WALL), and set the respective distribution functions inside this cell according to Eq.(16) and Eq.(18). */ void treatBoundary(double *collideField, int* flagField, const double * const wallVelocity, int xlength){ int x, y, z; int i; double density; int counter; int counter_wall; /*The following array are the values for i that are pointing in the direction of the inner cells * for example in the border where y = 0, the c vectors pointing inside must be the ones which * y component is = 1, in this case the ones with index 4, 11, 12, 13, 18, and the array is denoted * as y_min. The same case is for when y = xlength+1 and the array is y_max, and similarly for the * other 4 planes that form the border of the cube. */ int y_min[5]={4, 11, 12, 13, 18}; int y_max[5]={14, 7, 6, 5, 0}; int x_min[5]={3, 7, 10, 13, 17}; int x_max[5]={15, 11, 8, 5, 1}; int z_min[5]={14, 15, 16, 17, 18}; int z_max[5]={4, 3, 2, 1, 0}; /*This is divided in 6 similar for loops for each of the planes, starting with the plane where y = 0*/ y = 0; for(z = 0; z < xlength + 1; z++){ for(x = 0; x < xlength + 2; x++){ /* Store an index for the current cell */ counter = (z * (xlength+2) * (xlength+2) + y * (xlength+2) + x); /* Check if the boundary condition is NO SLIP*/ if(flagField[counter]==1){ for(i = 0; i<5; i++){ /*Check that the updated directions are pointing to the inner cells*/ if(((x+LATTICEVELOCITIES[y_min[i]][0]) > 0) && ((z+LATTICEVELOCITIES[y_min[i]][2]) > 0) && ((x+LATTICEVELOCITIES[y_min[i]][0])< xlength+1)&&((z+LATTICEVELOCITIES[y_min[i]][2])< xlength+1)){ collideField[Q*counter+y_min[i]]= collideField[Q*((z+LATTICEVELOCITIES[y_min[i]][2])* (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[y_min[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[y_min[i]][0]))+(Q-y_min[i]-1)] ; } } } if(flagField[counter]==2){ for(i = 0; i < 5; i++){ /* Check that there exists an inner cell in that direction*/ if(((x+LATTICEVELOCITIES[y_min[i]][0]) > 0) && ((z+LATTICEVELOCITIES[y_min[i]][2]) > 0) && ((x+LATTICEVELOCITIES[y_min[i]][0])< xlength+1)&&((z+LATTICEVELOCITIES[y_min[i]][2])< xlength+1)){ /*treat the boundary as MOVING WALL according to Eq. (18)*/ counter_wall = Q*((z+LATTICEVELOCITIES[y_min[i]][2]) * (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[y_min[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[y_min[i]][0])); computeDensity (&collideField[counter_wall] , &density) ; collideField[Q*counter+y_min[i]]= collideField[counter_wall+(Q-y_min[i]-1)]+ 2*LATTICEWEIGHTS[y_min[i]]*density/(C_S*C_S)*((LATTICEVELOCITIES[y_min[i]][0]*wallVelocity[0])+ (LATTICEVELOCITIES[y_min[i]][1]*wallVelocity[1])+(LATTICEVELOCITIES[y_min[i]][2]*wallVelocity[2])); } } } } } y = xlength+1; for(z = 0; z < xlength + 1; z++){ for(x = 0; x < xlength + 2; x++){ counter = (z * (xlength+2) * (xlength+2) + y * (xlength+2) + x); if(flagField[counter]==1){ for(i = 0; i<5; i++){ if(((x+LATTICEVELOCITIES[y_max[i]][0]) > 0) && ((z+LATTICEVELOCITIES[y_max[i]][2]) > 0) && ((x+LATTICEVELOCITIES[y_max[i]][0])< xlength+1)&&((z+LATTICEVELOCITIES[y_max[i]][2])< xlength+1)){ collideField[Q*counter+y_max[i]]= collideField[Q*((z+LATTICEVELOCITIES[y_max[i]][2])* (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[y_max[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[y_max[i]][0]))+(Q-y_max[i]-1)] ; } } } if(flagField[counter]==2){ for(i = 0; i < 5; i++){ if(((x+LATTICEVELOCITIES[y_max[i]][0]) > 0) && ((z+LATTICEVELOCITIES[y_max[i]][2]) > 0) && ((x+LATTICEVELOCITIES[y_max[i]][0])< xlength+1)&&((z+LATTICEVELOCITIES[y_max[i]][2])< xlength+1)){ counter_wall = Q*((z+LATTICEVELOCITIES[y_max[i]][2]) * (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[y_max[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[y_max[i]][0])); computeDensity (&collideField[counter_wall] , &density) ; collideField[Q*counter+y_max[i]]= collideField[counter_wall+(Q-y_max[i]-1)]+ 2*LATTICEWEIGHTS[y_max[i]]*density/(C_S*C_S)*((LATTICEVELOCITIES[y_max[i]][0]*wallVelocity[0])+ (LATTICEVELOCITIES[y_max[i]][1]*wallVelocity[1])+(LATTICEVELOCITIES[y_max[i]][2]*wallVelocity[2])); } } } } } x = 0; for(z = 0; z < xlength + 1; z++){ for(y = 0; y < xlength + 2; y++){ counter = (z * (xlength+2) * (xlength+2) + y * (xlength+2) + x); if(flagField[counter]==1){ for(i = 0; i<5; i++){ if(((y+LATTICEVELOCITIES[x_min[i]][1]) > 0) && ((z+LATTICEVELOCITIES[x_min[i]][2]) > 0) && ((y+LATTICEVELOCITIES[x_min[i]][1])< xlength+1)&&((z+LATTICEVELOCITIES[x_min[i]][2])< xlength+1)){ collideField[Q*counter+x_min[i]]= collideField[Q*((z+LATTICEVELOCITIES[x_min[i]][2])* (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[x_min[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[x_min[i]][0]))+(Q-x_min[i]-1)] ; } } } if(flagField[counter]==2){ for(i = 0; i < 5; i++){ /* Check that there exists a neighbor cell in that direction*/ if(((y+LATTICEVELOCITIES[x_min[i]][1]) > 0) && ((z+LATTICEVELOCITIES[x_min[i]][2]) > 0) && ((y+LATTICEVELOCITIES[x_min[i]][1])< xlength+1)&&((z+LATTICEVELOCITIES[x_min[i]][2])< xlength+1)){ /*treat the boundary as MOVING WALL according to Eq. (18)*/ counter_wall = Q*((z+LATTICEVELOCITIES[x_min[i]][2]) * (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[x_min[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[x_min[i]][0])); computeDensity (&collideField[counter_wall] , &density) ; collideField[Q*counter+x_min[i]]= collideField[counter_wall+(Q-x_min[i]-1)]+ 2*LATTICEWEIGHTS[x_min[i]]*density/(C_S*C_S)*((LATTICEVELOCITIES[x_min[i]][0]*wallVelocity[0])+ (LATTICEVELOCITIES[x_min[i]][1]*wallVelocity[1])+(LATTICEVELOCITIES[x_min[i]][2]*wallVelocity[2])); } } } } } x = xlength+1; for(z = 0; z < xlength + 1; z++){ for(y = 0; y < xlength + 2; y++){ counter = (z * (xlength+2) * (xlength+2) + y * (xlength+2) + x); if(flagField[counter]==1){ for(i = 0; i<5; i++){ if(((y+LATTICEVELOCITIES[x_max[i]][1]) > 0) && ((z+LATTICEVELOCITIES[x_max[i]][2]) > 0) && ((y+LATTICEVELOCITIES[x_max[i]][1])< xlength+1)&&((z+LATTICEVELOCITIES[x_max[i]][2])< xlength+1)){ collideField[Q*counter+x_max[i]]= collideField[Q*((z+LATTICEVELOCITIES[x_max[i]][2])* (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[x_max[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[x_max[i]][0]))+(Q-x_max[i]-1)] ; } } } if(flagField[counter]==2){ for(i = 0; i < 5; i++){ /* Check that there exists a neighbor cell in that direction*/ if(((y+LATTICEVELOCITIES[x_max[i]][1]) > 0) && ((z+LATTICEVELOCITIES[x_max[i]][2]) > 0) && ((y+LATTICEVELOCITIES[x_max[i]][1])< xlength+1)&&((z+LATTICEVELOCITIES[x_max[i]][2])< xlength+1)){ /*treat the boundary as MOVING WALL according to Eq. (18)*/ counter_wall = Q*((z+LATTICEVELOCITIES[x_max[i]][2]) * (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[x_max[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[x_max[i]][0])); computeDensity (&collideField[counter_wall] , &density) ; collideField[Q*counter+x_max[i]]= collideField[counter_wall+(Q-x_max[i]-1)]+ 2*LATTICEWEIGHTS[x_max[i]]*density/(C_S*C_S)*((LATTICEVELOCITIES[x_max[i]][0]*wallVelocity[0])+ (LATTICEVELOCITIES[x_max[i]][1]*wallVelocity[1])+(LATTICEVELOCITIES[x_max[i]][2]*wallVelocity[2])); } } } } } z = 0; for(y = 0; y < xlength + 2; y++){ for(x = 0; x < xlength + 2; x++){ counter = (z * (xlength+2) * (xlength+2) + y * (xlength+2) + x); if(flagField[counter]==1){ for(i = 0; i<5; i++){ if(((x+LATTICEVELOCITIES[z_min[i]][0]) > 0) && ((y+LATTICEVELOCITIES[z_min[i]][1]) > 0) && ((x+LATTICEVELOCITIES[z_min[i]][0])< xlength+1)&&((y+LATTICEVELOCITIES[z_min[i]][1])< xlength+1)){ collideField[Q*counter+z_min[i]]= collideField[Q*((z+LATTICEVELOCITIES[z_min[i]][2])* (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[z_min[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[z_min[i]][0]))+(Q-z_min[i]-1)] ; if(collideField[Q*counter+z_max[i]]<0 ||collideField[Q*counter+z_max[i]] > 2 ){ printf("x=%i y=%i z=%i value=%f\n",x,y,z,collideField[Q*counter+z_min[i]]); } } } } if(flagField[counter]==2){ for(i = 0; i < 5; i++){ /* Check that there exists a neighbor cell in that direction*/ if(((x+LATTICEVELOCITIES[z_min[i]][0]) > 0) && ((y+LATTICEVELOCITIES[z_min[i]][1]) > 0) && ((x+LATTICEVELOCITIES[z_min[i]][0])< xlength+1)&&((y+LATTICEVELOCITIES[z_min[i]][1])< xlength+1)){ /*treat the boundary as MOVING WALL according to Eq. (18)*/ counter_wall = Q*((z+LATTICEVELOCITIES[z_min[i]][2]) * (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[z_min[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[z_min[i]][0])); computeDensity (&collideField[counter_wall] , &density) ; collideField[Q*counter+z_min[i]]= collideField[counter_wall+(Q-z_min[i]-1)]+ 2*LATTICEWEIGHTS[z_min[i]]*density/(C_S*C_S)*((LATTICEVELOCITIES[z_min[i]][0]*wallVelocity[0])+ (LATTICEVELOCITIES[z_min[i]][1]*wallVelocity[1])+(LATTICEVELOCITIES[z_min[i]][2]*wallVelocity[2])); if(collideField[Q*counter+z_max[i]]<0 ||collideField[Q*counter+z_max[i]] > 2 ){ printf("x=%i y=%i z=%i value=%f\n",x,y,z,collideField[Q*counter+z_min[i]]); } } } } } } z = xlength+1; for(y = 0; y < xlength + 2; y++){ for(x = 0; x < xlength + 2; x++){ counter = (z * (xlength+2) * (xlength+2) + y * (xlength+2) + x); if(flagField[counter]==1){ for(i = 0; i<5; i++){ if(((x+LATTICEVELOCITIES[z_max[i]][0]) > 0) && ((y+LATTICEVELOCITIES[z_max[i]][1]) > 0) && ((x+LATTICEVELOCITIES[z_max[i]][0])< xlength+1)&&((y+LATTICEVELOCITIES[z_max[i]][1])< xlength+1)){ collideField[Q*counter+z_max[i]]= collideField[Q*((z+LATTICEVELOCITIES[z_max[i]][2])* (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[z_max[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[z_max[i]][0]))+(Q-z_max[i]-1)] ; } } } if(flagField[counter]==2){ for(i = 0; i < 5; i++){ /* Check that there exists a neighbor cell in that direction*/ if(((x+LATTICEVELOCITIES[z_max[i]][0]) > 0) && ((y+LATTICEVELOCITIES[z_max[i]][1]) > 0) && ((x+LATTICEVELOCITIES[z_max[i]][0]) < xlength+1)&&((y+LATTICEVELOCITIES[z_max[i]][1])< xlength+1)){ /*treat the boundary as MOVING WALL according to Eq. (18)*/ counter_wall = Q*((z+LATTICEVELOCITIES[z_max[i]][2]) * (xlength+2) * (xlength+2) + (y+LATTICEVELOCITIES[z_max[i]][1]) * (xlength+2) + (x+LATTICEVELOCITIES[z_max[i]][0])); computeDensity (&collideField[counter_wall] , &density) ; collideField[Q*counter+z_max[i]]= collideField[counter_wall+(Q-z_max[i]-1)]+ 2*LATTICEWEIGHTS[z_max[i]]*density/(C_S*C_S)*((LATTICEVELOCITIES[z_max[i]][0]*wallVelocity[0])+ (LATTICEVELOCITIES[z_max[i]][1]*wallVelocity[1])+(LATTICEVELOCITIES[z_max[i]][2]*wallVelocity[2])); } } } } } }
void GolemMaterialTH::computeQpProperties() { if (_has_lumped_mass_matrix) { (*_node_number)[_qp] = nearest(); (*_nodal_temp)[_qp] = (*_nodal_temp_var)[(*_node_number)[_qp]]; (*_nodal_temp_old)[_qp] = (*_nodal_temp_var_old)[(*_node_number)[_qp]]; (*_nodal_pf)[_qp] = (*_nodal_pf_var)[(*_node_number)[_qp]]; if (_has_boussinesq) (*_nodal_pf_old)[_qp] = (*_nodal_pf_var_old)[(*_node_number)[_qp]]; } _scaling_factor[_qp] = computeQpScaling(); computeDensity(); computeViscosity(); _porosity[_qp] = _porosity_uo->computePorosity(_phi0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); _permeability[_qp] = _permeability_uo->computePermeability(_k0, _phi0, _porosity[_qp], _scaling_factor[_qp]); // GolemKernelT related properties _T_kernel_diff[_qp] = _porosity[_qp] * _lambda_f + (1.0 - _porosity[_qp]) * _lambda_s; if (_has_T_source_sink) (*_T_kernel_source)[_qp] = -1.0 * _T_source_sink; // GolemKernelH related properties GolemPropertiesH(); // GolemkernelTH related poperties _TH_kernel[_qp] = -_H_kernel[_qp] * _fluid_density[_qp] * _c_f; if (_fe_problem.isTransient()) { // Correct H_kernel_time if (_drho_dpf[_qp] != 0.0) (*_H_kernel_time)[_qp] = (_porosity[_qp] * _drho_dpf[_qp]) / _fluid_density[_qp]; (*_T_kernel_time)[_qp] = _porosity[_qp] * _fluid_density[_qp] * _c_f + (1.0 - _porosity[_qp]) * _rho0_s * _c_s; } // Properties derivatives // H_kernel derivatives (*_dH_kernel_dpf)[_qp] = -_H_kernel[_qp] * _dmu_dpf[_qp] / _fluid_viscosity[_qp]; _dH_kernel_dT[_qp] = -_H_kernel[_qp] * _dmu_dT[_qp] / _fluid_viscosity[_qp]; // H_kernel_grav derivatives _dH_kernel_grav_dpf[_qp] = -_drho_dpf[_qp] * _gravity; _dH_kernel_grav_dT[_qp] = -_drho_dT[_qp] * _gravity; if (_fe_problem.isTransient()) { // T_kernel_time (*_dT_kernel_time_dpf)[_qp] = _drho_dpf[_qp] * _porosity[_qp] * _c_f; (*_dT_kernel_time_dT)[_qp] = _drho_dT[_qp] * _porosity[_qp] * _c_f; } // TH_kernel derivatives _dTH_kernel_dpf[_qp] = -(_fluid_density[_qp] * _c_f * (*_dH_kernel_dpf)[_qp] + _H_kernel[_qp] * _c_f * _drho_dpf[_qp]); _dTH_kernel_dT[_qp] = -(_fluid_density[_qp] * _c_f * _dH_kernel_dT[_qp] + _H_kernel[_qp] * _c_f * _drho_dT[_qp]); if (_has_SUPG_upwind) computeQpSUPG(); if (_has_disp) { // Declare some property when this material is used for fractures or faults in a THM simulation (*_dH_kernel_dev)[_qp] = RankTwoTensor(); (*_dT_kernel_diff_dev)[_qp] = 0.0; (*_dT_kernel_diff_dpf)[_qp] = 0.0; (*_dT_kernel_diff_dT)[_qp] = 0.0; if (_fe_problem.isTransient()) { (*_dT_kernel_time_dev)[_qp] = 0.0; (*_dH_kernel_time_dev)[_qp] = 0.0; (*_dH_kernel_time_dpf)[_qp] = 0.0; (*_dH_kernel_time_dT)[_qp] = 0.0; } } }
int main(int argc, char *argv[]) { std::cerr << "reading graph..."; Eigen::SparseMatrix<double> g = readGraph(std::string(argv[1])); std::cerr << "done." << std::endl; #if DEBUG std::cout << "Adjacency Matrix" << std::endl; std::cout << g << std::endl; #endif std::vector<C_tuple*> C; std::cerr << "getting C vector..."; getC(g, C); std::cerr << "sorting..."; __gnu_parallel::sort(C.begin(), C.end(), C_tuple_compare); //std::sort(C.begin(), C.end(), C_tuple_compare); std::cerr << "done." << std::endl; #if DEBUG for (uint64_t i = 0; i < C.size(); i++) { std::cout << C[i]->i << ", " << C[i]->j << ", " << C[i]->value<< std::endl; } #endif std::cerr << "creating T..."; node* root = createT(g, C); std::cerr << "done." << std::endl; #if DEBUG //postorder(printNode, root); levelorder(printNode, root); node* left = root->leftChild; while (left->leftChild) left = left->leftChild; node* right = root->rightChild; while (right->rightChild) right = right->rightChild; node* lca = LCA(left, right); std::cout << "lca for " << left->vertex << ", " << right->vertex << ": " << lca->vertex << std::endl; left = right->parent->leftChild; lca = LCA(left, right); std::cout << "lca for " << left->vertex << ", " << right->vertex << ": " << lca->vertex << std::endl; #endif std::cerr << "counting vertices and edges..."; countVerticesAndEdges(g, root); std::cerr << "done." << std::endl; std::cerr << "computing density..."; computeDensity(root); std::cerr << "done." << std::endl; #if DEBUG std::cout << "\nPrinting after the countVerticesAndEdges\n" << std::endl; postorder(printNode, root); #endif std::cerr << "extracting subgraphs..."; extractSubgraphs(root, 0.75); std::cerr << "done." << std::endl; }
// this is the real one void AtmosphericDrag::doCompute(UTCTime utc, EarthBody& rb, Spacecraft& sc) { // To consist with STK double omega_e = 7.292115E-05; // IERS 1996 conventions //double omega_e = rb.getSpinRate(utc); Vector<double> r = sc.R(); // satellite position in m Vector<double> v = sc.V(); // satellite velocity in m/s const double cd = sc.getDragCoeff(); const double area = sc.getDragArea(); const double mass = sc.getDryMass(); double rmag = norm(r); double beta = cd * area / mass; // [m^2/kg] // compute the atmospheric density double rho = computeDensity(utc, rb, r, v); // [kg/m^3] // debuging... //rho = 6.3097802844338E-12; // compute the relative velocity vector and magnitude Vector<double> we(3,0.0); we(2)= omega_e; Vector<double> wxr = cross(we,r); Vector<double> vr = v - wxr; double vrmag = norm(vr); // form -1/2 (Cd*A/m) rho double coeff = -0.5 * beta * rho; double coeff2 = coeff * vrmag; // compute the acceleration in ECI frame (km/s^2) a = vr * coeff2; ///////// a // Partial reference: Montenbruck,P248 // form partial of drag wrt v // da_dv = -0.5*Cd*(A/M)*p*(vr*transpose(vr)/vr+vr1) Matrix<double> tr(3,1,0.0); tr(0,0)=vr(0); tr(1,0)=vr(1); tr(2,0)=vr(2); Matrix<double> vrvrt = tr*transpose(tr); vrvrt = vrvrt / vrmag; double eye3[3*3] = {1,0,0,0,1,0,0,0,1}; Matrix<double> vrm(3,3,0.0); vrm = eye3; vrm = vrm * vrmag; da_dv = (vrvrt + vrm) * coeff; //////// da_dv // da_dr // da_dr = -0.5*Cd*(A/M)*vr*dp_dr-da_dv*X(w) da_dr.resize(3,3,0.0); Matrix<double> X(3,3,0.0); X(0,1) = -we(2); // -wz X(0,2) = +we(1); // wy X(1,0) = +we(2); // +wz X(1,2) = -we(0); // -wx X(2,0) = -we(1); // -wy X(2,1) = +we(0); // +wx Matrix<double> part1(3,3,0.0); Matrix<double> part2(3,3,0.0); // Get the J2000 to TOD transformation Matrix<double> N = ReferenceFrames::J2kToTODMatrix(utc); // Transform r from J2000 to TOD Vector<double> r_tod = N * r; Position geoidPos(r_tod(0),r_tod(1),r_tod(3)); // Satellite height double height = geoidPos.getAltitude()/1000.0; // convert to [km] const int n = CIRA_SIZE; ; int bracket = 0; if (height >= h0[n-1]) { bracket = n - 1; } else { for (int i = 0; i < (n-1); i++) { if ((height >= h0[i]) && (height < h0[i+1])) { bracket = i; } } } // End 'if (height >= h0[n-1]) ' double Hh = H[bracket]; double coeff4 = -1.0 / (Hh * rmag); Vector<double> drhodr = r*coeff4; Matrix<double> tr2(3,1,0.0); tr2(0,0) = drhodr(0); tr2(1,0) = drhodr(1); tr2(2,0) = drhodr(2); part1 = tr*transpose(tr2); // //Matrix part1 = vr.outerProduct(drhodr); part1 = part1*coeff2; //part1 = dp_dr*a/rho; part2 =-da_dv*X; da_dr = part1-part2; // form partial of drag wrt cd double coeff3 = coeff2 / cd; this->dadcd = vr*coeff3; //////// da_dcd this->da_dcd(0,0) = dadcd(0); this->da_dcd(1,0) = dadcd(1); this->da_dcd(2,0) = dadcd(2); } // End of method 'AtmosphericDrag::doCompute()'
double WLOP::iterate() { Timer time; initVertexes(); time.start("Sample Original Neighbor Tree!!!"); GlobalFun::computeBallNeighbors(samples, original, para->getDouble("CGrid Radius"), box); time.end(); time.start("Sample Sample Neighbor Tree"); GlobalFun::computeBallNeighbors(samples, NULL, para->getDouble("CGrid Radius"), samples->bbox); time.end(); if (nTimeIterated == 0) { if (para->getBool("Need Compute Density")) { double local_density_para = 0.95; time.start("Original Original Neighbor Tree"); GlobalFun::computeBallNeighbors(original, NULL, para->getDouble("CGrid Radius") * local_density_para, original->bbox); time.end(); time.start("Compute Original Density"); original_density.assign(original->vn, 0); computeDensity(true, para->getDouble("CGrid Radius") * local_density_para); time.end(); } } if (para->getBool("Need Compute Density")) { time.start("Compute Density For Sample"); computeDensity(false, para->getDouble("CGrid Radius")); time.end(); } time.start("Sample Original Neighbor Tree!!!"); GlobalFun::computeBallNeighbors(samples, original, para->getDouble("CGrid Radius"), box); time.end(); time.start("Compute Average Term"); computeAverageTerm(samples, original); time.end(); time.start("Compute Repulsion Term"); computeRepulsionTerm(samples); time.end(); double mu = para->getDouble("Repulsion Mu"); Point3f c; for(int i = 0; i < samples->vert.size(); i++) { CVertex& v = samples->vert[i]; c = v.P(); if (average_weight_sum[i] > 1e-20) { v.P() = average[i] / average_weight_sum[i]; } if (repulsion_weight_sum[i] > 1e-20 && mu >= 0) { v.P() += repulsion[i] * (mu / repulsion_weight_sum[i]); } if (average_weight_sum[i] > 1e-20 && repulsion_weight_sum[i] > 1e-20 ) { Point3f diff = v.P() - c; double move_error = sqrt(diff.SquaredNorm()); error_x += move_error; } } error_x = error_x / samples->vn; para->setValue("Current Movement Error", DoubleValue(error_x)); cout << "****finished compute WLOP error: " << error_x << endl; if (para->getBool("Need Compute PCA")) { time.start("Recompute PCA"); recomputePCA_Normal(); time.end(); } return error_x; }
void writeVtkOutput(const double* const collideField, const int* const flagField, const char* filename, unsigned int timestep, int xlength) { //final filename char szFileName[128]; //file handle FILE* fp = NULL; //create final filename snprintf(szFileName, sizeof(szFileName), "%s.%i.vtk", filename, timestep); //try to open the file fp = fopen(szFileName, "w"); //error check if(!fp) { ERROR("writeVtkOutput: Failed to open"); return; } //print vtk header fprintf(fp, "# vtk DataFile Version 2.0\n"); fprintf(fp, "generated by CFD LBM \n"); fprintf(fp, "ASCII\n"); fprintf(fp, "\n"); fprintf(fp, "DATASET STRUCTURED_GRID\n"); fprintf(fp, "DIMENSIONS %i %i %i \n", xlength+3, xlength+3, xlength+3); fprintf(fp, "POINTS %i float\n", (xlength+3)*(xlength+3)*(xlength+3)); //assume size=1 domain double dx = 1.0 / (xlength+2); //print list of points double originX = 0.0; double originY = 0.0; double originZ = 0.0; for(int i=0;i<=xlength+2;i++) { for(int j=0;j<=xlength+2;j++) { for(int k=0;k<=xlength+2;k++) { fprintf(fp, "%f %f %f\n", originX+(i*dx), originY+(j*dx), originZ+(k*dx)); } } } //print velocity vectors fprintf(fp, "\n"); fprintf(fp, "CELL_DATA %i \n", (xlength+2)*(xlength+2)*(xlength+2)); fprintf(fp, "VECTORS velocity float\n"); for(int x=0;x<=xlength+1;x++) { for(int y=0;y<=xlength+1;y++) { for(int z=0;z<=xlength+1;z++) { //variables for temporary calc double vel[3]; double dens; //base of fluid cell in collideField int index = NUM_LATTICE*((z *(xlength + 2)*(xlength + 2)) + y * (xlength + 2) + x); //calculate quantities for current cell computeDensity(&collideField[index], &dens); computeVelocity(&collideField[index], &dens, vel); //output vector fprintf(fp, "%f %f %f\n", vel[0], vel[1], vel[2]); } } } //print densities fprintf(fp, "\n"); fprintf(fp, "SCALARS density float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(int x=0;x<=xlength+1;x++) { for(int y=0;y<=xlength+1;y++) { for(int z=0;z<=xlength+1;z++) { //variables for temporary calc double dens; //base of fluid cell in collideField int index = NUM_LATTICE*((z *(xlength + 2)*(xlength + 2)) + y * (xlength + 2) + x); //calculate quantities for current cell computeDensity(&collideField[index], &dens); //output scalar fprintf(fp, "%f\n", dens); } } } //close file if(fclose(fp)!=0) { ERROR("writeVtkOutput: Failed to close"); } }
void writeVtkOutput(const double * const collideField, const int * const flagField, const char * filename, unsigned int t, int *xlength) { int x, y, z, currentCellIndex; double cellVelocity[3], cellDensity; char szFileName[80]; FILE *fp=NULL; sprintf( szFileName, "%s.%i.vtk", filename, t ); fp = fopen( szFileName, "w"); if( fp == NULL ) { char szBuff[80]; sprintf( szBuff, "Failed to open %s", szFileName ); ERROR( szBuff ); return; } write_vtkHeader( fp, xlength); write_vtkPointCoordinates(fp, xlength); fprintf(fp,"POINT_DATA %i \n", (xlength[0]) * (xlength[1]) * (xlength[2])); fprintf(fp,"\n"); fprintf(fp, "VECTORS velocity float\n"); for(z = 1; z <= xlength[2]; z++) for (y = 1; y <= xlength[1]; y++) for (x = 1; x <= xlength[0]; x++) { currentCellIndex = (z * (xlength[0] + 2) * (xlength[1] + 2) + y * (xlength[0] + 2) + x); computeDensity(collideField + currentCellIndex, &cellDensity, (xlength[0] + 2) * (xlength[1] + 2) * (xlength[2] + 2)); computeVelocity(collideField + currentCellIndex, &cellDensity, cellVelocity, (xlength[0] + 2) * (xlength[1] + 2) * (xlength[2] + 2)); fprintf(fp, "%f %f %f\n", cellVelocity[0], cellVelocity[1], cellVelocity[2]); } fprintf(fp,"\n"); fprintf(fp, "SCALARS density float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(z = 1; z <= xlength[2]; z++) for(y = 1; y <= xlength[1]; y++) for (x = 1; x <= xlength[0]; x++) { currentCellIndex = (z * (xlength[0] + 2) * (xlength[1] + 2) + y * (xlength[0] + 2) + x); computeDensity(collideField + currentCellIndex, &cellDensity, (xlength[0] + 2) * (xlength[1] + 2) * (xlength[2] + 2)); fprintf(fp, "%f\n", cellDensity); } fprintf(fp, "SCALARS boundaryType integer 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(z = 1; z <= xlength[2] ; z++) for(y = 1; y <= xlength[1] ; y++) for (x = 1; x <= xlength[0] ; x++) { currentCellIndex = (z * (xlength[0] + 2) * (xlength[1] + 2) + y * (xlength[0] + 2) + x); fprintf(fp, "%d\n", flagField[currentCellIndex]); } if( fclose(fp) ) { char szBuff[80]; sprintf( szBuff, "Failed to close %s", szFileName ); ERROR( szBuff ); } }
void writeVtkOutput(const double * const collideField, const int * const flagField, const char * filename, unsigned int t, int xlength) { char fn[80]; int len = xlength+2; // save filename as a combination of passed filename and timestep sprintf(fn, "%s.%i.vtk", filename, t); FILE *fp = NULL; fp = fopen(fn, "w"); if (fp == NULL) { ERROR("Failed to open file!"); return; } // write header fprintf(fp, "# vtk DataFile Version 2.0\n"); fprintf(fp, "generated by CFD-lab course output \n"); fprintf(fp, "ASCII\n\n"); fprintf(fp, "DATASET STRUCTURED_GRID\n"); fprintf(fp, "DIMENSIONS %d %d %d \n", xlength, xlength, xlength); fprintf(fp, "POINTS %d float\n\n", (xlength) * (xlength) * (xlength)); // print lattice points double step = 1.0 / (xlength - 1); for (double x = 0; x <= xlength-1; x+=1) { for (double y = 0; y <= xlength-1; y+=1) { for (double z = 0; z <= xlength-1; z+=1) { fprintf(fp, "%f %f %f\n", x*step, y*step, z*step); } } } double density; double vel[D]; const double *currentCell; // write density data fprintf(fp, "\nPOINT_DATA %d \n", (xlength) * (xlength) * (xlength)); fprintf(fp, "SCALARS density float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for (int x = 1; x < xlength+1; ++x) { for (int y = 1; y < xlength+1; ++y) { for (int z = 1; z < xlength+1; ++z) { currentCell = collideField + Q*( z*len*len + y*len + x); computeDensity(currentCell, &density); fprintf(fp, "%f\n", density); } } } // compute velocities for all cells fprintf(fp, "\nVECTORS velocity float\n"); for (int x = 1; x < xlength+1; ++x) { for (int y = 1; y < xlength+1; ++y) { for (int z = 1; z < xlength+1; ++z) { currentCell = collideField + Q*( z*len*len + y*len + x ); computeDensity(currentCell, &density); computeVelocity(currentCell, &density, vel); fprintf(fp, "%f %f %f\n", vel[0], vel[1], vel[2]); } } } // close the file if (fclose(fp)) { ERROR("Failed to close file!"); return; } }
void write_vtkFile(const char *szProblem, int t, int * length, double *collideField, int * flagField) { int x, y, z; char szFileName[80]; FILE *fp=NULL; int n[3] = {length[0] + 2,length[1] + 2,length[2] + 2}; double velocity[3]; double density; double * el = NULL; sprintf( szFileName, "%s.%i.vtk", szProblem, t ); fp = fopen( szFileName, "w"); if( fp == NULL ) { char szBuff[80]; sprintf( szBuff, "Failed to open %s", szFileName ); ERROR( szBuff ); return; } write_vtkHeader(fp, length); write_vtkPointCoordinates(fp, length); fprintf(fp,"POINT_DATA %i \n", length[0]*length[1]*length[2]); fprintf(fp,"\n"); fprintf(fp, "VECTORS velocity float\n"); for(z = 1; z <= length[0]; z++) { for(y = 1; y <= length[1]; y++) { for(x = 1; x <= length[2]; x++) { if (*getFlag(flagField, x, y, z, n) != OBSTACLE) { el = getEl(collideField, x, y, z, 0, n); computeDensity(el, &density); computeVelocity(el, &density, velocity); fprintf(fp, "%f %f %f\n", velocity[0], velocity[1], velocity[2]); } else { fprintf(fp, "%f %f %f\n", 0.0, 0.0, 0.0); } } } } fprintf(fp,"\n"); fprintf(fp, "SCALARS density float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(z = 1; z <= length[0]; z++) { for(y = 1; y <= length[1]; y++) { for(x = 1; x <= length[2]; x++) { if (*getFlag(flagField, x, y, z, n) != OBSTACLE) { computeDensity(getEl(collideField, x, y, z, 0, n), &density); fprintf(fp, "%f\n", density); } else { fprintf(fp, "%f\n", 1.0); } } } } if( fclose(fp) ) { char szBuff[80]; sprintf( szBuff, "Failed to close %s", szFileName ); ERROR( szBuff ); } }
void write_vtkFile(const char *szProblem, int t, int * length, double * collideField, int * my_pos, int my_rank, int * my_origin) { char szFileName[80]; FILE *fp=NULL; int x, y, z; int node[3]; int n[3] = { length[0] + 2, length[1] + 2, length[2] + 2 }; double velocity[3]; double density; double * el = NULL; sprintf( szFileName, "%s_%i.%i.vtk", szProblem, my_rank, t); fp = fopen( szFileName, "w"); if( fp == NULL ) { char szBuff[80]; sprintf( szBuff, "Failed to open %s", szFileName ); ERROR( szBuff ); return; } write_vtkHeader(fp, length); write_vtkPointCoordinates(fp, length, my_pos, my_origin); fprintf(fp,"POINT_DATA %i \n", length[0] * length[1] * length[2]); fprintf(fp,"\n"); fprintf(fp, "VECTORS velocity float\n"); for(z = 1; z <= length[2]; z++) { node[2] = z; for(y = 1; y <= length[1]; y++) { node[1] = y; for(x = 1; x <= length[0]; x++) { node[0] = x; el = getEl(collideField, node, 0, n); computeDensity(el, &density); computeVelocity(el, &density, velocity); fprintf(fp, "%f %f %f\n", velocity[0], velocity[1], velocity[2]); } } } fprintf(fp,"\n"); fprintf(fp, "SCALARS density float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(z = 1; z <= length[2]; z++) { node[2] = z; for(y = 1; y <= length[1]; y++) { node[1] = y; for(x = 1; x <= length[0]; x++) { node[0] = x; computeDensity(getEl(collideField, node, 0, n), &density); fprintf(fp, "%f\n", density); } } } if( fclose(fp) ) { char szBuff[80]; sprintf( szBuff, "Failed to close %s", szFileName ); ERROR( szBuff ); } }