| 1 | # -*- coding: utf-8 -*-
|
|---|
| 2 |
|
|---|
| 3 | import numpy as np
|
|---|
| 4 |
|
|---|
| 5 | from checkfield import checkfield
|
|---|
| 6 | from WriteData import WriteData
|
|---|
| 7 | from fielddisplay import fielddisplay
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | class frontalforcingsrignot(object):
|
|---|
| 11 | """FRONTALFORCINGSRIGNOT class definition
|
|---|
| 12 |
|
|---|
| 13 | Usage:
|
|---|
| 14 | frontalforcingsrignot = frontalforcingsrignot()
|
|---|
| 15 | """
|
|---|
| 16 |
|
|---|
| 17 | def __init__(self, *args): # {{{
|
|---|
| 18 | self.basin_id = np.nan
|
|---|
| 19 | self.num_basins = 0
|
|---|
| 20 | self.subglacial_discharge = np.nan
|
|---|
| 21 | self.thermalforcing = np.nan
|
|---|
| 22 |
|
|---|
| 23 | if len(args) == 0:
|
|---|
| 24 | self.setdefaultparameters()
|
|---|
| 25 | else:
|
|---|
| 26 | error('constructor not supported')
|
|---|
| 27 |
|
|---|
| 28 | # }}}
|
|---|
| 29 |
|
|---|
| 30 | def __repr__(self): # {{{
|
|---|
| 31 | s = ' Frontalforcings parameters:\n'
|
|---|
| 32 | s += '{}\n'.format(fielddisplay(self, 'basin_id', 'basin ID for elements'))
|
|---|
| 33 | s += '{}\n'.format(fielddisplay(self, 'num_basins', 'number of basins'))
|
|---|
| 34 | s += '{}\n'.format(fielddisplay(self, 'subglacial_discharge', 'sum of subglacial discharge for each basin [m/d]'))
|
|---|
| 35 | s += '{}\n'.format(fielddisplay(self, 'thermalforcing', 'thermal forcing [∘C]'))
|
|---|
| 36 | return s
|
|---|
| 37 | # }}}
|
|---|
| 38 |
|
|---|
| 39 | def setdefaultparameters(self): # {{{
|
|---|
| 40 | self.basin_id = np.nan
|
|---|
| 41 | self.num_basins = 0
|
|---|
| 42 | self.subglacial_discharge = np.nan
|
|---|
| 43 | self.thermalforcing = np.nan
|
|---|
| 44 |
|
|---|
| 45 | return self
|
|---|
| 46 | # }}}
|
|---|
| 47 |
|
|---|
| 48 | def extrude(self, md): # {{{
|
|---|
| 49 | return self
|
|---|
| 50 | # }}}
|
|---|
| 51 |
|
|---|
| 52 | def checkconsistency(self, md, solution, analyses): # {{{
|
|---|
| 53 | # Early return
|
|---|
| 54 | if (solution != 'TransientSolution') or (not md.transient.ismovingfront):
|
|---|
| 55 | return md
|
|---|
| 56 |
|
|---|
| 57 | md = checkfield(md, 'fieldname', 'frontalforcings.num_basins', 'numel', [1], 'NaN', 1, 'Inf', 1, '>', 0)
|
|---|
| 58 | md = checkfield(md, 'fieldname', 'frontalforcings.basin_id', 'Inf', 1, '>=', 0, '<=', md.frontalforcings.num_basins, 'size', [md.mesh.numberofelements])
|
|---|
| 59 | md = checkfield(md, 'fieldname', 'frontalforcings.subglacial_discharge', '>=', 0, 'NaN', 1, 'Inf', 1, 'timeseries', 1)
|
|---|
| 60 | md = checkfield(md, 'fieldname', 'frontalforcings.thermalforcing', 'NaN', 1, 'Inf', 1, 'timeseries', 1)
|
|---|
| 61 | return md
|
|---|
| 62 | # }}}
|
|---|
| 63 |
|
|---|
| 64 | def marshall(self, prefix, md, fid): # {{{
|
|---|
| 65 | WriteData(fid, prefix, 'name', 'md.frontalforcings.parameterization', 'data', 2, 'format', 'Integer')
|
|---|
| 66 | WriteData(fid, prefix, 'object', self, 'fieldname', 'basin_id', 'data', self.basin_id - 1, 'name', 'md.frontalforcings.basin_id', 'format', 'IntMat', 'mattype', 2) # 0-indexed
|
|---|
| 67 | WriteData(fid, prefix, 'object', self, 'fieldname', 'num_basins', 'format', 'Integer')
|
|---|
| 68 | WriteData(fid, prefix, 'object', self, 'fieldname', 'subglacial_discharge', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts)
|
|---|
| 69 | WriteData(fid, prefix, 'object', self, 'fieldname', 'thermalforcing', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts)
|
|---|
| 70 | # }}}
|
|---|