source: issm/trunk/src/m/classes/solidearth.py@ 27035

Last change on this file since 27035 was 27035, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 27033

File size: 5.9 KB
Line 
1import numpy as np
2from checkfield import checkfield
3from fielddisplay import fielddisplay
4from lovenumbers import lovenumbers
5from MatlabFuncs import *
6from planetradius import planetradius
7from rotational import rotational
8from solidearthsettings import solidearthsettings
9from solidearthsolution import solidearthsolution
10from WriteData import WriteData
11
12
13class 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.transitions = []
32 self.partitionice = []
33 self.partitionhydro = []
34 self.partitionocean = []
35
36 nargs = len(args)
37 if nargs == 0:
38 self.setdefaultparameters('earth')
39 elif nargs == 1:
40 self.setdefaultparameters(args[0])
41 else:
42 raise Exception('solidearth constructor error message: zero or one argument only!')
43 # }}}
44
45 def __repr__(self): # {{{
46 s = ' solidearthinputs, forcings and settings:\n'
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 s += '{}\n'.format(fielddisplay(self, 'partitionocean', 'ocean partition vector for barystatic contribution'))
53 if not self.external:
54 s += '{}\n'.format(fielddisplay(self, 'external', 'external solution, of the type solidearthsolution'))
55 print(self.settings)
56 print(self.lovenumbers)
57 print(self.rotational)
58 try:
59 print(self.external)
60 except TypeError:
61 pass
62 return s
63 # }}}
64
65 def setdefaultparameters(self, planet): # {{{
66 # Output default
67 self.requested_outputs = ['default']
68
69 # Transitions should be a list
70 self.transitions = []
71
72 # No partitions requested for barystatic contribution
73 self.partitionice = []
74 self.partitionhydro = []
75 self.partitionocean = []
76
77 # No external solutions by default
78 self.external = None
79
80 # Planet radius
81 self.planetradius = planetradius(planet)
82 # }}}
83
84 def checkconsistency(self, md, solution, analyses): # {{{
85 if ('SealevelchangeAnalysis' not in analyses) or (solution == 'TransientSolution' and not md.transient.isslc):
86 return md
87
88 md = checkfield(md, 'fieldname', 'solidearth.requested_outputs', 'stringrow', 1)
89
90 self.settings.checkconsistency(md, solution, analyses)
91 self.lovenumbers.checkconsistency(md, solution, analyses)
92 self.rotational.checkconsistency(md, solution, analyses)
93 if self.external:
94 if not isa(self.external, solidearthsolution):
95 raise Exception('solidearth consistency check: external field should be a solidearthsolution')
96 self.external.checkconsistency(md, solution, analyses)
97 return md
98 # }}}
99
100 def defaultoutputs(self, md): # {{{
101 return ['Sealevel']
102 # }}}
103
104 def marshall(self, prefix, md, fid): # {{{
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 if len(self.partitionocean):
119 npartocean = np.max(self.partitionocean) + 2
120 else:
121 npartocean = 0
122
123 WriteData(fid, prefix, 'object', self, 'fieldname', 'partitionice', 'mattype', 1, 'format', 'DoubleMat');
124 WriteData(fid, prefix, 'data', npartice, 'format', 'Integer', 'name', 'md.solidearth.npartice');
125 WriteData(fid, prefix, 'object', self, 'fieldname', 'partitionhydro', 'mattype', 1, 'format', 'DoubleMat');
126 WriteData(fid, prefix, 'data', nparthydro,'format', 'Integer', 'name','md.solidearth.nparthydro');
127 WriteData(fid, prefix, 'object', self, 'fieldname', 'partitionocean', 'mattype', 1, 'format', 'DoubleMat');
128 WriteData(fid, prefix, 'data', npartocean,'format', 'Integer', 'name','md.solidearth.npartocean');
129
130 self.settings.marshall(prefix, md, fid)
131 self.lovenumbers.marshall(prefix, md, fid)
132 self.rotational.marshall(prefix, md, fid)
133 if self.external:
134 WriteData(fid, prefix, 'data', 1, 'format', 'Integer', 'name', 'md.solidearth.isexternal')
135 self.external.marshall(prefix, md, fid)
136 else:
137 WriteData(fid, prefix, 'data', 0, 'format', 'Integer', 'name', 'md.solidearth.isexternal')
138
139 # Process requested outputs
140 outputs = self.requested_outputs
141 pos = np.where(np.asarray(outputs) == 'default')[0]
142 if len(pos):
143 outputs = np.delete(outputs, pos) # remove 'default' from outputs
144 outputs = np.append(outputs, self.defaultoutputs(md)) # add defaults
145 WriteData(fid, prefix, 'data', outputs, 'name', 'md.solidearth.requested_outputs', 'format', 'StringArray')
146 # }}}
147
148 def extrude(self, md): # {{{
149 return self
150 # }}}
Note: See TracBrowser for help on using the repository browser.