IceModelVec2T Class Reference

#include <iceModelVec2T.hh>

Inheritance diagram for IceModelVec2T:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 IceModelVec2T ()
 IceModelVec2T (const IceModelVec2T &other)
virtual void set_n_records (unsigned int N)
 Sets the number of records to store in memory. Call it before calling create().
virtual PetscErrorCode create (IceGrid &mygrid, const char my_short_name[], bool local, int width=1)
virtual PetscErrorCode init (string filename)
virtual PetscErrorCode update (double t_years, double dt_years)
 Read some data to make sure that the interval (t_years, t_years + dt_years) is covered.
virtual PetscErrorCode set_record (int n)
 Sets the record number n to the contents of the (internal) Vec v.
virtual PetscErrorCode get_record (int n)
 Sets the (internal) Vec v to the contents of the nth record.
virtual double max_timestep (double t_years)
 Given the time t_years and the current selected time-step dt_years, determines the maximum possible time-step this IceModelVec2T allows.
virtual PetscErrorCode interp (double t_years)
 Extract data corresponding to t_years using linear interpolation.
virtual PetscErrorCode interp (int i, int j, int N, PetscScalar *times, PetscScalar *results)
 Gets an interpolated time-series out. Has to be surrounded with begin_access() and end_access().
virtual PetscErrorCode average (int i, int j, double t_years, double dt_years, double &result)
 Finds the average value at i,j over the interval (t_years, t_years + dt_years) using trapezoidal rule.
virtual PetscErrorCode begin_access ()
 Checks if an IceModelVec is allocated and calls DAVecGetArray.
virtual PetscErrorCode end_access ()
 Checks if an IceModelVec is allocated and calls DAVecRestoreArray.

Protected Member Functions

virtual PetscErrorCode destroy ()
virtual PetscErrorCode get_array3 (PetscScalar ***&a3)
virtual PetscErrorCode update (int start)
 Update by reading at most n_records records from the file.
virtual PetscErrorCode discard (int N)
 Discard the first N records, shifting the rest of them towards the "beginning".

Protected Attributes

vector< doubletimes
 all the times available in filename
vector< doubleT
 times stored in memory
string filename
 file to read (regrid) from
LocalInterpCtxlic
DA da3
Vec v3
 a 3D Vec used to store records
void *** array3
int n_records
 maximum number of records to store in memory
int first
 in-file index of the first record stored in memory

Detailed Description

A class for storing and accessing 2D time-series (for climate forcing)

This class was created to read time-dependent and spatially-varying climate forcing data, in particular snow temperatures and precipitation.

It allocates a number (given as an argument to the create() method) of records and reads them from a file if necessary.

If requests (calls to update()) go in sequence, every records should be read only once.

Note that this class is optimized for use with a PDD scheme -- it stores records so that data corresponding to a grid point are stored in adjacent memory locations.

IceModelVec2T is always global (i.e. has no ghosts).

Both versions of interp() use linear interpolation and extrapolate (by a constant) outside the available range.

Usage example:

  // initialization:
  char filename[] = "climate_inputs.nc";
  IceModelVec2T v;
  v.set_n_records(config.get("climate_forcing_buffer_size"));
  ierr = v.create(grid, "snowtemp", false); CHKERRQ(ierr);
  ierr = v.set_attrs("climate_forcing", "snow surface temperature", "K", ""); CHKERRQ(ierr);
  ierr = v.init(filename); CHKERRQ(ierr);

  // actual use:

  // ask it how long a time-step is possible:
  double t = 0, max_dt = 1e16;
  ierr = v.max_timestep(t, max_dt); CHKERRQ(ierr);

  // update (this might read more data from the file)
  ierr = v.update(t, max_dt); CHKERRQ(ierr);

  // get a 2D field (such as precipitation):
  ierr = v.interp(t + max_dt / 2.0); CHKERRQ(ierr);
  // at this point v "looks" almost like an IceModelVec2S with data we need (and
  // can be type-cast to IceModelVec2S)

  // get a time-series for every grid location:
  int N = 21;
  vector<double> ts(N), values(N);
  double dt = max_dt / (N - 1);

  for (int j = 0; j < N; ++j) {
    ts[j] = t + dt * j;
  }

  // is is OK to call update() again, it will not re-read data if at all possible
  ierr = v.update(t, max_dt); CHKERRQ(ierr);

  ierr = v.begin_access(); CHKERRQ(ierr);
  for (PetscInt i=grid->xs; i<grid->xs+grid->xm; ++i)
    for (PetscInt j=grid->ys; j<grid->ys+grid->ym; ++j) {
      ierr = v.interp(i, j, N, &ts[0], &values[0]); CHKERRQ(ierr);
      // do more
    }
  ierr = v.end_access(); CHKERRQ(ierr);

  // compute an average value over a time interval at a certain grid location:

  double average;
  ierr = v.begin_access(); CHKERRQ(ierr);
  ierr = v.average(grid.xs, grid.ys, t, max_dt, average); CHKERRQ(ierr);
  ierr = v.end_access(); CHKERRQ(ierr);

Definition at line 106 of file iceModelVec2T.hh.


Constructor & Destructor Documentation

IceModelVec2T (  ) 

Definition at line 25 of file iceModelVec2T.cc.

References array3, da3, first, lic, IceModelVec.localp, n_records, T, and v3.

IceModelVec2T ( const IceModelVec2T other  ) 

Definition at line 36 of file iceModelVec2T.cc.

References array3, da3, filename, first, lic, IceModelVec.localp, n_records, IceModelVec.shallow_copy, T, times, and v3.


Member Function Documentation

PetscErrorCode average ( int  i,
int  j,
double  t_years,
double  dt_years,
double result 
) [virtual]

Finds the average value at i,j over the interval (t_years, t_years + dt_years) using trapezoidal rule.

Can (and should) be optimized. Later, though.

Definition at line 388 of file iceModelVec2T.cc.

References interp(), and vfnow.N.

Referenced by PAForcing.mean_precip(), and IceUnitModel.test_IceModelVec2T().

PetscErrorCode begin_access (  )  [virtual]

Checks if an IceModelVec is allocated and calls DAVecGetArray.

Reimplemented from IceModelVec.

Definition at line 105 of file iceModelVec2T.cc.

References array3, da3, and v3.

Referenced by PAForcing.begin_pointwise_access(), get_array3(), PAForcing.mean_precip(), and IceUnitModel.test_IceModelVec2T().

PetscErrorCode create ( IceGrid mygrid,
const char  my_short_name[],
bool  local,
int  width = 1 
) [virtual]
PetscErrorCode destroy (  )  [protected, virtual]

Reimplemented from IceModelVec.

Definition at line 79 of file iceModelVec2T.cc.

References da3, lic, and v3.

PetscErrorCode discard ( int  N  )  [protected, virtual]

Discard the first N records, shifting the rest of them towards the "beginning".

Definition at line 230 of file iceModelVec2T.cc.

References end_access(), IceModelVec2S.get_array(), get_array3(), IceModelVec.grid, nc2cdo.M, T, IceGrid.xm, IceGrid.xs, IceGrid.ym, and IceGrid.ys.

Referenced by update().

PetscErrorCode end_access (  )  [virtual]

Checks if an IceModelVec is allocated and calls DAVecRestoreArray.

Reimplemented from IceModelVec.

Definition at line 113 of file iceModelVec2T.cc.

References array3, da3, and v3.

Referenced by discard(), PAForcing.end_pointwise_access(), get_record(), interp(), PAForcing.mean_precip(), set_record(), and IceUnitModel.test_IceModelVec2T().

PetscErrorCode get_array3 ( PetscScalar ***&  a3  )  [protected, virtual]

Definition at line 98 of file iceModelVec2T.cc.

References array3, and begin_access().

Referenced by discard(), get_record(), interp(), and set_record().

PetscErrorCode get_record ( int  n  )  [virtual]

Sets the (internal) Vec v to the contents of the nth record.

Definition at line 266 of file iceModelVec2T.cc.

References end_access(), IceModelVec2S.get_array(), get_array3(), IceModelVec.grid, IceGrid.xm, IceGrid.xs, IceGrid.ym, and IceGrid.ys.

Referenced by interp().

PetscErrorCode init ( string  filename  )  [virtual]
PetscErrorCode interp ( int  i,
int  j,
int  N,
PetscScalar *  ts,
PetscScalar *  values 
) [virtual]

Gets an interpolated time-series out. Has to be surrounded with begin_access() and end_access().

Note: this method does not check ownership and does not check if an update() call is necessary!

Definition at line 354 of file iceModelVec2T.cc.

References array3, and T.

PetscErrorCode interp ( double  t_years  )  [virtual]

Extract data corresponding to t_years using linear interpolation.

Note: this method does not check if an update() call is necessary!

Definition at line 318 of file iceModelVec2T.cc.

References end_access(), IceModelVec2S.get_array(), get_array3(), get_record(), IceModelVec.grid, T, IceGrid.xm, IceGrid.xs, IceGrid.ym, and IceGrid.ys.

Referenced by average(), PAForcing.mean_annual_temp(), PAForcing.temp_snapshot(), PAForcing.temp_time_series(), IceUnitModel.test_IceModelVec2T(), PAForcing.write_diagnostic_fields(), and PAForcing.write_fields().

double max_timestep ( double  t_years  )  [virtual]

Given the time t_years and the current selected time-step dt_years, determines the maximum possible time-step this IceModelVec2T allows.

Returns -1 if any time step is OK at t_years.

Definition at line 285 of file iceModelVec2T.cc.

References vfnow.N, n_records, and times.

Referenced by PAForcing.max_timestep(), and IceUnitModel.test_IceModelVec2T().

void set_n_records ( unsigned int  N  )  [virtual]

Sets the number of records to store in memory. Call it before calling create().

Definition at line 52 of file iceModelVec2T.cc.

References n_records.

Referenced by PAForcing.init(), and IceUnitModel.test_IceModelVec2T().

PetscErrorCode set_record ( int  n  )  [virtual]

Sets the record number n to the contents of the (internal) Vec v.

Definition at line 251 of file iceModelVec2T.cc.

References end_access(), IceModelVec2S.get_array(), get_array3(), IceModelVec.grid, IceGrid.xm, IceGrid.xs, IceGrid.ym, and IceGrid.ys.

Referenced by update().

PetscErrorCode update ( int  start  )  [protected, virtual]
PetscErrorCode update ( double  t_years,
double  dt_years 
) [virtual]

Read some data to make sure that the interval (t_years, t_years + dt_years) is covered.

Definition at line 158 of file iceModelVec2T.cc.

References vfnow.N, n_records, T, and times.

Referenced by PAForcing.mean_annual_temp(), PAForcing.mean_precip(), PAForcing.temp_snapshot(), IceUnitModel.test_IceModelVec2T(), PAForcing.update(), PAForcing.write_diagnostic_fields(), and PAForcing.write_fields().


Member Data Documentation

void*** array3 [protected]

Definition at line 139 of file iceModelVec2T.hh.

Referenced by begin_access(), end_access(), get_array3(), IceModelVec2T(), and interp().

DA da3 [protected]

Definition at line 137 of file iceModelVec2T.hh.

Referenced by begin_access(), create(), destroy(), end_access(), and IceModelVec2T().

string filename [protected]

file to read (regrid) from

Definition at line 134 of file iceModelVec2T.hh.

Referenced by IceModelVec2T(), init(), and update().

int first [protected]

in-file index of the first record stored in memory

Definition at line 140 of file iceModelVec2T.hh.

Referenced by IceModelVec2T(), and update().

LocalInterpCtx* lic [protected]

We store the context because we might need to regrid many times

Definition at line 135 of file iceModelVec2T.hh.

Referenced by destroy(), IceModelVec2T(), init(), and update().

int n_records [protected]

maximum number of records to store in memory

Definition at line 140 of file iceModelVec2T.hh.

Referenced by create(), IceModelVec2T(), max_timestep(), set_n_records(), and update().

vector<double> T [protected]

times stored in memory

Definition at line 132 of file iceModelVec2T.hh.

Referenced by discard(), IceModelVec2T(), interp(), and update().

vector<double> times [protected]

all the times available in filename

Definition at line 132 of file iceModelVec2T.hh.

Referenced by IceModelVec2T(), init(), max_timestep(), and update().

Vec v3 [protected]

a 3D Vec used to store records

Definition at line 138 of file iceModelVec2T.hh.

Referenced by begin_access(), create(), destroy(), end_access(), and IceModelVec2T().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines
Generated by  doxygen 1.6.2-20100124