PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/coupler/PSConstantPIK.cc

Go to the documentation of this file.
00001 // Copyright (C) 2008-2011 Ed Bueler, Constantine Khroulev, Ricarda Winkelmann,
00002 // Gudfinna Adalgeirsdottir, Andy Aschwanden and Torsten Albrecht
00003 //
00004 // This file is part of PISM.
00005 //
00006 // PISM is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 2 of the License, or (at your option) any later
00009 // version.
00010 //
00011 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00014 // details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with PISM; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 #include "PISMSurface.hh"
00021 #include "PISMIO.hh"
00022 
00023 
00026 
00027 PetscErrorCode PSConstantPIK::init(PISMVars &vars) {
00028   PetscErrorCode ierr;
00029   bool regrid = false;
00030   int start = -1;
00031 
00032   //variables = &vars;
00033 
00034   ierr = verbPrintf(2, grid.com,
00035      "* Initializing the constant-in-time surface processes model PSConstantPIK.\n"
00036      "  It reads surface mass balance directly from the file and holds them constant.\n"
00037      "  Ice upper-surface temperature is parameterized as in Martin et al. 2011, Eqn. 2.0.2.\n"
00038      "  Any choice of atmosphere coupler (option '-atmosphere') is ignored.\n"); CHKERRQ(ierr);
00039 
00040 
00041   usurf = dynamic_cast<IceModelVec2S*>(vars.get("surface_altitude"));
00042    if (!usurf) SETERRQ(12, "ERROR: 'usurf' is not available or is wrong type in dictionary");
00043 
00044   lat = dynamic_cast<IceModelVec2S*>(vars.get("latitude"));
00045   if (!lat) SETERRQ(1, "ERROR: latitude is not available");
00046 
00047 
00048 
00049   // allocate IceModelVecs for storing temperature and surface mass balance fields
00050 
00051   // create mean annual ice equivalent snow precipitation rate (before melt, and not including rain)
00052   ierr = acab.create(grid, "acab", false); CHKERRQ(ierr);
00053   ierr = acab.set_attrs("climate_state",
00054                         "constant-in-time ice-equivalent surface mass balance (accumulation/ablation) rate",
00055                         "m s-1",
00056                         "land_ice_surface_specific_mass_balance"); // CF standard_name
00057                         CHKERRQ(ierr);
00058   ierr = acab.set_glaciological_units("m year-1"); CHKERRQ(ierr);
00059   acab.write_in_glaciological_units = true;
00060 
00061   ierr = artm.create(grid, "artm", false); CHKERRQ(ierr);
00062   ierr = artm.set_attrs("climate_state",
00063                         "constant-in-time ice temperature at the ice surface",
00064                         "K",
00065                         ""); CHKERRQ(ierr);
00066 
00067   // find PISM input file to read data from:
00068   ierr = find_pism_input(input_file, regrid, start); CHKERRQ(ierr);
00069 
00070   // read snow precipitation rate from file
00071   ierr = verbPrintf(2, grid.com,
00072     "    reading ice-equivalent surface mass balance rate 'acab' from %s ... \n",
00073     input_file.c_str()); CHKERRQ(ierr);
00074   if (regrid) {
00075     ierr = acab.regrid(input_file.c_str(), true); CHKERRQ(ierr); // fails if not found!
00076   } else {
00077     ierr = acab.read(input_file.c_str(), start); CHKERRQ(ierr); // fails if not found!
00078   }
00079 
00080 
00081   // parameterizing the ice surface temperature 'artm'
00082   ierr = verbPrintf(2, grid.com,"    parameterizing the ice surface temperature 'artm' ... \n"); CHKERRQ(ierr);
00083 
00084   return 0;
00085 }
00086 
00087 PetscErrorCode PSConstantPIK::ice_surface_mass_flux(IceModelVec2S &result) {
00088   PetscErrorCode ierr;
00089   string history  = "read from " + input_file + "\n";
00090 
00091   ierr = acab.copy_to(result); CHKERRQ(ierr);
00092   ierr = result.set_attr("history", history); CHKERRQ(ierr);
00093 
00094   return 0;
00095 }
00096 
00097 PetscErrorCode PSConstantPIK::ice_surface_temperature(IceModelVec2S &result) {
00098   PetscErrorCode ierr;
00099   string history  = "parmeterized ice surface temperature \n";
00100 
00101      ierr = result.begin_access();   CHKERRQ(ierr);
00102      ierr = artm.begin_access();   CHKERRQ(ierr);
00103     ierr = usurf->begin_access();   CHKERRQ(ierr);
00104     ierr = lat->begin_access(); CHKERRQ(ierr);
00105     for (PetscInt i=grid.xs; i<grid.xs+grid.xm; ++i) {
00106       for (PetscInt j=grid.ys; j<grid.ys+grid.ym; ++j) {
00107 
00108         result(i,j) = 273.15 + 30.7 - 0.0080830625 * (*usurf)(i,j) - 0.68775 * (*lat)(i,j)*(-1.0) ; //PollardMod2
00109         artm(i,j)=result(i,j);
00110         //ierr = verbPrintf(2, grid.com,"!!!!! h=%f, lat=%f, artm=%f\n",(*usurf)(i,j),(*lat)(i,j),result(i,j)); CHKERRQ(ierr);
00111       }
00112     }
00113     ierr = usurf->end_access();   CHKERRQ(ierr);
00114     ierr = lat->end_access(); CHKERRQ(ierr);
00115     ierr = result.end_access();   CHKERRQ(ierr);
00116     ierr = artm.end_access();   CHKERRQ(ierr);
00117 
00118   ierr = result.set_attr("history", history); CHKERRQ(ierr);
00119   //ierr = result.set(artm); CHKERRQ(ierr);
00120   //ierr = results.copy_to(artm); CHKERRQ(ierr);
00121 
00122   return 0;
00123 }
00124 
00125 void PSConstantPIK::add_vars_to_output(string /*keyword*/, set<string> &result) {
00126   result.insert("acab");
00127   result.insert("artm");
00128   // does not call atmosphere->add_vars_to_output().
00129 }
00130 
00131 PetscErrorCode PSConstantPIK::define_variables(set<string> vars, const NCTool &nc, nc_type nctype) {
00132   PetscErrorCode ierr;
00133 
00134   ierr = PISMSurfaceModel::define_variables(vars, nc, nctype); CHKERRQ(ierr);
00135 
00136   if (set_contains(vars, "artm")) {
00137     ierr = artm.define(nc, nctype); CHKERRQ(ierr);
00138   }
00139 
00140   if (set_contains(vars, "acab")) {
00141     ierr = acab.define(nc, nctype); CHKERRQ(ierr);
00142   }
00143 
00144   return 0;
00145 }
00146 
00147 PetscErrorCode PSConstantPIK::write_variables(set<string> vars, string filename) {
00148   PetscErrorCode ierr;
00149 
00150   if (set_contains(vars, "artm")) {
00151     ierr = artm.write(filename.c_str()); CHKERRQ(ierr);
00152   }
00153 
00154   if (set_contains(vars, "acab")) {
00155     ierr = acab.write(filename.c_str()); CHKERRQ(ierr);
00156   }
00157 
00158   return 0;
00159 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines