-
Notifications
You must be signed in to change notification settings - Fork 14
/
PlanetProfile.m
executable file
·3899 lines (3497 loc) · 171 KB
/
PlanetProfile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function outPlanet = PlanetProfile(Planet,Seismic,Params)
% PlanetProfile, Software framework for constructing interior structure models based on planetary properties.
% Copyright (C) 2018 Steven D. Vance
% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
% This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
% Based on
% S. Vance, M. Bouffard, M. Choukroun, and C. Sotin.
% Ganymede's internal structure including thermodynamics of magnesium sulfate oceans in contact with ice.
% Planetary And Space Science, 96:62-70, 2014.
% (http://dx.doi.org/10.1016/j.pss.2014.03.011)]
%
% Expanded in -- Github Release 1.0
% S. D. Vance, M. P. Panning, S. Staehler, F. Cammarano, B. G. Bills, G. Tobie, S..
% Kamata, S. Kedar, C. Sotin, W. T. Pike, et al.
% Geophysical investigations of habitability in ice-covered ocean worlds.
% Journal of Geophysical Research: Planets, Nov 2018.
%% new function to CheckCompatibility
vernum = PPversion;
disp(['PlanetProfile version ' vernum])
if all(vernum(end-2:end) == 'dev'); disp('This version is in development.'); end
% Check SeaFreeze compatibility and presence on path
% This version of PlanetProfile is compatible with the version number
% below.
seaVer = '0.9.2';
checkSeaFreeze(seaVer);
%% leave as is for now, separate file in python, or nonexistent
% First, get runtime config information
% Fetch this information from an external file so we don't track
% runtime settings in this file
if ~isfield(Params,'cfg')
cfg = config;
else
cfg = Params.cfg;
end
if ~isfield(Seismic,'DO_SEISMIC')
Seismic.DO_SEISMIC = 1;
end
%% worry about TauP implementation
if isfield(Params,'TauP')
try exist('taupcreate')
disp ('Taup Model file will be created. Curve will be plotted. Please use TauP (https://www.seis.sc.edu/taup/) for full functionality')
catch
disp('Add mattaup to path')
end
end
if strcmp(Planet.Ocean.comp,'Seawater')
wtPpt = Planet.Ocean.w_ocean_pct; % We are already using ppt for Seawater even though the variable is called WtPct
else
wtPpt = 10*Planet.Ocean.w_ocean_pct;
end
%% steve to clean this up by calling Params.cfg
Params.NOPLOTS = cfg.NO_PLOTS;
Params.CALC_NEW = cfg.CALC_NEW;
Params.CALC_NEW_REFPROFILES = cfg.CALC_NEW_REF;
Params.CALC_NEW_SOUNDSPEEDS = cfg.CALC_NEW_SOUND;
Params.INCLUDE_ELECTRICAL_CONDUCTIVITY = cfg.CONDUCT;
Params.HOLD = cfg.HOLD;
Params.savefigformat = cfg.fig_fmt;
%% Check for porosity so we know if we will need those plots --> to be moved somewhere more sensible -- make part of CheckFields function, or in python create a class Planet that creates all the fields
POROUS = isfield(Planet,'POROUS_ROCK') && Planet.POROUS_ROCK;
%% CreatePlots
% Show any figures already generated in case user has selected no_plots = 0
% after running with no_plots = 1
if ~Params.NOPLOTS
figList = findall(0, 'type', 'figure');
for iFig=1:numel(figList)
set(figList(iFig), 'visible', 'on');
end
% Let the user see changes in real time, and only pop up windows at the
% *start* of the first run on which we generate plots
drawnow
end
%% SetupFilenames
POROUS_ICE = isfield(Planet,'POROUS_ICE') && Planet.POROUS_ICE;
if POROUS_ICE; porIceStr = '_PorousIce'; else; porIceStr = ''; end
% implementing a feature to track silicate composition in output files
% because it's getting confusing as we investigate k2, Q, etc....
if isfield(Seismic,'mantleEOSname'); minEOS = ['_' Seismic.mantleEOSname]; else; minEOS = ''; end
% adjust file name based on keywords(clathrates, porous)
%if isfield(Planet,'Clathrate'); clathStr = '_Clathrates'; else; clathStr = ''; end
savebase = [Planet.name 'Profile_'];
if isfield(Planet,'Clathrate'); savebase = [savebase 'Clathrates_']; end
%savebase = [Planet.name 'Profile_' clathStr];
savefile = [savebase Planet.Ocean.comp ...
'_' num2str(round(Planet.Ocean.w_ocean_pct)) 'WtPct' minEOS porIceStr ];
% MJS 2020-10-02:
% strLow is a placeholder for a calculation that places a relevant string
% into filenames for differentiating mantle compositions. That calculation
% will need to be moved up to account for new additions placing the new
% Profile_fname field into Planet.
strLow = '';
datpath = strcat(Planet.name,'/');
figpath = strcat(Planet.name,'/figures/');
if ~exist(figpath,'dir')
error(['Figure path ' figpath ' does not exist. Check your Matlab path ' ...
' settings and add-with-subfolders the main PlanetProfile directory.'])
end
if ~exist(datpath,'dir')
error(['Data path ' datpath ' does not exist. Check your Matlab path ' ...
' settings and add-with-subfolders the main PlanetProfile directory.'])
end
%% globals for functions in fzero --> just swEOS_chooser this needs to be cleaned up --> SetupEOS
wo = Planet.Ocean.w_ocean_pct;
if strcmp(Planet.Ocean.comp,'Seawater')
global swEOS
swEOS.gsw = swEOS_chooser('gsw305');
elseif strcmp(Planet.Ocean.comp,'NaCl')
error(['NaCl is not currently implemented.'])
elseif strcmp(Planet.Ocean.comp,'NH3')
% error(['NH3 is not currently implemented.'])
elseif strcmp(Planet.Ocean.comp,'MgSO4')
conduct_scaling_MgSO4 = (1+4*wo); % empirical scaling of electrical conductivity from 1 bar values compiled in Hand and Chyba 2007
end
if isfield(Seismic,'mantleEOS')
thiseos = split(Seismic.mantleEOS,'.tab');
thiseos = char(thiseos(1));
else
thiseos = 'none';
end
bar2GPa = 1e-4;
Gg = 6.67300e-11; % m3 kg-1 s-2
if ~cfg.SKIP_PROFILES
%% Figure label settings
set(0,'defaultfigurecolor',[1 1 1]) % white background for figures
lbl = getPlotLabels(cfg.dft_font, cfg.dft_math, cfg.interpreter);
% Make shorter versions so they don't muck up the strings too much
nm = lbl.nm; bnm = lbl.bnm; math = lbl.math;
%% Figure generation
% Pre-generate all the figures so that we can work with them in the
% background, instead of popping up as they are focused.
% If the windows are still open, we can reuse them
% without grabbing focus by checking ishandle (or isempty for array values).
figs = getProfileFigRefs(lbl, Planet.Tb_K, Planet.FeCore, POROUS, cfg.HOLD, cfg.NO_PLOTS);
% Also grab the layered induction figures in order to pregenerate them
% since we will be a moment in this function
if cfg.CALC_NEW_INDUC && ...
(strcmp(Planet.name,'Europa') || strcmp(Planet.name,'Ganymede') || strcmp(Planet.name,'Callisto'))
[~] = getLayeredFigRefs(lbl, Planet.Tb_K, Planet.name, Planet.PLOT_SIGS, cfg.HOLD, cfg.NO_PLOTS);
end
%% Save in a file the densities of adiabats corresponding to different ocean concentrations
% These are reference profiles, for plotting on hydrosphere density vs
% pressure plots
% OceanFreezeDensities TBD
str_ref_densities = ['ref_densities_' Planet.name '_' Planet.Ocean.comp '_pp.mat'];
if Params.CALC_NEW_REFPROFILES
nPr = Params.nsteps_ref_rho;
%calculate the densities of liquid solution on the liquidus lines
%corresponding to different concentrations
wref = Params.wref;
lw = length(wref);
Pref_MPa=linspace(0,Params.Pseafloor_MPa,nPr);
Tref_K = zeros(lw,nPr);
rho_ref_kgm3 = Tref_K; %allocate
for jr=1:lw
for il=1:nPr
try
if ~isfield(Planet.Ocean,'fnTfreeze_K')
Tref_K(jr,il) = getTfreeze(Pref_MPa(il),wref(jr),Planet.Ocean.comp);
else
Tref_K(jr,il) = Planet.Ocean.fnTfreeze_K(Pref_MPa(il),wref(jr));
end
catch
disp('caught exception while calculating liquid densities (dashed lines); maybe the search range for fzero is too small?')
disp(['il = ' num2str(il)])
Tref_K(jr,il) = NaN;
end
rho_ref_kgm3(jr,il) = fluidEOS(Pref_MPa(il),Tref_K(jr,il),wref(jr),Planet.Ocean.comp);
end
if strcmp(Planet.Ocean.comp,'Seawater')
isreal = find(~isnan(rho_ref_kgm3(jr,:)));
rho_ref_kgm3(jr,:)=interp1(Pref_MPa(isreal),rho_ref_kgm3(jr,isreal),Pref_MPa,'linear','extrap');
end
end
save(fullfile([datpath str_ref_densities]),'rho_ref_kgm3','Pref_MPa','Tref_K')
else
try
load(fullfile([datpath str_ref_densities]));
catch
error(['ERROR: A reference density file for ' Planet.name ' ' Planet.Ocean.comp ' was not found. Re-run with calc_new_ref=1 to generate the needed file.'])
end
end
end % ~cfg.SKIP_PROFILES
% Filename strings
vsP = 'Porosity_vs_P';
vsR = 'Porosity_vs_R';
vperm = 'Permeability';
vgsks = 'Gs_Ks';
vseis = 'Seismic';
vcond = 'Conductivity';
vgrav = 'Gravity';
vmant = 'MantleDens';
vcore = 'CoreMantTrade';
vpvt4 = 'PTx4';
vpvt6 = 'PTx6';
vwedg = 'Wedge';
%% FEATURE! COMING SOON!
if ~isfield(Planet,'NoH2O') % backward compatibility--haven't finished implementing water-free worlds
Planet.NoH2O =0;
end
%SetupClathrates
[n_clath, n_iceI, n_ocean] = deal(zeros(1));
if isfield(Planet,'Clathrate')
disp('Running with clathrate parameters')
if isfield(Params,'Clathrate_set_depth') % checks if clathrates have set depth
max_clath_depth=Params.Clathrate_set_depth;
Check_clath_depth=1;
else
max_clath_depth=10e15;
Check_clath_depth=0;
end
else
Params.nsteps_clath = 0;
Check_clath_depth=0;
max_clath_depth=1e15;% ridiculous high number
% MJS 2021-10-27: This format is being removed in the python
% implementation. Using the already-included logical flag
% Planet.CLATHRATE as a check is a much more sensible way to
% toggle clathrate modeling.
end
%% SetupLayers
nsteps = Params.nsteps_iceI + Params.nsteps_ocean + Params.nsteps_clath;
% MJS 2021-10-28: This got moved up from below where saving/reloading a la
% CALC_NEW was done. We needed to do a bit more calculations before making
% the save files.
[z_m,r_m,g_ms2,M_above_kg,M_below_kg] = deal(zeros(1,nsteps));
M_above_kg(1) = 0;
M_below_kg(1) = Planet.M_kg;
r_m(1) = Planet.R_m;
g_ms2(1) = Gg*Planet.M_kg/Planet.R_m^2;
D_conductivityIh = 632; % W m-1; Andersson et al. 2005 (For comparison, Mckinnon 2006 uses a value of 621 from Slack 1980)
[Planet.Profile_fname, Planet.Profile_ID] = deal(strings(1));
% Preallocate for ConvectionDeschampsSotin
[Q_Wm2,deltaTBL_m,eTBL_m,Tc,rhoIce,alphaIce,CpIce,kIce,nu,CONVECTION_FLAG_I,Qb,Planet.zb_outerIce_m] = deal(zeros(1));
%%
%if ~Planet.NoH2O
if Params.CALC_NEW
% adds number of clathrates based on inputs or sets to zero, also sets
% maximum depth if specified
%%
[T_K,P_MPa,rho_kgm3, phi_hydro_frac] = deal(zeros(1,nsteps));
phase = zeros(1,nsteps);
% assign phase based on clathrates or Ih
phase((1+Params.nsteps_clath):(Params.nsteps_clath+Params.nsteps_iceI))=1;
phase(1:Params.nsteps_clath)=30; % index to indicate clathrates, which are not an ice phase
Tb_K = Planet.Tb_K;
%% IceLayers --- function iteratively setting up the thermal profile, the density and temperature of the layer with each pressure step
%ice Ih, ice III, ice V
%--------------------------------------------------------------------------
T_K(1) = Planet.Tsurf_K;
P_MPa(1) = Planet.Psurf_MPa;
% if ice shell had to be thinned in previous run, this will
% reset indexing correctly. Set starting values:
n_iceI = Params.nsteps_iceI; % these are redundant. just change text below to use Params.n...
n_clath = Params.nsteps_clath;
n_ocean = Params.nsteps_ocean; %
if n_clath>0
clath_out{1} = Helgerud_sI(P_MPa(1),T_K(1));
rho_kgm3(1)=clath_out{1}.rho;
[Cp(1) alpha_K(1)]= getCpIce(P_MPa(1),T_K(1),phase(1)) ;
else
rho_kgm3(1) = getRhoIce(P_MPa(1),T_K(1),1);
[Cp(1) alpha_K(1)]= getCpIce(P_MPa(1),T_K(1),phase(1)) ;
end
try
Pb_MPa = getPfreeze(Planet.Tb_K,wo,Planet.Ocean.comp);
%[Cp(1) alpha_K(1)]= getCpIce(P_MPa(1),T_K(1),phase(1)) ;
deltaP = Pb_MPa/(n_clath+n_iceI-1);
% assumes Pressure gradient doesnt change betweeen clathrates
% and need to check assumption
% if n_clath == 0 this will skip and move on to next section
%% ClathrateLayer function within IceLayers
for il=2:n_clath % propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (Planet.Tb_K.^(P_MPa(il)./Pb_MPa)).*(Planet.Tsurf_K.^(1-P_MPa(il)./Pb_MPa));
clath_out{il} = Helgerud_sI(P_MPa(il),T_K(il));
rho_kgm3(il)=clath_out{il}.rho;
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),phase(il)) ;
z_m(il) = z_m(il-1)+ (P_MPa(il)-P_MPa(il-1))*1e6/g_ms2(il-1)/rho_kgm3(il-1);
r_m(il) = Planet.R_m-z_m(il);
% determine local gravity and check to make sure maximum
% clathrate depth isn't reached
M_below_kg(il) = M_above_kg(il-1) + 4/3*pi*(r_m(il-1)^3-r_m(il)^3)*rho_kgm3(il);
M_below_kg(il) = Planet.M_kg-M_above_kg(il);
g_ms2(il) = Gg*M_below_kg(il)/r_m(il)^2;
if z_m(il)>max_clath_depth % check to see if maximum depth of clathrates reached
n_iceI=n_iceI+(n_clath-il)+1;
n_clath=il-1;
phase((1+n_clath):(n_clath+n_iceI))=1;
break
end
%rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
end % end ClathrateLayer
if n_clath>0
ii=n_clath+1;
else
ii=2;
end
%% IceILayer
for il=ii:(n_iceI+n_clath) % propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (Planet.Tb_K.^(P_MPa(il)./Pb_MPa)).*(Planet.Tsurf_K.^(1-P_MPa(il)./Pb_MPa));
rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1); % I THINK THIS CALL CAN ACCEPT A VECTOR
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),phase(il)) ; % I THINK THIS CALL CAN ACCEPT A VECTOR
%rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
end
nIceIIILithosphere=0;
nIceVLithosphere=0;
PbI_MPa = Pb_MPa;
catch
disp('PlanetProfile failed to get Pb! Here''s why:')
disp(lasterr)
disp('Maybe it''s okay? If execution stopped, then probably not. Try looking where getPfreeze is called.')
%% IceIIIUnderplateLayer
if isfield(Params,'BOTTOM_ICEIII') && Params.BOTTOM_ICEIII % this will elicit an error if one has set the temperature too low but one hasn't specified ice III or V under the ice I
disp('Adding ice III to the bottom of ice Ih. Make sure the ocean salinity is high enough that doing this makes sense')
nIceIIILithosphere=5;
phase((n_iceI+n_clath)-nIceIIILithosphere:(n_iceI+n_clath))=3;
PbI_MPa = 210; % the Ih-III transition is essentially fixed, within a few MPa
deltaP = PbI_MPa/((n_iceI+n_clath)-5-1); % save five entries at the bottom for ice III
for il=2:n_clath % propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (Planet.Tb_K.^(P_MPa(il)./Pb_MPa)).*(Planet.Tsurf_K.^(1-P_MPa(il)./Pb_MPa));
clath_out{il} = Helgerud_sI(P_MPa(il),T_K(il));
rho_kgm3(il)=clath_out{il}.rho;
z_m(il) = z_m(il-1)+ (P_MPa(il)-P_MPa(il-1))*1e6/g_ms2(il-1)/rho_kgm3(il-1);
r_m(il) = Planet.R_m-z_m(il);
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),phase(il))
% determine local gravity
M_above_kg(il) = M_above_kg(il-1) + 4/3*pi*(r_m(il-1)^3-r_m(il)^3)*rho_kgm3(il);
M_below_kg(il) = Planet.M_kg-M_above_kg(il);
g_ms2(il) = Gg*M_below_kg(il)/r_m(il)^2;
if z_m(il)>max_clath_depth % check to see if maximum depth of clathrates reached
n_iceI=n_iceI+(n_clath-il)+1;
n_clath=il-1;
phase(:,(1+n_clath):(n_clath+n_iceI))=1;
break
end
%rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
end
if n_clath>0
ii=n_clath+1;
else
ii=2;
end
for il=ii:(n_iceI+n_clath)-nIceIIILithosphere % propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (Planet.Tb_K.^(P_MPa(il)./Pb_MPa)).*(Planet.Tsurf_K.^(1-P_MPa(il)./Pb_MPa));
rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),phase(il)) ;
%rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
end
TbIII = Planet.Tb_K+1;
Pb_MPa = getPfreezeIII(TbIII,wo,Planet.Ocean.comp);% fix the thickness of the ice III layer based on T>Tb by 2K
deltaP = (Pb_MPa-PbI_MPa)/nIceIIILithosphere; % five entries at the bottom for ice III
for il = (n_clath+n_iceI)-nIceIIILithosphere+1:(n_iceI+n_clath)
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (TbIII.^(P_MPa(il)./Pb_MPa)).*(TbIII.^(1-P_MPa(il)./Pb_MPa));
rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),3);
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),3) ;
end
elseif isfield(Params,'BOTTOM_ICEV') && Params.BOTTOM_ICEV
disp('Adding ice V and III to the bottom of ice Ih. Make sure the ocean salinity is high enough that doing this makes sense')
nIceIIILithosphere=5;
nIceVLithosphere=5;
phase(n_iceI-nIceVLithosphere-nIceIIILithosphere:n_iceI-nIceVLithosphere)=3;
phase(n_iceI-nIceVLithosphere:n_iceI)=5;
PbI_MPa = 210; % the Ih-V transition is essentially fixed, within a few MPa
deltaP = PbI_MPa/((n_iceI+n_clath)-5-1); % save five entries at the bottom for ice V
%clathrates
for il=2:n_clath % propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (Planet.Tb_K.^(P_MPa(il)./Pb_MPa)).*(Planet.Tsurf_K.^(1-P_MPa(il)./Pb_MPa));
clath_out{il} = Helgerud_sI(P_MPa(il),T_K(il));
rho_kgm3(il)=clath_out{il}.rho;
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),phase(il))
z_m(il) = z_m(il-1)+ (P_MPa(il)-P_MPa(il-1))*1e6/g_ms2(il-1)/rho_kgm3(il-1);
r_m(il) = Planet.R_m-z_m(il);
% determine local gravity
M_above_kg(il) = M_above_kg(il-1) + 4/3*pi*(r_m(il-1)^3-r_m(il)^3)*rho_kgm3(il);
M_below_kg(il) = Planet.M_kg-M_above_kg(il);
g_ms2(il) = Gg*M_below_kg(il)/r_m(il)^2;
if z_m(il)>max_clath_depth % check to see if maximum depth of clathrates reached
n_iceI=n_iceI+(n_clath-il)+1;
n_clath=il-1;
phase(:,(1+n_clath):(n_clath+n_iceI))=1;
break
end
%rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
end
if n_clath>0
ii=n_clath+1;
else
ii=2;
end
%ice Ih
% propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
for il=ii:(n_iceI+n_clath)-nIceVLithosphere % propagate P,T,rho to the bottom of the ice % THIS CAN BE COMPUTED AS A VECTOR INSTEAD.
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (Planet.Tb_K.^(P_MPa(il)./Pb_MPa)).*(Planet.Tsurf_K.^(1-P_MPa(il)./Pb_MPa));
rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),phase(ill));
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),phase(ill)) ;
%rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),1);
end
%ice III
TbIII = Planet.Tb_K+1;
Pb_MPa = getPfreezeIII(TbIII,wo,Planet.Ocean.comp);% fix the thickness of the ice III layer based on T>Tb by 2K
deltaP = (Pb_MPa-PbI_MPa)/(nIceIIILithosphere); % five entries at the bottom for ice III
for il = (n_iceI+n_clath)-nIceIIILithosphere+1:(n_iceI+n_clath)
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (TbIII.^(P_MPa(il)./Pb_MPa)).*(TbIII.^(1-P_MPa(il)./Pb_MPa));
rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),3);
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),3) ;
end
%ice V
TbV = Planet.Tb_K+1;
Pb_MPa = getPfreezeV(TbV,wo,Planet.Ocean.comp);% fix the thickness of the ice V layer based on T>Tb by 2K
deltaP = (Pb_MPa-PbI_MPa)/(nIceVLithosphere); % five entries at the bottom for ice V
for il = (n_iceI+n_clath)-nIceVLithosphere+1:(n_iceI+n_clath)
P_MPa(il) = P_MPa(il-1) + deltaP;
T_K(il) = (TbV.^(P_MPa(il)./Pb_MPa)).*(TbV.^(1-P_MPa(il)./Pb_MPa));
rho_kgm3(il) = getRhoIce(P_MPa(il),T_K(il),3);
[Cp(il) alpha_K(il)]= getCpIce(P_MPa(il),T_K(il),3) ;
end
%adjusts for surface porosity if set
if POROUS_ICE % Steve to ask Angela if this is actually being used.
% correction for porosity
por_in.p=P_MPa(1:il)*1e-3;
por_in.t = T_K(1:il);
por_in.den = rho_kgm3(1:il);
%por_in.vp = velsIce.Vclathl_kms;
%por_in.vs = velsIce.Vclatht_kms;
if isfield(Planet,'phi_surface')
por_out = get_porosity_ice(por_in,Planet.phi_surface);
else
por_out =get_porosity_ice(por_in);
end
%permeability = por_out.per;
%ice_ind=find(phase==30);
rho_kgm3(1:il) = por_out.den;
phi_hydro_frac(1:il)=por_out.por;
%velsIce.Vclathl_kms = por_out.vp;
%velsIce.Vclatht_kms = por_out.vs;
disp(['Average ice porosity: ' num2str(mean(phi_hydro_frac(1:il)))])
disp(['Porosity: ' num2str(phi_hydro_frac(1:il))])
end
end % end IceIIIUnderplateLayer
end
%% OceanLayer
%OCEAN + ICE III/V/VI SHELL
%--------------------------------------------------------------------------
deltaP = (Params.Pseafloor_MPa-Pb_MPa)/n_ocean; %
if deltaP<=0 % prevent an embarassing error that can occur when adapting a file for a small object to that of a larger one.
error('negative increment of pressure while computing ocean profile. Be sure Params.Pseafloor_MPa is greater than the likely pressure at the silicate interface. Currently it''s less than the pressure at the base of the ice I layer.')
end
for il =1:n_ocean
ill = il+n_iceI+n_clath;
disp(['il: ' num2str(il) '; P_MPa: ' num2str(round(P_MPa(ill-1))) '; T_K: ' num2str(round(T_K(ill-1)))]);
P_MPa(ill) = Pb_MPa + il*deltaP;
if il==1 % establish the phase vector
phase(ill) = getIcePhase(P_MPa(ill-1),T_K(ill-1),wo,Planet.Ocean.comp);%p = 0 for liquid, I for I, 2 for II, 3 for III, 5 for V and 6 for VI
elseif phase(ill-1)~=6
phase(ill) = getIcePhase(P_MPa(ill-1),T_K(ill-1),wo,Planet.Ocean.comp);%p = 0 for liquid, I for I, 2 for II, 3 for III, 5 for V and 6 for VI
if phase(ill-1)==3 && phase(ill)==0 % fix to instabilities in the phase lookup for ice III
disp('Fixing apparent instability in the EOS?ice III is forming above the ocean where it wasn''t specified')
phase(ill)=3;
end
if phase(ill-1)==0 && phase(ill)==1 % fix to instabilities in the phase lookup for ice I
disp('Fixing apparent instability in the EOS?ice Ih is forming under the ocean')
phase(ill)=0;
end
if phase(ill-1)==5 && phase(ill)==0 % fix to instabilities in the phase lookup for ice V for Titan NH3 LBF svance Jul 6 2021
disp('Fixing apparent instability in the EOS? fluid is forming under ice V')
phase(ill)=5;
end
else
phase(ill) = 6;
end
if phase(ill) == 0 %if ocean
[rho_ocean,Cp(ill-1),alpha_o]= fluidEOS(P_MPa(ill-1),T_K(ill-1),wo,Planet.Ocean.comp);
% Forbidding MgSO4 in the check below avoids a problem in
% application of the EOS for low-salinity MgSO4 oceans.
% Negative thermal expansivity regions in the MgSO4 EOS may be
% artifacts of the current EOS calculation. See Vance et al. 2014
if alpha_o<=0 && ~strcmp(Planet.Ocean.comp,'MgSO4') && ~Planet.ALLOW_NEGALPHA
disp('Ocean alpha at ice interface is less than zero. adjusting temperature upward.')
disp('This means there''s a conductive layer at the interface with thickness inversely proportional to the heat flow.')
disp('The thickness is likely less than a few 100 m. See Melosh et al. 2004.')
Tnew = fzero(@(T) alphaAdjust(P_MPa(ill),T,wo,Planet.Ocean.comp),273);
disp(['The new temperature is ' num2str(Tnew) ', or delta T = ' num2str(Tnew-T_K(ill-1)) '.'])
T_K(ill)=Tnew;
else
T_K(ill) = T_K(ill-1)+ alpha_o*T_K(ill-1)./(Cp(ill-1))./(rho_ocean)*deltaP*1e6; %adiabatic gradient in ocean; this introduces an error, in that we are using the temperature from the previous step
end
alpha_K(ill) = alpha_o;
rho_kgm3(ill) = fluidEOS(P_MPa(ill),T_K(ill),wo,Planet.Ocean.comp); % to be deleted
% [rho_ocean,Cp(ill),alpha_o]= fluidEOS(P_MPa(ill),T_K(ill-1),wo,Planet.Ocean.comp);% THIS IS REDUNDANT TO THE CALCULATION OF RHO_OCEAN ABOVE
else %% HPIceLayers
% allow for stable dense fluid under high pressure ice --> this
% was added for the callisto study. Commented out currently
rhoice = getRhoIce(P_MPa(ill),T_K(ill-1),phase(ill));
% rhoocean = fluidEOS(P_MPa(ill),T_K(ill-1),wo,Planet.Ocean.comp);
% if rhoocean>=rhoice
% phase(ill)=0;
% end
if ~isfield(Planet.Ocean,'fnTfreeze_K')
if il==6
x = 1;
end
T_K(ill) = getTfreeze(P_MPa(ill),wo,Planet.Ocean.comp,T_K(ill-1)); %find the temperature on the liquidus line corresponding to P(k,i+nIceI); should really use a conductive profile here, but that would seem to naturally bring us back to the liquidus. Steve wants to confirm.
else
T_K(ill) = Planet.Ocean.fnTfreeze_K(P_MPa(ill),wo);
end
if T_K(ill)<T_K(ill-1)
T_K(ill)=T_K(ill-1); % this may no longer be needed because negalpha is accounted for above -- sincerely, steve 6/15/21
end
rho_kgm3(ill) = getRhoIce(P_MPa(ill),T_K(ill),phase(ill));
% [rho_ocean,Cp(ill),alpha_o]=
% fluidEOS(P_MPa(ill),T_K(ill-1),wo,Planet.Ocean.comp);
% % this is odd and doesn't seem to be needed--steve
% 6/15/21
[Cp(ill), alpha_K(ill)]= getCpIce(P_MPa(ill),T_K(ill),phase(ill));
end
end
% MJS 2021-10-29: I don't think these lines are important or do
% anything substantial. Both quantities are recalculated
% aplenty in the next loops. This was being done just before
% saving/reloading in the master branch before now.
rho_kgm3(1) = rho_kgm3(2); % continuity
Cp(1)=Cp(2);
%%%%%%%%%%%%%%%%%%%%%
% convert to depth —- PlanetDepths
%%%%%%%%%%%%%%%%%%%
%% calculate gravity in each layer instead of assuming surface gravity applies.
% allocate variables
%% HydrosphereDepths
deltaP = Pb_MPa/(n_iceI+n_clath);
% calculates depth for clathrates and ice separatly so the depths
% can be recorded accurately
for il = 2:(n_clath)
% calculate depth
z_m(il) = z_m(il-1)+ (P_MPa(il)-P_MPa(il-1))*1e6/g_ms2(il-1)/rho_kgm3(il-1);
% convert to radius
r_m(il) = Planet.R_m-z_m(il);
% determine local gravity
M_above_kg(il) = M_above_kg(il-1) + 4/3*pi*(r_m(il-1)^3-r_m(il)^3)*rho_kgm3(il);
M_below_kg(il) = Planet.M_kg-M_above_kg(il);
g_ms2(il) = Gg*M_below_kg(il)/r_m(il)^2;
end
%checks if there were clathrates or not
if n_clath>0
ii=n_clath+1;
Zclath=z_m(n_clath);
Planet.Zclath=Zclath;
else
ii=2;
Zclath=0;
Planet.Zclath=0;
end
for il = ii:(n_clath+n_iceI)
% calculate depth
z_m(il) = z_m(il-1)+ (P_MPa(il)-P_MPa(il-1))*1e6/g_ms2(il-1)/rho_kgm3(il-1);
% convert to radius
r_m(il) = Planet.R_m-z_m(il);
% determine local gravity
M_above_kg(il) = M_above_kg(il-1) + 4/3*pi*(r_m(il-1)^3-r_m(il)^3)*rho_kgm3(il);
M_below_kg(il) = Planet.M_kg-M_above_kg(il);
g_ms2(il) = Gg*M_below_kg(il)/r_m(il)^2;
end
if isempty(il)
zb_outerIce_m=z_m(ii-1);
Planet.zb_outerIce_m=zb_outerIce_m;
else
zb_outerIce_m=z_m(il);
Planet.zb_outerIce_m=zb_outerIce_m;
end
deltaP = (Params.Pseafloor_MPa-Pb_MPa)/n_ocean; %
for il = 1:n_ocean
ill = il+(n_iceI+n_clath);
%calculate depth
dz = deltaP*1e6/g_ms2(il-1+(n_iceI+n_clath))/rho_kgm3(ill);
z_m(ill) = z_m(il-1+(n_iceI+n_clath))+ dz; % using the previous gravity step, since we haven't calculated the present step. this introduces an error
% convert to radius
r_m(ill) = Planet.R_m-z_m(ill);
% determine local gravity
M_above_kg(ill) = M_above_kg(il-1+(n_iceI+n_clath))+4/3*pi*((r_m(ill)+dz)^3-r_m(ill)^3)*rho_kgm3(ill);
M_below_kg(ill) = Planet.M_kg-M_above_kg(ill);
g_ms2(ill) = Gg*M_below_kg(ill)/r_m(ill)^2;
end
disp(['z_iceI: ' num2str(zb_outerIce_m/1e3) ' km'])
z_ocean_m= z_m(n_ocean); % depth to the ocean
%% compute conductive heat through the ice I layer
Qb = D_conductivityIh*log(Planet.Tb_K/Planet.Tsurf_K)/Planet.zb_outerIce_m;
%% compute solid state convection ice
% We use these values much later, but we need them to construct
% the filename shortly, so we calculate them now. This allows
% us to skip unnecessary calculations in the case of
% cfg.SKIP_PROFILES=1
if max_clath_depth<Planet.zb_outerIce_m % only a clathrate lid
% asummes Q across ice-ocean is same Q across clathrates/ice.
% The below line updated per A. Marusiak 2023-01-21
[Q_Wm2(iT), T_clath_ice(iT), deltaTBL_m(iT),eTBL_m(iT),Tc(iT)]= ...
clathrate_lid_thermo(Planet.Tsurf_K,Planet.Tb_K(iT),PbI_MPa(iT)/2, max_clath_depth);
else
[Q_Wm2,deltaTBL_m,eTBL_m,Tc,rhoIce,alphaIce,CpIce,kIce,nu,CONVECTION_FLAG_I]=...
ConvectionDeschampsSotin2001(Planet.Tsurf_K,Planet.Tb_K,PbI_MPa/2,Planet.zb_outerIce_m,g_ms2(1),phase(1)+1);
end
% Make this calculation now in order to get Planet.Qmantle_Wm2 for making
% filenames shortly
if CONVECTION_FLAG_I && eTBL_m>zb_outerIce_m
warning('Convection predicted but not possible because the conductive layer thickness exceeds the thickness of the ice.')
disp('Perhaps T_surf is outside the valid range for the scaling from Deschamps and Sotin 2001.')
disp('Setting CONVECTION_FLAG_I to zero')
CONVECTION_FLAG_I = 0;
end
% Convection has to be calculated prior to assigning depths in case
% ice shell needs to be thinned to account for clathrates
if CONVECTION_FLAG_I
%conductive upper layer
nConvectIce=(n_iceI+n_clath)-nIceIIILithosphere-1; % indices where ice/claths exist in upper layer
nconold=nConvectIce;
if max_clath_depth<Planet.zb_outerIce_m
%eTBL_m=eTBL_m+max_clath_depth; fixed in new
%version
T_K(1:n_clath)=linspace(Planet.Tsurf_K,T_clath_ice,n_clath);
inds_eTBL = find(z_m(n_clath:nConvectIce)<=eTBL_m);
if ~isempty(inds_eTBL)
inds_eTBL=inds_eTBL +n_clath;
if length(inds_eTBL)>1
Pterm =(P_MPa(inds_eTBL)-P_MPa(inds_eTBL(1)))./(P_MPa(inds_eTBL(end))-P_MPa(inds_eTBL(1)));
T_K(inds_eTBL) = (Tc.^(Pterm)).*(T_clath_ice.^(1-Pterm));
else
T_K(inds_eTBL)=T_clath_ice+Q_Wm2./kIce.*(z_m(inds_eTBL)-z_m(inds_eTBL-1));
end
else
inds_eTBL=n_clath;
end
else
inds_eTBL = find(z_m(1:nConvectIce)<=eTBL_m);
Pterm = P_MPa(inds_eTBL)./P_MPa(inds_eTBL(end));
if phase(inds_eTBL(1))==1
T_K(inds_eTBL) = (Tc.^(Pterm)).*(Planet.Tsurf_K.^(1-Pterm));
elseif phase(inds_eTBL(1))==30;
T_K(1:inds_eTBL(end))=linspace(Planet.Tsurf_K,Tc,length(inds_eTBL));
end
end
rho_kgm3(1:inds_eTBL(end))=getRhoIce(P_MPa(1:inds_eTBL(end)),T_K(1:inds_eTBL(end)),phase(1:inds_eTBL(end)));
P_bound=P_MPa(inds_eTBL(end));
T_K_ccbound=T_K(inds_eTBL(end));
%convective region
for iconv = inds_eTBL(end)+1:nConvectIce % added parentheses around 1:nConvectIce 20200103 SDV
rho_kgm3(iconv)=getRhoIce(P_MPa(iconv),T_K(iconv-1),phase(iconv));
if POROUS_ICE % adjust if porosity needs to be considered
por_in.p=P_MPa(iconv)*1e-3;
por_in.t = T_K(iconv-1);
por_in.den = rho;
if isfield(Planet,'phi_surface')
por_out = get_porosity_ice(por_in,Planet.phi_surface);
else
por_out =get_porosity_ice(por_in);
end
rho = por_out.den;
phi = pot_out.por;
else
phi = 0;
end
%[Cp(iconv), alpha_K(iconv)] = getCpIce(P_MPa(iconv),T_K(iconv-1),1);
if phase(iconv)==1 % if water ice, use SeaFreeze otherwise use Helgeurd.
cpout=SeaFreeze([P_MPa(iconv),T_K(iconv-1)],'Ih');
alpha_K(iconv)=cpout.alpha;
Cp(iconv)=cpout.Cp;
else
cpout=Helgerud_sI(P_MPa(iconv),T_K(iconv-1));
[Cp(iconv) alpha_K(iconv)]= getCpIce(P_MPa(iconv),T_K(iconv-1),phase(iconv)) ;
alpha_K(iconv)=cpout.alpha; % use better alpha
end
%aK = 1.56e-4; % thermal expansive? Switch and use SeaFreeze ( find clath values()
%T_K(iconv) = T_K(iconv-1)+alpha_K(iconv).*T_K(iconv)./Cp(iconv)./rho_kgm3(iconv)*deltaP*1e6;
% The line above replaced with the below if/else per A. Marusiak 2023-01-21
if n_clath>0
T_K(iconv)=Tc(iT);
else
T_K(iconv) = T_K(iconv-1)+alpha_K(iconv).*T_K(iconv)./Cp(iconv)./rho_kgm3(iconv)*deltaP*1e6;
end
% double check temperatures make sense
if strcmp(Planet.Ocean.comp,'NH3')
phase_test = getIcePhase(P_MPa(iconv),T_K(iconv-1),wo,Planet.Ocean.comp);%p = 0 for liquid, I for I, 2 for II, 3 for III, 5 for V and 6 for VI
else
phase_test=SF_WhichPhase([P_MPa(iconv),T_K(iconv)]);
end
if phase_test==0 % & n_clath>0
Planet.Tb_K=T_K(iconv);
%iconv=iconv-2;
Zm_break=z_m(iconv); % saves the depth at which is broked
zb_outerIce_m=Zm_break; % new ice depth is saved
Zdiff=z_m(nConvectIce)-Zm_break; % change in depth
% previous convection layer
nConvectIce=iconv;% changes the indices for convection
%make adjustments to indices n_clath+n_ice+n_ocean
%should always be the same.
n_iceI = iconv - n_clath; % new ice layer is the last index-n_clath
if n_iceI<0
n_iceI = 0; % indicates entire ice shell would be clathrates
iconv = iconv-1;
Zclath = z_m(iconv);
end
n_ocean = nsteps - n_iceI - n_clath;% adds more indices to ocean
PbI_MPa=P_MPa(iconv);
Pb_MPa=P_MPa(iconv);
% alculate parameters
% [Q_Wm2_new,deltaTBL_m_new,eTBL_m_new,Tc_new,rhoIce,alphaIce,CpIce,kIce,nu,CONVECTION_FLAG_I]=...
% ConvectionDeschampsSotin2001(Planet.Tsurf_K,Planet.Tb_K,PbI_MPa/2,zb_outerIce_m,g_ms2(1),phase(iconv)+1);
inds_deltaTBL = find(z_m(1:nConvectIce)>=z_m(nConvectIce)-deltaTBL_m);
T_K(inds_deltaTBL) = (Planet.Tb_K.^(P_MPa(inds_deltaTBL)./PbI_MPa)).*(T_K(inds_deltaTBL(1)-1).^(1-P_MPa(inds_deltaTBL)./PbI_MPa));
% %
%
deltaP = (Params.Pseafloor_MPa-Pb_MPa)/n_ocean; % in case PbMPa changed
% recalculate ocean
for il=1:n_ocean
ill=il+inds_deltaTBL(end);
% adjust for new ocean layers if necessary
P_MPa(ill) = Pb_MPa + il*deltaP;
[rho_ocean,Cp(ill),alpha_o]= fluidEOS(P_MPa(ill),T_K(ill-1),wo,Planet.Ocean.comp);
if alpha_o<=0
disp('Ocean alpha at ice interface is less than zero. adjusting temperature upward.')
disp('This means there''s a conductive layer at the interface with thickness inversely proportional to the heat flow.')
disp('The thickness is likely less than a few 100 m. See Melosh et al. 2004.')
Tnew = fzero(@(T) alphaAdjust(P_MPa(ill),T,wo,Planet.Ocean.comp),273);
disp(['The new temperature is ' num2str(Tnew) ', or delta T = ' num2str(Tnew-T_K(ill-1)) '.'])
T_K(ill)=Tnew;
else
T_K(ill) = T_K(ill-1)+ alpha_o*T_K(ill-1)./(Cp(ill))./(rho_ocean)*deltaP*1e6; %adiabatic gradient in ocean; this introduces an error, in that we are using the temperature from the previous step
end
phase(ill) = getIcePhase(P_MPa(ill),T_K(ill-1),wo,Planet.Ocean.comp);%p = 0 for liquid, I for I, 2 for II, 3 for III, 5 for V and 6 for VI
if phase(ill)==0
rho_kgm3(ill) = rho_ocean;
[rho_ocean,Cp(ill),alpha_o]= fluidEOS(P_MPa(ill),T_K(ill-1),wo,Planet.Ocean.comp);
alpha_K(ill) = alpha_o;
else
rho_kgm3(ill) = getRhoIce(P_MPa(ill),T_K(ill),phase(ill));
if ~isfield(Planet.Ocean,'fnTfreeze_K')
T_K(ill) = getTfreeze(P_MPa(ill),wo,Planet.Ocean.comp,T_K(ill-1)); %find the temperature on the liquidus line corresponding to P(k,i+nIceI); should really use a conductive profile here, but that would seem to naturally bring us back to the liquidus. Steve wants to confirm.
else
T_K(ill) = Planet.Ocean.fnTfreeze_K(P_MPa(ill),wo);
end
if T_K(ill)<T_K(ill-1)
T_K(ill) = T_K(ill-1);
end
[Cp(ill), alpha_K(ill)]= getCpIce(P_MPa(iconv),T_K(iconv-1),phase(ill)) ;
end
end
z_ocean_m=z_m(ill);
break
end
phi_hydro_frac(iconv) = phi;
end
if nconold==nConvectIce
% bottom layer of conduction, recalculates for phase at bottom
[Q_Wm2,deltaTBL_m,eTBL_m,Tc,rhoIce,alphaIce,CpIce,kIce,nu,CONVECTION_FLAG_I]=...
ConvectionDeschampsSotin2001(Planet.Tsurf_K,Planet.Tb_K,PbI_MPa/2,zb_outerIce_m,g_ms2(1),phase(iconv)+1);
inds_deltaTBL = find(z_m(1:nConvectIce)>=z_m(nConvectIce)-deltaTBL_m);
%
%
T_K(inds_deltaTBL) = (Planet.Tb_K.^(P_MPa(inds_deltaTBL)./PbI_MPa)).*(T_K(inds_deltaTBL(1)-1).^(1-P_MPa(inds_deltaTBL)./PbI_MPa));
% end
rho_kgm3(inds_deltaTBL) = getRhoIce(P_MPa(inds_deltaTBL),T_K(inds_deltaTBL),phase(inds_deltaTBL));
%[Cp(inds_deltaTBL) alpha_K(inds_deltaTBL)]= getCpIce(P_MPa(iconv),T_K(iconv-1),phase(inds_deltaTBL)) ;
z_ocean_m= z_m(inds_deltaTBL(end)+1);
if POROUS_ICE
por_in.p=P_MPa(inds_deltaTBL)*1e-3;
por_in.t = T_K(inds_deltaTBL);
por_in.den = rho_kgm3(inds_deltaTBL);
if isfield(Planet,'phi_surface')
por_out = get_porosity_ice(por_in,Planet.phi_surface);
else
por_out =get_porosity_ice(por_in);
end
rho_kgm3(inds_deltaTBL) = por_out.den;
phi_hydro_frac(inds_deltaTBL) = por_out.por;
end
end
else
z_ocean_m = zb_outerIce_m;
% if nconold==nConvectIce
% % bottom layer of conduction, recalculates for phase at bottom
% [Q_Wm2,deltaTBL_m,eTBL_m,Tc,rhoIce,alphaIce,CpIce,kIce,nu,CONVECTION_FLAG_I]=...
% ConvectionDeschampsSotin2001(Planet.Tsurf_K,Planet.Tb_K,PbI_MPa/2,zb_outerIce_m,g_ms2(1),phase(iconv)+1);
%
% inds_deltaTBL = find(z_m(1:nConvectIce)>=z_m(nConvectIce)-deltaTBL_m);
% %
% %
% T_K(inds_deltaTBL) = (Planet.Tb_K.^(P_MPa(inds_deltaTBL)./PbI_MPa)).*(T_K(inds_deltaTBL(1)-1).^(1-P_MPa(inds_deltaTBL)./PbI_MPa));
% % end
% rho_kgm3(inds_deltaTBL) = getRhoIce(P_MPa(inds_deltaTBL),T_K(inds_deltaTBL),phase(inds_deltaTBL));
% %[Cp(inds_deltaTBL) alpha_K(inds_deltaTBL)]= getCpIce(P_MPa(iconv),T_K(iconv-1),phase(inds_deltaTBL)) ;
%
%
% z_ocean_m= z_m(inds_deltaTBL(end)+1);
%
% if POROUS_ICE
% por_in.p=P_MPa(inds_deltaTBL)*1e-3;
% por_in.t = T_K(inds_deltaTBL);
% por_in.den = rho_kgm3(inds_deltaTBL);
% if isfield(Planet,'phi_surface')
% por_out = get_porosity_ice(por_in,Planet.phi_surface);
% else
% por_out =get_porosity_ice(por_in);
% end
%
% rho_kgm3(inds_deltaTBL) = por_out.den;
% end
% end
end % if CONVECTION_FLAG
if Planet.EQUIL_Q
if (~isfield(Params,'NO_ICEI_CONVECTION') || Params.NO_ICEI_CONVECTION == false) && ...
(CONVECTION_FLAG_I || (isfield(Params,'FORCE_ICEI_CONVECTION') && Params.FORCE_ICEI_CONVECTION == true))
Qmantle_Wm2 = Q_Wm2;
else
Qmantle_Wm2 = Qb;
end
else
Qmantle_Wm2 = 2.2e11/4/pi/Planet.R_m^2; % this is more reasonable for radiogenic only
end
Planet.Qmantle_Wm2 = Qmantle_Wm2;
deltaP = (Params.Pseafloor_MPa-Pb_MPa)/n_ocean; %
Planet.zClath_m = Zclath;
Planet.Profile_ID = ['Ts' num2str(Planet.Tsurf_K,'%0.0f') 'Zb' strLow num2str(Planet.zb_outerIce_m,'%0.0f') ...
'mQm' num2str(1000*Planet.Qmantle_Wm2,'%0.0f') 'mWm2_CMR2p' ...
num2str(10000*Planet.Cmeasured,'%0.0f') '_' thiseos];
Planet.Profile_fname = [savefile '_' char(Planet.Profile_ID)];
% end % ~Planet.NoH2O
% Assign electrical conductivities for the ocean
if cfg.CONDUCT
k_S_m = NaN*ones(size(P_MPa));
switch Planet.Ocean.comp
case 'MgSO4'
if wo==10 && isfield(Planet.Ocean,'Electrical') && strcmp(Planet.Ocean.Electrical,'Pan2020')
% use values from Pan et al. 2020
for iTb = 1:length(Planet.Tb_K)
thisP = P_MPa(iTb,phase(iTb,:)==0);
thisT = T_K(iTb,phase(iTb,:)==0);
for iP = 1:length(thisP)
kvals(iP) = getSigmaMgSO4_Pan(thisP(iP),thisT(iP));
end
k_S_m(iTb,phase(iTb,:)==0) = kvals;
end
else
% Extrapolation from Larionov 1984 to high concentration and low
% temperature
LarionovMgSO4 = getLarionov1984MgSO4Conductivities(1);
Pextrap = LarionovMgSO4.Pextrap_MPa;
Textrap = LarionovMgSO4.Textrap_K;
k_S_m_extrap = LarionovMgSO4.k_S_m_extrap_p01m;
[Pgg,Tgg]=meshgrid(Pextrap,Textrap);
for iTb = 1:length(Planet.Tb_K)
k_S_m(iTb,phase(iTb,:)==0) = interp2(Pextrap,Textrap,k_S_m_extrap,P_MPa(iTb,phase(iTb,:)==0),T_K(iTb,phase(iTb,:)==0),'spline') * conduct_scaling_MgSO4;
end