PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/coupler/PScalarForcing.hh

Go to the documentation of this file.
00001 // Copyright (C) 2011 Constantine Khroulev
00002 //
00003 // This file is part of PISM.
00004 //
00005 // PISM is free software; you can redistribute it and/or modify it under the
00006 // terms of the GNU General Public License as published by the Free Software
00007 // Foundation; either version 2 of the License, or (at your option) any later
00008 // version.
00009 //
00010 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
00011 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013 // details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with PISM; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef _PSCALARFORCING_H_
00020 #define _PSCALARFORCING_H_
00021 
00022 #include "PISMSurface.hh"
00023 #include "PISMAtmosphere.hh"
00024 #include "PISMOcean.hh"
00025 
00026 template<class Model, class Mod>
00027 class PScalarForcing : public Mod
00028 {
00029 public:
00030   PScalarForcing(IceGrid &g, const NCConfigVariable &conf, Model* in)
00031     : Mod(g, conf, in), input(in) {}
00032   virtual ~PScalarForcing()
00033   {
00034     if (offset)
00035       delete offset;
00036   }
00037 
00038   virtual PetscErrorCode update(PetscReal t_years, PetscReal dt_years)
00039   {
00040     Mod::t = my_mod(t_years);
00041     Mod::dt = dt_years;
00042 
00043     PetscErrorCode ierr = Mod::input_model->update(t_years, dt_years); CHKERRQ(ierr);
00044     return 0;
00045   }
00046 
00047 protected:
00048   virtual PetscErrorCode init_internal()
00049   {
00050     PetscErrorCode ierr;
00051     bool option_set, bc_period_set, bc_ref_year_set;
00052 
00053     IceGrid &g = Mod::grid;
00054 
00055     bc_period = 0;
00056     bc_reference_year = 0;
00057 
00058     ierr = PetscOptionsBegin(g.com, "", "Scalar forcing options", ""); CHKERRQ(ierr);
00059     {
00060       ierr = PISMOptionsString(option, "Specifies a file with scalar offsets",
00061                                filename, option_set); CHKERRQ(ierr);
00062       ierr = PISMOptionsReal("-bc_period", "Specifies the length of the climate data period",
00063                              bc_period, bc_period_set); CHKERRQ(ierr);
00064       ierr = PISMOptionsReal("-bc_reference_year", "Boundary condition reference year",
00065                              bc_reference_year, bc_ref_year_set); CHKERRQ(ierr);
00066     }
00067     ierr = PetscOptionsEnd(); CHKERRQ(ierr);
00068 
00069     if (option_set == false) {
00070       ierr = verbPrintf(2, g.com, "  WARNING: %s is not set; forcing is inactive.\n",
00071                         option.c_str()); CHKERRQ(ierr);
00072       delete offset;
00073       offset = NULL;
00074     }
00075 
00076     if (offset) {
00077       ierr = verbPrintf(2, g.com, 
00078                         "  reading %s data from forcing file %s...\n",
00079                         offset->short_name.c_str(), filename.c_str());
00080       CHKERRQ(ierr);
00081 
00082       ierr = offset->read(filename.c_str()); CHKERRQ(ierr);
00083     }
00084 
00085     return 0;
00086   }
00087 
00088   PetscErrorCode offset_data(IceModelVec2S &result) {
00089     if (offset) {
00090       PetscErrorCode ierr = result.shift((*offset)(Mod::t + 0.5*Mod::dt)); CHKERRQ(ierr);
00091     }
00092     return 0;
00093   }
00094 
00096   PetscReal my_mod(PetscReal in) {
00097     if (bc_period < 1e-6) return in;
00098 
00099     // compute time since the reference year:
00100     PetscReal delta = in - bc_reference_year;
00101 
00102     // compute delta mod bc_period:
00103     return delta - floor(delta / bc_period) * bc_period;
00104   }
00105 
00106   Model *input;
00107   Timeseries *offset;
00108   string filename, offset_name, option;
00109 
00110   PetscReal bc_period, bc_reference_year;
00111 
00112 };
00113 
00114 class PSdTforcing : public PScalarForcing<PISMSurfaceModel,PSModifier>
00115 {
00116 public:
00117   PSdTforcing(IceGrid &g, const NCConfigVariable &conf, PISMSurfaceModel* in);
00118   virtual ~PSdTforcing() {}
00119 
00120   virtual PetscErrorCode init(PISMVars &vars);
00121 
00122   virtual PetscErrorCode ice_surface_temperature(IceModelVec2S &result);
00123 };
00124 
00125 class PAdTforcing : public PScalarForcing<PISMAtmosphereModel,PAModifier>
00126 {
00127 public:
00128   PAdTforcing(IceGrid &g, const NCConfigVariable &conf, PISMAtmosphereModel* in);
00129   virtual ~PAdTforcing() {}
00130 
00131   virtual PetscErrorCode init(PISMVars &vars);
00132 
00133   virtual PetscErrorCode mean_annual_temp(IceModelVec2S &result);
00134 
00135   virtual PetscErrorCode temp_time_series(int i, int j, int N,
00136                                           PetscReal *ts, PetscReal *values);
00137   virtual PetscErrorCode temp_snapshot(IceModelVec2S &result);
00138 
00139 };
00140 
00141 class POdSLforcing : public PScalarForcing<PISMOceanModel,POModifier>
00142 {
00143 public:
00144   POdSLforcing(IceGrid &g, const NCConfigVariable &conf, PISMOceanModel* in);
00145   virtual ~POdSLforcing() {}
00146 
00147   virtual PetscErrorCode init(PISMVars &vars);
00148   virtual PetscErrorCode sea_level_elevation(PetscReal &result);
00149 };
00150 
00151 #endif /* _PSCALARFORCING_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines