pism

[fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
git clone git://src.adamsgaard.dk/pism # fast
git clone https://src.adamsgaard.dk/pism.git # slow
Log | Files | Refs | README | LICENSE Back to index

Given.cc (3671B)


      1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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 "Given.hh"
     20 
     21 #include "pism/util/IceGrid.hh"
     22 #include "pism/util/Time.hh"
     23 
     24 #include "pism/coupler/util/options.hh"
     25 #include "pism/geometry/Geometry.hh"
     26 
     27 namespace pism {
     28 namespace frontalmelt {
     29 
     30 Given::Given(IceGrid::ConstPtr g)
     31   : FrontalMelt(g, nullptr) {
     32 
     33   m_frontal_melt_rate.reset(new IceModelVec2T(g, "frontal_melt_rate", 1, 1));
     34 
     35   m_frontal_melt_rate->init_constant(0.0);
     36 }
     37 
     38 Given::~Given() {
     39   // empty
     40 }
     41 
     42 void Given::init_impl(const Geometry &geometry) {
     43   (void) geometry;
     44 
     45   m_log->message(2,
     46                  "* Initializing the frontal melt model reading melt rates\n"
     47                  "  from a file...\n");
     48 
     49   ForcingOptions opt(*m_grid->ctx(), "frontal_melt.given");
     50 
     51   {
     52     unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
     53     unsigned int evaluations_per_year = m_config->get_number("input.forcing.evaluations_per_year");
     54     bool periodic = opt.period > 0;
     55 
     56     File file(m_grid->com, opt.filename, PISM_NETCDF3, PISM_READONLY);
     57 
     58     m_frontal_melt_rate = IceModelVec2T::ForcingField(m_grid,
     59                                                       file,
     60                                                       "frontal_melt_rate",
     61                                                       "", // no standard name
     62                                                       buffer_size,
     63                                                       evaluations_per_year,
     64                                                       periodic);
     65   }
     66 
     67   m_frontal_melt_rate->set_attrs("climate_forcing", "frontal melt rate",
     68                                  "m s-1", "m year-1", "", 0);
     69 
     70   m_frontal_melt_rate->init(opt.filename, opt.period, opt.reference_time);
     71 }
     72 
     73 void Given::update_impl(const FrontalMeltInputs &inputs, double t, double dt) {
     74 
     75   const IceModelVec2CellType &cell_type = inputs.geometry->cell_type;
     76 
     77   // fill m_frontal_melt_rate with values read from an file
     78   m_frontal_melt_rate->update(t, dt);
     79   m_frontal_melt_rate->average(t, dt);
     80 
     81   // post-processing: keep values at grounded (or grounded and floating) margins and in
     82   // the interior, filling the rest with zeros
     83 
     84   IceModelVec::AccessList list{&cell_type, m_frontal_melt_rate.get()};
     85 
     86   for (Points p(*m_grid); p; p.next()) {
     87     const int i = p.i(), j = p.j();
     88 
     89     auto R = (*m_frontal_melt_rate)(i, j);
     90 
     91     if (apply(cell_type, i, j)) {
     92       (*m_frontal_melt_rate)(i, j) = R;
     93     } else {
     94       (*m_frontal_melt_rate)(i, j) = 0.0;
     95     }
     96   }
     97 }
     98 
     99 MaxTimestep Given::max_timestep_impl(double t) const {
    100 
    101   auto dt = m_frontal_melt_rate->max_timestep(t);
    102 
    103   if (dt.finite()) {
    104     return MaxTimestep(dt.value(), "frontal_melt given");
    105   } else {
    106     return MaxTimestep("frontal_melt given");
    107   }
    108 }
    109 
    110 
    111 const IceModelVec2S& Given::frontal_melt_rate_impl() const {
    112   return *m_frontal_melt_rate;
    113 }
    114 
    115 } // end of namespace frontalmelt
    116 } // end of namespace pism