forked from ImpactsWiki/pyko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKOMatlabv0_2.m
1933 lines (1782 loc) · 76.1 KB
/
KOMatlabv0_2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%% Slower KO program for ease of coding
% Adapted from Mark L. Wilkins KO Program
% By Nathaniel Helminiak
% Fortran Version Maintained by John Borg
%https://www.eng.mu.edu/shockphysics/KO/
% C Version Maintained by David Helminiak
%https://github.com/Yatagarasu50469/KO-Hydrocode
%-------------------Version History-------------------
% V0_1 Coded Version
% V0_2 Updated Timesetting and added output
%-------------------SUGGESTED TO DO-------------------
% Add better comments and clean
% Add input deck
% Add more strength models such as JC
% Add material library
% Add local timestep based on local info speed
% Add parallelization
%% Clean Workspace
clc
clear
close all
% c KO see Springer book by Wilkins, M.
% c "Computer simulations of Dynamic Phenomena"
% parameter(jj = 1510) !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
% 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)
%
% 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)
% real*8 deltaZ, Vdot ,dt_min, dr_min,delt_temp
% real*8 deltar, qbar
% real*8 a, b, Co, CL, d ,a_min,b_min,rho_min
% 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
% character*20 name
% character*172 text
%% Initial Variables
tstop=2 %Stop Time
jj = 20*6; %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
jmat=7; %number of materials
nmax=4; %NSH number of placeholders for time: t(1) and t(2) current, t(3) and t(4) new
Co = 2; %artifical viscoity constants, default=2
CL = 1; %artifical viscoity constants, default=1
pvoid = 0; %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 = 1; %defines geometry (1-1D planar, 2-1D cylinderical-never tested), see willkins
deltat_0 = 3.0d-3;
delt = 3.0d-3;
iskip = 1; %number of iterations to skip to echo to screen
tskip = 0; % this is the value at which data starts getting written to file
dtskip = 0.01; % This is the amount of time skipped between writes to file
amr = 0; % this is an adaptive mesh refinement (1 is on - 0 is off)
flag = 0;
init=zeros(jmat,16);
P=zeros(nmax+1,jj+1);
m=zeros(1,jj+1);
E=zeros(nmax+1,jj+1);
V=zeros(nmax+1,jj+1);
rho=zeros(1,jj+1);
%% Zero All Variables
fprintf('Initializing variables ...\n')
zero = 0;
for n = 0+1:nmax+1
for j = 0+1:jj+1
ibc(j) = 9; % these are non-used nodes
U(n,j) = zero;
U2(n,j) = zero;
r(n,j) = zero;
t(n) = deltat_0*single(n-1);
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;
end
end
for j=1:jmat
for i=1+1:7+1
eos(j,i)= 0.d0;
end
for i=1:4
init(j,i)= 0.d0;
end
end
for j=1+1:jj+1
for jzz=1:2
ieos(jzz,j)= 0;
end
end
%% Read In Materials
fprintf('running\n')
imat = 0; %number of materials
jsum = 0;
% jGeometry: cm cm Mbar cm/us g/cc g/cc cm/us unitless Megabar Megbar Megbar Mbar-cc/K-g
% 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
% iEOS Nodes Length xstart P_0 U_0 Rho_0 E_0 Rho_00 Co s s2 gamma Yeld,Y mu,G pfrac Cv a_p a_e p_e p_s rho_0
%MAT1
MATPROP(1,:)=[ 1 16 0.2 -0.21 0.0E-6 0.0200 8.0 0.000 8.0 0.460 1.49 0.00 2.17 2.5e-3 .79 1.0e9 1.0e-9 0.00 0.00 0.00 0.00 0.00];
%MAT2
MATPROP(2,:)=[ 1 32 0.4 0.0 0.0E-6 0.0000 6.0 0.000 6.0 0.460 1.49 0.00 2.17 2.5e-3 .79 0.25e-1 1.0e-9 0.00 0.00 0.00 0.00 0.00];
temp=size(MATPROP);
imat=temp(1);
for i=1:imat
ieos(1,jj-i+2) = i
end
for imat=1:size(MATPROP)
ieos(2,jj-(imat-1)+1) = MATPROP(imat,1)
j1(imat) = MATPROP(imat,2);
LL(imat) = MATPROP(imat,3);
xstart(imat) = MATPROP(imat,4);
init(imat,1) = MATPROP(imat,5);
init(imat,2) = MATPROP(imat,6);
init(imat,3) = MATPROP(imat,7);
init(imat,4) = MATPROP(imat,8);
init(imat,5) = MATPROP(imat,9);
eos(imat,1) = MATPROP(imat,10);
eos(imat,2) = MATPROP(imat,11);
eos(imat,3) = MATPROP(imat,12);
eos(imat,4) = MATPROP(imat,13);
eos(imat,5) = MATPROP(imat,14);
eos(imat,6) = MATPROP(imat,15);
eos(imat,7) = MATPROP(imat,16);
eos(imat,8) = MATPROP(imat,17);
eos(imat,9) = MATPROP(imat,18);
eos(imat,10) = MATPROP(imat,19);
eos(imat,11) = MATPROP(imat,20);
eos(imat,12) = MATPROP(imat,21);
eos(imat,13) = MATPROP(imat,22);
end
if ( int32(j1(imat)/2) ~= single(j1(imat))/2.)
fprintf('Error: nodes specificed for a material must be even\n')
else
fprintf('OK\n');
end
jsum = jsum + j1(imat);
if (jsum >= jj)
fprintf('Error: Increase jj or reduce the # nodes in kov3.in');
end
fprintf('data at j %2.0f CV %2.0f\n',imat,eos(imat,7));
fprintf('gg Yield %2.0f\n',eos(imat,4));
fprintf('End of material data input file...\n');
%% Boundary Conditions % This ONE is A bit strange
% Boundary Conditions:
% 1 2 3 4 5 6
% iend P_0 U_0 Rho_0 E_0 V_0
% -1 0.0e-1 .0 2.70 0.000 1.0
% 1 0.0e-1 .0 2.70 0.000 1.0
BOUNDARY(1,:)=[ -1 0.0e-1 .0 8 0.000 1.0];
BOUNDARY(2,:)=[ 1 0.0e-1 .0 6 0.000 1.0 ];
ibc(1) =BOUNDARY(1,1);
bc(1,1)=BOUNDARY(1,2);
bc(1,2)=BOUNDARY(1,3);
bc(1,3)=BOUNDARY(1,4);
bc(1,4)=BOUNDARY(1,5);
bc(1,5)=BOUNDARY(1,6);
ibc(jj+1)=BOUNDARY(2,1);
bc(2,1)=BOUNDARY(2,2);
bc(2,2)=BOUNDARY(2,3);
bc(2,3)=BOUNDARY(2,4);
bc(2,4)=BOUNDARY(2,5);
bc(2,5)=BOUNDARY(2,6);
%% Discritization LOOP
fprintf('distrize ..')
r(0+1,1) = xstart(1);
r(1+1,1) = xstart(1);
for jjj=1:imat
fprintf('distrize ..%2.0f\n',jjj)
deltar = LL(jjj)/(j1(jjj)/2);
%write(*,'(a6,1x,3e24.16)') 'deltar',deltar
if (jjj == 1) % this if assigns the ipoint to the first node of the material
% and checks to see it materials are initally in contact.
ipoint = 1;
elseif (abs(r(0+1,ipoint+j1(jjj-1))-xstart(jjj)) < 1.e-5)
% no gap between materials
r(0+1,ipoint+j1(jjj-1)) = xstart(jjj);
r(1+1,ipoint+j1(jjj-1)) = xstart(jjj);
ibc(ipoint+j1(jjj-1)) = 0;
ipoint = ipoint+j1(jjj-1);
elseif ( r(0+1,ipoint+j1(jjj-1)) < xstart(jjj))
% inital gap between materials
ipoint = ipoint+j1(jjj-1)+2;
ibc(ipoint ) = -2;
ieos(2,ipoint-1)= 0;
ibc(ipoint-2) = 2;
else
fprintf('Input Geometry Error!')
end
r(1,ipoint) = xstart(jjj);
r(1+1,ipoint) = xstart(jjj);
ibc(1+1) = 0;
U(0+1,ipoint) = init(jjj,2);
U(1+1,ipoint) = init(jjj,2);
for j=ipoint+2:2:ipoint+j1(jjj) %node definitions
ibc(j) = 0; %this defines the node as a centeral difference
r(1,j) = r(0+1,j-2) + deltar;
r(2,j) = r(1+1,j-2) + deltar;
U(1,j) = init(jjj,2);
U(2,j) = init(jjj,2);
end
for j=ipoint+1:2:ipoint+j1(jjj)-1 %cell definitions initial conditions
ibc(j) = 0; %this defines the cell as a centeral difference
r(1,j) = 0.5*(r(0+1,j+1)+r(0+1,j-1));
r(2,j) = 0.5d0*(r(1+1,j+1)+r(1+1,j-1));
P(1,j) = init(jjj,1);
P(2,j) = init(jjj,1);
rho(j) = init(jjj,3); %rho is not updated in time therefore it is always rho0
E(1,j) = init(jjj,4); % this gets overwritten below
E(2,j) = init(jjj,4);
ieos(1,j) = ieos(1,jj-(jjj-1)+1); %info was stored there (RHS) just temp.
ieos(2,j) = ieos(2,jj-(jjj-1)+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);
end
ieos(1,jj-(jjj-1)+1) = 0; %this assigns values to the last cell center
ieos(2,jj-(jjj-1)+1) = 0;
ibc(j1(jjj)+ipoint) = 2;
ibc(j1(jjj)+1+ipoint) = 9;
end % jjj loop through imat
%NATHAIEL ibc(jj) should be 1
ibc(j1(imat)+ipoint) = ibc(jj+1); %this assigns values to the last node
ibc(jj+1)=9;
fprintf('ipoint %2.0f %2.0f\n',j1(imat)+ipoint,ibc(jj+1));
fprintf('Assign mass to nodes\n');
for j=0+1:2:jj-2+1
if (ibc(j+1) == 0)
m(j+1) = rho(j+1)*((r(0+1,j+2)^d - r(0+1,j)^d)/d);
end
end
%% Set the Initial Volume
%ieos screwed up j=302
for j=0+1:2:jj-2+1
if (ibc(j+1) == 0)
V(0+1,j+1)=rho(j+1)*((r(0+1,j+2)^d-r(0+1,j)^d)/d)/m(j+1);
V(1+1,j+1)=rho(j+1)*((r(0+1,j+2)^d-r(0+1,j)^d)/d)/m(j+1);
E(0+1,j+1)=P(0+1,j+1)/(V(0+1,j+1)*eos(ieos(1,j+1),4)-1);
E(1+1,j+1)=P(1+1,j+1)/(V(1+1,j+1)*eos(ieos(1,j+1),4)-1);
Temp(0+1,j+1) =E(0+1,j+1)/(rho(j+1)*eos(ieos(1,j+1),8));
Temp(1+1,j+1) =E(1+1,j+1)/(rho(j+1)*eos(ieos(1,j+1),8));
entropy(0+1,j+1) = 6.8d-5; %! i got this from a VT website EES thing
entropy(1+1,j+1) = 6.8d-5; %! units mbar-cc/K/g
fprintf('Pres [Mbar] %2.0f \n',P(0+1,j+1));
fprintf('Engr [MBar-cc/cc] %2.0f \n',E(0+1,j+1));
fprintf('Volm [cc] %2.0f \n',((r(0+1,j+2)^d-r(0+1,j)^d)/d));
fprintf('temp*[K] %2.0f %2.0f %2.0f %2.0f \n',Temp(0+1,j+1),rho(j+1),m(j+1),V(0+1,j+1));
fprintf('entropy %2.0f %2.0f \n',entropy(0+1,j+1),eos(ieos(1+1,j+1),8));
end
end
%% Output Inital Conditions to screen
n=1+1;
%% MAIN LOOP
%%%%%%%%%%%%
ncount = 0
timesteps=1
%%
while (t(n) <= tstop)
%for timesteps=1:2000%147%147
% clc
% clear
% load('SaveTimeMassCrash')
% timesteps=234
%fprintf('%2.0f \n',timesteps);
% 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) ~= m(3) )
fprintf('Masses do not match %2.0f %2.0f %2.0f',n,m(1),m(3))
else
%disp('ok')
end
%% Contact Check
if (1 == 1)
for j=0+1:2:jj+1
if (ibc(j) ~= 9)
%delt = (t(n+2)-t(n+1))/2;
r(n+2,j) = r(n,j)+U(n-1,j)*deltat;
r(n+1,j) = (r(n,j)+r(n+2,j))/2;
end
end
% % c
% Loop below needs checking!
% begin 144 -1 0 0 0 0 0 0 0 0 0 0 0 1 9 9 9 9 9 1 9 1
for j=2+1:2:jj-2+1
if ( ibc(j) ~= 9 && r(n+2,j) <= r(n+2,j-2) && ibc(j-1) == 9)
j
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.
fprintf('Contact Eminent! %2.4f %2.4f\n',n,j);
fprintf('Previous half Time step %2.4f\n',t(n)-t(n-1));
fprintf('For time step 2 x Deltat %2.4f\n',2.d0*delt);
fprintf(' Estimated collision:\n');
fprintf('Void Node at %2.4f will move to %2.4f\n',r(n,j-2), r(n,j-2)+U(n-1,j-2)*2.d0*deltat);
fprintf('Void node velocity %2.4f\n',U(n-1,j-2));
fprintf('J Node at %2.4f will move to %2.4f\n',r(n,j),r(n,j)+U(n-1,j)*2.d0*delt);
fprintf('J node velocity %2.4f\n',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);
%
% 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));
% 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));
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);
fprintf('sig %2.4f %2.4f %2.4f %2.4f \n',sigmar(n,jjj+1),phij,sigmar(n,jjv-1),phiv);
fprintf('bet %2.4f %2.4f %2.4f \n',betav,betaj,d);
fprintf('%2.4f %2.4f %2.4f %2.4f \n',aa,bb,rr,ww);
fprintf('%2.4f %2.4f %2.4f %2.4f \n',rho(jjv-1),r(n,jjv),r(n,jjv-2),V(n,jjv-1));
fprintf('%2.4f %2.4f %2.4f %2.4f \n',rho(jjj+1),r(n,jjj+2),r(n,jjj),V(n,jjj+1));
fprintf('betav %2.4f %2.4f %2.4f %2.4f %2.4f %2.4f',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;
while (abs(dti1-dti0) > 1.d-16)
jj1 = jj1 + 1;
dti0 = dti1;
dti1 = dti0-(aa*dti0*dti0+bb*dti0+2.d0*rr)/(2.d0*aa*dti0+bb);
fprintf('%2.4f %2.4f %2.4f %2.4f\n',aa,bb,rr,ww);
fprintf('iteration\n',dti0,dti1);
if (jj1 > 1)
%read(*,*) foo
end
end
fprintf('Whole Time step adjusted from %2.4f \n',2.d0*delt);
deltat = dti1/2.d0; %this might need to be adjusted because i changed the way time steping works
fprintf('To %2.4f\n',(deltat+dti1));
fprintf('where %2.4f is the time to impact \n',dti1);
fprintf('and %2.4f is an arbatrary small number. \n',deltat);
%read(*,*) foo
end %contact if
end
%read(*,*) foo
end %!contact check if
%%
% % 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 == 2) % 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;
flag=1;
if (dti1 - deltat < 0. || t(n+2)-t(n+1) < 0.)
fprintf('Time step Error from contact'\n);
fprintf('%2.0f %2.0f %2.0f',dti1,deltat,dti1 - deltat , t(n+2)-t(n+1));
end
else
%deltat=deltat_0;
%t(n+1) = t(n) + (deltat/2.d0)/lower
%t(n+2) = t(n) + (deltat)/lower
t(n+1) = t(n) + deltat/2.d0; %Higher
t(n+2) = t(n) + deltat; %Higher
end
%%
%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
for j=0+1:2:jj-1+1
if (ibc(j+1) == 0) %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));
end
end
%%
delt = t(n+1)-t(n-1); %this is different than deltat, deltat is the true timestep
%c
for j=0+1:2:jj+1
%c
if (ibc(j) ~= 9) %13
if (ibc(j) == -1)
%%%%%%%%<Problem HERE NSH
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));
if (delt/phi(n,j))*(sigmar(n,j+1)+0.000000000000)+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))*(sigmar(n,j+1)+0.000000000000)+delt*beta(n,j)*(d-1.d0);
end
%c print *,'BC thing',bc(-1,1)
% What the heck is bc(-1,1)
elseif (ibc(j) == 1)
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));
if (delt/phi(n,j))*(-bc( 1,1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
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);
end
%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) == -2 || ibc(j) == -3)
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) == 2)
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) == 0)
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;
if (delt/phi(n,j))*(sigmar(n,j+1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
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);
end
elseif (ibc(j) == -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) == 4)
U(n+1,j) = 0.d0;
%c if ( U(n+1,j) .lt. 1.d-5) U(n+1,j) = 0.d0
else
fprintf('Momentum ERROR!!! \n');
fprintf('%2.0f %2.0f',j,ibc(j));
end
%c
end
end
%% Increase or decrease timestep based on convergence?
if flag == 0
delt2 = (t(n+1)-t(n-1))/4; %NSH for self adjusting timestep
%c
for j=0+1:2:jj+1
%c
if (ibc(j) ~= 9) %13
if (ibc(j) == -1)
%%%%%%%%<Problem HERE NSH
phi2(n,j) = (rho(j+1)*((r(n,j+2)-r(n,j))/V(n,j+1)))/2.d0;
beta2(n,j) = (sigmar(n,j+1)-sigmao(n,j+1))*V(n,j+1)/(r(n,j+1)*rho(j+1));
if (delt2/phi2(n,j))*(sigmar(n,j+1)+0.000000000000)+delt2*beta2(n,j)*(d-1.d0) == 0
U2(n+2,j) = U(n-1,j);
else
U2(n+2,j) = U(n-1,j)+(delt2/phi2(n,j))*(sigmar(n,j+1)+0.000000000000)+delt2*beta2(n,j)*(d-1.d0);
end
%c print *,'BC thing',bc(-1,1)
% What the heck is bc(-1,1)
elseif (ibc(j) == 1)
phi2(n,j) = rho(j-1)*((r(n,j)-r(n,j-2))/V(n,j-1))/2.d0;
beta2(n,j) = (sigmar(n,j-1)-sigmao(n,j-1))*V(n,j-1)/(r(n,j-1)*rho(j-1));
if (delt2/phi2(n,j))*(-bc( 1,1)-sigmar(n,j-1))+delt2*beta2(n,j)*(d-1.d0) == 0
U2(n+2,j) = U(n-1,j);
else
U2(n+2,j) = U(n-1,j)+(delt2/phi2(n,j))*(-bc( 1,1)-sigmar(n,j-1))+delt2*beta2(n,j)*(d-1.d0);
end
%c U(n+2,j) = 0.d0
%c
%c this is the new way which treats the voids like inner or outer bc's
elseif (ibc(j) == -2 || ibc(j) == -3)
phi2(n,j) = (rho(j+1)*((r(n,j+2)-r(n,j))/V(n,j+1)))/2.d0;
beta2(n,j) = (sigmar(n,j+1)-sigmao(n,j+1))*V(n,j+1)/(r(n,j+1)*rho(j+1));
U2(n+2,j) = U(n-1,j)+(delt2/phi2(n,j))*(sigmar(n,j+1)+pvoid)+delt2*beta2(n,j)*(d-1.d0);
elseif (ibc(j) == 2)
phi2(n,j) = rho(j-1)*((r(n,j)-r(n,j-2))/V(n,j-1))/2.d0;
beta2(n,j) = (sigmar(n,j-1)-sigmao(n,j-1))*V(n,j-1)/(r(n,j-1)*rho(j-1));
U2(n+2,j) = U(n-1,j)+(delt2/phi2(n,j))*(pvoid-sigmar(n,j-1))+delt2*beta2(n,j)*(d-1.d0);
elseif (ibc(j) == 0)
phi2(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)));
beta2(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;
if (delt2/phi2(n,j))*(sigmar(n,j+1)-sigmar(n,j-1))+delt2*beta2(n,j)*(d-1.d0) == 0
U2(n+2,j) = U(n-1,j);
else
U2(n+2,j) = U(n-1,j)+(delt2/phi2(n,j))*(sigmar(n,j+1)-sigmar(n,j-1))+delt2*beta2(n,j)*(d-1.d0);
end
elseif (ibc(j) == -4)
U2(n+2,j) = 0.d0;
%c if ( U(n+2,j) .lt. 1.d-5) U(n+2,j) = 0.d0
elseif (ibc(j) == 4)
U2(n+2,j) = 0.d0;
%c if ( U(n+2,j) .lt. 1.d-5) U(n+2,j) = 0.d0
else
fprintf('Momentum ERROR!!! \n');
fprintf('%2.0f %2.0f',j,ibc(j));
end
%c
end
end
if sum((U(n+1,:)-U2(n+2,:))/nnz(U(n+1,:))) < 1e-4 % This is current Recomendation 1e-7
fprintf('increasetime\n')
deltat=deltat*1.01;
t(n+1) = t(n) + deltat/2.d0; %Higher
t(n+2) = t(n) + deltat; %Higher
delt = t(n+1)-t(n-1); %this is different than deltat, deltat is the true timestep
%c
for j=0+1:2:jj+1
%c
if (ibc(j) ~= 9) %13
if (ibc(j) == -1)
%%%%%%%%<Problem HERE NSH
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));
if (delt/phi(n,j))*(sigmar(n,j+1)+0.000000000000)+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))*(sigmar(n,j+1)+0.000000000000)+delt*beta(n,j)*(d-1.d0);
end
%c print *,'BC thing',bc(-1,1)
% What the heck is bc(-1,1)
elseif (ibc(j) == 1)
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));
if (delt/phi(n,j))*(-bc( 1,1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
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);
end
%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) == -2 || ibc(j) == -3)
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) == 2)
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) == 0)
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;
if (delt/phi(n,j))*(sigmar(n,j+1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
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);
end
elseif (ibc(j) == -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) == 4)
U(n+1,j) = 0.d0;
%c if ( U(n+1,j) .lt. 1.d-5) U(n+1,j) = 0.d0
else
fprintf('Momentum ERROR!!! \n');
fprintf('%2.0f %2.0f',j,ibc(j));
end
%c
end
end
else
deltat=deltat/4;
t(n+1) = t(n) + deltat/2.d0; %Higher
t(n+2) = t(n) + deltat; %Higher
delt = t(n+1)-t(n-1); %this is different than deltat, deltat is the true timestep
%c
for j=0+1:2:jj+1
%c
if (ibc(j) ~= 9) %13
if (ibc(j) == -1)
%%%%%%%%<Problem HERE NSH
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));
if (delt/phi(n,j))*(sigmar(n,j+1)+0.000000000000)+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
U(n+1,j) = U(n-1,j)+(delt/phi(n,j))*(sigmar(n,j+1)+0.000000000000)+delt*beta(n,j)*(d-1.d0);
end
%c print *,'BC thing',bc(-1,1)
% What the heck is bc(-1,1)
elseif (ibc(j) == 1)
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));
if (delt/phi(n,j))*(-bc( 1,1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
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);
end
%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) == -2 || ibc(j) == -3)
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) == 2)
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) == 0)
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;
if (delt/phi(n,j))*(sigmar(n,j+1)-sigmar(n,j-1))+delt*beta(n,j)*(d-1.d0) == 0
U(n+1,j) = U(n-1,j);
else
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);
end
elseif (ibc(j) == -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) == 4)
U(n+1,j) = 0.d0;
%c if ( U(n+1,j) .lt. 1.d-5) U(n+1,j) = 0.d0
else
fprintf('Momentum ERROR!!! \n');
fprintf('%2.0f %2.0f',j,ibc(j));
end
%c
end
end
end
SaveTimeStep(timesteps)=deltat;
fprintf('TimeStep = %4.4d\n',deltat)
end
flag=0;
%%
%ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
%c 3. Position - within j
%c
for j=0+1:2:jj+1
if (ibc(j) ~= 9)
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;
end
end
%%
% c debug block
% if 1==1; %(idebug == 1 && ncount >= ndebug)
% j=jdebug
% fprintf('j= %2.4f n= %2.0f ncount= %2.4f \n',j,n,ncount);
% fprintf('time %2.4f %2.4f %2.4f %2.4f \n',t(n-1),t(n),t(n+1),t(n+2));
% fprintf('deltat %2.4f %2.4f \n',deltat,delt);
% fprintf('vel %2.4f %2.4f \n',U(n,j),U(n+1,j));
% fprintf('r %2.4f %2.4f %2.4f \n',r(n,j-2),r(n,j),r(n,j+2));
% fprintf('V %2.4f %2.4f %2.4f \n',V(n,j+1),V(n,j),V(n,j-1));
% fprintf('rho %2.4f %2.4f %2.4f \n',rho(j-1),rho(j),rho(j+1));
% fprintf('sigmar %2.4f %2.4f \n',sigmar(n,j+1),sigmar(n,j-1));
% fprintf('sigmao %2.4f %2.4f \n',sigmao(n,j-1),sigmao(n,j+1));
% fprintf('4 %2.4f %2.4f %2.4f \n',phi(n,j),beta(n,j),U(n-1,j));
% fprintf('5 %2.4f \n',(deltat/phi(n,j))*(sigmar(n,j+1)-0.d0));
% % read(*,*) foo
% end
% c print *,'Line 537'
%%
% c
% cccccc Begin the connection of nodes due to contact check
% c
%% ISSUE HERE WITH IBC
for j=2+1:2:jj-2+1
if ( ibc(j) == -3 )
fprintf('Joining Nodes %2.0f and %2.4f at n= %2.4f \n',j-2,j,n);
fprintf('Before Joining: \n');
fprintf('The two nodes (VOID (left)and J(right)) at: \n');
fprintf('left: r(void,n-2)= %2.4f U= %2.4f \n',r(n,j-4),U(n-1,j-4));
fprintf('VOID: r(void,n-2)=%2.4f U= %2.4f \n',r(n,j-2),U(n-1,j-2));
fprintf('J: r(j ,n-2)=%2.4f U= %2.4f \n',r(n,j) ,U(n-1,j));
fprintf('right:r(j ,n-2)=%2.4f U= %2.4f \n',r(n,j+2),U(n-1,j+2));
fprintf('then stepped to: \n');
fprintf('left: r(-2 )=%2.4f U= %2.4f \n',r(n+2,j-4),U(n+1,j-4));
fprintf('VOID: r(void)=%2.4f U= %2.4f \n',r(n+2,j-2),U(n+1,j-2));
fprintf('J: r(j )=%2.4f U= %2.4f \n',r(n+2,j) ,U(n+1,j));
fprintf('right:r(+2 )=%2.4f U= %2.4f \n',r(n+2,j+2),U(n+1,j+2));
fprintf('where they were joined \n');
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));
fprintf('Usave %2.4f %2.4f %2.4f %2.4f %2.4f %2.4f %2.4f \n',Usave,m(j+1),U(n+1,j),m(j-3),U(n+1,j-2),m(j-3),m(j+1));
for jjj = j-2:jj-2
for 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
end
end
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
fprintf('After Joining:');
fprintf('left: r(j-2)=%2.4f U= %2.4f\n',r(n+2,j-4),U(n+1,j-4));
fprintf('New: r(j) = %2.4f U= %2.4f\n',r(n+2,j-2),Usave);
fprintf('right:r(j+2)=%2.4f U= %2.4f\n',r(n+2,j ),U(n+1,j));
% read(*,*) foo
% for 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)
% end
%read(*,*) foo
end
end
% c print *,'line 608'
% cccccccccccccccccccccc End of contact ccccccccccccccccccccccccccccc
% c Node passes it's neighbor check
% c
for j=2+1:2:jj-2+1
if ( ibc(j) ~= 9 && r(n+2,j) < r(n+2,j-2) )
fprintf('Contact Check Failed %2.4f %2.4f\n',t(n),j);
fprintf('Try lowering time step\n');
fprintf('Void %2.4f %2.4f\n',r(n+2,j-2),U(n+1,j-2));
fprintf('j %2.4f %2.4f\n',r(n+2,j) ,U(n+1,j));
fprintf('deltat %2.4f\n',deltat);
fprintf('%2.4f %2.4f\n',bc(-1,1),bc(1,1));
% read(*,*) foo
end
end
%%
% ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
% c 3. Relative VOLUME - within j
% c
% c deltat = t(n+2)-t(n)
% c print *,'line 626'
% c read(*,*) foo
for j=0+1:2:jj-2+1
if (ibc(j+1) == 0)
% c
r(n+1,j+1) = ( r(n+1,j)+r(n+1,j+2) ) /2.d0;
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) == 0.)
fprintf('------------- Zero volume error! #1-----------------');
fprintf('volume %2.0f %2.0f %2.0f %2.0f %2.0f',n,j+1,r(n+2,j+2),r(n+2,j),V(n+2,j+1));
%read(*,*) foo
end
if ( V(n+1,j+1) == 0.)
fprintf('------------- Zero volume error! #2-----------------');
fprintf('volume %2.0f %2.0f %2.0f %2.0f %2.0f',n,j+1,r(n+1,j+2),r(n+1,j),V(n+1,j+1));
%read(*,*) foo
end
%ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
%c 4. VELOCITY STRAINS - finish j
%c
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
if (d == 1.)
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));
end
end
end %! 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 ibc(241) means j =239
%c print *,'line 679'
for j=0+1:2:jj-2+1
if (ibc(j+1) == 0)
%c deltat = t(n+2)-t(n)
if (ieos(2,j+1) ~= 3)
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;
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;
end %! iEOS check
%c
end
end
if (idebug == 1 && n >= ndebug)
j=jdebug;
fprintf('1 %2.0f %2.0f %2.0f %2.0f %2.0f',j,eos(ieos(1,j+1),6),V(n+2,j+1),V(n,j+1),V(n+1,j+1));
fprintf('s %2.0f %2.0f %2.0f %2.0f',s1(n+2,j+1),s2(n+2,j+1),s3(n+2,j+1),epsi1(n+1,j+1));
end
%%
% ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
% c 6. VON MISES YIELD CONDITION - start j
% c
for j=0+1:2:jj-2+1
if (ibc(j+1) == 0)
if (ieos(2,j+1) ~= 3)
% 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) > 0.)
%fprintf('material yeilded 1\n')
% 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);
end
% 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) > 0.)
% fprintf('material yeilded 2\n')
% 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
end
% c
% c print *,s1(n+2,j+1),s2(n+2,j+1),s3(n+2,j+1)
if(idebug == 1 )
fprintf('Yield Check %2.0f %2.0f',Y(j+1),k(n+2,j+1))
% read(*,*) foo
end %! debug if
end %!ibc(j+1) .eq. 0
%
% if s1(n+1,j+1) < 1e-8 && s2(n+1,j+1) < 1e-8 && s3(n+1,j+1) < 1e-8
% s1(n+1,j+1) = 0;
% s2(n+1,j+1) = 0;
% s3(n+1,j+1) = 0;
% end
% if s1(n+2,j+1) < 1e-8 && s2(n+2,j+1) < 1e-8 && s3(n+2,j+1) < 1e-8
% s1(n+2,j+1)=0;
% s2(n+2,j+1)=0;
% s3(n+2,j+1)=0;
% end
%ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
%c 7. ARTIFICIAL VISCOSITY - within j
%c
if (1 == 1)
%c print *,j,u(n+1,j+2),u(n+1,j)
if( U(n+1,j+2) < U(n+1,j) && V(n+2,j+1)-V(n,j+1) < 0. )
xx = rho(j+1)/V(n+1,j+1);
if (P(n,j+1) < 0.)
%c print *,'Negative Pressure!'
a = sqrt(-P(n,j+1)/xx);
else
a = sqrt( P(n,j+1)/xx);