void generateZigZagIninfill_noEndPieces(const Polygons& in_outline, Polygons& result, int extrusionWidth, int lineSpacing, double infillOverlap, double rotation) { if (in_outline.size() == 0) return; Polygons outline = in_outline.offset(extrusionWidth * infillOverlap / 100 - extrusionWidth / 2); if (outline.size() == 0) return; PointMatrix matrix(rotation); outline.applyMatrix(matrix); auto addLine = [&](Point from, Point to) { PolygonRef p = result.newPoly(); p.add(matrix.unapply(from)); p.add(matrix.unapply(to)); }; AABB boundary(outline); int scanline_min_idx = boundary.min.X / lineSpacing; int lineCount = (boundary.max.X + (lineSpacing - 1)) / lineSpacing - scanline_min_idx; std::vector<std::vector<int64_t> > cutList; // mapping from scanline to all intersections with polygon segments for(int n=0; n<lineCount; n++) cutList.push_back(std::vector<int64_t>()); for(unsigned int polyNr=0; polyNr < outline.size(); polyNr++) { std::vector<Point> firstBoundarySegment; std::vector<Point> boundarySegment; bool isFirstBoundarySegment = true; bool firstBoundarySegmentEndsInEven = true; bool isEvenScanSegment = false; Point p0 = outline[polyNr][outline[polyNr].size()-1]; for(unsigned int i=0; i < outline[polyNr].size(); i++) { Point p1 = outline[polyNr][i]; int64_t xMin = p1.X, xMax = p0.X; if (xMin == xMax) { p0 = p1; continue; } if (xMin > xMax) { xMin = p0.X; xMax = p1.X; } int scanline_idx0 = (p0.X + ((p0.X > 0)? -1 : -lineSpacing)) / lineSpacing; // -1 cause a linesegment on scanline x counts as belonging to scansegment x-1 ... int scanline_idx1 = (p1.X + ((p1.X > 0)? -1 : -lineSpacing)) / lineSpacing; // -linespacing because a line between scanline -n and -n-1 belongs to scansegment -n-1 (for n=positive natural number) int direction = 1; if (p0.X > p1.X) { direction = -1; scanline_idx1 += 1; // only consider the scanlines in between the scansegments } else scanline_idx0 += 1; // only consider the scanlines in between the scansegments if (isFirstBoundarySegment) firstBoundarySegment.push_back(p0); else boundarySegment.push_back(p0); for(int scanline_idx = scanline_idx0; scanline_idx != scanline_idx1+direction; scanline_idx+=direction) { int x = scanline_idx * lineSpacing; int y = p1.Y + (p0.Y - p1.Y) * (x - p1.X) / (p0.X - p1.X); cutList[scanline_idx - scanline_min_idx].push_back(y); bool last_isEvenScanSegment = isEvenScanSegment; if (scanline_idx % 2 == 0) isEvenScanSegment = true; else isEvenScanSegment = false; if (!isFirstBoundarySegment) { if (last_isEvenScanSegment && !isEvenScanSegment) { // add whole boundarySegment (including the just obtained point) for (unsigned int p = 1; p < boundarySegment.size(); p++) { addLine(boundarySegment[p-1], boundarySegment[p]); } addLine(boundarySegment[boundarySegment.size()-1], Point(x,y)); boundarySegment.clear(); } else if (isEvenScanSegment) // we are either in an end piece or an uneven boundary segment { boundarySegment.clear(); boundarySegment.emplace_back(x,y); } else boundarySegment.clear(); } if (isFirstBoundarySegment) { firstBoundarySegment.emplace_back(x,y); firstBoundarySegmentEndsInEven = isEvenScanSegment; isFirstBoundarySegment = false; boundarySegment.emplace_back(x,y); } } if (!isFirstBoundarySegment && isEvenScanSegment) boundarySegment.push_back(p1); p0 = p1; } if (!isFirstBoundarySegment && isEvenScanSegment && !firstBoundarySegmentEndsInEven) { for (unsigned int i = 1; i < firstBoundarySegment.size() ; i++) addLine(firstBoundarySegment[i-1], firstBoundarySegment[i]); } } addLineInfill(result, matrix, scanline_min_idx, lineSpacing, boundary, cutList, extrusionWidth); }
//The controls we get the current position and simply increment/decrement. Then when the last buffer is cleared we blit to the new position. void pawn::controls(int x2,int y2, int w, int h) { int oldx = x; int oldy = y; if(key[KEY_D]) { x+=speed; } if(key[KEY_S]) { y+= speed; //The animation frame relates to our bitmap. we have several frames of movement and we simply tell the program to go to the next position. animationFrame+=14; if (animationFrame>=112) { animationFrame=0; } } if (key[KEY_A]) { x-=speed; } if (key[KEY_W]) { y-=speed; animationFrame+=14; if (animationFrame>=112) { animationFrame=0; } } if (key[KEY_LSHIFT]) { speed = 0.5; } else { speed = 2; } boundary(); //This is my collistion checking function. The values I pass in here are for the walls. //If the player intersets with a wall his position is set back a few places. if ((x >= x2 +w) || (y >= y2 +h) || (x2 >= x +16) || (y2 >= y +16)) { } else { //y = oldy; //I had to add this secondary check because for some reason the program wasn't properly checking when the player was on the right of the wall. if(y > y2- 1) { y+=9; } if(x > x2 - 1) { x+=9; } if(x2 > x ) { x-=9; } if(y2 > y ) { y-=9; } } }
void generateZigZagIninfill_endPieces(const Polygons& in_outline, Polygons& result, int extrusionWidth, int lineSpacing, double infillOverlap, double rotation, bool connect_zigzags) { (void)infillOverlap; // if (in_outline.size() == 0) return; // Polygons outline = in_outline.offset(extrusionWidth * infillOverlap / 100 - extrusionWidth / 2); Polygons empty; Polygons outline = in_outline.difference(empty); // copy if (outline.size() == 0) return; PointMatrix matrix(rotation); outline.applyMatrix(matrix); auto addLine = [&](Point from, Point to) { PolygonRef p = result.newPoly(); p.add(matrix.unapply(from)); p.add(matrix.unapply(to)); }; AABB boundary(outline); int scanline_min_idx = boundary.min.X / lineSpacing; int lineCount = (boundary.max.X + (lineSpacing - 1)) / lineSpacing - scanline_min_idx; std::vector<std::vector<int64_t> > cutList; // mapping from scanline to all intersections with polygon segments for(int n=0; n<lineCount; n++) cutList.push_back(std::vector<int64_t>()); for(unsigned int polyNr=0; polyNr < outline.size(); polyNr++) { std::vector<Point> firstBoundarySegment; std::vector<Point> unevenBoundarySegment; // stored cause for connected_zigzags a boundary segment which ends in an uneven scanline needs to be included bool isFirstBoundarySegment = true; bool firstBoundarySegmentEndsInEven = false; bool isEvenScanSegment = false; Point p0 = outline[polyNr][outline[polyNr].size()-1]; Point lastPoint = p0; for(unsigned int i=0; i < outline[polyNr].size(); i++) { Point p1 = outline[polyNr][i]; int64_t xMin = p1.X, xMax = p0.X; if (xMin == xMax) { lastPoint = p1; p0 = p1; continue; } if (xMin > xMax) { xMin = p0.X; xMax = p1.X; } int scanline_idx0 = (p0.X + ((p0.X > 0)? -1 : -lineSpacing)) / lineSpacing; // -1 cause a linesegment on scanline x counts as belonging to scansegment x-1 ... int scanline_idx1 = (p1.X + ((p1.X > 0)? -1 : -lineSpacing)) / lineSpacing; // -linespacing because a line between scanline -n and -n-1 belongs to scansegment -n-1 (for n=positive natural number) int direction = 1; if (p0.X > p1.X) { direction = -1; scanline_idx1 += 1; // only consider the scanlines in between the scansegments } else scanline_idx0 += 1; // only consider the scanlines in between the scansegments if (isFirstBoundarySegment) firstBoundarySegment.push_back(p0); for(int scanline_idx = scanline_idx0; scanline_idx != scanline_idx1+direction; scanline_idx+=direction) { int x = scanline_idx * lineSpacing; int y = p1.Y + (p0.Y - p1.Y) * (x - p1.X) / (p0.X - p1.X); cutList[scanline_idx - scanline_min_idx].push_back(y); bool last_isEvenScanSegment = isEvenScanSegment; if (scanline_idx % 2 == 0) isEvenScanSegment = true; else isEvenScanSegment = false; if (!isFirstBoundarySegment) { if (last_isEvenScanSegment && (connect_zigzags || !isEvenScanSegment)) addLine(lastPoint, Point(x,y)); else if (connect_zigzags && !last_isEvenScanSegment && !isEvenScanSegment) // if we end an uneven boundary in an uneven segment { // add whole unevenBoundarySegment (including the just obtained point) for (unsigned int p = 1; p < unevenBoundarySegment.size(); p++) { addLine(unevenBoundarySegment[p-1], unevenBoundarySegment[p]); } addLine(unevenBoundarySegment[unevenBoundarySegment.size()-1], Point(x,y)); unevenBoundarySegment.clear(); } if (connect_zigzags && last_isEvenScanSegment && !isEvenScanSegment) unevenBoundarySegment.push_back(Point(x,y)); else unevenBoundarySegment.clear(); } lastPoint = Point(x,y); if (isFirstBoundarySegment) { firstBoundarySegment.emplace_back(x,y); firstBoundarySegmentEndsInEven = isEvenScanSegment; isFirstBoundarySegment = false; } } if (!isFirstBoundarySegment) { if (isEvenScanSegment) addLine(lastPoint, p1); else if (connect_zigzags) unevenBoundarySegment.push_back(p1); } lastPoint = p1; p0 = p1; } if (isEvenScanSegment || isFirstBoundarySegment || connect_zigzags) { for (unsigned int i = 1; i < firstBoundarySegment.size() ; i++) { if (i < firstBoundarySegment.size() - 1 || !firstBoundarySegmentEndsInEven || connect_zigzags) // only add last element if connect_zigzags or boundary segment ends in uneven scanline addLine(firstBoundarySegment[i-1], firstBoundarySegment[i]); } } else if (!firstBoundarySegmentEndsInEven) addLine(firstBoundarySegment[firstBoundarySegment.size()-2], firstBoundarySegment[firstBoundarySegment.size()-1]); } if (cutList.size() == 0) return; if (connect_zigzags && cutList.size() == 1 && cutList[0].size() <= 2) return; // don't add connection if boundary already contains whole outline! addLineInfill(result, matrix, scanline_min_idx, lineSpacing, boundary, cutList, extrusionWidth); }
/// @brief /// @todo Doc me! /// @return int boundaryId() const { return boundary() ? 1 : 0; }
void poly_nonherm_precon(spinor * const R, spinor * const S, const double e, const double d, const int n, const int N) { int j; double a1, a2, dtmp; static spinor *work, *work_; static int initpnH = 0; spinor * psi, * chi, *tmp0, *tmp1, *cptmp; if(initpnH == 0) { work_ = calloc(4*VOLUMEPLUSRAND+1, sizeof(spinor)); #if (defined SSE || defined SSE2 || defined SSE3) work = (spinor *)(((unsigned long int)(work_)+ALIGN_BASE)&~ALIGN_BASE); #else work = work_; #endif initpnH = 1; } psi = work; chi = &work[VOLUMEPLUSRAND]; tmp0 = &work[2*VOLUMEPLUSRAND]; tmp1 = &work[3*VOLUMEPLUSRAND]; /* signs to be clarified!! */ /* P_0 * S */ mul_r(psi, 1./d, S, N); /* P_1 * S = a_1(1+kappa*H) * S */ a1 = d/(d*d-e*e/2.); boundary(g_kappa/d); dtmp = g_mu; g_mu = g_mu/d; D_psi(chi, S); mul_r(chi, a1, chi, N); boundary(g_kappa); g_mu = dtmp; /* boundary(-g_kappa); */ /* g_mu = -g_mu; */ /* D_psi(aux, chi); */ /* diff(aux, aux, S, N); */ /* dtmp = square_norm(aux, N, 1); */ /* printf("1 %1.3e\n", dtmp); */ /* boundary(-g_kappa); */ /* g_mu = -g_mu; */ /* assign(chi, d, N); */ for(j = 2; j < n+1; j++) { /* a_n */ a2 = 1./(d-a1*e*e/4.); /* 1-a_n */ a1 = 1.-d*a2; /* aux = a_n*S + (1-a_n) psi */ mul_add_mul_r(tmp0, S, psi, a2, a1, N); /* sv = kappa H chi = (D_psi(-kappa, -2kappamu) - 1) chi */ D_psi(tmp1, chi); /* why is the following sign like this? */ diff(tmp1, chi, tmp1, N); /* psi = aux + a_n * sv */ mul_add_mul_r(psi, tmp0, tmp1, 1., a2, N); cptmp = psi; psi = chi; chi = cptmp; /* boundary(-g_kappa); */ /* g_mu = -g_mu; */ if(g_debug_level>4) { D_psi(tmp0, chi); diff(tmp0, tmp0, S, N); dtmp = square_norm(tmp0, N, 1); if(g_proc_id == 0) printf("poly %d %1.3e\n", j, dtmp); } /* boundary(-g_kappa); */ /* g_mu = -g_mu; */ a1 = a2; } assign(R, chi, N); boundary(g_kappa); g_mu = dtmp; return; }
void tetDecompositionEngineMesh::move() { scalar deltaZ = engineDB_.pistonDisplacement().value(); Info<< "deltaZ = " << deltaZ << endl; // Position of the top of the static mesh layers above the piston scalar pistonPlusLayers = pistonPosition_.value() + pistonLayers_.value(); pointField newPoints = points(); tetPolyMesh tetMesh(*this); // Select the set of boundary condition types. For symmetry planes // and wedge boundaries, the slip condition should be used; // otherwise, use the fixedValue wordList boundaryTypes ( boundary().size(), fixedValueTetPolyPatchScalarField::typeName ); forAll (boundary(), patchI) { if ( isType<symmetryFvPatch>(boundary()[patchI]) || isType<wedgeFvPatch>(boundary()[patchI]) || isType<emptyFvPatch>(boundary()[patchI]) ) { boundaryTypes[patchI] = slipTetPolyPatchScalarField::typeName; } } tetPointScalarField motionUz ( IOobject ( "motionUz", engineDB_.timeName(), engineDB_, IOobject::NO_READ, IOobject::NO_WRITE ), tetMesh, dimensionedScalar("0", dimLength, 0), boundaryTypes ); motionUz.boundaryField()[pistonIndex_] == deltaZ; { scalarField linerPoints = motionUz.boundaryField()[linerIndex_].patch() .localPoints().component(vector::Z); motionUz.boundaryField()[linerIndex_] == deltaZ*pos(deckHeight_.value() - linerPoints) *(deckHeight_.value() - linerPoints) /(deckHeight_.value() - pistonPlusLayers); } elementScalarField diffusion ( IOobject ( "motionDiffusion", engineDB_.timeName(), engineDB_, IOobject::NO_READ, IOobject::NO_WRITE ), tetMesh, dimensionedScalar("d", dimless, 1.0) ); const fvPatchList& patches = boundary(); forAll (patches, patchI) { const unallocLabelList& fc = patches[patchI].faceCells(); forAll (fc, fcI) { diffusion[fc[fcI]] = 2; } } solve(tetFem::laplacian(diffusion, motionUz)); newPoints.replace ( vector::Z, newPoints.component(vector::Z) + scalarField::subField ( motionUz.internalField(), newPoints.size() ) ); if (engineDB_.foundObject<surfaceScalarField>("phi")) { surfaceScalarField& phi = const_cast<surfaceScalarField&> (engineDB_.lookupObject<surfaceScalarField>("phi")); const volScalarField& rho = engineDB_.lookupObject<volScalarField>("rho"); const volVectorField& U = engineDB_.lookupObject<volVectorField>("U"); bool absolutePhi = false; if (moving()) { phi += fvc::interpolate(rho)*fvc::meshPhi(rho, U); absolutePhi = true; } movePoints(newPoints); if (absolutePhi) { phi -= fvc::interpolate(rho)*fvc::meshPhi(rho, U); } } pistonPosition_.value() += deltaZ; scalar pistonSpeed = deltaZ/engineDB_.deltaT().value(); Info<< "clearance: " << deckHeight_.value() - pistonPosition_.value() << nl << "Piston speed = " << pistonSpeed << " m/s" << endl; }
int main(int argc, char *argv[]) { FILE *parameterfile = NULL; int j, i, ix = 0, isample = 0, op_id = 0; char datafilename[206]; char parameterfilename[206]; char conf_filename[50]; char * input_filename = NULL; char * filename = NULL; double plaquette_energy; struct stout_parameters params_smear; spinor **s, *s_; #ifdef _KOJAK_INST #pragma pomp inst init #pragma pomp inst begin(main) #endif #if (defined SSE || defined SSE2 || SSE3) signal(SIGILL, &catch_ill_inst); #endif DUM_DERI = 8; DUM_MATRIX = DUM_DERI + 5; #if ((defined BGL && defined XLC) || defined _USE_TSPLITPAR) NO_OF_SPINORFIELDS = DUM_MATRIX + 3; #else NO_OF_SPINORFIELDS = DUM_MATRIX + 3; #endif verbose = 0; g_use_clover_flag = 0; #ifdef MPI # ifdef OMP int mpi_thread_provided; MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_thread_provided); # else MPI_Init(&argc, &argv); # endif MPI_Comm_rank(MPI_COMM_WORLD, &g_proc_id); #else g_proc_id = 0; #endif process_args(argc,argv,&input_filename,&filename); set_default_filenames(&input_filename, &filename); /* Read the input file */ if( (j = read_input(input_filename)) != 0) { fprintf(stderr, "Could not find input file: %s\nAborting...\n", input_filename); exit(-1); } #ifdef OMP init_openmp(); #endif /* this DBW2 stuff is not needed for the inversion ! */ if (g_dflgcr_flag == 1) { even_odd_flag = 0; } g_rgi_C1 = 0; if (Nsave == 0) { Nsave = 1; } if (g_running_phmc) { NO_OF_SPINORFIELDS = DUM_MATRIX + 8; } tmlqcd_mpi_init(argc, argv); g_dbw2rand = 0; /* starts the single and double precision random number */ /* generator */ start_ranlux(rlxd_level, random_seed); /* we need to make sure that we don't have even_odd_flag = 1 */ /* if any of the operators doesn't use it */ /* in this way even/odd can still be used by other operators */ for(j = 0; j < no_operators; j++) if(!operator_list[j].even_odd_flag) even_odd_flag = 0; #ifndef MPI g_dbw2rand = 0; #endif #ifdef _GAUGE_COPY j = init_gauge_field(VOLUMEPLUSRAND, 1); #else j = init_gauge_field(VOLUMEPLUSRAND, 0); #endif if (j != 0) { fprintf(stderr, "Not enough memory for gauge_fields! Aborting...\n"); exit(-1); } j = init_geometry_indices(VOLUMEPLUSRAND); if (j != 0) { fprintf(stderr, "Not enough memory for geometry indices! Aborting...\n"); exit(-1); } if (no_monomials > 0) { if (even_odd_flag) { j = init_monomials(VOLUMEPLUSRAND / 2, even_odd_flag); } else { j = init_monomials(VOLUMEPLUSRAND, even_odd_flag); } if (j != 0) { fprintf(stderr, "Not enough memory for monomial pseudo fermion fields! Aborting...\n"); exit(-1); } } if (even_odd_flag) { j = init_spinor_field(VOLUMEPLUSRAND / 2, NO_OF_SPINORFIELDS); } else { j = init_spinor_field(VOLUMEPLUSRAND, NO_OF_SPINORFIELDS); } if (j != 0) { fprintf(stderr, "Not enough memory for spinor fields! Aborting...\n"); exit(-1); } if (g_running_phmc) { j = init_chi_spinor_field(VOLUMEPLUSRAND / 2, 20); if (j != 0) { fprintf(stderr, "Not enough memory for PHMC Chi fields! Aborting...\n"); exit(-1); } } g_mu = g_mu1; if (g_cart_id == 0) { /*construct the filenames for the observables and the parameters*/ strncpy(datafilename, filename, 200); strcat(datafilename, ".data"); strncpy(parameterfilename, filename, 200); strcat(parameterfilename, ".para"); parameterfile = fopen(parameterfilename, "w"); write_first_messages(parameterfile, "invert", git_hash); fclose(parameterfile); } /* define the geometry */ geometry(); /* define the boundary conditions for the fermion fields */ boundary(g_kappa); phmc_invmaxev = 1.; init_operators(); /* list and initialize measurements*/ if(g_proc_id == 0) { printf("\n"); for(int j = 0; j < no_measurements; j++) { printf("# measurement id %d, type = %d\n", j, measurement_list[j].type); } } init_measurements(); /* this could be maybe moved to init_operators */ #ifdef _USE_HALFSPINOR j = init_dirac_halfspinor(); if (j != 0) { fprintf(stderr, "Not enough memory for halffield! Aborting...\n"); exit(-1); } if (g_sloppy_precision_flag == 1) { j = init_dirac_halfspinor32(); if (j != 0) { fprintf(stderr, "Not enough memory for 32-bit halffield! Aborting...\n"); exit(-1); } } # if (defined _PERSISTENT) if (even_odd_flag) init_xchange_halffield(); # endif #endif for (j = 0; j < Nmeas; j++) { sprintf(conf_filename, "%s.%.4d", gauge_input_filename, nstore); if (g_cart_id == 0) { printf("#\n# Trying to read gauge field from file %s in %s precision.\n", conf_filename, (gauge_precision_read_flag == 32 ? "single" : "double")); fflush(stdout); } if( (i = read_gauge_field(conf_filename,g_gauge_field)) !=0) { fprintf(stderr, "Error %d while reading gauge field from %s\n Aborting...\n", i, conf_filename); exit(-2); } if (g_cart_id == 0) { printf("# Finished reading gauge field.\n"); fflush(stdout); } #ifdef MPI xchange_gauge(g_gauge_field); #endif /*compute the energy of the gauge field*/ plaquette_energy = measure_plaquette( (const su3**) g_gauge_field); if (g_cart_id == 0) { printf("# The computed plaquette value is %e.\n", plaquette_energy / (6.*VOLUME*g_nproc)); fflush(stdout); } if (use_stout_flag == 1){ params_smear.rho = stout_rho; params_smear.iterations = stout_no_iter; /* if (stout_smear((su3_tuple*)(g_gauge_field[0]), ¶ms_smear, (su3_tuple*)(g_gauge_field[0])) != 0) */ /* exit(1) ; */ g_update_gauge_copy = 1; plaquette_energy = measure_plaquette( (const su3**) g_gauge_field); if (g_cart_id == 0) { printf("# The plaquette value after stouting is %e\n", plaquette_energy / (6.*VOLUME*g_nproc)); fflush(stdout); } } /* if any measurements are defined in the input file, do them here */ measurement * meas; for(int imeas = 0; imeas < no_measurements; imeas++){ meas = &measurement_list[imeas]; if (g_proc_id == 0) { fprintf(stdout, "#\n# Beginning online measurement.\n"); } meas->measurefunc(nstore, imeas, even_odd_flag); } if (reweighting_flag == 1) { reweighting_factor(reweighting_samples, nstore); } /* Compute minimal eigenvalues, if wanted */ if (compute_evs != 0) { eigenvalues(&no_eigenvalues, 5000, eigenvalue_precision, 0, compute_evs, nstore, even_odd_flag); } if (phmc_compute_evs != 0) { #ifdef MPI MPI_Finalize(); #endif return(0); } /* Compute the mode number or topological susceptibility using spectral projectors, if wanted*/ if(compute_modenumber != 0 || compute_topsus !=0){ s_ = calloc(no_sources_z2*VOLUMEPLUSRAND+1, sizeof(spinor)); s = calloc(no_sources_z2, sizeof(spinor*)); if(s_ == NULL) { printf("Not enough memory in %s: %d",__FILE__,__LINE__); exit(42); } if(s == NULL) { printf("Not enough memory in %s: %d",__FILE__,__LINE__); exit(42); } for(i = 0; i < no_sources_z2; i++) { #if (defined SSE3 || defined SSE2 || defined SSE) s[i] = (spinor*)(((unsigned long int)(s_)+ALIGN_BASE)&~ALIGN_BASE)+i*VOLUMEPLUSRAND; #else s[i] = s_+i*VOLUMEPLUSRAND; #endif random_spinor_field_lexic(s[i], reproduce_randomnumber_flag,RN_Z2); /* what is this here needed for?? */ /* spinor *aux_,*aux; */ /* #if ( defined SSE || defined SSE2 || defined SSE3 ) */ /* aux_=calloc(VOLUMEPLUSRAND+1, sizeof(spinor)); */ /* aux = (spinor *)(((unsigned long int)(aux_)+ALIGN_BASE)&~ALIGN_BASE); */ /* #else */ /* aux_=calloc(VOLUMEPLUSRAND, sizeof(spinor)); */ /* aux = aux_; */ /* #endif */ if(g_proc_id == 0) { printf("source %d \n", i); } if(compute_modenumber != 0){ mode_number(s[i], mstarsq); } if(compute_topsus !=0) { top_sus(s[i], mstarsq); } } free(s); free(s_); } /* move to operators as well */ if (g_dflgcr_flag == 1) { /* set up deflation blocks */ init_blocks(nblocks_t, nblocks_x, nblocks_y, nblocks_z); /* the can stay here for now, but later we probably need */ /* something like init_dfl_solver called somewhere else */ /* create set of approximate lowest eigenvectors ("global deflation subspace") */ /* g_mu = 0.; */ /* boundary(0.125); */ generate_dfl_subspace(g_N_s, VOLUME, reproduce_randomnumber_flag); /* boundary(g_kappa); */ /* g_mu = g_mu1; */ /* Compute little Dirac operators */ /* alt_block_compute_little_D(); */ if (g_debug_level > 0) { check_projectors(reproduce_randomnumber_flag); check_local_D(reproduce_randomnumber_flag); } if (g_debug_level > 1) { check_little_D_inversion(reproduce_randomnumber_flag); } } if(SourceInfo.type == 1) { index_start = 0; index_end = 1; } g_precWS=NULL; if(use_preconditioning == 1){ /* todo load fftw wisdom */ #if (defined HAVE_FFTW ) && !( defined MPI) loadFFTWWisdom(g_spinor_field[0],g_spinor_field[1],T,LX); #else use_preconditioning=0; #endif } if (g_cart_id == 0) { fprintf(stdout, "#\n"); /*Indicate starting of the operator part*/ } for(op_id = 0; op_id < no_operators; op_id++) { boundary(operator_list[op_id].kappa); g_kappa = operator_list[op_id].kappa; g_mu = 0.; if(use_preconditioning==1 && PRECWSOPERATORSELECT[operator_list[op_id].solver]!=PRECWS_NO ){ printf("# Using preconditioning with treelevel preconditioning operator: %s \n", precWSOpToString(PRECWSOPERATORSELECT[operator_list[op_id].solver])); /* initial preconditioning workspace */ operator_list[op_id].precWS=(spinorPrecWS*)malloc(sizeof(spinorPrecWS)); spinorPrecWS_Init(operator_list[op_id].precWS, operator_list[op_id].kappa, operator_list[op_id].mu/2./operator_list[op_id].kappa, -(0.5/operator_list[op_id].kappa-4.), PRECWSOPERATORSELECT[operator_list[op_id].solver]); g_precWS = operator_list[op_id].precWS; if(PRECWSOPERATORSELECT[operator_list[op_id].solver] == PRECWS_D_DAGGER_D) { fitPrecParams(op_id); } } for(isample = 0; isample < no_samples; isample++) { for (ix = index_start; ix < index_end; ix++) { if (g_cart_id == 0) { fprintf(stdout, "#\n"); /*Indicate starting of new index*/ } /* we use g_spinor_field[0-7] for sources and props for the moment */ /* 0-3 in case of 1 flavour */ /* 0-7 in case of 2 flavours */ prepare_source(nstore, isample, ix, op_id, read_source_flag, source_location); //randmize initial guess for eigcg if needed-----experimental if( (operator_list[op_id].solver == INCREIGCG) && (operator_list[op_id].solver_params.eigcg_rand_guess_opt) ){ //randomize the initial guess gaussian_volume_source( operator_list[op_id].prop0, operator_list[op_id].prop1,isample,ix,0); //need to check this } operator_list[op_id].inverter(op_id, index_start, 1); } } if(use_preconditioning==1 && operator_list[op_id].precWS!=NULL ){ /* free preconditioning workspace */ spinorPrecWS_Free(operator_list[op_id].precWS); free(operator_list[op_id].precWS); } if(operator_list[op_id].type == OVERLAP){ free_Dov_WS(); } } nstore += Nsave; } #ifdef OMP free_omp_accumulators(); #endif free_blocks(); free_dfl_subspace(); free_gauge_field(); free_geometry_indices(); free_spinor_field(); free_moment_field(); free_chi_spinor_field(); free(filename); free(input_filename); #ifdef MPI MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); #endif return(0); #ifdef _KOJAK_INST #pragma pomp inst end(main) #endif }
void op_invert(const int op_id, const int index_start, const int write_prop) { operator * optr = &operator_list[op_id]; double atime = 0., etime = 0., nrm1 = 0., nrm2 = 0.; int i; optr->iterations = 0; optr->reached_prec = -1.; g_kappa = optr->kappa; boundary(g_kappa); atime = gettime(); if(optr->type == TMWILSON || optr->type == WILSON || optr->type == CLOVER) { g_mu = optr->mu; g_c_sw = optr->c_sw; if(optr->type == CLOVER) { if (g_cart_id == 0 && g_debug_level > 1) { printf("#\n# csw = %e, computing clover leafs\n", g_c_sw); } init_sw_fields(VOLUME); sw_term( (const su3**) g_gauge_field, optr->kappa, optr->c_sw); /* this must be EE here! */ /* to match clover_inv in Qsw_psi */ sw_invert(EE, optr->mu); } for(i = 0; i < 2; i++) { if (g_cart_id == 0) { printf("#\n# 2 kappa mu = %e, kappa = %e, c_sw = %e\n", g_mu, g_kappa, g_c_sw); } if(optr->type != CLOVER) { if(use_preconditioning){ g_precWS=(void*)optr->precWS; } else { g_precWS=NULL; } optr->iterations = invert_eo( optr->prop0, optr->prop1, optr->sr0, optr->sr1, optr->eps_sq, optr->maxiter, optr->solver, optr->rel_prec, 0, optr->even_odd_flag,optr->no_extra_masses, optr->extra_masses, optr->id ); /* check result */ M_full(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], optr->prop0, optr->prop1); } else { optr->iterations = invert_clover_eo(optr->prop0, optr->prop1, optr->sr0, optr->sr1, optr->eps_sq, optr->maxiter, optr->solver, optr->rel_prec, &g_gauge_field, &Qsw_pm_psi, &Qsw_minus_psi); /* check result */ Msw_full(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], optr->prop0, optr->prop1); } diff(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI], optr->sr0, VOLUME / 2); diff(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+1], optr->sr1, VOLUME / 2); nrm1 = square_norm(g_spinor_field[DUM_DERI], VOLUME / 2, 1); nrm2 = square_norm(g_spinor_field[DUM_DERI+1], VOLUME / 2, 1); optr->reached_prec = nrm1 + nrm2; /* convert to standard normalisation */ /* we have to mult. by 2*kappa */ if (optr->kappa != 0.) { mul_r(optr->prop0, (2*optr->kappa), optr->prop0, VOLUME / 2); mul_r(optr->prop1, (2*optr->kappa), optr->prop1, VOLUME / 2); } if (optr->solver != CGMMS && write_prop) /* CGMMS handles its own I/O */ optr->write_prop(op_id, index_start, i); if(optr->DownProp) { optr->mu = -optr->mu; } else break; } } else if(optr->type == DBTMWILSON || optr->type == DBCLOVER) { g_mubar = optr->mubar; g_epsbar = optr->epsbar; g_c_sw = 0.; if(optr->type == DBCLOVER) { g_c_sw = optr->c_sw; if (g_cart_id == 0 && g_debug_level > 1) { printf("#\n# csw = %e, computing clover leafs\n", g_c_sw); } init_sw_fields(VOLUME); sw_term( (const su3**) g_gauge_field, optr->kappa, optr->c_sw); sw_invert_nd(optr->mubar*optr->mubar-optr->epsbar*optr->epsbar); } for(i = 0; i < SourceInfo.no_flavours; i++) { if(optr->type != DBCLOVER) { optr->iterations = invert_doublet_eo( optr->prop0, optr->prop1, optr->prop2, optr->prop3, optr->sr0, optr->sr1, optr->sr2, optr->sr3, optr->eps_sq, optr->maxiter, optr->solver, optr->rel_prec); } else { optr->iterations = invert_cloverdoublet_eo( optr->prop0, optr->prop1, optr->prop2, optr->prop3, optr->sr0, optr->sr1, optr->sr2, optr->sr3, optr->eps_sq, optr->maxiter, optr->solver, optr->rel_prec); } g_mu = optr->mubar; if(optr->type != DBCLOVER) { M_full(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], optr->prop0, optr->prop1); } else { Msw_full(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], optr->prop0, optr->prop1); } assign_add_mul_r(g_spinor_field[DUM_DERI+1], optr->prop2, -optr->epsbar, VOLUME/2); assign_add_mul_r(g_spinor_field[DUM_DERI+2], optr->prop3, -optr->epsbar, VOLUME/2); g_mu = -g_mu; if(optr->type != DBCLOVER) { M_full(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+4], optr->prop2, optr->prop3); } else { Msw_full(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+4], optr->prop2, optr->prop3); } assign_add_mul_r(g_spinor_field[DUM_DERI+3], optr->prop0, -optr->epsbar, VOLUME/2); assign_add_mul_r(g_spinor_field[DUM_DERI+4], optr->prop1, -optr->epsbar, VOLUME/2); diff(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+1], optr->sr0, VOLUME/2); diff(g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+2], optr->sr1, VOLUME/2); diff(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+3], optr->sr2, VOLUME/2); diff(g_spinor_field[DUM_DERI+4], g_spinor_field[DUM_DERI+4], optr->sr3, VOLUME/2); nrm1 = square_norm(g_spinor_field[DUM_DERI+1], VOLUME/2, 1); nrm1 += square_norm(g_spinor_field[DUM_DERI+2], VOLUME/2, 1); nrm1 += square_norm(g_spinor_field[DUM_DERI+3], VOLUME/2, 1); nrm1 += square_norm(g_spinor_field[DUM_DERI+4], VOLUME/2, 1); optr->reached_prec = nrm1; g_mu = g_mu1; /* For standard normalisation */ /* we have to mult. by 2*kappa */ mul_r(g_spinor_field[DUM_DERI], (2*optr->kappa), optr->prop0, VOLUME/2); mul_r(g_spinor_field[DUM_DERI+1], (2*optr->kappa), optr->prop1, VOLUME/2); mul_r(g_spinor_field[DUM_DERI+2], (2*optr->kappa), optr->prop2, VOLUME/2); mul_r(g_spinor_field[DUM_DERI+3], (2*optr->kappa), optr->prop3, VOLUME/2); /* the final result should be stored in the convention used in */ /* hep-lat/0606011 */ /* this requires multiplication of source with */ /* (1+itau_2)/sqrt(2) and the result with (1-itau_2)/sqrt(2) */ mul_one_pm_itau2(optr->prop0, optr->prop2, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], -1., VOLUME/2); mul_one_pm_itau2(optr->prop1, optr->prop3, g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+3], -1., VOLUME/2); /* write propagator */ if(write_prop) optr->write_prop(op_id, index_start, i); mul_r(optr->prop0, 1./(2*optr->kappa), g_spinor_field[DUM_DERI], VOLUME/2); mul_r(optr->prop1, 1./(2*optr->kappa), g_spinor_field[DUM_DERI+1], VOLUME/2); mul_r(optr->prop2, 1./(2*optr->kappa), g_spinor_field[DUM_DERI+2], VOLUME/2); mul_r(optr->prop3, 1./(2*optr->kappa), g_spinor_field[DUM_DERI+3], VOLUME/2); /* mirror source, but not for volume sources */ if(i == 0 && SourceInfo.no_flavours == 2 && SourceInfo.type != 1) { if (g_cart_id == 0) { fprintf(stdout, "# Inversion done in %d iterations, squared residue = %e!\n", optr->iterations, optr->reached_prec); } mul_one_pm_itau2(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], optr->sr0, optr->sr2, -1., VOLUME/2); mul_one_pm_itau2(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+3], optr->sr1, optr->sr3, -1., VOLUME/2); mul_one_pm_itau2(optr->sr0, optr->sr2, g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI], +1., VOLUME/2); mul_one_pm_itau2(optr->sr1, optr->sr3, g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+1], +1., VOLUME/2); } /* volume sources need only one inversion */ else if(SourceInfo.type == 1) i++; } } else if(optr->type == OVERLAP) { g_mu = 0.; m_ov=optr->m; eigenvalues(&optr->no_ev, 5000, optr->ev_prec, 0, optr->ev_readwrite, nstore, optr->even_odd_flag); /* ov_check_locality(); */ /* index_jd(&optr->no_ev_index, 5000, 1.e-12, optr->conf_input, nstore, 4); */ ov_n_cheby=optr->deg_poly; if(use_preconditioning==1) g_precWS=(void*)optr->precWS; else g_precWS=NULL; if(g_debug_level > 3) ov_check_ginsparg_wilson_relation_strong(); invert_overlap(op_id, index_start); if(write_prop) optr->write_prop(op_id, index_start, 0); } etime = gettime(); if (g_cart_id == 0 && g_debug_level > 0) { fprintf(stdout, "# Inversion done in %d iterations, squared residue = %e!\n", optr->iterations, optr->reached_prec); fprintf(stdout, "# Inversion done in %1.2e sec. \n", etime - atime); } return; }
void cloverdet_derivative(const int id, hamiltonian_field_t * const hf) { monomial * mnl = &monomial_list[id]; /* This factor 2 a missing factor 2 in trace_lambda */ (*mnl).forcefactor = 2.; /********************************************************************* * * even/odd version * * This a term is det(\hat Q^2(\mu)) * *********************************************************************/ g_mu = mnl->mu; g_mu3 = mnl->rho; boundary(mnl->kappa); // we compute the clover term (1 + T_ee(oo)) for all sites x sw_term(hf->gaugefield, mnl->kappa, mnl->c_sw); // we invert it for the even sites only sw_invert(EE, mnl->mu); if(mnl->solver != CG && g_proc_id == 0) { fprintf(stderr, "Bicgstab currently not implemented, using CG instead! (cloverdet_monomial.c)\n"); } // Invert Q_{+} Q_{-} // X_o -> DUM_DERI+1 chrono_guess(g_spinor_field[DUM_DERI+1], mnl->pf, mnl->csg_field, mnl->csg_index_array, mnl->csg_N, mnl->csg_n, VOLUME/2, mnl->Qsq); mnl->iter1 += cg_her(g_spinor_field[DUM_DERI+1], mnl->pf, mnl->maxiter, mnl->forceprec, g_relative_precision_flag, VOLUME/2, mnl->Qsq); chrono_add_solution(g_spinor_field[DUM_DERI+1], mnl->csg_field, mnl->csg_index_array, mnl->csg_N, &mnl->csg_n, VOLUME/2); // Y_o -> DUM_DERI mnl->Qm(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1]); // apply Hopping Matrix M_{eo} // to get the even sites of X_e H_eo_sw_inv_psi(g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+1], EE, -mnl->mu); // \delta Q sandwitched by Y_o^\dagger and X_e deriv_Sb(OE, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], hf); // to get the even sites of Y_e H_eo_sw_inv_psi(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI], EE, mnl->mu); // \delta Q sandwitched by Y_e^\dagger and X_o // uses the gauge field in hf and changes the derivative fields in hf deriv_Sb(EO, g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+1], hf); // here comes the clover term... // computes the insertion matrices for S_eff // result is written to swp and swm // even/even sites sandwiched by gamma_5 Y_e and gamma_5 X_e gamma5(g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+2], VOLUME/2); sw_spinor(EO, g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+3]); // odd/odd sites sandwiched by gamma_5 Y_o and gamma_5 X_o gamma5(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI], VOLUME/2); sw_spinor(OE, g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1]); // compute the contribution for the det-part // we again compute only the insertion matrices for S_det // the result is added to swp and swm // even sites only! sw_deriv(EE, mnl->mu); // now we compute // finally, using the insertion matrices stored in swm and swp // we compute the terms F^{det} and F^{sw} at once // uses the gaugefields in hf and changes the derivative field in hf sw_all(hf, mnl->kappa, mnl->c_sw); g_mu = g_mu1; g_mu3 = 0.; boundary(g_kappa); return; }
void FirstPersonCamera::Update(double dt, vector<InteractableOBJs>&InteractablesList, vector<Building>&BuildingsList, Player &somePlayer) { Vector3 boundary(1000, 1000, 1000); speed = 30; mouseSpeed = 12; static const float CAMERA_SPEED = 50.f; //if (Application::IsKeyPressed('R')) //{ // Reset(); //} //view.y < 0.9396 && view.y > -09396 //Mouse - Shania //int Angle = 50; //horizontalAngle += mouseSpeed * dt * float(1680 / 2 - Application::mouseX); //if (verticalAngle + mouseSpeed * dt * float(1080 / 2 - Application::mouseY) < Angle && verticalAngle + mouseSpeed * dt * float(1080 / 2 - Application::mouseY) > -Angle) //{ // verticalAngle += mouseSpeed * dt * float(1080 / 2 - Application::mouseY); //} //Vector3 view(cos(Math::DegreeToRadian(verticalAngle)) * sin(Math::DegreeToRadian(horizontalAngle)), // sin(Math::DegreeToRadian(verticalAngle)), // cos(Math::DegreeToRadian(verticalAngle)) * cos(Math::DegreeToRadian(horizontalAngle))); //Vector3 right(sin(Math::DegreeToRadian(horizontalAngle - 90)), 0, cos(Math::DegreeToRadian(horizontalAngle - 90))); //up = right.Cross(view); //target = position + view.Normalized(); // Mouse - DonoDon Vector3 view = (target - position).Normalized(); float yaw = 0; float pitch = 0; yaw = (float)(mouseSpeed * dt * (1680 / 2 - Application::mouseX)); pitch = (float)(mouseSpeed * dt * (1080 / 2 - Application::mouseY)); // Mouse Mtx44 rotationYaw; rotationYaw.SetToRotation(yaw, 0, 1, 0); view = (target - position); Vector3 right = view.Cross(up); view = rotationYaw * view; target = view + position; up = rotationYaw * up; Mtx44 rotationPitch; view = (target - position); right = view.Cross(up); right.y = 0; up = right.Cross(view).Normalized(); rotationPitch.SetToRotation(pitch, right.x, right.y, right.z); view = rotationPitch * view; target = view + position; view = (target - position).Normalized(); Position camPos; // Position to check collision with if (Application::IsKeyPressed('W')) { camPos.Set(somePlayer.pos.x + view.Normalized().x, somePlayer.pos.y + view.Normalized().y, somePlayer.pos.z + view.Normalized().z); if (createBoundary(InteractablesList, BuildingsList, somePlayer, camPos)) { position.x = position.x + view.Normalized().x; // position = position + view position.z = position.z + view.Normalized().z; // position = position + view target.x = target.x + view.Normalized().x; // target = target + view target.z = target.z + view.Normalized().z; // target = target + view somePlayer.pos.x += view.Normalized().x; somePlayer.pos.z += view.Normalized().z; } } if (Application::IsKeyPressed('S')) { //camPos.Set(position.x - view.x, position.Normalized().y - view.y, position.z - view.z); camPos.Set(somePlayer.pos.x - view.Normalized().x, somePlayer.pos.y - view.Normalized().y, somePlayer.pos.z - view.Normalized().z); if (createBoundary(InteractablesList, BuildingsList, somePlayer, camPos)) { position.x = position.x - (target - position).Normalized().x; position.z = position.z - (target - position).Normalized().z; target.x = target.x - (target - position).Normalized().x; target.z = target.z - (target - position).Normalized().z; somePlayer.pos.x -= view.Normalized().x; somePlayer.pos.z -= view.Normalized().z; } } if (Application::IsKeyPressed('A')) { //camPos.Set(position.x - right.Normalized().x, position.Normalized().y - right.Normalized().y, position.z - right.Normalized().z); camPos.Set(somePlayer.pos.x - right.Normalized().x, somePlayer.pos.y - right.Normalized().y, somePlayer.pos.z - right.Normalized().z); if (createBoundary(InteractablesList, BuildingsList, somePlayer, camPos)) { position -= right.Normalized(); target -= right.Normalized(); somePlayer.pos.x -= right.Normalized().x; somePlayer.pos.z -= right.Normalized().z; } } if (Application::IsKeyPressed('D')) { //camPos.Set(position.x + right.Normalized().x, position.Normalized().y + right.Normalized().y, position.z + right.Normalized().z); camPos.Set(somePlayer.pos.x + right.Normalized().x, somePlayer.pos.y + right.Normalized().y, somePlayer.pos.z + right.Normalized().z); if (createBoundary(InteractablesList, BuildingsList, somePlayer, camPos)) { position += right.Normalized(); target += right.Normalized(); somePlayer.pos.x += right.Normalized().x; somePlayer.pos.z += right.Normalized().z; } } }
int main (int argc, char ** argv) { if (argc != 2) { std::cout << "Usage: " << argv[0] << " [depthMap.yml]" << std::endl; return 1; } IplImage * tmp = (IplImage*)cvLoad(argv[1]); cv::Mat depth (tmp); cv::Mat boundary (depth.rows, depth.cols, CV_8UC3); enum RegionType {Shadow, Veil, Object}; for (size_t j = 0; j < boundary.rows; ++j) { for (size_t i = 0; i < boundary.cols; ++i) { boundary.at<cv::Vec3b>(j, i)[0] = boundary.at<cv::Vec3b>(j, i)[1] = boundary.at<cv::Vec3b>(j, i)[2] = 0; if (depth.at<float>(j, i) <= 0) { boundary.at<cv::Vec3b>(j, i)[Shadow] = 255; } else { boundary.at<cv::Vec3b>(j, i)[Object] = 255; } } } cv::Mat mean (boundary.rows, boundary.cols, CV_32FC1); cv::Mat var (boundary.rows, boundary.cols, CV_32FC1); int window = 2; float sumVar = 0; int nVar = 0; for (size_t j = 0; j < boundary.rows; ++j) { for (size_t i = 0; i < boundary.cols; ++i) { if (boundary.at<cv::Vec3b>(j, i)[Shadow] == 255) { continue; } float sum = 0; float sum2 = 0; int n = 0; int left = MAX(0, (int)i - window); int right = MIN (boundary.cols - 1, (int)i + window); int top = MAX (0, (int)j - window); int bottom = MIN (boundary.rows - 1, (int)j + window); for (int x = left; x < right; ++x) { for (int y = top; y < bottom; ++y) { float horz = fabs(depth.at<float>(y, x) - depth.at<float>(y, x + 1)); float vert = fabs(depth.at<float>(y, x) - depth.at<float>(y + 1, x)); if (boundary.at<cv::Vec3b>(y, x + 1)[Shadow] == 0) { sum += horz; sum2 += horz*horz; ++n; } if (boundary.at<cv::Vec3b>(y + 1, x)[Shadow] == 0) { sum += vert; sum2 += vert*vert; ++n; } } } if (n) { mean.at<float>(j, i) = sum/n; var.at<float>(j, i) = sum2/n - pow (mean.at<float>(j, i), 2.0); sumVar += var.at<float>(j, i); ++nVar; } else { mean.at<float>(j, i) = 0; var.at<float>(j, i) = 0; } } } float meanVar = sumVar/nVar; for (size_t j = 0; j < boundary.rows; ++j) { for (size_t i = 0; i < boundary.cols; ++i) { if (var.at<float>(j, i) > meanVar) { boundary.at<cv::Vec3b>(j, i)[Veil] = 255; } } } cv::imwrite("foo.jpg", boundary); std::ofstream output ("foo.csv"); for (size_t j = 0; j < var.rows; ++j) { for (size_t i = 0; i < var.cols; ++i) { output << depth.at<float>(j,i) << " "; } output << std::endl; } output.close(); cvReleaseImage (&tmp); return 0; }
void PeriodicFlow<_Tesselation>::computeFacetForcesWithCache(bool onlyCache) { RTriangulation& Tri = T[currentTes].Triangulation(); CVector nullVect(0,0,0); static vector<CVector> oldForces; if (oldForces.size()<=Tri.number_of_vertices()) oldForces.resize(Tri.number_of_vertices()+1); //reset forces for (FiniteVerticesIterator v = Tri.finite_vertices_begin(); v != Tri.finite_vertices_end(); ++v) { if (noCache) {oldForces[v->info().id()]=nullVect; v->info().forces=nullVect;} else {oldForces[v->info().id()]=v->info().forces; v->info().forces=nullVect;} } CellHandle neighbourCell; VertexHandle mirrorVertex; CVector tempVect; //FIXME : Ema, be carefull with this (noCache), it needs to be turned true after retriangulation if (noCache) { for (VCellIterator cellIt=T[currentTes].cellHandles.begin(); cellIt!=T[currentTes].cellHandles.end(); cellIt++){ CellHandle& cell = *cellIt; for (int k=0;k<4;k++) cell->info().unitForceVectors[k]=nullVect; for (int j=0; j<4; j++) if (!Tri.is_infinite(cell->neighbor(j))) { // #ifdef EIGENSPARSE_LIB // if (!cell->info().Pcondition) ++nPCells; // #endif neighbourCell = cell->neighbor(j); const CVector& Surfk = cell->info().facetSurfaces[j]; //FIXME : later compute that fluidSurf only once in hydraulicRadius, for now keep full surface not modified in cell->info for comparison with other forces schemes //The ratio void surface / facet surface Real area = sqrt(Surfk.squared_length()); CVector facetNormal = Surfk/area; const std::vector<CVector>& crossSections = cell->info().facetSphereCrossSections; CVector fluidSurfk = cell->info().facetSurfaces[j]*cell->info().facetFluidSurfacesRatio[j]; /// handle fictious vertex since we can get the projected surface easily here if (cell->vertex(j)->info().isFictious) { Real projSurf=abs(Surfk[boundary(cell->vertex(j)->info().id()).coordinate]); tempVect=-projSurf*boundary(cell->vertex(j)->info().id()).normal; //define the cached value for later use with cache*p cell->info().unitForceVectors[j]=cell->info().unitForceVectors[j]+ tempVect; } /// Apply weighted forces f_k=sqRad_k/sumSqRad*f CVector facetUnitForce = -fluidSurfk*cell->info().solidSurfaces[j][3]; for (int y=0; y<3;y++) { //add to cached value cell->info().unitForceVectors[facetVertices[j][y]]=cell->info().unitForceVectors[facetVertices[j][y]]+facetUnitForce*cell->info().solidSurfaces[j][y]; //uncomment to get total force / comment to get only viscous forces (Bruno) if (!cell->vertex(facetVertices[j][y])->info().isFictious) { //add to cached value cell->info().unitForceVectors[facetVertices[j][y]]=cell->info().unitForceVectors[facetVertices[j][y]]-facetNormal*crossSections[j][y]; } } } } noCache=false;//cache should always be defined after execution of this function if (onlyCache) return; }// end if(noCache) //use cached values //First define products that will be used below for all cells: Real pDeltas [3]; for (unsigned int k=0; k<3;k++) pDeltas[k]=CellInfo::hSize[k]*CellInfo::gradP; //Then compute the forces for (VCellIterator cellIt=T[currentTes].cellHandles.begin(); cellIt!=T[currentTes].cellHandles.end(); cellIt++){ const CellHandle& cell = *cellIt; for (int yy=0;yy<4;yy++) { VertexInfo& vhi = cell->vertex(yy)->info(); Real unshiftedP = cell->info().p(); //the pressure translated to a ghost cell adjacent to the non-ghost vertex unshiftedP -= pDeltas[0]*vhi.period[0] + pDeltas[1]*vhi.period[1] +pDeltas[2]*vhi.period[2]; T[currentTes].vertexHandles[vhi.id()]->info().forces=T[currentTes].vertexHandles[vhi.id()]->info().forces + cell->info().unitForceVectors[yy]*unshiftedP; } } if (debugOut) { CVector totalForce = nullVect; for (FiniteVerticesIterator v = Tri.finite_vertices_begin(); v != Tri.finite_vertices_end(); v++) { if (!v->info().isFictious /*&& !v->info().isGhost*/ ){ totalForce = totalForce + v->info().forces;} else /*if (!v->info().isGhost)*/{ if (boundary(v->info().id()).flowCondition==1) totalForce = totalForce + v->info().forces; } } cout << "totalForce = "<< totalForce << endl;} }