PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/base/util/PISMComponent.hh

Go to the documentation of this file.
00001 // Copyright (C) 2008-2011 Ed Bueler and 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 __PISMComponent_hh
00020 #define __PISMComponent_hh
00021 
00022 #include <petsc.h>
00023 #include <gsl/gsl_math.h>
00024 #include "NCVariable.hh"
00025 #include "PISMVars.hh"
00026 #include "grid.hh"
00027 #include "PISMDiagnostic.hh"
00028 
00030 
00093 class PISMComponent {
00094 public:
00095   PISMComponent(IceGrid &g, const NCConfigVariable &conf)
00096     : grid(g), config(conf) {}
00097   virtual ~PISMComponent() {}
00098 
00099   virtual PetscErrorCode init(PISMVars &vars) = 0;
00100 
00103 
00106   virtual void add_vars_to_output(string /*keyword*/, set<string> &/*result*/) {}
00107 
00110   virtual PetscErrorCode define_variables(set<string> /*vars*/, const NCTool &/*nc*/,
00111                                           nc_type /*nctype*/)
00112   { return 0; }
00113 
00116   virtual PetscErrorCode write_variables(set<string> /*vars*/, string /*filename*/)
00117   { return 0; }
00118 
00120   virtual void get_diagnostics(map<string, PISMDiagnostic*> &/*dict*/) {}
00121 
00122   // //! Add pointers to scalar diagnostic quantities to a dictionary.
00123   // virtual void get_scalar_diagnostics(map<string, PISMDiagnostic_Scalar*> &/*dict*/) {}
00124 protected:
00125   virtual PetscErrorCode find_pism_input(string &filename, bool &regrid, int &start);
00126   IceGrid &grid;
00127   const NCConfigVariable &config;
00128 };
00129 
00132 
00136 class PISMComponent_Diag : public PISMComponent
00137 {
00138 public:
00139   PISMComponent_Diag(IceGrid &g, const NCConfigVariable &conf)
00140     : PISMComponent(g, conf) {}
00141   virtual ~PISMComponent_Diag() {}
00142 
00143   virtual PetscErrorCode update(bool /*fast*/)
00144   { return 0; }
00145 };
00146 
00150 class PISMComponent_TS : public PISMComponent
00151 {
00152 public:
00153   PISMComponent_TS(IceGrid &g, const NCConfigVariable &conf)
00154     : PISMComponent(g, conf)
00155   { t = dt = GSL_NAN; }
00156   virtual ~PISMComponent_TS() {}
00157 
00160   virtual PetscErrorCode max_timestep(PetscReal /*t_years*/, PetscReal &dt_years)
00161   { dt_years = -1; return 0; }
00162 
00164   virtual PetscErrorCode update(PetscReal /*t_years*/, PetscReal /*dt_years*/) = 0;
00165 
00166 protected:
00167   PetscReal t,                  
00168     dt;                         
00169 };
00170 
00173 
00179 template<class Model>
00180 class Modifier : public Model
00181 {
00182 public:
00183   Modifier(IceGrid &g, const NCConfigVariable &conf, Model* in)
00184     : Model(g, conf), input_model(in) {}
00185   virtual ~Modifier()
00186   {
00187     delete input_model;
00188   }
00189 
00190   virtual void add_vars_to_output(string keyword, set<string> &result)
00191   {
00192     input_model->add_vars_to_output(keyword, result);
00193   }
00194 
00195   virtual PetscErrorCode define_variables(set<string> vars, const NCTool &nc,
00196                                           nc_type nctype)
00197   {
00198     PetscErrorCode ierr = input_model->define_variables(vars, nc, nctype); CHKERRQ(ierr);
00199     return 0;
00200   }
00201 
00202   virtual PetscErrorCode write_variables(set<string> vars, string filename)
00203   {
00204     PetscErrorCode ierr = input_model->write_variables(vars, filename); CHKERRQ(ierr);
00205     return 0;
00206   }
00207 
00208   virtual void get_diagnostics(map<string, PISMDiagnostic*> &dict)
00209   {
00210     input_model->get_diagnostics(dict);
00211   }
00212 
00213   virtual PetscErrorCode max_timestep(PetscReal t_years, PetscReal &dt_years)
00214   {
00215     PetscErrorCode ierr = input_model->max_timestep(t_years, dt_years); CHKERRQ(ierr);
00216     return 0;
00217   }
00218 
00219   virtual PetscErrorCode update(PetscReal t_years, PetscReal dt_years)
00220   {
00221     Model::t = t_years;
00222     Model::dt = dt_years;
00223     PetscErrorCode ierr = input_model->update(t_years, dt_years); CHKERRQ(ierr);
00224     return 0;
00225   }
00226 
00227 protected:
00228   Model *input_model;
00229 };
00230 
00231 #endif // __PISMComponent_hh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines