PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Given.cc
Go to the documentation of this file.
1// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 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#include "pism/coupler/frontalmelt/Given.hh"
20
21#include "pism/util/Grid.hh"
22
23#include "pism/coupler/util/options.hh"
24#include "pism/geometry/Geometry.hh"
25#include "pism/util/array/Forcing.hh"
26#include "pism/util/Logger.hh"
27#include "pism/util/io/IO_Flags.hh"
28
29namespace pism {
30namespace frontalmelt {
31
32Given::Given(std::shared_ptr<const Grid> grid)
33 : FrontalMelt(grid, std::shared_ptr<FrontalMelt>()) {
34
35 m_frontal_melt_rate = array::Forcing::Constant(grid, "frontal_melt_rate", 0.0);
36}
37
38void Given::init_impl(const Geometry &geometry) {
39 (void) geometry;
40
41 m_log->message(2,
42 "* Initializing the frontal melt model reading melt rates\n"
43 " from a file...\n");
44
45 ForcingOptions opt(*m_grid->ctx(), "frontal_melt.given");
46
47 {
48 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
49
51
52 m_frontal_melt_rate = std::make_shared<array::Forcing>(m_grid, file, "frontal_melt_rate",
53 "", // no standard name
54 buffer_size, opt.periodic);
55 }
56
57 m_frontal_melt_rate->metadata(0)
58 .long_name("frontal melt rate")
59 .units("m s^-1")
60 .output_units("m year^-1");
61
63}
64
65void Given::update_impl(const FrontalMeltInputs &inputs, double t, double dt) {
66
67 const auto &cell_type = inputs.geometry->cell_type;
68
69 // fill m_frontal_melt_rate with values read from an file
70 m_frontal_melt_rate->update(t, dt);
71 m_frontal_melt_rate->average(t, dt);
72
73 // post-processing: keep values at grounded (or grounded and floating) margins and in
74 // the interior, filling the rest with zeros
75
76 array::AccessScope list{ &cell_type, m_frontal_melt_rate.get() };
77
78 for (auto p : m_grid->points()) {
79 const int i = p.i(), j = p.j();
80
81 auto R = (*m_frontal_melt_rate)(i, j);
82
83 if (apply(cell_type, i, j)) {
84 (*m_frontal_melt_rate)(i, j) = R;
85 } else {
86 (*m_frontal_melt_rate)(i, j) = 0.0;
87 }
88 }
89}
90
92
93 auto dt = m_frontal_melt_rate->max_timestep(t);
94
95 if (dt.finite()) {
96 return {dt.value(), "frontal_melt given"};
97 }
98 return {"frontal_melt given"};
99}
100
101
105
106} // end of namespace frontalmelt
107} // end of namespace pism
std::shared_ptr< const Grid > grid() const
Definition Component.cc:107
std::shared_ptr< const Config > m_config
configuration database used by this component
Definition Component.hh:160
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition Component.hh:158
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
High-level PISM I/O class.
Definition File.hh:57
const Geometry * geometry
array::CellType2 cell_type
Definition Geometry.hh:55
double value() const
Get the value of the maximum time step.
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:66
static std::shared_ptr< Forcing > Constant(std::shared_ptr< const Grid > grid, const std::string &short_name, double value)
Definition Forcing.cc:148
bool apply(const array::CellType1 &M, int i, int j) const
A very rudimentary PISM frontal melt model.
std::shared_ptr< array::Forcing > m_frontal_melt_rate
Definition Given.hh:42
void init_impl(const Geometry &geometry)
Definition Given.cc:38
MaxTimestep max_timestep_impl(double t) const
Definition Given.cc:91
const array::Scalar & frontal_melt_rate_impl() const
Definition Given.cc:102
Given(std::shared_ptr< const Grid > g)
Definition Given.cc:32
void update_impl(const FrontalMeltInputs &inputs, double t, double dt)
Definition Given.cc:65
@ PISM_NETCDF3
Definition IO_Flags.hh:58
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
std::string filename
Definition options.hh:33