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