URI: 
       tField.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
  HTML git clone git://src.adamsgaard.dk/pism
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tField.hh (5522B)
       ---
            1 /* Copyright (C) 2014, 2015, 2019 PISM Authors
            2  *
            3  * This file is part of PISM.
            4  *
            5  * PISM is free software; you can redistribute it and/or modify it under the
            6  * terms of the GNU General Public License as published by the Free Software
            7  * Foundation; either version 3 of the License, or (at your option) any later
            8  * version.
            9  *
           10  * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
           11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
           12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
           13  * details.
           14  *
           15  * You should have received a copy of the GNU General Public License
           16  * along with PISM; if not, write to the Free Software
           17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
           18  */
           19 
           20 #ifndef _FIELD_H_
           21 #define _FIELD_H_
           22 
           23 namespace pism {
           24 
           25 class Field {
           26 protected:
           27   Field(IceGrid::ConstPtr g, const std::string &name);
           28 public:
           29   virtual ~Field();
           30   // metadata
           31   std::string name() const;
           32   void set_name(const std::string &name, int component = 0);
           33   void set_units(const std::string &units, const std::string &external_units);
           34 
           35   SpatialVariableMetadata& metadata(unsigned int N = 0);
           36   const SpatialVariableMetadata& metadata(unsigned int N = 0) const;
           37 
           38   void set_attrs(const std::string &my_pism_intent, const std::string &my_long_name,
           39                  const std::string &my_units, const std::string &my_standard_name,
           40                  int component = 0);
           41   void read_attrs(const std::string &filename, int component = 0);
           42 
           43   // input and output
           44   void define(const File &nc, IO_Type output_datatype) const;
           45 
           46   void read(const std::string &filename, unsigned int time);
           47   void read(const File &nc, unsigned int time);
           48 
           49   void write(const std::string &filename, IO_Type nctype = PISM_DOUBLE) const;
           50   void write(const File &nc, IO_Type nctype = PISM_DOUBLE) const;
           51 
           52   void regrid(const std::string &filename, RegriddingFlag flag,
           53               double default_value = 0.0);
           54   void regrid(const File &nc, RegriddingFlag flag,
           55               double default_value = 0.0);
           56 
           57   // in-place modification
           58   void scale(double alpha);
           59 
           60   // low-level access
           61   Vec get_vec();
           62   PISMDM::Ptr get_dm() const;
           63   void copy_to_vec(PISMDM::Ptr destination_da, Vec destination) const;
           64   void copy_from_vec(Vec source);
           65 
           66   // point-wise access
           67   void begin_access() const;
           68   void end_access() const;
           69 
           70   // miscellaneous
           71   int modification_counter() const;
           72   int modified();
           73   void set_time_independent(bool value);
           74 
           75   // debugging
           76   void dump(const char filename[]) const;
           77 protected:
           78   void get_dof(PISMDM::Ptr da_result, Vec result, unsigned int n,
           79                unsigned int count=1) const;
           80   void set_dof(PISMDM::Ptr da_source, Vec source, unsigned int n,
           81                unsigned int count=1);
           82   void check_array_indices(int i, int j, unsigned int k) const;
           83 
           84   std::string m_name;
           85   Vec m_v;
           86   IceGrid::ConstPtr m_grid;
           87   mutable void *m_array;
           88   PISMDM::Ptr m_da;          //!< distributed mesh manager (DM)
           89   unsigned int m_dof;
           90 
           91   //! stores metadata (NetCDF variable attributes)
           92   std::vector<SpatialVariableMetadata> m_metadata;
           93   std::string m_name;
           94 private:
           95   mutable int m_access_counter;
           96   int m_modification_counter;
           97 
           98   // disable copy constructor and the assignment operator
           99   Field(const Field &);
          100   Field& operator=(const Field &);
          101 
          102 public:
          103   //! Makes sure that we call begin_access() and end_access() for all accessed IceModelVecs.
          104   class AccessList {
          105   public:
          106     AccessList();
          107     AccessList(const IceModelVec &v);
          108     ~AccessList();
          109     void add(const IceModelVec &v);
          110   private:
          111     std::vector<const Field*> m_fields;
          112   };
          113 };
          114 
          115 class GhostedField : virtual public Field {
          116 public:
          117   GhostedField(IceGrid::ConstPtr grid, const std::string &name, unsigned int stencil_width);
          118   virtual ~GhostedField();
          119   unsigned int stencil_width() const;
          120   void update_ghosts();
          121 protected:
          122   unsigned int m_stencil_width;
          123   void scatter_to(Vec output) const;
          124 };
          125 
          126 class ScalarField : virtual public Field {
          127 public:
          128   struct Range {
          129     double min, max;
          130   };
          131   ScalarField(IceGrid::ConstPtr grid, const std::string &name);
          132   virtual ~ScalarField();
          133   void set(double value);
          134   void shift(double amount);
          135   void squareroot();
          136   Range range() const;
          137 };
          138 
          139 class GhostedScalar2DField;
          140 class Scalar2DField : virtual public ScalarField {
          141 public:
          142   Scalar2DField(IceGrid::ConstPtr grid,  const std::string &name);
          143   virtual ~Scalar2DField();
          144   void copy_from(const Scalar2DField &input);
          145   void scatter_to_ghosted(GhostedScalar2DField &output) const;
          146   inline double& operator()(int i, int j);
          147   inline const double& operator()(int i, int j) const;
          148 };
          149 
          150 // finite differences
          151 namespace FD {
          152 inline double diff_x(const Scalar2DField &field, int i, int j) const;
          153 inline double diff_y(const Scalar2DField &field, int i, int j) const;
          154 inline double diff_x_p(const Scalar2DField &field, int i, int j) const;
          155 inline double diff_y_p(const Scalar2DField &field, int i, int j) const;
          156 }
          157 
          158 class GhostedScalar3DField;
          159 class Scalar3DField : virtual public ScalarField {
          160 public:
          161   Scalar3DField(IceGrid::ConstPtr grid,  const std::string &name,
          162                 const std::vector<double> &levels);
          163   virtual ~Scalar3DField();
          164   void copy_from(const Scalar3DField &input);
          165   void scatter_to_ghosted(GhostedScalar3DField &output) const;
          166   inline double& operator()(int i, int j, unsigned int k);
          167   inline const double& operator()(int i, int j, unsigned int k) const;
          168 protected:
          169   std::vector<double> m_levels;
          170 };
          171 
          172 } // end of namespace pism
          173 
          174 #endif /* _FIELD_H_ */