void Broadcaster::initiatePosition(){ if(SpawnPoint.empty()){ for(const tmx::MapLayer layers : map->GetLayers()){ if(layers.name == "Spawn"){ for(const tmx::MapObject point : layers.objects){ SpawnPoint.push_back(point.GetPosition()); } } } } QString newZ("N "); for(ClientThread* playa : *clientList){ newZ += QString::number(playa->getNumber()) + QString(" "); playa->resetCounter(); } newZ += "\n"; EventQueue.append(newZ); std::shuffle(SpawnPoint.begin(), SpawnPoint.end(), rng); int playerSize = clientList->size(); // qDebug() << playerSize; for(int i = 0; i < playerSize; i++){ clientList->at(i)->setInitialPosition(SpawnPoint.at(i)); EventQueue.append( "WD " + QString::number(clientList->at(i)->getNumber()) + QString(" ") + QString::number(SpawnPoint.at(i).x) + QString(" ") + QString::number(SpawnPoint.at(i).y) + QString(" ") + QString::number(0) +"\n"); } }
void SMACOF::run( const Matrix<double>& Weights, const Matrix<double>& Distances, const double& tol, const unsigned& maxloops, Matrix<double>& InitialZ ) { unsigned M = Distances.nrows(); // Calculate V Matrix<double> V(M,M); double totalWeight=0.; for(unsigned i=0; i<M; ++i) { for(unsigned j=0; j<M; ++j) { if(i==j) continue; V(i,j)=-Weights(i,j); if( j<i ) totalWeight+=Weights(i,j); } for(unsigned j=0; j<M; ++j) { if(i==j)continue; V(i,i)-=V(i,j); } } // And pseudo invert V Matrix<double> mypseudo(M, M); pseudoInvert(V, mypseudo); Matrix<double> dists( M, M ); double myfirstsig = calculateSigma( Weights, Distances, InitialZ, dists ) / totalWeight; // initial sigma is made up of the original distances minus the distances between the projections all squared. Matrix<double> temp( M, M ), BZ( M, M ), newZ( M, InitialZ.ncols() ); for(unsigned n=0; n<maxloops; ++n) { if(n==maxloops-1) plumed_merror("ran out of steps in SMACOF algorithm"); // Recompute BZ matrix for(unsigned i=0; i<M; ++i) { for(unsigned j=0; j<M; ++j) { if(i==j) continue; //skips over the diagonal elements if( dists(i,j)>0 ) BZ(i,j) = -Weights(i,j)*Distances(i,j) / dists(i,j); else BZ(i,j)=0.; } //the diagonal elements are -off diagonal elements BZ(i,i)-=BZ(i,j) (Equation 8.25) BZ(i,i)=0; //create the space memory for the diagonal elements which are scalars for(unsigned j=0; j<M; ++j) { if(i==j) continue; BZ(i,i)-=BZ(i,j); } } mult( mypseudo, BZ, temp); mult(temp, InitialZ, newZ); //Compute new sigma double newsig = calculateSigma( Weights, Distances, newZ, dists ) / totalWeight; //Computing whether the algorithm has converged (has the mass of the potato changed //when we put it back in the oven!) if( fabs( newsig - myfirstsig )<tol ) break; myfirstsig=newsig; InitialZ = newZ; } }
//--------------------------------------------------------- void NDG2D::OutputVTK(const DMat& FData, int order, int zfield) //--------------------------------------------------------- { static int count = 0; string output_dir = "."; // The caller loads each field of interest into FData, // storing (Np*K) scalars per column. // // For high (or low) resolution output, the user can // specify an arbitrary order of interpolation for // exporting the fields. Thus while a simulation may // use N=3, we can export the solution fields with // high-order, regularized elements (e.g. with N=12). string buf = umOFORM("%s/sim_N%02d_%04d.vtk", output_dir.c_str(), order, ++count); FILE *fp = fopen(buf.c_str(), "w"); if (!fp) { umLOG(1, "Could no open %s for output!\n", buf.c_str()); return; } // Set flags and totals int Output_N = std::max(2, order); int Ncells=0, Npts=0; Ncells = OutputSampleNelmt2D(Output_N); Npts = OutputSampleNpts2D (Output_N); // set totals for Vtk output int vtkTotalPoints = this->K * Npts; int vtkTotalCells = this->K * Ncells; int vtkTotalConns = (this->EToV.num_cols()+1) * this->K * Ncells; //------------------------------------- // 1. Write the VTK header details //------------------------------------- fprintf(fp, "# vtk DataFile Version 2"); fprintf(fp, "\nNuDG++ 2D simulation"); fprintf(fp, "\nASCII"); fprintf(fp, "\nDATASET UNSTRUCTURED_GRID\n"); fprintf(fp, "\nPOINTS %d double", vtkTotalPoints); int newNpts=0; //------------------------------------- // 2. Write the vertex data //------------------------------------- DMat newX, newY, newZ, newFData; // Build new {X,Y,Z} vertices that regularize the // elements, then interpolate solution fields onto // this new set of elements: OutputSampleXYZ(Output_N, newX, newY, newZ, FData, newFData, zfield); //double maxF1 = newFData.max_col_val_abs(1), scaleF=1.0; //if (maxF1 != 0.0) { scaleF = 1.0/maxF1; } newNpts = newX.num_rows(); if (zfield>0) { // write 2D vertex data, with z-elevation for (int k=1; k<=this->K; ++k) { for (int n=1; n<=newNpts; ++n) { // use exponential format to allow for // arbitrary (astro, nano) magnitudes: fprintf(fp, "\n%20.12e %20.12e %20.12e", newX(n, k), newY(n, k), newZ(n,k)); //*scaleF); } } } else { // write 2D vertex data to file for (int k=1; k<=this->K; ++k) { for (int n=1; n<=newNpts; ++n) { // use exponential format to allow for // arbitrary (astro, nano) magnitudes: fprintf(fp, "\n%20.12e %20.12e 0.0", newX(n, k), newY(n, k)); } } } //------------------------------------- // 3. Write the element connectivity //------------------------------------- IMat newELMT; // Number of indices required to define connectivity fprintf(fp, "\n\nCELLS %d %d", vtkTotalCells, vtkTotalConns); // build regularized tri elements at selected order OutputSampleELMT2D(Output_N, newELMT); newNpts = OutputSampleNpts2D(Output_N); int newNTri = newELMT.num_rows(); int newNVert = newELMT.num_cols(); // write element connectivity to file for (int k=0; k<this->K; ++k) { int nodesk = k*newNpts; for (int n=1; n<=newNTri; ++n) { fprintf(fp, "\n%d", newNVert); for (int i=1; i<=newNVert; ++i) { fprintf(fp, " %5d", nodesk+newELMT(n, i)); } } } //------------------------------------- // 4. Write the cell types //------------------------------------- // For each element (cell) write a single integer // identifying the cell type. The integer should // correspond to the enumeration in the vtk file: // /VTK/Filtering/vtkCellType.h fprintf(fp, "\n\nCELL_TYPES %d", vtkTotalCells); for (int k=0; k<this->K; ++k) { fprintf(fp, "\n"); for (int i=1; i<=Ncells; ++i) { fprintf(fp, "5 "); // 5:VTK_TRIANGLE if (! (i%10)) fprintf(fp, "\n"); } } //------------------------------------- // 5. Write the scalar "vtkPointData" //------------------------------------- fprintf(fp, "\n\nPOINT_DATA %d", vtkTotalPoints); // For each field, write POINT DATA for each point // in the vtkUnstructuredGrid. int Nfields = FData.num_cols(); for (int fld=1; fld<=Nfields; ++fld) { fprintf(fp, "\nSCALARS field%d double 1", fld); fprintf(fp, "\nLOOKUP_TABLE default"); // Write the scalar data, using exponential format // to allow for arbitrary (astro, nano) magnitudes: for (int n=1; n<=newFData.num_rows(); ++n) { fprintf(fp, "\n%20.12e ", newFData(n, fld)); } } // add final newline to output fprintf(fp, "\n"); fclose(fp); }