[25125] | 1 | import numpy as np
|
---|
[25758] | 2 |
|
---|
[25125] | 3 | from checkfield import checkfield
|
---|
| 4 | from fielddisplay import fielddisplay
|
---|
[25153] | 5 | from lovenumbers import lovenumbers
|
---|
[25125] | 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):
|
---|
[25688] | 15 | """SOLIDEARTH class definition
|
---|
[25125] | 16 |
|
---|
[25688] | 17 | Usage:
|
---|
| 18 | solidearth = solidearth()
|
---|
| 19 | """
|
---|
[25125] | 20 |
|
---|
[25153] | 21 | def __init__(self, *args): #{{{
|
---|
[25764] | 22 | self.initialsealevel = np.nan
|
---|
[25758] | 23 | self.settings = solidearthsettings()
|
---|
[25764] | 24 | self.external = []
|
---|
[25758] | 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 = []
|
---|
[25125] | 33 |
|
---|
[25767] | 34 | nargs = len(args)
|
---|
[25125] | 35 |
|
---|
[25767] | 36 | if nargs == 0:
|
---|
| 37 | self.setdefaultparameters('earth')
|
---|
| 38 | elif nargs == 1:
|
---|
| 39 | self.setdefaultparameters(args[0])
|
---|
[25125] | 40 | else:
|
---|
[25767] | 41 | raise Exception('solidearth constructor error message: zero or one argument only!')
|
---|
[25125] | 42 | #}}}
|
---|
| 43 |
|
---|
[25153] | 44 | def __repr__(self): # {{{
|
---|
[25125] | 45 | s = ' solidearthinputs, forcings and settings:\n'
|
---|
[25764] | 46 | s += '{}\n'.format(fielddisplay(self, 'initialsealevel', 'sea level at the start of computation [m]'))
|
---|
[25125] | 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'))
|
---|
[25764] | 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)
|
---|
[25125] | 60 | return s
|
---|
| 61 | #}}}
|
---|
| 62 |
|
---|
[25767] | 63 | def setdefaultparameters(self, planet): # {{{
|
---|
[25758] | 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 |
|
---|
[25764] | 74 | # No external solutions by defalt
|
---|
| 75 | self.external = []
|
---|
| 76 |
|
---|
[25758] | 77 | # Earth radius
|
---|
[25767] | 78 | self.planetradius = planetradius(planet)
|
---|
[25125] | 79 | #}}}
|
---|
| 80 |
|
---|
[25153] | 81 | def checkconsistency(self, md, solution, analyses): # {{{
|
---|
[25688] | 82 | if ('SealevelriseAnalysis' not in analyses) or (solution == 'TransientSolution' and not md.transient.isslr):
|
---|
[25125] | 83 | return md
|
---|
[25764] | 84 | md = checkfield(md, 'fieldname', 'solidearth.initialsealevel', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofvertices])
|
---|
[25125] | 85 | md = checkfield(md, 'fieldname', 'solidearth.requested_outputs', 'stringrow', 1)
|
---|
[25758] | 86 |
|
---|
[25125] | 87 | self.settings.checkconsistency(md, solution, analyses)
|
---|
| 88 | self.surfaceload.checkconsistency(md, solution, analyses)
|
---|
[25169] | 89 | self.lovenumbers.checkconsistency(md, solution, analyses)
|
---|
[25125] | 90 | self.rotational.checkconsistency(md, solution, analyses)
|
---|
[25764] | 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)
|
---|
[25125] | 96 | return md
|
---|
| 97 | #}}}
|
---|
| 98 |
|
---|
[25153] | 99 | def defaultoutputs(self, md): #{{{
|
---|
[25125] | 100 | return ['Sealevel']
|
---|
| 101 | #}}}
|
---|
| 102 |
|
---|
[25153] | 103 | def marshall(self, prefix, md, fid): #{{{
|
---|
[25764] | 104 | WriteData(fid, prefix, 'object', self, 'fieldname', 'initialsealevel', 'mattype', 1, 'format', 'DoubleMat', 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', md.constants.yts)
|
---|
[25125] | 105 | WriteData(fid, prefix, 'object', self, 'fieldname', 'planetradius', 'format', 'Double')
|
---|
| 106 | WriteData(fid, prefix, 'object', self, 'fieldname', 'transitions', 'format', 'MatArray')
|
---|
| 107 |
|
---|
[25758] | 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 |
|
---|
[25125] | 123 | self.settings.marshall(prefix, md, fid)
|
---|
| 124 | self.surfaceload.marshall(prefix, md, fid)
|
---|
[25169] | 125 | self.lovenumbers.marshall(prefix, md, fid)
|
---|
[25125] | 126 | self.rotational.marshall(prefix, md, fid)
|
---|
[25764] | 127 | if self.external:
|
---|
| 128 | self.external.marshall(prefix, md, fid)
|
---|
[25125] | 129 |
|
---|
| 130 | #process requested outputs
|
---|
| 131 | outputs = self.requested_outputs
|
---|
| 132 | pos = np.where(np.asarray(outputs) == 'default')[0]
|
---|
[25161] | 133 | if len(pos):
|
---|
[25450] | 134 | outputs = np.delete(outputs, pos) #remove 'default' from outputs
|
---|
| 135 | outputs = np.append(outputs, self.defaultoutputs(md)) #add defaults
|
---|
[25125] | 136 | WriteData(fid, prefix, 'data', outputs, 'name', 'md.solidearth.requested_outputs', 'format', 'StringArray')
|
---|
| 137 | #}}}
|
---|
| 138 |
|
---|
[25688] | 139 | def extrude(self, md): #{{{
|
---|
[25764] | 140 | self.initialsealevel = project3d(md, 'vector', self.initialsealevel, 'type', 'node')
|
---|
[25125] | 141 | return self
|
---|
| 142 | #}}}
|
---|