URI:
       tInitialization.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
  HTML git clone git://src.adamsgaard.dk/pism
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tInitialization.cc (4774B)
       ---
            1 /* Copyright (C) 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 
           20 #include "Initialization.hh"
           21 #include "pism/util/pism_utilities.hh"
           22 #include "pism/util/io/io_helpers.hh"
           23 #include "pism/util/io/File.hh"
           24 #include "pism/util/pism_options.hh"
           25 #include "pism/coupler/util/init_step.hh"
           26 
           27 namespace pism {
           28 namespace ocean {
           29 
           30 InitializationHelper::InitializationHelper(IceGrid::ConstPtr g, std::shared_ptr<OceanModel> in)
           31   : OceanModel(g, in) {
           32 
           33   m_melange_back_pressure_fraction = allocate_melange_back_pressure(g);
           34   m_melange_back_pressure_fraction->set_name("effective_melange_back_pressure_fraction");
           35   m_melange_back_pressure_fraction->metadata().set_string("pism_intent", "model_state");
           36 
           37   m_shelf_base_temperature = allocate_shelf_base_temperature(g);
           38   m_shelf_base_temperature->set_name("effective_shelf_base_temperature");
           39   m_shelf_base_temperature->metadata().set_string("pism_intent", "model_state");
           40 
           41   m_shelf_base_mass_flux = allocate_shelf_base_mass_flux(g);
           42   m_shelf_base_mass_flux->set_name("effective_shelf_base_mass_flux");
           43   // use internal units when saving
           44   auto units = m_shelf_base_mass_flux->metadata().get_string("units");
           45   m_shelf_base_mass_flux->metadata().set_string("glaciological_units", units);
           46   m_shelf_base_mass_flux->metadata().set_string("pism_intent", "model_state");
           47 }
           48 
           49 void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
           50   OceanModel::update_impl(geometry, t, dt);
           51 
           52   m_melange_back_pressure_fraction->copy_from(m_input_model->melange_back_pressure_fraction());
           53   m_shelf_base_temperature->copy_from(m_input_model->shelf_base_temperature());
           54   m_shelf_base_mass_flux->copy_from(m_input_model->shelf_base_mass_flux());
           55 }
           56 
           57 void InitializationHelper::init_impl(const Geometry &geometry) {
           58   m_input_model->init(geometry);
           59 
           60   InputOptions opts = process_input_options(m_grid->com, m_config);
           61 
           62   if (opts.type == INIT_RESTART) {
           63     m_log->message(2, "* Reading effective ocean model outputs from '%s' for re-starting...\n",
           64                    opts.filename.c_str());
           65 
           66     File file(m_grid->com, opts.filename, PISM_GUESS, PISM_READONLY);
           67     const unsigned int time_length = file.nrecords();
           68     const unsigned int last_record = time_length > 0 ? time_length - 1 : 0;
           69 
           70     m_melange_back_pressure_fraction->read(file, last_record);
           71     m_shelf_base_mass_flux->read(file, last_record);
           72     m_shelf_base_temperature->read(file, last_record);
           73 
           74     file.close();
           75   } else {
           76     m_log->message(2, "* Performing a 'fake' ocean model time-step for bootstrapping...\n");
           77 
           78     init_step(this, geometry, *m_grid->ctx()->time());
           79   }
           80 
           81   // Support regridding. This is needed to ensure that initialization using "-i" is equivalent to
           82   // "-i ... -bootstrap -regrid_file ..."
           83   {
           84     regrid("ocean model initialization helper", *m_melange_back_pressure_fraction,
           85            REGRID_WITHOUT_REGRID_VARS);
           86     regrid("ocean model initialization helper", *m_shelf_base_mass_flux,
           87            REGRID_WITHOUT_REGRID_VARS);
           88     regrid("ocean model initialization helper", *m_shelf_base_temperature,
           89            REGRID_WITHOUT_REGRID_VARS);
           90   }
           91 }
           92 
           93 void InitializationHelper::define_model_state_impl(const File &output) const {
           94   m_melange_back_pressure_fraction->define(output);
           95   m_shelf_base_mass_flux->define(output);
           96   m_shelf_base_temperature->define(output);
           97 
           98   m_input_model->define_model_state(output);
           99 }
          100 
          101 void InitializationHelper::write_model_state_impl(const File &output) const {
          102   m_melange_back_pressure_fraction->write(output);
          103   m_shelf_base_mass_flux->write(output);
          104   m_shelf_base_temperature->write(output);
          105 
          106   m_input_model->write_model_state(output);
          107 }
          108 
          109 const IceModelVec2S& InitializationHelper::shelf_base_temperature_impl() const {
          110   return *m_shelf_base_temperature;
          111 }
          112 
          113 const IceModelVec2S& InitializationHelper::shelf_base_mass_flux_impl() const {
          114   return *m_shelf_base_mass_flux;
          115 }
          116 
          117 const IceModelVec2S& InitializationHelper::melange_back_pressure_fraction_impl() const {
          118   return *m_melange_back_pressure_fraction;
          119 }
          120 
          121 } // end of namespace ocean
          122 } // end of namespace pism