-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpyko.py
More file actions
3621 lines (3600 loc) · 211 KB
/
pyko.py
File metadata and controls
3621 lines (3600 loc) · 211 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
pyKO 1D HYDROCODE
Based on Mark Wilkins, Computer Simulation of Dynamic Phenomena, Springer-Verlag, 1999
Adapted from John Borg's Fortran KO code v11
PROGRAM DOCUMENTATION
https://impactswiki.github.io/pyko/
PROGRAM REPOSITORY
https://github.com/ImpactsWiki/pyko
AUTHOR
Created on Wed Jan 25 08:05:24 2023
@author: S. T. Stewart, U. California Davis
LICENSE
GNU General Public License v3.0
CHANGELOG
see CHANGELOG.md in GitHub repo
VERSIONS
2023-07-05: v0.6.x in progress adding plastic strain and SG strength model
2023-07-04: v0.6.1 - added temperatures to TIL and MGR EOS models. Bug fixes.
2023-06-27: v0.6 first public release for beta testing
"""
##############################################################
# IMPORT PYTHON MODULES
import numpy as np
from copy import deepcopy
from numpy import sqrt as npsqrt
from numpy import power as nppower
from numpy import where as npwhere
from numpy import absolute as npabs
from numpy import sum as npsum
import re
import sys
from os import system
from os.path import exists
import eos_table as etab # Stewart group EOS table libraries for ANEOS and Tillotson
import time
import pickle
from dataclasses import dataclass
import yaml
import pint
# see https://pint.readthedocs.io/en/develop/advanced/performance.html for ways to speed up performance with pint
#ureg = pint.UnitRegistry(cache_folder=":auto:")
ureg = pint.UnitRegistry()
Q_ = ureg.Quantity
#
# Silence NEP 18 warning
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Q_([])
#
# GLOBAL VARIABLE
__version__ = 'v0.6.x-dev-2023-07-05'
#
##############################################################
# KO CODE UNITS FROM WILKINS BOOK
#
# eu = energy unit = 10^12 ergs = 100 kJ
# rho = density = g/cm3 = 1000 kg/m3
# vr = relative volume [to initial state] = dimless
# iev0 = internal energy per original volume = eu/g*rho0 = eu/cm3 = 100 GJ/m3
# time = time = microseconds = 1e-6 seconds
# x,y = space coordinates = cm = 1.e-2 m
# xdot, ydot = velocity = cm/microsec = 10 km/s
# temp = temperature = K
# p = pressure = Mbar = 1e12 dynes/cm3 = 100 GPa
# cv = specific heat at constant volume = eu*rho0/(g K) = eu/(k cm3) = 100 GJ/K/m3
#
##############################################################
# Main CLASSES
#
# EOS names
# 'MGR' Mie-Gruneisen EOS
# 'IDG' ideal gas EOS
# 'TIL' Tillotson EOS
# 'SES' STD+EXT SESAME tables - needs Stewart Group eos_table.py module
#
# Constitutive model names
# 'HYDRO' Hydrodynamic; shear modulus=0
# 'VM' Von Mises Yield
# 'SG' Steinberg-Guinan strength model v0.6.2+
# more strength models coming later
# Dynamic fracture and void closure is implemented in v0.5+
#
# Boundary Condition names
# 'FREE' for free surface p=pvoid
# 'FIXED' for fixed surface up=0
#
# Gravity
# Gravitational acceleration implemented in v0.5+
#
#------------------
class RunClass:
""" top level information for the calculation in pyKO """
def __init__(self,fin='config.yml',fout='output.dat',ftype='YAML'):
self.inputfiletype = ftype # YAML OR BORG for comparison to fortran
self.inputfilename = fin # name of input file, string
self.outputfilename = fout # name of output file, string
self.tstop = 0. # time in microseconds, double
self.ncount = 0 # count for number of time steps, integer
self.nmat = 0 # number of material layers, integer
self.ieosid = [] # material EOS flag using tag names, list of strings length nmat
self.ieos = [] # list to hold EOS parameter objects, list length nmat
self.inodes = np.zeros(0,dtype=int) # number of nodes for each material, intarray length nmat = 2xspatial cells
self.ilength = np.zeros(0) # length of each layer, cm
self.ixstart = np.zeros(0) # initial left position of each layer, cm
self.iupstart = np.zeros(0) # initial particle velocity of each layer, cm/us
self.irhostart = np.zeros(0) # initial density of each layer, g/cm3
self.ipstart = np.zeros(0) # initial pressure of each layer, Mbar
self.itempstart = np.zeros(0) # initial temperature of each layer, Mbar
self.iiev0start= np.zeros(0) # initial internal energy per original volume of each layer, 1e12 erg/cm3
self.istrid = [] # material constitutive model names, list of strings length nmat
self.istr = [] # list to hold strength parameter objects, list length nmat
self.ifrac = [] # list to hold fracture parameter objects, list length nmat
self.nbc = [] # number of initial boundary conditions, integer
self.ibcid = [] # initial boundary conditions, at least [left, right]; can be more interfaces; list of strings
self.ibc = [] # parameters for each boundary condition
self.grav = GravityClass() # gravity parameters
self.dtstart = 0.001 # initial time step for fKO comparison
self.dtmin = 1.e-9 # DEBUG later add a check for too small time steps to halt the calculation
self.pvoid = 0. # require for input for now
self.dgeom = 0. # geometry d is DOUBLE (used in math)
self.dflag = '' # geometry is a string for boolean checks
# 'PLA' or 'CYL' or 'SPH'
self.avcl = 1. # artificial viscosity C_L
self.avc0 = 2. # artificial viscosity C_0
self.step_skip = -1 # number of steps to skip for output file dumps
self.time_skip = 0.0 # default for fKO comp; dt between data dumps, microsec
self.next_time_dump = self.time_skip #
self.outputsteps = np.zeros(0,dtype=int) #
self.outputtimes = np.zeros(0) #
self.outputietot = np.zeros(0)
self.outputketot = np.zeros(0)
self.outputmvtot = np.zeros(0)
# Debugging and feature flags
self.tstepscale = 6 # reduces the time step by this factor; 6 ok for plate impacts; 1 ok for ideal gas sod test
self.debugflag = False # optional debugging full grid output
if ftype == 'BORG':
self.binoutput = False # flag for binary output
else:
self.binoutput = True # flag for binary output
#
def __str__(self):
""" Print pyKO model run parameters """
return '\npyKO '+__version__+' run parameters\n' + \
' All outputs are in code units \n' + \
f' Input file: {self.inputfilename} \n' + \
f' Output file: {self.outputfilename} \n' + \
f' Number of materials: {self.nmat} \n' + \
f' Number of nodes in each material: {self.inodes} \n' + \
f' Length of each material: {self.ilength} \n' + \
f' Initial left edge of each material: {self.ixstart} \n' + \
f' Boundary conditions: {self.ibcid}\n' + \
f' Material EOS: {self.ieosid} \n' + \
f' Geometry: {self.dflag} \n' + \
f' Gravity: {self.grav.gravity} \n' + \
f' Void pressure: {self.pvoid} \n' + \
f' Time step factor: {self.tstepscale} \n' + \
f' Stop time: {self.tstop}'
def binaryoutput(self):
""" Save the run time parameters for this simulation in a pickle file. """
with open(self.outputfilename+'.parameters',"wb") as f:
#print('dumping dataout class with pickle ',self.stepn)
pickle.dump(self,f)
def checkinput(self):
readinput_yaml(self,verbose=True)
return
#
class TILClass:
""" Tillotson EOS: Material Parameters
and initial state of the homogeneous material layer.
This EOS model relies upon eos_table module. """
def __init__(self):
self.name = '' # name of the material, string
# Variables are stored in code units using pint during input processing
# here showing SESAME units as a guide for the variables
# Tillotson EOS parameters
self.rhoref= 0. # reference density g/m3
self.E0 = 0. # E0 constant MJ/kg
self.EIV = 0. # specific internal energy of incipient vaporization MJ/kg
self.ECV = 0. # specific internal energy of complete vaporization MJ/kg
self.AA = 0. # Bulk modulus K0 GPa
self.BB = 0. # B constant GPa
self.a = 0. # a constant [-]
self.b = 0. # b constant [-]
self.alpha = 0. # alpha constant [-]
self.beta = 0. # beta constant [-] a+b=Gruneisen gamma at rho0
self.cs = 0. # cm/s, sound speed(U,rho)
self.cv = 0. # specific heat capacity MJ/K/kg
self.region= 0 # region flag: 1-condensed, 2-interpolated, 3-expanded, 4-low energy exapansion
# Initial state parameters
self.rho0 = 0. # initial state density, g/cm3
self.p0 = 0. # initial state pressure, Mbar
self.up0 = 0. # initial state particle velocity, cm/us=10 km/s
self.iev0 = 0. # initial state internal energy per original volume, 1e12 ergs/cm3 = 100 GJ/m3
self.v0 = 0. # initial state specific volume, cm3/g
self.t0 = 0. # initial state temperature, K
self.params = np.zeros(0) # numpy array of parameters to pass to Tillotson EOS functions
self.ecold = etab.EOScurve() # reference cold curve for temperature estimate
def fillparams(self):
self.params = np.asarray([self.rhoref,self.E0,self.EIV,self.ECV, \
self.AA,self.BB,self.a,self.b,self.alpha,self.beta,self.cv])
return
def calcecold(self):
""" Calculate the internal energy of the cold curve. Passed to Tillotson EOS function with params for temperature. """
# start by compressing a factor of 3 with 1000 steps
nsteps = 100
self.ecold.rho = np.arange(nsteps)/nsteps*(3.*self.rho0)+self.rho0 # rho is rho0 to 3*rho0
self.ecold.U = np.zeros(nsteps) # initial energy is zero by definition
self.ecold.P = np.zeros(nsteps) # initial pressure is zero by definition
self.ecold.T = np.zeros(nsteps)+self.t0 # initial temperature is T0 by definition
h = self.ecold.rho[1]-self.ecold.rho[0]
x0 = self.ecold.rho[0]
y = 0.0
for i in range(1, nsteps):
#"Apply Runge Kutta Formulas to find next value of y"
# Rundage 2015: dE/drho = P(rho,E)/rho^2
# etab.Till_P returns [pout,flag,csout,tout]
k1 = h * etab.Till_P(x0,y,self.params,self.ecold,calctemp=False)[0]/x0/x0
k2 = h * etab.Till_P(x0 + 0.5 * h,y + 0.5 * k1,self.params,self.ecold,calctemp=False)[0]/(x0 + 0.5 * h)/(x0 + 0.5 * h)
k3 = h * etab.Till_P(x0 + 0.5 * h,y + 0.5 * k2,self.params,self.ecold,calctemp=False)[0]/(x0 + 0.5 * h)/(x0 + 0.5 * h)
k4 = h * etab.Till_P(x0 + h,y + k3,self.params,self.ecold,calctemp=False)[0]/(x0+h)/(x0+h)
#k1 = h * dydx(x0, y)
#k2 = h * dydx(x0 + 0.5 * h, y + 0.5 * k1)
#k3 = h * dydx(x0 + 0.5 * h, y + 0.5 * k2)
#k4 = h * dydx(x0 + h, y + k3)
# Update next value of y
y = y + (1.0 / 6.0)*(k1 + 2 * k2 + 2 * k3 + k4)
# Update next value of x
x0 = x0 + h
# update structure arrays
self.ecold.rho[i] = x0
self.ecold.U[i] = y
self.ecold.P[i] = etab.Till_P(x0,y,self.params,self.ecold,calctemp=False)[0]
return
def __str__(self):
""" Print the Tillotson EOS parameters """
return f'\n{self.name} Tillotson EOS parameters [code units]: \n' + \
f' rhoref: {self.rho0} \n' + \
f' a: {self.a} \n' + \
f' b: {self.b} \n' + \
f' AA: {self.AA} \n' + \
f' BB: {self.BB} \n' + \
f' E0: {self.E0} \n' + \
f' alpha: {self.alpha} \n' + \
f' beta: {self.beta} \n' + \
f' Eiv: {self.EIV} \n' + \
f' Ecv: {self.ECV} \n' + \
f' cv: {self.cv} \n' + \
' initial state: \n' + \
f' rho0: {self.rho0} \n' + \
f' p0: {self.p0} \n' + \
f' iev0: {self.iev0} \n' + \
f' t0: {self.t0} \n' + \
f' up0: {self.up0} \n'
#
class MGRClass:
""" Mie-Grueneisen EOS: Material Parameters
and initial state of the homogeneous material layer.
Wilkins MGR model assumes a linear Us=c+s*up Hugoniot, gamma/V is constant and cv = 3R.
"""
def __init__(self):
self.name = '' # name of the material, string
self.rhoref = 0. # reference density for EOS g/cm3
self.c0 = 0. # bulk sound speed, cm/us=10 km/s, intercept for linear Us=c0+s1+up
self.s1 = 0. # linear Hugoniot slope, dimless
#self.s2 = 0. # quadratic Hugoniot coefficient, [us/cm] # NOT COMPATIBLE WITH OTHER PARTS OF MGR MODEL
self.gamma0 = 0. # Thermodynamic grueneisen parameter, dimless
self.cv = 0. # Heat capacity at constant volume, (Mbar cm3)/(K g)
self.rho0 = 0. # initial state density, g/cm3
self.p0 = 0. # initial state pressure, Mbar
self.up0 = 0. # initial state particle velocity, cm/us=10 km/s
self.iev0 = 0. # initial state internal energy per original volume, 1e12 ergs/cm3 = 100 GJ/m3
self.v0 = 0. # initial state specific volume, cm3/g
self.t0 = 298.15 # initial state temperature assumed to be 25C=298.15 K
self.cv = 0. # constant specific heat capacity, code units should be 1.12 ergs/K/g = eu/K/g
self.coefs = np.zeros(4) # k1,k2,k3,k4 in Wilkins Section 3.7
# coefs for MG EOS from Wilkins
# x = 1 - vr
# P = k1*x + k2*x^2 + k3*x^3 + k4*E
# alternative formula in Appendix B
# eta = 1/vr = rho/rho0
# P = a(eta-1)+b(eta-1)^2+c(eta-1)^3+d*eta*E
self.ecoefs = np.zeros(5) # e0,e1,e2,e3,e4 in Wilkins Section 3.7
self.ecold = etab.EOScurve() # reference cold curve for temperature estimate
def calccoefs(self):
# this form in Wilkins assumes gamma_0/V_0 = constant and linear Us=c+s1*up
# right now no treatment of porosity
if self.rho0 != self.rhoref:
sys.exit("FATAL ERROR: Mie-Grueneisen model must have rho0=rhoref.")
self.coefs[0] = self.rhoref*self.c0*self.c0 # k1
self.coefs[1] = self.coefs[0]*(2.*self.s1-self.gamma0/2.) # k2
self.coefs[2] = self.coefs[0]*self.s1*(3.*self.s1-self.gamma0) # k3
self.coefs[3] = self.gamma0 # k4
#
def calcecoefs(self):
# energy expansion used to calculate temperature with MGR EOS
# Wilkins MGR model assumes a linear Us=c+s*up Hugoniot, gamma/V is constant and cv = 3nR
# Wilkins Eq 3.54
# eps_0 = eps_00 + eps_01*x + eps_02*x^2 + eps_03*x^3 + eps_04*x^4
# x = 1-vr (vr is relative volume so unitless)
# units are set by the leading term eps_00 = -3*R*T0 = -900R in Wilkins for T0=300 K and cv=3R
# --> eps_00 = -cv*T0 in units of eu/g
# Wilkins R is in units of gas constant/atomic weight = eu/K/g*(n=# atoms per formula unit)
# E = eps/V0 is energy per original volume cm3
# E/rho_0 is energy per unit mass = eu/g
# T = (1/(3R))*(E/rho_0 - eps_0) = (1/cv)*(E/rho_0 - eps_0)
# Here, we input the heat capacity rather than assume cv = 3R
# cv is converted to eu/K/original volume [code units] during input
# so here needs to be converted to eu/K/g by diving by rho0
self.ecoefs[0] = -self.cv*self.t0/self.rho0
self.ecoefs[1] = self.gamma0*self.ecoefs[0]
self.ecoefs[2] = 0.5*(self.c0*self.c0 + self.gamma0*self.gamma0*self.ecoefs[0])
self.ecoefs[3] = (1./6.)*(4.*self.s1*self.c0*self.c0 + np.power(self.gamma0,3) * self.ecoefs[0])
self.ecoefs[4] = (1./24.)*(18.*self.s1*self.s1*self.c0*self.c0 - 2.*self.gamma0*self.s1*self.c0*self.c0 + np.power(self.gamma0,4)*self.ecoefs[0])
#
def calcecold(self):
""" Calculate the internal energy and pressure of the cold curve. Not used in pyKO - e(V,T0) is calculated on the fly in the code.
This function is used to calculate the cold curve for EOS fitting and comparisons.
Must calculate ecoefs before calling this function. """
# start by compressing a factor of 2 with 100 steps
nsteps = 100
self.ecold.rho = np.arange(nsteps)/nsteps*(2.*self.rho0)+self.rho0 # rho is rho0 to 3*rho0
self.ecold.U = np.zeros(nsteps) # initial energy is self.ecoefs[0] by definition
self.ecold.P = np.zeros(nsteps) # initial pressure is zero by definition
self.ecold.T = np.zeros(nsteps)+self.t0 # temperature is T0 by definition
strain = 1.0 - self.rho0/self.ecold.rho
self.ecold.U = self.ecoefs[0] + self.ecoefs[1]*strain + self.ecoefs[2]*np.power(strain,2) + \
self.ecoefs[3]*np.power(strain,3) + self.ecoefs[4]*np.power(strain,4)
self.ecold.P = self.rho0*(self.ecoefs[1]+2*self.ecoefs[2]*strain+3*self.ecoefs[3]*strain*strain+4*self.ecoefs[4]*np.power(strain,3))
#
def __str__(self):
""" Print the Mie Gruneisen material parameters """
return f'\nClass Mie Grueneisen Material Model [code units]: {self.name} \n' + \
f' rhoref: {self.rhoref} \n' + \
f' c0: {self.c0} \n' + \
f' s1: {self.s1} \n' + \
f' gamma0: {self.gamma0} \n' + \
f' cv: {self.cv} \n' + \
' initial state: \n' + \
f' rho0: {self.rho0} \n' + \
f' p0: {self.p0} \n' + \
f' iev0: {self.iev0} \n' + \
f' up0: {self.up0} \n' + \
f' k1,k2,k3,k4= {self.coefs[0]},{self.coefs[1]},{self.coefs[2]},{self.coefs[3]} \n' + \
f' e0,e1,e2,e3,e4= {self.ecoefs[0]},{self.ecoefs[1]},{self.ecoefs[2]},{self.ecoefs[3]},{self.ecoefs[4]} \n'
#
class IDGClass:
""" Ideal Gas EOS: Material Parameters
and initial state of the homogeneous material layer """
def __init__(self):
self.name = '' # name of the material, string
self.gamma0 = 0. # Thermodynamic grueneisen parameter, dimless
self.cv = 0. # Heat capacity at constant volume, (Mbar cm3)/(K g)
self.rho0 = 0. # initial state density, g/cm3
self.p0 = 0. # initial state pressure, Mbar
self.up0 = 0. # initial state particle velocity, cm/us=10 km/s
self.iev0 = 0. # initial state internal energy per original volume, 1e12 ergs/cm3 = 100 GJ/m3
self.v0 = 0. # initial state specific volume, cm3/g
self.t0 = 0. # initial state temperature, K
#
def __str__(self):
""" Print the Ideal Gas material parameters """
return f'\nClass Ideal Gas [code units]: {self.name} \n' + \
f' gamma0: {self.gamma0} \n' + \
f' cv: {self.cv} \n' + \
' initial state: \n' + \
f' rho0: {self.rho0} \n' + \
f' p0: {self.p0} \n' + \
f' iev0: {self.iev0} \n' + \
f' up0: {self.up0} \n' + \
f' t0: {self.t0} \n'
#
class SESClass:
""" ANEOS SESAME Table EOS: Material Parameters
and initial state of the homogeneous material layer.
Requires eos_table.py module. """
def __init__(self):
self.name = '' # name of the material, string
self.path = '' # path to the ANEOS file set
self.aneosin = 'ANEOS.INPUT' # path and name for the sesame table file, string
self.aneosout = 'ANEOS.OUTPUT' # path and name for the sesame table file, string
self.sesstd = 'NEW-SESAME-STD.TXT' # path and name for the sesame table file, string
self.sesext = 'NEW-SESAME-EXT.TXT' # path and name for the sesame table file, string
self.sesstdnt = 'NEW-SESAME-STD-NOTENSION.TXT' # path and name for the sesame table file, string
self.gamma0 = 0. # Thermodynamic grueneisen parameter, dimless
self.cv = 0. # Heat capacity at constant volume, (Mbar cm3)/(K g)
self.rho0 = 0. # initial state density, g/cm3
self.p0 = 0. # initial state pressure, Mbar
self.up0 = 0. # initial state particle velocity, cm/us=10 km/s
self.iev0 = 0. # initial state internal energy per original volume, 1e12 ergs/cm3 = 100 GJ/m3
self.v0 = 0. # initial state specific volume, cm3/g
self.t0 = 0. # initial state temperature, K
self.cs0 = 0. # initial state sound velocity
self.EOS = etab.extEOStable() # initialize table object (eos_table module)
self.rhoref = 0.
#
def readsesext(self, verbose=False):
"""
# READ IN NEW ANEOS MODEL and fill the extEOStable class object
# HARD CODED UNIT CONVERSION from Stewart Group ANEOS to KO code units
# DEPRECATED: only for testing with Borg style inputs
# yaml configuration files includes units conversions; use readtable function instead
"""
#------------------------------------------------------------------
self.EOS.loadextsesame(self.path+self.sesext) #'NEW-SESAME-EXT.TXT') # LOAD THE EXTENDED 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS
self.EOS.loadstdsesame(self.path+self.sesstd) # 'NEW-SESAME-STD.TXT') # LOAD THE STANDARD 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS
#print(NewEOS.units) # these are the default units for SESAME rho-T tables
#'Units: g/c3, K, GPa, MJ/kg, MJ/kg, MJ/K/kg, cm/s, MJ/K/kg, KPA flag. 2D arrays are (NT,ND).'
# CONVERT THE TABLE UNITS TO WILKINS CODE UNITS
# T in K; rho in g/cm3
if verbose: print('WARNING HARD CODED SESAME UNITS CONVERSION! \n' + \
'U by 1/100 MJ/kg -> 100 kJ/g; not normalizing to rho0')
self.EOS.P = self.EOS.P/100. # GPa to Mbar
self.EOS.U = self.EOS.U/100. # MJ/kg *10/1000 -> 100 kJ/g
self.EOS.S = self.EOS.S/100. # MJ/K/kg *10/1000 -> 100 kJ/g
#
def readtable(self, config, verbose=False):
"""
# Read in SESAME style EOS tables and fill the extEOStable class object
# Unit conversion between table units and code units requires units section
# in yaml configuration file
#
# NOTE: The specific energy in the table remains in specific energy units.
# The normalization to initial volume is done in the interpolation function
# used in the energy conservation loop because this requires the initial state
# information for the problem.
"""
#------------------------------------------------------------------
# LOAD THE STANDARD 301 SESAME FILE GENERATED BY STSM ANEOS SCRIPTS NEW-SESAME-STD.TXT
self.EOS.loadstdsesame(self.path+self.sesstd)
# LOAD THE EXTENDED 301 SESAME FILE GENERATED BY STSM ANEOS SCRIPTS NEW-SESAME-EXT.TXT
self.EOS.loadextsesame(self.path+self.sesext)
# print(NewEOS.units) # these are the units for Stewart Group SESAME T-rho tables
#'Units: g/cm3, K, GPa, MJ/kg, MJ/kg, MJ/K/kg, cm/s, MJ/K/kg, KPA flag. 2D arrays are (NT,ND).'
# CONVERT THE TABLE UNITS TO CODE UNITS using pint and yaml configuration file information
# T in K; rho in g/cm3
# print('Converting EOS Table to code units.')
rho = Q_(self.EOS.rho,config['tableunits']['density'])
self.EOS.rho = rho.to(config['codeunits']['density']).magnitude
temp = Q_(self.EOS.T,config['tableunits']['temperature'])
self.EOS.T = temp.to(config['codeunits']['temperature']).magnitude
P = Q_(self.EOS.P,config['tableunits']['pressure'])
self.EOS.P = P.to(config['codeunits']['pressure']).magnitude
U = Q_(self.EOS.U,config['tableunits']['sp_energy'])
self.EOS.U = U.to(config['codeunits']['sp_energy']).magnitude
S = Q_(self.EOS.S,config['tableunits']['sp_entropy'])
self.EOS.S = S.to(config['codeunits']['sp_entropy']).magnitude
cs = Q_(self.EOS.cs,config['tableunits']['sound_speed'])
self.EOS.cs = cs.to(config['codeunits']['velocity']).magnitude
cv = Q_(self.EOS.cv,config['tableunits']['sp_heat_cap'])
self.EOS.cv = cv.to(config['codeunits']['sp_heat_cap']).magnitude
A = Q_(self.EOS.A,config['tableunits']['sp_energy'])
self.EOS.A = A.to(config['codeunits']['sp_energy']).magnitude
# if no sound speeds tabulated, calculate a bulk sound speed
if np.max(self.EOS.cs) == 0:
print('NO SOUND SPEEDS. CALCULATING BULK SOUND SPEEDS.')
for irho in range(1,self.EOS.ND-1):
for itemp in range(1,self.EOS.NT-1):
btlocal = self.EOS.rho[irho]* \
(self.EOS.P[itemp,irho+1]-self.EOS.P[itemp,irho-1])/ \
(self.EOS.rho[irho+1]-self.EOS.rho[irho-1])
cslocal = np.sqrt(np.abs(btlocal)/self.EOS.rho[irho])
#print(self.EOS.rho[irho],self.EOS.T[itemp],btlocal,cslocal,self.EOS.CS0REF)
# in code units
if cslocal == 0.0:
cslocal = self.EOS.CS0REF
self.EOS.cs[itemp,irho] = cslocal
return
#
def findpve(self,p,rho):
rindex = npwhere(self.EOS.rho >= rho)[0][0]
tindex = npwhere(self.EOS.P[:,rindex] >= p)[0][0]
print('findpve p, rho -> rho, p, U', p, rho, self.EOS.rho[rindex],self.EOS.P[tindex,rindex],self.EOS.U[tindex,rindex])
#
def sesplog(self,rho,u,p,t,eps):
""" Testing linear interpolation of log values. Only works for ideal gas.
Cannot use with tables with a tension region.
Input rho, u, p, t must be in the same units as the table."""
pnew = np.copy(p)
tnew = np.copy(t)
# if eps = 0., then no change in state
ichange = npwhere(eps != 0.)[0]
#print('ichagne = ',ichange)
for ij in ichange:
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
rindex = npwhere(self.EOS.rho > rho[ij])[0][0]
tindex = npwhere(self.EOS.U[:,rindex] > u[ij])[0][0]
P11 = self.EOS.P[tindex-1,rindex-1]
P21 = self.EOS.P[tindex,rindex-1]
P12 = self.EOS.P[tindex-1,rindex]
P22 = self.EOS.P[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
r1 = np.log10(self.EOS.rho[rindex-1]) # try linearly interpreting on the log of the index
r2 = np.log10(self.EOS.rho[rindex])
logrij = np.log10(rho[ij])
loguij = np.log10(u[ij])
t1 = np.log10(self.EOS.T[tindex-1])
t2 = np.log10(self.EOS.T[tindex])
u1 = np.log10(U11) * (r2-logrij)/(r2-r1) + np.log10(U12) * (logrij-r1)/(r2-r1)
u2 = np.log10(U21) * (r2-logrij)/(r2-r1) + np.log10(U22) * (logrij-r1)/(r2-r1)
p1 = np.log10(P11) * (r2-logrij)/(r2-r1) + np.log10(P12) * (logrij-r1)/(r2-r1)
p2 = np.log10(P21) * (r2-logrij)/(r2-r1) + np.log10(P22) * (logrij-r1)/(r2-r1)
pij = p1 * (u2-loguij)/(u2-u1) + p2 * (loguij-u1)/(u2-u1)
pnew[ij] = nppower(10.,pij)
tij = t1 * (u2-loguij)/(u2-u1) + t2 * (loguij-u1)/(u2-u1)
tnew[ij] = nppower(10.,tij)
if True:
print('bilinear = ',rindex,tindex,'\n',\
nppower(10.,r1),rho[ij],nppower(10.,r2),'\n',\
nppower(10.,u1),u[ij],nppower(10.,u2),'\n', \
nppower(10.,p1),pnew[ij],nppower(10.,p2),'\n',\
nppower(10.,t1),tnew[ij],nppower(10.,t2))
print()
print('')
return pnew,tnew
#
def sesp(self,rho,u,p,t,s,eps):
""" Linear interpolation to extract table P and T from rho and U.
Input rho, u, p, t must be in the same units as the table.
Returns pnew, tnew arrays.
Temperature calculation is not stable in tension resions. This function needs work.
"""
pnew = np.copy(p) # This routine only calculates cells with nonzero strain.
tnew = np.copy(t) # copy current P & T values to populate cells with no change.
snew = np.copy(s) # This routine only calculates cells with nonzero strain.
# if eps = 0., then no change in state
ichange = npwhere(eps != 0.)[0]
#print('ichange = ',ichange)
for ij in ichange:
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
rindex = npwhere(self.EOS.rho > rho[ij])[0][0]
tindex = npwhere(self.EOS.U[:,rindex] > u[ij])[0][0]
if tindex == 0:
# this is a kludge that needs attention
tindex = npwhere(self.EOS.U[:,rindex-1] > u[ij])[0][0]+1
# print(u[ij],rho[ij],rindex)
# print(self.EOS.U[:,rindex])
# stop
#if tindex == 0:
# # probably in tension region; look for tension region solution
# temptind = npwhere(self.EOS.P[:,rindex] < 0.)[0]
# tindex = npwhere(self.EOS.U[temptind,rindex] > u[ij])[0][0]
# print(tindex,u[ij])
P11 = self.EOS.P[tindex-1,rindex-1]
P21 = self.EOS.P[tindex,rindex-1]
P12 = self.EOS.P[tindex-1,rindex]
P22 = self.EOS.P[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
S11 = self.EOS.S[tindex-1,rindex-1]
S21 = self.EOS.S[tindex,rindex-1]
S12 = self.EOS.S[tindex-1,rindex]
S22 = self.EOS.S[tindex,rindex]
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
t1 = self.EOS.T[tindex-1]
t2 = self.EOS.T[tindex]
u1 = U11 * (r2-rho[ij])/(r2-r1) + U12 * (rho[ij]-r1)/(r2-r1)
u2 = U21 * (r2-rho[ij])/(r2-r1) + U22 * (rho[ij]-r1)/(r2-r1)
p1 = P11 * (r2-rho[ij])/(r2-r1) + P12 * (rho[ij]-r1)/(r2-r1)
p2 = P21 * (r2-rho[ij])/(r2-r1) + P22 * (rho[ij]-r1)/(r2-r1)
pij = p1 * (u2-u[ij])/(u2-u1) + p2 * (u[ij]-u1)/(u2-u1)
pnew[ij] = pij
tij = t1 * (u2-u[ij])/(u2-u1) + t2 * (u[ij]-u1)/(u2-u1)
tnew[ij] = tij
s1 = S11 * (r2-rho[ij])/(r2-r1) + S12 * (rho[ij]-r1)/(r2-r1)
s2 = S21 * (r2-rho[ij])/(r2-r1) + S22 * (rho[ij]-r1)/(r2-r1)
sij = s1 * (u2-u[ij])/(u2-u1) + s2 * (u[ij]-u1)/(u2-u1)
snew[ij] = sij
if False:
print(self.EOS.U[0:10,rindex])
print(self.EOS.P[0:50,rindex])
print('bilinear = ',rindex,tindex,'\n',\
r1,rho[ij],r2,'\n',\
u1,u[ij],u2,'\n', \
p1,pnew[ij],p2,'\n',\
t1,tnew[ij],t2,'\n',\
s1,snew[ij],s2)
print('')
stop
return pnew,tnew,snew
def sescs(self,rho,u):
""" Linear interpolation to extract table cs from rho and U.
Input rho, u must be in the same units as the table.
Returns cs array. """
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
csarr = np.zeros(len(rho))
for ij in np.arange(len(rho)):
rindex = npwhere(self.EOS.rho > rho[ij])[0][0]
tindex = npwhere(self.EOS.U[:,rindex] > u[ij])[0][0]
C11 = self.EOS.cs[tindex-1,rindex-1]
C21 = self.EOS.cs[tindex,rindex-1]
C12 = self.EOS.cs[tindex-1,rindex]
C22 = self.EOS.cs[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
u1 = U11 * (r2-rho[ij])/(r2-r1) + U12 * (rho[ij]-r1)/(r2-r1)
u2 = U21 * (r2-rho[ij])/(r2-r1) + U22 * (rho[ij]-r1)/(r2-r1)
c1 = C11 * (r2-rho[ij])/(r2-r1) + C12 * (rho[ij]-r1)/(r2-r1)
c2 = C21 * (r2-rho[ij])/(r2-r1) + C22 * (rho[ij]-r1)/(r2-r1)
cij = c1 * (u2-u[ij])/(u2-u1) + c2 * (u[ij]-u1)/(u2-u1)
csarr[ij] = cij
return csarr
def sesphase(self,rho,u):
""" Linear interpolation to extract table phase from rho and U.
Input rho, u must be in the same units as the table.
Returns phase array. """
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
phasearr = np.zeros(len(rho))
for ij in np.arange(len(rho)):
rindex = npwhere(self.EOS.rho > rho[ij])[0][0]
tindex = npwhere(self.EOS.U[:,rindex] > u[ij])[0][0]
K11 = self.EOS.KPA[tindex-1,rindex-1]
K21 = self.EOS.KPA[tindex,rindex-1]
K12 = self.EOS.KPA[tindex-1,rindex]
K22 = self.EOS.KPA[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
u1 = U11 * (r2-rho[ij])/(r2-r1) + U12 * (rho[ij]-r1)/(r2-r1)
u2 = U21 * (r2-rho[ij])/(r2-r1) + U22 * (rho[ij]-r1)/(r2-r1)
k1 = K11 * (r2-rho[ij])/(r2-r1) + K12 * (rho[ij]-r1)/(r2-r1)
k2 = K21 * (r2-rho[ij])/(r2-r1) + K22 * (rho[ij]-r1)/(r2-r1)
kij = k1 * (u2-u[ij])/(u2-u1) + k2 * (u[ij]-u1)/(u2-u1)
phasearr[ij] = kij
#print('in sesphase rho, phasearr = ',rho,phasearr)
return phasearr
def oneptc(self,rho,u):
""" Linear interpolation to extract table one point P, T, cs from rho and U.
Input rho, u must be in the same units as the table.
Returns P, T, cs """
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
rindex = npwhere(self.EOS.rho > rho)[0][0]
tindex = npwhere(self.EOS.U[:,rindex] > u)[0][0]
P11 = self.EOS.P[tindex-1,rindex-1]
P21 = self.EOS.P[tindex,rindex-1]
P12 = self.EOS.P[tindex-1,rindex]
P22 = self.EOS.P[tindex,rindex]
C11 = self.EOS.cs[tindex-1,rindex-1]
C21 = self.EOS.cs[tindex,rindex-1]
C12 = self.EOS.cs[tindex-1,rindex]
C22 = self.EOS.cs[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
t1 = self.EOS.T[tindex-1]
t2 = self.EOS.T[tindex]
u1 = U11 * (r2-rho)/(r2-r1) + U12 * (rho-r1)/(r2-r1)
u2 = U21 * (r2-rho)/(r2-r1) + U22 * (rho-r1)/(r2-r1)
p1 = P11 * (r2-rho)/(r2-r1) + P12 * (rho-r1)/(r2-r1)
p2 = P21 * (r2-rho)/(r2-r1) + P22 * (rho-r1)/(r2-r1)
p = p1 * (u2-u)/(u2-u1) + p2 * (u-u1)/(u2-u1)
t = t1 * (u2-u)/(u2-u1) + t2 * (u-u1)/(u2-u1)
c1 = C11 * (r2-rho)/(r2-r1) + C12 * (rho-r1)/(r2-r1)
c2 = C21 * (r2-rho)/(r2-r1) + C22 * (rho-r1)/(r2-r1)
c = c1 * (u2-u)/(u2-u1) + c2 * (u-u1)/(u2-u1)
return p,t,c
#
def onepuc(self,rho,t):
""" Linear interpolation to extract table one point P, U, cs from rho and T.
Input rho, t must be in the same units as the table,
which is converted to code units.
Returns P, U, cs """
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
rindex = npwhere(self.EOS.rho >= rho)[0][0]
tindex = npwhere(self.EOS.T >= t)[0][0]
P11 = self.EOS.P[tindex-1,rindex-1]
P21 = self.EOS.P[tindex,rindex-1]
P12 = self.EOS.P[tindex-1,rindex]
P22 = self.EOS.P[tindex,rindex]
C11 = self.EOS.cs[tindex-1,rindex-1]
C21 = self.EOS.cs[tindex,rindex-1]
C12 = self.EOS.cs[tindex-1,rindex]
C22 = self.EOS.cs[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
t1 = self.EOS.T[tindex-1]
t2 = self.EOS.T[tindex]
u1 = U11 * (r2-rho)/(r2-r1) + U12 * (rho-r1)/(r2-r1)
u2 = U21 * (r2-rho)/(r2-r1) + U22 * (rho-r1)/(r2-r1)
p1 = P11 * (r2-rho)/(r2-r1) + P12 * (rho-r1)/(r2-r1)
p2 = P21 * (r2-rho)/(r2-r1) + P22 * (rho-r1)/(r2-r1)
p = p1 * (t2-t)/(t2-t1) + p2 * (t-t1)/(t2-t1)
u = u1 * (t2-t)/(t2-t1) + u2 * (t-t1)/(t2-t1)
c1 = C11 * (r2-rho)/(r2-r1) + C12 * (rho-r1)/(r2-r1)
c2 = C21 * (r2-rho)/(r2-r1) + C22 * (rho-r1)/(r2-r1)
c = c1 * (t2-t)/(t2-t1) + c2 * (t-t1)/(t2-t1)
return p,u,c
#
def oneruc(self,p,t):
""" Linear interpolation to extract table one point rho, U, cs from P and T.
Altenatively, use a notension table to initialize with gravity.
Input P and T must be in the same units as the table.
Returns rho, U, cs """
# bilinear interpolation
# https://x-engineer.org/bilinear-interpolation/
tindex = npwhere(self.EOS.T >= t)[0][0]
rtmp = npwhere(self.EOS.P[tindex-1,:] >= p)[0]
rindex = rtmp[0]
if self.EOS.T[tindex] == t:
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
u1 = self.EOS.U[tindex,rindex-1]
u2 = self.EOS.U[tindex,rindex]
p1 = self.EOS.P[tindex,rindex-1]
p2 = self.EOS.P[tindex,rindex]
c1 = self.EOS.cs[tindex,rindex-1]
c2 = self.EOS.cs[tindex,rindex]
u = u1 * (p2-p)/(p2-p1) + u2 * (p-p1)/(p2-p1)
rho = r1 * (p2-p)/(p2-p1) + r2 * (p-p1)/(p2-p1)
c = c1 * (p2-p)/(p2-p1) + c2 * (p-p1)/(p2-p1)
#print('ruc = ',r1,r2,p1,p2,p,rho,u,c,tindex,rindex)
return rho,u,c
P11 = self.EOS.P[tindex-1,rindex-1]
P21 = self.EOS.P[tindex,rindex-1]
P12 = self.EOS.P[tindex-1,rindex]
P22 = self.EOS.P[tindex,rindex]
C11 = self.EOS.cs[tindex-1,rindex-1]
C21 = self.EOS.cs[tindex,rindex-1]
C12 = self.EOS.cs[tindex-1,rindex]
C22 = self.EOS.cs[tindex,rindex]
U11 = self.EOS.U[tindex-1,rindex-1]
U21 = self.EOS.U[tindex,rindex-1]
U12 = self.EOS.U[tindex-1,rindex]
U22 = self.EOS.U[tindex,rindex]
r1 = self.EOS.rho[rindex-1]
r2 = self.EOS.rho[rindex]
t1 = self.EOS.T[tindex-1]
t2 = self.EOS.T[tindex]
u1 = U11 * (t2-t)/(t2-t1) + U21 * (t-t1)/(t2-t1)
u2 = U12 * (t2-t)/(t2-t1) + U22 * (t-t1)/(t2-t1)
p1 = P11 * (t2-t)/(t2-t1) + P21 * (t-t1)/(t2-t1)
p2 = P12 * (t2-t)/(t2-t1) + P22 * (t-t1)/(t2-t1)
c1 = C11 * (t2-t)/(t2-t1) + C21 * (t-t1)/(t2-t1)
c2 = C12 * (t2-t)/(t2-t1) + C22 * (t-t1)/(t2-t1)
u = u1 * (p2-p)/(p2-p1) + u2 * (p-p1)/(p2-p1)
rho = r1 * (p2-p)/(p2-p1) + r2 * (p-p1)/(p2-p1)
c = c1 * (p2-p)/(p2-p1) + c2 * (p-p1)/(p2-p1)
return rho,u,c
#
def __str__(self):
""" Print overview of SESAME Table EOS material parameters """
return f'\nClass SESAME [code units]: {self.name} \n' + \
f' eos_table module version {etab.__version__} \n' + \
f' table path: {self.path} \n' + \
f' file names: {self.sesstd} {self.sesext} \n' + \
' initial state: \n' + \
f' rho0: {self.rho0} \n' + \
f' p0: {self.p0} \n' + \
f' iev0: {self.iev0} \n' + \
f' up0: {self.up0} \n' + \
f' t0: {self.t0} \n' + \
f' CS0REF: {self.EOS.CS0REF} \n' + \
f' cs0: {self.cs0} '
#
class HydroClass:
""" Hydrodynamic material class """
def __init__(self):
self.name = '' # name of the material, string
def __str__(self):
""" Print HYDRO material descriptor """
return f'\n{self.name}: Hydrodynamic material'
#
class VonMisesClass:
""" Strength class for Von Mises Yield """
def __init__(self):
self.name = '' # name of the material, string
self.gmod = 0. # shear modulus, Mbar
self.ys = 0. # von Mises yield stress, Mbar
def __str__(self):
""" Print Von Mises material parameters [code units] """
return f'\n{self.name} Von Mises parameters: \n' + \
f' Shear modulus: {self.gmod} \n' + \
f' Yield stress: {self.ys}'
#
class SteinbergGuinanClass:
""" Strength class for Steinberg-Guinan Yield Model as implemented in Wilkins book """
def __init__(self):
self.name = '' # name of the material, string
self.Y0 = 0.0 #
self.Ymax = 0.0 #
self.beta = 0.0
self.n = 0.0
self.b = 0.0
self.h = 0.0
self.Tm0 = 0.0
self.mu0 = 0.0
self.gamm0 = 0.0
def __str__(self):
""" Print Steinberg-Guinan material parameters """
return f'\n{self.name} Steinberg-Guinan parameters [code units]: \n' + \
f' Yield stress: {self.Y0} \n' + \
f' Max yield stress: {self.Ymax} \n' + \
f' beta: {self.beta} \n' + \
f' n: {self.n} \n' + \
f' b: {self.b} \n' + \
f' h: {self.h} \n' + \
f' Melt temperature: {self.Tm0} \n' + \
f' Shear modulus: {self.mu0} \n' + \
f' g0 (from EOS): {self.gamma0} \n'
#
class FractureClass:
""" Fracture strength class. Fracture requires -P > pfrac and rho < rhomin*rhoref. """
def __init__(self):
self.name = '' # optional string to describe fracture parameters
self.usefrac = False # Boolean to enter fracture code section; default is fracture is off unless found in the input parameters file
self.pfrac = 1.E99 # fracture pressure; fracture requires -P > pfrac
self.nrhomin = 0.8 # normalized maximum distension factor; fracture requires rho < (nrhomin*rhoref); usually 0.8-0.95
def __str__(self):
""" Fracture parameters """
return f'\n{self.name} Fracture parameters [code units]: \n' + \
f' Fracture is turned on: {self.usefrac} \n' + \
f' Fracture pressure: {self.pfrac} \n' + \
f' Fracture maximum distension (rhomin/rhoref): {self.nrhomin}'
#
class BCClass:
""" Boundary Conditions """
def __init__(self):
self.name = '' # name of the boundary condition, string
self.pbc = 0. # pressure in ghost cell, Mbar
self.upbc = 0. # particle velocity in ghost cell, cm/us
self.rrefbc = 0. # density in ghost cell, g/cm3
self.iebc = 0. # internal energy per original volume in ghost cell, 1e12 ergs/cm3
self.vrbc = 0. # relative volume in ghost cell, dimless
def __str__(self):
""" Print boundary condition parameters """
return f'\nClass Boundary Condition [code units]: {self.name} \n' + \
f' Pressure: {self.pbc} ' # \n' + \
#f' Particle velocity [cm/us]: {self.upbc} \n' + \
#f' Reference density [g/cm3]: {self.rrefbc} \n' + \
#f' Internal energy [Mbar]: {self.iebc} \n' + \
#f' Relative volume [-]: {self.vrbc}'
#
class GravityClass:
""" Gravity parameters """
def __init__(self):
self.gravity = 0. # gravitational acceleration
self.matflag = np.zeros(0,dtype='int') # Flag for initialization with gravity
self.refpos = np.zeros(0) # Reference position for initialization with gravity
self.refpres = np.zeros(0) # reference pressure at reference position
def __str__(self):
""" Print boundary condition parameters """
return f'\nClass Gravity [code units]: \n' + \
f' Gravitational acceleration: {self.gravity} \n' + \
f' Reference position: {self.refpos} ' # \n' + \
#f' Reference density [g/cm3]: {self.rrefbc} \n' + \
#f' Internal energy [Mbar]: {self.iebc} \n' + \
#f' Relative volume [-]: {self.vrbc}'
#
@dataclass
class OutputClass:
""" Problem domain data structure for output dumps """
def __init__(self):
""" Initialize the main arrays for the problem domain """
# unknown number of cells initially. Initialize data types with zero length.
# variables in space at a particular snapshot in time
self.stepn = np.zeros(0,dtype='int') # counter for the number of time steps; int
self.time = np.zeros(0) # same time for each cell; used to make pandas conversion easier
self.mat = np.zeros(0,dtype='int') # material id number
self.pos = np.zeros(0) # position in 1D geometry (x,r_cyl,r_sph)
self.rho0 = np.zeros(0) # initial density rho0 g/cm3; DEBUG later can free up this memory by referring to imat definition
self.rho = np.zeros(0) # local density g/cm3
self.up = np.zeros(0) # particle velocity
#self.iev0 = np.zeros(0) # internal energy per initial volume 1e12 erg/cm3
self.ie = np.zeros(0) # specific internal energy
self.pres = np.zeros(0) # pressure Mbar
self.mass = np.zeros(0) # mass in node g
self.temp = np.zeros(0) # temperature K
self.sigmar = np.zeros(0) # total radial stress sigma_r, only evaluated at n=1 current time
self.sigmao = np.zeros(0) # total tangential stress sigma_theta, only evaluated at n=1 current time
self.etot = np.zeros(0) # total IE + total KE
self.j = np.zeros(0) # node index for comparisons to fKO
#self.vr = np.zeros(0) # relative volume to initial state=rho0/rho=1/eta in Wilkins [dimless]
#self.phi = np.zeros(0) # rho0*(pos_j+1-pos_j)/vr_j+1/2 = (pos_j+1-pos_j)/rho_j+1/2=phi in Wilkins
#self.q = np.zeros(0) # artificial viscosity Mbar
#self.eps1 = np.zeros(0) # velocity strain dup/dpos, per microsec
#self.eps2 = np.zeros(0) # velocity strain up/pos, per microsec
# plastic strain variables
self.epsip1 = np.zeros(0) # incremental plastic strain in x dir
self.epsip2 = np.zeros(0) # incremental plastic strain in y dir
self.epsip3 = np.zeros(0) # incremental plastic strain in z dir
self.epstrain = np.zeros(0) # effective plastic strain
self.eestrain = np.zeros(0) # accumulated total elastic strain
# these variables are evaluated at n=3; full time step ahead
#self.beta = np.zeros(0) # (sigmar-sigmao)/(0.5 dpos)*rho = beta in Wilkins
#self.s1 = np.zeros(0) # s1 stress deviator deriv = 2G(deps1-dvr/vr/3)
#self.s2 = np.zeros(0) # s2 stress deviator deriv
#self.s3 = np.zeros(0) # s3 stress deviator deriv; not needed in 1D; kept for equation clarity
self.entropy = np.zeros(0) # entropy [code units is eu/K/g]
self.dtminj = np.zeros(0) # calculated minimum time step
# variables in time only - n
#self.ibc = np.zeros(0,dtype='int') # boundary condition id number, integer
self.yld = np.zeros(0) # yield stress
self.mu = np.zeros(0) # shear modulus
self.pfrac = np.zeros(0) # fracture stress
#self.deltaz = np.zeros(0) # distortion energy Mbar
self.alocal = np.zeros(0) # sound speed; intermediate variable for AV
#
def printunits(self):
print('pyKO output data class keys and units: \n' +\
f' stepn: {self.stepn.units} \n' + \
f' time: {self.time.units} \n' + \
f' mat: {self.mat.units} \n' + \
f' pos: {self.pos.units} \n' + \
f' rho0: {self.rho0.units} \n' + \
f' rho: {self.rho.units} \n' + \
f' up: {self.up.units} \n' + \
f' ie: {self.ie.units} \n' + \
f' pres: {self.pres.units} \n' + \
f' mass: {self.mass.units} \n' + \
f' temp: {self.temp.units} \n' + \
f' sigmar: {self.sigmar.units} \n' + \
f' sigmao: {self.sigmao.units} \n' + \
f' etot: {self.etot.units} \n' + \
' j: (dimless)' + \
f' entropy:{self.entropy.units} \n' + \
f' dtminj: {self.dtminj.units} \n' + \
f' yld: {self.yld.units} \n' + \
f' mu: {self.mu.units} \n' + \
f' pfrac: {self.pfrac.units} \n' + \
f' alocal: {self.alocal.units} \n'
)
return
#
@dataclass
class DebugClass:
""" Detailed domain data structure for debugging output dumps
"""
def __init__(self):
""" Initialize the main arrays for the problem domain """
# unknown number of cells initially. Initialize data types with zero length.
# variables in space at a particular snapshot in time
self.stepn = np.zeros(0,dtype='int') # counter for the number of time steps; int
self.time = np.zeros(0) # same time for each cell; used to make pandas conversion easier
self.mat = np.zeros(0,dtype='int') # material id number
self.pos = np.zeros(0) # position in 1D geometry (x,r_cyl,r_sph)
self.rho0 = np.zeros(0) # initial density rho0 g/cm3; DEBUG later can free up this memory by referring to imat definition
self.rho = np.zeros(0) # local density g/cm3
self.up = np.zeros(0) # particle velocity
#self.iev0 = np.zeros(0) # internal energy per initial volume 1e12 erg/cm3
self.ie = np.zeros(0) # specific internal energy
self.pres = np.zeros(0) # pressure Mbar
self.mass = np.zeros(0) # mass in node g
self.temp = np.zeros(0) # temperature K
self.sigmar = np.zeros(0) # total radial stress sigma_r, only evaluated at n=1 current time
self.sigmao = np.zeros(0) # total tangential stress sigma_theta, only evaluated at n=1 current time
self.etot = np.zeros(0) # total IE + total KE
self.j = np.zeros(0) # node index for comparisons to fKO
self.vr = np.zeros(0) # relative volume to initial state=rho0/rho=1/eta in Wilkins [dimless]
self.phi = np.zeros(0) # rho0*(pos_j+1-pos_j)/vr_j+1/2 = (pos_j+1-pos_j)/rho_j+1/2=phi in Wilkins
self.q = np.zeros(0) # artificial viscosity Mbar
self.eps1 = np.zeros(0) # velocity strain dup/dpos, per microsec
self.eps2 = np.zeros(0) # velocity strain up/pos, per microsec
self.epsip1 = np.zeros(0) # incremental plastic strain x dir
self.epsip2 = np.zeros(0) # incremental plastic strain y dir
self.epsip3 = np.zeros(0) # incremental plastic strain z dir
self.epstrain = np.zeros(0) # effective plastic strain
self.eestrain = np.zeros(0) # total elastic strain
# these variables are evaluated at n=3; full time step ahead
self.beta = np.zeros(0) # (sigmar-sigmao)/(0.5 dpos)*rho = beta in Wilkins
self.s1 = np.zeros(0) # s1 stress deviator deriv = 2G(deps1-dvr/vr/3)
self.s2 = np.zeros(0) # s2 stress deviator deriv
self.s3 = np.zeros(0) # s3 stress deviator deriv; not needed in 1D; kept for equation clarity