{"action":"created","comment":{"url":"https://api.github.com/repos/dealii/dealii/pulls/comments/50125495","id":50125495,"diff_hunk":"@@ -2870,6 +2870,180 @@ namespace GridTools\n \n \n \n+  template <class Container>\n+  std::vector<typename Container::cell_iterator>\n+  get_cells_at_coarsest_common_level (\n+    const std::vector<typename Container::active_cell_iterator> &patch)\n+  {\n+    Assert (patch.size() > 0, ExcMessage(\"Vector containing patch cells should not be an empty vector!\"));\n+    // In order to extract the set of cells with the coarsest common level from the give vector of cells:\n+    // First it finds the number associated with the minimum level of refinmenet, namely \"min_level\"\n+    int min_level = patch[0]->level();\n+\n+    for (unsigned int i=0; i<patch.size(); ++i)\n+      min_level = std::min (min_level, patch[i]->level() );\n+    std::set<typename Container::cell_iterator>  uniform_cells;\n+    typename std::vector<typename Container::active_cell_iterator>::const_iterator  patch_cell;\n+    // it loops through all cells of the input vector\n+    for (patch_cell=patch.begin(); patch_cell!=patch.end () ; ++patch_cell)\n+      {\n+        // If the refinement level of each cell i the loop be equal to the min_level, so that\n+        // that cell inserted into the set of uniform_cells, as the set of cells with the coarsest common refinement level\n+        if ((*patch_cell)->level() == min_level)\n+          uniform_cells.insert (*patch_cell);\n+        else\n+          // If not, it asks for the parent of the cell, until it finds the parent cell\n+          // with the refinement level equal to the min_level and inserts that parent cell into the\n+          // the set of uniform_cells, as the set of cells with the coarsest common refinement level.\n+          {\n+            typename Container::cell_iterator parent = *patch_cell;\n+\n+            while (parent->level() > min_level)\n+              parent = parent-> parent();\n+            uniform_cells.insert (parent);\n+          }\n+      }\n+\n+    return std::vector<typename Container::cell_iterator> (uniform_cells.begin(),\n+                                                           uniform_cells.end());\n+  }\n+\n+\n+\n+  template <class Container>\n+  void build_triangulation_from_patch(const std::vector<typename Container::active_cell_iterator> &patch,\n+                                      Triangulation<Container::dimension,Container::space_dimension> &local_triangulation,\n+                                      std::map<typename Triangulation<Container::dimension,Container::space_dimension>::active_cell_iterator,\n+                                      typename Container::active_cell_iterator> &patch_to_global_tria_map)\n+\n+  {\n+    const std::vector<typename Container::cell_iterator> uniform_cells =\n+      get_cells_at_coarsest_common_level <Container> (patch);\n+    // First it creates triangulation from the vector of \"uniform_cells\"\n+    local_triangulation.clear();\n+    std::vector<Point<Container::space_dimension> > vertices;\n+    const unsigned int n_uniform_cells=uniform_cells.size();\n+    std::vector<CellData<Container::dimension> > cells(n_uniform_cells);\n+    unsigned int k=0;// for enumerating cells\n+    unsigned int i=0;// for enumerating vertices\n+    typename std::vector<typename Container::cell_iterator>::const_iterator uniform_cell;\n+    for (uniform_cell=uniform_cells.begin(); uniform_cell!=uniform_cells.end(); ++uniform_cell)\n+      {\n+        bool repeat_vertex;\n+        for (unsigned int j=0;  j< GeometryInfo<Container::dimension>::vertices_per_cell; ++j)\n+          {\n+            Point<Container::space_dimension> position=(*uniform_cell)->vertex (j);\n+            repeat_vertex=false;\n+\n+            for (unsigned int m=0; m<i; ++m)\n+              {\n+                if (position == vertices[m])\n+                  {\n+                    repeat_vertex=true;\n+                    cells[k].vertices[j]=m;\n+                    break;\n+                  }\n+              }\n+            if (repeat_vertex==false)\n+              {\n+                vertices.push_back(position);\n+                cells[k].vertices[j]=i;\n+                i=i+1;\n+              }\n+\n+          }//for vertices_per_cell\n+        k=k+1;\n+      }\n+    local_triangulation.create_triangulation(vertices,cells,SubCellData());\n+    Assert (local_triangulation.n_active_cells() == uniform_cells.size(), ExcInternalError());\n+    local_triangulation.clear_user_flags ();\n+    unsigned int index=0;\n+    // Create a map between cells of class DofHandler into class Triangulation\n+    std::map<typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator,\n+        typename Container::cell_iterator> patch_to_global_tria_map_tmp;\n+    for (typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator coarse_cell = local_triangulation.begin();\n+         coarse_cell != local_triangulation.end(); ++coarse_cell, ++index)\n+      {\n+        patch_to_global_tria_map_tmp.insert (std::make_pair(coarse_cell, uniform_cells[index]));\n+        // To ensure that the cells with the same coordinates (here, we compare their centers) are mapped into each other.\n+\n+        Assert(coarse_cell->center().distance( uniform_cells[index]->center())<=1e-15*coarse_cell->diameter(),\n+               ExcInternalError());\n+      }\n+    bool refinement_necessary;\n+    // In this loop we start to do refinement on the above coarse triangulation to reach\n+    // to the same level of refinement as the patch cells are really on\n+    do\n+      {\n+        refinement_necessary = false;\n+        for (typename Triangulation<Container::dimension,Container::space_dimension>::active_cell_iterator\n+             active_tria_cell = local_triangulation.begin_active();\n+             active_tria_cell != local_triangulation.end(); ++active_tria_cell)\n+          {\n+            if (patch_to_global_tria_map_tmp[active_tria_cell]->has_children())\n+              {\n+                active_tria_cell -> set_refine_flag();\n+                refinement_necessary = true;\n+              }\n+            else for (unsigned int i=0; i<patch.size(); ++i)\n+                {\n+                  if (patch_to_global_tria_map_tmp[active_tria_cell]==patch[i])\n+                    {\n+                      active_tria_cell->set_user_flag();\n+                      break;\n+                    }\n+                }\n+          }\n+\n+        if (refinement_necessary)\n+          {\n+            local_triangulation.execute_coarsening_and_refinement ();\n+\n+            for (typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator\n+                 cell = local_triangulation.begin();\n+                 cell != local_triangulation.end(); ++cell)\n+              {\n+\n+                if (patch_to_global_tria_map_tmp.find(cell)!=patch_to_global_tria_map_tmp.end())\n+                  {\n+                    if (cell-> has_children())\n+                      {\n+                        // Note: Since the cell got children, then it should not be in the map anymore\n+                        // children may be added into the map, instead\n+\n+                        // these children may not yet be in the map\n+                        for (unsigned int c=0; c< cell ->n_children(); ++c)\n+                          {\n+                            if (patch_to_global_tria_map_tmp.find(cell->child(c)) ==\n+                                patch_to_global_tria_map_tmp.end())\n+                              {\n+                                patch_to_global_tria_map_tmp.insert (std::make_pair(cell ->child(c),\n+                                                                                    patch_to_global_tria_map_tmp[cell]->child(c)));\n+\n+                                Assert(cell->child(c)->center().distance( patch_to_global_tria_map_tmp[cell]->child(c)->center())","path":"source/grid/grid_tools.cc","position":154,"original_position":154,"commit_id":"4050000c16416cd878046a64d3488795523235a6","original_commit_id":"4050000c16416cd878046a64d3488795523235a6","user":{"login":"srobertp","id":12628222,"avatar_url":"https://avatars.githubusercontent.com/u/12628222?v=3","gravatar_id":"","url":"https://api.github.com/users/srobertp","html_url":"https://github.com/srobertp","followers_url":"https://api.github.com/users/srobertp/followers","following_url":"https://api.github.com/users/srobertp/following{/other_user}","gists_url":"https://api.github.com/users/srobertp/gists{/gist_id}","starred_url":"https://api.github.com/users/srobertp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srobertp/subscriptions","organizations_url":"https://api.github.com/users/srobertp/orgs","repos_url":"https://api.github.com/users/srobertp/repos","events_url":"https://api.github.com/users/srobertp/events{/privacy}","received_events_url":"https://api.github.com/users/srobertp/received_events","type":"User","site_admin":false},"body":"I will do that.","created_at":"2016-01-19T15:26:54Z","updated_at":"2016-01-19T15:26:54Z","html_url":"https://github.com/dealii/dealii/pull/1934#discussion_r50125495","pull_request_url":"https://api.github.com/repos/dealii/dealii/pulls/1934","_links":{"self":{"href":"https://api.github.com/repos/dealii/dealii/pulls/comments/50125495"},"html":{"href":"https://github.com/dealii/dealii/pull/1934#discussion_r50125495"},"pull_request":{"href":"https://api.github.com/repos/dealii/dealii/pulls/1934"}}},"pull_request":{"url":"https://api.github.com/repos/dealii/dealii/pulls/1934","id":52421979,"html_url":"https://github.com/dealii/dealii/pull/1934","diff_url":"https://github.com/dealii/dealii/pull/1934.diff","patch_url":"https://github.com/dealii/dealii/pull/1934.patch","issue_url":"https://api.github.com/repos/dealii/dealii/issues/1934","number":1934,"state":"open","locked":false,"title":"Add GridTools::build_triangulation_from_patch() and GridTools::get_cells_at_coarsest_common_level().","user":{"login":"Arezou-gh","id":8826658,"avatar_url":"https://avatars.githubusercontent.com/u/8826658?v=3","gravatar_id":"","url":"https://api.github.com/users/Arezou-gh","html_url":"https://github.com/Arezou-gh","followers_url":"https://api.github.com/users/Arezou-gh/followers","following_url":"https://api.github.com/users/Arezou-gh/following{/other_user}","gists_url":"https://api.github.com/users/Arezou-gh/gists{/gist_id}","starred_url":"https://api.github.com/users/Arezou-gh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arezou-gh/subscriptions","organizations_url":"https://api.github.com/users/Arezou-gh/orgs","repos_url":"https://api.github.com/users/Arezou-gh/repos","events_url":"https://api.github.com/users/Arezou-gh/events{/privacy}","received_events_url":"https://api.github.com/users/Arezou-gh/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-02T16:49:57Z","updated_at":"2016-01-19T15:26:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7f511529b603b6718c7ad94374da7285ad70b5fd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dealii/dealii/pulls/1934/commits","review_comments_url":"https://api.github.com/repos/dealii/dealii/pulls/1934/comments","review_comment_url":"https://api.github.com/repos/dealii/dealii/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dealii/dealii/issues/1934/comments","statuses_url":"https://api.github.com/repos/dealii/dealii/statuses/4050000c16416cd878046a64d3488795523235a6","head":{"label":"Arezou-gh:local-triangulations","ref":"local-triangulations","sha":"4050000c16416cd878046a64d3488795523235a6","user":{"login":"Arezou-gh","id":8826658,"avatar_url":"https://avatars.githubusercontent.com/u/8826658?v=3","gravatar_id":"","url":"https://api.github.com/users/Arezou-gh","html_url":"https://github.com/Arezou-gh","followers_url":"https://api.github.com/users/Arezou-gh/followers","following_url":"https://api.github.com/users/Arezou-gh/following{/other_user}","gists_url":"https://api.github.com/users/Arezou-gh/gists{/gist_id}","starred_url":"https://api.github.com/users/Arezou-gh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arezou-gh/subscriptions","organizations_url":"https://api.github.com/users/Arezou-gh/orgs","repos_url":"https://api.github.com/users/Arezou-gh/repos","events_url":"https://api.github.com/users/Arezou-gh/events{/privacy}","received_events_url":"https://api.github.com/users/Arezou-gh/received_events","type":"User","site_admin":false},"repo":{"id":40194967,"name":"dealii","full_name":"Arezou-gh/dealii","owner":{"login":"Arezou-gh","id":8826658,"avatar_url":"https://avatars.githubusercontent.com/u/8826658?v=3","gravatar_id":"","url":"https://api.github.com/users/Arezou-gh","html_url":"https://github.com/Arezou-gh","followers_url":"https://api.github.com/users/Arezou-gh/followers","following_url":"https://api.github.com/users/Arezou-gh/following{/other_user}","gists_url":"https://api.github.com/users/Arezou-gh/gists{/gist_id}","starred_url":"https://api.github.com/users/Arezou-gh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arezou-gh/subscriptions","organizations_url":"https://api.github.com/users/Arezou-gh/orgs","repos_url":"https://api.github.com/users/Arezou-gh/repos","events_url":"https://api.github.com/users/Arezou-gh/events{/privacy}","received_events_url":"https://api.github.com/users/Arezou-gh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Arezou-gh/dealii","description":"The development repository for the deal.II finite element library.","fork":true,"url":"https://api.github.com/repos/Arezou-gh/dealii","forks_url":"https://api.github.com/repos/Arezou-gh/dealii/forks","keys_url":"https://api.github.com/repos/Arezou-gh/dealii/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Arezou-gh/dealii/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Arezou-gh/dealii/teams","hooks_url":"https://api.github.com/repos/Arezou-gh/dealii/hooks","issue_events_url":"https://api.github.com/repos/Arezou-gh/dealii/issues/events{/number}","events_url":"https://api.github.com/repos/Arezou-gh/dealii/events","assignees_url":"https://api.github.com/repos/Arezou-gh/dealii/assignees{/user}","branches_url":"https://api.github.com/repos/Arezou-gh/dealii/branches{/branch}","tags_url":"https://api.github.com/repos/Arezou-gh/dealii/tags","blobs_url":"https://api.github.com/repos/Arezou-gh/dealii/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Arezou-gh/dealii/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Arezou-gh/dealii/git/refs{/sha}","trees_url":"https://api.github.com/repos/Arezou-gh/dealii/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Arezou-gh/dealii/statuses/{sha}","languages_url":"https://api.github.com/repos/Arezou-gh/dealii/languages","stargazers_url":"https://api.github.com/repos/Arezou-gh/dealii/stargazers","contributors_url":"https://api.github.com/repos/Arezou-gh/dealii/contributors","subscribers_url":"https://api.github.com/repos/Arezou-gh/dealii/subscribers","subscription_url":"https://api.github.com/repos/Arezou-gh/dealii/subscription","commits_url":"https://api.github.com/repos/Arezou-gh/dealii/commits{/sha}","git_commits_url":"https://api.github.com/repos/Arezou-gh/dealii/git/commits{/sha}","comments_url":"https://api.github.com/repos/Arezou-gh/dealii/comments{/number}","issue_comment_url":"https://api.github.com/repos/Arezou-gh/dealii/issues/comments{/number}","contents_url":"https://api.github.com/repos/Arezou-gh/dealii/contents/{+path}","compare_url":"https://api.github.com/repos/Arezou-gh/dealii/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Arezou-gh/dealii/merges","archive_url":"https://api.github.com/repos/Arezou-gh/dealii/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Arezou-gh/dealii/downloads","issues_url":"https://api.github.com/repos/Arezou-gh/dealii/issues{/number}","pulls_url":"https://api.github.com/repos/Arezou-gh/dealii/pulls{/number}","milestones_url":"https://api.github.com/repos/Arezou-gh/dealii/milestones{/number}","notifications_url":"https://api.github.com/repos/Arezou-gh/dealii/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Arezou-gh/dealii/labels{/name}","releases_url":"https://api.github.com/repos/Arezou-gh/dealii/releases{/id}","created_at":"2015-08-04T16:09:52Z","updated_at":"2015-08-04T16:10:59Z","pushed_at":"2016-01-13T23:51:47Z","git_url":"git://github.com/Arezou-gh/dealii.git","ssh_url":"git@github.com:Arezou-gh/dealii.git","clone_url":"https://github.com/Arezou-gh/dealii.git","svn_url":"https://github.com/Arezou-gh/dealii","homepage":"http://www.dealii.org/","size":130105,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dealii:master","ref":"master","sha":"2aed52502bc8470e5a3638fc8816ddca77fbf6fd","user":{"login":"dealii","id":7506070,"avatar_url":"https://avatars.githubusercontent.com/u/7506070?v=3","gravatar_id":"","url":"https://api.github.com/users/dealii","html_url":"https://github.com/dealii","followers_url":"https://api.github.com/users/dealii/followers","following_url":"https://api.github.com/users/dealii/following{/other_user}","gists_url":"https://api.github.com/users/dealii/gists{/gist_id}","starred_url":"https://api.github.com/users/dealii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dealii/subscriptions","organizations_url":"https://api.github.com/users/dealii/orgs","repos_url":"https://api.github.com/users/dealii/repos","events_url":"https://api.github.com/users/dealii/events{/privacy}","received_events_url":"https://api.github.com/users/dealii/received_events","type":"Organization","site_admin":false},"repo":{"id":21943980,"name":"dealii","full_name":"dealii/dealii","owner":{"login":"dealii","id":7506070,"avatar_url":"https://avatars.githubusercontent.com/u/7506070?v=3","gravatar_id":"","url":"https://api.github.com/users/dealii","html_url":"https://github.com/dealii","followers_url":"https://api.github.com/users/dealii/followers","following_url":"https://api.github.com/users/dealii/following{/other_user}","gists_url":"https://api.github.com/users/dealii/gists{/gist_id}","starred_url":"https://api.github.com/users/dealii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dealii/subscriptions","organizations_url":"https://api.github.com/users/dealii/orgs","repos_url":"https://api.github.com/users/dealii/repos","events_url":"https://api.github.com/users/dealii/events{/privacy}","received_events_url":"https://api.github.com/users/dealii/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dealii/dealii","description":"The development repository for the deal.II finite element library.","fork":false,"url":"https://api.github.com/repos/dealii/dealii","forks_url":"https://api.github.com/repos/dealii/dealii/forks","keys_url":"https://api.github.com/repos/dealii/dealii/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dealii/dealii/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dealii/dealii/teams","hooks_url":"https://api.github.com/repos/dealii/dealii/hooks","issue_events_url":"https://api.github.com/repos/dealii/dealii/issues/events{/number}","events_url":"https://api.github.com/repos/dealii/dealii/events","assignees_url":"https://api.github.com/repos/dealii/dealii/assignees{/user}","branches_url":"https://api.github.com/repos/dealii/dealii/branches{/branch}","tags_url":"https://api.github.com/repos/dealii/dealii/tags","blobs_url":"https://api.github.com/repos/dealii/dealii/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dealii/dealii/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dealii/dealii/git/refs{/sha}","trees_url":"https://api.github.com/repos/dealii/dealii/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dealii/dealii/statuses/{sha}","languages_url":"https://api.github.com/repos/dealii/dealii/languages","stargazers_url":"https://api.github.com/repos/dealii/dealii/stargazers","contributors_url":"https://api.github.com/repos/dealii/dealii/contributors","subscribers_url":"https://api.github.com/repos/dealii/dealii/subscribers","subscription_url":"https://api.github.com/repos/dealii/dealii/subscription","commits_url":"https://api.github.com/repos/dealii/dealii/commits{/sha}","git_commits_url":"https://api.github.com/repos/dealii/dealii/git/commits{/sha}","comments_url":"https://api.github.com/repos/dealii/dealii/comments{/number}","issue_comment_url":"https://api.github.com/repos/dealii/dealii/issues/comments{/number}","contents_url":"https://api.github.com/repos/dealii/dealii/contents/{+path}","compare_url":"https://api.github.com/repos/dealii/dealii/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dealii/dealii/merges","archive_url":"https://api.github.com/repos/dealii/dealii/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dealii/dealii/downloads","issues_url":"https://api.github.com/repos/dealii/dealii/issues{/number}","pulls_url":"https://api.github.com/repos/dealii/dealii/pulls{/number}","milestones_url":"https://api.github.com/repos/dealii/dealii/milestones{/number}","notifications_url":"https://api.github.com/repos/dealii/dealii/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dealii/dealii/labels{/name}","releases_url":"https://api.github.com/repos/dealii/dealii/releases{/id}","created_at":"2014-07-17T14:00:26Z","updated_at":"2016-01-13T23:56:48Z","pushed_at":"2016-01-19T13:44:36Z","git_url":"git://github.com/dealii/dealii.git","ssh_url":"git@github.com:dealii/dealii.git","clone_url":"https://github.com/dealii/dealii.git","svn_url":"https://github.com/dealii/dealii","homepage":"http://www.dealii.org/","size":137932,"stargazers_count":120,"watchers_count":120,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":136,"mirror_url":null,"open_issues_count":135,"forks":136,"open_issues":135,"watchers":120,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dealii/dealii/pulls/1934"},"html":{"href":"https://github.com/dealii/dealii/pull/1934"},"issue":{"href":"https://api.github.com/repos/dealii/dealii/issues/1934"},"comments":{"href":"https://api.github.com/repos/dealii/dealii/issues/1934/comments"},"review_comments":{"href":"https://api.github.com/repos/dealii/dealii/pulls/1934/comments"},"review_comment":{"href":"https://api.github.com/repos/dealii/dealii/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dealii/dealii/pulls/1934/commits"},"statuses":{"href":"https://api.github.com/repos/dealii/dealii/statuses/4050000c16416cd878046a64d3488795523235a6"}}}}