PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/coupler/PSExternal.hh

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 #ifndef _PSEXTERNAL_H_
00020 #define _PSEXTERNAL_H_
00021 
00022 #include "PISMSurface.hh"
00023 
00024 const int TAG_EBM_RUN     = 1;
00025 const int TAG_EBM_STOP    = 2;
00026 const int TAG_EBM_COMMAND = 3;
00027 const int TAG_EBM_STATUS  = 4;
00028 
00029 const int EBM_STATUS_READY  = 1;
00030 const int EBM_STATUS_FAILED = 2;
00031 
00033 class EBM_driver {
00034 public:
00035   EBM_driver(MPI_Comm com);
00036   int run();
00037 protected:
00038   MPI_Comm inter_comm;          // communicator used to send messages to PISM
00039   string command;               // EBM command
00040   int run_ebm(double year);
00041 };
00042 
00045 class PSExternal : public PISMSurfaceModel {
00046 public:
00047   PSExternal(IceGrid &g, const NCConfigVariable &conf, MPI_Comm my_inter_comm)
00048     : PISMSurfaceModel(g, conf)
00049   {
00050     update_interval = 1;        // years
00051     ebm_update_interval = 0.5 * update_interval;
00052     last_ebm_update_year = GSL_NAN;
00053     last_bc_update_year = GSL_NAN;
00054     ebm_is_running = false;
00055     inter_comm = my_inter_comm;
00056   }
00057 
00058   virtual ~PSExternal();
00059 
00060   virtual PetscErrorCode init(PISMVars &vars);
00061 
00062   virtual void add_vars_to_output(string keyword, set<string> &result);
00063   virtual PetscErrorCode define_variables(set<string> vars, const NCTool &nc,
00064                                           nc_type nctype);
00065   virtual PetscErrorCode write_variables(set<string> vars, string filename);
00066 
00067   virtual void attach_atmosphere_model(PISMAtmosphereModel *input)
00068   { delete input; }
00069   virtual void get_diagnostics(map<string, PISMDiagnostic*> &/*dict*/) {}
00070 
00071   virtual PetscErrorCode ice_surface_mass_flux(IceModelVec2S &result);
00072   virtual PetscErrorCode ice_surface_temperature(IceModelVec2S &result);
00073   virtual PetscErrorCode update(PetscReal t_years, PetscReal dt_years);
00074   virtual PetscErrorCode max_timestep(PetscReal t_years, PetscReal &dt_years);
00075 protected:
00076   double gamma, update_interval, ebm_update_interval, last_ebm_update_year, last_bc_update_year;
00077   IceModelVec2S acab, artm;
00078   MPI_Comm inter_comm;
00079   string ebm_command, ebm_input, ebm_output;
00080   bool ebm_is_running;
00081   vector<IceModelVec*> ebm_vars;
00082 
00083   virtual PetscErrorCode update_artm();
00084   virtual PetscErrorCode update_acab();
00085   virtual PetscErrorCode run(double t_years);
00086   virtual PetscErrorCode wait();
00087   virtual PetscErrorCode write_coupling_fields();
00088 };
00089 
00092 
00096 class PSExternal_ALR : public PSExternal
00097 {
00098 public:
00099   PSExternal_ALR(IceGrid &g, const NCConfigVariable &conf, MPI_Comm my_inter_comm)
00100     : PSExternal(g, conf, my_inter_comm)
00101   {
00102     gamma = 0;                  // essentially disables the lapse rate correction
00103   }
00104 
00105   virtual ~PSExternal_ALR() {}
00106 
00107   virtual PetscErrorCode init(PISMVars &vars);
00108   virtual void add_vars_to_output(string keyword, set<string> &result);
00109 protected:
00110   IceModelVec2S artm_0, *usurf;
00111   PetscReal gamma;
00112 
00113   virtual PetscErrorCode update_artm();
00114 };
00115 
00116 #endif /* _PSEXTERNAL_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines