inline Vector2F Vector2F::NormalizeCopy () const { float norm = Norm(); return operator/(norm); }
/*---------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { int my_rank, m, n, p, max_iter, suppress, i, total_iter, iter; double tolerance, residual, elapsed; double* temp_A; double* local_A; double* b; double* temp_b; double* x; double* xx; double* xxx; double* y; double* yy; double* yyy; double* residuals; MPI_Comm comm; MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &p); MPI_Comm_rank(comm, &my_rank); if (my_rank == 0) { n = Get_n(argc, argv); tolerance = Get_tolerance(argc, argv); max_iter = Get_max_iter(argc, argv); } MPI_Bcast(&n, 1, MPI_INT, 0, comm); MPI_Bcast(&tolerance, 1, MPI_DOUBLE, 0, comm); MPI_Bcast(&max_iter, 1, MPI_INT, 0, comm); MPI_Bcast(&suppress, 1, MPI_INT, 0, comm); if (n < 2 || tolerance == -1.0 || max_iter == -1 || suppress == -1) { if (my_rank == 0) Usage(argv[0]); MPI_Finalize(); exit(0); } b = malloc(n*sizeof(double)); temp_b = malloc(n*sizeof(double)); x = malloc(n*sizeof(double)); xx = malloc(n*sizeof(double)); xxx = malloc(n*sizeof(double)); y = malloc(n*sizeof(double)); yy = malloc(n*sizeof(double)); yyy = malloc(n*sizeof(double)); local_A = malloc((n*n/p)*sizeof(double)); if (my_rank == 0) { residuals = malloc(n*sizeof(double)); temp_A = malloc((n*n)*sizeof(double)); Read_matrix_vector(temp_A, b, n, p); printf("\n"); } MPI_Scatter(temp_A, n*n/p, MPI_DOUBLE, local_A, n*n/p, MPI_DOUBLE, 0, comm); MPI_Bcast(b, n, MPI_DOUBLE, 0, comm); MPI_Bcast(x, n, MPI_DOUBLE, 0, comm); MPI_Bcast(xx, n, MPI_DOUBLE, 0, comm); MPI_Bcast(y, n, MPI_DOUBLE, 0, comm); MPI_Bcast(yy, n, MPI_DOUBLE, 0, comm); for (i = 0; i < n; i++) temp_b[i] = b[i]; Parallel_conjugate_gradient(local_A, x, n, p, tolerance, max_iter, my_rank, comm, &residual, &elapsed, &total_iter); printf("Parallel Conjugate Gradient Method was %d.\n", total_iter); /* Parallel_cg_error(local_A, y, c, n, p, tolerance, max_iter, my_rank, comm, &residual, &elapsed, &total_iter); */ iter = 50; while ( iter <= 1000) { Parallel_conjugate_gradient(local_A, xx, n, p, tolerance, iter, my_rank, comm, &residual, &elapsed, &total_iter); Parallel_cg_error(local_A, yy, n, p, tolerance, iter, my_rank, comm); for (i = 0; i < n; i++) { xxx[i] = x[i] - xx[i]; yyy[i] = x[i] -yy[i]; } Matrix_vector(temp_A, xxx, xx, n); Matrix_vector(temp_A, yyy, yy, n); double a1 = sqrt(Dot_product(xxx, xx, n)); double a2 = sqrt(Dot_product(yyy, yy, n)); double a3 = (a2 -a1) / a1; //printf( "At iteration %d, diff is %lf\n", iter, a1 ); //printf( "At iteration %d, diff is %lf\n", iter, a2 ); printf( "%lf\n", a3 ); //printf("The a norm error definition is %lf.\n", a3); iter+=50; } if (my_rank == 0) { printf("The total number of iterations for the "); printf("Parallel Conjugate Gradient Method was %d.\n", total_iter); printf("The Parallel Conjugate Gradient Method completed in"); printf(" %.14e seconds.\n", elapsed); if (!suppress) { // printf("The solution to the linear system is:\n"); // Print_vector(x, n); } printf("The norm of the residual calculated by the "); printf("Conjugate Gradient Method was %lf.\n", residual); Matrix_vector(temp_A, x, residuals, n); for (i = 0; i < n; i++) residuals[i] = b[i] - residuals[i]; printf("The norm of the residual calculated directly by the "); printf("definition of residual is %lf.\n", sqrt(Norm(residuals, n))); } free(b); free(x); free(local_A); if (my_rank == 0) { free(residuals); free(temp_A); } MPI_Finalize(); return 0; } /* main */
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); //Do not respond to changes that have a Sync origin if(origin & ChangedOrigin::Sync) { return; } if((whichField & BaseGeometryFieldMask) && getBaseGeometry() != NULL) { if(getBaseGeometry()->getTypes() != NULL) { setTypes(getBaseGeometry()->getTypes()); } if(getBaseGeometry()->getLengths() != NULL) { setLengths(getBaseGeometry()->getLengths()); } if(getBaseGeometry()->getPositions() != NULL) { GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone()); setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos)); } if(getBaseGeometry()->getNormals() != NULL) { GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone()); setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm)); } if(getBaseGeometry()->getColors() != NULL) { setColors(getBaseGeometry()->getColors()); } if(getBaseGeometry()->getSecondaryColors() != NULL) { setSecondaryColors(getBaseGeometry()->getSecondaryColors()); } if(getBaseGeometry()->getTexCoords() != NULL) { setTexCoords(getBaseGeometry()->getTexCoords()); } if(getBaseGeometry()->getTexCoords1() != NULL) { setTexCoords1(getBaseGeometry()->getTexCoords1()); } if(getBaseGeometry()->getTexCoords2() != NULL) { setTexCoords2(getBaseGeometry()->getTexCoords2()); } if(getBaseGeometry()->getTexCoords3() != NULL) { setTexCoords3(getBaseGeometry()->getTexCoords3()); } if(getBaseGeometry()->getTexCoords4() != NULL) { setTexCoords4(getBaseGeometry()->getTexCoords4()); } if(getBaseGeometry()->getTexCoords5() != NULL) { setTexCoords5(getBaseGeometry()->getTexCoords5()); } if(getBaseGeometry()->getTexCoords6() != NULL) { setTexCoords6(getBaseGeometry()->getTexCoords6()); } if(getBaseGeometry()->getTexCoords7() != NULL) { setTexCoords7(getBaseGeometry()->getTexCoords7()); } if(getBaseGeometry()->getIndices() != NULL) { setIndices(getBaseGeometry()->getIndices()); } setMaterial(getBaseGeometry()->getMaterial()); } if(whichField & InternalJointsFieldMask) { _JointPoseTransforms.resize(getNumJoints()); } if( (whichField & BaseGeometryFieldMask) || (whichField & InternalJointsFieldMask) || (whichField & InternalWeightIndexesFieldMask) || (whichField & InternalWeightsFieldMask) || (whichField & BindTransformationFieldMask)) { if(getNumJoints() > 0) { _JointPoseTransforms.resize(getNumJoints()); calculatePositions(); } } }
void Game_Engine::Rocket_Place(const int &Player_number) { if (!this->Current_Game.Players[Player_number].Rocket_Ammount) return; this->Current_Game.Players[Player_number].Rocket_Ammount--; Rocket _Rock(this->Current_Game.Players[Player_number].MyCycle.Current_Point + (1.2*this->Constants->LightCycle_Length)*(Norm(this->Current_Game.Players[Player_number].MyCycle.Direction)), this->Current_Game.Players[Player_number].MyCycle.Direction, this->Constants->Rocket_Speed, this->Constants->Rocket_Length, this->Constants->Rocket_Radius ); _Rock.Owner = Player_number; this->Current_Game.Rockets.push_back(_Rock); // Rocket _Rock2(this->Current_Game.Players[Player_number].MyCycle.Current_Point, this->Current_Game.Players[Player_number].MyCycle.Direction, this->Constants->Rocket_Speed, this->Constants->Rocket_Length, this->Constants->Rocket_Radius); this->Game_Changes.Placed_Rocket.push_back(_Rock); return; }
void FVMesh3D::complete_data() { // initialize the list of cell for each vertex for(size_t i=0;i<_nb_vertex;i++) { _vertex[i].nb_cell=0; } // we have to determine the list of neighbor cell for each vertex further // compute the centroid and length of edge for(size_t i=0;i<_nb_edge;i++) { _edge[i].centroid=(_edge[i].firstVertex->coord+_edge[i].secondVertex->coord)*(double)0.5; FVPoint3D<double> u; u=_edge[i].firstVertex->coord-_edge[i].secondVertex->coord; _edge[i].length=Norm(u); } // We have completly finish with the edge // compute geometric stuff for the face for(size_t i=0;i<_nb_face;i++) { _face[i].perimeter=0.; _face[i].area=0.; _face[i].centroid=0.; // conpute perimeter or the face for(size_t j=0;j<_face[i].nb_edge;j++) { _face[i].perimeter+=_face[i].edge[j]->length; _face[i].centroid+=_face[i].edge[j]->centroid*_face[i].edge[j]->length; } // compute the centroid of the face _face[i].centroid/=_face[i].perimeter; // compute the area of the face for(size_t j=0;j<_face[i].nb_edge;j++) { FVPoint3D<double> u,v,w; u=_face[i].edge[j]->firstVertex->coord-_face[i].centroid; v=_face[i].edge[j]->secondVertex->coord-_face[i].centroid; w=CrossProduct(u,v); _face[i].area+=Norm(w)*0.5; } // build the list of vertex pointer for the face pos_v=0; for(size_t j=0;j<_face[i].nb_edge;j++) { bool _still_exist; _still_exist=false; for(size_t k=0;k<pos_v;k++) if(_face[i].edge[j]->firstVertex==_face[i].vertex[k]) _still_exist=true; if(!_still_exist) {_face[i].vertex[pos_v]=_face[i].edge[j]->firstVertex;pos_v++;} _still_exist=false; for(size_t k=0;k<pos_v;k++) if(_face[i].edge[j]->secondVertex==_face[i].vertex[k]) _still_exist=true; if(!_still_exist) {_face[i].vertex[pos_v]=_face[i].edge[j]->secondVertex;pos_v++;} } _face[i].nb_vertex=pos_v; } // left and right cell, normal vector will be determined after the loop on cells // end loop on the faces for(size_t i=0;i<_nb_cell;i++) { _cell[i].surface=0.; _cell[i].volume=0.; _cell[i].centroid=0.; // conpute surface of the cell // determine the left and right cell for the face for(size_t j=0;j<_cell[i].nb_face;j++) { size_t pos; _cell[i].surface+=_cell[i].face[j]->area; _cell[i].centroid+=_cell[i].face[j]->centroid*_cell[i].face[j]->area; pos=_cell[i].face[j]->label-1; if(!(_face[pos].leftCell) ) _face[pos].leftCell=&(_cell[i]); else _face[pos].rightCell=&(_cell[i]); } // compute the centroid of the cell _cell[i].centroid/=_cell[i].surface; // compute the cell2face vector // compute the volume of the cell for(size_t j=0;j<_cell[i].nb_face;j++) { _cell[i].cell2face[j]= _cell[i].face[j]->centroid-_cell[i].centroid; for(size_t k=0;k<_cell[i].face[j]->nb_edge;k++) { FVPoint3D<double> u,v,w; u=_cell[i].cell2face[j]; v=_cell[i].face[j]->edge[k]->firstVertex->coord-_cell[i].centroid; w=_cell[i].face[j]->edge[k]->secondVertex->coord-_cell[i].centroid; _cell[i].volume+=fabs(Det(u,v,w))/6; } } // build the list of the vertex pointer for a cell pos_v=0; for(size_t j=0;j<_cell[i].nb_face;j++) for(size_t k=0;k<_cell[i].face[j]->nb_edge;k++) { bool _still_exist; _still_exist=false; for(size_t m=0;m<pos_v;m++) if(_cell[i].face[j]->edge[k]->firstVertex==_cell[i].vertex[m]) _still_exist=true; if(!_still_exist) {_cell[i].vertex[pos_v]=_cell[i].face[j]->edge[k]->firstVertex;pos_v++;} _still_exist=false; for(size_t m=0;m<pos_v;m++) if(_cell[i].face[j]->edge[k]->secondVertex==_cell[i].vertex[m]) _still_exist=true; if(!_still_exist) {_cell[i].vertex[pos_v]=_cell[i].face[j]->edge[k]->secondVertex;pos_v++;} } _cell[i].nb_vertex=pos_v; // build the list of the cell pointer for a vertex for(size_t j=0;j<_cell[i].nb_vertex;j++) { size_t pos; pos=_cell[i].vertex[j]->label-1; _vertex[pos].cell[_vertex[pos].nb_cell]=&(_cell[i]); _vertex[pos].nb_cell++; if(_vertex[pos].nb_cell>=NB_CELL_PER_VERTEX_3D) cout<<"Warning, overflow in class FVVertex3D, too many Cells, found "<<_vertex[pos].nb_cell<<endl; } } // we compute the normal from left to rigth for each sub-triangle _boundary_face.resize(0); _nb_boundary_face=0; for(size_t i=0;i<_nb_face;i++) { for(size_t j=0;j<_face[i].nb_edge;j++) { FVPoint3D<double> u,v,w; double no; u=_face[i].edge[j]->firstVertex->coord-_face[i].centroid; v=_face[i].edge[j]->secondVertex->coord-_face[i].centroid; w=CrossProduct(u,v); no=Norm(w); w/=no; _face[i].normal[j]=w; u=_face[i].centroid-_face[i].leftCell->centroid; if(w*u<0) _face[i].normal[j]*=-1.; } // build the list of boundary face if(! (_face[i].rightCell)) {_boundary_face.push_back(&(_face[i]));_nb_boundary_face++;} } }
void SolveSystemTransient(REAL deltaT,REAL maxTime, TPZAnalysis *NonLinearAn, TPZCompMesh* CMesh) { TPZFMatrix<STATE> Patn; TPZFMatrix<STATE> PatnMinusOne; // { // TPZBFileStream load; // load.OpenRead("MultiphaseSaturationSol.bin"); // SolutiontoLoad.Read(load,0); // meshvec[2]->LoadSolution(SolutiontoLoad); // TPZBuildMultiphysicsMesh::TransferFromMeshes(meshvec, mphysics); // } std::string OutPutFile = "WaveSolution"; TPZMaterial *mat1 = CMesh->FindMaterial(1); TPZLinearWave * material1 = dynamic_cast<TPZLinearWave *>(mat1); // TPZMultiphase * material2 = dynamic_cast<TPZMultiphase *>(mat2); material1->SetTimeStep(deltaT); // Starting Newton Iterations TPZFMatrix<STATE> DeltaX = CMesh->Solution(); TPZFMatrix<STATE> Uatn = CMesh->Solution(); TPZFMatrix<STATE> Uatk = CMesh->Solution(); REAL TimeValue = 0.0; REAL Tolerance = 1.0e-7; int cent = 0; int MaxIterations = 50; TimeValue = cent*deltaT; REAL NormValue =1.0; bool StopCriteria = false; TPZFMatrix<STATE> RhsAtnMinusOne, RhsAtn, RhsAtnPlusOne, Residual; std::string outputfile; outputfile = OutPutFile; std::stringstream outputfiletemp; outputfiletemp << outputfile << ".vtk"; std::string plotfile = outputfiletemp.str(); PosProcess(material1->Dimension(),*NonLinearAn,outputfile,2); std::cout << " Starting the time computations. " << std::endl; while (TimeValue < maxTime) { material1->SetMinusOneState(); CMesh->LoadSolution(PatnMinusOne); NonLinearAn->AssembleResidual(); RhsAtnMinusOne = NonLinearAn->Rhs(); material1->SetNState(); CMesh->LoadSolution(Patn); NonLinearAn->AssembleResidual(); RhsAtn = NonLinearAn->Rhs(); material1->SetPlusOneState(); CMesh->LoadSolution(Patn); NonLinearAn->Assemble(); RhsAtnPlusOne = NonLinearAn->Rhs(); Residual= RhsAtnMinusOne + RhsAtn + RhsAtnPlusOne; NormValue = Norm(Residual); int iterations= 0; while (NormValue > Tolerance) { Residual*=-1.0; NonLinearAn->Rhs()=Residual; NonLinearAn->Solve(); DeltaX = NonLinearAn->Solution(); Uatk = (Uatn + DeltaX); CMesh->LoadSolution(Uatn + DeltaX); #ifdef LOG4CXX if(logdata->isDebugEnabled()) { std::stringstream sout; sout.precision(20); Residual.Print(sout); Uatk.Print(sout); LOGPZ_DEBUG(logdata,sout.str()); } #endif material1->SetPlusOneState(); NonLinearAn->Assemble(); RhsAtnPlusOne = NonLinearAn->Rhs(); Residual= RhsAtnMinusOne + RhsAtn + RhsAtnPlusOne; NormValue = Norm(Residual); #ifdef LOG4CXX if(logdata->isDebugEnabled()) { std::stringstream sout; sout.precision(15); Uatk.Print(sout); Residual.Print("Res = ",sout,EMathematicaInput); LOGPZ_DEBUG(logdata,sout.str()); } #endif iterations++; std::cout << " Newton's Iteration = : " << iterations << " L2 norm = : " << NormValue << std::endl; if (iterations == MaxIterations) { StopCriteria = true; std::cout << " Time Step number = : " << iterations << "\n Exceed max iterations numbers = : " << MaxIterations << std::endl; break; } Uatn = Uatk; } outputfile = OutPutFile; std::stringstream outputfiletemp; outputfiletemp << outputfile << ".vtk"; std::string plotfile = outputfiletemp.str(); PosProcess(material1->Dimension(),*NonLinearAn,outputfile,2); if (StopCriteria) { std::cout << " Newton's Iteration = : " << iterations << " L2 norm = : " << NormValue << std::endl; break; } cent++; TimeValue = cent*deltaT; std::cout << " Time Step : " << cent << " Time : " << TimeValue << std::endl; PatnMinusOne = Patn; Patn = Uatk; } }
float Quaternion::Magnitude() const { return Sqrt(Norm()); }
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if((whichField & BaseGeometryFieldMask) && getBaseGeometry() != NULL) { if(getBaseGeometry()->getTypes() != NULL) { setTypes(getBaseGeometry()->getTypes()); } if(getBaseGeometry()->getLengths() != NULL) { setLengths(getBaseGeometry()->getLengths()); } if(getBaseGeometry()->getPositions() != NULL) { GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone()); setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos)); } if(getBaseGeometry()->getNormals() != NULL) { GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone()); setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm)); } if(getBaseGeometry()->getColors() != NULL) { setColors(getBaseGeometry()->getColors()); } if(getBaseGeometry()->getSecondaryColors() != NULL) { setSecondaryColors(getBaseGeometry()->getSecondaryColors()); } if(getBaseGeometry()->getTexCoords() != NULL) { setTexCoords(getBaseGeometry()->getTexCoords()); } if(getBaseGeometry()->getTexCoords1() != NULL) { setTexCoords1(getBaseGeometry()->getTexCoords1()); } if(getBaseGeometry()->getTexCoords2() != NULL) { setTexCoords2(getBaseGeometry()->getTexCoords2()); } if(getBaseGeometry()->getTexCoords3() != NULL) { setTexCoords3(getBaseGeometry()->getTexCoords3()); } if(getBaseGeometry()->getTexCoords4() != NULL) { setTexCoords4(getBaseGeometry()->getTexCoords4()); } if(getBaseGeometry()->getTexCoords5() != NULL) { setTexCoords5(getBaseGeometry()->getTexCoords5()); } if(getBaseGeometry()->getTexCoords6() != NULL) { setTexCoords6(getBaseGeometry()->getTexCoords6()); } if(getBaseGeometry()->getTexCoords7() != NULL) { setTexCoords7(getBaseGeometry()->getTexCoords7()); } if(getBaseGeometry()->getIndices() != NULL) { setIndices(getBaseGeometry()->getIndices()); } setMaterial(getBaseGeometry()->getMaterial()); } if((whichField & JointsFieldMask) || (whichField & PositionIndexesFieldMask) || (whichField & BlendAmountsFieldMask)) { calculatePositions(); } if(whichField & SkeletonsFieldMask) { for(std::vector<EventConnection>::iterator Itor(_SkeletonListenerConnections.begin()) ; Itor != _SkeletonListenerConnections.end() ; ++Itor) { Itor->disconnect(); } _SkeletonListenerConnections.clear(); for(UInt32 i(0) ; i<getMFSkeletons()->size() ; ++i) { _SkeletonListenerConnections.push_back(getSkeletons(i)->addSkeletonListener(this)); } } }
double Cosine(value* x, value* y){ double dist; dist = InnerProductCosine(x->content,y->content)/(Norm(x->content)*Norm(y->content)); return - (dist -1 ); }
/* Compare two vectors and check if they are the same */ int compareVectors(vec3 a, vec3 b){ if(Norm(VectorSub(a,b)) < 0.00001){ return 1; } return 0; }
void March(GLfloat **mTris, GLfloat **mNorms,Tetra *tetras) { cell = realloc(cell, DIM*DIM*DIM*sizeof(Cell)); mc.pos = SetVector(XMIN, YMIN, ZMIN); int i; free(*mTris); free(*mNorms); *mTris = malloc(0); *mNorms = malloc(0); free(verts); verts = malloc(0); vertListSize = 0; // loop through all cells and calculate number of particles for(i = 0; i < DIM*DIM*DIM; i++) { cell[i].nrParts = 0; cell[i].state = 0; int j; for(j = 0; j < NO_OBJECTS; j++) { // Check if particle is inside this cell //OBS! Will NOT register both cells on cell border if(tetras[j].pos.x >= mc.pos.x && tetras[j].pos.x < (mc.pos.x + cellSize) && tetras[j].pos.y >= mc.pos.y && tetras[j].pos.y < (mc.pos.y + cellSize) && tetras[j].pos.z >= mc.pos.z && tetras[j].pos.z < (mc.pos.z + cellSize)) { // If particle is inside cell add to this cells particle count cell[i].nrParts++; tetras[j].whichCell = i; } } if(cell[i].nrParts >= isolevel) { // If threshold is reached set state to 1!!!!!!!!!!! cell[i].state = 1; } /* Step through cells using the position and check against the borders. When XMAX position is reached, step up in y direction and reset xpos. */ mc.pos.x += cellSize; if(mc.pos.x == XMAX) { mc.pos.x = XMIN; mc.pos.y += cellSize; if(mc.pos.y == YMAX) { mc.pos.y = YMIN; mc.pos.z += cellSize; } } } int m, j, x, y, z, Case; y=z=0; x=-1; vec3 edge[12]; int count = 0; float xCell, yCell, zCell; for(j=0; j< DIM * DIM * DIM; j++) { //detta gör vi för att inte alla hörnpunkter ska få värdet 1 for(m=0; m<8; m++) cubeCorners[m] = 0; x++; if(x == DIM) { y++; x=0; } if(y == DIM) { z++; x=y=0; } // nollställ density for(m = 0; m < 24; m++) density[m] = 0; //Kolla mot kuber som ligger "vägg i vägg" med vår kub // Kolla även denstiy så den får rätt antal partiklar mot varje hörn if(x!=0 && cell[j-1].state == 1) { cubeCorners[0] = 1; density[0] += cell[j-1].nrParts; cubeCorners[3] = 8; density[9] += cell[j-1].nrParts; cubeCorners[4] = 16; density[12] += cell[j-1].nrParts; cubeCorners[7] = 128; density[21] += cell[j-1].nrParts; } if(x!=DIM-1 && cell[j+1].state == 1) { cubeCorners[1] = 2; density[3] += cell[j+1].nrParts; cubeCorners[2] = 4; density[6] += cell[j+1].nrParts; cubeCorners[5] = 32; density[15] += cell[j+1].nrParts; cubeCorners[6] = 64; density[18] += cell[j+1].nrParts; } if(y!=0 && cell[j-DIM].state == 1) { cubeCorners[0] = 1; density[1] += cell[j-DIM].nrParts; cubeCorners[1] = 2; density[4] += cell[j-DIM].nrParts; cubeCorners[2] = 4; density[7] += cell[j-DIM].nrParts; cubeCorners[3] = 8; density[10] += cell[j-DIM].nrParts; } if(y!=DIM-1 && cell[j+DIM].state == 1) { cubeCorners[4] = 16; density[13] += cell[j+DIM].nrParts; cubeCorners[5] = 32; density[16] += cell[j+DIM].nrParts; cubeCorners[6] = 64; density[19] += cell[j+DIM].nrParts; cubeCorners[7] = 128; density[22] += cell[j+DIM].nrParts; } if(z!=0 && cell[j-DIM*DIM].state == 1) { cubeCorners[0] = 1; density[2] += cell[j-DIM*DIM].nrParts; cubeCorners[1] = 2; density[5] += cell[j-DIM*DIM].nrParts; cubeCorners[4] = 16; density[14] += cell[j-DIM*DIM].nrParts; cubeCorners[5] = 32; density[17] += cell[j-DIM*DIM].nrParts; } if(z!=DIM-1 && cell[j+DIM*DIM].state == 1) { cubeCorners[2] = 4; density[8] += cell[j+DIM*DIM].nrParts; cubeCorners[3] = 8; density[11] += cell[j+DIM*DIM].nrParts; cubeCorners[6] = 64; density[20] += cell[j+DIM*DIM].nrParts; cubeCorners[7] = 128; density[23] += cell[j+DIM*DIM].nrParts; } //Kolla kuber som delar en edge med vår kub if(x!=0 && y!=0 && cell[j-DIM - 1].state == 1) { cubeCorners[0] = 1; density[0] += cell[j-DIM-1].nrParts; density[1] += cell[j-DIM-1].nrParts; cubeCorners[3] = 8; density[9] += cell[j-DIM-1].nrParts; density[10] += cell[j-DIM-1].nrParts; } if(x!=DIM-1 && y!=0 && cell[j-DIM + 1].state == 1) { cubeCorners[1] = 2; density[3] += cell[j-DIM+1].nrParts; density[4] += cell[j-DIM+1].nrParts; cubeCorners[2] = 4; density[6] += cell[j-DIM+1].nrParts; density[7] += cell[j-DIM+1].nrParts; } if(y!=0 && z!=0 && cell[j-DIM - DIM*DIM].state == 1) { cubeCorners[0] = 1; density[1] += cell[j-DIM - DIM*DIM].nrParts; density[2] += cell[j-DIM - DIM*DIM].nrParts; cubeCorners[1] = 2; density[4] += cell[j-DIM - DIM*DIM].nrParts; density[5] += cell[j-DIM - DIM*DIM].nrParts; } if(y!=0 && z!=DIM-1 && cell[j-DIM + DIM*DIM].state == 1) { cubeCorners[2] = 4; density[7] += cell[j-DIM + DIM*DIM].nrParts; density[8] += cell[j-DIM + DIM*DIM].nrParts; cubeCorners[3] = 8; density[10] += cell[j-DIM + DIM*DIM].nrParts; density[11] += cell[j-DIM + DIM*DIM].nrParts; } if(x!=0 && y!=DIM-1 && cell[j+DIM - 1].state == 1) { cubeCorners[4] = 16; density[12] += cell[j+DIM - 1].nrParts; density[13] += cell[j+DIM - 1].nrParts; cubeCorners[7] = 128; density[21] += cell[j+DIM - 1].nrParts; density[22] += cell[j+DIM - 1].nrParts; } if(x!=DIM-1 && y!=DIM-1 && cell[j+DIM + 1].state == 1) { cubeCorners[5] = 32; density[15] += cell[j+DIM + 1].nrParts; density[16] += cell[j+DIM + 1].nrParts; cubeCorners[6] = 64; density[18] += cell[j+DIM + 1].nrParts; density[19] += cell[j+DIM + 1].nrParts; } if(y!=DIM-1 && z!=0 && cell[j+DIM - DIM*DIM].state == 1) { cubeCorners[4] = 16; density[13] += cell[j+DIM - DIM*DIM].nrParts; density[14] += cell[j+DIM - DIM*DIM].nrParts; cubeCorners[5] = 32; density[16] += cell[j+DIM - DIM*DIM].nrParts; density[17] += cell[j+DIM - DIM*DIM].nrParts; } if(y!=DIM-1 && z!=DIM-1 && cell[j+DIM + DIM*DIM].state == 1) { cubeCorners[6] = 64; density[19] += cell[j+DIM + DIM*DIM].nrParts; density[20] += cell[j+DIM + DIM*DIM].nrParts; cubeCorners[7] = 128; density[22] += cell[j+DIM + DIM*DIM].nrParts; density[23] += cell[j+DIM + DIM*DIM].nrParts; } if(x!=0 && z!=0 && cell[j-1 - DIM*DIM].state == 1) { cubeCorners[0] = 1; density[0] += cell[j-1 - DIM*DIM].nrParts; density[2] += cell[j-1 - DIM*DIM].nrParts; cubeCorners[4] = 16; density[12] += cell[j-1 - DIM*DIM].nrParts; density[14] += cell[j-1 - DIM*DIM].nrParts; } if(x!=DIM-1 && z!=0 && cell[j+1 - DIM*DIM].state == 1) { cubeCorners[1] = 2; density[3] += cell[j+1 - DIM*DIM].nrParts; density[5] += cell[j+1 - DIM*DIM].nrParts; cubeCorners[5] = 32; density[15] += cell[j+1 - DIM*DIM].nrParts; density[17] += cell[j+1 - DIM*DIM].nrParts; } if(x!=0 && z!=DIM-1 && cell[j-1 + DIM*DIM].state == 1) { cubeCorners[7] = 128; density[21] += cell[j-1 + DIM*DIM].nrParts; density[23] += cell[j-1 + DIM*DIM].nrParts; cubeCorners[3] = 8; density[9] += cell[j-1 + DIM*DIM].nrParts; density[11] += cell[j-1 + DIM*DIM].nrParts; } if(x!=DIM-1 && z!=DIM-1 && cell[j+1 + DIM*DIM].state == 1) { cubeCorners[6] = 64; density[18] += cell[j+1 + DIM*DIM].nrParts; density[20] += cell[j+1 + DIM*DIM].nrParts; cubeCorners[2] = 4; density[6] += cell[j+1 + DIM*DIM].nrParts; density[8] += cell[j+1 + DIM*DIM].nrParts; } //Kollar kuber som delar hörnpunkt med vår kub if(x!=0 && y!=0 && z!=0 && cell[j-1 - DIM - DIM*DIM].state == 1) { cubeCorners[0] = 1; density[0] += cell[j-1 - DIM - DIM*DIM].nrParts; density[1] += cell[j-1 - DIM - DIM*DIM].nrParts; density[2] += cell[j-1 - DIM - DIM*DIM].nrParts; } if(x!=DIM-1 && y!=0 && z!=0 && cell[j+1 - DIM - DIM*DIM].state == 1) { cubeCorners[1] = 2; density[3] += cell[j+1 - DIM - DIM*DIM].nrParts; density[4] += cell[j+1 - DIM - DIM*DIM].nrParts; density[5] += cell[j+1 - DIM - DIM*DIM].nrParts; } if(x!=0 && y!=0 && z!=DIM-1 && cell[j-1 - DIM + DIM*DIM].state == 1) { cubeCorners[3] = 8; density[9] += cell[j-1 - DIM + DIM*DIM].nrParts; density[10] += cell[j-1 - DIM + DIM*DIM].nrParts; density[11] += cell[j-1 - DIM + DIM*DIM].nrParts; } if(x!=DIM-1 && y!=0 && z!=DIM-1 && cell[j+1 - DIM + DIM*DIM].state == 1) { cubeCorners[2] = 4; density[6] += cell[j+1 - DIM + DIM*DIM].nrParts; density[7] += cell[j+1 - DIM + DIM*DIM].nrParts; density[8] += cell[j+1 - DIM + DIM*DIM].nrParts; } if(x!=0 && y!=DIM-1 && z!=0 && cell[j-1 + DIM - DIM*DIM].state == 1) { cubeCorners[4] = 16; density[12] += cell[j-1 + DIM - DIM*DIM].nrParts; density[13] += cell[j-1 + DIM - DIM*DIM].nrParts; density[14] += cell[j-1 + DIM - DIM*DIM].nrParts; } if(x!=DIM-1 && y!=DIM-1 && z!=0 && cell[j+1 + DIM - DIM*DIM].state == 1) { cubeCorners[5] = 32; density[15] += cell[j+1 + DIM - DIM*DIM].nrParts; density[16] += cell[j+1 + DIM - DIM*DIM].nrParts; density[17] += cell[j+1 + DIM - DIM*DIM].nrParts; } if(x!=0 && y!=DIM-1 && z!=DIM-1 && cell[j-1 + DIM + DIM*DIM].state == 1) { cubeCorners[7] = 128; density[21] += cell[j-1 + DIM + DIM*DIM].nrParts; density[22] += cell[j-1 + DIM + DIM*DIM].nrParts; density[23] += cell[j-1 + DIM + DIM*DIM].nrParts; } if(x!=DIM-1 && y!=DIM-1 && z!=DIM-1 && cell[j+1 + DIM + DIM*DIM].state == 1) { cubeCorners[6] = 64; density[18] += cell[j+1 + DIM + DIM*DIM].nrParts; density[19] += cell[j+1 + DIM + DIM*DIM].nrParts; density[20] += cell[j+1 + DIM + DIM*DIM].nrParts; } int k; Case = 0; for(k = 0; k<8; k++) { Case += cubeCorners[k]; } //vart ligger edgesen i världen // Ersätta detta med en loop ? if(interOn){ edge[0] = SetVector( interpolate(-1.0f+x*cellSize, -1.0f+x*cellSize+cellSize, density[0], density[3]) , -1.0f+y*cellSize, -1.0f+z*cellSize); edge[1] = SetVector(-1.0f+(x+1)*cellSize, -1.0f+y*cellSize, interpolate(-1.0f+z*cellSize, -1.0f+z*cellSize + cellSize, density[5], density[8])); edge[2] = SetVector( interpolate(-1.0f+x*cellSize, -1.0f+x*cellSize + cellSize, density[9], density[6]) , -1.0f+y*cellSize, -1.0f+(z+1)*cellSize); edge[3] = SetVector(-1.0f+x*cellSize, -1.0f+y*cellSize, interpolate(-1.0f+z*cellSize, -1.0f+z*cellSize + cellSize, density[2], density[11])); //toppen av cuben edge[4] = SetVector(interpolate(-1.0f+x*cellSize, -1.0f+x*cellSize + cellSize, density[12], density[15]) , -1.0f+(y+1)*cellSize, -1.0f+z*cellSize); edge[5] = SetVector(-1.0f+(x+1)*cellSize, -1.0f+(y+1)*cellSize, interpolate(-1.0f+z*cellSize, -1.0f+z*cellSize + cellSize, density[17], density[20])); edge[6] = SetVector(interpolate(-1.0f+x*cellSize, -1.0f+x*cellSize + cellSize, density[21], density[18]) , -1.0f+(y+1)*cellSize, -1.0f+(z+1)*cellSize); edge[7] = SetVector(-1.0f+x*cellSize, -1.0f+(y+1)*cellSize, interpolate(-1.0f+z*cellSize, -1.0f+z*cellSize+cellSize, density[14], density[23])); //sidorna av cuben edge[8] = SetVector(-1.0f+x*cellSize, interpolate(-1.0f+y*cellSize, -1.0f+y*cellSize+cellSize, density[1], density[13]) , -1.0f+z*cellSize); edge[9] = SetVector(-1.0f+(x+1)*cellSize, interpolate(-1.0f+y*cellSize, -1.0f+y*cellSize+cellSize, density[4], density[16]) , -1.0f+z*cellSize); edge[10] = SetVector(-1.0f+(x+1)*cellSize, interpolate(-1.0f+y*cellSize, -1.0f+y*cellSize+cellSize, density[7], density[19]) , -1.0f+(z+1)*cellSize); edge[11] = SetVector(-1.0f+x*cellSize, interpolate(-1.0f+y*cellSize, -1.0f+y*cellSize+cellSize, density[10], density[22]) , -1.0f+(z+1)*cellSize); }else{ yCell = y*cellSize; xCell = x*cellSize; zCell = z*cellSize; edge[0] = SetVector(-1.0f+xCell+halfSize, -1.0f+ yCell, -1.0f+zCell); edge[1] = SetVector(-1.0f+xCell +cellSize, -1.0f+ yCell, -1.0f+zCell+halfSize); edge[2] = SetVector(-1.0f+xCell+halfSize, -1.0f+ yCell, -1.0f+zCell + cellSize); edge[3] = SetVector(-1.0f+xCell, -1.0f+ yCell, -1.0f+zCell+halfSize); //toppen av cuben edge[4] = SetVector(-1.0f+xCell+halfSize, -1.0f+yCell + cellSize, -1.0f+zCell); edge[5] = SetVector(-1.0f+xCell + cellSize, -1.0f+yCell + cellSize, -1.0f+zCell+halfSize); edge[6] = SetVector(-1.0f+xCell+halfSize, -1.0f+yCell + cellSize, -1.0f+zCell + cellSize); edge[7] = SetVector(-1.0f+xCell, -1.0f+yCell + cellSize, -1.0f+zCell+halfSize); //sidorna av cuben edge[8] = SetVector(-1.0f+xCell, -1.0f+ yCell+halfSize, -1.0f+zCell); edge[9] = SetVector(-1.0f+xCell + cellSize, -1.0f+ yCell+halfSize, -1.0f+zCell); edge[10] = SetVector(-1.0f+xCell +cellSize, -1.0f+ yCell+halfSize, -1.0f+zCell + cellSize); edge[11] = SetVector(-1.0f+xCell, -1.0f+ yCell+halfSize, -1.0f+zCell + cellSize); } //hämta vilket case int tmp; for(k = 0; k<16; k++) { tmp = triTable[Case][k]; if(tmp != -1) { (*mTris) = realloc((*mTris),(count+3) * sizeof(GLfloat)); /* give the pointer some memory */ /* Here one could save the points via index. If the point already exists. Use the index. Otherwise add point to list and then use the index. */ (*mTris)[count] = edge[tmp].x; count++; (*mTris)[count] = edge[tmp].y; count++; (*mTris)[count] = edge[tmp].z; count++; //////////////////////////////////////////////////////////////////////// int ind = vertIndex(edge[tmp]); if(ind == -1){ verts = realloc(verts, (vertListSize+1) * sizeof(Vertlist)); verts[vertListSize].position = SetVector(edge[tmp].x, edge[tmp].y, edge[tmp].z); verts[vertListSize].normal = SetVector(0.0f, 0.0f, 0.0f); verts[vertListSize].nr = 1; vertListSize++; }else{ verts[ind].nr++; //printf("%i \n", ind); } //////////////////////////////////////////////////////////////////////// } else k=15; } } //printf("found a total of %i vertices \n\n", vertListSize); int normalCount = 0; vec3 normal, u, v, v1, v2; //Index of the normal int normInd; (*mNorms) = realloc((*mNorms),count * sizeof(GLfloat)); while(normalCount < count) { v1 = SetVector((*mTris)[normalCount], (*mTris)[normalCount+1], (*mTris)[normalCount+2]); v2 = SetVector((*mTris)[normalCount+3], (*mTris)[normalCount+4], (*mTris)[normalCount+5]); u = VectorSub(v2, v1); v2 = SetVector((*mTris)[normalCount+6], (*mTris)[normalCount+7], (*mTris)[normalCount+8]); v = Normalize(VectorSub(v2, v1)); normal = Normalize(CrossProduct(u, v)); (*mNorms)[normalCount] = normal.x; (*mNorms)[normalCount+1] = normal.y; (*mNorms)[normalCount+2] = normal.z; (*mNorms)[normalCount+3] = normal.x; (*mNorms)[normalCount+4] = normal.y; (*mNorms)[normalCount+5] = normal.z; (*mNorms)[normalCount+6] = normal.x; (*mNorms)[normalCount+7] = normal.y; (*mNorms)[normalCount+8] = normal.z; /* /*Find the index of this normal with help of vertex. Then add this normal to a summed normal.*/ if(vertNormOn && Norm(normal) > 0.0001){ normInd = vertIndex(SetVector((*mTris)[normalCount], (*mTris)[normalCount+1], (*mTris)[normalCount+2])); verts[normInd].normal = VectorAdd(verts[normInd].normal, SetVector(normal.x, normal.y, normal.z)); normInd = vertIndex(SetVector((*mTris)[normalCount+3], (*mTris)[normalCount+4], (*mTris)[normalCount+5])); verts[normInd].normal = VectorAdd(verts[normInd].normal, SetVector(normal.x, normal.y, normal.z)); normInd = vertIndex(SetVector((*mTris)[normalCount+6], (*mTris)[normalCount+7], (*mTris)[normalCount+8])); verts[normInd].normal = VectorAdd(verts[normInd].normal, SetVector(normal.x, normal.y, normal.z)); //printf("normal is %f, %f, %f ", normal.x, normal.y, normal.z); } normalCount+=9; } //printf("%s", "\n\n"); /* Normals for all indices have been calculated. Now one could add up all normals sharing a vertex. Then divide with number of vertices or normalize. Then set normals for all with the same index in the vertex list. 1. Get all normals and divide by number of vertices sharing that normal and then normalize. Klar 2. Take one point and find its index 3. Use index to get new normal */ if(vertNormOn){ int k; for(k=0; k<vertListSize; k++){ verts[k].normal.x = verts[k].normal.x / verts[k].nr; verts[k].normal.y = verts[k].normal.y / verts[k].nr; verts[k].normal.z = verts[k].normal.z / verts[k].nr; verts[k].normal = Normalize(verts[k].normal); //printf("New normal is %f, %f, %f Number of normals was %i \n", verts[k].normal.x, verts[k].normal.y, verts[k].normal.z, verts[k].nr); } int ind; for(k=0; k<count; k=k+3){ ind = vertIndex(SetVector((*mTris)[k], (*mTris)[k+1], (*mTris)[k+2])); (*mNorms)[k] = verts[ind].normal.x; (*mNorms)[k+1] = verts[ind].normal.y; (*mNorms)[k+2] = verts[ind].normal.z; } } //printf("%s", "\n\n"); //Ge triSize storleken på det allokerade minnet triSize = (count) * sizeof(GLfloat); }
void AnalysisSparse(Bool_t save_output = kFALSE) { gStyle->SetGridColor(kGray); // TString tmpstr(fname); // if (tmpstr.Contains("data")) { // Printf("!!! Real Data !!!"); // mc = kFALSE; // } TString gtitle = Form("Monte Carlo, %s", graph_name.Data()); grapht = graph_name.Data(); Double_t grx[999], gry[999], gry2[999], gry3[999], gry4[999], gry_eff[999], gry_fix[999], grxE[999]; Double_t gry22[999], gry22E[999], grx22E[999]; Double_t gry_true[999], gry_true_eff[999], gry_true_effE[999]; TH1::AddDirectory(kFALSE); TFile::SetCacheFileDir(gSystem->HomeDirectory()); TFile *f = TFile::Open(fname.Data(), "CACHEREAD"); if (!f) return; TList *l; f->GetObject(lname.Data(), l); if (!l) return; Int_t bf[999], bl[999]; Int_t nn = FindExactRange(((THnSparse *)(l->FindObject(s1name.Data())))-> Projection(1), del_step, bf, bl); // Int_t nn = FindRange5(bf, bl); Bool_t binhaluska = kFALSE; if (binAnders) { nn = 8; bf[0] = 6;bf[1] = 9;bf[2] = 11;bf[3] = 16;bf[4] = 21;bf[5] = 26; bl[0] = 8;bl[1] = 10;bl[2] = 15;bl[3] = 20;bl[4] = 25;bl[5] = 30; bf[6] = 31;bf[7] = 41; bl[6] = 40;bl[7] = 50; } Printf("number of intervals = %d =>", nn); Int_t count = 0; Double_t ptmean = 0, value = 0; Int_t fitStatus = -1; gStyle->SetOptStat(0); TCanvas *c = new TCanvas("c", "Signal & Background"); c->Divide(5, 5); c->Modified(); c->Draw(); TCanvas *c2 = (TCanvas *)c->DrawClone("c2"); c2->SetTitle("Phi mesons (raw)"); c2->Modified(); c2->Draw(); TCanvas *c3, *c4; if (mc) { c3 = (TCanvas *)c->DrawClone("c3"); c3->SetTitle("Phi mesons (gen)"); c3->Modified(); c3->Draw(); c4 = (TCanvas *)c->DrawClone("c4"); c4->SetTitle("Phi mesons (true)"); c4->Modified(); c4->Draw(); } for (Int_t i = 0; i < nn; i++) { c->cd(count + 1)->SetGrid(); h1 = (TH1D *)PullHisto(l, s1name.Data(), bf[i], bl[i], ptmean); h1->SetLineColor(kRed); h1->GetXaxis()->SetTitle("inv. mass, GeV/c^2"); h1->Draw("hist"); h3_p = (TH1D *)PullHisto(l, s3name_p.Data(), bf[i], bl[i], ptmean); h3_m = (TH1D *)PullHisto(l, s3name_m.Data(), bf[i], bl[i], ptmean); // !!!!!!!!!!!!!!!!!!!!!!!! if (count==0) h3_p = h1; // !!!!!!!!!!!!!!!!!!!!!!!! else { h3_p->Add(h3_m); // h3_p->Add((TH1D *)PullHisto(l, smix.Data(), bf[i], bl[i], ptmean)); // h3_p->Add((TH1D *)PullHisto(l, smixpp.Data(), bf[i], bl[i], ptmean)); // h3_p->Add((TH1D *)PullHisto(l, smixmm.Data(), bf[i], bl[i], ptmean)); Norm(h1, h3_p, norm[0], norm[1]); } h3_p->SetLineColor(kBlue); h3_p->Draw("hist, same"); if (mc) { c3->cd(count + 1)->SetGrid(); Printf("%s", s1namegen.Data()); hg = (TH1D *)PullHisto(l, s1namegen.Data(), bf[i], bl[i], ptmean); hg->SetLineColor(kMagenta); hg->GetXaxis()->SetTitle("inv. mass, GeV/c^2"); hg->Draw("hist"); c4->cd(count + 1)->SetGrid(); ht = (TH1D *)PullHisto(l, s1nametrue.Data(), bf[i], bl[i], ptmean); ht->SetLineColor(kMagenta-5); ht->GetXaxis()->SetTitle("inv. mass, GeV/c^2"); ht->Draw("hist"); } c2->cd(count + 1)->SetGrid(); TH1 *hh = (TH1 *)h1->Clone("hh"); hh->SetLineColor(kRed+1); hh->Add(h3_p, -1); /// !!!!!!!!!!!!!!!!!!!!!! ////////// if ((ilist == 3) && (count < 2)) hh->Reset(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! hh->Draw("hist"); // !!!!!!!!!!!!!!!!!! ff->SetParameters(0.1, 1.02, 0.004, -25000., 0., 0., 0.); ff->SetLineColor(hh->GetLineColor()); ff->SetLineWidth(1); // ff->SetLineStyle(kDashed); // where fit Double_t fmin = 1.02-2*0.004; Double_t fmax = 1.02+2*0.004; // Double_t fmin = 0.995; // Double_t fmax = 1.185; // !!!!!!!!!!!!!!!!!! Bool_t hisfun = kFALSE; // kFALSE = integral from function Double_t hisfun_k = 1.0/hh->GetBinWidth(10); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (binhaluska) if (i > 9) hisfun_k = 0.5/hh->GetBinWidth(10); Printf("======= %f", hisfun_k); // !!!!!!!!!!!!!!!!!! // wehere integral (his or fun) Double_t fmini = 1.02-2*0.004; Double_t fmaxi = 1.02+2*0.004; hh->Fit(ff, "Q", "", fmin, fmax); hh->Fit(ff, "Q", "", fmin, fmax); fitStatus = hh->Fit(ff, "Q", "", fmin, fmax); TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax); pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4), ff->GetParameter(5), ff->GetParameter(6)); pp3->SetLineWidth(1); pp3->SetLineColor(h3_p->GetLineColor()); pp3->Draw("same"); // ff->SetRange(fmin, fmax); // ff->DrawCopy("same"); value = hh->Integral(hh->FindBin(fmini), hh->FindBin(fmaxi)); if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k - pp3->Integral(fmini, fmaxi)*hisfun_k; if (value < 0) value = 0; if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) { printf(" SKIP Data"); value = 0; } grx[count] = ptmean; if (binhaluska) { if (count < 10) grxE[count] = 0.25; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! else grxE[count] = 0.50; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } else // grxE[count] = (1.30-1.10)/2.0; // !!!!!!!!!!!!!!!!!!!!!!!!!! grxE[count] = 0.05; gry[count] = value; Double_t tmp1 = h1->Integral(h1->FindBin(fmini), h1->FindBin(fmaxi)); Double_t tmp2 = h3_p->Integral(h3_p->FindBin(fmini), h3_p->FindBin(fmaxi)); Double_t tmp_sg = tmp1 - tmp2; Double_t tmp_bg = tmp2; // if ((tmp_sg <= -tmp_bg) || (tmp_bg < 33.0)) { // gry3[count] = 0.0; // gry4[count] = 0.0; // } // else { gry3[count] = tmp_sg/tmp_bg; gry4[count] = tmp_sg/TMath::Sqrt(tmp_sg + tmp_bg); // } // Printf("%4.2f, %10f, %10f, %10f", ptmean, tmp1, tmp2, gry3[count]); if (mc) { c3->cd(count + 1); // !!!!!!!!!!!!!!!! ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.); hg->Fit(ff, "Q", "", fmin, fmax); hg->Fit(ff, "Q", "", fmin, fmax); fitStatus = hg->Fit(ff, "Q", "", fmin, fmax); /* TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax); pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4), ff->GetParameter(5), ff->GetParameter(6)); pp3->SetLineWidth(1); pp3->SetLineColor(h3_p->GetLineColor()); pp3->Draw("same"); */ value = hg->Integral(hg->FindBin(fmini), hg->FindBin(fmaxi)); if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k; //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k; if (value <= 0) value = -1; if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) { printf(" SKIP MC"); value = -1; } gry2[count] = value; Double_t superfactor = CalculateFactor(l, 0.1); if (useCF) { gry22E[i] = TMath::Sqrt(gry2[i])*superfactor; // gry22E[i] = 0.0001; gry22[i] = gry2[i]*superfactor; grx22E[i] = 0.05; } gry_eff[count] = gry[count]/gry2[count]; c4->cd(count + 1); // !!!!!!!!!!!!!!!! ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.); ht->Fit(ff, "Q", "", fmin, fmax); ht->Fit(ff, "Q", "", fmin, fmax); fitStatus = ht->Fit(ff, "Q", "", fmin, fmax); /* TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax); pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4), ff->GetParameter(5), ff->GetParameter(6)); pp3->SetLineWidth(1); pp3->SetLineColor(h3_p->GetLineColor()); pp3->Draw("same"); */ value = ht->Integral(ht->FindBin(fmini), ht->FindBin(fmaxi)); if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k; //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k; if (value <= 0) value = -1; if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) { printf(" SKIP true"); value = -1; } gry_true[count] = value; gry_true_eff[count] = gry_true[count]/gry2[count]; // Propagation of uncertainty (A/B) Double_t AAA = gry_true[count]; Double_t AAAE = TMath::Sqrt(AAA); Double_t BBB = gry2[count]; Double_t BBBE = TMath::Sqrt(BBB); Double_t EEE = TMath::Sqrt((AAAE/AAA)*(AAAE/AAA)+(BBBE/BBB)*(BBBE/BBB)); EEE = EEE*gry_true_eff[count]; gry_true_effE[count] = EEE; } Printf("=> %6.4f", ptmean); count++; } new TCanvas(); TGraph *gr = new TGraph(count, grx, gry); gr->SetMarkerStyle(8); gr->SetMarkerColor(hh->GetLineColor()); gr->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr->SetTitle(Form("raw phi, %s", gtitle.Data())); gr->Draw("AP"); cc3 = new TCanvas(); TGraph *gr3 = new TGraph(count, grx, gry3); gr3->SetMarkerStyle(22); gr3->SetMarkerColor(kBlue+1); gr3->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr3->SetTitle(Form("SIG / BKG, %s", gtitle.Data())); gr3->SetMinimum(0); gr3->Draw("AP"); cc4 = new TCanvas(); TGraph *gr4 = new TGraph(count, grx, gry4); gr4->SetMarkerStyle(23); gr4->SetMarkerColor(kBlue-1); gr4->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr4->SetTitle(Form("Significance, %s", gtitle.Data())); gr4->SetMinimum(0); gr4->Draw("AP"); ccc = new TCanvas("ccc","ccc",0,0,900,300); ccc->Divide(2, 1, 0.001, 0.001); ccc->cd(1); gr3->Draw("AP"); ccc->cd(2); gr4->Draw("AP"); TString blabla = "mc"; if (!mc) blabla = "data"; // gr3->SaveAs(Form("SB_%s_%s.C", blabla.Data(), grapht.Data())); // gr4->SaveAs(Form("Sig_%s_%s.C", blabla.Data(), grapht.Data())); // ccc->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data())); // c->SaveAs(Form("%s_%s_0.eps", blabla.Data(), grapht.Data())); // c2->SaveAs(Form("%s_%s_1.eps", blabla.Data(), grapht.Data())); // cc3->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data())); // gr3->SaveAs(Form("sig_bck_%s_%s.C", blabla.Data(), grapht.Data())); if (mc) { new TCanvas(); TGraph *gr2 = new TGraph(count, grx, gry2); gr2->SetMarkerStyle(8); gr2->SetMarkerColor(hg->GetLineColor()); gr2->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr2->SetTitle(Form("gen phi, %s", gtitle.Data())); gr2->Draw("AP"); new TCanvas(); TGraphErrors *gr22 = new TGraphErrors(count, grx, gry22, grx22E, gry22E); gr22->SetMarkerStyle(8); gr22->SetMarkerColor(kCyan); gr22->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr22->SetTitle(Form("gen phi, %s", gtitle.Data())); gr22->Draw("AP"); c = new TCanvas(); c->SetGrid(); TGraph *gr_e = new TGraph(count, grx, gry_eff); gr_e->SetMarkerStyle(22); gr_e->SetMarkerColor(kBlack); gr_e->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_e->SetTitle(Form("efficiency (raw), %s", grapht.Data())); gr_e->Draw("AP"); Printf("Save as '\033[1meffi_raw_%s\033[0m' file", grapht.Data()); for (Int_t i = 0; i < gr_e->GetN(); i++) Printf("%f %f", gr_e->GetX()[i], gr_e->GetY()[i]); cvb = new TCanvas(); cvb->cd(); TGraph *gr_true = new TGraph(count, grx, gry_true); gr_true->SetMarkerStyle(8); gr_true->SetMarkerColor(ht->GetLineColor()); gr_true->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_true->SetTitle(Form("true phi, %s", gtitle.Data())); gr_true->Draw("AP"); c = new TCanvas(); c->cd(); c->SetGrid(); TGraphErrors *gr_true_eff = new TGraphErrors(count, grx, gry_true_eff, grxE, gry_true_effE); gr_true_eff->SetMarkerStyle(20); // gr_true_eff->SetMarkerSize(0.75); gr_true_eff->SetMarkerColor(kBlack); gr_true_eff->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_true_eff->SetTitle(Form("efficiency (true), %s", grapht.Data())); gr_true_eff->Draw("AEP"); m_gr->Add(gr_true_eff); Printf("Save as '\033[1meffi_true_%s\033[0m' file", grapht.Data()); TString tout; Double_t oux, ouy, ouxe, ouye; for (Int_t i = 0; i < gr_true_eff->GetN(); i++) { oux = gr_true_eff->GetX()[i]; ouy = gr_true_eff->GetY()[i]; ouy = MinusCheck(ouy); ouxe = gr_true_eff->GetErrorX(i); ouye = gr_true_eff->GetErrorY(i); ouye = NanCheck(ouye); Printf("%f %f %f %f", gr_true_eff->GetX()[i], gr_true_eff->GetY()[i], gr_true_eff->GetErrorX(i), gr_true_eff->GetErrorY(i)); if (!save_output) continue; gSystem->mkdir(dir_prefix.Data()); tout = Form("%f %f %f %f", oux, ouy, ouxe, ouye); if (i == 0) tout = Form("Printf(\"%s\"); > %s/effi_%s", tout.Data(), dir_prefix.Data(), grapht.Data()); else tout = Form("Printf(\"%s\"); >> %s/effi_%s", tout.Data(), dir_prefix.Data(), grapht.Data()); // Printf(":::::: %s", tout.Data()); gROOT->ProcessLine(tout.Data()); } // ------------------ c = new TCanvas("cfinal", "mc_effi", 1200, 450); c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw(); c->cd(1); gr_true->SetMinimum(0); gr_true->SetTitle(Form("phi (true & raw), %s", gtitle.Data())); gr_true->SetMarkerColor(kGreen+1); gr_true->Draw("AP"); gr->SetMarkerColor(kRed+1); gr->Draw("P"); c->cd(2)->SetGrid(); gr_true_eff->SetMinimum(0); gr_true_eff->SetTitle(Form("efficiency, %s", grapht.Data())); gr_true_eff->SetMarkerColor(kGreen+1); gr_true_eff->Draw("AP"); gr_e->SetMarkerColor(kRed+1); gr_e->Draw("P"); // c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data())); return; } // TGraph *geff = new TGraph(Form("effi_raw_%s", grapht.Data())); // TGraph *geff = new TGraph(Form("effi_true_%s", grapht.Data())); // TGraph *geff = new TGraph("effi_true_Phi2010_qualityonly"); TGraph *geff = new TGraph("effi_true_PhiNsigma_qualityonly"); if (geff->IsZombie()) return; geff->SetMarkerStyle(22); geff->SetMarkerColor(kBlack); geff->GetXaxis()->SetTitle("p_{t}, GeV/c"); geff->SetTitle(Form("efficiency, %s", grapht.Data())); c = new TCanvas(); c->SetGrid(); geff->Draw("AP"); Double_t tpcsigma = 9999.9; if (ilist == 1) tpcsigma = 1.0; if (ilist == 2) tpcsigma = 1.5; if (ilist == 3) tpcsigma = 2.0; if (ilist == 4) tpcsigma = 2.5; if (ilist == 5) tpcsigma = 3.0; Double_t sss = TMath::Erf(tpcsigma/TMath::Sqrt(2.0)); if (noSigma) sss = 1.0; Printf("sigma = %10f", sss); // for (Int_t i = 0; i < count; i++) // geff->GetY()[i] = (sss*sss)/(geff->GetY()[i]); // geff->SetMaximum(1.0); // geff->Draw("AP"); for (Int_t i = 0; i < count; i++) { Double_t deno = geff->Eval(grx[i])*sss*sss; if (deno < 0.00001) deno = 1; gry_fix[i] = gry[i]/deno; } new TCanvas; TGraph *gr_fix = new TGraph(count, grx, gry_fix); gr_fix->SetMarkerStyle(21); gr_fix->SetMarkerColor(hh->GetLineColor()); gr_fix->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_fix->SetTitle(Form("corrected phi * #sigma^{2}, %s", gtitle.Data())); if (noSigma) gr_fix->SetTitle(Form("corrected phi (no #sigma), %s", gtitle.Data())); gr_fix->Draw("AP"); //--------------------- c = new TCanvas("cfinald", "data_correct", 1200, 450); c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw(); c->cd(1); gr->SetMinimum(0); gr->SetMarkerColor(kBlack); gr->Draw("AP"); c->cd(2); gr_fix->SetMinimum(0); gr_fix->SetMarkerColor(kGreen+3); gr_fix->Draw("AP"); TString bla9 = Form("qualityonly_PID2_%s", grapht.Data()); if (noSigma) bla9 = Form("%s_noSig.C", bla9.Data()); else bla9 = Form("%s.C", bla9.Data()); // gr_fix->SaveAs(bla9.Data()); // TPad *cp = new TPad("cpf", "", 0.45,0.45,0.99,0.92); TPad *cp = new TPad("cpf", "", 0.60,0.55,0.99,0.93); cp->SetLogy(); cp->Draw(); cp->cd(); TGraph *cloneg = ((TGraph *)gr_fix->Clone()); cloneg->SetTitle(); cloneg->SetMarkerSize(0.8); cloneg->Draw("AP"); // c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data())); f->Close(); }
inline float Length () const { return Norm(); } // A convenience
inline float Magnitude () const { return Norm(); } // A convenience
void BaseBuilding::creerToitPrisme(bool addChimney) { /* d_________________c | | e|________g________|f --> arrête supérieure du prisme | | |________h________| a b */ double air = Quadrangle(listPoints[0],listPoints[1],listPoints[2],listPoints[3]).Area(); if(air > airMin) { double hauteurPrisme = (double) UNIT * 3; Vector monterEnZ(0,0,hauteurPrisme); int j; Vector e = ( (listPoints[3] + listPoints[0]) /2 ) + monterEnZ; Vector f = ( (listPoints[2] + listPoints[1]) /2 ) + monterEnZ; glBegin(GL_TRIANGLES); // Face ade Vector n= (listPoints[3]-listPoints[0])/(e-listPoints[0]); n/=Norm(n); glNormal3f(n[0],n[1],n[2]); glColor3ub(Vector::col1,Vector::col2,Vector::col3); glVertex3f(listPoints[0][0], listPoints[0][1], listPoints[0][2]); glVertex3f(listPoints[3][0], listPoints[3][1], listPoints[3][2]); glVertex3f(e[0], e[1], e[2]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[0][j]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[3][j]); for(j=0;j<=2;j++) PrismRoof.push_back(e[j]); glEnd(); glBegin(GL_QUADS); // Face abfe n= (listPoints[1]-listPoints[0])/(e-listPoints[0]); n/=Norm(n); glNormal3f(n[0],n[1],n[2]); glColor3ub(Vector::col1,Vector::col2,Vector::col3); glVertex3f(listPoints[0][0], listPoints[0][1], listPoints[0][2]); glVertex3f(listPoints[1][0], listPoints[1][1], listPoints[1][2]); glVertex3f(f[0], f[1], f[2]); glVertex3f(e[0], e[1], e[2]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[0][j]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[1][j]); for(j=0;j<=2;j++) PrismRoof.push_back(f[j]); for(j=0;j<=2;j++) PrismRoof.push_back(e[j]); glEnd(); glBegin(GL_QUADS); // Face cdef n= (listPoints[3]-listPoints[2])/(f-listPoints[2]); n/=Norm(n); glNormal3f(n[0],n[1],n[2]); glColor3ub(Vector::col1,Vector::col2,Vector::col3); glVertex3f(listPoints[2][0], listPoints[2][1], listPoints[2][2]); glVertex3f(listPoints[3][0], listPoints[3][1], listPoints[3][2]); glVertex3f(e[0], e[1], e[2]); glVertex3f(f[0], f[1], f[2]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[2][j]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[3][j]); for(j=0;j<=2;j++) PrismRoof.push_back(e[j]); for(j=0;j<=2;j++) PrismRoof.push_back(f[j]); glEnd(); glBegin(GL_TRIANGLES); // Face bcf n= (listPoints[2]-listPoints[1])/(f-listPoints[1]); n/=Norm(n); glNormal3f(n[0],n[1],n[2]); glColor3ub(Vector::col1,Vector::col2,Vector::col3); glVertex3f(listPoints[1][0], listPoints[1][1], listPoints[1][2]); glVertex3f(listPoints[2][0], listPoints[2][1], listPoints[2][2]); glVertex3f(f[0], f[1], f[2]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[1][j]); for(j=0;j<=2;j++) PrismRoof.push_back(listPoints[2][j]); for(j=0;j<=2;j++) PrismRoof.push_back(f[j]); glEnd(); //-------------------Cheminée-----------------------------> if(addChimney) { Vector g = (e + f)/2; Vector h = (listPoints[0] + listPoints[1])/2; double chimneyWidth = (double) UNIT; std::vector<Vector> newPoints; newPoints.push_back(listPoints[0] + monterEnZ/3); newPoints.push_back(h + monterEnZ/3); //e - monterEnZ + (monterEnZ/3) newPoints.push_back(e - (monterEnZ*2/3)); //g - monterEnZ + (monterEnZ/3) newPoints.push_back(g - (monterEnZ*2/3)); Vector tmp = (listPoints[0] + e + g + h)/4; Vector centerAEGH = Vector(tmp[0],tmp[1], newPoints[0][2]); //le centre de la cheminée double tailleAd = Norm(newPoints[3] - newPoints[0]); double tailleAb = Norm(newPoints[1] - newPoints[0]); double ratioAbEtDc,ratioAdEtBc; if(tailleAd > tailleAb) { ratioAbEtDc = tailleAd/tailleAb; ratioAdEtBc = 1; } else { ratioAbEtDc = 1; ratioAdEtBc = tailleAb/tailleAd; } for(unsigned int i = 0; i < newPoints.size(); i++) { double pas = Norm(newPoints[i] - centerAEGH)/chimneyWidth; newPoints[i] = centerAEGH + ( (newPoints[i] - centerAEGH)/pas ); } //Les sommets de la cheminée Vector a,b,c,d; a = newPoints[0]; b = newPoints[1]; c = newPoints[3]; d = newPoints[2]; //comme on veut que tous les côtés soient égaux, on applique un ratio PrismQuad( a, a + (b - a)*ratioAbEtDc, d + (c - d)*ratioAbEtDc, a + (d - a)*ratioAdEtBc, ((double)UNIT)*3).Render(); } } }
void ISNorm::norm (ssi_stream_t &stream, ssi_size_t stream_index) { if (_params[stream_index]) { Norm(stream, *_params[stream_index]); } }
void Vector3::Normalize() { float norm = Norm(); x /= norm; y /= norm; z /= norm; }
void TestBandDiv(tmv::DivType dt) { const int N = 10; std::vector<tmv::BandMatrixView<T> > b; std::vector<tmv::BandMatrixView<std::complex<T> > > cb; MakeBandList(b,cb); tmv::Matrix<T> a1(N,N); for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) a1(i,j) = T(3+i-2*j); a1.diag().addToAll(T(10)*N); a1 /= T(10); tmv::Matrix<std::complex<T> > ca1 = a1 * std::complex<T>(3,-4); tmv::Vector<T> v1(N); tmv::Vector<T> v2(N-1); for (int i=0; i<N; ++i) v1(i) = T(16-3*i); for (int i=0; i<N-1; ++i) v2(i) = T(-6+i); tmv::Vector<std::complex<T> > cv1(N); tmv::Vector<std::complex<T> > cv2(N-1); for (int i=0; i<N; ++i) cv1(i) = std::complex<T>(16-3*i,i+4); for (int i=0; i<N-1; ++i) cv2(i) = std::complex<T>(2*i-3,-6+i); tmv::Matrix<T> a3 = a1.colRange(0,N/2); tmv::Matrix<std::complex<T> > ca3 = ca1.colRange(0,N/2); tmv::Matrix<T> a4 = a1.rowRange(0,N/2); tmv::Matrix<std::complex<T> > ca4 = ca1.rowRange(0,N/2); tmv::Matrix<T> a5 = a1.colRange(0,0); tmv::Matrix<std::complex<T> > ca5 = ca1.colRange(0,0); tmv::Matrix<T> a6 = a1.rowRange(0,0); tmv::Matrix<std::complex<T> > ca6 = ca1.rowRange(0,0); tmv::Matrix<T> a7 = a1; tmv::Matrix<std::complex<T> > ca7 = ca1; a7.diag().addToAll(T(10)*N); ca7.diag().addToAll(T(10)*N); for(size_t i=START;i<b.size();i++) { if (showstartdone) std::cout<<"Start loop: i = "<<i<<"\nbi = "<<tmv::TMV_Text(b[i])<< " "<<b[i]<<std::endl; tmv::BandMatrixView<T> bi = b[i]; tmv::BandMatrixView<std::complex<T> > cbi = cb[i]; if (dt == tmv::LU && !bi.isSquare()) continue; bi.saveDiv(); cbi.saveDiv(); tmv::Matrix<T> m(bi); m.saveDiv(); bi.divideUsing(dt); bi.setDiv(); m.divideUsing(dt); m.setDiv(); std::ostream* divout = showdiv ? &std::cout : 0; Assert(bi.checkDecomp(divout),"CheckDecomp"); T eps = m.rowsize()*EPS*Norm(m)*Norm(m.inverse()); if (bi.colsize() == N) { tmv::Vector<T> x1 = v1/bi; tmv::Vector<T> x2 = v1/m; if (showacc) { std::cout<<"v/b: Norm(x1-x2) = "<<Norm(x1-x2)<< " "<<eps*Norm(x1)<<std::endl; } Assert(Norm(x1-x2) < eps*Norm(x1),"Band v/b"); } if (bi.rowsize() == N) { tmv::Vector<T> x1 = v1%bi; tmv::Vector<T> x2 = v1%m; if (showacc) { std::cout<<"v%b: Norm(x1-x2) = "<<Norm(x1-x2)<< " "<<eps*Norm(x1)<<std::endl; } Assert(Norm(x1-x2) < eps*Norm(x1),"Band v%b"); } tmv::Matrix<T,tmv::ColMajor> binv = bi.inverse(); tmv::Matrix<T,tmv::ColMajor> minv = m.inverse(); if (showacc) { std::cout<<"minv = "<<minv<<std::endl; std::cout<<"binv = "<<binv<<std::endl; std::cout<<"Norm(minv-binv) = "<<Norm(minv-binv)<< " "<<eps*Norm(binv)<<std::endl; } Assert(Norm(binv-minv) < eps*Norm(binv),"Band Inverse"); if (m.isSquare()) { if (showacc) { std::cout<<"Det(b) = "<<Det(bi)<< ", Det(m) = "<<Det(m)<<std::endl; std::cout<<"abs(bdet-mdet) = "<<std::abs(Det(bi)-Det(m)); std::cout<<" EPS*abs(mdet) = "<< eps*std::abs(Det(m))<<std::endl; std::cout<<"abs(abs(bdet)-abs(mdet)) = "<< std::abs(std::abs(Det(bi))-std::abs(Det(m))); std::cout<<" EPS*abs(mdet) = "<< eps*std::abs(Det(m))<<std::endl; } Assert(std::abs(Det(m)-Det(bi)) < eps*std::abs(Det(m)+Norm(m)), "Band Det"); T msign, bsign; Assert(std::abs(m.logDet(&msign)-bi.logDet(&bsign)) < N*eps, "Band LogDet"); Assert(std::abs(msign-bsign) < N*eps,"Band LogDet - sign"); } cbi.divideUsing(dt); cbi.setDiv(); Assert(cbi.checkDecomp(divout),"CheckDecomp"); tmv::Matrix<std::complex<T> > cm(cbi); cm.saveDiv(); cm.divideUsing(dt); cm.setDiv(); T ceps = EPS*Norm(cm)*Norm(cm.inverse()); if (cm.isSquare()) { if (showacc) { std::cout<<"Det(cbi) = "<<Det(cbi)<<", Det(cm) = "<< Det(cm)<<std::endl; std::cout<<"abs(cbidet-cmdet) = "<<std::abs(Det(cbi)-Det(cm)); std::cout<<" cbidet/cmdet = "<<Det(cbi)/Det(cm); std::cout<<" EPS*abs(cmdet) = "<< ceps*std::abs(Det(cm))<<std::endl; std::cout<<"abs(abs(bdet)-abs(mdet)) = "<< std::abs(std::abs(Det(bi))-std::abs(Det(m))); std::cout<<" EPS*abs(mdet) = "<< ceps*std::abs(Det(m))<<std::endl; } Assert(std::abs(Det(cbi)-Det(cm)) < ceps*std::abs(Det(cm)+Norm(cm)), "Band CDet"); std::complex<T> cmsign, cbsign; Assert(std::abs(cm.logDet(&cmsign)-cbi.logDet(&cbsign)) < N*eps, "Band CLogDet"); Assert(std::abs(cmsign-cbsign) < N*eps,"Band CLogDet - sign"); } tmv::Vector<std::complex<T> > cv(v1 * std::complex<T>(1,1)); cv(1) += std::complex<T>(-1,5); cv(2) -= std::complex<T>(-1,5); if (m.colsize() == N) { // test real / complex tmv::Vector<std::complex<T> > y1 = v1/cbi; tmv::Vector<std::complex<T> > y2 = v1/cm; if (showacc) { std::cout<<"v/cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band v/cb"); // test complex / real y1 = cv/bi; y2 = cv/m; if (showacc) { std::cout<<"cv/b: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<eps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < eps*Norm(y1),"Band cv/b"); // test complex / complex y1 = cv/cbi; y2 = cv/cm; if (showacc) { std::cout<<"cv/cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band cv/cb"); } if (bi.rowsize() == N) { tmv::Vector<std::complex<T> > y1 = v1%cbi; tmv::Vector<std::complex<T> > y2 = v1%cm; if (showacc) { std::cout<<"v%cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band v%cb"); y1 = cv%bi; y2 = cv%m; if (showacc) { std::cout<<"cv%b: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<eps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < eps*Norm(y1),"Band cv%b"); y1 = cv%cbi; y2 = cv%cm; if (showacc) { std::cout<<"cv%cb: Norm(y1-y2) = "<<Norm(y1-y2)<< " "<<ceps*Norm(y1)<<std::endl; } Assert(Norm(y1-y2) < ceps*Norm(y1),"Band cv%cb"); } } TestBandDiv_A<T>(dt); TestBandDiv_B1<T>(dt); TestBandDiv_B2<T>(dt); TestBandDiv_C1<T>(dt); if (dt == tmv::LU) TestBandDiv_C2<T>(dt); TestBandDiv_D1<T>(dt); if (dt == tmv::LU) TestBandDiv_D2<T>(dt); std::cout<<"BandMatrix<"<<tmv::TMV_Text(T())<<"> Division using "; std::cout<<tmv::TMV_Text(dt)<<" passed all tests\n"; }
void makeFlux(FVMesh2D &m, FVVect<double> &phi, FVVect< FVPoint2D<double> > &u, FVVect<double> &Vd,FVVect<double> &Vn, FVVect<double> &F,Parameter ¶) { //FVEdge2D *ptr_e; double leftPhi,rightPhi,normal_velocity; FVPoint2D<double> BB; m.beginEdge(); size_t edges = m.getNbEdge(); //avoid getting static values in loops const unsigned int dirCode = para.getUnsigned("DirichletCode"); const unsigned int neuCode = para.getUnsigned("NeumannCode"); const double difusion = getDiffusion(NULL,para); for(size_t i = 0; i < edges; i++) { FVEdge2D *ptr_e; //ptr_e = m.nextEdge(); ptr_e = m.getEdge(i); normal_velocity = Dot(u[ptr_e->label-1],ptr_e->normal); leftPhi = phi[ptr_e->leftCell->label-1]; if(ptr_e->rightCell) { // edge has the code = 0 rightPhi = phi[ptr_e->rightCell->label-1]; // compute the convection contribution if(normal_velocity<0) { F[ptr_e->label-1] = normal_velocity*rightPhi; } else { F[ptr_e->label-1] = normal_velocity*leftPhi; } // compute the diffusive contribution BB=ptr_e->rightCell->centroid - ptr_e->leftCell->centroid; F[ptr_e->label-1] -= difusion*(rightPhi-leftPhi)/Norm(BB); } else { // we are on the boundary if(ptr_e->code == dirCode) { // we have a Dirichlet condition rightPhi = Dirichlet(ptr_e->centroid,para); // compute the convection contribution if(normal_velocity<0) { F[ptr_e->label-1] = normal_velocity*rightPhi; } else { F[ptr_e->label-1] = normal_velocity*leftPhi; } // compute the diffusive contribution BB = ptr_e->centroid - ptr_e->leftCell->centroid; F[ptr_e->label-1] -= difusion*(rightPhi-leftPhi)/Norm(BB); } if(ptr_e->code == neuCode) { // we have a Neumann condition F[ptr_e->label-1] = Neumann(ptr_e->centroid,para); } } // here, we have all the data to compute the flux F[ptr_e->label-1] *= ptr_e->length; } }
bool Map::Generate_Vertices() { HRESULT hresult = 0; int start_x = 0; int start_z = 0; int end_x = length; int end_z = width; float u_increment = 1.0f / (float)cell_length; float v_increment = 1.0f / (float)cell_width; IDirect3DVertexBuffer9* temp_buffer = 0; mesh->GetVertexBuffer(&temp_buffer); Terrain_Vertex* v; temp_buffer->Lock(0, 0, (void**)&v, 0); int i = 0; for (int z = start_z; z <= end_z; z = z + cell_spacing) //### { int j = 0; for (int x = start_x; x <= end_x; x = x + cell_spacing) { int element = (i * vertex_length) + j; D3DXVECTOR3 Posi((float)x, height_float_vector[element], (float)z); D3DXVECTOR3 Norm(-N[element].x, -N[element].y, N[element].z); v[element] = Terrain_Vertex( Posi, Norm, (float)j * u_increment * 5, (float)i * v_increment * 5, (float)j * u_increment * 5, (float)i * v_increment * 5, (float)j * u_increment * 5, (float)i * v_increment * 5, (float)j * u_increment, (float)i * v_increment, (float)j * u_increment, (float)i * v_increment); j++; } i++; } temp_buffer->Unlock(); return true; }
bool Game_Engine::Intersect(const Rocket &_Rocket, const double &dt) { //bool Intersect(const LightCycle &Cycle, const Wall &_Wall); Wall Rock(Segment2D <double>(_Rocket.Current_Point, _Rocket.Current_Point + dt*this->Constants->Rocket_Speed*Norm(_Rocket.Direction)), -1, -1); for (size_t i = 0; i < this->Current_Game.Players.size(); i++) { if (this->Current_Game.Players[i].Alive) if (Intersect(this->Current_Game.Players[i].MyCycle, Rock)) return true; } for (size_t i = 0; i < this->Current_Game.Walls.size(); i++) { if (Intersect(Polygon_from_wall(this->Current_Game.Walls[i]), Polygon_from_wall(Rock))) return true; } return false; }
void ff(TextureCompressDXT,format,coding,fiting)(RESOURCEINFO &texo, RESOURCEINFO &texd, ULONG *texs, ULONG *texr, int level, int l, int blocksize, int flags) { /* square dimension of this surface-level */ /* square area of this surface-level */ const int lv = (1 << l); const int av = lv * lv; /* ------------------------------------------------------------------------------------------------------- */ const int NORMALS_SCALEBYLEVEL = ::NORMALS_SCALEBYLEVEL; const int ALPHAS_SCALEBYLEVEL = ::ALPHAS_SCALEBYLEVEL; const float colorgamma = ::colorgamma; const float alphacontrast = ::alphacontrast; const float colorgammainv = ::colorgammainv; const float alphacontrastinv = ::alphacontrastinv; int iwidth = texo.Width; int iheight = texo.Height; int owidth = texd.Width; int oheight = texd.Height; int cwidth = owidth; int cheight = oheight; /* get the data back to the CPU */ cheight = (cheight + 3) / 4; /* 4x4 LONG ... */ cwidth = (cwidth + 3) / 4; /* 4x4 LONG ... */ cwidth *= 2 * blocksize; /* ... to 2x|4x LONG */ /* ensure tile ability (bit on overhead for non-4 resolutions) */ owidth = (owidth + (TX - 1)) & (~(TX - 1)); oheight = (oheight + (TY - 1)) & (~(TY - 1)); assert((owidth & (TX - 1)) == 0); assert((oheight & (TY - 1)) == 0); #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) /* constant buffer array */ Concurrency::array_view<const SingleColourLookup_CCR, 2> lArr(2, 256, (const SingleColourLookup_CCR *)::lookup_34_56_ccr); Concurrency::array_view<const IndexBlockLookup_CCR, 2> yArr(4, 8, (const IndexBlockLookup_CCR *)::lookup_c34a57_ccr); /* get a two-dimensional extend over the whole output (without re-cast to LONG), * then get a tile-extend over that one () */ Concurrency::extent<2> ee(oheight, owidth); Concurrency::tiled_extent<TY, TX> te(ee); Concurrency::array_view<const unsigned int, 2> sArr(iheight, iwidth, (const unsigned int *)texs); Concurrency::array_view< unsigned int, 2> dArr(cheight, cwidth, ( unsigned int *)texr); Concurrency::parallel_for_each(te /*dArr.extent.tile<TY, TX>(osize)*/, [=](tiled_index<TY, TX> elm) restrict(amp) { typedef type accu[DIM]; /* tile static memory */ // tile_static UTYPE bTex[2][TY*TX]; tile_static type fTex[2][TY*TX][DIM]; tile_static int iTex[2][TY*TX][DIM]; /* generate this level's 4x4-block from the original surface */ // const int y = elm.global[0] - ly; // const int x = elm.global[1] - lx; const int y = elm.tile[0] * TY; const int x = elm.tile[1] * TX; const int ly = elm.local[0]; const int lx = elm.local[1]; const int lxy = ly * TX + lx; #else Concurrency::array_view<const SingleColourLookup_CCR, 2> lArr(2, 256, (const SingleColourLookup_CCR *)::lookup_34_56_ccr); Concurrency::array_view<const unsigned int, 2> sArr(iheight, iwidth, (const unsigned int *)texs); Concurrency::array_view< unsigned int, 2> dArr(cheight, cwidth, ( unsigned int *)texr, true); for (int groupsy = 0; groupsy < (owidth / TY); groupsy++) for (int groupsx = 0; groupsx < (oheight / TX); groupsx++) { typedef type accu[DIM]; /* tile static memory */ // UTYPE bTex[2][TY*TX]; type fTex[2][TY*TX][DIM]; int iTex[2][TY*TX][DIM]; for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy * TY; const int x = groupsx * TX; const int ly = tiley; const int lx = tilex; const int lxy = ly * TX + lx; #endif { const int yl = ((y + ly) << l); const int xl = ((x + lx) << l); accu tt = {0}; /* access all pixels this level's 4x4-block represents in * the full dimension original surface (high quality mip-mapping) */ for (int oy = 0; oy < lv; oy += 1) { for (int ox = 0; ox < lv; ox += 1) { /* assume seamless tiling: wrap pixels around */ const int posx = (xl + ox) % iwidth; const int posy = (yl + oy) % iheight; const ULONG &t = sArr(posy, posx); Accu(tt, t); // += } } /* build average of each channel */ Norm(fTex[0][lxy], tt, av, level, l); } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static accu tr; tr[lxy & 7] = 0; tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #else } accu tr = {0}; #endif /* runs on only 1 thread per tile (reduction) */ #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) if (elm.local == index<2>(0, 0)) #endif { /* analyze this level's 4x4-block */ for (int lxy = 0; lxy < TY*TX; lxy += 1) { Look(fTex[0][lxy], tr); } } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #else for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy; const int x = groupsx; const int ly = tiley; const int lx = tilex; const int lxy = ly * TX + lx; #endif /* generate this level's 4x4-block from the original surface */ { /* build average of each channel an join */ Code (fTex[0][lxy], tr, (TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS (format) ? 2 : 0)) == 2 ? 8 : (TCOMPRESS_SWIZZL (format) ? 6 : 5)); Range(iTex[0][lxy], fTex[0][lxy]); #if (TCOMPRESS_SWIZZL(format)) /* swizzle ABGR -> AGBR */ { int swap = iTex[0][lxy][1]; iTex[0][lxy][1] = iTex[0][lxy][2]; iTex[0][lxy][2] = swap ; } #endif /* write the result */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #if ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 4) /* ABGR -> RGBA */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 3) /* -BGR -> RGB- */ iTex[0][lxy][0] = 0xFF; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 2) /* --YX -> XY-- */ /* AL-- -> LA-- */ #if (format == TCOMPRESS_XYz) iTex[0][lxy][0] = iTex[0][lxy][2], // Y iTex[1][lxy][0] = iTex[0][lxy][3]; // X #else iTex[0][lxy][0] = iTex[0][lxy][0], // A iTex[1][lxy][0] = iTex[0][lxy][1]; // Z #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 1) /* -Z-- -> Z--- */ /* A--- -> A--- */ /* -LLL -> L--- */ #if (format == TCOMPRESS_a ) iTex[0][lxy][0] = iTex[0][lxy][0]; // A #elif (format == TCOMPRESS_A ) iTex[0][lxy][0] = iTex[0][lxy][0]; // A #elif (format == TCOMPRESS_xyZ) iTex[0][lxy][0] = iTex[0][lxy][1]; // Z #else iTex[0][lxy][0] = iTex[0][lxy][3]; // X #endif #else #error #endif } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) tile_static_memory_fence(elm.barrier); // elm.barrier.wait_with_tile_static_memory_fence(); #define local_is(a,b) elm.local == index<2>(a, b) #else } for (int tiley = 0; tiley < TY; tiley++) for (int tilex = 0; tilex < TX; tilex++) { const int y = groupsy; const int x = groupsx; const int ly = tiley; const int lx = tilex; const int lxy = ly * TX + lx; #define local_is(a,b) ((ly == a) && (lx == b)) #endif /* put this level's 4x4-block into the destination surface */ { /* round down */ int posx = (x + lx) >> 2; int posy = (y + ly) >> 2; /* first and second block */ unsigned int b[2][2]; /* compress to DXT1/DXT3/DXT5/ATI1/ATI2 */ #define sflgs TCOMPRESS_COLOR(format) ? SQUISH_METRIC_PERCEPTUAL : SQUISH_METRIC_UNIFORM, \ TCOMPRESS_TRANS(format), \ fiting /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #if ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 4) || \ ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 3) /* 1x LONG per block for DXT1, 2x for the others */ #if (coding == 1) { posx <<= 0; squish::CompressColorBtc1(elm.barrier, lxy, iTex[0], 0xFFFF, b[1], sflgs, yArr, lArr); dArr(posy, posx + 0) = b[1][0]; dArr(posy, posx + 1) = b[1][1]; } #elif (coding == 2) { posx <<= 1; squish::CompressAlphaBtc2(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); squish::CompressColorBtc2(elm.barrier, lxy, iTex[0], 0xFFFF, b[1], sflgs, yArr, lArr); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; dArr(posy, posx + 2) = b[1][0]; dArr(posy, posx + 3) = b[1][1]; } #elif (coding == 3) { posx <<= 1; squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); squish::CompressColorBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[1], sflgs, yArr, lArr); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; dArr(posy, posx + 2) = b[1][0]; dArr(posy, posx + 3) = b[1][1]; } #else #error #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 1) /* 1x LONG for ATI1 */ #if (coding == 4) { posx <<= 0; squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; } #else #error #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #elif ((TCOMPRESS_CHANNELS(format) + (TCOMPRESS_GREYS(format) ? 2 : 0)) == 2) /* 2x LONG for ATI2 */ #if (coding == 5) { posx <<= 1; squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[0], 0xFFFF, b[0] , yArr ); squish::CompressAlphaBtc3(elm.barrier, lxy, iTex[1], 0xFFFF, b[1] , yArr ); dArr(posy, posx + 0) = b[0][0]; dArr(posy, posx + 1) = b[0][1]; dArr(posy, posx + 2) = b[1][0]; dArr(posy, posx + 3) = b[1][1]; } #else #error #endif #else #error #endif #undef sflgs // elm.barrier.wait(); /* advance pointer of compressed blocks */ // wTex += blocksize; // dTex += blocksize; } #if defined(SQUASH_USE_AMP) && !defined(SQUASH_USE_AMP_DEBUG) // elm.barrier.wait(); // dTex += 0; }); dArr.synchronize(); #else }}
Polygon2D < double > Game_Engine::Polygon_from_cycle(const LightCycle &Cycle) { return Polygon_from(Cycle.Current_Point, this->Constants->LightCycle_Length * Norm(Cycle.Direction), this->Constants->LightCycle_Width); }
static void TestAliasMultUL2( const M& m, const Ma& ma, const Mb& mb, M1& m1, const M1a& m1a, const M1b& m1b, std::string label) { if (showstartdone) { std::cout<<"Start AliasMultUL2\n"; std::cout<<"m = "<<m<<std::endl; std::cout<<"ma = "<<ma<<std::endl; std::cout<<"mb = "<<mb<<std::endl; } typedef typename M::value_type T; typedef typename M::real_type RT; const int N = m.colsize(); tmv::Matrix<T> m2(N,N); RT eps = EPS * RT(N); if (!std::numeric_limits<RT>::is_integer) eps *= Norm(m); m1 = m; m1 = m1a * m1b; m2 = ma * mb; Assert(Equal(m1,m2,eps),label+" m=a*b"); m1 = m; m1 += m1a * m1b; m2 = m + ma * mb; Assert(Equal(m1,m2,eps),label+" m+=a*b"); m1 = m; m1 = T(10) * m1a * m1b; m2 = T(10) * ma * mb; Assert(Equal(m1,m2,eps),label+" m=10*a*b"); m1 = m; m1 += T(10) * m1a * m1b; m2 = m + T(10) * ma * mb; Assert(Equal(m1,m2,eps),label+" m+=10*a*b"); m1 = m; m1 = m1a * m1b.transpose(); m2 = ma * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m=a*bT"); m1 = m; m1 += m1a * m1b.transpose(); m2 = m + ma * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m+=a*bT"); m1 = m; m1 = T(10) * m1a * m1b.transpose(); m2 = T(10) * ma * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m=10*a*bT"); m1 = m; m1 += T(10) * m1a * m1b.transpose(); m2 = m + T(10) * ma * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m+=10*a*bT"); m1 = m; m1 = m1a.transpose() * m1b; m2 = ma.transpose() * mb; Assert(Equal(m1,m2,eps),label+" m=aT*b"); m1 = m; m1 += m1a.transpose() * m1b; m2 = m + ma.transpose() * mb; Assert(Equal(m1,m2,eps),label+" m+=aT*b"); m1 = m; m1 = T(10) * m1a.transpose() * m1b; m2 = T(10) * ma.transpose() * mb; Assert(Equal(m1,m2,eps),label+" m=10*aT*b"); m1 = m; m1 += T(10) * m1a.transpose() * m1b; m2 = m + T(10) * ma.transpose() * mb; Assert(Equal(m1,m2,eps),label+" m+=10*aT*b"); m1 = m; m1 = m1a.transpose() * m1b.transpose(); m2 = ma.transpose() * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m=aT*bT"); m1 = m; m1 += m1a.transpose() * m1b.transpose(); m2 = m + ma.transpose() * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m+=aT*bT"); m1 = m; m1 = T(10) * m1a.transpose() * m1b.transpose(); m2 = T(10) * ma.transpose() * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m=10*aT*bT"); m1 = m; m1 += T(10) * m1a.transpose() * m1b.transpose(); m2 = m + T(10) * ma.transpose() * mb.transpose(); Assert(Equal(m1,m2,eps),label+" m+=10*aT*bT"); }
double CColorMappingDlg::CycleLenToPos(double CycleLen) const { return(Norm(CycleLen, GetCycleLenBase(), 1, m_Quality) * CYCLE_LEN_RANGE); }
void Gmsh::FVMesh2Gmsh(FVMesh2D &m) // constructor which convert a FVMesh2D into a gmah struct { _dim=2; // a two dimension mesh FVVertex2D* ptr_v; _nb_node=m.getNbVertex(); _node.resize(_nb_node); for((ptr_v=m.beginVertex());(ptr_v=m.nextVertex());) { size_t i=ptr_v->label; _node[i-1].label = i; _node[i-1].coord.x= ptr_v->coord.x; _node[i-1].coord.y= ptr_v->coord.y; _node[i-1].coord.z= 0; } FVCell2D *ptr_c; double order[4],doux; size_t noux; FVPoint2D<double> Paux; _nb_element=m.getNbCell(); _element.resize(_nb_element); for((ptr_c=m.beginCell());(ptr_c=m.nextCell());) { size_t i=ptr_c->label; _element[i-1].label=i; switch(ptr_c->nb_vertex) { case 3: _element[i-1].type_element=2; // we use triangle break; case 4: _element[i-1].type_element=3; // we use quadrangle break; default: cout<<"cell does not correspond to a gmsh element. Abort convertion"<<endl; _nb_node=0;_nb_element=0; return; } _element[i-1].code_physical=ptr_c->code; _element[i-1].code_elementary=ptr_c->code; _element[i-1].dim=_dim; _element[i-1].nb_node=ptr_c->nb_vertex; for(size_t j=0;j<ptr_c->nb_vertex;j++) { _element[i-1].node[j]=ptr_c->vertex[j]->label; Paux.x=_node[_element[i-1].node[j]-1].coord.x-ptr_c->centroid.x; Paux.y=_node[_element[i-1].node[j]-1].coord.y-ptr_c->centroid.y; Paux/=Norm(Paux); order[j]=(1-Paux.x)*0.5;if(Paux.y<0) order[j]*=-1; } // reordering the node (bubble sort) to cast in the gmah framework following order for(size_t j=ptr_c->nb_vertex-1;j>0;j--) { for(size_t k=0;k<j;k++) { if(order[k+1]<order[k]) { doux=order[k+1];noux=_element[i-1].node[k+1]; order[k+1]=order[k];_element[i-1].node[k+1]=_element[i-1].node[k]; order[k]=doux;_element[i-1].node[k]=noux; } } } } }
bool Ellipse::doMeasureShapelet( const std::vector<PixelList>& pix, const std::vector<BVec>* psf, BVec& b, int order, int order2, int maxm, DMatrix* bCov) const { xdbg<<"Start MeasureShapelet: order = "<<order<<std::endl; xdbg<<"b.order, sigma = "<<b.getOrder()<<", "<<b.getSigma()<<std::endl; xdbg<<"el = "<<*this<<std::endl; if (maxm < 0 || maxm > order) maxm = order; xdbg<<"order = "<<order<<','<<order2<<','<<maxm<<std::endl; // ( u )' = exp(-mu)/sqrt(1-gsq) ( 1-g1 -g2 ) ( u-uc ) // ( v ) ( -g2 1+g1 ) ( v-vc ) // // z' = u' + I v' // = exp(-mu)/sqrt(1-gsq) // [ (1-g1)(u-uc)-g2(v-vc)-Ig2(u-uc)+I(1+g1)(v-vc) ] // = exp(-mu)/sqrt(1-gsq) [ z-zc - g1(z-zc)* -Ig2(z-zc)* ] // = exp(-mu)/sqrt(1-gsq) ( z-zc - g (z-zc)* ) double sigma = b.getSigma(); double gsq = std::norm(_gamma); Assert(gsq < 1.); std::complex<double> mm = exp(-_mu)/sqrt(1.-gsq); int bsize = (order+1)*(order+2)/2; xdbg<<"bsize = "<<bsize<<std::endl; int bsize2 = (order2+1)*(order2+2)/2; xdbg<<"bsize2 = "<<bsize2<<std::endl; int ntot = 0; const int nexp = pix.size(); for(int i=0;i<nexp;++i) ntot += pix[i].size(); dbg<<"ntot = "<<ntot<<" in "<<nexp<<" images\n"; if (ntot < bsize) { dbg<<"Too few pixels for given order.\n"; return false; } DVector I(ntot); DVector W(ntot); CDVector Z(ntot); for(int k=0,n=0;k<nexp;++k) { double sigma_obs = psf ? sqrt(pow(sigma,2)+pow((*psf)[k].getSigma(),2)) : sigma; xdbg<<"sigma_obs["<<k<<"] = "<<sigma_obs<<std::endl; const int npix = pix[k].size(); for(int i=0;i<npix;++i,++n) { I(n) = pix[k][i].getFlux()*pix[k][i].getInverseSigma(); W(n) = pix[k][i].getInverseSigma(); std::complex<double> z1 = pix[k][i].getPos(); std::complex<double> z2 = mm*((z1-_cen) - _gamma*conj(z1-_cen)); Z(n) = z2 / sigma_obs; } } //xdbg<<"Z = "<<Z<<std::endl; //xdbg<<"I = "<<I<<std::endl; //xdbg<<"W = "<<W<<std::endl; #ifdef USE_TMV // Figure out a permutation that puts all the m <= maxm first. // I don't know how to do this with Eigen, but I don't really // use maxm < order on a regular basis, so only implement this for TMV. tmv::Permutation P(bsize); int msize = bsize; if (maxm < order) { tmv::Vector<double> mvals(bsize); for(int n=0,k=0;n<=order;++n) { for(int m=n;m>=0;m-=2) { mvals[k++] = m; if (m > 0) mvals[k++] = m; } } xdbg<<"mvals = "<<mvals<<std::endl; mvals.sort(P); xdbg<<"mvals => "<<mvals<<std::endl; // 00 10 10 20 20 11 30 30 21 21 40 40 31 31 22 50 50 41 41 32 32 // n = 0 1 2 3 4 5 6 // 0size = 1 1 2 2 3 3 4 = (n)/2 + 1 // 1size = 1 3 4 6 7 9 10 = (3*(n-1))/2 + 3 // 2size = 1 3 6 8 11 13 16 = (5*(n-2))/2 + 6 // 3size = 1 3 6 10 13 17 20 = (7*(n-3))/2 + 10 // nsize = (n+1)*(n+2)/2 // msize = (m+1)*(m+2)/2 + (2*m+1)*(n-m)/2 msize = (maxm+1)*(maxm+2)/2 + (2*maxm+1)*(order-maxm)/2; xdbg<<"msize = "<<msize<<std::endl; xdbg<<"mvals["<<msize-1<<"] = "<<mvals[msize-1]<<std::endl; xdbg<<"mvals["<<msize<<"] = "<<mvals[msize]<<std::endl; Assert(mvals[msize-1] == maxm); Assert(mvals[msize] == maxm+1); } #endif DMatrix A(ntot,bsize); Assert(ntot >= bsize); // Should have been addressed by calling routine. //xdbg<<"A = "<<A<<std::endl; if (psf) { for(int k=0,n=0,nx;k<nexp;++k,n=nx) { xdbg<<"psf = "<<(*psf)[k]<<std::endl; int psforder = (*psf)[k].getOrder(); int newpsforder = std::max(psforder,order2); xdbg<<"psforder = "<<psforder<<std::endl; xdbg<<"newpsforder = "<<newpsforder<<std::endl; const double psfsigma = (*psf)[k].getSigma(); xdbg<<"sigma = "<<psfsigma<<std::endl; BVec newpsf(newpsforder,psfsigma); int psfsize = (*psf)[k].size(); int newpsfsize = newpsf.size(); xdbg<<"psfsize = "<<psfsize<<std::endl; bool setnew = false; if (_gamma != 0.) { DMatrix S(newpsfsize,psfsize); CalculateGTransform(_gamma,newpsforder,psforder,S); newpsf.vec() = S * (*psf)[k].vec(); setnew = true; xdbg<<"newpsf = "<<newpsf<<std::endl; } if (real(_mu) != 0.) { if (setnew) { DMatrix D(newpsfsize,newpsfsize); CalculateMuTransform(real(_mu),newpsforder,D); newpsf.vec() = D * newpsf.vec(); } else { DMatrix D(newpsfsize,psfsize); CalculateMuTransform(real(_mu),newpsforder,psforder,D); newpsf.vec() = D * (*psf)[k].vec(); setnew = true; } newpsf.vec() *= exp(2.*real(_mu)); xdbg<<"newpsf => "<<newpsf<<std::endl; } if (imag(_mu) != 0.) { if (setnew) { #ifdef USE_TMV DBandMatrix R(newpsfsize,newpsfsize,1,1); #else DBandMatrix R(newpsfsize,newpsfsize); #endif CalculateThetaTransform(imag(_mu),newpsforder,R); newpsf.vec() = R * newpsf.vec(); } else { #ifdef USE_TMV DBandMatrix R(newpsfsize,psfsize,1,1); #else DBandMatrix R(newpsfsize,psfsize); #endif CalculateThetaTransform(imag(_mu),newpsforder,psforder,R); newpsf.vec() = R * (*psf)[k].vec(); setnew = true; } xdbg<<"newpsf => "<<newpsf<<std::endl; } DMatrix C(bsize2,bsize); if (setnew) { CalculatePsfConvolve(newpsf,order2,order,b.getSigma(),C); } else { CalculatePsfConvolve((*psf)[k],order2,order,b.getSigma(),C); } const int npix = pix[k].size(); nx = n+npix; DMatrix A1(npix,bsize2); DVectorView W1 = W.TMV_subVector(n,nx); MakePsi(A1,Z.TMV_subVector(n,nx),order2,&W1); TMV_rowRange(A,n,nx) = A1 * C; } } else { DVectorView W1 = TMV_view(W); MakePsi(A,TMV_vview(Z),order,&W1); } const double MAX_CONDITION = 1.e8; #ifdef USE_TMV A *= P.transpose(); tmv::MatrixView<double> Am = A.colRange(0,msize); // I used to use SVD for this, rather than the QRP decomposition. // But QRP is significantly faster, and the condition estimate // produced is good enough for what we need here. // TODO: I need to add a real condition estimator to division methods // other than SVD in TMV. LAPACK has this functionality... Am.saveDiv(); Am.divideUsing(tmv::QRP); Am.qrpd(); xdbg<<"R diag = "<<Am.qrpd().getR().diag()<<std::endl; if ( #if TMV_VERSION_AT_LEAST(0,65) Am.qrpd().isSingular() || #else // Fixed a bug in the isSingular function in v0.65. // Until that is the standard TMV version for DES, use this instead: (Am.qrpd().getR().diag().minAbs2Element() < 1.e-16 * Am.qrpd().getR().diag().maxAbs2Element()) || #endif DiagMatrixViewOf(Am.qrpd().getR().diag()).condition() > MAX_CONDITION) { dbg<<"Poor condition in MeasureShapelet: \n"; dbg<<"R diag = "<<Am.qrpd().getR().diag()<<std::endl; dbg<<"condition = "<< DiagMatrixViewOf(Am.qrpd().getR().diag()).condition()<< std::endl; dbg<<"det = "<<Am.qrpd().det()<<std::endl; return false; } b.vec().subVector(0,msize) = I/Am; xdbg<<"b = "<<b<<std::endl; xdbg<<"Norm(I) = "<<Norm(I)<<std::endl; xdbg<<"Norm(Am*b) = "<<Norm(Am*b.vec().subVector(0,msize))<<std::endl; xdbg<<"Norm(I-Am*b) = "<<Norm(I-Am*b.vec().subVector(0,msize))<<std::endl; b.vec().subVector(msize,bsize).setZero(); b.vec().subVector(0,bsize) = P.transpose() * b.vec().subVector(0,bsize); xdbg<<"b => "<<b<<std::endl; if (bCov) { bCov->setZero(); Am.makeInverseATA(bCov->subMatrix(0,msize,0,msize)); bCov->subMatrix(0,bsize,0,bsize) = P.transpose() * bCov->subMatrix(0,bsize,0,bsize) * P; } #else Eigen::SVD<DMatrix> svd = A.svd().sort(); const DMatrix& svd_u = svd.matrixU(); const DVector& svd_s = svd.singularValues(); const DMatrix& svd_v = svd.matrixV(); double max = svd_s(0); double min = svd_s(svd_s.size()-1); if (max > MAX_CONDITION * min) { xdbg<<"Poor condition in MeasureShapelet: \n"; xdbg<<"svd = "<<svd_s.transpose()<<std::endl; xdbg<<"condition = "<<max/min<<std::endl; return false; } // USVtb = I // b = VS^-1UtI DVector temp = svd_u.transpose() * I; temp = svd_s.cwise().inverse().asDiagonal() * temp; b.vec().TMV_subVector(0,bsize) = svd_v * temp; if (bCov) { bCov->setZero(); // (AtA)^-1 = (VSUt USVt)^-1 = (V S^2 Vt)^-1 = V S^-2 Vt bCov->TMV_subMatrix(0,bsize,0,bsize) = svd_v * svd_s.cwise().square().cwise().inverse().asDiagonal() * svd_v.transpose(); } #endif if (!(b(0) > 0.)) { dbg<<"Calculated b vector has negative b(0):\n"; dbg<<"b = "<<b<<std::endl; return false; } if (order < b.getOrder()) { xdbg<<"Need to zero the rest of b\n"; xdbg<<"bsize = "<<bsize<<" b.size = "<<b.size()<<std::endl; // Zero out the rest of the shapelet vector: b.vec().TMV_subVector(bsize,b.size()).setZero(); } xdbg<<"Done measure Shapelet\n"; xdbg<<"b = "<<b.vec()<<std::endl; return true; }
void Gmsh::FVMesh2Gmsh(FVMesh3D &m) // constructor which convert a FVMesh3D into a gmah struct { _dim=3; // a three dimension mesh FVVertex3D* ptr_v; FVEdge3D* ptr_e; FVFace3D* ptr_f; FVCell3D *ptr_c; FVPoint3D<double> Paux,t1,t2; double order[5],doux; size_t noux; size_t it; _nb_node=m.getNbVertex(); _node.resize(_nb_node); //cout<<"find "<<_nb_node<<" nodes"<<endl;fflush(NULL); for((ptr_v=m.beginVertex());(ptr_v=m.nextVertex());) { size_t i=ptr_v->label; _node[i-1].label = i; _node[i-1].coord.x= ptr_v->coord.x; _node[i-1].coord.y= ptr_v->coord.y; _node[i-1].coord.z= ptr_v->coord.z; } _nb_element=m.getNbCell(); _element.resize(_nb_element); //cout<<"find "<<_nb_element<<" elements"<<endl;fflush(NULL); for((ptr_c=m.beginCell());(ptr_c=m.nextCell());) { size_t i=ptr_c->label; _element[i-1].label=i; _element[i-1].code_physical=ptr_c->code; _element[i-1].code_elementary=ptr_c->code; _element[i-1].dim=_dim; _element[i-1].nb_node=ptr_c->nb_vertex; //cout<<"element "<<i<<" with "<<ptr_c->nb_vertex<<" nodes"<<endl;fflush(NULL); switch(_element[i-1].nb_node) { case 4: _element[i-1].type_element=4; // we use tetrahedron for(size_t j=0;j<4;j++) // the order is not important _element[i-1].node[j]=ptr_c->vertex[j]->label; break; case 5: _element[i-1].type_element=7; // pyramid it=0; for((ptr_f=ptr_c->beginFace());(ptr_f=ptr_c->nextFace());it++) { if( ptr_c->face[it]->nb_vertex==4) break; } if (it>=ptr_c->nb_face) {cout<<" not a pyramidal element"<<endl;return;} ptr_f=ptr_c->face[it]; // ok, I have the 4-vertex-face now I load the 5 nodes for(size_t j=0;j<5;j++) _element[i-1].node[j]=ptr_c->vertex[j]->label; // the "positive" vertex is the top of the pyramid for(size_t j=0;j<5;j++) { Paux=_node[_element[i-1].node[j]-1].coord-ptr_c->centroid; doux=Paux*ptr_c->cell2face[it]; if(doux<0) {noux=_element[i-1].node[j];_element[i-1].node[j]=_element[i-1].node[4];_element[i-1].node[4]=noux;} } // at that stge the node[4] is the top vertex // we have to sort the four first points. t1.x=ptr_c->cell2face[it].y;t1.y=-ptr_c->cell2face[it].y;t1.z=0;t1/=Norm(t1);// first tangente t2.x=ptr_c->cell2face[it].z;t2.z=-ptr_c->cell2face[it].x;t2.y=0;t2/=Norm(t2);// second tangente for(size_t j=0;j<3;j++) { Paux=_node[_element[i-1].node[j]-1].coord-ptr_f->centroid; Paux/=Norm(Paux); order[j]=(1-Paux*t1)*0.5;if(Paux*t2<0) order[j]*=-1; } for(size_t j=3;j>0;j--) { for(size_t k=0;k<j;k++) { if(order[k+1]<order[k]) { doux=order[k+1];noux=_element[i-1].node[k+1]; order[k+1]=order[k];_element[i-1].node[k+1]=_element[i-1].node[k]; order[k]=doux;_element[i-1].node[k]=noux; } } } break; case 6: _element[i-1].type_element=6; // prism it=0; for((ptr_f=ptr_c->beginFace());(ptr_f=ptr_c->nextFace());it++) {if(ptr_f->nb_vertex==3) break;} for(size_t j=0;j<3;j++) {_element[i-1].node[j]=ptr_f->vertex[j]->label;_element[i-1].node[j+3]=0;} // at that stage the basement face is ordered // we see the complementary point for(size_t j=0;j<3;j++) { it=_element[i-1].node[j]; // take a node of the reference base for((ptr_f=ptr_c->beginFace());(ptr_f=ptr_c->nextFace());) for((ptr_e=ptr_f->beginEdge());(ptr_e=ptr_f->nextEdge());) { if((ptr_e->firstVertex->label!=it) && (ptr_e->secondVertex->label!=it)) continue; if(ptr_e->firstVertex->label==it) noux=ptr_e->secondVertex->label; else noux=ptr_e->firstVertex->label; bool still_exist=false; for(size_t k=0;k<3;k++) if(noux==_element[i-1].node[k]) still_exist=true; if(!still_exist) {_element[i-1].node[j+3]=noux;} } } // check if we have really 6 nodes for(size_t j=0;j<6;j++) { if(! _element[i-1].node[j]) { cout<<" Not a prism element: abort convertion"<<endl; return; } } break; case 8: _element[i-1].type_element=5; // cube ptr_f=ptr_c->face[0]; // reference face for(size_t j=0;j<4;j++) _element[i-1].node[j]=ptr_f->vertex[j]->label; // we have to sort the four first points. t1= _node[_element[i-1].node[0]-1].coord-ptr_f->centroid;t1/=Norm(t1);// first tangente t2=CrossProduct(t1,ptr_f->normal[0]);t2/=Norm(t2);// second tangente for(size_t j=0;j<4;j++) { Paux=_node[_element[i-1].node[j]-1].coord-ptr_f->centroid; Paux/=Norm(Paux); order[j]=(1-Paux*t1)*0.5;if(Paux*t2<0) order[j]*=-1; } for(size_t j=3;j>0;j--) { for(size_t k=0;k<j;k++) { if(order[k+1]<order[k]) { doux=order[k+1];noux=_element[i-1].node[k+1]; order[k+1]=order[k];_element[i-1].node[k+1]=_element[i-1].node[k]; order[k]=doux;_element[i-1].node[k]=noux; } } } // at that stage the basement face is ordered // we see the complementary point for(size_t j=0;j<4;j++) { it=_element[i-1].node[j]; // take a node of the reference base for((ptr_f=ptr_c->beginFace());(ptr_f=ptr_c->nextFace());) for((ptr_e=ptr_f->beginEdge());(ptr_e=ptr_f->nextEdge());) { if((ptr_e->firstVertex->label!=it) && (ptr_e->secondVertex->label!=it)) continue; if(ptr_e->firstVertex->label==it) noux=ptr_e->secondVertex->label; else noux=ptr_e->firstVertex->label; bool still_exist=false; for(size_t k=0;k<4;k++) if(noux==_element[i-1].node[k]) still_exist=true; if(!still_exist) _element[i-1].node[j+4]=noux; } } break; default: cout<<"cell does not correspond to a gmsh element. Abort convertion"<<endl; _nb_node=0;_nb_element=0; return; } } }
double FVRecons3D::_evalMean(void *ptr,size_t type,size_t alpha1,size_t alpha2,size_t alpha3) { FVPoint3D<double> P1,P2,P; double sum,S,S_global,aux,V,V_global; sum=0.; FVPoint2D<double> GPEdge; FVPoint3D<double> GPFace; FVPoint4D<double> GPCell; FVGaussPoint1D G1D; FVGaussPoint2D G2D; FVGaussPoint3D G3D; FVCell3D *ptr_c; FVFace3D *ptr_f; FVEdge3D *ptr_e; FVVertex3D *ptr_v1,*ptr_v2; FVPoint3D<double> centroidF,centroidC; switch(type) { case FVVERTEX3D: P=((FVVertex3D *)ptr)->coord; return(pow(P.x-_ref_point.x,(double)alpha1)*pow(P.y-_ref_point.y,(double)alpha2)*pow(P.z-_ref_point.z,(double)alpha3)); //break; case FVEDGE3D: P1=((FVEdge3D *)ptr)->firstVertex->coord; P2=((FVEdge3D *)ptr)->secondVertex->coord; GPEdge=G1D.getPoint(5,1); P=GPEdge.x*P1+GPEdge.y*P2; sum+=G1D.getWeight(5,1)*pow(P.x-_ref_point.x,(double)alpha1)*pow(P.y-_ref_point.y,(double)alpha2)*pow(P.z-_ref_point.z,(double)alpha3); GPEdge=G1D.getPoint(5,2); P=GPEdge.x*P1+GPEdge.y*P2; sum+=G1D.getWeight(5,2)*pow(P.x-_ref_point.x,(double)alpha1)*pow(P.y-_ref_point.y,(double)alpha2)*pow(P.z-_ref_point.z,(double)alpha3); GPEdge=G1D.getPoint(5,3); P=GPEdge.x*P1+GPEdge.y*P2; sum+=G1D.getWeight(5,3)*pow(P.x-_ref_point.x,(double)alpha1)*pow(P.y-_ref_point.y,(double)alpha2)*pow(P.z-_ref_point.z,(double)alpha3); return(sum); //break; case FVFACE3D: ptr_f=((FVFace3D *)ptr); centroidF=ptr_f->centroid; S_global=0; ptr_f->beginEdge(); while((ptr_e=ptr_f->nextEdge())) { ptr_v1=ptr_e->firstVertex; ptr_v2=ptr_e->secondVertex; S= Norm(CrossProduct(ptr_v1->coord-centroidF,ptr_v2->coord-centroidF))*0.5; if(S<0) S*=-1.; aux=0; for (size_t i=1;i<=G2D.getNbPoint(5);i++) { GPFace=G2D.getPoint(5,i); P=GPFace.x*ptr_v1->coord+GPFace.y*ptr_v2->coord+GPFace.z*centroidF; aux+=G2D.getWeight(5,i)*pow(P.x-_ref_point.x,(double)alpha1)*pow(P.y-_ref_point.y,(double)alpha2)*pow(P.z-_ref_point.z,(double)alpha3); } sum+=aux*S; S_global+=S; } return(sum/S_global); //break; case FVCELL3D: ptr_c=((FVCell3D *)ptr); centroidC=ptr_c->centroid; V_global=0; ptr_c->beginFace(); while((ptr_f=ptr_c->nextFace())) { centroidF=ptr_f->centroid; ptr_f->beginEdge(); while((ptr_e=ptr_f->nextEdge())) { ptr_v1=ptr_e->firstVertex; ptr_v2=ptr_e->secondVertex; V= Det(ptr_v1->coord-centroidC,ptr_v2->coord-centroidC,centroidF-centroidC)/6; if(V<0) V*=-1.; aux=0; for(size_t i=1;i<=G3D.getNbPoint(5);i++) { GPCell=G3D.getPoint(5,i); P=GPCell.x*ptr_v1->coord+GPCell.y*ptr_v2->coord+GPCell.z*centroidF+GPCell.t*centroidC; aux+=G3D.getWeight(5,i)*pow(P.x-_ref_point.x,(double)alpha1)*pow(P.y-_ref_point.y,(double)alpha2)*pow(P.z-_ref_point.z,(double)alpha3); } sum+=aux*V; V_global+=V; } } return(sum/V_global); //break; default: cout<<"WARNING: unknow geometrical entity in FVReconstruction3D"<<endl; return(0); //break; } //return(0); }
inline Vector2F& Vector2F::Normalize () { *this /= Norm(); return *this; }