PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
GivenClimate.cc
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 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/surface/GivenClimate.hh"
20 
21 #include "pism/util/Time.hh"
22 #include "pism/util/Grid.hh"
23 #include "pism/coupler/util/options.hh"
24 #include "pism/util/array/Forcing.hh"
25 
26 namespace pism {
27 namespace surface {
28 
29 Given::Given(std::shared_ptr<const Grid> grid, std::shared_ptr<atmosphere::AtmosphereModel> input)
30  : SurfaceModel(grid)
31 {
32  (void) input;
33 
34  ForcingOptions opt(*m_grid->ctx(), "surface.given");
35 
36  {
37  unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
38 
40 
41  m_temperature = std::make_shared<array::Forcing>(m_grid,
42  file,
43  "ice_surface_temp",
44  "", // no standard name
45  buffer_size,
46  opt.periodic,
47  LINEAR);
48 
49  m_mass_flux = std::make_shared<array::Forcing>(m_grid,
50  file,
51  "climatic_mass_balance",
52  "land_ice_surface_specific_mass_balance_flux",
53  buffer_size,
54  opt.periodic);
55  }
56 
57  m_temperature->metadata(0)
58  .long_name("temperature of the ice at the ice surface but below firn processes")
59  .units("Kelvin");
60  m_temperature->metadata()["valid_range"] = { 0.0, 323.15 }; // [0C, 50C]
61 
62  const double smb_max = m_config->get_number("surface.given.smb_max", "kg m-2 second-1");
63 
64  m_mass_flux->metadata(0)
65  .long_name("surface mass balance (accumulation/ablation) rate")
66  .units("kg m-2 s-1")
67  .output_units("kg m-2 year-1")
68  .standard_name("land_ice_surface_specific_mass_balance_flux");
69 
70  m_mass_flux->metadata()["valid_range"] = {-smb_max, smb_max};
71 }
72 
73 void Given::init_impl(const Geometry &geometry) {
74 
75  m_log->message(2,
76  "* Initializing the surface model reading temperature at the top of the ice\n"
77  " and ice surface mass flux from a file...\n");
78 
79  ForcingOptions opt(*m_grid->ctx(), "surface.given");
80 
81  m_temperature->init(opt.filename, opt.periodic);
82  m_mass_flux->init(opt.filename, opt.periodic);
83 
84  // read time-independent data right away:
85  if (m_temperature->buffer_size() == 1 && m_mass_flux->buffer_size() == 1) {
86  update(geometry, time().current(), 0); // dt is irrelevant
87  }
88 }
89 
90 void Given::update_impl(const Geometry &geometry, double t, double dt) {
91  (void) geometry;
92 
93  m_mass_flux->update(t, dt);
94  m_temperature->update(t, dt);
95 
96  m_mass_flux->average(t, dt);
97  m_temperature->average(t, dt);
98 
102 
103 }
104 
106  return *m_mass_flux;
107 }
108 
110  return *m_temperature;
111 }
112 
114  return *m_accumulation;
115 }
116 
118  return *m_melt;
119 }
120 
122  return *m_runoff;
123 }
124 
125 void Given::define_model_state_impl(const File &output) const {
126  m_mass_flux->define(output, io::PISM_DOUBLE);
127  m_temperature->define(output, io::PISM_DOUBLE);
128 }
129 
130 void Given::write_model_state_impl(const File &output) const {
131  m_mass_flux->write(output);
132  m_temperature->write(output);
133 }
134 
135 } // end of namespace surface
136 } // end of namespace pism
const Time & time() const
Definition: Component.cc:109
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 array::Scalar & accumulation_impl() const
const array::Scalar & melt_impl() const
const array::Scalar & runoff_impl() const
const array::Scalar & mass_flux_impl() const
Given(std::shared_ptr< const Grid > g, std::shared_ptr< atmosphere::AtmosphereModel > input)
Definition: GivenClimate.cc:29
std::shared_ptr< array::Forcing > m_temperature
Definition: GivenClimate.hh:46
void update_impl(const Geometry &geometry, double t, double dt)
Definition: GivenClimate.cc:90
void init_impl(const Geometry &geometry)
Definition: GivenClimate.cc:73
std::shared_ptr< array::Forcing > m_mass_flux
Definition: GivenClimate.hh:45
void write_model_state_impl(const File &output) const
The default (empty implementation).
const array::Scalar & temperature_impl() const
void define_model_state_impl(const File &output) const
The default (empty implementation).
void update(const Geometry &geometry, double t, double dt)
void dummy_accumulation(const array::Scalar &smb, array::Scalar &result)
std::shared_ptr< array::Scalar > m_melt
std::shared_ptr< array::Scalar > m_runoff
void dummy_melt(const array::Scalar &smb, array::Scalar &result)
std::shared_ptr< array::Scalar > m_accumulation
void dummy_runoff(const array::Scalar &smb, array::Scalar &result)
The interface of PISM's surface models.
Definition: SurfaceModel.hh:42
@ PISM_GUESS
Definition: IO_Flags.hh:56
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:72
@ PISM_DOUBLE
Definition: IO_Flags.hh:52
std::string filename
Definition: options.hh:33