/* stores the locations of all current work in the cluster */ void Cluster::storeBlockLocs() { /* loop through every physical node */ for (unsigned int rank = 0; rank < this->getNumNodes(); ++rank) { const Node& n = this->getNode(rank); /* loop through work on each node */ for (unsigned int block = 0; block < n.numSubDomains(); ++block) { SubDomain *currentBlock = n.getSubDomain(block); int linIndex = currentBlock->getLinIndex(); //fprintf(stderr, "***linIndex:%d.\n", linIndex); this->setBlockLoc(linIndex, rank); } /* loop through all devices on node */ for (unsigned int c = 0; c < n.getNumChildren(); ++c) { const Node& child = n.getChild(c); /* loop through all work on each device */ for (unsigned int block = 0; block < child.numSubDomains(); ++block) { SubDomain *currentBlock = child.getSubDomain(block); int linIndex = currentBlock->getLinIndex(); //fprintf(stderr, "***linIndex:%d.", linIndex); this->setBlockLoc(linIndex, rank); } } } /* stores the ranks of all neighbors on each task block */ this->updateBlockNeighbors(); }
void Project::DisplayDomain(int index) { if (index == 0 && fullDomain) { SetVisibleDomain(fullDomain); if (projectTree) { projectTree->setCurrentItem(projectTree->findItems("Full Domain", Qt::MatchExactly | Qt::MatchRecursive).first()); } if (editSubdomainList) { editSubdomainList->clearSelection(); } } else if (index <= subDomains.size()) { SubDomain *targetDomain = subDomains.at(index-1); if (targetDomain) { QString name = targetDomain->GetDomainName(); SetVisibleDomain(subDomains.at(index-1)); if (projectTree) { projectTree->setCurrentItem(projectTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } if (editSubdomainList) { editSubdomainList->setCurrentItem(editSubdomainList->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } }
SubDomain* Node::popSubDomain() { SubDomain* s = subD.back(); subD.pop_back(); int linear_index = s->getLinIndex(); linear_lookup.erase(linear_lookup.find(linear_index)); return s; }
void Project::SaveSubdomainChanges(QString subdomain) { Domain *targetDomain = DetermineDomain(subdomain); SubDomain *targetSubdomain = DetermineSubdomain(targetDomain); if (targetSubdomain) { targetSubdomain->SaveAllChanges(); } }
void Project::ResetNodalValues(QString subdomainName, unsigned int nodeNumber) { Domain *currentDomain = DetermineDomain(subdomainName); if (currentDomain && fullDomain) { SubDomain *currentSubdomain = DetermineSubdomain(currentDomain); if (currentSubdomain) currentSubdomain->ResetNodalValues(nodeNumber, fullDomain->GetFort14()); } }
void Project::ResetAllNodalValues(QString subdomainName) { Domain *currentDomain = DetermineDomain(subdomainName); if (currentDomain && fullDomain) { SubDomain *currentSubdomain = DetermineSubdomain(currentDomain); if (currentSubdomain) currentSubdomain->ResetAllNodalValues(fullDomain->GetFort14()); } }
void Project::SetVisibleDomain(Domain *newDomain) { if (newDomain) { visibleDomain = newDomain; if (glPanel) glPanel->SetActiveDomainNew(visibleDomain); Fort14 *currFort14 = visibleDomain->GetFort14(); if (currFort14) { emit numElements(currFort14->GetNumElements()); emit numNodes(currFort14->GetNumNodes()); } emit undoAvailable(visibleDomain->UndoAvailable()); emit redoAvailable(visibleDomain->RedoAvailable()); if (displayOptions && displayOptions->isVisible()) { displayOptions->SetActiveDomain(visibleDomain); displayOptions->update(); } if (projectTree) { if (visibleDomain == fullDomain) projectTree->setCurrentItem(projectTree->findItems("Full Domain", Qt::MatchExactly | Qt::MatchRecursive).first()); else { SubDomain *targetDomain = DetermineSubdomain(visibleDomain); if (targetDomain) { QString name = targetDomain->GetDomainName(); projectTree->setCurrentItem(projectTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } if (editSubdomainList) { if (visibleDomain == fullDomain) editSubdomainList->clearSelection(); else { SubDomain *targetDomain = DetermineSubdomain(visibleDomain); if (targetDomain) { QString name = targetDomain->GetDomainName(); editSubdomainList->setCurrentItem(editSubdomainList->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } } }
/* sets the rank of each neighbor for each subdomain */ void Cluster::updateBlockNeighbors() { /* loop through every physical node */ for (unsigned int rank = 0; rank < this->getNumNodes(); ++rank) { const Node& n = this->getNode(rank); /* loop through work on each node */ for (unsigned int block = 0; block < n.numTotalSubDomains(); ++block) { SubDomain *currentBlock = n.globalGetSubDomain(block); currentBlock->setNeighbors(this->blockLocations); // printNeighbors(currentBlock); // DEBUG } // printf("node[%d] has %d total dataBlocks.\n", rank, n.numTotalSubDomains()); } }
void Project::SelectSingleSubdomainNode() { SubDomain *currentSub = 0; for (std::vector<SubDomain*>::iterator it = subDomains.begin(); it != subDomains.end(); ++it) { currentSub = *it; if (currentSub == visibleDomain) { currentSub->UseTool(ClickToolType, NodeSelection, Select); break; } } }
void Project::SetProgressBar(QProgressBar *newBar) { progressBar = newBar; if (fullDomain) fullDomain->SetProgressBar(newBar); SubDomain *currDomain = 0; for (std::vector<SubDomain*>::iterator it = subDomains.begin(); it != subDomains.end(); ++it) { currDomain = *it; if (currDomain) currDomain->SetProgressBar(newBar); } }
//----------------------------------------------------------------------------- void MeshSmoothing::snap_boundary(Mesh& mesh, const SubDomain& sub_domain, bool harmonic_smoothing) { log(PROGRESS, "Snapping boundary of mesh: %s", mesh.str(false).c_str()); if (mesh.geometry().degree() != 1) { dolfin_error("MeshSmoothing.cpp", "snap mesh boundary", "This function does not support higher-order mesh geometry"); } // Extract boundary of mesh BoundaryMesh boundary(mesh, "exterior"); const std::size_t dim = mesh.geometry().dim(); // Smooth boundary MeshGeometry& geometry = boundary.geometry(); for (std::size_t i = 0; i < boundary.num_vertices(); i++) { Point p = geometry.point(i); Array<double> x(dim, p.coordinates()); sub_domain.snap(x); geometry.set(i, p.coordinates()); } // Move interior vertices move_interior_vertices(mesh, boundary, harmonic_smoothing); }
void Balancer::populateAdjacencies(Cluster* cluster, int* adj_indices, int* adj_nodes, int* node_weights, int* adj_weights) { // validate if (cluster == NULL || adj_indices == NULL || adj_nodes == NULL) return; // go through each node and record the location of each neighbor const int kNumNodes = static_cast<int> (cluster->getNumNodes()); const int kNumNeighbors3D = 26; const int kNumNeighbors2D = 8; int current_adj_index = 0; const int kNumDimensions = cluster->getBlockLinear(0)->getDimensionality(); int num_neighbors = (kNumDimensions == 3) ? kNumNeighbors3D : kNumNeighbors2D; adj_indices[0] = current_adj_index; for (int node_index = 0; node_index < kNumNodes; ++node_index) { std::map<int, int> adj_map; Node& node = cluster->getNode(node_index); node_weights[node_index] = static_cast<int> (node.getWeight()); const int kNumBlocks = static_cast<int> (node.numTotalSubDomains()); for (int block_index = 0; block_index < kNumBlocks; ++block_index) { SubDomain* block = node.globalGetSubDomain(block_index); for (int neighbor_index = 0; neighbor_index < num_neighbors; ++neighbor_index) { const int kNoNeighbor = -1; const int kNodeRank = block->getNeighborLoc(neighbor_index); if (kNodeRank != kNoNeighbor) { // block has a neighbor adj_map[kNodeRank] = 1; } } } // transfer data from map to CSR adjacency array std::map<int, int>::iterator itr; for (itr = adj_map.begin(); itr != adj_map.end(); ++itr, ++current_adj_index) { adj_nodes[current_adj_index] = itr->first; // key is node rank int edge_weight = static_cast<int> (cluster->getNode(itr->first).getEdgeWeight()); adj_weights[current_adj_index] = edge_weight; } adj_indices[node_index + 1] = current_adj_index; } }
void Project::SetNodalValues(QString subdomainName, unsigned int nodeNumber, QString x, QString y, QString z) { SubDomain *currentSubdomain; for (std::vector<SubDomain*>::iterator it = subDomains.begin(); it != subDomains.end(); ++it) { currentSubdomain = *it; if (currentSubdomain) { if (currentSubdomain->GetDomainName() == subdomainName) { currentSubdomain->SetNodalValues(nodeNumber, x, y, z); break; } } } }
SubDomain* Project::BuildSubdomain(QString subdomainName) { SubDomain *newSubdomain = new SubDomain(subdomainName, projectFile, this); connect(newSubdomain, SIGNAL(mouseX(float)), this, SIGNAL(mouseX(float))); connect(newSubdomain, SIGNAL(mouseY(float)), this, SIGNAL(mouseY(float))); connect(newSubdomain, SIGNAL(undoAvailable(bool)), this, SIGNAL(undoAvailable(bool))); connect(newSubdomain, SIGNAL(redoAvailable(bool)), this, SIGNAL(redoAvailable(bool))); connect(newSubdomain, SIGNAL(editNode(uint,QString,QString,QString)), this, SIGNAL(editNode(uint,QString,QString,QString))); if (progressBar) newSubdomain->SetProgressBar(progressBar); subDomains.push_back(newSubdomain); emit subdomainCreated(subdomainName); return newSubdomain; }
void Project::SetOpenGLPanel(OpenGLPanel *newPanel) { if (newPanel) { glPanel = newPanel; connect(this, SIGNAL(subdomainCreated(QString)), glPanel, SLOT(addSubdomainToMenus(QString))); connect(glPanel, SIGNAL(openColorOptions()), this, SLOT(ShowDisplayOptionsDialog())); connect(glPanel, SIGNAL(matchColors(QAction*)), this, SLOT(MatchColors(QAction*))); connect(glPanel, SIGNAL(matchCamera(QAction*)), this, SLOT(MatchCamera(QAction*))); connect(glPanel, SIGNAL(clearSelections()), this, SLOT(ClearSelections())); for (std::vector<SubDomain*>::iterator it = subDomains.begin(); it != subDomains.end(); ++it) { SubDomain* currSubdomain = *it; emit subdomainCreated(currSubdomain->GetDomainName()); } } }
void Cluster::distributeBlocks(Decomposition* blocks) { const unsigned int kNumBlocks = blocks->getNumSubDomains(); const unsigned int kNumNodes = getNumNodes(); printf("num_nodes: %d.\n", kNumNodes); unsigned int total_slabs = 0; for (unsigned int node_index = 0; node_index < kNumNodes; ++node_index) { Node& node = getNode(static_cast<int> (node_index)); /* give node all blocks */ int blocks_needed = node.getBalCount(); printf("node %d needs %d blocks.\n", node_index, blocks_needed); if (0 < blocks_needed) { ++total_slabs; node.addSubDomain(blocks->getAggregate3D(blocks_needed)); } /* give blocks to node's children */ const int kNumChildren = node.getNumChildren(); for (int child_id = 0; child_id < kNumChildren; ++child_id) { Node& child = node.getChild(child_id); blocks_needed = child.getBalCount(); printf("child %d on node %d needs %d blocks.\n", child_id, node_index, blocks_needed); if (0 < blocks_needed) { ++total_slabs; child.addSubDomain(blocks->getAggregate3D(blocks_needed)); } } } // now update the grid dimensions for all blocks for (unsigned int index = 0; index < kNumNodes; ++index) { Node& node = getNode(index); for (unsigned int block_index = 0; block_index < node.numTotalSubDomains(); ++block_index) { SubDomain* block = node.globalGetSubDomain(block_index); block->setGridDim(total_slabs, 1, 1); } } }
//----------------------------------------------------------------------------- void NewDirichletBC::init(SubDomain& sub_domain) { cout << "Creating sub domain markers for boundary condition." << endl; // Create mesh function for sub domain markers on facets _mesh.init(_mesh.topology().dim() - 1); sub_domains = new MeshFunction<uint>(_mesh, _mesh.topology().dim() - 1); sub_domains_local = true; // Mark everything as sub domain 1 (*sub_domains) = 1; // Mark the sub domain as sub domain 0 sub_domain.mark(*sub_domains, 0); }
//----------------------------------------------------------------------------- SubMesh::SubMesh(const Mesh& mesh, const SubDomain& sub_domain) { // Create mesh function and mark sub domain MeshFunction<std::size_t> sub_domains(mesh, mesh.topology().dim()); sub_domains = 0; sub_domain.mark(sub_domains, 1); // Copy data into std::vector const std::vector<std::size_t> _sub_domains(sub_domains.values(), sub_domains.values() + sub_domains.size()); // Create sub mesh init(mesh, _sub_domains, 1); }
//----------------------------------------------------------------------------- void MeshSmoothing::snap_boundary(Mesh& mesh, const SubDomain& sub_domain, bool harmonic_smoothing) { cout << "Snapping boundary of mesh: " << mesh << endl; // Extract boundary of mesh BoundaryMesh boundary(mesh); const uint dim = mesh.geometry().dim(); Array<double> x; // Smooth boundary MeshGeometry& geometry = boundary.geometry(); for (uint i = 0; i < boundary.num_vertices(); i++) { x.update(dim, geometry.x(i)); sub_domain.snap(x); } // Move interior vertices move_interior_vertices(mesh, boundary, harmonic_smoothing); }
//----------------------------------------------------------------------------- void MeshSmoothing::snap_boundary(Mesh& mesh, const SubDomain& sub_domain, bool harmonic_smoothing) { cout << "Snapping boundary of mesh: " << mesh << endl; // Extract boundary of mesh BoundaryMesh boundary(mesh, "exterior"); const std::size_t dim = mesh.geometry().dim(); // Smooth boundary MeshGeometry& geometry = boundary.geometry(); for (std::size_t i = 0; i < boundary.num_vertices(); i++) { Point p = geometry.point(i); Array<double> x(dim, p.coordinates()); sub_domain.snap(x); geometry.set(i, p.coordinates()); } // Move interior vertices move_interior_vertices(mesh, boundary, harmonic_smoothing); }
/** * @brief Counts how many segments will have to be exchanged with external nodes * @return number of external neighbor blocks. */ unsigned int Node::numExternalBlockNeighbors() { unsigned int external_block_neighbors = 0; const int kNumBlocks = this->numSubDomains(); for (int block_index = 0; block_index < kNumBlocks; ++block_index) { SubDomain* block = this->globalGetSubDomain(block_index); const int kNumDimensions = block->getDimensionality(); const int k2D = 2; const int k3D = 3; const int kNoNeighbor = -1; const int kMyRank = this->getRank(); if (kNumDimensions == k2D) { if (block->getNeighborLoc(x2DCorner0) != kNoNeighbor && block->getNeighborLoc(x2DCorner0) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DCorner1) != kNoNeighbor && block->getNeighborLoc(x2DCorner1) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DCorner2) != kNoNeighbor && block->getNeighborLoc(x2DCorner2) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DCorner3) != kNoNeighbor && block->getNeighborLoc(x2DCorner3) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DPole0) != kNoNeighbor && block->getNeighborLoc(x2DPole0) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DPole1) != kNoNeighbor && block->getNeighborLoc(x2DPole1) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DPole2) != kNoNeighbor && block->getNeighborLoc(x2DPole2) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x2DPole3) != kNoNeighbor && block->getNeighborLoc(x2DPole3) != kMyRank) ++external_block_neighbors; } else if (kNumDimensions == k3D) { if (block->getNeighborLoc(x3DCorner0) != kNoNeighbor && block->getNeighborLoc(x3DCorner0) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner1) != kNoNeighbor && block->getNeighborLoc(x3DCorner1) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner2) != kNoNeighbor && block->getNeighborLoc(x3DCorner2) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner3) != kNoNeighbor && block->getNeighborLoc(x3DCorner3) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner4) != kNoNeighbor && block->getNeighborLoc(x3DCorner4) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner5) != kNoNeighbor && block->getNeighborLoc(x3DCorner5) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner6) != kNoNeighbor && block->getNeighborLoc(x3DCorner6) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DCorner7) != kNoNeighbor && block->getNeighborLoc(x3DCorner7) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DFace0) != kNoNeighbor && block->getNeighborLoc(x3DFace0) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DFace1) != kNoNeighbor && block->getNeighborLoc(x3DFace1) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DFace2) != kNoNeighbor && block->getNeighborLoc(x3DFace2) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DFace3) != kNoNeighbor && block->getNeighborLoc(x3DFace3) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DFace4) != kNoNeighbor && block->getNeighborLoc(x3DFace4) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DFace5) != kNoNeighbor && block->getNeighborLoc(x3DFace5) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole0) != kNoNeighbor && block->getNeighborLoc(x3DPole0) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole1) != kNoNeighbor && block->getNeighborLoc(x3DPole1) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole2) != kNoNeighbor && block->getNeighborLoc(x3DPole2) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole3) != kNoNeighbor && block->getNeighborLoc(x3DPole3) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole4) != kNoNeighbor && block->getNeighborLoc(x3DPole4) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole5) != kNoNeighbor && block->getNeighborLoc(x3DPole5) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole6) != kNoNeighbor && block->getNeighborLoc(x3DPole6) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole7) != kNoNeighbor && block->getNeighborLoc(x3DPole7) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole8) != kNoNeighbor && block->getNeighborLoc(x3DPole8) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole9) != kNoNeighbor && block->getNeighborLoc(x3DPole9) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole10) != kNoNeighbor && block->getNeighborLoc(x3DPole10) != kMyRank) ++external_block_neighbors; if (block->getNeighborLoc(x3DPole11) != kNoNeighbor && block->getNeighborLoc(x3DPole11) != kMyRank) ++external_block_neighbors; } } return external_block_neighbors; }
SparsityBuilderFromNodeConnectivity::SparsityBuilderFromNodeConnectivity(SubDomain &ddc_dom, const MeshLib::IMesh &msh, DofEquationIdTable &dofManager, MathLib::RowMajorSparsity &sparse) { MeshLib::TopologyNode2NodesConnectedByElements topo_node2nodes(msh); SparsityTool::createRowMajorSparsityFromNodeConnectivity(topo_node2nodes, *ddc_dom.getGlobalLocalIdMap(), msh.getID(), dofManager, sparse); }