void peanoclaw::parallel::MasterWorkerAndForkJoinCommunicator::sendCellDuringForkOrJoin( const Cell& localCell, const tarch::la::Vector<DIMENSIONS, double>& position, const tarch::la::Vector<DIMENSIONS, double>& size, const State& state ) { #ifdef Parallel bool isForking = tarch::parallel::Node::getInstance().isGlobalMaster() || _remoteRank != tarch::parallel::NodePool::getInstance().getMasterRank(); if(localCell.isInside() && ( (isForking && localCell.getRankOfRemoteNode() == _remoteRank) || (!isForking && !localCell.isAssignedToRemoteRank()) ) ) { if(localCell.holdsSubgrid()) { Patch subgrid(localCell); _subgridCommunicator.sendSubgrid(subgrid); //Switch to remote after having sent the patch away... subgrid.setIsRemote(true); ParallelSubgrid parallelSubgrid(localCell); parallelSubgrid.resetNumberOfTransfersToBeSkipped(); } } #endif }
void peanoclaw::parallel::MasterWorkerAndForkJoinCommunicator::receivePatch(int localCellDescriptionIndex) { logTraceInWith3Arguments("receivePatch", localCellDescriptionIndex, _position, _level); #ifdef Parallel std::vector<CellDescription> remoteCellDescriptionVector = CellDescriptionHeap::getInstance().receiveData(_remoteRank, _position, _level, _messageType); assertionEquals2(remoteCellDescriptionVector.size(), 1, _position, _level); CellDescription remoteCellDescription = remoteCellDescriptionVector[0]; assertion3(localCellDescriptionIndex >= 0, localCellDescriptionIndex, _position, _level); CellDescription localCellDescription = CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).at(0); #ifdef Asserts assertionNumericalEquals2(remoteCellDescription.getPosition(), localCellDescription.getPosition(), localCellDescription.toString(), remoteCellDescription.toString()); assertionNumericalEquals2(remoteCellDescription.getSize(), localCellDescription.getSize(), localCellDescription.toString(), remoteCellDescription.toString()); assertionEquals2(remoteCellDescription.getLevel(), localCellDescription.getLevel(), localCellDescription.toString(), remoteCellDescription.toString()); #endif //Load arrays and stores according indices in cell description if(remoteCellDescription.getUIndex() != -1) { remoteCellDescription.setUIndex(_subgridCommunicator.receiveDataArray()); } //Reset undesired values remoteCellDescription.setNumberOfTransfersToBeSkipped(0); //Copy remote cell description to local cell description deleteArraysFromPatch(localCellDescriptionIndex); remoteCellDescription.setCellDescriptionIndex(localCellDescriptionIndex); CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).at(0) = remoteCellDescription; assertionEquals(CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).size(), 1); Patch subgrid(localCellDescriptionIndex); subgrid.initializeNonParallelFields(); //TODO unterweg debug // std::cout << "Received cell description on rank " << tarch::parallel::Node::getInstance().getRank() // << " from rank " << _remoteRank << ": " << remoteCellDescription.toString() << std::endl << subgrid.toStringUNew() << std::endl; #if defined(AssertForPositiveValues) && defined(Asserts) if(subgrid.isLeaf() || subgrid.isVirtual()) { assertion4(!subgrid.containsNonPositiveNumberInUnknownInUNew(0), tarch::parallel::Node::getInstance().getRank(), _remoteRank, subgrid, subgrid.toStringUNew()); } #endif assertionEquals(CellDescriptionHeap::getInstance().getData(localCellDescriptionIndex).at(0).getCellDescriptionIndex(), localCellDescriptionIndex); #endif logTraceOut("receivePatch"); }
void VirtualRelay::findForces(Grid& knownWorld) { force.j=0; force.i=0; for(int neighbour_index=0; neighbour_index<Neighbours.size(); neighbour_index++) { double force_temp; VirtualRelay* interactor = Neighbours[neighbour_index]; IJ_Componet d; d.j=interactor->getLocation().getRow()-Location.getRow(); d.i=interactor->getLocation().getColumn()-Location.getColumn(); d.set_magnetude(); SubGrid subgrid(knownWorld, Location, interactor->getLocation()); int walls_left_top, walls_right_bot, walls_left_bot, walls_right_top; subgrid.Wall_count(Location,walls_left_top, walls_right_bot , walls_left_bot, walls_right_top); //cout<<"Walls"<<walls_left_top+walls_right_bot<<endl; double PL_do=10*path_loss_exp*log(d0); if(d.magnetude==0) { force_temp = 0; } else { force_temp = (PL_do + 10*path_loss_exp*log(d.magnetude)+WL*(walls_left_top+walls_right_bot)); } double theta; // cout<<d_j<<"/"<<d_i<<endl; if(d.i==0) { theta =3.141519/2; //stop dev by 0 error } else { double ratio =d.j /d.i; // cout<<"Ratio"<<ratio<<endl; theta= atan(ratio); } if(d.j>0 && d.i>0) { //first quata theta=theta; } else if(d.j>=0 && d.i<0) { //second quata theta=3.141519-theta; } else if(d.j<=0 && d.i<0) { //thrid quata theta=theta+3.141519; } else if(d.j>0 && d.i>0) { //fourth theta= -theta; } // cout<<"theta:"<<theta<<endl; // cout<<"Force:"<<Force_temp<<endl; force.j=force.j+force_temp*sin(theta); force.i=force.i+force_temp*cos(theta); // cout<<"i:"<<Force_temp*cos(theta)<<" j:"<<Force_temp*sin(theta)<<endl; } //cout<<"i fin:"<<Force_i<<" j fin:"<<Force_j<<endl<<endl; }