-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathkov11e.f
More file actions
1677 lines (1653 loc) · 68.4 KB
/
kov11e.f
File metadata and controls
1677 lines (1653 loc) · 68.4 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
c Fortran code by John Borg
c v11c - updated by STS for I/O comparisons to pyKOv0.1; initial minimalist code match
c v11d - checking d=2, d=3 and ibc +- 4 with pyKOv0.2
c v11d - I/O tweaks for clean test cases with pyKOv0.3; added etot to main output
c January 30, 2023, updated February 2, 2023; updated 2/10/23
c KO see Springer book by Wilkins, M.
c "Computer simulations of Dynamic Phenomena"
PROGRAM fKO
parameter(jj = 502) !total number of nodes allowed
!this number should be greater than the number
!of nodes that you want so that nodes can be added
!if fracture occurs
parameter(jmat=7) !number of materials
parameter(nmax=4) !number of placeholders for time: t(0) and t(1) current, t(2) and t(3) new; keeps memory very small
!! fortran is crazy and lets you declare the first index 0 instead of 1
! ! all these deckared variables have first index 0
integer narg
integer n, j,imat,ibc(0:jj), icontact,idebug,jdebug,iskip,ipoint
integer j1(jj),iEOS(2,0:jj),jjj,jzz,ndebug,i,amr
integer icompact(0:nmax,jj), mat(0:jj), stepn
real*8 m(0:jj), r(0:nmax,0:jj), U(0:nmax,0:jj)
real*8 t(0:nmax),pfrac(0:jj),pvoid
real*8 phi(0:nmax,0:jj), sigmar(0:nmax,0:jj)
real*8 sigmao(0:nmax,0:jj),Temp(0:nmax,0:jj)
real*8 beta(0:nmax,0:jj), P(0:nmax,0:jj), q(0:nmax,0:jj)
real*8 s1(0:nmax,0:jj),s2(0:nmax,0:jj), s3(0:nmax,0:jj)
real*8 rho(0:jj), V(0:nmax,0:jj), entropy(0:nmax,0:jj)
real*8 epsi1(0:nmax,0:jj),epsi2(0:nmax,0:jj),epdt1(0:nmax,0:jj)
real*8 E(0:nmax,0:jj), K(0:nmax,0:jj), Y(0:jj),dtminj(0:jj)
real*8 deltaZ, Vdot ,dt_min, dr_min,delt_temp,deltaZarr(0:jj)
real*8 deltar, qbar
real*8 a, b, Co, CL, d ,a_min,b_min,rho_min
real*8 alocal(0:jj),rholocal(0:jj)
real*8 EOS(0:jmat,13),init(jmat,16),bc(-9:9,5),LL(jj),xstart(jj)
real*8 xx,xa,xb,deltat_0,deltat,delt,tstop
c real*8 U_0,P_0,V_0,E_0,rho_0,a_0,up
c real*8 U_1,P_1,V_1,E_1,a,
real *8 zero
real*8 aa,ww,rr,bb,dti0,dti1,Usave
real*8 phiv,phij,betav,betaj,dthalf
real*8 qtotal,mvtotal,ketotal,ietotal,etotal,ke3total
real*8 bs1,bs2,bs3,bs4,bs5,bs6,bs7,bs8,bs9,bs10
real*8 tskip,dtskip
real*8 rho_local,stemp,ctemp,gtemp,v0,v00,vv
c real*8 alpha
c real*8 pe,ps,ap,ae
real*8 k1,k2,k3,gamma0
real*8 Us,up,PH,EH,TH,strain,P0,E0,T0
real*8 En2j1,diffE
real*8 startTime,endTime
character*20 name
character*172 text
character*40 fin, fout,arg,foutlong
fin = 'none'
fout = 'none'
foutlong = 'none'
DO i = 1, iargc()
CALL getarg(i, arg)
C WRITE (*,*) arg
if (i .eq. 1) then
fin = trim(arg)
endif
if (i .eq. 2) then
fout = trim(arg)
endif
if (i .eq. 3) then
read(arg,'(f5.3)')dtskip
endif
END DO
if (fin .eq. 'none') then
fin = 'ko.in'
endif
if (fout .eq. 'none') then
fout = 'ko-fort.dat'
endif
write (*,*) fin, fout, dtskip
!read(*,*) foo
c
c Initalize some key varables
Co = 2.0d0 !artifical viscoity constants, default=2 Von Neumann formulation
CL = 1.0d0 !artifical viscoity constants, default=1
pvoid = 0.d0 !pressure in the void
icontact = 0 !contact flag this should not be changed but i think it could
! be elimated if the code were cleaned up.
idebug = 0 ! turn on debug
ndebug = 1 ! what time steup to you want to print to screen
jdebug = 2 ! what node do you want to look at when debugging
d = 0.d0 !defines geometry (1-1D planar, 2-1D cylinderical-never tested), see willkins
deltat_0 = 1.0d-3 ! initial time step to get going microsec
c
iskip = 1000 !number of iterations to skip to echo to screen
dtskip = 0.01 ! This is the amount of time skipped between writes to file this is 3rd argument
tskip = dtskip-deltat_0 ! this is the value at which data starts getting written to file
amr = 0 ! this is an adaptive mesh refinement (1 is on - 0 is off)
c---------------------------------------------------------------------
c zero all variables
c
c print *,'Initializing variables ...'
zero = 0.d0
stepn=0
do n = 0,nmax
do j = 0,jj
ibc(j) = 9 ! these are non-used nodes
U(n,j) = zero
r(n,j) = zero
t(n) = zero ! sts changed deltat_0*dfloat(n)
deltat = deltat_0
phi(n,j) = zero
sigmar(n,j) = zero
sigmao(n,j) = zero
beta(n,j) = zero
q(n,j) = zero
s1(n,j) = zero
s2(n,j) = zero
s3(n,j) = zero
epsi1(n,j) = zero
epsi2(n,j) = zero
K(n,j) = zero
Y(j) = zero
deltaZ = zero
pfrac(j) = zero
Temp(n,j) = zero
entropy(n,j)= zero
mat(j) = 0 ! stsm int
dtminj(j) = zero ! stsm
alocal(j) = zero ! stsm
rholocal(j) = zero ! stsm
enddo
enddo
c
do j=1,jmat
do i=1,7
eos(j,i)= 0.d0
enddo
do i=1,4
init(j,i)= 0.d0
enddo
enddo
do j=1,jj
do jzz=1,2
ieos(jzz,j)= 0
enddo
enddo
c---------------------------------------------------------------------
c Read input Data file
c
c print *,'running'
c read(*,*) foo
imat = 0
jsum = 0
c write(*,*) "test"
c open (unit=31,file='ko.in',form='formatted',status='unknown')
open (unit=31,file=fin,form='formatted',status='unknown')
c open (unit=35, file='fko-energy.dat',
c & form='formatted', status='unknown')
print *,'input file: ',fin
c read(*,*) foo
Read(31,'(A149)') text
c print *,text
Read(31,'(A149)') text
c print *,text
c read(*,*) foo
print *,'EOS input'
5 imat=imat+1
c print *,'reading',imat
c read(*,*) foo
Read(31,'(A149)') text
c print *,Text
c print *,'testing text'
c read(*,*) foo
if(text(1:7) .eq. ' ') goto 6
c print *,'text passed.'
iEOS(1,jj-(imat-1)) = imat
Read(text,'(2I7,7e7.3,3e9.3,10e7.3)') !g77 ! reads until there is a blank line and then goto exits the loop
c Read(text,*) !g90
& iEOS(2,jj-(imat-1)),j1(imat),LL(imat),xstart(imat),
& init(imat,1),init(imat,2),init(imat,3),
& init(imat,4),init(imat,5),
& eos(imat,1),eos(imat,2),eos(imat,3),eos(imat,4),
& eos(imat,5),eos(imat,6),eos(imat,7),eos(imat,8),eos(imat,9),
& eos(imat,10),eos(imat,11),eos(imat,12),eos(imat,13)
if ( int(j1(imat)/2) .ne. float(j1(imat))/2.) then
print *,'Error: nodes specificed for a material must be even'
read(*,*) foo
endif
mat(jsum:jsum+j1(imat)) = imat
jsum = jsum + j1(imat)
if (jsum .ge. jj) then
print *,'Error: Increase jj or reduce the # nodes in kov3.in'
read(*,*) foo
endif
C print *,'data at j',imat,eos(imat,7)
C print *,'gg',eos(imat,4)
write (*,'(3I4,13f11.4,2e12.4e2)')
& iEOS(1,jj-(imat-1)),
& iEOS(2,jj-(imat-1)),j1(imat),LL(imat),xstart(imat),
& init(imat,1),init(imat,2),init(imat,3),
& init(imat,4),init(imat,5),
& eos(imat,1),eos(imat,2),eos(imat,3),eos(imat,4),
& eos(imat,5),eos(imat,6),eos(imat,7),eos(imat,8)
c & eos(imat,9),
c & eos(imat,10),eos(imat,11),eos(imat,12)
c read(*,*) foo
goto 5
6 Print *,' '
imat = imat-1
c read(*,*) foo
c
c---------------------------------------------------------------------
c Input boundary conditions
c
Read(31,'(A113)') text
c print *,text
c read(*,*) foo
Read(31,'(A113)') text
c print *,text
c read(*,*) foo
Read(31,'(A113)') text
c print *,text
Read(text,'(I7,5e7.3)') ! g77
c Read(text,*) ! g90
& ibc(0),bc(-1,1),bc(-1,2),bc(-1,3),bc(-1,4),bc(-1,5)
print *,'Boundary Conditions'
write(*,'(I4,5f7.3)') ! g77
& ibc(0),bc(-1,1),bc(-1,2),bc(-1,3),bc(-1,4),bc(-1,5) !note that ibc is stored at jjj just temporarily
c print *,'read Boundary Conditions...',ibc(0)
c read(*,*) foo
Read(31,'(A150)') text
c print *,text
Read(text,'(I7,5e7.3)') ! g77
& ibc(jj),bc( 1,1),bc( 1,2),bc( 1,3),bc( 1,4),bc( 1,5) !note that ibc is stored at jjj just temporarily
c print *,'read Boundary Conditions...',ibc(jj)
write(*,'(I4,5f7.3)') ! g77
& ibc(jj),bc( 1,1),bc( 1,2),bc( 1,3),bc( 1,4),bc( 1,5) !note that ibc is stored at jjj just temporarily
c
Read(31,'(A113)') text
c print *,text
Read(31,'(A113)') text
c print *,text
Read(31,'(e20.3)') tstop ! g77
c print *,'tstop = ',tstop
Read(31,'(A113)') text
c print *,text
Read(31,'(e20.3)') d ! g77 geometry
c print *,'d = ',d
if (d .ne. 1.0) then
if (d .ne. 2.0) then
if (d .ne. 3.0) then
print *,'INVALID GEOMETRY d=',d
print *,'STOP'
read(*,*) foo
endif
endif
endif
!read(*,*) foo ! a debugging stop
close(31)
c
c STS output file format for comparison to pyKO
print *,'output file: ',fout
open (unit=33, file=fout, form='formatted', status='unknown')
write(33,*) "step j ibc mat time r(0) r(1) r(2) pos
& up vr rho rho0 iev0 pres sigmar s1 s2 q dtminj phi beta
& eps1 eps2 deltaz aj rhoj sigmao temp etot"
c open (unit=34, file=foutlong, form='formatted', status='unknown')
c write(34,*) "step j ibc mat time r(0) r(1) r(2) pos
c & up vr rho rho0 iev0 pres sigmar s1 s2 q dtminj phi beta
c & eps1 eps2 deltaz aj rhoj sigmao temp etot"
cc---------------------------------------------------------------------
c Distritazation LOOP -- assign initial mass
c
C print *,'distrize ..'
c read(*,*) foo
r(0,1) = xstart(1) ! stsm these 2 statement are overwritten below
r(1,1) = xstart(1)
do jjj=1,imat
C print *,'distrize ..',jjj
c read(*,*) foo
deltar = Ll(jjj)/dfloat(j1(jjj)/2)
C write(*,'(a6,1x,3e24.16)') 'deltar',deltar
c read(*,*) foo
if (jjj .eq. 1) then ! this if assigns the ipoint to the first node of the material
! and checks to see it materials are initally in contact.
ipoint = 0
elseif (abs(r(0,ipoint+j1(jjj-1))-xstart(jjj)) .lt. 1.e-5) then
c no gap between materials
r(0,ipoint+j1(jjj-1)) = xstart(jjj)
r(1,ipoint+j1(jjj-1)) = xstart(jjj)
r(2,ipoint+j1(jjj-1)) = xstart(jjj)
r(3,ipoint+j1(jjj-1)) = xstart(jjj)
ibc(ipoint+j1(jjj-1)) = 0
ipoint = ipoint+j1(jjj-1)
elseif ( r(0,ipoint+j1(jjj-1)) .lt. xstart(jjj)) then
c inital gap between materials
ipoint = ipoint+j1(jjj-1)+2
ibc(ipoint ) = -2
ieos(2,ipoint-1)= 0
ibc(ipoint-2) = 2
else
print *,'Input Geometry Error!'
read(*,*) foo
endif
c ! here if ipoint=0 for first material
r(0,ipoint) = xstart(jjj) ! jjj=1
r(1,ipoint) = xstart(jjj)
r(2,ipoint) = xstart(jjj) ! jjj=1
r(3,ipoint) = xstart(jjj)
ibc(1) = 0
U(0,ipoint) = init(jjj,2)
U(1,ipoint) = init(jjj,2)
U(2,ipoint) = init(jjj,2)
U(3,ipoint) = init(jjj,2)
do j=ipoint+2,ipoint+j1(jjj),2 !node definitions
ibc(j) = 0 !this defines the node as a centeral difference
r(0,j) = r(0,j-2) + deltar
r(1,j) = r(1,j-2) + deltar
r(2,j) = r(2,j-2) + deltar
r(3,j) = r(3,j-2) + deltar
U(0,j) = init(jjj,2)
U(1,j) = init(jjj,2)
U(2,j) = init(jjj,2)
U(3,j) = init(jjj,2)
enddo
c read(*,*) foo
do j=ipoint+1,ipoint+j1(jjj)-1,2 !cell definitions initial conditions
ibc(j) = 0 !this defines the cell as a centeral difference
r(0,j) = 0.5d0*(r(0,j+1)+r(0,j-1))
r(1,j) = 0.5d0*(r(1,j+1)+r(1,j-1))
P(0,j) = init(jjj,1)
P(1,j) = init(jjj,1)
P(2,j) = init(jjj,1) ! added by sts
P(3,j) = init(jjj,1) ! added by sts
rho(j) = init(jjj,3) !rho is not updated in time therefore it is always rho0
E(0,j) = init(jjj,4) ! this gets overwritten below
E(1,j) = init(jjj,4)
ieos(1,j) = ieos(1,jj-(jjj-1)) !info was stored there (RHS) just temp.
ieos(2,j) = ieos(2,jj-(jjj-1)) !info was stored there (RHS) just temp.
Y(j) = eos(jjj,5)
pfrac(j-1) = eos(jjj,7)
pfrac(j) = eos(jjj,7)
pfrac(j+1) = eos(jjj,7)
enddo
ieos(1,jj-(jjj-1)) = 0 !this assigns values to the last cell center
ieos(2,jj-(jjj-1)) = 0
ibc(j1(jjj)+ipoint) = 2
ibc(j1(jjj)+1+ipoint) = 9
enddo ! jjj loop through imat
ibc(j1(imat)+ipoint) = ibc(jj) !this assigns values to the last node
c rho(j1(imat)+ipoint+1) = init(imat,3) !rho is not updated in time therefore it is always rho0
c print *,'ipoint',j1(imat)+ipoint,ibc(jj),
c c init(imat-1,3),init(imat,3)
c
C print *,'Assign mass to nodes'
c
do j=0,jj-2,2
if (ibc(j+1) .eq. 0) then
m(j+1) = rho(j+1)*((r(0,j+2)**d- r(0,j)**d)/d)
endif
enddo
c read(*,*) foo
c---------------------------------------------------------------------
c set initial specific volume
do j=0,jj-2,2
if (ibc(j+1) .eq. 0) then
V(0,j+1)=rho(j+1)*((r(0,j+2)**d-r(0,j)**d)/d)/m(j+1)
V(1,j+1)=rho(j+1)*((r(0,j+2)**d-r(0,j)**d)/d)/m(j+1)
c
E(0,j+1)=P(0,j+1)/(v(0,j+1)*eos(ieos(1,j+1),4)-1)
E(1,j+1)=P(1,j+1)/(v(1,j+1)*eos(ieos(1,j+1),4)-1)
Temp(0,j+1) =E(0,j+1)/(rho(j+1)*eos(ieos(1,j+1),8))
Temp(1,j+1) =E(1,j+1)/(rho(j+1)*eos(ieos(1,j+1),8))
entropy(0,j+1) = 6.8d-5 ! i got this from a VT website EES thing
entropy(1,j+1) = 6.8d-5 ! units mbar-cc/K/g
! sts added for first time step output
V(2,j+1)=rho(j+1)*((r(0,j+2)**d-r(0,j)**d)/d)/m(j+1)
V(3,j+1)=rho(j+1)*((r(0,j+2)**d-r(0,j)**d)/d)/m(j+1)
E(2,j+1)=P(0,j+1)/(v(0,j+1)*eos(ieos(1,j+1),4)-1)
E(3,j+1)=P(1,j+1)/(v(1,j+1)*eos(ieos(1,j+1),4)-1)
Temp(2,j+1) =E(0,j+1)/(rho(j+1)*eos(ieos(1,j+1),8)) ! this needs a loop for each material or an array with cvs STS DEBUG; currently wrong
Temp(3,j+1) =E(1,j+1)/(rho(j+1)*eos(ieos(1,j+1),8))
C print *,'Pres [Mbar]',P(0,j+1)
C print *,'Engr [MBar-cc/cc]',E(0,j+1)
C print *,'Volm [cc]',((r(0,j+2)**d-r(0,j)**d)/d)
C print *,'temp*[K]',Temp(0,j+1),rho(j+1),m(j+1),v(0,j+1)
C print *,'entropy',entropy(0,j+1),eos(ieos(1,j+1),8)
c print *,'rho(j+1)',rho(j+1),Temp(3,j+1),E(3,j+1)
c read(*,*) foo
C print *,'here1',j
c icompact(0,j-2) = 0 ! compaction flag for use with snow plow type models initilized to zero
c print *,'here2',j
c icompact(1,j-2) = 0 ! compaction flag for use with snow plow type models initilized to zero
c print *,'here3',j
c icompact(2,j-2) = 0 ! compaction flag for use with snow plow type models initilized to zero
c print *,'i am here'
c read(*,*) foo
endif
enddo
c---------------------------------------------------------------------
c Output Initial Conditions to screen
c
n=1
C write(*,98)
C &'j','ibc',' rad',' rad','Vel','Vel'
C &,'pres','Vol'
c do j=0,jj-2,2
C do j=0,jj-2,1
c write(*,'(I4,0I2,10f15.7)')
C write(*,*)
C & j, !ieos(1,j+1),ieos(2,j+1),
C & !ibc(j),ibc(j+1),ibc(j+2),
C & ibc(j),r(n,j),r(n,j+1),r(n,j+2),U(n,j),P(n,j+1)!,
C & !v(n,j+1),m(j+1),rho(j+1),Y(j+1)
C enddo
c
c STS write initial conditions as 0th time step
qtotal = 0.
mvtotal = 0.
ketotal = 0.
ietotal = 0.
etotal = 0.
do j = 0,jj-2,2
if (ibc(j+1) .eq. 0) then
qtotal = qtotal + q(n+2,j)
mvtotal = mvtotal + m(j+1)*( u(n+1,j) + u(n+1,j+2) )/2.d0
ketotal = ketotal + 0.5*m(j+1)*
& (0.5*((u(n+1,j) + u(n+1,j+2))))**2
ietotal = ietotal + E(n+2,j+1)/rho(j+1)*m(j+1)
etotal = ietotal + ketotal
endif
enddo
do j=0,jj-1,2
rhoout= 0.
if (ibc(j) .eq. 0) then
rhoout = rho(j+1)/v(n+2,j+1)
endif
write(33,'(4I6,26e17.8e3)')
& stepn, j, ibc(j), mat(j),
& t(n+2), r(n-1,j), r(n,j),r(n+1,j),r(n+2,j),
& U(n+1,j), V(n+2,j+1), rhoout, rho(j+1),
& E(n+2,j+1), P(n+2,j+1), sigmar(n,j+1), s1(n+2,j+1),
& s2(n+2,j+1),q(n+1,j+1),dtminj(j),phi(n,j),beta(n,j),
& epsi1(n+1,j+1),epsi2(n+1,j+1),deltaZarr(j),
& alocal(j+1),rholocal(j+1),sigmao(n,j+1),Temp(n+1,j+1),
& etotal
enddo ! this is j loop
c
c do j=0,jj-1,1
c write(34,'(4I6,26e17.8e3)')
c & stepn, j, ibc(j), mat(j),
c & t(n+2), r(n-1,j), r(n,j),r(n+1,j),r(n+2,j),
c & U(n+1,j), V(n+2,j+1), rhoout, rho(j+1),
c & E(n+2,j+1), P(n+2,j+1), sigmar(n,j+1), s1(n+2,j+1),
c & s2(n+2,j+1),q(n+1,j+1),dtminj(j),phi(n,j),beta(n,j),
c & epsi1(n+1,j+1),epsi2(n+1,j+1),deltaZarr(j),
c & alocal(j+1),rholocal(j+1),sigmao(n,j+1),Temp(n+2,j+1),
c & etotal
c enddo ! this is j loop
stepn=1 ! advance for the first time step
print *,'Start Main Loop, goto tstop = ',tstop
c read(*,*) foo
c
98 format(2A3,11x,A9,A9,A9,A10,a8)
c99 format(2I3,e9.2,9e9.2,2f7.4,6e9.2)
c
c*****************************************************************************
c******************************** MAIN LOOP **********************************
c*****************************************************************************
c
call cpu_time(startTime)
ncount = -1
c if (t(n) .le. tstop) then
1 ncount = ncount + 2 ! when this use to count to an integer, ncount was the max integer
n = 1 ! this use to be the time step counter when all n data was stored
! n must remain n=1 because the time data is no longer stored
!if( m(1) .ne. m(3) ) then
! print *,'Masses do not match',n,m(1),m(3)
!read(*,*) foo ! keep going to see if cylindrical and spherical geometries will work
!endif
c
cccccccccccccccc Contact Check ccccccccccccccccccccccc
c
c calculate exact time of contact between 2 nodes to meet at one point
c removes the extra node and then joins
c every node is assigned a value; if zero then a central different node
c ibc is -1 or 1; second order left stencil or second order right stencil -- could be a rigid wall or inflow or outflow
c every node has a boundary condition
c -2 and -3; +2 +3 are internal boundaries (planes or fractures)
c CONTACT IS NOT IN WILKINS BOOK - this is Borg code
c
if (1 .eq. 0) then ! if you have a gap -- when contact need to eliminate a surface node and join the 2 surfaces together
do j=0,jj,2
if (ibc(j) .ne. 9) then
delt = (t(n+1)-t(n-1))/2.d0
r(n+2,j) = r(n,j)+U(n-1,j)*delt*2.0d0
r(n+1,j) = (r(n,j)+r(n+2,j))/2.d0
endif
enddo
c
do j=2,jj-2,2
if ( ibc(j) .ne. 9 .and. r(n+2,j) .le. r(n+2,j-2) .and.
& ibc(j-1) .eq. 9) then
icontact = 2
ibc(j) = -3 !this is a flag to let the contact stuff after the
! momentum step know that
! the delta t was recaclulated so that the two nodes
! that are about to collide will touch perfectely after
! this time step.
print *,'Contact Eminent!',n,j
print *,'Previous half Time step',t(n)-t(n-1)
print *,'For time step 2 x Deltat',2.d0*delt
Print *,' Estimated collision:'
print *,'Void Node at ',r(n,j-2),' will move to ',
& r(n,j-2)+U(n-1,j-2)*2.d0*deltat
print *,'Void node velocity',U(n-1,j-2)
print *,'J Node at ',r(n,j),' will move to ',
& r(n,j) +U(n-1,j )*2.d0*delt
print *,'J node velocity',U(n-1,j)
jjv = j-2
jjj = j
ww = U(n-1,jjj) - U(n-1,jjv)
rr = r(n ,jjj) - r(n ,jjv)
c
c this is the ibc(j)= 1 for the inside (v) side of the boundary
sigmar(n,jjv-1) = (-(P(n,jjv-1)+q(n-1,jjv-1))+s1(n,jjv-1))
sigmao(n,jjv-1) = (-(P(n,jjv-1)+q(n-1,jjv-1))+s2(n,jjv-1))
phiv = (rho(jjv-1)*((r(n,jjv)-r(n,jjv-2))/V(n,jjv-1)))/2.d0
betav = (sigmar(n,jjv-1)-sigmao(n,jjv-1))*V(n,jjj-1)/
& (r(n,jjv-1)*rho(jjv-1))
c this is the ibc(j)=-1 for the outside (j) side of the boundary
sigmar(n,jjj+1) = (-(P(n,jjj+1)+q(n-1,jjj+1))+s1(n,jjj+1))
sigmao(n,jjj+1) = (-(P(n,jjj+1)+q(n-1,jjj+1))+s2(n,jjj+1))
phij = (rho(jjj+1)*((r(n,jjj+2)-r(n,jjj))/V(n,jjj+1)))/2.d0
betaj = (sigmar(n,jjj+1)-sigmao(n,jjj+1))*V(n,jjj+1)/
& (r(n,jjj+1)*rho(jjj+1))
c
aa = sigmar(n,jjj+1)/phij + sigmar(n,jjv-1)/phiv
& + (betav + betaj)*(d-1.d0)
dthalf = t(n) - t(n-1)
bb = (2.d0*ww + aa * dthalf)
dti0 = 0.d0
dti1 = dti0-(aa*dti0*dti0+bb*dti0+2.d0*rr)/(2.d0*aa*dti0+bb)
print *,'sig',sigmar(n,jjj+1),phij,sigmar(n,jjv-1),phiv
print *,'bet',betav,betaj,d
print *,aa,bb,rr,ww
print *,rho(jjv-1),r(n,jjv),r(n,jjv-2),V(n,jjv-1)
print *,rho(jjj+1),r(n,jjj+2),r(n,jjj),V(n,jjj+1)
print *,'betav',sigmar(n,jjv-1),sigmao(n,jjv-1),
& r(n,jjj),r(n,jjj-2),V(n,jjj-1),rho(jjj-1)
c
jj1=0
do while (abs(dti1-dti0) .gt. 1.d-16)
jj1 = jj1 + 1
dti0 = dti1
dti1 = dti0-(aa*dti0*dti0+bb*dti0+2.d0*rr)/(2.d0*aa*dti0+bb)
print *,aa,bb,rr,ww
print *,'iteration',dti0,dti1
if (jj1 .gt.1) read(*,*) foo
enddo
print *,'Whole Time step adjusted from ',2.d0*delt
deltat = dti1/2.d0 !this might need to be adjusted because i changed the way time steping works
print *,'To ',(deltat+dti1)
print *,'where ',dti1,' is the time to impact'
print *,'and ',deltat,' is an arbatrary small number.'
read(*,*) foo
endif !contact if
enddo
read(*,*) foo
endif !contact check if ! need this to do a 1d mesosecale
c
ccccccccccccccccccccccc Advance Time step cccccccccccccccccccccccccccccc
c
c advance time step, for first calculation timestep is set by deltat_0
c after that the time step is calculated after the end of the current time step, deltat
c
if (icontact .eq. 2) then ! if there was contact time step adjusted to perfectly
t(n+1) = t(n) + dti1/2.d0 ! have nodes touch at the end of the time step
t(n+2) = t(n+1) + deltat
icontact = 0
if (dti1 - deltat .lt. 0. .or. t(n+2)-t(n+1) .lt. 0.) then
print *,'Time step Error from contact'
print *, dti1,deltat,dti1 - deltat , t(n+2)-t(n+1)
10 read(*,*) foo
go to 10
endif
else
t(n+1) = t(n) + deltat/2.d0
t(n+2) = t(n) + deltat
endif
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 2. Conservation of Momumtum - start j
c
c Boundary Conditions
c -/+ 1 Free End, stress free
c -/+ 2 and 3 Part of contact check
c -/+ 4 Fixed end
c
c System is failing in this do loop line 450
do j=0,jj-1,2
if (ibc(j+1) .eq. 0) then !this is true for central difference cells
sigmar(n,j+1) = (-(P(n,j+1)+q(n-1,j+1))+s1(n,j+1))
sigmao(n,j+1) = (-(P(n,j+1)+q(n-1,j+1))+s2(n,j+1))
endif
enddo
c
do j=0,jj,2
c
delt = t(n+1)-t(n-1) !this is different than deltat, deltat is the true timestep
if (ibc(j) .ne. 9) then
if (ibc(j) .eq. -1) then
phi(n,j) = (rho(j+1)*((r(n,j+2)-r(n,j))/V(n,j+1)))/2.d0
beta(n,j) = (sigmar(n,j+1)-sigmao(n,j+1))*V(n,j+1)
& /(r(n,j+1)*rho(j+1)) ! STSM this is just the value betewen j and j+2 as written in wilkins
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))
& *( sigmar(n,j+1)+bc(-1,1))+delt*beta(n,j)*(d-1.d0)
c print *,'BC thing',bc(-1,1)
elseif (ibc(j) .eq. 1) then
phi(n,j) = rho(j-1)*((r(n,j)-r(n,j-2))/V(n,j-1))/2.d0
beta(n,j) = (sigmar(n,j-1)-sigmao(n,j-1))*V(n,j-1)
& /(r(n,j-1)*rho(j-1))
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))
& *(-bc( 1,1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0)
c U(n+1,j) = 0.d0
c
c this is the new way which treats the voids like inner or outer bc's
elseif (ibc(j) .eq. -2 .or. ibc(j) .eq. -3) then
phi(n,j) = (rho(j+1)*((r(n,j+2)-r(n,j))/V(n,j+1)))/2.d0
beta(n,j) = (sigmar(n,j+1)-sigmao(n,j+1))*V(n,j+1)
& /(r(n,j+1)*rho(j+1))
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))
& *(sigmar(n,j+1)+pvoid)+delt*beta(n,j)*(d-1.d0)
elseif (ibc(j) .eq. 2) then
phi(n,j) = rho(j-1)*((r(n,j)-r(n,j-2))/V(n,j-1))/2.d0
beta(n,j) = (sigmar(n,j-1)-sigmao(n,j-1))*V(n,j-1)
& /(r(n,j-1)*rho(j-1))
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))
& *(pvoid-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0)
elseif (ibc(j) .eq. 0) then ! this is a central node and will follow equations B-2 for central nodes !! MAIN CENTRAL CELLS
phi(n,j) = (0.5d0)*(rho(j+1)*((r(n,j+2)-r(n,j))/V(n,j+1))+
& rho(j-1)*((r(n,j)-r(n,j-2))/V(n,j-1)))
beta(n,j)=( (sigmar(n,j+1)-sigmao(n,j+1))*(V(n,j+1)/rho(j+1))/
& (0.5d0*(r(n,j+2)+r(n,j ))) +
& (sigmar(n,j-1)-sigmao(n,j-1))*(V(n,j-1)/rho(j-1))/
& (0.5d0*(r(n,j )+r(n,j-2))) )/2.d0
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))
& *(sigmar(n,j+1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0)
elseif (ibc(j) .eq. -4) then ! fixed boundary condition -4 or 4
U(n+1,j) = 0.d0
c if ( U(n+1,j) .lt. 1.d-5) U(n+1,j) = 0.d0
elseif (ibc(j) .eq. 4) then
U(n+1,j) = 0.d0
c if ( U(n+1,j) .lt. 1.d-5) U(n+1,j) = 0.d0
else
print *,'Momentum ERROR!!!'
print *,j,ibc(j)
read(*,*) foo
endif
c
endif
enddo
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 3. Position - within j
c
do j=0,jj,2
if (ibc(j) .ne. 9) then ! 9 is reserved for extra nodes usually add 10 or 20 extra nodes; nodes at r=0 with 0 stress and pressure -- extra nodes used for spalling
r(n+2,j) = r(n,j)+U(n+1,j)*deltat
r(n+1,j) = (r(n,j)+r(n+2,j))/2.d0
endif
enddo
c debug block
if (idebug .eq. 1 .and. ncount .ge. ndebug) then
j=jdebug
print *,'j=',j,'n=',n,'ncount=',ncount
print *,'time',t(n-1),t(n),t(n+1),t(n+2)
print *,'deltat',deltat,delt
print *,'vel',U(n,j),U(n+1,j)
print *,'r',r(n,j-2),r(n,j),r(n,j+2)
print *,'V',V(n,j+1),V(n,j),V(n,j-1)
print *,'rho',rho(j-1),rho(j),rho(j+1)
print *,'sigmar',sigmar(n,j+1),sigmar(n,j-1)
print *,'sigmao',sigmao(n,j-1),sigmao(n,j+1)
print *,'4',phi(n,j),beta(n,j),U(n-1,j)
print *,'5',(deltat/phi(n,j))*(sigmar(n,j+1)-0.d0)
read(*,*) foo
endif
c print *,'Line 537'
c
cccccc Begin the connection of nodes due to contact check
c
do j=2,jj-2,2 ! print info for the node contact
if ( ibc(j) .eq. -3 ) then
print *,'Joining Nodes',j-2,' and ',j,' at n= ',n
print *,'Before Joining:'
print *,'The two nodes (VOID (left)and J(right)) at:'
print *,'left: r(void,n-2)=',r(n,j-4),' U= ',U(n-1,j-4)
print *,'VOID: r(void,n-2)=',r(n,j-2),' U= ',U(n-1,j-2)
print *,'J: r(j ,n-2)=',r(n,j) ,' U= ',U(n-1,j)
print *,'right:r(j ,n-2)=',r(n,j+2),' U= ',U(n-1,j+2)
print *,'then stepped to:'
print *,'left: r(-2 )=',r(n+2,j-4),' U= ',U(n+1,j-4)
print *,'VOID: r(void)=',r(n+2,j-2),' U= ',U(n+1,j-2)
print *,'J: r(j )=',r(n+2,j) ,' U= ',U(n+1,j)
print *,'right:r(+2 )=',r(n+2,j+2),' U= ',U(n+1,j+2)
print *,'where they were joined'
ibc(j) = 0
Usave = (m(j+1)*U(n+1,j)+m(j-3)*U(n+1,j-2))
& /(m(j-3)+m(j+1))
print *,'Usave',usave,m(j+1),U(n+1,j),m(j-3),U(n+1,j-2)
& ,m(j-3),m(j+1)
do jjj = j-2,jj-2 ! shifts all the nodes together
do nz = n,n+2
ibc( jjj ) = ibc( jjj+2)
ibc( jjj+1) = ibc( jjj+3)
ieos(1, jjj+1) = ieos(1, jjj+3)
ieos(2, jjj+1) = ieos(2, jjj+3)
m( jjj ) = m( jjj+2)
rho( jjj+1) = rho( jjj+3)
r(nz ,jjj ) = r(nz ,jjj+2)
U(nz ,jjj ) = U(nz ,jjj+2)
phi(nz ,jjj ) = phi(nz ,jjj+2)
beta(nz ,jjj ) = beta(nz ,jjj+2)
sigmar(nz ,jjj+1) = sigmar(nz ,jjj+3)
sigmao(nz ,jjj+1) = sigmao(nz ,jjj+3)
V(nz ,jjj+1) = V(nz ,jjj+3)
s1(nz ,jjj+1) = s1(nz ,jjj+3)
s2(nz ,jjj+1) = s2(nz ,jjj+3)
s3(nz ,jjj+1) = s3(nz ,jjj+3)
E(nz ,jjj+1) = E(nz ,jjj+3)
Y( jjj+1) = Y( jjj+3)
pfrac( jjj ) = pfrac( jjj+2) !node value
pfrac( jjj+1) = pfrac( jjj+3) !Cell value
enddo
enddo
U(n+1 ,j -2) = Usave
pfrac( j -2) = 1.d-2
c Y( j -1) = 0.d0 !ie the materials are not welded after impact
c r(n+2 ,j -2) = r(n+1,j-2)+Usave*(t(n+2)-t(n+1))
c if (abs(r(0,ipoint+j1(jjj-1))-xstart(jjj)) .lt. 1.e-5) then
c Print *,'Warning: Joined moved to same spot'
c endif
print *,'After Joining:'
print *,'left: r(j-2)=',r(n+2,j-4),' U= ',u(n+1,j-4)
print *,'New: r(j) = ',r(n+2,j-2),' U= ',usave
print *,'right:r(j+2)=',r(n+2,j ),' U= ',u(n+1,j)
read(*,*) foo
do jzz=1,jj-2,2
write(*,'(I4,5I2,3f7.3,2e9.3,5f7.3)')
& jzz,ieos(1,jzz),ieos(2,jzz),
& ibc(jzz-1),ibc(jzz),ibc(jzz+1),
& r(n+2,jzz-1),r(n+2,jzz),r(n+2,jzz+2),
& U(n+1,jzz-1),U(n+1,jzz+2),U(n+1,jzz+1)
c & ,v(n+2,jzz+1),m(jzz+1),rho(jzz+1),y(jzz+1),pfrac(jzz+2)
enddo
read(*,*) foo
endif
enddo
c print *,'line 608'
cccccccccccccccccccccc End of contact ccccccccccccccccccccccccccccc
c Node passes it's neighbor check
c check that no nodes are overlapping
c
do j=2,jj-2,2
if ( ibc(j) .ne. 9 .and. r(n+2,j) .lt. r(n+2,j-2) ) then
print *,'Contact Check Failed',t(n),j
print *,'Try lowering time step'
print *,'Void',r(n+2,j-2),U(n+1,j-2)
print *,'j ',r(n+2,j) ,U(n+1,j)
print *,'deltat',deltat
print *,bc(-1,1),bc(1,1)
read(*,*) foo
endif
enddo
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 3. Relative VOLUME - within j
c B-3 conservation of mass
c deltat = t(n+2)-t(n)
c print *,'line 626'
c read(*,*) foo
do j=0,jj-2,2
if (ibc(j+1) .eq. 0) then
c
r(n+1,j+1) = ( r(n+1,j)+r(n+1,j+2) ) /2.d0 ! average data in the intermediate nodes - central; staggered mesh in time and space
r(n+2,j+1) = ( r(n+2,j)+r(n+2,j+2) ) /2.d0
c
V(n+2,j+1)=rho(j+1)*((r(n+2,j+2)**d-r(n+2,j)**d)/d)/m(j+1)
V(n+1,j+1)=rho(j+1)*((r(n+1,j+2)**d-r(n+1,j)**d)/d)/m(j+1)
c
if ( V(n+2,j+1) .eq. 0.) then
print *,'------------- Zero volume error! #1-----------------'
print *,'volume',n,j+1,r(n+2,j+2),r(n+2,j),V(n+2,j+1)
read(*,*) foo
endif
if ( V(n+1,j+1) .eq. 0.) then
print *,'------------- Zero volume error! #2-----------------'
print *,'volume',n,j+1,r(n+1,j+2),r(n+1,j),V(n+1,j+1)
read(*,*) foo
endif
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 4. VELOCITY STRAINS - finish j
c half steps in time and space
epsi1(n+1,j+1) = (U(n+1,j+2)-U(n+1,j))/(r(n+1,j+2)-r(n+1,j))
epdt1(n+1,j+1) = (epsi1(n+1,j+1)-epsi1(n-1,j+1))/deltat !this is 1st order accurate ! stsm not used here
if (d .eq. 1.) then
epsi2(n+1,j+1) = 0.d0
else
epsi2(n+1,j+1) = (U(n+1,j+2)+U(n+1,j))/(r(n+1,j+2)+r(n+1,j))
endif
endif
enddo ! end j loop for volume
c-------------------- AMR Feature -------------------------------
if (idebug .eq. 1 .and. n .ge. ndebug) then
j=jdebug
print *,'r',j,r(n+2,j+1),m(j+1)
print *,'epsil',j,V(n+1,j+1),V(n+2,j+1),
& epsi1(n+1,j+1),epsi2(n+1,j+1)
read(*,*) foo
endif
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 5a. STRESSES - start j
c B-5 stress deviators and then pressure done below 5b
c print *,'line 679'
do j=0,jj-2,2
if (ibc(j+1) .eq. 0) then
c deltat = t(n+2)-t(n)
if (iEOS(2,j+1) .ne. 3) then
s1(n+2,j+1) = s1(n,j+1) + 2.d0*eos(ieos(1,j+1),6)
& * ( epsi1(n+1,j+1)*deltat
& - (V(n+2,j+1)-V(n,j+1))/(3.d0*V(n+1,j+1)) )
s2(n+2,j+1) = s2(n,j+1) + 2.d0*eos(ieos(1,j+1),6)
& * ( epsi2(n+1,j+1)*deltat
& - (V(n+2,j+1)-V(n,j+1))/(3.d0*V(n+1,j+1)) )
s3(n+2,j+1) = -(s1(n+2,j+1)+s2(n+2,j+1))
c
s1(n+1,j+1) = ( s1(n+2,j+1) + s1(n,j+1) )/2.d0 ! fill in the staggered mesh averages
s2(n+1,j+1) = ( s2(n+2,j+1) + s2(n,j+1) )/2.d0
s3(n+1,j+1) = ( s3(n+2,j+1) + s3(n,j+1) )/2.d0
else !Gamma law ideal gas Newtonian Stress
s1(n+2,j+1) = 4.d0*1.8d-10*epsi1(n+1,j+1)/3.d0
& -1.387e-6* (V(n+2,j+1)-V(n,j+1))/V(n+1,j+1)
c s1(n+2,j+1) = s1(n,j+1)+4.d0*1.8d-10*epdt1(n+1,j+1)*deltat/3.d0
c & -1.387e-6* (V(n+2,j+1)-V(n,j+1))/(3.d0*V(n+1,j+1))
c
c print *,epdt1(n+1,j+1),epsi1(n+1,j+1),epsi1(n-1,j+1)
c
s1(n+1,j+1) = ( s1(n+2,j+1) + s1(n,j+1) )/2.d0
endif ! iEOS check
c
endif
enddo
if (idebug .eq. 1 .and. n .ge. ndebug) then
j=jdebug
j=199
print *,'1',j,eos(ieos(1,j+1),6),V(n+2,j+1),V(n,j+1),V(n+1,j+1)
print *,'s',s1(n+2,j+1),s2(n+2,j+1),s3(n+2,j+1),
& epsi1(n+1,j+1),deltat
endif
c if (idebug .eq. 1 .and. n .ge. ndebug) read(*,*) foo
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 6. VON MISES YIELD CONDITION - start j
c
do j=0,jj-2,2
if (ibc(j+1) .eq. 0) then
if (iEOS(2,j+1) .ne. 3) then
c calculate the deviatoric strain at n+1 and compare it to the yield strength
c
k(n+1,j+1) =(s1(n+1,j+1)**2 + s2(n+1,j+1)**2 + s3(n+1,j+1)**2)
& -(2.d0/3.d0)*Y(j+1)**2
c print *,'Yield check',Y(j+1),k(n+2,j+1)
if (k(n+1,j+1) .gt. 0.) then
c Print *,'material yielded',j,k(n+2,j+1)
c read(*,*) foo
c print *,s1(n+2,j+1),s2(n+2,j+1),s3(n+2,j+1)
xx = sqrt(s1(n+1,j+1)**2 + s2(n+1,j+1)**2 + s3(n+1,j+1)**2)
xx = sqrt(2.d0/3.d0)*Y(j+1)/xx
s1(n+1,j+1) = xx*s1(n+1,j+1)
s2(n+1,j+1) = xx*s2(n+1,j+1)
s3(n+1,j+1) = xx*s3(n+1,j+1)
endif
c calculate the deviatoric strain at n+2 and compare it to the yield strength
k(n+2,j+1) =(s1(n+2,j+1)**2 + s2(n+2,j+1)**2 + s3(n+2,j+1)**2)
& -(2.d0/3.d0)*Y(j+1)**2
c print *,'Yield check',Y(j+1),k(n+2,j+1)
if (k(n+2,j+1) .gt. 0.) then
c Print *,'material yielded',j,k(n+2,j+1)
c read(*,*) foo
c print *,s1(n+2,j+1),s2(n+2,j+1),s3(n+2,j+1)
xx = sqrt(s1(n+2,j+1)**2 + s2(n+2,j+1)**2 + s3(n+2,j+1)**2)
xx = sqrt(2.d0/3.d0)*Y(j+1)/xx
s1(n+2,j+1) = xx*s1(n+2,j+1)
s2(n+2,j+1) = xx*s2(n+2,j+1)
s3(n+2,j+1) = xx*s3(n+2,j+1)
c s1(n+1,j+1) = ( s1(n+2,j+1) + s1(n,j+1) )/2.d0
c s2(n+1,j+1) = ( s2(n+2,j+1) + s2(n,j+1) )/2.d0
c s3(n+1,j+1) = ( s3(n+2,j+1) + s3(n,j+1) )/2.d0
c Print *,'material yielded',j,k(n+2,j+1),Y(j+1)
else !iEOS = 3, i.e. gamma law gas
endif
c
c print *,s1(n+2,j+1),s2(n+2,j+1),s3(n+2,j+1)
if(idebug .eq. 1 ) then
Print *,'Yield Check',Y(j+1),k(n+2,j+1)
read(*,*) foo
endif ! debug if
endif !ibc(j+1) .eq. 0
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 7. ARTIFICIAL VISCOSITY - within j
c
if (1 .eq. 1) then
c print *,j,u(n+1,j+2),u(n+1,j)
if( u(n+1,j+2) .lt. u(n+1,j) .and.
& V(n+2,j+1)-V(n,j+1) .lt. 0. ) then
xx = rho(j+1)/V(n+1,j+1)
if (p(n,j+1) .lt. 0.) then
c print *,'Negative Pressure!'
a = dsqrt(-P(n,j+1)/xx)
else
a = dsqrt( P(n,j+1)/xx)
endif
if (dabs(P(n,j+1)) .lt. 0.002d0) a = 0.d0
rholocal(j+1) = xx
alocal(j+1) = a
c print *,'Sound Speed',j,P(n,j+1),xx,a
q(n+1,j+1) = Co*Co*xx* (U(n+1,j+2)-U(n+1,j))**2
& + CL*a *xx*dabs(U(n+1,j+2)-U(n+1,j))
else
q(n+1,j+1)=0.d0
endif
endif ! if vel strain and volume check is on
endif ! if 1=1
enddo !j counter
if (idebug .eq. 1 .and. n .ge. ndebug) then
j=jdebug
print *,'Q',j,q(n+1,j+1),xx,(U(n+1,j+2)-U(n+1,j)),
& a,rho(j+1),v(n,j+1),P(n,j+1)
endif
if(idebug .eq.1 .and. n .ge. ndebug) read(*,*) foo
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c 8. ENERGY - start j
c EOS provides the internal energy at V and P
c iEOS(2,imat)=1 - Mie Grunisen
c iEOS(2,imat)=2 - Gamma law ideal gas
c iEOS(2,imat)=3 - Gamma law ideal gas with Newtonian Stress and heat transfer
c iEOS(2,imat)=4 - snow plow model with KO inputs for Hugoniot
c iEOS(2,imat)=5 - snow plow model with anamolous hugoniot
c iEOS(2,imat)=6 - P-alpha Model
c
do j=0,jj-2,2
if (ibc(j+1) .eq. 0) then
c
if (iEOS(2,j+1) .eq. 1) then !Mie Grunisen
gamma0 = eos(ieos(1,j+1),4)
k1 = rho(j+1)*eos(ieos(1,j+1),1)**2
k2 = k1*(2.d0*eos(ieos(1,j+1),2)-gamma0/2.d0)
k3 = k1*(3.d0*eos(ieos(1,j+1),2)-gamma0)*eos(ieos(1,j+1),2)
qbar = (q(n+1,j+1)+q(n-1,j+1))/2.d0
deltaZ = V(n+1,j+1)*(s1(n+1,j+1)*epsi1(n+1,j+1)
& +(d-1.d0)*s2(n+1,j+1)*epsi2(n+1,j+1))*deltat
deltaZarr(j) = deltaZ
strain = 1.d0 - V(n+2,j+1)
xb = gamma0 !gamma
if(strain .lt. 0.d0) then
xa = k1*strain + k3*strain**3
else
xa = k1*strain + k2*strain**2 + k3*strain**3
endif
E(n+2,j+1)=
& ( E(n,j+1)-((xa+P(n,j+1))/2.d0+ qbar)*(V(n+2,j+1)-V(n,j+1))
& + deltaZ )
& / (1.d0 + xb*(V(n+2,j+1)-V(n,j+1))/2.d0)
E(n+1,j+1)= ( E(n+2,j+1) + E(n,j+1) )/2.d0
c if (n .eq. 33) then
c write (*,'(a2,I3,9e9.2)')
c & 'E ',j,E(n+2,j+1),E(n+2,j+1),xa,P(n,j+1),qbar,deltaZ
c & ,V(n+2,j+1),V(n,j+1)
cc read(*,*) foo
c endif
c
elseif (iEOS(2,j+1) .eq. 2) then !Gamma law ideal gas
qbar = (q(n+1,j+1)+q(n-1,j+1))/2.d0
delt = t(n+1)-t(n)
deltaZ = V(n+1,j+1)*(s1(n+1,j+1)*epsi1(n+1,j+1)
& +(d-1.d0)*s2(n+1,j+1)*epsi2(n+1,j+1))*delt
c
xa = 0.d0
xb = (eos(ieos(1,j+1),4)-1.d0)/V(n+2,j+1) !gamma
E(n+2,j+1)= ( E(n,j+1)
& -((xa+P(n,j+1))/2.d0+ qbar)*(V(n+2,j+1)-V(n,j+1)) + deltaZ )/
& (1.d0+xb*(V(n+2,j+1)-V(n,j+1))/2.d0)