PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
label_components.cc
Go to the documentation of this file.
1 /* Copyright (C) 2019, 2020, 2021, 2022, 2023 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 "pism/util/label_components.hh"
21 
22 #include "pism/util/array/Scalar.hh"
23 #include "pism/util/error_handling.hh"
24 #include "pism/util/connected_components.hh"
25 #include "pism/util/petscwrappers/Vec.hh"
26 
27 namespace pism {
28 
30  petsc::Vec &mask_p0,
31  bool identify_icebergs, double mask_grounded) {
32 
33  mask.put_on_proc0(mask_p0);
34 
35  auto grid = mask.grid();
36 
37  ParallelSection rank0(grid->com);
38  try {
39  if (grid->rank() == 0) {
40  petsc::VecArray array(mask_p0);
42  static_cast<int>(grid->My()),
43  static_cast<int>(grid->Mx()),
44  identify_icebergs,
45  static_cast<int>(mask_grounded));
46  }
47  } catch (...) {
48  rank0.failed();
49  }
50  rank0.check();
51 
52  mask.get_from_proc0(mask_p0);
53 }
54 
55 void label_components(array::Scalar &mask, bool identify_icebergs, double mask_grounded) {
56  auto mask_p0 = mask.allocate_proc0_copy();
57  label_components(mask, *mask_p0, identify_icebergs, mask_grounded);
58 }
59 
60 } // end of namespace pism
void failed()
Indicates a failure of a parallel section.
void get_from_proc0(petsc::Vec &onp0)
Gets a local Array2 from processor 0.
Definition: Array.cc:1095
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
std::shared_ptr< petsc::Vec > allocate_proc0_copy() const
Definition: Array.cc:963
void put_on_proc0(petsc::Vec &onp0) const
Puts a local array::Scalar on processor 0.
Definition: Array.cc:1052
double * get()
Definition: Vec.cc:54
Wrapper around VecGetArray and VecRestoreArray.
Definition: Vec.hh:44
void label_connected_components(double *image, int nrows, int ncols, bool identify_icebergs, int mask_grounded, int first_label)
void label_components(array::Scalar &mask, petsc::Vec &mask_p0, bool identify_icebergs, double mask_grounded)