URI: 
       tSeaLevel.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
       ---
       tSeaLevel.cc (3790B)
       ---
            1 /* Copyright (C) 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 "pism/coupler/SeaLevel.hh"
           21 
           22 #include "pism/util/MaxTimestep.hh"
           23 
           24 #include "pism/util/pism_utilities.hh" // combine
           25 
           26 namespace pism {
           27 namespace ocean {
           28 namespace sea_level {
           29 
           30 // "Modifier" constructor.
           31 SeaLevel::SeaLevel(IceGrid::ConstPtr grid, std::shared_ptr<SeaLevel> input)
           32   : Component(grid),
           33     m_input_model(input),
           34     m_sea_level(grid, "sea_level", WITHOUT_GHOSTS) {
           35 
           36   m_sea_level.set_attrs("diagnostic",
           37                         "sea level elevation, relative to the geoid",
           38                         "meter", "meter", "", 0);
           39 }
           40 
           41 // "Model" constructor (returns sea level is zero).
           42 SeaLevel::SeaLevel(IceGrid::ConstPtr g)
           43   : SeaLevel(g, std::shared_ptr<SeaLevel>()) {
           44   // empty
           45 }
           46 
           47 SeaLevel::~SeaLevel() {
           48   // empty
           49 }
           50 
           51 void SeaLevel::init(const Geometry &geometry) {
           52   init_impl(geometry);
           53 }
           54 
           55 void SeaLevel::init_impl(const Geometry &geometry) {
           56   if (m_input_model) {
           57     m_input_model->init(geometry);
           58   } else {
           59     // set the default value
           60     m_sea_level.set(0.0);
           61     m_log->message(2, "* Using constant (zero) sea level...\n");
           62   }
           63 }
           64 
           65 void SeaLevel::update(const Geometry &geometry, double t, double dt) {
           66   update_impl(geometry, t, dt);
           67 }
           68 
           69 void SeaLevel::update_impl(const Geometry &geometry, double t, double dt) {
           70   if (m_input_model) {
           71     m_input_model->update(geometry, t, dt);
           72   } else {
           73     m_sea_level.set(0.0);
           74   }
           75 }
           76 
           77 const IceModelVec2S& SeaLevel::elevation() const {
           78   return m_sea_level;
           79 }
           80 
           81 MaxTimestep SeaLevel::max_timestep_impl(double t) const {
           82   if (m_input_model) {
           83     return m_input_model->max_timestep(t);
           84   }
           85   return MaxTimestep("sea level forcing");
           86 }
           87 
           88 void SeaLevel::define_model_state_impl(const File &output) const {
           89   if (m_input_model) {
           90     m_input_model->define_model_state(output);
           91   }
           92 }
           93 
           94 void SeaLevel::write_model_state_impl(const File &output) const {
           95   if (m_input_model) {
           96     m_input_model->write_model_state(output);
           97   }
           98 }
           99 
          100 namespace diagnostics {
          101 
          102 /*! @brief Sea level elevation. */
          103 class SL : public Diag<SeaLevel> {
          104 public:
          105   SL(const SeaLevel *m)
          106     : Diag<SeaLevel>(m) {
          107     /* set metadata: */
          108     m_vars = {SpatialVariableMetadata(m_sys, "sea_level")};
          109 
          110     set_attrs("sea level elevation, relative to the geoid", "", "meters", "meters", 0);
          111   }
          112 
          113 protected:
          114   IceModelVec::Ptr compute_impl() const {
          115 
          116     IceModelVec2S::Ptr result(new IceModelVec2S(m_grid, "sea_level", WITHOUT_GHOSTS));
          117     result->metadata(0) = m_vars[0];
          118 
          119     result->copy_from(model->elevation());
          120 
          121     return result;
          122   }
          123 };
          124 
          125 } // end of namespace diagnostics
          126 
          127 DiagnosticList SeaLevel::diagnostics_impl() const {
          128   DiagnosticList result = {
          129     {"sea_level", Diagnostic::Ptr(new diagnostics::SL(this))},
          130   };
          131 
          132   if (m_input_model) {
          133     return combine(result, m_input_model->diagnostics());
          134   } else {
          135     return result;
          136   }
          137 }
          138 
          139 TSDiagnosticList SeaLevel::ts_diagnostics_impl() const {
          140   if (m_input_model) {
          141     return m_input_model->ts_diagnostics();
          142   } else {
          143     return {};
          144   }
          145 }
          146 
          147 } // end of namespace sea_level
          148 } // end of namespace ocean
          149 } // end of namespace pism