tlabel_components.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tlabel_components.cc (1681B)
---
1 /* Copyright (C) 2019 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "label_components.hh"
21
22 #include "pism/util/iceModelVec.hh"
23 #include "pism/util/error_handling.hh"
24 #include "connected_components.hh"
25
26 namespace pism {
27
28 /*!
29 * Label connected components in a mask stored in an IceModelVec2Int.
30 *
31 * This function allocates a copy on rank 0 and so should not be used if that is a
32 * problem.
33 */
34 void label_components(IceModelVec2Int &mask, bool identify_icebergs, double mask_grounded) {
35 auto mask_p0 = mask.allocate_proc0_copy();
36
37 mask.put_on_proc0(*mask_p0);
38
39 auto grid = mask.grid();
40
41 ParallelSection rank0(grid->com);
42 try {
43 if (grid->rank() == 0) {
44 petsc::VecArray array(*mask_p0);
45 label_connected_components(array.get(), grid->My(), grid->Mx(),
46 identify_icebergs, mask_grounded);
47 }
48 } catch (...) {
49 rank0.failed();
50 }
51 rank0.check();
52
53 mask.get_from_proc0(*mask_p0);
54 }
55
56 } // end of namespace pism