forked from cfrankdavis/NeLoGeM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlaciation52-github.java
3975 lines (3436 loc) · 164 KB
/
Glaciation52-github.java
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
/*
* copied from FrozenRadioactiveAsteroid.java
*/
package glaciation;
/* jdk1.1.6 */
// repeat glaciations
// preliminary Earth model
// re-roganising graphics
// CZYN Cenozoic Year Numbering from Chicxulub crater 66.043 million years ago (working)
// ACS WORKING SINGLE-LAYER ATMOSPHERE MODEL
// 8.5 km atmosphere with fixed TOA display
// daily solar radiation calculations working (I hope), timestep solar gain timesteptable
// solar gain timestepTable in operation.
// variable albedo implemented
// AirMeltedIceSheet code debugged and working
// calculating pressure, internal planet gravitational acceleration
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.lang.Math;
import java.text.SimpleDateFormat;
import javax.swing.JTable;
public class Glaciation extends java.applet.Applet implements Runnable {
private Thread testThread = null;
EventHandler eventHandler;
int count, xmax, ymax;
Image offImage;
Graphics offGraphics;
Color colorpalette[] = new Color[15];
int xpoints[] = new int[4];
int ypoints[] = new int[4];
int x1, x2, y1, y2, paletteindex;
int p1, p2, p3, p4;
boolean go = true;
ItemGraphCanvas canvas1;
Image fieldImage;
Graphics fieldGraphics;
LayerDisplay layerDisplay = new LayerDisplay();
Image layerImage;
Graphics layerGraphics;
Image textImage;
Graphics textGraphics;
int layerMargin;
boolean printManager = false;
int mode = 1;
int runmode = 1;
boolean clearScreen = true;
double timeOfDay = 0.0; // time of day 0 - 23
double hoursPerDay = 10.0;
double hourstimestep = 0.5; // time step interval (hrs)
int day = 0;
int outcount = 0;
// double conductionHeatGain = 0.0;
// double subtemp[][] = new double[2][500]; // subsurface temperatures
double tcount, tsum, tmean;
int selector = 0;
int opcontrol = 2;
// asteroid additions
Asteroid asteroid;
double secondsPerYear = 31540000.0;
double scale;
double screenWidth = 400;
Dimension appletSize;
double year, century, millennium;
double currentCZYN = 66043000; // Cenozoic Tear Bumber 0 is 66 million years before 1 Jan 2000 (Chicxulub crater)
double eemianCZYN = 66043000 - 100000; // Emian interglacial
double initialRadius = 6371000;
double maxRadius = 6371000;
double initialLayerHeight = 17;
double fractionGranite = 1.0;
double heatGranite = 1E-9;
long tick = 0;
long longPeriodIndex = 0;
double previousGlaciationTotal = 0;
double glaciationTotal = 0; // counter
double glaciationPeriod = 0; // counter
double glaciationMaxPeriod = 1000; // period over which to measure glaciation
double glaciationPercent = 0; // % glaciation over glaciationMaxPeriod
boolean rollingGraphUpdated = false;
int rollingGraphWidth;
int rollingGraphHeight;
int rollingGraphStreams;
SolarRadiation sr;
double timeStepYears = 0.01;
AirMeltedIceSheet amis;
int videoWindow[][] = {
{ 360, 240, },
{ 480, 360, },
{ 640, 480, },
{ 1280, 720, },
{ 1920, 1080, }
};
public void init() {
this.enableEvents( AWTEvent.MOUSE_EVENT_MASK );
// amis = new AirMeltedIceSheet( 1000, 24, 273 + 0.1 );
// setSize( (int)screenWidth, (int)screenWidth );
screenWidth = videoWindow[1][0];
setSize( videoWindow[1][0], videoWindow[1][1] );
appletSize = this.getSize();
xmax = appletSize.width; // graphics width
ymax = appletSize.height; // graphics height
setBackground(Color.white);
count=0;
year = 0;
century = 0;
millennium = 0;
scale = videoWindow[1][0] / ( maxRadius * 2.5 );
offImage = createImage( videoWindow[1][0], videoWindow[1][0] );
offGraphics = offImage.getGraphics();
// set up textImage for text display
textImage = createImage( ( 3 * videoWindow[1][0] / 4 ), ( videoWindow[1][0] / 2 ) );
textGraphics = textImage.getGraphics();
eventHandler = new EventHandler( this );
eventHandler.insertEvent( eemianCZYN );
eventHandler.insertEvent( eemianCZYN + 15007 );
// eventHandler.insertEvent( eemianCZYN + 15018 );
currentCZYN = eventHandler.eventQueue[0];
eventHandler.printEventQueue();
System.out.println( (long)(eemianCZYN + 15018) );
// layer display setup
layerMargin = videoWindow[1][0] / 4;
layerImage = createImage( layerMargin, videoWindow[1][0] );
layerGraphics = layerImage.getGraphics();
layerDisplay.setDisplaySize( layerMargin, videoWindow[1][1] );
// rolling graph display setup
rollingGraphWidth = videoWindow[1][0] * 3 / 4;
rollingGraphHeight = videoWindow[1][1] / 2;
canvas1 = new ItemGraphCanvas( this, offGraphics, rollingGraphWidth, rollingGraphHeight, 5, true );
fieldImage = createImage( rollingGraphWidth, rollingGraphHeight );
fieldGraphics = fieldImage.getGraphics();
fieldGraphics.setColor(Color.white);
fieldGraphics.fillRect(0, 0, rollingGraphWidth, rollingGraphHeight );
canvas1.calendarLabel = "e5";
// sr = new SolarRadiation( 1367.0, 65.0, 0.00273785078713210130047912388775, 365.25 ); // daily
sr = new SolarRadiation( 1367.0, 30.0, timeStepYears, 365.25 );
// sr = new SolarRadiation( 1367.0 );
/* get displaymode */
try {
mode = Integer.parseInt( getParameter("MODE" ) );
} catch( Exception e ) {
mode = 1;
}
colorpalette[0] = new Color(000, 000, 000); // black
colorpalette[1] = new Color( 64, 64, 64); // light grey
colorpalette[2] = new Color(128, 128, 128); // mid gray
colorpalette[3] = new Color(192, 192, 192); // darke gray
colorpalette[4] = new Color(255, 255, 255); // white
colorpalette[5] = Color.RED;
colorpalette[6] = Color.ORANGE;
colorpalette[7] = Color.YELLOW;
colorpalette[8] = Color.CYAN;
colorpalette[9] = new Color( 85, 52, 52); // brown?
colorpalette[10] = new Color(135,206, 250); // sky blue
colorpalette[11] = new Color(240,240, 240); // steam
colorpalette[12] = new Color( 0, 0, 255); // blue
colorpalette[13] = new Color( 0, 0, 255); // blue
colorpalette[14] = new Color( 0, 0, 255); // blue
asteroid = new Asteroid( this, 0 );
// asteroid.setRadioactiveHeatGeneration( 2, mantle( 6371000, 3400000, 4650, 9990, 20E12 ) );
// asteroid = new Asteroid( this, 50000, 30, 2, 5000, 5000 );
asteroid.setRadioactiveHeatGeneration( 2, 2.1773010891400347E-8 );
// asteroid.setRadioactiveHeatGeneration( 2, 0 );
// asteroid.solarGain = 0;
// asteroid.printAsteroid(x1);
// System.out.println( asteroid.stefanBoltzmannHeatflow(1.0, 273 ) + " " + asteroid.stefanBoltzmannTemperature( 1.0, 314.96494193766694 ) );
double r1 = 100.0;
double r2 = 110.0;
double v = asteroid.sphereVolume(r2) - asteroid.sphereVolume(r1);
System.out.println( "r2 = " + asteroid.layerRadius( v, asteroid.sphereVolume(r1) ) );
// asteroid = new Asteroid( initialRadius, initialLayerHeight, fractionGranite, heatGranite );
System.out.println( "w/m^3= " + mantle( 6371000, 3400000, 4650, 9990, 20E12 ) );
tsum = 0.0; tcount = 0.0;
// go = false;
}
public void start() {
if (testThread == null) {
testThread = new Thread(this, "Test1");
testThread.start();
}
}
public void processMouseEvent( MouseEvent e) {
if ( e.getID() == MouseEvent.MOUSE_ENTERED ) { go = false; }
else if ( e.getID() == MouseEvent.MOUSE_EXITED ) { go = true; }
else if ( e.getID() == MouseEvent.MOUSE_RELEASED ) {
offGraphics.setPaintMode();
offGraphics.setColor( Color.white );
offGraphics.fillRect( 0, 0, xmax, ymax );
x2 = e.getX();
y2 = e.getY();
p1 = 1 + x2 % 5;
p2 = 1 + y2 % 5;
p3 = 1 + Math.abs( x2-y2 ) % 5;
p4 = 1 + (x2 + y2) % 6;
go = true;
}
else super.processMouseEvent(e);
System.out.println("The line number is " + new Exception().getStackTrace()[0].getLineNumber());
Object o = this;
Class c = o.getClass();
System.out.println("class name is: " + c.getName());
System.out.println("method name is: " + new Exception().getStackTrace()[0].getMethodName());
System.out.println("calling method name is: " + Thread.currentThread().getStackTrace()[2].getMethodName());
// System.out.println("The class name is " + java.lang.Class.getSimpleName() );
}
public void run() {
runmode = mode;
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
Thread myThread = Thread.currentThread();
while (testThread == myThread) {
if ( go ) {
mathEngine();
if ( opcontrol == 2 ) {
// clearScreen = true;
// repaint();
}
runmode++; // change display graph mode
if ( runmode > 5) { runmode= 0; }
count++;
}
try {
Thread.sleep(1);
} catch (InterruptedException e){ }
}
}
void mathEngine() {
// double y, ytimestep = 0.01;
double y, ytimestep = this.timeStepYears;
double printIinterval = 25000;
double printDate = printIinterval;
int nlayer;
double meltingRadius, boilingRadius;
int someTimePeriod = 100;
// do eventchecking first
eventHandler.checkEventQueue();
// System.out.println( "CZYN = " + (long)currentCZYN );
// with ytimestep=0.01, 100 * period = 1.0 year
someTimePeriod = (int)( 1.0 / ytimestep );
for ( int period=0; period < someTimePeriod; period++ ) {
if ( period%10 == 0 ) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
String str = sdf.format(date);
}
year += ytimestep; // time step monthly
century = year / 100.0;
millennium = year / 1000.0;
// find new temperatures
asteroid.getNewLayerTemperatures( ( this.secondsPerYear * ytimestep ), year, 600000, 0.5 );
tick++;
y = (int)( year * 10 ); // get a single decimal place
}
currentCZYN++;
}
void rollingGraphOutput( double interval) {
String s;
int maxn = 5;
canvas1.day = (int)(interval);
// canvas1.calendarStep = (int)(interval*10); // years per pixel
canvas1.calendarStep = 1000; // years per pixel
double maxtemp = 500;
canvas1.nexty[0] = asteroid.lastSurfaceTemperature;
s = "Ts";
canvas1.setStreamLabel(0, s);
canvas1.setStreamMaxMin( 0, maxtemp, 0 );
/*
canvas1.nexty[1] = Math.abs( asteroid.surfaceRockHeatFlowRate * 100);
// System.out.println( "heat flow " +asteroid.surfaceRockHeatFlowRate );
s = "hFl" ;
canvas1.setStreamLabel(1, s);
canvas1.setStreamMaxMin( 1, maxtemp, 0 );
*/
canvas1.nexty[1] = Math.abs( asteroid.airLowestBandTemperature );
s = "Ta" ;
canvas1.setStreamLabel(1, s);
canvas1.setStreamMaxMin( 1, maxtemp, 0 );
canvas1.nexty[2] = asteroid.surfaceRockTemperature;
s = "T" + Integer.toString(1);
canvas1.setStreamLabel(2, s);
canvas1.setStreamMaxMin( 2, maxtemp, 0 );
canvas1.nexty[3] = asteroid.iceWaterDepth;
// System.out.println( "asteroid.iceDepth " + asteroid.iceDepth );
// canvas1.nexty[3] = glaciationPercent;
s = "ice";
canvas1.setStreamLabel(3, s);
canvas1.setStreamMaxMin( 3, maxtemp * 10, 0 );
canvas1.nexty[4] = asteroid.atmosphereTemperature;
s = "Ta" ;
canvas1.setStreamLabel(4, s);
canvas1.setStreamMaxMin( 4, maxtemp, 0 );
}
// given 20 terawatt Earth radioactive heat gain (in mantle) find heat production per kg of mantle material
double mantle( double rAsteroid, double rCore, double densityMantle, double densityCore, double totalRadioactiveHeat ) {
double vAsteroid = 1.33333 * Math.PI * rAsteroid * rAsteroid * rAsteroid;
double vCore = 1.33333 * Math.PI * rCore * rCore * rCore;
double vMantle = vAsteroid - vCore;
double massCore = densityCore * vCore;
double massMantle = densityMantle * vMantle; // target mass 4 E 24 Kg
double heatPerCubicMetre = totalRadioactiveHeat / vMantle;
double heatPerKilogram = totalRadioactiveHeat / massMantle;
System.out.println( "massCore " + massCore + " massMantle " + massMantle + " heatPerCubicMetre " + heatPerCubicMetre );
return( heatPerCubicMetre );
}
public void paint(Graphics g) {
update(g);
// paintAsteroid( g );
// canvas1.paint(g);
}
public void update( Graphics g ) {
int n, bradius, nlayers;
long lyear;
int xcentre, ycentre, xtopleft, ytopleft, hr;
double topRadiusMaterial[] = new double[10];
if ( rollingGraphUpdated ) {
canvas1.paint( fieldGraphics );
this.rollingGraphUpdated = false;
} else {
// System.out.println( "roling graph not updated ");
}
// extract date from graphicLayer array of layer data
n = 0;
int material = -1;
while ( asteroid.graphicLayer[n][0] >= 0 ) {
if ( asteroid.graphicLayer[n][1] != material ) {
material = (int)asteroid.graphicLayer[n][1];
topRadiusMaterial[ material ] = asteroid.graphicLayer[n][2];
}
n++;
}
nlayers = n;
offGraphics.setPaintMode();
if ( clearScreen ) {
offGraphics.setColor( Color.white );
offGraphics.fillRect( 0, 0, xmax, ymax/2 ); // only clear top half of offImage
}
lyear = (long)year;
// display screen text
textGraphics.setPaintMode();
textGraphics.setColor( Color.white );
textGraphics.fillRect( 0, 0, xmax, ymax );
textGraphics.setColor( Color.black );
int px = 15;
textGraphics.drawString( "CZYN " + (float)(currentCZYN - eemianCZYN), 2, px );
px += 15;
textGraphics.drawString( "Thin Surface " + asteroid.thinSurfaceBand + " T=" + (float)asteroid.thinSurfaceBandTemperature, 2, px );
px += 15;
textGraphics.drawString( "Rock " + (int)asteroid.surfaceRockBand + " hfr=" + (float)asteroid.surfaceRockHeatFlowRate, 2, px );
px += 15;
textGraphics.drawString( "IceWater Depth " + (float)asteroid.iceWaterDepth, 2, px );
px += 15;
double var;
boolean showTemperatures = true;
for ( n=asteroid.graphicSurfaceRockBand; n<asteroid.graphicLayerCount; n++ ) {
if ( asteroid.graphicLayer[n][0] >= 0 ) {
if ( showTemperatures ) {
var = asteroid.graphicLayer[asteroid.graphicLayerCount-n-1][4];
} else {
// show conductive heat flows to layer above
var = asteroid.graphicLayer[asteroid.graphicLayerCount-n-1][6];
}
textGraphics.drawString( "" + (int)asteroid.graphicLayer[asteroid.graphicLayerCount-n-1][1] + "band " + n + " T" + (int)asteroid.graphicLayer[asteroid.graphicLayerCount-n-1][0] + "= " + (float)var, 2, px );
px += 15;
}
}
// paintTemperatureGraph( xtoa, jscale );
// paint the asteroid layers into layerImage
layerDisplay.paint( layerGraphics, asteroid, topRadiusMaterial[ 2 ] );
// draw the layerimage into top left corner of offImage
offGraphics.drawImage( layerImage, 0, 0, this );
// draw the textImage offset into offImage
offGraphics.drawImage( textImage, layerMargin, 0, this );
// draw the rolling graph fieldImage offset into offImage
offGraphics.drawImage( fieldImage, layerMargin, ymax/2, this );
g.drawImage( offImage, 0, 0, this );
}
Color setColour( int index ) {
Color colour = Color.white;
if ( index == 1 ) colour = Color.black;
if ( index == 2 ) colour = Color.darkGray;
if ( index == 3 ) colour = Color.lightGray;
if ( index == 4 ) colour = Color.cyan;
return( colour );
}
/*
Color setColour( int index , double temperature ) {
Color colour = Color.white;
Material mt = new Material( index );
int cindex = 0;
if ( temperature > mt.phaseTemperature1 ) cindex = 1;
if ( temperature > mt.phaseTemperature2 ) cindex = 2;
colour = colorpalette[ mt.colourIndex[ cindex ] ];
// if ( index == 1 ) colour = Color.black;
// if ( index == 2 ) colour = Color.darkGray;
return( colour );
}
*/
Color setColour( int index, double phase ) {
Color colour = Color.white;
Material mt = new Material( index );
int cindex = 0;
if ( phase == 1 ) cindex = 1;
if ( phase == 2 ) cindex = 2;
colour = colorpalette[ mt.colourIndex[ cindex ] ];
return( colour );
}
int scaleRadius( double r, double jscale ) {
int pixelHeight = (int)( r * jscale );
return( pixelHeight );
}
//
public void stop() {
testThread = null;
}
}
class Asteroid {
Glaciation ap;
// planet Earth
// material type T = 1, iron?, T = 2, rock, T= 3 ice, (T = 4 WAS water,) T = 5 air
double[][] layers = {
// 0 1 2 3 4 5 6 7 8 9
// n, h, k, s.h, d, d K, MT,
{ 2, 610750, 2.12, 790, 12800, 7000, 6, 0, 0, 6371500 }, // 0 inner core
{ 8, 281250, 2.12, 790, 9900, 5000, 7, 0, 0, 6371500 }, // 0 outer core
{ 8, 224000, 2.12, 790, 4400, 4000, 8, 0, 0, 6371500 }, // 2 lower mantle
{ 4, 227000, 2.12, 790, 3400, 3000, 9, 0, 0, 6371500 }, // 2 upper mantle
{ 5, 25000, 2.12, 790, 2650, 1800, 1, 0, 0, 6371500 }, // 3 asthenosphere
{ 4, 6250, 2.12, 790, 2650, 1500, 2, 0, 0, 6371500 }, // 3 lithosphere
{ 15, 2000, 2.12, 790, 2650, 1200, 2, 0, 0, 6371500 }, // 3 lithosphere
{ 18, 1000, 2.12, 790, 2650, 600, 2, 0, 0, 6371500 }, // 3 lithosphere
{ 4, 500, 2.12, 790, 2650, 400, 2, 0, 0, 6371500 }, // 3 lithosphere
{ 1, 0, 2.12, 790, 2650, 288, 0, 0, 0, 6371500 }, // 5 thin surface layer
{ 1, 8500, 0.0243, 1000, 1.29, 243, 5, 0, 0, 6371500 }, // 5 atmospheric air
{ 1, 8500, 0.0243, 1000, 1.29, 243, 5, 0, 0, 6371500 }, // 6 dummy atmospheric air (troposphere)
{ -1, }
};
// 30 asteroid lsyer temperatures after 2.6 million years
double[] temps = {
300.13, 536.8, 771.2, 1006.0, 1240.2, 1473.5, 1705.7, 1935.4, 2163.6, 2388.8,
2609.1, 2824.9, 3033.8, 3235.0, 3430.8, 3616.7, 3793.8, 3960.4, 4117.9, 4262.5,
4396.5, 4436.0, 4552.5, 4656.3, 4746.4, 4822.5, 4883.6, 4928.7, 4955.5, 4955.5,
};
// 30 asteroid lsyer temperatures after 1.5 million years
double[] temps1 = {
420.13, 708.8, 970.2, 1229.0, 1488.2, 1746.5, 2001.7, 2254.4, 2501.6, 2741.8,
2974.1, 3197.9, 3411.8, 3613.0, 3804.8, 3982.7, 4146.8, 4295.4, 4430.9, 4549.5,
4653.5, 4741.0, 4815.5, 4874.3, 4919.4, 4953.5, 4975.6, 4989.7, 4996.5, 4996.5,
};
// 30 asteroid lsyer temperatures after 1.5 million years
double[] temps2 = {
276.88, 487.35, 690.75, 886.22, 1074.8, 1258.7, 1440.0, 1620.2, 1800.1, 2323.6,
2159.0, 2337.6, 2514.8, 2690.2, 2863.4, 3034.2, 3202.2, 3366.9, 3527.8, 3684.5,
3836.2, 3982.2, 4121.6, 4253.3, 4375.7, 4486.8, 4583.8, 4662.0, 4712.5, 4712.5,
};
// 30 asteroid lsyer temperatures after 1.8 million years
double[] temps3 = {
275.16, 485.28, 702.23, 924.87, 1151.9, 1382.0, 1613.6, 1845.2, 2082.0, 2323.6,
2561.4, 2793.8, 3019.4, 3237.0, 3445.4, 3643.5, 3830.6, 4005.6, 4167.8, 4316.4,
4450.7, 4570.3, 4674.7, 4763.6, 4837.2, 4895.7, 4939.8, 4970.4, 4988.9, 5000.0,
};
double radius;
double nominalRadius; // radius used in graphic display
int nlayers;
LinkedList<ConductiveLayer> llayer = new LinkedList<ConductiveLayer>();
double initialTemperatureK;
int nIterations = 0;
double referenceRadius = 6371000.0; // earth radius
int surfaceBand; // surface band for solar irradiation
int thinSurfaceBand; // thin radiative surface band number
double thinSurfaceBandTemperature; // thin radiative surface band temperature
int airLowestBand; // bottom layer of air in atmospher
double airLowestBandTemperature; // temperature of bottom layer of air
double surfaceBandTemperature;
double lastSurfaceTemperature;
double surfaceRockHeatFlowRate;
double surfaceRockTemperature = 0;
double atmosphereTemperature;
int surfaceRockBand;
double surfaceHeatFlowRate = 0;
double year;
double graphicLayer[][] = new double[2000][10]; // date for graphics display
int graphicLayerCount = 0; // data for grapjic display
int graphicSurfaceRockBand = 0; // data for graphic display
boolean resynchronise = true;
double annualSolarInsolation = 1362 * 3.6E6; // annual solar radiation kwh-> J UK
double solarGain; // solar gain Watts
double albedo = 0.3; // mean Earth albedo
double secondsPerYear = 3.154e+7;
double iceDepth = 0;
double iceWaterDepth = 0;
boolean printFlag = true;
double surfaceArea; // surface area of asteroid
double mass; // mass of asteroid (earth 5.972 × 10^24 kg)
double atmosphereMass; // (earth 5.1480×10^18 kg)
double topOfAtmosphere;
int topLayerOfAtmosphere;
double surfaceGravity = 9.81; // surface gravitaional acceleration (should be calculated)
Asteroid() { }
Asteroid( Glaciation a ) {
ap = a;
int i, n = 0;
double layerTemperature, layerTemperatureChange = 0;
double wLayer, rLayer = 0;
double mt, hLayer;
double totalMass = 0;
boolean atmosphereFound = false;
ConductiveLayer layer;
ACSalgebra();
// solarGain = annualSolarInsolation / secondsPerYear;
solarGain = 342.0; // mean terrestrial solar radiation
System.out.println( solarGain + "watts solar gain ");
referenceRadius = layers[0][9];
topOfAtmosphere = referenceRadius;
this.surfaceArea = this.sphereSurfaceArea( referenceRadius );
this.nlayers = 0;
// build asteroid from centre outwards
while ( layers[n][0] >= 0 ) {
// initialise with linear temperature changes
if ( n > 0 ) {
layerTemperatureChange = ( layers[n][5] - layers[n-1][5] ) / layers[n][0];
layerTemperature = layers[n-1][5] + layerTemperatureChange;
} else {
layerTemperature = layers[n][5]; // core temperature
}
System.out.println( (n) + " layerTemperatureChange " + layerTemperatureChange );
System.out.println( layers[n][0] );
hLayer = layers[n][1];
// initialTemperatureK = layerTemperature;
for ( i=0; i<layers[n][0]; i++ ) {
rLayer = rLayer + hLayer;
wLayer = rLayer / referenceRadius; // layer width assumes top surface layer width = 1 metre
mt = layers[n][6];
// if ( mt == 3.0 && layerTemperature > 273 ) mt = 4.0;
// if ( mt == 4.0 && layerTemperature < 273 ) mt = 3.0; // no longer using 4 for water
// radius. width, height, temp, material index
layer = new ConductiveLayer( rLayer, wLayer, hLayer, layerTemperature, mt, 0 );
llayer.addFirst( layer );
this.nlayers++;
layerTemperature += layerTemperatureChange;
if ( mt == 5 ) {
topOfAtmosphere += layer.height;
topLayerOfAtmosphere = layer.nBand;
// single layer atmosphere is first air mass found
if ( !atmosphereFound ) {
System.out.println( "atmosphere mass " + (layer.mass * this.surfaceArea) + " Kg asteroid mass " + (totalMass * this.surfaceArea) + " Kg" );
atmosphereFound = true;
}
}
totalMass += layer.mass;
}
n++;
}
this.nominalRadius = rLayer;
reSynchronise();
setGeothermalGradient( 289, 25.0, 50.0 );
reSynchronise();
setExponentialTemperatures( 900, 6000, 426 );
this.setLayerPhases();
printAsteroid( 0 );
printAsteroidRC( 0 );
// for ( n=1; n<=10; n++ ) {
// System.out.println( n + ": " + exrponentialTemperature( 6000, (double)( n * 150 ), 20 ) );
// }
}
// variant of above that uses table layer heights and densities to find layer masses
Asteroid( Glaciation a, int j ) {
ap = a;
int i, n = 0;
double layerTemperature, layerTemperatureChange = 0;
double wLayer, rLayer = 0;
double mt, hLayer;
double totalMass = 0;
boolean atmosphereFound = false;
ConductiveLayer layer;
ACSalgebra();
// solarGain = annualSolarInsolation / secondsPerYear;
solarGain = 342.0; // mean terrestrial solar radiation
System.out.println( solarGain + "watts solar gain ");
referenceRadius = layers[0][9];
topOfAtmosphere = referenceRadius;
this.surfaceArea = this.sphereSurfaceArea( referenceRadius );
this.nlayers = 0;
// build asteroid from centre outwards
while ( layers[n][0] >= 0 ) {
// initialise with linear temperature changes over multiple layers with same temperature
if ( n > 0 ) {
layerTemperatureChange = ( layers[n][5] - layers[n-1][5] ) / layers[n][0];
layerTemperature = layers[n-1][5] + layerTemperatureChange;
} else {
layerTemperature = layers[n][5]; // core temperature
}
System.out.println( (n) + " layerTemperatureChange " + layerTemperatureChange );
System.out.println( layers[n][0] );
hLayer = layers[n][1];
// initialTemperatureK = layerTemperature;
for ( i=0; i<layers[n][0]; i++ ) {
rLayer = rLayer + hLayer;
wLayer = rLayer / referenceRadius; // layer width assumes top surface layer width = 1 metre
mt = layers[n][6];
// if ( mt == 3.0 && layerTemperature > 273 ) mt = 4.0;
// if ( mt == 4.0 && layerTemperature < 273 ) mt = 3.0; // no longer using 4 for water
// radius. width, height, temp, material index
layer = new ConductiveLayer( rLayer, wLayer, hLayer, layerTemperature, mt, 0 );
llayer.addFirst( layer );
this.nlayers++;
layerTemperature += layerTemperatureChange;
if ( mt == 5 ) {
topOfAtmosphere += layer.height;
topLayerOfAtmosphere = layer.nBand;
// single layer atmosphere is first air mass found
if ( !atmosphereFound ) {
System.out.println( "atmosphere mass " + (layer.mass * this.surfaceArea) + " Kg asteroid mass " + (totalMass * this.surfaceArea) + " Kg" );
atmosphereFound = true;
}
}
totalMass += layer.mass;
}
n++;
}
this.nominalRadius = rLayer;
reSynchronise();
// set 25 degree/km temperature gradient to depth 50 km
setGeothermalGradient( 289, 25.0, 50.0 );
reSynchronise();
setExponentialTemperatures( 900, 6000, 426 );
this.setLayerPhases();
printAsteroid( 0 );
printAsteroidRC( 0 );
System.out.println( "entire asteroid mass " + this.massOfEntireAsteroid() );
printWholeAsteroid();
redimensionLayers();
// findNonTaperingLayerPressures( 1.0 );
// for ( n=1; n<=10; n++ ) {
// System.out.println( n + ": " + exrponentialTemperature( 6000, (double)( n * 150 ), 20 ) );
// }
}
// construct a spherical asteroid of radius r with nlayers from material mt
Asteroid( Glaciation a, double radius, int numLayers, double mt, double coreTemperatureK, double surfaceTemperatureK ) {
int n;
double rLayer, hLayer, wLayer, lastrLayer;
ConductiveLayer layer;
double layerTemperatureK = coreTemperatureK;
double tstep = ( coreTemperatureK - surfaceTemperatureK ) / (double)(numLayers-1);
double radiusLayer0 = equalLayerVolumeSphere( numLayers, radius );
double volumeLayer0 = sphereVolume( radiusLayer0 );
ap = a;
rLayer = 0;
lastrLayer = 0;
for ( n=0; n<numLayers; n++ ) {
rLayer = radiusConstantVolumeLayer( n, volumeLayer0 );
hLayer = rLayer - lastrLayer;
wLayer = rLayer / radius; // layer width assumes top surface layer width = 1 metre
layer = new ConductiveLayer( rLayer, wLayer, hLayer, layerTemperatureK, mt, 0 );
// layer.volume = volumeLayer0; // overwrite calculated volume
llayer.addFirst( layer );
layerTemperatureK -= tstep;
lastrLayer = rLayer;
}
this.nominalRadius = rLayer;
this.referenceRadius = this.nominalRadius;
System.out.println( "referenceRadius " + referenceRadius + " nominalRadius " + nominalRadius);
System.out.println( "asteroid slice mass " + this.massOfAllLayers() );
System.out.println( "asteroid mass " + this.massOfEntireAsteroid() );
this.setLayerTemperatures( temps1, 1.00 );
// add ice or water
rLayer += 20;
hLayer = rLayer - lastrLayer;
wLayer = rLayer / radius; // layer width assumes top surface layer width = 1 metre
layer = new ConductiveLayer( rLayer, wLayer, hLayer, 270, 3, 0 );
llayer.addFirst( layer );
// dummy top layer
rLayer += 1000; // air
hLayer = rLayer - lastrLayer;
wLayer = rLayer / radius; // layer width assumes top surface layer width = 1 metre
layer = new ConductiveLayer( rLayer, wLayer, hLayer, 276, 5, 0 );
llayer.addFirst( layer );
reSynchronise();
System.out.println( "this.surfaceRockBand " + this.surfaceRockBand);
// addLayer( this.surfaceRockBand+1, 273, 0, 0);
addLayer( 30+1, 273, 0, 0);
reSynchronise();
System.out.println( "meanAsteroidTemperature " + meanAsteroidTemperature() );
System.out.println( "constant layer volume asteroid complete " );
printAsteroid( 0 );
// divide 561.839 m top rock layer into 5 layers each 112.267 m high
// divideLayerIntoMultipleLayers( 29, 5 );
// divide 1129 m top rock layer into 7 layers each 16 m high
// equal in resistance to 25 m ice
// divideLayerIntoMultipleLayers( 33, 7 );
// recalculateRadii( 0 );
// recalculateRadii( 0 );
// System.out.println( "radii recalculated " );
this.setLayerPhases();
System.out.println( "ice index 100K " + layer.material.indexIceTemperature( 100 ) );
System.out.println( "ice index 150K " + layer.material.indexIceTemperature( 150 ) );
System.out.println( "ice index 200K " + layer.material.indexIceTemperature( 200 ) );
printAsteroidRC( 0 );
}
// find all condutctive heat flows
// using link list iterator
void getNewLayerTemperatures( double interval, double y, double snowStartYear, double snowDepthPerYear ) {
int removeLayer = -1;
this.year = y;
int n, bmax, bmin, i;
boolean flag = false;
double heatflowrate, heatgain, dtemp, tmax, tmin, hfr, effectiveTemperature;
ConductiveLayer lyr[] = new ConductiveLayer[3];
int counter = 0;
ListIterator<ConductiveLayer> itr = null;
// get the top 3 layers
// layer 0 is a dummy floating layer
heatflowrate = 0.0;
itr = llayer.listIterator();
if ( itr.hasNext() ) {
lyr[0] = itr.next();
counter++;
}
// layer 1 is a layer of air
if ( itr.hasNext() ) {
lyr[1] = itr.next();
counter++;
}
// layer 2 is either a layer of water or ice or rock
// lyr[] contains layer[n-1], layer[n], layer[n+1] for all layers
while(itr.hasNext()){
lyr[2] = itr.next();
counter++;
// here come the heat flow calculations
heatflowrate = 0.0;
lyr[0].layerResistance();
lyr[1].layerResistance();
lyr[2].layerResistance();
if ( lyr[1].materialType == 0 ) {
solarGain = ap.sr.getNextSolarGain() / interval;
// if thin surface layer albedo < 0, use albedo of layer below
this.albedo = Math.abs( lyr[1].material.albedo );
if ( lyr[1].material.albedo < 0 ) {
this.albedo = Math.abs( lyr[2].material.albedo );
}
// surface layer coducts heat to layer below, and radiates to layer above
// iterative solution for radiative surface temperature Ts
double tparam;
double newsense = 1.0;
double oldsense = 1.0;
double tstep = 10.0;
int timeout = 100;
double ts = lyr[1].currentTemperatureK;
double difference = -surfaceHeatFlowRate( lyr[0], lyr[1], lyr[2], lyr[1].currentTemperatureK );
if ( difference >= 0.0 ) { newsense = -1.0; } else { newsense = 1.0; }
oldsense = newsense;
while ( Math.abs( difference ) > 0.01 ) {
ts += tstep * oldsense;
tparam = ts;
difference = -surfaceHeatFlowRate( lyr[0], lyr[1], lyr[2], tparam );
// System.out.println( "difference " + difference + " oldsense " + (int)oldsense + " tstep " + tstep + " ts " + ts );
// if ( printFlag ) System.out.println( ts + " hfr " + difference + " step " + tstep );
if ( difference >= 0.0 ) { newsense = -1.0; } else { newsense = 1.0; }
if ( newsense != oldsense ) { oldsense = newsense; tstep = 0.1 * tstep; }
if ( timeout-- < 0 ) {
difference = 0.0;
System.out.println( "surface iteration timeout " );
ts = lyr[1].currentTemperatureK;
}
}
this.lastSurfaceTemperature = ts;
lyr[1].nextTemperatureK = ts;
printFlag = false;
} else if ( lyr[1].materialType == 5 ) {
// ACS single layer atmosphere
// radiative heat exchanges from atmospheric air
heatflowrate = 0;
// heat radiated from surface below
heatflowrate += lyr[1].material.emissivity * wattsRadiated( lyr[2].currentTemperatureK, 1.0 );
// heat radiated to surface below and to space
heatflowrate -= 2.0 * wattsRadiated( lyr[1].currentTemperatureK, lyr[1].material.emissivity );
// find heat gain over timestep
heatgain = heatflowrate * interval;
// find change in temperature due to heat gain.
dtemp = heatgain / ( lyr[1].mass * lyr[1].layerSpecificHeat );
lyr[1].nextTemperatureK = lyr[1].currentTemperatureK + dtemp;
} else if ( lyr[1].materialType > 0 ) {
// while layer phase change is in process, currentTemperatureK is fixed, and
// phaseTemperature is used instead until phase change is complete
if ( lyr[1].phaseChange ) {
effectiveTemperature = lyr[1].pseudoTemperatureK;
} else {
effectiveTemperature = lyr[1].currentTemperatureK;
}
// conductive heat transfer
// heat flow rate rate from higher layer 0 to layer 1
heatflowrate += conductiveHeatFlow( lyr[1], lyr[0].layerResistance, lyr[1].layerResistance, lyr[0].currentTemperatureK, effectiveTemperature );
lyr[1].upwardHeatFlowRate = heatflowrate;
if ( lyr[1].nBand == this.surfaceRockBand ) this.surfaceRockHeatFlowRate = heatflowrate;
// heat flow rate from lower layer layer 2 to layer 1
heatflowrate += conductiveHeatFlow( lyr[1], lyr[2].layerResistance, lyr[1].layerResistance, lyr[2].currentTemperatureK, effectiveTemperature );
heatflowrate += lyr[1].heatProduced; // radioactive heat production in layer
// find heat gain over timestep
heatgain = heatflowrate * interval;
// find change in temperature due to heat gain.
dtemp = heatgain / ( lyr[1].mass * lyr[1].layerSpecificHeat );
// set the next layer temperature that will replace current layer tmperature
// during a phase change, hold next temperature constant, while varying phase temperature
if ( lyr[1].phaseChange ) {
lyr[1].pseudoTemperatureK = lyr[1].pseudoTemperatureK + dtemp;
lyr[1].nextTemperatureK = lyr[1].phaseTemperatureK;
} else {
lyr[1].nextTemperatureK = lyr[1].currentTemperatureK + dtemp;
}
// catch any phase change btween current temperature and next temperature
lyr[1].phaseSum = phaseCheck( lyr[1].phaseSum, lyr[1], lyr[1].currentTemperatureK, lyr[1].nextTemperatureK );
}
// roll layers up
lyr[0] = lyr[1];
lyr[1] = lyr[2];
}
// now copy next temperatures to current temperatures
// and perform other housekeeping tasks
double asteroidRadius = 0;
counter = 0;
itr=llayer.listIterator();
while(itr.hasNext()){
lyr[0] = itr.next();
// set current temperature of layer