PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/earth/PISMBedDef.cc

Go to the documentation of this file.
00001 // Copyright (C) 2010, 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 #include "PISMBedDef.hh"
00020 
00021 PISMBedDef::PISMBedDef(IceGrid &g, const NCConfigVariable &conf)
00022   : PISMComponent_TS(g, conf) {
00023 
00024   thk    = NULL;
00025   topg   = NULL;
00026   uplift = NULL;
00027 
00028   t_beddef_last = GSL_NAN;
00029 
00030   PetscErrorCode ierr = pismbeddef_allocate();
00031   if (ierr != 0) {
00032     PetscPrintf(grid.com, "PISMBedDef::PISMBedDef(...): pismbeddef_allocate() failed\n");
00033     PISMEnd();
00034   }
00035 }
00036 
00037 PetscErrorCode PISMBedDef::pismbeddef_allocate() {
00038   PetscErrorCode ierr;
00039   PetscInt WIDE_STENCIL = grid.max_stencil_width;
00040 
00041   ierr = topg_initial.create(grid, "topg_initial", true, WIDE_STENCIL); CHKERRQ(ierr);
00042   ierr = topg_initial.set_attrs("model_state", "bedrock surface elevation (at the beginning of the run)",
00043                                 "m", ""); CHKERRQ(ierr);
00044 
00045   ierr = topg_last.create(grid, "topg", true, WIDE_STENCIL); CHKERRQ(ierr);
00046   ierr = topg_last.set_attrs("model_state", "bedrock surface elevation",
00047                              "m", "bedrock_altitude"); CHKERRQ(ierr);
00048 
00049   return 0;
00050 }
00051 
00052 void PISMBedDef::add_vars_to_output(string /*keyword*/, set<string> &result) {
00053   result.insert("topg_initial");
00054 }
00055 
00056 PetscErrorCode PISMBedDef::define_variables(set<string> vars, const NCTool &nc,
00057                                             nc_type nctype) {
00058   PetscErrorCode ierr;
00059 
00060   if (set_contains(vars, "topg_initial")) {
00061     ierr = topg_initial.define(nc, nctype); CHKERRQ(ierr);
00062   }
00063 
00064   return 0;
00065 }
00066 
00067 PetscErrorCode PISMBedDef::write_variables(set<string> vars, string filename) {
00068   PetscErrorCode ierr;
00069 
00070   if (set_contains(vars, "topg_initial")) {
00071     ierr = topg_initial.write(filename.c_str()); CHKERRQ(ierr);
00072   }
00073 
00074   return 0;
00075 }
00076 
00077 PetscErrorCode PISMBedDef::init(PISMVars &vars) {
00078   PetscErrorCode ierr;
00079 
00080   t_beddef_last = grid.year;
00081 
00082   thk = dynamic_cast<IceModelVec2S*>(vars.get("land_ice_thickness"));
00083   if (!thk) SETERRQ(1, "ERROR: thk is not available");
00084 
00085   topg = dynamic_cast<IceModelVec2S*>(vars.get("bedrock_altitude"));
00086   if (!topg) SETERRQ(1, "ERROR: topg is not available");
00087 
00088   uplift = dynamic_cast<IceModelVec2S*>(vars.get("tendency_of_bedrock_altitude"));
00089   if (!uplift) SETERRQ(1, "ERROR: uplift is not available");
00090 
00091   // Save the bed elevation at the beginning of the run:
00092   ierr = topg_initial.copy_from(*topg); CHKERRQ(ierr);
00093   
00094   return 0;
00095 }
00096 
00098 PetscErrorCode PISMBedDef::compute_uplift(PetscScalar dt_beddef) {
00099   PetscErrorCode ierr;
00100 
00101   ierr = topg->add(-1, topg_last, *uplift); CHKERRQ(ierr);
00103   ierr = uplift->scale(1.0 / (dt_beddef * secpera)); CHKERRQ(ierr); 
00104 
00105   return 0;
00106 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines