| 1 | import numpy as np
|
|---|
| 2 | from checkfield import checkfield
|
|---|
| 3 | from fielddisplay import fielddisplay
|
|---|
| 4 | from lovenumbers import lovenumbers
|
|---|
| 5 | from MatlabFuncs import *
|
|---|
| 6 | from planetradius import planetradius
|
|---|
| 7 | from rotational import rotational
|
|---|
| 8 | from solidearthsettings import solidearthsettings
|
|---|
| 9 | from solidearthsolution import solidearthsolution
|
|---|
| 10 | from WriteData import WriteData
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | class solidearth(object):
|
|---|
| 14 | """SOLIDEARTH class definition
|
|---|
| 15 |
|
|---|
| 16 | Usage:
|
|---|
| 17 | solidearth = solidearth()
|
|---|
| 18 | solidearth = solidearth('earth')
|
|---|
| 19 |
|
|---|
| 20 | TODO:
|
|---|
| 21 | - Update translation from solidearth.m
|
|---|
| 22 | """
|
|---|
| 23 |
|
|---|
| 24 | def __init__(self, *args): # {{{
|
|---|
| 25 | self.settings = solidearthsettings()
|
|---|
| 26 | self.external = None
|
|---|
| 27 | self.lovenumbers = lovenumbers()
|
|---|
| 28 | self.rotational = rotational()
|
|---|
| 29 | self.planetradius = planetradius('earth')
|
|---|
| 30 | self.requested_outputs = []
|
|---|
| 31 | self.transfercount = []
|
|---|
| 32 | self.transitions = []
|
|---|
| 33 | self.partitionice = []
|
|---|
| 34 | self.partitionhydro = []
|
|---|
| 35 | self.partitionocean = []
|
|---|
| 36 |
|
|---|
| 37 | nargs = len(args)
|
|---|
| 38 | if nargs == 0:
|
|---|
| 39 | self.setdefaultparameters('earth')
|
|---|
| 40 | elif nargs == 1:
|
|---|
| 41 | self.setdefaultparameters(args[0])
|
|---|
| 42 | else:
|
|---|
| 43 | raise Exception('solidearth constructor error message: zero or one argument only!')
|
|---|
| 44 | # }}}
|
|---|
| 45 |
|
|---|
| 46 | def __repr__(self): # {{{
|
|---|
| 47 | s = ' solidearthinputs, forcings and settings:\n'
|
|---|
| 48 | s += '{}\n'.format(fielddisplay(self, 'planetradius', 'planet radius [m]'))
|
|---|
| 49 | s += '{}\n'.format(fielddisplay(self, 'transitions', 'indices into parts of the mesh that will be icecaps'))
|
|---|
| 50 | s += '{}\n'.format(fielddisplay(self, 'transfercount', 'number of icecaps vertices are part of'))
|
|---|
| 51 | s += '{}\n'.format(fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
|
|---|
| 52 | s += '{}\n'.format(fielddisplay(self, 'partitionice', 'ice partition vector for barystatic contribution'))
|
|---|
| 53 | s += '{}\n'.format(fielddisplay(self, 'partitionhydro', 'hydro partition vector for barystatic contribution'))
|
|---|
| 54 | s += '{}\n'.format(fielddisplay(self, 'partitionocean', 'ocean partition vector for barystatic contribution'))
|
|---|
| 55 | if not self.external:
|
|---|
| 56 | s += '{}\n'.format(fielddisplay(self, 'external', 'external solution, of the type solidearthsolution'))
|
|---|
| 57 | print(self.settings)
|
|---|
| 58 | print(self.lovenumbers)
|
|---|
| 59 | print(self.rotational)
|
|---|
| 60 | try:
|
|---|
| 61 | print(self.external)
|
|---|
| 62 | except TypeError:
|
|---|
| 63 | pass
|
|---|
| 64 | return s
|
|---|
| 65 | # }}}
|
|---|
| 66 |
|
|---|
| 67 | def setdefaultparameters(self, planet): # {{{
|
|---|
| 68 | # Output default
|
|---|
| 69 | self.requested_outputs = ['default']
|
|---|
| 70 |
|
|---|
| 71 | # Transitions should be a list
|
|---|
| 72 | self.transitions = []
|
|---|
| 73 | self.transfercount = [0]
|
|---|
| 74 |
|
|---|
| 75 | # No partitions requested for barystatic contribution
|
|---|
| 76 | self.partitionice = []
|
|---|
| 77 | self.partitionhydro = []
|
|---|
| 78 | self.partitionocean = []
|
|---|
| 79 |
|
|---|
| 80 | # No external solutions by default
|
|---|
| 81 | self.external = None
|
|---|
| 82 |
|
|---|
| 83 | # Planet radius
|
|---|
| 84 | self.planetradius = planetradius(planet)
|
|---|
| 85 | # }}}
|
|---|
| 86 |
|
|---|
| 87 | def checkconsistency(self, md, solution, analyses): # {{{
|
|---|
| 88 | if ('SealevelchangeAnalysis' not in analyses) or (solution == 'TransientSolution' and not md.transient.isslc):
|
|---|
| 89 | return md
|
|---|
| 90 |
|
|---|
| 91 | md = checkfield(md, 'fieldname', 'solidearth.requested_outputs', 'stringrow', 1)
|
|---|
| 92 |
|
|---|
| 93 | self.settings.checkconsistency(md, solution, analyses)
|
|---|
| 94 | self.lovenumbers.checkconsistency(md, solution, analyses)
|
|---|
| 95 | self.rotational.checkconsistency(md, solution, analyses)
|
|---|
| 96 | if self.external:
|
|---|
| 97 | if not isa(self.external, solidearthsolution):
|
|---|
| 98 | raise Exception('solidearth consistency check: external field should be a solidearthsolution')
|
|---|
| 99 | self.external.checkconsistency(md, solution, analyses)
|
|---|
| 100 | return md
|
|---|
| 101 | # }}}
|
|---|
| 102 |
|
|---|
| 103 | def defaultoutputs(self, md): # {{{
|
|---|
| 104 | return ['Sealevel']
|
|---|
| 105 | # }}}
|
|---|
| 106 |
|
|---|
| 107 | def marshall(self, prefix, md, fid): # {{{
|
|---|
| 108 | WriteData(fid, prefix, 'object', self, 'fieldname', 'planetradius', 'format', 'Double')
|
|---|
| 109 | WriteData(fid, prefix, 'object', self, 'fieldname', 'transitions', 'format', 'MatArray')
|
|---|
| 110 | WriteData(fid, prefix, 'object', self, 'fieldname', 'transfercount', 'format', 'DoubleMat', 'mattype', 1)
|
|---|
| 111 |
|
|---|
| 112 | if len(self.partitionice):
|
|---|
| 113 | npartice = np.max(self.partitionice) + 2
|
|---|
| 114 | else:
|
|---|
| 115 | npartice = 0
|
|---|
| 116 |
|
|---|
| 117 | if len(self.partitionhydro):
|
|---|
| 118 | nparthydro = np.max(self.partitionhydro) + 2
|
|---|
| 119 | else:
|
|---|
| 120 | nparthydro = 0
|
|---|
| 121 |
|
|---|
| 122 | if len(self.partitionocean):
|
|---|
| 123 | npartocean = np.max(self.partitionocean) + 2
|
|---|
| 124 | else:
|
|---|
| 125 | npartocean = 0
|
|---|
| 126 |
|
|---|
| 127 | WriteData(fid, prefix, 'object', self, 'fieldname', 'partitionice', 'mattype', 1, 'format', 'DoubleMat');
|
|---|
| 128 | WriteData(fid, prefix, 'data', npartice, 'format', 'Integer', 'name', 'md.solidearth.npartice');
|
|---|
| 129 | WriteData(fid, prefix, 'object', self, 'fieldname', 'partitionhydro', 'mattype', 1, 'format', 'DoubleMat');
|
|---|
| 130 | WriteData(fid, prefix, 'data', nparthydro,'format', 'Integer', 'name','md.solidearth.nparthydro');
|
|---|
| 131 | WriteData(fid, prefix, 'object', self, 'fieldname', 'partitionocean', 'mattype', 1, 'format', 'DoubleMat');
|
|---|
| 132 | WriteData(fid, prefix, 'data', npartocean,'format', 'Integer', 'name','md.solidearth.npartocean');
|
|---|
| 133 |
|
|---|
| 134 | self.settings.marshall(prefix, md, fid)
|
|---|
| 135 | self.lovenumbers.marshall(prefix, md, fid)
|
|---|
| 136 | self.rotational.marshall(prefix, md, fid)
|
|---|
| 137 | if self.external:
|
|---|
| 138 | WriteData(fid, prefix, 'data', 1, 'format', 'Integer', 'name', 'md.solidearth.isexternal')
|
|---|
| 139 | self.external.marshall(prefix, md, fid)
|
|---|
| 140 | else:
|
|---|
| 141 | WriteData(fid, prefix, 'data', 0, 'format', 'Integer', 'name', 'md.solidearth.isexternal')
|
|---|
| 142 |
|
|---|
| 143 | # Process requested outputs
|
|---|
| 144 | outputs = self.requested_outputs
|
|---|
| 145 | pos = np.where(np.asarray(outputs) == 'default')[0]
|
|---|
| 146 | if len(pos):
|
|---|
| 147 | outputs = np.delete(outputs, pos) # remove 'default' from outputs
|
|---|
| 148 | outputs = np.append(outputs, self.defaultoutputs(md)) # add defaults
|
|---|
| 149 | WriteData(fid, prefix, 'data', outputs, 'name', 'md.solidearth.requested_outputs', 'format', 'StringArray')
|
|---|
| 150 | # }}}
|
|---|
| 151 |
|
|---|
| 152 | def extrude(self, md): # {{{
|
|---|
| 153 | return self
|
|---|
| 154 | # }}}
|
|---|