|
PISM, A Parallel Ice Sheet Model stable 0.4.1779
|
00001 // Copyright (C) 2008-2011 Ed Bueler, Constantine Khroulev, Ricarda Winkelmann, 00002 // Gudfinna Adalgeirsdottir and Andy Aschwanden 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 // Implementation of the constant-in-time atmosphere model (-atmosphere 00021 // constant). 00022 00023 #include "PISMAtmosphere.hh" 00024 00025 PetscErrorCode PAConstant::init(PISMVars &/*vars*/) { 00026 PetscErrorCode ierr; 00027 bool regrid = false; 00028 int start = -1; 00029 00030 ierr = verbPrintf(2, grid.com, "* Initializing the constant-in-time atmosphere model...\n"); CHKERRQ(ierr); 00031 00032 // allocate IceModelVecs for storing temperature and precipitation fields: 00033 00034 // create mean annual ice equivalent precipitation rate (before separating rain, 00035 // and before melt, etc. in PISMSurfaceModel) 00036 ierr = precip.create(grid, "precip", false); CHKERRQ(ierr); 00037 ierr = precip.set_attrs("climate_state", 00038 "mean annual ice-equivalent precipitation rate", 00039 "m s-1", 00040 ""); CHKERRQ(ierr); // no CF standard_name ?? 00041 ierr = precip.set_glaciological_units("m year-1"); CHKERRQ(ierr); 00042 precip.write_in_glaciological_units = true; 00043 precip.time_independent = true; 00044 00045 ierr = temperature.create(grid, "temp_ma", false); CHKERRQ(ierr); // FIXME! choose the right name 00046 ierr = temperature.set_attrs( 00047 "climate_state", 00048 "mean annual near-surface (2 m) air temperature", 00049 "K", 00050 ""); CHKERRQ(ierr); 00051 temperature.time_independent = true; 00052 00053 // find PISM input file to read data from: 00054 00055 ierr = find_pism_input(input_file, regrid, start); CHKERRQ(ierr); 00056 00057 // read snow precipitation rate and temperatures from file 00058 ierr = verbPrintf(2, grid.com, 00059 " reading mean annual ice-equivalent precipitation rate 'precip'\n" 00060 " and mean annual near-surface air temperature 'temp_ma' from %s ... \n", 00061 input_file.c_str()); CHKERRQ(ierr); 00062 if (regrid) { 00063 ierr = precip.regrid(input_file.c_str(), true); CHKERRQ(ierr); // fails if not found! 00064 ierr = temperature.regrid(input_file.c_str(), true); CHKERRQ(ierr); // fails if not found! 00065 } else { 00066 ierr = precip.read(input_file.c_str(), start); CHKERRQ(ierr); // fails if not found! 00067 ierr = temperature.read(input_file.c_str(), start); CHKERRQ(ierr); // fails if not found! 00068 } 00069 00070 airtemp_var.init_2d("airtemp", grid); 00071 airtemp_var.set_string("pism_intent", "diagnostic"); 00072 airtemp_var.set_string("long_name", 00073 "snapshot of the near-surface air temperature"); 00074 ierr = airtemp_var.set_units("K"); CHKERRQ(ierr); 00075 00076 return 0; 00077 } 00078 00079 PetscErrorCode PAConstant::mean_precip(IceModelVec2S &result) { 00080 PetscErrorCode ierr; 00081 00082 string precip_history = "read from " + input_file + "\n"; 00083 00084 ierr = precip.copy_to(result); CHKERRQ(ierr); 00085 ierr = result.set_attr("history", precip_history); 00086 return 0; 00087 } 00088 00089 PetscErrorCode PAConstant::mean_annual_temp(IceModelVec2S &result) { 00090 PetscErrorCode ierr; 00091 00092 string temp_history = "read from " + input_file + "\n"; 00093 00094 ierr = temperature.copy_to(result); CHKERRQ(ierr); 00095 ierr = result.set_attr("history", temp_history); 00096 return 0; 00097 } 00098 00099 PetscErrorCode PAConstant::begin_pointwise_access() { 00100 PetscErrorCode ierr; 00101 ierr = temperature.begin_access(); CHKERRQ(ierr); 00102 return 0; 00103 } 00104 00105 PetscErrorCode PAConstant::end_pointwise_access() { 00106 PetscErrorCode ierr; 00107 ierr = temperature.end_access(); CHKERRQ(ierr); 00108 return 0; 00109 } 00110 00111 PetscErrorCode PAConstant::temp_time_series(int i, int j, int N, 00112 PetscReal */*ts*/, PetscReal *values) { 00113 for (PetscInt k = 0; k < N; k++) 00114 values[k] = temperature(i,j); 00115 return 0; 00116 } 00117 00118 PetscErrorCode PAConstant::temp_snapshot(IceModelVec2S &result) { 00119 PetscErrorCode ierr; 00120 00121 ierr = mean_annual_temp(result); CHKERRQ(ierr); 00122 00123 return 0; 00124 } 00125 00126 void PAConstant::add_vars_to_output(string keyword, set<string> &result) { 00127 result.insert("precip"); 00128 result.insert("temp_ma"); 00129 00130 if (keyword == "big") { 00131 result.insert("airtemp"); 00132 } 00133 } 00134 00135 PetscErrorCode PAConstant::define_variables(set<string> vars, const NCTool &nc, 00136 nc_type nctype) { 00137 PetscErrorCode ierr; 00138 int varid; 00139 00140 if (set_contains(vars, "airtemp")) { 00141 ierr = airtemp_var.define(nc, varid, nctype, false); CHKERRQ(ierr); 00142 } 00143 00144 if (set_contains(vars, "precip")) { 00145 ierr = precip.define(nc, nctype); CHKERRQ(ierr); 00146 } 00147 00148 if (set_contains(vars, "temp_ma")) { 00149 ierr = temperature.define(nc, nctype); CHKERRQ(ierr); 00150 } 00151 00152 return 0; 00153 } 00154 00155 PetscErrorCode PAConstant::write_variables(set<string> vars, string filename) { 00156 PetscErrorCode ierr; 00157 00158 if (set_contains(vars, "airtemp")) { 00159 IceModelVec2S airtemp; 00160 ierr = airtemp.create(grid, "airtemp", false); CHKERRQ(ierr); 00161 ierr = airtemp.set_metadata(airtemp_var, 0); CHKERRQ(ierr); 00162 00163 ierr = temp_snapshot(airtemp); CHKERRQ(ierr); 00164 00165 ierr = airtemp.write(filename.c_str()); CHKERRQ(ierr); 00166 } 00167 00168 if (set_contains(vars, "precip")) { 00169 ierr = precip.write(filename.c_str()); CHKERRQ(ierr); 00170 } 00171 00172 if (set_contains(vars, "temp_ma")) { 00173 ierr = temperature.write(filename.c_str()); CHKERRQ(ierr); 00174 } 00175 00176 return 0; 00177 } 00178
1.7.3