Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.1-cd005eec8 committed by Constantine Khrulev on 2025-03-07
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IcebergRemoverFEM.cc
Go to the documentation of this file.
1/* Copyright (C) 2021, 2022, 2023, 2024, 2025 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 <cassert>
21
22#include "pism/util/petscwrappers/DM.hh"
23#include "pism/util/connected_components/label_components.hh"
24
25#include "pism/frontretreat/util/IcebergRemoverFEM.hh"
26
27#include "pism/util/fem/Element.hh"
28#include "pism/util/array/CellType.hh"
29#include "pism/util/Mask.hh"
30#include "pism/util/Interpolation1D.hh"
31#include "pism/util/fem/Quadrature.hh"
32
33namespace pism {
34namespace calving {
35
36IcebergRemoverFEM::IcebergRemoverFEM(std::shared_ptr<const Grid> grid)
37 : IcebergRemover(grid),
38 m_mask(grid, "temporary_mask") {
40}
41
42/*! Remove "icebergs" using the finite element notion of connectivity: two elements are
43 * connected if they share a boundary.
44 *
45 * 1. Loop over elements and create a mask that will be used to determine connectivity
46 * between elements.
47 *
48 * - an element is a "grounded ice element" if all nodes are icy and are either grounded
49 * or belong to the set of Dirichlet nodes
50 *
51 * - an element is "floating ice" if all nodes are icy and at least one node is
52 * "floating ice"
53 *
54 * - all other elements are ice-free
55 *
56 * 2. Label connected components, identifying "icebergs".
57 *
58 * Once "iceberg" elements are labeled we need to remove *nodes* that belong to icebergs
59 * but *do not* belong to any elements connected to grounded ice.
60 *
61 * 3. Create a mask filled with zeros. Loop over elements and add 1 to nodes of all
62 * "iceberg" elements. Add -1 to all nodes of "grounded" elements.
63 *
64 * 4. Now loop over all nodes and remove nodes with positive mask values.
65 *
66 */
68 array::CellType1 &cell_type,
69 array::Scalar &ice_thickness) {
70 const int
71 mask_grounded_ice = 1,
72 mask_floating_ice = 2;
73
74 int bc_mask_nodal[fem::q1::n_chi];
75 int cell_type_nodal[fem::q1::n_chi];
76
77 assert(bc_mask.stencil_width() >= 1);
78 assert(cell_type.stencil_width() >= 1);
79
80 array::AccessScope list{&bc_mask, &cell_type, &m_iceberg_mask};
81
83
84 // prepare the iceberg mask: the value at (i, j) describes an *element* with (i,j) as a
85 // lower left corner
86 {
87 // loop over all nodes in a local sub-domain
88 for (auto p = m_grid->points(); p; p.next()) {
89 const int i = p.i(), j = p.j();
90
91 element.reset(i, j);
92 // the following two calls use ghost values
93 element.nodal_values(bc_mask, bc_mask_nodal);
94 element.nodal_values(cell_type, cell_type_nodal);
95
96 // check if all nodes are icy
97 bool icy = true;
98 for (int n = 0; icy and n < fem::q1::n_chi; ++n) {
99 icy &= mask::icy(cell_type_nodal[n]);
100 }
101
102 if (icy) {
103 // This is an icy element: check if all nodes are grounded or are a part of the
104 // set of Dirichlet nodes
105 bool grounded = true;
106 for (int n = 0; grounded and n < fem::q1::n_chi; ++n) {
107 grounded &= (mask::grounded(cell_type_nodal[n]) or bc_mask_nodal[n] == 1);
108 }
109
110 m_iceberg_mask(i, j) = grounded ? mask_grounded_ice : mask_floating_ice;
111 } else {
112 // This is an ice-free element.
113 m_iceberg_mask(i, j) = 0;
114 }
115 } // end of the loop over local nodes
116 } // end of the block preparing the mask
117
118 // Identify icebergs:
119 {
122 }
123
124 // create a mask indicating if a *node* should be removed
125 {
126 DMDALocalInfo info;
127 {
128 auto da = m_grid->get_dm(1, 0); // dof = 1, stencil_width = 0
129 PetscErrorCode ierr = DMDAGetLocalInfo(*da, &info);
130 if (ierr != 0) {
131 throw std::runtime_error("Failed to get DMDA info");
132 }
133 }
134
135 m_mask.set(0);
136 list.add(m_mask);
137 double **M = m_mask.array();
138
139 double mask_iceberg[] = {1.0, 1.0, 1.0, 1.0};
140 double mask_grounded[] = {-1.0, -1.0, -1.0, -1.0};
141
142 // loop over all the elements that have at least one owned node
143 for (int j = info.gys; j < info.gys + info.gym - 1; j++) {
144 for (int i = info.gxs; i < info.gxs + info.gxm - 1; i++) {
145 element.reset(i, j);
146
147 // the following two calls use ghost values
148 element.nodal_values(bc_mask, bc_mask_nodal);
149 element.nodal_values(cell_type, cell_type_nodal);
150
151 // check if all nodes are icy
152 bool icy = true;
153 for (int n = 0; icy and n < fem::q1::n_chi; ++n) {
154 icy &= mask::icy(cell_type_nodal[n]);
155 }
156
157 if (icy) {
158 // check if all nodes are grounded or are a part of the set of Dirichlet nodes
159 bool grounded = true;
160 for (int n = 0; grounded and n < fem::q1::n_chi; ++n) {
161 grounded &= (mask::grounded(cell_type_nodal[n]) or bc_mask_nodal[n] == 1);
162 }
163
164 if (m_iceberg_mask.as_int(i, j) == 1) {
165 // this is an iceberg element
166 element.add_contribution(mask_iceberg, M);
167 } else {
168 element.add_contribution(mask_grounded, M);
169 }
170 }
171 }
172 } // end of the loop over elements
173 } // end of the block identifying nodes to remove
174
175 // loop over all *nodes* and modify ice thickness and mask
176 {
177 list.add(ice_thickness);
178
179 for (auto p = m_grid->points(); p; p.next()) {
180 const int i = p.i(), j = p.j();
181
182 if (m_mask(i, j) > 0) {
183 ice_thickness(i,j) = 0.0;
184 cell_type(i,j) = MASK_ICE_FREE_OCEAN;
185 }
186 }
187 }
188
189 // update ghosts of the mask and the ice thickness (then surface
190 // elevation can be updated redundantly)
191 cell_type.update_ghosts();
192 ice_thickness.update_ghosts();
193}
194
195} // end of namespace calving
196} // end of namespace pism
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition Component.hh:156
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:64
void set_interpolation_type(InterpolationType type)
Definition Array.cc:178
void set(double c)
Result: v[j] <- c for all j.
Definition Array.cc:629
void update_ghosts()
Updates ghost points.
Definition Array.cc:615
unsigned int stencil_width() const
Get the stencil width of the current Array. Returns 0 if ghosts are not available.
Definition Array.cc:302
int as_int(int i, int j) const
Definition Scalar.hh:45
IcebergRemoverFEM(std::shared_ptr< const Grid > g)
void update_impl(const array::Scalar &bc_mask, array::CellType1 &cell_type, array::Scalar &ice_thickness)
void reset(int i, int j)
Initialize the Element to element (i, j) for the purposes of inserting into global residual and Jacob...
Definition Element.cc:196
void add_contribution(const T *local, T **y_global) const
Add the values of element-local contributions y to the global vector y_global.
Definition Element.hh:238
void nodal_values(const array::Scalar &x_global, int *result) const
Get nodal values of an integer mask.
Definition Element.cc:185
Q1 element with sides parallel to X and Y axes.
Definition Element.hh:264
The 1-point Gaussian quadrature on the square [-1,1]*[-1,1].
Definition Quadrature.hh:90
#define n
Definition exactTestM.c:37
void label_isolated(array::Scalar1 &mask, int reachable)
const int n_chi
Definition FEM.hh:191
bool icy(int M)
Ice-filled cell (grounded or floating).
Definition Mask.hh:48
bool grounded(int M)
Grounded cell (grounded ice or ice-free).
Definition Mask.hh:44
@ MASK_ICE_FREE_OCEAN
Definition Mask.hh:35