Anomaly.cc (3324B)
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 "Anomaly.hh" 20 #include "pism/util/IceGrid.hh" 21 #include "pism/util/io/io_helpers.hh" 22 #include "pism/coupler/util/options.hh" 23 24 namespace pism { 25 namespace ocean { 26 27 Anomaly::Anomaly(IceGrid::ConstPtr g, std::shared_ptr<OceanModel> in) 28 : OceanModel(g, in) { 29 30 ForcingOptions opt(*m_grid->ctx(), "ocean.anomaly"); 31 32 { 33 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size"); 34 unsigned int evaluations_per_year = m_config->get_number("input.forcing.evaluations_per_year"); 35 bool periodic = opt.period > 0; 36 37 File file(m_grid->com, opt.filename, PISM_NETCDF3, PISM_READONLY); 38 39 m_shelf_base_mass_flux_anomaly = IceModelVec2T::ForcingField(m_grid, 40 file, 41 "shelf_base_mass_flux_anomaly", 42 "", // no standard name 43 buffer_size, 44 evaluations_per_year, 45 periodic); 46 } 47 48 m_shelf_base_mass_flux_anomaly->set_attrs("climate_forcing", 49 "anomaly of the shelf base mass flux rate", 50 "kg m-2 s-1", "kg m-2 year-1", "", 0); 51 52 m_shelf_base_mass_flux = allocate_shelf_base_mass_flux(g); 53 54 55 } 56 57 Anomaly::~Anomaly() { 58 // empty 59 } 60 61 void Anomaly::init_impl(const Geometry &geometry) { 62 63 if (m_input_model) { 64 m_input_model->init(geometry); 65 } 66 67 m_log->message(2, 68 "* Initializing the '-ocean ...,anomaly' modifier...\n"); 69 70 ForcingOptions opt(*m_grid->ctx(), "ocean.anomaly"); 71 72 m_log->message(2, 73 " reading anomalies from %s ...\n", opt.filename.c_str()); 74 75 m_shelf_base_mass_flux_anomaly->init(opt.filename, opt.period, opt.reference_time); 76 } 77 78 void Anomaly::update_impl(const Geometry &geometry, double t, double dt) { 79 m_input_model->update(geometry, t, dt); 80 81 m_shelf_base_mass_flux_anomaly->update(t, dt); 82 83 m_shelf_base_mass_flux_anomaly->average(t, dt); 84 85 m_input_model->shelf_base_mass_flux().add(1.0, *m_shelf_base_mass_flux_anomaly, 86 *m_shelf_base_mass_flux); 87 } 88 89 const IceModelVec2S &Anomaly::shelf_base_mass_flux_impl() const { 90 return *m_shelf_base_mass_flux; 91 } 92 93 94 } // end of namespace ocean 95 } // end of namespace pism