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